diff options
| author | Yong He <yonghe@outlook.com> | 2023-05-30 21:15:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-30 21:15:55 -0700 |
| commit | 5c28677ff8bb1ab498954795ae3907f3b6c3b03f (patch) | |
| tree | 9056f65b0637a61700cd70c1af84d5b97b8c1b69 /tests | |
| parent | 5e1974e8cad3396a8c4bedfd63c1ad31b82ec8eb (diff) | |
Fix type checking & loop value hoisting (#2907)
* Fix type checking crash in language server.
* Fix loop var hoisting logic.
Fixes #2903.
* fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/reverse-loop-diff-only-3.slang | 74 | ||||
| -rw-r--r-- | tests/autodiff/reverse-loop-diff-only-3.slang.expected.txt | 6 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-loop-diff-only-3.slang b/tests/autodiff/reverse-loop-diff-only-3.slang new file mode 100644 index 000000000..e36b6c09c --- /dev/null +++ b/tests/autodiff/reverse-loop-diff-only-3.slang @@ -0,0 +1,74 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; +typedef float.Differential dfloat; + +// Test that compute does not have a context. +// CHECK-NOT: struct {{[a-zA-Z0-9_]*}}_compute_{{[a-zA-Z0-9_]*}} + +[BackwardDifferentiable] +[PreferRecompute] +float compute(float x, float y, out float k) +{ + k = y * 2; + return x * y; +} + +// Test that computeLoop compiles to just return 0. +// CHECK: float computeLoop{{[_0-9]*}}(float y{{[_0-9]*}}) +// CHECK-NOT: for{{.*}} +// CHECK: return 0 + +[BackwardDifferentiable] +[PreferRecompute] +float computeLoop(float y) +{ + float w = 0; + int i = 0; + [MaxIters(8)] + do + { + float k = float(0.f); + w += compute(i, y, k); + w += k * k; + i++; + } + while (i < 8); + + return w - detach(w); +} + +// Since computeLoop is recomputed, test_simple_loop should have nothing to store +// therefore we check that there is no intermediate context type generated for test_simple_loop. + +// CHECK-NOT: struct {{[a-zA-Z0-9_]*}}test_simple_loop{{[a-zA-Z0-9_]*}} +[BackwardDifferentiable] +float test_simple_loop(float y) +{ + float x = computeLoop(y); + return y + x; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + dpfloat dpa = dpfloat(1.0, 0.0); + + __bwd_diff(test_simple_loop)(dpa, 1.0f); + outputBuffer[0] = dpa.d; // Expect: 29.0 + } + + { + dpfloat dpa = dpfloat(0.4, 0.0); + + __bwd_diff(test_simple_loop)(dpa, 0.5f); + outputBuffer[1] = dpa.d; // Expect: 14.5 + } + + outputBuffer[2] = computeLoop(1.0); +} diff --git a/tests/autodiff/reverse-loop-diff-only-3.slang.expected.txt b/tests/autodiff/reverse-loop-diff-only-3.slang.expected.txt new file mode 100644 index 000000000..fedac0520 --- /dev/null +++ b/tests/autodiff/reverse-loop-diff-only-3.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +93.000000 +27.300001 +0.000000 +0.000000 +0.000000 |
