summaryrefslogtreecommitdiff
path: root/tests/autodiff
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-11-10 13:55:14 -0800
committerGitHub <noreply@github.com>2023-11-10 13:55:14 -0800
commit011d4281647e3a2a3cf0dbdda1fa65cc1b8ed881 (patch)
tree70f91655e86d30529eda0a683e15f378eeae2cb5 /tests/autodiff
parentbfd3f39d04047d7a46e75206cd125ed87b3f3f99 (diff)
Cleanup builtin arithmetic interfaces. (#3317)
* wip: clean up IArithmetic * wip. * Cleanup builtin arithmetic interfaces. * Fix. * Fixes. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/autodiff')
-rw-r--r--tests/autodiff/generic-constructor.slang39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/autodiff/generic-constructor.slang b/tests/autodiff/generic-constructor.slang
new file mode 100644
index 000000000..aad9824ec
--- /dev/null
+++ b/tests/autodiff/generic-constructor.slang
@@ -0,0 +1,39 @@
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+interface IFoo : IDifferentiable
+{
+ [Differentiable]
+ __init(Differential v);
+}
+
+struct Impl : IFoo
+{
+ float x;
+
+ [Differentiable]
+ __init(Differential v)
+ {
+ x = v.x;
+ }
+}
+
+[Differentiable]
+float test(float x)
+{
+ Impl.Differential v0 = { x };
+ var v1 = Impl(v0);
+ return v1.x * v1.x;
+}
+
+[numthreads(1,1,1)]
+void computeMain(uint tid : SV_DispatchThreadID)
+{
+ var p = diffPair(3.0, 0.0);
+ bwd_diff(test)(p, 1.0);
+ outputBuffer[tid] = p.d;
+ // CHECK: 6.0
+}