summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-diagnostic-defs.h2
-rw-r--r--source/slang/slang-ir-autodiff.cpp10
-rw-r--r--tests/autodiff/dont-warn-on-simple-prefer-recompute.slang26
-rw-r--r--tests/autodiff/warn-on-prefer-recompute-side-effects.slang2
4 files changed, 36 insertions, 4 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 3a1444117..9a14b71e4 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -790,7 +790,7 @@ DIAGNOSTIC(41904, Error, unableToAlignOf, "alignof could not be performed for ty
DIAGNOSTIC(42001, Error, invalidUseOfTorchTensorTypeInDeviceFunc, "invalid use of TorchTensor type in device/kernel functions. use `TensorView` instead.")
-DIAGNOSTIC(42050, Warning, potentialIssuesWithPreferRecomputeOnSideEffectMethod, "$0 has [PreferRecompute] and may have side effects. side effects may execute multiple times. use [PreferRecompute(SideEffectBehavior.Allow)], or mark function with [NoSideEffect]")
+DIAGNOSTIC(42050, Warning, potentialIssuesWithPreferRecomputeOnSideEffectMethod, "$0 has [PreferRecompute] and may have side effects. side effects may execute multiple times. use [PreferRecompute(SideEffectBehavior.Allow)], or mark function with [__NoSideEffect]")
DIAGNOSTIC(45001, Error, unresolvedSymbol, "unresolved external symbol '$0'.")
diff --git a/source/slang/slang-ir-autodiff.cpp b/source/slang/slang-ir-autodiff.cpp
index 6c729ea63..bed6a68e4 100644
--- a/source/slang/slang-ir-autodiff.cpp
+++ b/source/slang/slang-ir-autodiff.cpp
@@ -2416,9 +2416,15 @@ void checkAutodiffPatterns(
if (auto func = as<IRFunc>(inst))
{
if (func->sourceLoc.isValid() && // Don't diagnose for synthesized functions
- func->findDecoration<IRPreferRecomputeDecoration>() &&
- !func->findDecoration<IRNoSideEffectDecoration>())
+ func->findDecoration<IRPreferRecomputeDecoration>())
{
+ // If we don't have any side-effect behavior, we should warn (note: read-none is a stronger
+ // guarantee than no-side-effect)
+ //
+ if (func->findDecoration<IRNoSideEffectDecoration>() ||
+ func->findDecoration<IRReadNoneDecoration>())
+ continue;
+
auto preferRecomputeDecor = func->findDecoration<IRPreferRecomputeDecoration>();
auto sideEffectBehavior = as<IRIntLit>(preferRecomputeDecor->getOperand(0))->getValue();
diff --git a/tests/autodiff/dont-warn-on-simple-prefer-recompute.slang b/tests/autodiff/dont-warn-on-simple-prefer-recompute.slang
new file mode 100644
index 000000000..c1c4d7d70
--- /dev/null
+++ b/tests/autodiff/dont-warn-on-simple-prefer-recompute.slang
@@ -0,0 +1,26 @@
+//TEST:SIMPLE(filecheck=CHECK): -target hlsl -line-directive-mode none -stage compute -entry computeMain
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[BackwardDifferentiable]
+[PreferRecompute]
+float comp(float a, float b)
+{
+ // CHECK: standard error = {
+ // CHECK-NEXT: }
+ return a * b;
+}
+
+
+[shader("compute")]
+[numthreads(128, 1, 1)]
+void computeMain(uint3 group_thread_id: SV_GroupThreadID, uint3 dispatch_thread_id: SV_DispatchThreadID)
+{
+ DifferentialPair<float> value1 = diffPair(3.f, 0.f);
+ DifferentialPair<float> value2 = diffPair(3.f, 0.f);
+
+ bwd_diff(comp)(value1, value2, 1.f);
+
+ outputBuffer[dispatch_thread_id.x] = value1.d;
+} \ No newline at end of file
diff --git a/tests/autodiff/warn-on-prefer-recompute-side-effects.slang b/tests/autodiff/warn-on-prefer-recompute-side-effects.slang
index 38543e67f..b7dc8cf2a 100644
--- a/tests/autodiff/warn-on-prefer-recompute-side-effects.slang
+++ b/tests/autodiff/warn-on-prefer-recompute-side-effects.slang
@@ -12,7 +12,7 @@ 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: 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: ^~~~~~~~~~~~~~~~~~
}