[mlir][gpu] Fix logic error in D79508 computing number of private attributions.

Fix logic error in D79508. The old logic would make the first check in
`GPUFuncOp::verifyBody` always pass.
This commit is contained in:
Wen-Heng (Jack) Chung 2020-06-01 10:48:23 -05:00
parent a67949913a
commit 603b974cf7
4 changed files with 22 additions and 6 deletions

View File

@ -249,7 +249,7 @@ def GPU_GPUFuncOp : GPU_Op<"func", [HasParent<"GPUModuleOp">,
/// Returns the number of buffers located in the private memory.
unsigned getNumPrivateAttributions() {
return getOperation()->getNumOperands() - getType().getNumInputs() -
return getBody().front().getNumArguments() - getType().getNumInputs() -
getNumWorkgroupAttributions();
}

View File

@ -675,13 +675,10 @@ static LogicalResult verifyAttributions(Operation *op,
LogicalResult GPUFuncOp::verifyBody() {
unsigned numFuncArguments = getNumArguments();
unsigned numWorkgroupAttributions = getNumWorkgroupAttributions();
unsigned numPrivateAttributions = getNumPrivateAttributions();
unsigned numBlockArguments = front().getNumArguments();
if (numBlockArguments <
numFuncArguments + numWorkgroupAttributions + numPrivateAttributions)
if (numBlockArguments < numFuncArguments + numWorkgroupAttributions)
return emitOpError() << "expected at least "
<< numFuncArguments + numWorkgroupAttributions +
numPrivateAttributions
<< numFuncArguments + numWorkgroupAttributions
<< " arguments to body region";
ArrayRef<Type> funcArgTypes = getType().getInputs();

View File

@ -423,3 +423,15 @@ module {
}
}
}
// -----
module {
gpu.module @gpu_funcs {
// expected-error @+1 {{'gpu.func' op expected at least 5 arguments to body region}}
"gpu.func"() ( {
^bb0(%arg0: f32, %arg1: memref<?xf32>, %arg2: memref<5xf32, 3>, %arg3: memref<5xf32, 5>):
"gpu.return"() : () -> ()
} ) {gpu.kernel, sym_name = "kernel_1", type = (f32, memref<?xf32>) -> (), workgroup_attributions = 3: i64} : () -> ()
}
}

View File

@ -136,4 +136,11 @@ module attributes {gpu.container_module} {
}
}
gpu.module @explicit_attributions {
// CHECK-LABEL: gpu.func @kernel_1({{.*}}: f32, {{.*}}: memref<?xf32>) workgroup({{.*}}: memref<5xf32, 3>) private({{.*}}: memref<5xf32, 5>)
"gpu.func"() ( {
^bb0(%arg0: f32, %arg1: memref<?xf32>, %arg2: memref<5xf32, 3>, %arg3: memref<5xf32, 5>):
"gpu.return"() : () -> ()
} ) {gpu.kernel, sym_name = "kernel_1", type = (f32, memref<?xf32>) -> (), workgroup_attributions = 1: i64} : () -> ()
}
}