diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2024-10-28 15:47:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-28 15:47:58 -0400 |
| commit | b61be5e6fb7fe1c4ec8228cdf73f49f11e5a0ac9 (patch) | |
| tree | 0e392546b41a55d36a874f2a82110867e6dd422c /tests | |
| parent | 0557a199d2eb205bf133c8fc111cce3a19336fde (diff) | |
Assorted auto-diff enhancements for increased performance & more streamlined auto-diff results (#5394)
* Various AD enhancements
* Fix issue with pt-loop test
* Update pt-loop.slang
* More fixes for perf. Final minimal context test now passes.
* Fix issue with loop-elimination pass not running after dce
* Try fix wgpu test by removing select operator
* Disable wgpu
* Delete out.wgsl
* Remove comments
* Update slang-ir-util.cpp
* Fix header relative paths for slang-embed
* Disbale wgpu for a few other tests
* Better way of determining which params to ignore for side-effects
* Update slang-ir-dce.cpp
* Fix issue with circular reference from previous AD pass being left behind for the next AD pass
* Update slang-ir-dce.cpp
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/high-order-backward-diff-3.slang | 5 | ||||
| -rw-r--r-- | tests/autodiff/high-order-backward-diff-4.slang | 6 | ||||
| -rw-r--r-- | tests/autodiff/path-tracer/pt-loop.slang | 4 | ||||
| -rw-r--r-- | tests/autodiff/reverse-continue-loop.slang | 10 | ||||
| -rw-r--r-- | tests/autodiff/reverse-control-flow-3.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/reverse-loop-checkpoint-test.slang | 7 | ||||
| -rw-r--r-- | tests/autodiff/reverse-loop.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/reverse-nested-calls.slang | 4 | ||||
| -rw-r--r-- | tests/autodiff/test-minimal-context.slang | 76 |
9 files changed, 97 insertions, 19 deletions
diff --git a/tests/autodiff/high-order-backward-diff-3.slang b/tests/autodiff/high-order-backward-diff-3.slang index 100a9a1e0..1df6415fe 100644 --- a/tests/autodiff/high-order-backward-diff-3.slang +++ b/tests/autodiff/high-order-backward-diff-3.slang @@ -1,6 +1,7 @@ //TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-dx12 -compute -shaderobj -output-using-type //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; diff --git a/tests/autodiff/high-order-backward-diff-4.slang b/tests/autodiff/high-order-backward-diff-4.slang index 9ee9aa4c4..e1392c05f 100644 --- a/tests/autodiff/high-order-backward-diff-4.slang +++ b/tests/autodiff/high-order-backward-diff-4.slang @@ -1,6 +1,8 @@ //TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-dx12 -compute -shaderobj -output-using-type + //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; diff --git a/tests/autodiff/path-tracer/pt-loop.slang b/tests/autodiff/path-tracer/pt-loop.slang index ac8bf763d..85e1825ab 100644 --- a/tests/autodiff/path-tracer/pt-loop.slang +++ b/tests/autodiff/path-tracer/pt-loop.slang @@ -1,7 +1,7 @@ //Tests automatic synthesis of Differential type requirement. -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -Xslang -loop-inversion -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type -Xslang -loop-inversion +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; diff --git a/tests/autodiff/reverse-continue-loop.slang b/tests/autodiff/reverse-continue-loop.slang index 0b6e56f78..72f112d4c 100644 --- a/tests/autodiff/reverse-continue-loop.slang +++ b/tests/autodiff/reverse-continue-loop.slang @@ -1,7 +1,7 @@ -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -Xslang -dump-intermediates //TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj -//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates +//TEST:SIMPLE(filecheck=CHK):-target hlsl -stage compute -entry computeMain -report-checkpoint-intermediates //TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; @@ -9,14 +9,14 @@ RWStructuredBuffer<float> outputBuffer; typedef DifferentialPair<float> dpfloat; typedef float.Differential dfloat; -//CHK: note: checkpointing context of 24 bytes associated with function: 'test_loop_with_continue' +//CHK-DAG: note: checkpointing context of 24 bytes associated with function: 'test_loop_with_continue' [BackwardDifferentiable] float test_loop_with_continue(float y) { - //CHK: note: 20 bytes (FixedArray<float, 5> ) used to checkpoint the following item: + //CHK-DAG: note: 20 bytes (FixedArray<float, 5> ) used to checkpoint the following item: float t = y; - //CHK: note: 4 bytes (int32_t) used for a loop counter here: + //CHK-DAG: note: 4 bytes (int32_t) used for a loop counter here: for (int i = 0; i < 3; i++) { if (t > 4.0) diff --git a/tests/autodiff/reverse-control-flow-3.slang b/tests/autodiff/reverse-control-flow-3.slang index b4fa68e3a..c8c09d44f 100644 --- a/tests/autodiff/reverse-control-flow-3.slang +++ b/tests/autodiff/reverse-control-flow-3.slang @@ -1,5 +1,5 @@ //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 +//DISABLE_TEST:SIMPLE(filecheck=CHK):-target hlsl -stage compute -entry computeMain -report-checkpoint-intermediates //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer diff --git a/tests/autodiff/reverse-loop-checkpoint-test.slang b/tests/autodiff/reverse-loop-checkpoint-test.slang index 53a089b21..19316a786 100644 --- a/tests/autodiff/reverse-loop-checkpoint-test.slang +++ b/tests/autodiff/reverse-loop-checkpoint-test.slang @@ -1,7 +1,8 @@ -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-dx12 -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none -//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates -//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu +//DISABLE_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; diff --git a/tests/autodiff/reverse-loop.slang b/tests/autodiff/reverse-loop.slang index 2ba8535be..18b672860 100644 --- a/tests/autodiff/reverse-loop.slang +++ b/tests/autodiff/reverse-loop.slang @@ -1,7 +1,7 @@ //TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type //TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj -//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates +//DISABLE_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; diff --git a/tests/autodiff/reverse-nested-calls.slang b/tests/autodiff/reverse-nested-calls.slang index 3c1a52c21..1b59cc75d 100644 --- a/tests/autodiff/reverse-nested-calls.slang +++ b/tests/autodiff/reverse-nested-calls.slang @@ -1,7 +1,7 @@ //TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type //TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type //TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj -//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates +//DISABLE_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; @@ -16,11 +16,9 @@ float g(float y) return result * result; } -//CHK: note: checkpointing context of 4 bytes associated with function: 'f' [BackwardDifferentiable] float f(float x) { - //CHK: note: 4 bytes (float) used to checkpoint the following item: return 3.0f * g(2.0f * x); } diff --git a/tests/autodiff/test-minimal-context.slang b/tests/autodiff/test-minimal-context.slang new file mode 100644 index 000000000..c2a2b87ed --- /dev/null +++ b/tests/autodiff/test-minimal-context.slang @@ -0,0 +1,76 @@ +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none +//DISABLE_TEST:SIMPLE(filecheck=CTX):-target glsl -stage compute -entry computeMain -report-checkpoint-intermediates + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; +typedef float.Differential dfloat; + +[BackwardDerivative(bwd_load)] +float load(uint idx) +{ + return outputBuffer[idx]; +} + +void bwd_load(uint idx, float dOut) +{ + outputBuffer[idx + 2] += dOut; +} + +[BackwardDerivative(bwd_store)] +void store(uint idx, float a) +{ + outputBuffer[idx] = a; +} + +[ForceInline] +float inner_bwd_store(uint idx) +{ + return outputBuffer[idx + 2]; +} + +[ForceInline] +void bwd_store(uint idx, inout DifferentialPair<float> a) +{ + a = diffPair(a.p, inner_bwd_store(idx)); +} + +[BackwardDerivative(bwd_g)] +float g(float x) +{ + return load(1) * load(1); +} + +void bwd_g(inout DifferentialPair<float> x, float dOut) +{ + float y = load(1); + x = diffPair(x.p + 2 * y, x.d + 2 * y * dOut); + store(0, x.d); +} + +[BackwardDifferentiable] +float f(int p, float x) +{ + float y = g(x); + + store(0, y); + + return 0; +} + +// Check that there are no calls to primal_ctx_f in bwd_f. + +// CHECK: void s_bwd_f_{{[0-9]+}} +// CHECK-NOT: s_primal_ctx_f_{{[0-9]+}} +// CHECK: return + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + dpfloat dpa = dpfloat(2.0, 0.0); + + bwd_diff(f)(0, dpa, 1.0f); + outputBuffer[0] = dpa.d; // Expect: 1 +} +// CTX: note:
\ No newline at end of file |
