diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-06-10 14:57:09 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-10 11:57:09 -0700 |
| commit | 37e8917d10626b519470f2e34625f0efe741352f (patch) | |
| tree | 4e8e51bd63ebc03fcdf0c893b675906cf507d73c /tests/cuda | |
| parent | 0d9bd79e8fd4d57e1a723ca6b6a45efec2b42872 (diff) | |
CUDA layout corner cases/testing (#1881)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add support for sizeOf/alignOf/offsetOf to stdlib.
Add $G intrinsic expansion that works of the generic parameters not the param type
* Test cuda layout.
* Fix CUDA layout issues.
Fix reflection to handle other built in types.
Fix __offsetOf
* Tests of reflection and layout as reported directly from CUDA.
* Comment about use of aligned size as size.
* Fix warning from VS.
* Check alignment is pow2.
* Small improvements to alignment calcs.
* Tab to spaces.
* Fix alignment pointer sizes on 32 bit OS for CUDA.
* Fix CUDA reflection on 32 bit.
Diffstat (limited to 'tests/cuda')
| -rw-r--r-- | tests/cuda/cuda-array-layout.slang | 32 | ||||
| -rw-r--r-- | tests/cuda/cuda-array-layout.slang.expected.txt | 9 | ||||
| -rw-r--r-- | tests/cuda/cuda-layout.slang | 24 | ||||
| -rw-r--r-- | tests/cuda/cuda-layout.slang.expected.txt | 33 | ||||
| -rw-r--r-- | tests/cuda/cuda-reflection.slang | 28 | ||||
| -rw-r--r-- | tests/cuda/cuda-reflection.slang.expected | 250 |
6 files changed, 376 insertions, 0 deletions
diff --git a/tests/cuda/cuda-array-layout.slang b/tests/cuda/cuda-array-layout.slang new file mode 100644 index 000000000..7fee3b192 --- /dev/null +++ b/tests/cuda/cuda-array-layout.slang @@ -0,0 +1,32 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer : register(u0); + +struct PadLadenStruct +{ + double a; + uint8_t b; +}; + +// This is to check if the last half can be inserted 'inside' the spare padding of a. It should not be +struct StructWithArray +{ + PadLadenStruct a[1]; + uint8_t b; + + matrix<half, 3, 3> c; + uint8_t d; +}; + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + StructWithArray s; + outputBuffer[0] = __sizeOf(s); + + outputBuffer[1] = __offsetOf(s, s.a); + outputBuffer[2] = __offsetOf(s, s.b); + outputBuffer[3] = __offsetOf(s, s.c); + outputBuffer[4] = __offsetOf(s, s.d); +} diff --git a/tests/cuda/cuda-array-layout.slang.expected.txt b/tests/cuda/cuda-array-layout.slang.expected.txt new file mode 100644 index 000000000..bc3e8bd6c --- /dev/null +++ b/tests/cuda/cuda-array-layout.slang.expected.txt @@ -0,0 +1,9 @@ +type: int32_t +48 +0 +16 +20 +44 +0 +0 +0 diff --git a/tests/cuda/cuda-layout.slang b/tests/cuda/cuda-layout.slang new file mode 100644 index 000000000..725bf798e --- /dev/null +++ b/tests/cuda/cuda-layout.slang @@ -0,0 +1,24 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer : register(u0); + +#define WRITE_TYPE_ALIGN(base, type) \ + outputBuffer[base * 4 + 0] = __alignOf<type>(); \ + outputBuffer[base * 4 + 1] = __alignOf<vector<type, 2> >(); \ + outputBuffer[base * 4 + 2] = __alignOf<vector<type, 3> >(); \ + outputBuffer[base * 4 + 3] = __alignOf<vector<type, 4> >(); + + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + WRITE_TYPE_ALIGN(0, uint8_t) + WRITE_TYPE_ALIGN(1, uint16_t) + WRITE_TYPE_ALIGN(2, int) + WRITE_TYPE_ALIGN(3, int64_t) + + WRITE_TYPE_ALIGN(4, half) + WRITE_TYPE_ALIGN(5, float) + WRITE_TYPE_ALIGN(6, double) +} diff --git a/tests/cuda/cuda-layout.slang.expected.txt b/tests/cuda/cuda-layout.slang.expected.txt new file mode 100644 index 000000000..bf4edf064 --- /dev/null +++ b/tests/cuda/cuda-layout.slang.expected.txt @@ -0,0 +1,33 @@ +type: int32_t +1 +2 +1 +4 +2 +4 +2 +8 +4 +8 +4 +16 +8 +16 +8 +16 +2 +4 +4 +4 +4 +8 +4 +16 +8 +16 +8 +16 +0 +0 +0 +0 diff --git a/tests/cuda/cuda-reflection.slang b/tests/cuda/cuda-reflection.slang new file mode 100644 index 000000000..95bf591c9 --- /dev/null +++ b/tests/cuda/cuda-reflection.slang @@ -0,0 +1,28 @@ +// cuda-reflection.slang + +//TEST:REFLECTION:-stage compute -entry main -target cuda + +struct PadLadenStruct +{ + double a; + uint8_t b; +}; + +// This is to check if the last half can be inserted 'inside' the spare padding of a. It should not be +struct StructWithArray +{ + PadLadenStruct a[1]; + uint8_t c; + + matrix<half, 3, 3> d; + uint8_t e; +}; + +ConstantBuffer<StructWithArray> cb; +RWStructuredBuffer<StructWithArray> sb; + +[numthreads(1, 1, 1)] +void main( + uint3 dispatchThreadID : SV_DispatchThreadID) +{ +}
\ No newline at end of file diff --git a/tests/cuda/cuda-reflection.slang.expected b/tests/cuda/cuda-reflection.slang.expected new file mode 100644 index 000000000..d27d99557 --- /dev/null +++ b/tests/cuda/cuda-reflection.slang.expected @@ -0,0 +1,250 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "cb", + "binding": {"kind": "uniform", "offset": 0, "size": 8}, + "type": { + "kind": "constantBuffer", + "elementType": { + "kind": "struct", + "name": "StructWithArray", + "fields": [ + { + "name": "a", + "type": { + "kind": "array", + "elementCount": 1, + "elementType": { + "kind": "struct", + "name": "PadLadenStruct", + "fields": [ + { + "name": "a", + "type": { + "kind": "scalar", + "scalarType": "float64" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 8} + }, + { + "name": "b", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 8, "size": 1} + } + ] + }, + "uniformStride": 16 + }, + "binding": {"kind": "uniform", "offset": 0, "size": 16} + }, + { + "name": "c", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 16, "size": 1} + }, + { + "name": "d", + "type": { + "kind": "matrix", + "rowCount": 3, + "columnCount": 3, + "elementType": { + "kind": "scalar", + "scalarType": "float16" + } + }, + "binding": {"kind": "uniform", "offset": 20, "size": 24} + }, + { + "name": "e", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 44, "size": 1} + } + ] + }, + "containerVarLayout": { + "binding": {"kind": "uniform", "offset": 0, "size": 8} + }, + "elementVarLayout": { + "type": { + "kind": "struct", + "name": "StructWithArray", + "fields": [ + { + "name": "a", + "type": { + "kind": "array", + "elementCount": 1, + "elementType": { + "kind": "struct", + "name": "PadLadenStruct", + "fields": [ + { + "name": "a", + "type": { + "kind": "scalar", + "scalarType": "float64" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 8} + }, + { + "name": "b", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 8, "size": 1} + } + ] + }, + "uniformStride": 16 + }, + "binding": {"kind": "uniform", "offset": 0, "size": 16} + }, + { + "name": "c", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 16, "size": 1} + }, + { + "name": "d", + "type": { + "kind": "matrix", + "rowCount": 3, + "columnCount": 3, + "elementType": { + "kind": "scalar", + "scalarType": "float16" + } + }, + "binding": {"kind": "uniform", "offset": 20, "size": 24} + }, + { + "name": "e", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 44, "size": 1} + } + ] + }, + "binding": {"kind": "uniform", "offset": 0, "size": 48} + } + } + }, + { + "name": "sb", + "binding": {"kind": "uniform", "offset": 8, "size": 16}, + "type": { + "kind": "resource", + "baseShape": "structuredBuffer", + "access": "readWrite", + "resultType": { + "kind": "struct", + "name": "StructWithArray", + "fields": [ + { + "name": "a", + "type": { + "kind": "array", + "elementCount": 1, + "elementType": { + "kind": "struct", + "name": "PadLadenStruct", + "fields": [ + { + "name": "a", + "type": { + "kind": "scalar", + "scalarType": "float64" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 8} + }, + { + "name": "b", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 8, "size": 1} + } + ] + }, + "uniformStride": 16 + }, + "binding": {"kind": "uniform", "offset": 0, "size": 16} + }, + { + "name": "c", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 16, "size": 1} + }, + { + "name": "d", + "type": { + "kind": "matrix", + "rowCount": 3, + "columnCount": 3, + "elementType": { + "kind": "scalar", + "scalarType": "float16" + } + }, + "binding": {"kind": "uniform", "offset": 20, "size": 24} + }, + { + "name": "e", + "type": { + "kind": "scalar", + "scalarType": "uint8" + }, + "binding": {"kind": "uniform", "offset": 44, "size": 1} + } + ] + } + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "compute", + "parameters": [ + { + "name": "dispatchThreadID", + "semanticName": "SV_DISPATCHTHREADID", + "type": { + "kind": "vector", + "elementCount": 3, + "elementType": { + "kind": "scalar", + "scalarType": "uint32" + } + } + } + ], + "threadGroupSize": [1, 1, 1] + } + ] +} +} |
