yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -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 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9 10[ForwardDifferentiable] 11float f(float x) 12{ 13 float3 vx = float3(x, 2*x, 3*x); 14 float3 vexpx = exp(vx); 15 return vexpx.x + vexpx.y + vexpx.z; 16} 17 18[numthreads(1, 1, 1)] 19void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 20{ 21 { 22 dpfloat dpa = dpfloat(2.0, 1.0); 23 24 outputBuffer[0] = f(dpa.p); // Expect: 465.415999 25 outputBuffer[1] = __fwd_diff(f)(dpa).d; // Expect: 1326.871736 26 } 27}