/// The number of launch configuration operands, placed at the leading
/// positions of the operand list.
static constexpr unsigned kNumConfigOperands = 6;
+
+private:
+ /// The name of the function attribute specifying the kernel to launch.
+ static StringRef getKernelAttrName() { return "kernel"; }
};
#define GET_OP_CLASSES
result->addOperands(
{gridSizeX, gridSizeY, gridSizeZ, blockSizeX, blockSizeY, blockSizeZ});
result->addOperands(kernelOperands);
- result->addAttribute("kernel", builder->getFunctionAttr(kernelFunc));
+ result->addAttribute(getKernelAttrName(),
+ builder->getFunctionAttr(kernelFunc));
}
void LaunchFuncOp::build(Builder *builder, OperationState *result,
}
Function *LaunchFuncOp::kernel() {
- return this->getAttr("kernel").dyn_cast<FunctionAttr>().getValue();
+ return this->getAttr(getKernelAttrName()).dyn_cast<FunctionAttr>().getValue();
}
unsigned LaunchFuncOp::getNumKernelOperands() {
}
LogicalResult LaunchFuncOp::verify() {
- auto kernelAttr = this->getAttr("kernel");
+ auto kernelAttr = this->getAttr(getKernelAttrName());
if (!kernelAttr) {
return emitOpError("attribute 'kernel' must be specified");
} else if (!kernelAttr.isa<FunctionAttr>()) {
return emitOpError("attribute 'kernel' must be a function");
}
Function *kernelFunc = this->kernel();
+ if (!kernelFunc->getAttrOfType<mlir::UnitAttr>(
+ GPUDialect::getKernelFuncAttrName())) {
+ return emitError("kernel function is missing the '" +
+ GPUDialect::getKernelFuncAttrName() + "' attribute");
+ }
unsigned numKernelFuncArgs = kernelFunc->getNumArguments();
if (getNumKernelOperands() != numKernelFuncArgs) {
return emitOpError("got " + Twine(getNumKernelOperands()) +
// -----
-func @kernel_1(%arg1 : !llvm<"float*">) attributes { nvvm.kernel: true } {
+func @kernel_1(%arg1 : !llvm<"float*">) {
+ return
+}
+
+func @launch_func_missing_kernel_attr(%sz : index, %arg : !llvm<"float*">) {
+ // expected-error@+1 {{kernel function is missing the 'gpu.kernel' attribute}}
+ "gpu.launch_func"(%sz, %sz, %sz, %sz, %sz, %sz, %arg)
+ {kernel: @kernel_1 : (!llvm<"float*">) -> ()}
+ : (index, index, index, index, index, index, !llvm<"float*">) -> ()
+ return
+}
+
+// -----
+
+func @kernel_1(%arg1 : !llvm<"float*">) attributes { gpu.kernel } {
return
}
// -----
-func @kernel_1(%arg1 : !llvm<"float*">) attributes { nvvm.kernel: true } {
+func @kernel_1(%arg1 : !llvm<"float*">) attributes { gpu.kernel } {
return
}
}
func @kernel_1(%arg0 : f32, %arg1 : memref<?xf32, 1>)
- attributes { nvvm.kernel: true } {
+ attributes { gpu.kernel } {
%tIdX = "gpu.thread_id"() {dimension: "x"} : () -> (index)
%tIdY = "gpu.thread_id"() {dimension: "y"} : () -> (index)
%tIdZ = "gpu.thread_id"() {dimension: "z"} : () -> (index)