yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
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 float.Differential dfloat; 10 11[ForwardDifferentiable] 12float f(float x) 13{ 14 return x; 15} 16 17dpfloat g_jvp_(dpfloat dpx) 18{ 19 return dpfloat(dpx.p, 2 * dpx.d); 20} 21 22[ForwardDerivative(g_jvp_)] 23float g(float x) 24{ 25 return x + x; 26} 27 28[ForwardDifferentiable] 29float h(float x, float y) 30{ 31 float m = x + y; 32 float n = x - y; 33 return m * n + 2 * x * y; 34} 35 36[ForwardDifferentiable] 37float j(float x, float y) 38{ 39 float m = x / y; 40 return m * y; 41} 42 43[numthreads(1, 1, 1)] 44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 45{ 46 { 47 dpfloat dpa = dpfloat(2.0, 1.0); 48 dpfloat dpb = dpfloat(1.5, 1.0); 49 50 outputBuffer[0] = __fwd_diff(f)(dpa).d; // Expect: 1 51 outputBuffer[1] = __fwd_diff(f)(dpfloat(dpa.p, 0.0)).d; // Expect: 0 52 outputBuffer[2] = __fwd_diff(g)(dpa).d; // Expect: 2 53 outputBuffer[3] = __fwd_diff(h)(dpa, dpb).d; // Expect: 8 54 outputBuffer[4] = __fwd_diff(j)(dpa, dpb).d; // Expect: 1 55 } 56}