summaryrefslogtreecommitdiff
path: root/tests/compute
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-01-21 09:38:10 -0500
committerGitHub <noreply@github.com>2020-01-21 09:38:10 -0500
commit47392bc72b826b4ad427b703391a77e697735a65 (patch)
tree7c541c4295742b765124f42bab9f713276c83580 /tests/compute
parenta8669ade5cb3add8b9ce08e2c3bd96e93190bca8 (diff)
CUDA support improvements (#1168)
* Add test result for compile-to-cuda * Add RAII for some CUDA types to simplify usage. * First pass handling of some instrinsics on CUDA (for example transcendentals) * CUDA working with built in intrinsics. * Add missing CUDA prelude intrinsics. * CUDA matches CPU output on simple-cross-compile.slang * First pass at hlsl-scalar-float-intrinsic.slang test. * Fix smoothstep impl on CUDA and CPU. * Fixed step intrinsic on CUDA/CPU. * Added operator[] to Matrix for C++, to allow row access. Needs a fix for CUDA. * Fixed warning on clang build.
Diffstat (limited to 'tests/compute')
-rw-r--r--tests/compute/hlsl-scalar-float-intrinsic.slang88
-rw-r--r--tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt4
-rw-r--r--tests/compute/transcendental.slang1
3 files changed, 93 insertions, 0 deletions
diff --git a/tests/compute/hlsl-scalar-float-intrinsic.slang b/tests/compute/hlsl-scalar-float-intrinsic.slang
new file mode 100644
index 000000000..213db4b23
--- /dev/null
+++ b/tests/compute/hlsl-scalar-float-intrinsic.slang
@@ -0,0 +1,88 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int idx = int(dispatchThreadID.x);
+
+ float f = idx * (1.0f / (4.0f - 1));
+
+ int it = 0;
+ float ft = 0.0f;
+
+ // fmod
+ // ft += f % 0.5f;
+
+ ft += sin(f);
+ ft += cos(f);
+ ft += tan(f);
+
+ ft += asin(f);
+ ft += acos(f);
+ ft += atan(f);
+
+ ft += atan2(f, 2.0);
+
+ {
+ float sf, cf;
+ sincos(f, sf, cf);
+
+ ft += sf;
+ ft += cf;
+ }
+
+ ft += rcp(1.0 + f);
+ ft += sign(f - 0.5);
+
+ ft += saturate(f * 4 - 2.0);
+
+ ft += sqrt(f);
+ ft += rsqrt(1.0f + f);
+
+ ft += exp2(f);
+ ft += exp(f);
+
+
+ ft += frac(f * 3);
+// ft += ceil(f * 5 - 3);
+
+ ft += floor(f * 10 - 7);
+ ft += trunc(f * 7);
+
+
+ ft += log(f + 10.0);
+ ft += log2(f * 3 + 2);
+
+ // ft += log10(f * 10 + 4);
+
+ ft += abs(f * 4 - 2.0f);
+
+ ft += min(0.5, f);
+ ft += max(f, 0.75);
+
+ ft += pow(0.5, f);
+
+ ft += smoothstep(0.2, 0.7, f);
+ ft += lerp(-100, 100, f);
+
+
+ ft += clamp(f, 0.1, 0.3);
+
+ ft += step(f, 0.5);
+
+ int vi = asint(f - f) + idx;
+
+ ft += float(vi);
+
+ uint vu = asuint(f);
+ ft += asfloat(vu);
+
+ outputBuffer[idx] = int(ft * 16);
+} \ No newline at end of file
diff --git a/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt b/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt
new file mode 100644
index 000000000..04d17659c
--- /dev/null
+++ b/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt
@@ -0,0 +1,4 @@
+FFFFFA3C
+FFFFFEEC
+3CA
+8C1
diff --git a/tests/compute/transcendental.slang b/tests/compute/transcendental.slang
index aa40da752..bde43ee38 100644
--- a/tests/compute/transcendental.slang
+++ b/tests/compute/transcendental.slang
@@ -1,3 +1,4 @@
+//TEST(compute):COMPARE_COMPUTE:-cuda
//TEST(compute):COMPARE_COMPUTE:-cpu
//TEST(compute):COMPARE_COMPUTE:
//TEST(compute,vulcan):COMPARE_COMPUTE:-vk