summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-01-17 22:19:10 -0800
committerGitHub <noreply@github.com>2023-01-17 22:19:10 -0800
commit86ddb9c452c4f33d09b4f7d4f90a9abad4984071 (patch)
tree833f8bb0fd5df8f0328e20a4568a19081593cedb /tests
parenta0994a8da142e54362e9ec1fdb5e5abc708ec3d2 (diff)
First custom backward-derivative test case working. (#2598)
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang33
-rw-r--r--tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang.expected.txt5
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang b/tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang
new file mode 100644
index 000000000..ce282eb77
--- /dev/null
+++ b/tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang
@@ -0,0 +1,33 @@
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+typedef DifferentialPair<float> dpfloat;
+typedef DifferentialPair<float2> dpfloat2;
+typedef DifferentialPair<float3> dpfloat3;
+
+[BackwardDifferentiable]
+float diffExp(float x)
+{
+ return exp(x);
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ {
+ dpfloat dpx = dpfloat(2.0, 1.0);
+ __bwd_diff(diffExp)(dpx, 1.0);
+ outputBuffer[0] = dpx.p; // Expect: 2
+ outputBuffer[1] = dpx.d; // Expect: 7.389056
+ }
+
+ {
+ dpfloat dpx = dpfloat(0.0, 1.0);
+ __bwd_diff(diffExp)(dpx, 1.0);
+ outputBuffer[2] = dpx.p; // Expect: 0.000000
+ outputBuffer[3] = dpx.d; // Expect: 1.000000
+ }
+}
diff --git a/tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang.expected.txt b/tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang.expected.txt
new file mode 100644
index 000000000..49e34b0bf
--- /dev/null
+++ b/tests/autodiff-dstdlib/dstdlib-elementary-bwd.slang.expected.txt
@@ -0,0 +1,5 @@
+type: float
+2.000000
+7.389056
+0.000000
+1.000000 \ No newline at end of file