diff options
| author | Yong He <yonghe@outlook.com> | 2022-11-09 19:19:17 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-09 19:19:17 -0800 |
| commit | 004f6e30b5df3a3df2c26fe5c4a5e78c49f71166 (patch) | |
| tree | cbc942746bab043da0eb5298993d95f9665dfddf /tests | |
| parent | cedd93690c63188cf98e452c9d104cf51aad6c4e (diff) | |
Add `[ForwardDerivativeOf]` attribute. (#2501)
* Add [ForwardDerivativeOf] attribute.
* Fix handling around phi nodes.
* Fixes.
* Remove IR opcode for ForwardDerivativeOfDecoration.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/custom-intrinsic-2.slang | 37 | ||||
| -rw-r--r-- | tests/autodiff/custom-intrinsic-2.slang.expected.txt | 6 | ||||
| -rw-r--r-- | tests/autodiff/dstdlib-vector.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/dstdlib.slang | 6 |
4 files changed, 47 insertions, 4 deletions
diff --git a/tests/autodiff/custom-intrinsic-2.slang b/tests/autodiff/custom-intrinsic-2.slang new file mode 100644 index 000000000..0a2fd9c0b --- /dev/null +++ b/tests/autodiff/custom-intrinsic-2.slang @@ -0,0 +1,37 @@ +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; + +float f(float x) +{ + return x*x; +} + +[ForwardDerivativeOf(f)] +DifferentialPair<float> df(DifferentialPair<float> x) +{ + var primal = x.p * x.p; + var diff = 2 * x.p * x.d; + return DifferentialPair<float>(primal, diff); +} + +[ForwardDifferentiable] +float g(float x) +{ + return f(x); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + { + dpfloat dpa = dpfloat(3.0, 1.0); + + outputBuffer[0] = f(dpa.p); // Expect: 9.0 + outputBuffer[1] = __fwd_diff(g)(dpa).d; // Expect: 6.0 + } +} diff --git a/tests/autodiff/custom-intrinsic-2.slang.expected.txt b/tests/autodiff/custom-intrinsic-2.slang.expected.txt new file mode 100644 index 000000000..5483a4781 --- /dev/null +++ b/tests/autodiff/custom-intrinsic-2.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +9.000000 +6.000000 +0.000000 +0.000000 +0.000000 diff --git a/tests/autodiff/dstdlib-vector.slang b/tests/autodiff/dstdlib-vector.slang index 1a1bd0dfa..ba66f0756 100644 --- a/tests/autodiff/dstdlib-vector.slang +++ b/tests/autodiff/dstdlib-vector.slang @@ -10,7 +10,7 @@ typedef DifferentialPair<float> dpfloat; float f(float x) { float3 vx = float3(x, 2*x, 3*x); - float3 vexpx = dstd.exp(vx); + float3 vexpx = exp(vx); return vexpx.x + vexpx.y + vexpx.z; } diff --git a/tests/autodiff/dstdlib.slang b/tests/autodiff/dstdlib.slang index 247200511..b96cd3c51 100644 --- a/tests/autodiff/dstdlib.slang +++ b/tests/autodiff/dstdlib.slang @@ -9,19 +9,19 @@ typedef DifferentialPair<float> dpfloat; [ForwardDifferentiable] float f(float x) { - return dstd.exp(x); + return exp(x); } [ForwardDifferentiable] float g(float x) { - return dstd.sin(x); + return sin(x); } [ForwardDifferentiable] float h(float x) { - return dstd.cos(x); + return cos(x); } [numthreads(1, 1, 1)] |
