-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AD] Add support for resolving custom derivatives where generic param…
…eters can't be automatically inferred (#5630) * [AD] Add support for resolving custom derivatives where generic parameters can't be automatically inferred * Fix failing tests * Update custom-derivative-generic.slang
- Loading branch information
1 parent
95125f2
commit 9913cfb
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type | ||
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type | ||
|
||
enum MyEnum { A, B, C }; | ||
|
||
[BackwardDerivative(mDiff)] | ||
float m<let M : MyEnum>(float x) | ||
{ | ||
switch (M) | ||
{ | ||
case MyEnum.A: | ||
return x * x; | ||
case MyEnum.B: | ||
return x; | ||
case MyEnum.C: | ||
return 3 * x; | ||
default: | ||
return 0; | ||
} | ||
} | ||
|
||
void mDiff<let M : MyEnum>(inout DifferentialPair<float> x, float dResult) | ||
{ | ||
switch (M) | ||
{ | ||
case MyEnum.A: | ||
updateDiff(x, 2 * dResult * x.p); | ||
break; | ||
case MyEnum.B: | ||
updateDiff(x, dResult); | ||
break; | ||
case MyEnum.C: | ||
updateDiff(x, 3 * dResult); | ||
break; | ||
default: | ||
updateDiff(x, 0); | ||
break; | ||
} | ||
} | ||
|
||
[Differentiable] | ||
float test(float x) | ||
{ | ||
return m<MyEnum.A>(x); | ||
} | ||
|
||
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer | ||
RWStructuredBuffer<float> outputBuffer; | ||
|
||
[numthreads(1, 1, 1)] | ||
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) | ||
{ | ||
var a = diffPair(3.0); | ||
__bwd_diff(test)(a, 1.0); | ||
outputBuffer[dispatchThreadID.x] = a.d; | ||
// CHECK: 6.0 | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters