diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/reverse-checkpoint-1.slang | 1 | ||||
| -rw-r--r-- | tests/autodiff/reverse-checkpoint-2.slang | 43 | ||||
| -rw-r--r-- | tests/autodiff/reverse-checkpoint-2.slang.expected.txt | 5 |
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-checkpoint-1.slang b/tests/autodiff/reverse-checkpoint-1.slang index e503fb50f..beb983b3b 100644 --- a/tests/autodiff/reverse-checkpoint-1.slang +++ b/tests/autodiff/reverse-checkpoint-1.slang @@ -10,6 +10,7 @@ typedef DifferentialPair<float> dpfloat; typedef float.Differential dfloat; [BackwardDifferentiable] +[PreferCheckpoint] float g(float x) { return log(x); diff --git a/tests/autodiff/reverse-checkpoint-2.slang b/tests/autodiff/reverse-checkpoint-2.slang new file mode 100644 index 000000000..bd787d83a --- /dev/null +++ b/tests/autodiff/reverse-checkpoint-2.slang @@ -0,0 +1,43 @@ +//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] +[PreferRecompute] +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: {{[_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-2.slang.expected.txt b/tests/autodiff/reverse-checkpoint-2.slang.expected.txt new file mode 100644 index 000000000..1ea0454e4 --- /dev/null +++ b/tests/autodiff/reverse-checkpoint-2.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +0.693147 +0.000000 +0.000000 +0.000000 |
