blob: 4782b4297ff52df4ea02e5561403e0112f38d9b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//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
interface IFoo : IDifferentiable
{
float myFunc();
}
struct Bar: IDifferentiable
{
float y;
}
struct Foo : IFoo
{
typealias Differential = Bar;
[DerivativeMember(Differential.y)]
float x;
[BackwardDifferentiable]
float myFunc()
{
return x * x;
};
}
//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=g_output
RWStructuredBuffer<float> g_output;
[BackwardDifferentiable]
float wrapper(Foo f)
{
return f.myFunc();
}
[shader("compute")]
void computeMain(uint3 thread_id : SV_DispatchThreadID)
{
var di = diffPair(Foo(1.0f), Bar(0.0f));
bwd_diff(wrapper)(di, 1.0f);
// CHECK: 2.0
g_output[0] = di.d.y;
}
|