diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/generic-differential-synthesis.slang | 35 | ||||
| -rw-r--r-- | tests/autodiff/generic-differential-synthesis.slang.expected.txt | 5 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/autodiff/generic-differential-synthesis.slang b/tests/autodiff/generic-differential-synthesis.slang new file mode 100644 index 000000000..8c858b9b3 --- /dev/null +++ b/tests/autodiff/generic-differential-synthesis.slang @@ -0,0 +1,35 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +__generic<let C : int> +struct Foo : IDifferentiable +{ + float x[C]; +}; + +[Differentiable] +Foo<3> getFoo(float x) +{ + return { { x, x, x } }; +} + +[Differentiable] +float foobar(float x) +{ + int i = 3 * int(floor(x)); + Foo<3> foo = getFoo(x); + return foo.x[i] * foo.x[i]; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + { + float a = 0.5; + var d = fwd_diff(foobar)(diffPair(a, 1.0)).d; + outputBuffer[0] = d; + } +} diff --git a/tests/autodiff/generic-differential-synthesis.slang.expected.txt b/tests/autodiff/generic-differential-synthesis.slang.expected.txt new file mode 100644 index 000000000..97de29f1f --- /dev/null +++ b/tests/autodiff/generic-differential-synthesis.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +1.000000 +0.000000 +0.000000 +0.000000 |
