From bee74b16eafa64ccc33bb386a1dc753cd6c41a82 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 26 Oct 2023 14:01:26 -0700 Subject: Add more diagnostics around use of custom derivatives. (#3291) Co-authored-by: Yong He --- tests/diagnostics/custom-derivative-generic.slang | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/diagnostics/custom-derivative-generic.slang (limited to 'tests') diff --git a/tests/diagnostics/custom-derivative-generic.slang b/tests/diagnostics/custom-derivative-generic.slang new file mode 100644 index 000000000..5f2cd9951 --- /dev/null +++ b/tests/diagnostics/custom-derivative-generic.slang @@ -0,0 +1,51 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +typedef DifferentialPair dpfloat; + +interface IFoo +{ + static float bar1(float x); + + // CHECK-DAG: {{.*}}(13): error 31152 + [PrimalSubstitute(bar1)] + static float bar(float x); + + static DifferentialPair dd(DifferentialPair x); +} + +__generic +float f(float x) +{ + return N*x*x; +} + +// CHECK-DAG: {{.*}}(26): error 31153 +[ForwardDerivative(IFoo.dd)] +float bbb(float x); + +// CHECK-DAG: {{.*}}(30): error 31152 +[ForwardDerivativeOf(IFoo.bar)] +DifferentialPair dd1(DifferentialPair x) +{ + return x; +} + +// CHECK-DAG: {{.*}}(37): error 31151 +[BackwardDerivative(f)] +DifferentialPair df(inout DifferentialPair x, float dOut) +{ + var primal = x.p * x.p; + var diff = 2 * x.p * x.d * N; + return DifferentialPair(primal, diff); +} +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + { + dpfloat dpa = dpfloat(3.0, 1.0); + outputBuffer[1] = __fwd_diff(f<3>)(dpa).d; // Expect: 6.0 + } +} -- cgit v1.2.3