summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-03-24 04:33:51 -0700
committerGitHub <noreply@github.com>2023-03-24 04:33:51 -0700
commit03c10833beb331e234554808c2a80d3cadecc7c0 (patch)
treeb135201bfb1128409739405ca508a01922a97333 /tests
parent56a84a06488afb817f79fbd99e8b470bd587ccd1 (diff)
Fix nested bwdContextType lowering. (#2731)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/cuda-kernel-export-2.slang48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/autodiff/cuda-kernel-export-2.slang b/tests/autodiff/cuda-kernel-export-2.slang
new file mode 100644
index 000000000..9cbb4e881
--- /dev/null
+++ b/tests/autodiff/cuda-kernel-export-2.slang
@@ -0,0 +1,48 @@
+//DISABLE_TEST:SIMPLE: -target cuda -line-directive-mode none
+
+// Verify that we can output a cuda device function with [CudaDeviceExport].
+// Disabled until we have FileCheck.
+
+
+//////////////////////////////////////////////////////////////////////////
+// Lambda GGX
+//////////////////////////////////////////////////////////////////////////
+
+[CudaDeviceExport]
+[BackwardDifferentiable]
+float lambdaGGX(const float alphaSqr, const float cosTheta)
+{
+ const float SPECULAR_EPSILON = 1e-4f;
+ float _cosTheta = clamp(cosTheta, SPECULAR_EPSILON, 1.0f - SPECULAR_EPSILON);
+ float cosThetaSqr = _cosTheta * _cosTheta;
+ float tanThetaSqr = (1.0 - cosThetaSqr) / cosThetaSqr;
+ return 0.5f * (sqrt(1.0f + alphaSqr * tanThetaSqr) - 1.0f);
+}
+
+[CudaDeviceExport]
+void lambdaGGX_bwd(inout DifferentialPair<float> alphaSqr, inout DifferentialPair<float> cosTheta, const float d_out)
+{
+ __bwd_diff(lambdaGGX)(alphaSqr, cosTheta, d_out);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Masking Smith
+//////////////////////////////////////////////////////////////////////////
+
+[CudaDeviceExport]
+[BackwardDifferentiable]
+float maskingSmithGGXCorrelated(const float alphaSqr, const float cosThetaI, const float cosThetaO)
+{
+ float lambdaI = lambdaGGX(alphaSqr, cosThetaI);
+ float lambdaO = lambdaGGX(alphaSqr, cosThetaO);
+ return 1.0f / (1.0f + lambdaI + lambdaO);
+}
+
+[CudaDeviceExport]
+void maskingSmithGGXCorrelated_bwd(inout DifferentialPair<float> alphaSqr,
+ inout DifferentialPair<float> cosThetaI,
+ inout DifferentialPair<float> cosThetaO,
+ const float d_out)
+{
+ __bwd_diff(maskingSmithGGXCorrelated)(alphaSqr, cosThetaI, cosThetaO, d_out);
+}