From e8a1dd11eab4c07366b29aca775eb927a465e133 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 8 Sep 2023 12:26:07 -0700 Subject: Don't inline callees with custom derivative before autodiff. (#3196) Co-authored-by: Yong He --- tests/autodiff/inline.slang | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/autodiff/inline.slang (limited to 'tests') diff --git a/tests/autodiff/inline.slang b/tests/autodiff/inline.slang new file mode 100644 index 000000000..9b41b5f1f --- /dev/null +++ b/tests/autodiff/inline.slang @@ -0,0 +1,45 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -output-using-type +//TEST:SIMPLE(filecheck=CHECK):-stage compute -entry computeMain -target hlsl + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +typedef DifferentialPair dpfloat; +typedef float.Differential dfloat; + +// CHECK-NOT: void mySqr{{.*}}( + +// Test that calls to a ForceInline function stil get correct custom derivative. +[BackwardDerivative(bwd_mySqr)] +[ForceInline] +void mySqr(float x, out float y) +{ + y = x * x; +} + +void bwd_mySqr(inout DifferentialPair dpx, in float.Differential dy) +{ + dpx = DifferentialPair(dpx.p, 1001.0); +} + +[Differentiable] +void myF(float x, out float y) +{ + mySqr(x, y); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + dpfloat dpa = dpfloat(2.0, 1.0); + __bwd_diff(myF)(dpa, 1.0); + // BUFFER: 1001.0 + outputBuffer[0] = dpa.d; + + float o; + myF(1.0, o); + outputBuffer[1] = o; + } +} -- cgit v1.2.3