-
Notifications
You must be signed in to change notification settings - Fork 299
Add subscript operator support in cuda #6830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
72b90b2
to
0bd47d4
Compare
795637a
to
1fbd035
Compare
1fbd035
to
a9b6b9d
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for the subscript operator for read-only textures in CUDA by introducing inline PTX intrinsic functions to perform texture fetch/load operations across 1D, 2D, 3D, and array textures. Key changes include:
- Implementation of tex1Dfetch_int, tex2Dfetch_int, tex3Dfetch_int functions for various dimensional textures.
- Addition of tex1DArrayfetch_int and tex2DArrayfetch_int to support array textures.
- Updates to the test suite to validate the new functionality.
Files not reviewed (4)
- source/slang/hlsl.meta.slang: Language not supported
- tests/compute/texture-subscript-cuda.slang: Language not supported
- tests/compute/texture-subscript-cuda.slang.expected.txt: Language not supported
- tests/language-feature/capability/capability-invalid-fragment-in-compute.slang: Language not supported
source/slang/hlsl.meta.slang
Outdated
switch(Shape.flavor) | ||
{ | ||
case $(SLANG_TEXTURE_1D): | ||
__intrinsic_asm "<PTX does not support 1D texture read>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this just going to lead to an error in the downstream compiler (nvrtc)?
should that be a static_assert
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, seems like the bootstrap has some issues with the assert. I will try to fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok seems like that was because of missing default. I've added that back, and the static_assert. Please check.
__intrinsic_asm "tex2Dfetch_int<$T0>($0, ($1).x, ($1).y)"; | ||
case $(SLANG_TEXTURE_3D): | ||
__intrinsic_asm "tex3Dfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)"; | ||
case $(SLANG_TEXTURE_CUBE): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there no PTX intrinsics for cube map reads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, cubemap requires float coordinates. Confirmed with the ptx team as well. I even saw error:
line 84; error : Floating-point coordinates required
d3459d8
to
c83cd9a
Compare
This CL adds support for the subscript operator for Read Only textures in cuda. Also adds a test for this. Fixes shader-slang#6781
c83cd9a
to
9dd729e
Compare
prelude/slang-cuda-prelude.h
Outdated
asm("tex.3d.v4.f32.s32 {%0, %1, %2, %3}, [%4, {%5, %6, %7, %8}];" | ||
: "=f"(result), "=f"(dummy), "=f"(dummy), "=f"(dummy) | ||
: "l"(texObj), "r"(x), "r"(y), "r"(z), "r"(z)); | ||
// Note: The repeated z is a WAR for a bug in PTX. That is a dummy parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add more details. Does PTX only support vec4 fetch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write a test which will start failing when this bug is fixed downstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that is not a bug. Fixed the note after I confirmed with the ptx team. It is how the 3D textures are addressed.
From the docs:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-instructions-tex
Operand c is a scalar or singleton tuple for 1d textures; is a two-element vector for 2d textures;
and is a four-element vector for 3d textures,
prelude/slang-cuda-prelude.h
Outdated
asm("tex.3d.v4.f32.s32 {%0, %1, %2, %3}, [%4, {%5, %6, %7, %8}];" | ||
: "=f"(result), "=f"(dummy), "=f"(dummy), "=f"(dummy) | ||
: "l"(texObj), "r"(x), "r"(y), "r"(z), "r"(z)); | ||
// Note: The repeated z is a WAR for a bug in PTX. That is a dummy parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write a test which will start failing when this bug is fixed downstream?
source/slang/hlsl.meta.slang
Outdated
|
||
switch(Shape.flavor) | ||
{ | ||
case $(SLANG_TEXTURE_2D): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to handle 3d here as well, inline with the static assert (I think that an if/else here would be clearer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we support 3D array textures in slang? I could not find Texture3DArray
. I have updated the static_assert to be clearer, and also made this an if
. Please let me know if this is OK.
/format |
🌈 Formatted, please merge the changes from this PR |
* cuda: Add support for subscript operator This CL adds support for the subscript operator for Read Only textures in cuda. Also adds a test for this. Fixes shader-slang#6781 * format code * fix review comments * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
This CL adds support for the subscript operator for Read Only
textures in cuda. Also adds a test for this.
Now that we support .Load for read only textures in cuda, an existing test also needs to be modified.