summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2022-06-30 19:24:24 -0400
committerGitHub <noreply@github.com>2022-06-30 19:24:24 -0400
commit77af111867eb72f26b460c5925be47aa22c71556 (patch)
treeb516734ccec92f01eaa07a7844b3862b3c5ab628 /tests
parent2c09275388d4c88ea26bf709132b8be4a9e342bc (diff)
Added `[__custom_jvp(func)]` attribute, and modified the derivative pass to only process referenced functions. (#2309)
* Added JVPTranscriber to handle differentiation of load, store, var, param and return instructions, as well as conversion of data and function types * Changed class names to be more in line with convention. Added correct type checking for __jvp() and verified that simple calls with only loads and stores are processed correctly * Added logic to differentiate basic arithmetic and literals inside IRConstruct and fixed the way parameters are differentiated * Replaced some SLANG_UNEXPECTED macro uses with diagnostics instead * Added work-list-based on-demand generation of derivative functions * Fixed up a couple of TODOs * Added attribute [__custom_jvp(f)] to assign a custom derivative function to a declaration * Added a test for CustomJVPAttribute on a redeclaration of an imported function * Moving arithmetic test to new folder * Moving arithmetic test to new folder (2) * Added missing test module * Fixed a minor note Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/arithmetic-jvp.slang (renamed from tests/ir/derivative-op-ir-test.slang)8
-rw-r--r--tests/autodiff/arithmetic-jvp.slang.expected.txt (renamed from tests/ir/derivative-op-ir-test.slang.expected.txt)0
-rw-r--r--tests/autodiff/redecl-custom-jvp.slang28
-rw-r--r--tests/autodiff/redecl-custom-jvp.slang.expected.txt5
-rw-r--r--tests/autodiff/test-intrinsics.slang6
5 files changed, 46 insertions, 1 deletions
diff --git a/tests/ir/derivative-op-ir-test.slang b/tests/autodiff/arithmetic-jvp.slang
index 7addccdc2..8632aa332 100644
--- a/tests/ir/derivative-op-ir-test.slang
+++ b/tests/autodiff/arithmetic-jvp.slang
@@ -9,7 +9,13 @@ __differentiate_jvp float f(float x)
return x;
}
-__differentiate_jvp float g(float x)
+float g_jvp_(float x, float dx)
+{
+ return 2 * dx;
+}
+
+[__custom_jvp(g_jvp_)]
+float g(float x)
{
return x + x;
}
diff --git a/tests/ir/derivative-op-ir-test.slang.expected.txt b/tests/autodiff/arithmetic-jvp.slang.expected.txt
index 0545c08a1..0545c08a1 100644
--- a/tests/ir/derivative-op-ir-test.slang.expected.txt
+++ b/tests/autodiff/arithmetic-jvp.slang.expected.txt
diff --git a/tests/autodiff/redecl-custom-jvp.slang b/tests/autodiff/redecl-custom-jvp.slang
new file mode 100644
index 000000000..2bc7cd582
--- /dev/null
+++ b/tests/autodiff/redecl-custom-jvp.slang
@@ -0,0 +1,28 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+import test_intrinsics;
+
+float my_pow_jvp(float x, float n, float dx, float dn)
+{
+ return dx * n * pow(x, n-1) + dn * pow(x, n) * log(x);
+}
+
+[__custom_jvp(my_pow_jvp)]
+float _pow(float, float);
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ {
+ float a = 5.0;
+ float n = 2;
+ float da = 1.0;
+ float dn = 0;
+
+ outputBuffer[0] = __jvp(_pow)(a, n, da, dn); // Expect: 10.0
+ outputBuffer[1] = __jvp(_pow)(a, n, 0.0, 1.0); // Expect: 40.23595
+ }
+}
diff --git a/tests/autodiff/redecl-custom-jvp.slang.expected.txt b/tests/autodiff/redecl-custom-jvp.slang.expected.txt
new file mode 100644
index 000000000..965f2cb48
--- /dev/null
+++ b/tests/autodiff/redecl-custom-jvp.slang.expected.txt
@@ -0,0 +1,5 @@
+type: float
+10.0
+40.23595
+0.0
+0.0 \ No newline at end of file
diff --git a/tests/autodiff/test-intrinsics.slang b/tests/autodiff/test-intrinsics.slang
new file mode 100644
index 000000000..3fa53e85a
--- /dev/null
+++ b/tests/autodiff/test-intrinsics.slang
@@ -0,0 +1,6 @@
+//TEST_IGNORE_FILE:
+
+float pow_(float x, float n)
+{
+ return pow(x, n);
+}