blob: c52d88b967a9884518bea2622465564b6cb4d9f5 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates
//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;
[BackwardDifferentiable]
bool doWork(float x, out float y)
{
bool retVal = false;
y = 0;
for (;;)
{
if (x == 0.0)
break;
bool exited = (x == 1.0);
y += x;
if (!exited)
{
if (x < 1.0)
{
float b = x * 2.0f;
y += b;
exited = true;
}
}
retVal = true;
break;
}
return retVal;
}
[BackwardDifferentiable]
bool doWork2(float x, out float y)
{
y = 0;
if (x == 0.0) return false;
[ForceUnroll]
for (int i = 0; i < 2; ++i)
{
if (x > 0.0)
{
y += x;
if (x == 1.0) break;
y += x;
}
else
{
y += x;
}
}
return true;
}
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
{
var dpx = diffPair(0.5f, 1.0f);
__bwd_diff(doWork)(dpx, 1.0f);
outputBuffer[0] = dpx.d;
}
{
var dpx = diffPair(0.5f, 0.0f);
__bwd_diff(doWork2)(dpx, 1.0);
outputBuffer[1] = dpx.d;
}
}
//CHK: (0): note: no checkpoint contexts to report
|