Skip to content

Commit cabb972

Browse files
[mlir][spirv] Mark several SPIR-V TOSA Ext Inst ops as NoMemoryEffects (llvm#191814)
Initially such ops were marked Pure wrongly since they could overflow or underflow the accumulator and result in undefined behavior. Signed-off-by: Davide Grohmann <davide.grohmann@arm.com>
1 parent 3fe0bdf commit cabb972

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTosaOps.td

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class SPIRV_TosaBoolElementwiseBinaryOp<string mnemonic, int opcode, list<Trait>
150150
}
151151

152152
class SPIRV_TosaConvolutionOp<string mnemonic, int opcode, list<Trait> traits = []> :
153-
SPIRV_TosaOpWithResult<mnemonic, opcode, !listconcat(traits, [Pure,
153+
SPIRV_TosaOpWithResult<mnemonic, opcode, !listconcat(traits, [NoMemoryEffect,
154154
TypeConstraintImplicationOn<"input", I8, "output", [I32]>,
155155
TypeConstraintImplicationOn<"input", I16, "output", [I64]>,
156156
TypeConstraintImplicationOn<"input", BF16, "output", [BF16]>,
@@ -273,7 +273,7 @@ def SPIRV_TosaArgMaxOp : SPIRV_TosaOpWithResult<"ArgMax", 0, [Pure,
273273
}
274274

275275

276-
def SPIRV_TosaAvgPool2DOp : SPIRV_TosaOpWithResult<"AvgPool2D", 1, [Pure,
276+
def SPIRV_TosaAvgPool2DOp : SPIRV_TosaOpWithResult<"AvgPool2D", 1, [NoMemoryEffect,
277277
TypeImpliesAccType<"input", I8, ["INT32"]>,
278278
TypeImpliesAccType<"input", I16, ["INT32"]>,
279279
TypeImpliesAccType<"input", F16, ["FP16", "FP32"]>,
@@ -287,7 +287,8 @@ def SPIRV_TosaAvgPool2DOp : SPIRV_TosaOpWithResult<"AvgPool2D", 1, [Pure,
287287
window of size given by <kernel size> is passed over the input tensor, with
288288
the mean value being placed in the output tensor. When calculating the
289289
average, only the number of valid input tensor values, but not padding, are
290-
used to calculate the divisor.
290+
used to calculate the divisor. The behaviour is undefined if the accumulated
291+
result overflows or underflows.
291292

292293
References:
293294
* https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_avg_pool2d
@@ -343,6 +344,8 @@ def SPIRV_TosaConv2DOp : SPIRV_TosaConvolutionOp<"Conv2D", 2> {
343344

344345
Input and weight have respective zero point values provided in input_zp and weight_zp.
345346

347+
The behaviour is undefined if the accumulated result overflows or underflows.
348+
346349
References:
347350
* https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_conv2d
348351
* https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_conv2d
@@ -396,6 +399,8 @@ def SPIRV_TosaConv3DOp : SPIRV_TosaConvolutionOp<"Conv3D", 3> {
396399

397400
Input and weight have respective zero point values provided in input_zp and weight_zp.
398401

402+
The behaviour is undefined if the accumulated result overflows or underflows.
403+
399404
References:
400405
* https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_conv3d
401406
* https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_conv3d
@@ -450,6 +455,8 @@ def SPIRV_TosaDepthwiseConv2DOp : SPIRV_TosaConvolutionOp<"DepthwiseConv2D", 4>
450455

451456
Input and weight have respective zero point values provided in input_zp and weight_zp.
452457

458+
The behaviour is undefined if the accumulated result overflows or underflows.
459+
453460
References:
454461
* https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_depthwise_conv2d
455462
* https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_depthwise_conv2d
@@ -546,7 +553,7 @@ def SPIRV_TosaFFT2DOp : SPIRV_TosaOpWithComplexResult<"FFT2D", 5, [Pure]> {
546553
}
547554

548555

549-
def SPIRV_TosaMatMulOp : SPIRV_TosaOpWithResult<"MatMul", 6, [Pure,
556+
def SPIRV_TosaMatMulOp : SPIRV_TosaOpWithResult<"MatMul", 6, [NoMemoryEffect,
550557
TypeConstraintImplicationOn<"A", I8, "output", [I32]>,
551558
TypeConstraintImplicationOn<"A", I16, "output", [I64]>,
552559
TypeConstraintImplicationOn<"A", BF16, "output", [F32]>,
@@ -557,8 +564,11 @@ def SPIRV_TosaMatMulOp : SPIRV_TosaOpWithResult<"MatMul", 6, [Pure,
557564

558565
let description = [{
559566
Performs two dimensional matrix multiplications.
567+
560568
A, B are the inputs with respective zero point values in A_zp, B_zp.
561569

570+
The behaviour is undefined if the accumulated result overflows or underflows.
571+
562572
References:
563573
* https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_matmul
564574
* https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_matmul
@@ -708,6 +718,8 @@ def SPIRV_TosaTransposeConv2DOp : SPIRV_TosaConvolutionOp<"TransposeConv2D", 9>
708718

709719
Input and weight have respective zero point values provided in input_zp and weight_zp.
710720

721+
The behaviour is undefined if the accumulated result overflows or underflows.
722+
711723
References:
712724
* https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_transpose_conv2d
713725
* https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_transpose_conv2d

0 commit comments

Comments
 (0)