summaryrefslogtreecommitdiff
path: root/tests/diagnostics/force-no-diff-this.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics/force-no-diff-this.slang')
-rw-r--r--tests/diagnostics/force-no-diff-this.slang42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/diagnostics/force-no-diff-this.slang b/tests/diagnostics/force-no-diff-this.slang
new file mode 100644
index 000000000..ae1464ffb
--- /dev/null
+++ b/tests/diagnostics/force-no-diff-this.slang
@@ -0,0 +1,42 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
+
+struct MyStruct<T> where T: __BuiltinFloatingPointType
+{
+ float a;
+ __init(float a) { this.a = a;}
+
+ [Differentiable]
+ T eval(T x)
+ {
+ //CHECK: ([[# @LINE+1]]): warning 31159
+ return exp(x * T(a) * T(a));
+ }
+
+ [Differentiable]
+ [NoDiffThis]
+ T eval1(T x)
+ {
+ //CHECK-NOT: ([[# @LINE+1]]): warning 31159
+ return exp(x * T(a) * T(a));
+ }
+};
+
+[Differentiable]
+float evalFunc(float x)
+{
+ MyStruct<float> s = {x};
+ return s.eval(x) + s.eval1(x);
+}
+
+RWStructuredBuffer<float> output;
+
+[shader("compute")]
+[numthreads(1,1,1)]
+void computeMain(uint id : SV_DispatchThreadID)
+{
+ var x = diffPair(2.0f);
+ bwd_diff(evalFunc)(x, 1.0f);
+
+ output[0] = x.d;
+}
+