From 011d4281647e3a2a3cf0dbdda1fa65cc1b8ed881 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 10 Nov 2023 13:55:14 -0800 Subject: Cleanup builtin arithmetic interfaces. (#3317) * wip: clean up IArithmetic * wip. * Cleanup builtin arithmetic interfaces. * Fix. * Fixes. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He --- tests/autodiff/generic-constructor.slang | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/autodiff/generic-constructor.slang (limited to 'tests/autodiff') diff --git a/tests/autodiff/generic-constructor.slang b/tests/autodiff/generic-constructor.slang new file mode 100644 index 000000000..aad9824ec --- /dev/null +++ b/tests/autodiff/generic-constructor.slang @@ -0,0 +1,39 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +interface IFoo : IDifferentiable +{ + [Differentiable] + __init(Differential v); +} + +struct Impl : IFoo +{ + float x; + + [Differentiable] + __init(Differential v) + { + x = v.x; + } +} + +[Differentiable] +float test(float x) +{ + Impl.Differential v0 = { x }; + var v1 = Impl(v0); + return v1.x * v1.x; +} + +[numthreads(1,1,1)] +void computeMain(uint tid : SV_DispatchThreadID) +{ + var p = diffPair(3.0, 0.0); + bwd_diff(test)(p, 1.0); + outputBuffer[tid] = p.d; + // CHECK: 6.0 +} -- cgit v1.2.3