yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Harsh Aggarwal (NVIDIA)Fix 7723 - Add autodiff tests (#7919)d10732742

master
887 B24 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9typedef DifferentialPair<float3> dpfloat3;
10
11[ForwardDifferentiable]
12float f(float x, float[3] y)
13{
14    return x * no_diff(outputBuffer[4]) + y[2] * x * no_diff(y[1]);
15}
16
17
18[numthreads(1, 1, 1)]
19void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
20{
21    var dpx = fwd_diff(f)(DifferentialPair<float>(1.0f, 1.0f), DifferentialPair<float[3]>( { 1.0f, 2.0f, 3.0f }, { 1.0f, 2.0f, 3.0f }));
22    outputBuffer[0] = dpx.p; // Expect: 6.0
23    outputBuffer[1] = dpx.d; // Expect: 12.0
24}