diff options
| author | Yong He <yonghe@outlook.com> | 2023-09-08 12:26:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-08 12:26:07 -0700 |
| commit | e8a1dd11eab4c07366b29aca775eb927a465e133 (patch) | |
| tree | 6f1e0788860ace253c05c3fbb37be8cd1f07fecf /tests | |
| parent | cb5dd19992fb77ca2be866d9c6f2f4436c8b1c1e (diff) | |
Don't inline callees with custom derivative before autodiff. (#3196)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/inline.slang | 45 |
1 files changed, 45 insertions, 0 deletions
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<float> outputBuffer; + +typedef DifferentialPair<float> 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<float> dpx, in float.Differential dy) +{ + dpx = DifferentialPair<float>(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; + } +} |
