summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2024-08-27 21:13:00 -0400
committerGitHub <noreply@github.com>2024-08-27 18:13:00 -0700
commit6bb32aa976494466bd6303f8ae6e348b297edb44 (patch)
tree54765fd5168e1d6590f403c6df04b30404ee6346 /tests
parenta9882c648c58e6f2821df11c7ee6ac77d9f09473 (diff)
Adds a warning for using `[PreferRecompute]` on methods that may contain side effects (#4707)
* Adds a warning for using prefer-recompute on methods that contain side effects * Rename `SideEffects` -> `SideEffectBehavior` --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/warn-on-prefer-recompute-side-effects.slang47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/autodiff/warn-on-prefer-recompute-side-effects.slang b/tests/autodiff/warn-on-prefer-recompute-side-effects.slang
new file mode 100644
index 000000000..38543e67f
--- /dev/null
+++ b/tests/autodiff/warn-on-prefer-recompute-side-effects.slang
@@ -0,0 +1,47 @@
+//TEST:SIMPLE(filecheck=CHECK): -target hlsl -line-directive-mode none
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+groupshared float s_shared;
+
+[BackwardDifferentiable]
+[PreferRecompute]
+float get_thread_5_value(float v, uint group_thread_id)
+{
+ if(group_thread_id == 5)
+ {
+ s_shared = detach(v);
+ // CHECK: tests/autodiff/warn-on-prefer-recompute-side-effects.slang(10): warning 42050: get_thread_5_value has [PreferRecompute] and may have side effects. side effects may execute multiple times. use [PreferRecompute(SideEffectBehavior.Allow)], or mark function with [NoSideEffect]
+ // CHECK: float get_thread_5_value(float v, uint group_thread_id)
+ // CHECK: ^~~~~~~~~~~~~~~~~~
+ }
+ GroupMemoryBarrierWithGroupSync();
+ return s_shared;
+}
+
+[BackwardDifferentiable]
+[PreferRecompute(SideEffectBehavior.Allow)] // Suppress warning here
+float get_thread_6_value(float v, uint group_thread_id)
+{
+ if (group_thread_id == 6)
+ {
+ s_shared = detach(v);
+ // CHECK-NOT: warning 42050
+
+ }
+ GroupMemoryBarrierWithGroupSync();
+ return s_shared;
+}
+
+[shader("compute")]
+[numthreads(128, 1, 1)]
+void computeMain(uint3 group_thread_id: SV_GroupThreadID, uint3 dispatch_thread_id: SV_DispatchThreadID)
+{
+ DifferentialPair<float> value = diffPair(3.f, 0.f);
+
+ bwd_diff(get_thread_5_value)(value, group_thread_id.x, 1.0f);
+ bwd_diff(get_thread_6_value)(value, group_thread_id.x, 1.0f);
+
+ outputBuffer[dispatch_thread_id.x] = value.d;
+} \ No newline at end of file