summaryrefslogtreecommitdiffstats
path: root/tests/autodiff
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-12-20 00:53:49 -0800
committerGitHub <noreply@github.com>2024-12-20 00:53:49 -0800
commite93cb8a4d1bb7d835bc3762ce25ced422e75e97a (patch)
tree47b482d99fdbb12f8bc3940d7cbf39444c47c671 /tests/autodiff
parent5c9f011fa4948d1f70689b03ddcd203cb2525b2b (diff)
Check subscript/property accessor for differentiability. (#5922)
Diffstat (limited to 'tests/autodiff')
-rw-r--r--tests/autodiff/subscript.slang33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/autodiff/subscript.slang b/tests/autodiff/subscript.slang
new file mode 100644
index 000000000..2b16597c0
--- /dev/null
+++ b/tests/autodiff/subscript.slang
@@ -0,0 +1,33 @@
+//TEST:COMPARE_COMPUTE(filecheck-buffer=CHK): -output-using-type
+
+interface ITest
+{
+ __subscript(int i) -> float
+ {
+ [BackwardDifferentiable] get;
+ }
+}
+struct Test : ITest
+{
+ __subscript(int i) -> float
+ {
+ [BackwardDifferentiable] get { return 5.0f * i; }
+ }
+}
+
+[Differentiable]
+float test(ITest arg)
+{
+ return arg[1];
+}
+
+//TEST_INPUT:set output = out ubuffer(data=[0 0 0 0], stride=4)
+RWStructuredBuffer<float> output;
+
+[numthreads(1,1,1)]
+void computeMain()
+{
+ Test t = {};
+ output[0] = test(t);
+ // CHK: 5.0
+} \ No newline at end of file