diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/reverse-checkpoint-1.slang | 42 | ||||
| -rw-r--r-- | tests/autodiff/reverse-checkpoint-1.slang.expected.txt | 5 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-checkpoint-1.slang b/tests/autodiff/reverse-checkpoint-1.slang new file mode 100644 index 000000000..e503fb50f --- /dev/null +++ b/tests/autodiff/reverse-checkpoint-1.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; +typedef float.Differential dfloat; + +[BackwardDifferentiable] +float g(float x) +{ + return log(x); +} + +[BackwardDifferentiable] +float f(int p, float x) +{ + float y = 1.0; + // Test that phi parameter can be restored. + if (p == 0) + y = g(x); + return y * y; +} + +// Check that there are no calls to primal_g in bwd_f. + +// CHECK: void s_bwd_f_{{[0-9]+}} +// CHECK-NOT: {{[_a-zA-Z0-9]+}} = s_bwd_primal_g_{{[0-9]+}} +// CHECK: return + + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + dpfloat dpa = dpfloat(2.0, 0.0); + + __bwd_diff(f)(0, dpa, 1.0f); + outputBuffer[0] = dpa.d; // Expect: 1 +} diff --git a/tests/autodiff/reverse-checkpoint-1.slang.expected.txt b/tests/autodiff/reverse-checkpoint-1.slang.expected.txt new file mode 100644 index 000000000..1ea0454e4 --- /dev/null +++ b/tests/autodiff/reverse-checkpoint-1.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +0.693147 +0.000000 +0.000000 +0.000000 |
