From b7d318f48db2cb83a41d665f1727ae93fc555124 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 28 Sep 2023 18:07:40 -0700 Subject: Support `constref` parameters passing. (#3249) * Support `constref` parameters passing. * Fix. * Fix. * Add test and diagnostic on mix use of __constref and no_diff. * check for [constref] on differentiable member method. --------- Co-authored-by: Yong He --- tests/autodiff/constref-param.slang | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/autodiff/constref-param.slang (limited to 'tests/autodiff/constref-param.slang') diff --git a/tests/autodiff/constref-param.slang b/tests/autodiff/constref-param.slang new file mode 100644 index 000000000..5bce8e304 --- /dev/null +++ b/tests/autodiff/constref-param.slang @@ -0,0 +1,41 @@ +//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(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cpu -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +struct NonDiff +{ + float a; +} + +[Differentiable] +float myFunc(__constref NonDiff fIn, float x, __constref no_diff float y) +{ + return x * fIn.a + y; +} + +// test that the ordering of no_diff and __constref doesn't matter. +[Differentiable] +float myFunc2(__constref NonDiff fIn, float x, no_diff __constref float y) +{ + return x * fIn.a + y; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + float a = 10.0; + NonDiff fIn = { a }; + DifferentialPair dpx = DifferentialPair(4.f, 1.f); + float rs = __fwd_diff(myFunc)(fIn, dpx, 1.0).d; + float rs2 = __fwd_diff(myFunc2)(fIn, dpx, 1.0).d; + + // CHECK: 10.0 + // CHECK: 10.0 + + outputBuffer[0] = rs; + outputBuffer[1] = rs2; +} -- cgit v1.2.3