[flang-commits] [flang] 834d001 - [flang][cuda] Relax the verifier for cuf.register_kernel op (#112585)
via flang-commits
flang-commits at lists.llvm.org
Thu Oct 17 08:30:17 PDT 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-10-17T08:30:13-07:00
New Revision: 834d001e10912c815fa7af14422f60c28162f8d8
URL: https://github.com/llvm/llvm-project/commit/834d001e10912c815fa7af14422f60c28162f8d8
DIFF: https://github.com/llvm/llvm-project/commit/834d001e10912c815fa7af14422f60c28162f8d8.diff
LOG: [flang][cuda] Relax the verifier for cuf.register_kernel op (#112585)
Relax the verifier since the `gpu.func` might be converted to
`llvm.func` before `cuf.register_kernel` is converted.
Added:
Modified:
flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
flang/test/Fir/cuf-invalid.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp b/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
index 9e3bbd1f9cbee9..0b03e070a0076e 100644
--- a/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
+++ b/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
@@ -16,6 +16,7 @@
#include "flang/Optimizer/Dialect/FIRAttr.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinOps.h"
@@ -276,18 +277,26 @@ mlir::LogicalResult cuf::RegisterKernelOp::verify() {
mlir::SymbolTable symTab(mod);
auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(getKernelModuleName());
- if (!gpuMod)
+ if (!gpuMod) {
+ // If already a gpu.binary then stop the check here.
+ if (symTab.lookup<mlir::gpu::BinaryOp>(getKernelModuleName()))
+ return mlir::success();
return emitOpError("gpu module not found");
+ }
mlir::SymbolTable gpuSymTab(gpuMod);
- auto func = gpuSymTab.lookup<mlir::gpu::GPUFuncOp>(getKernelName());
- if (!func)
- return emitOpError("device function not found");
-
- if (!func.isKernel())
- return emitOpError("only kernel gpu.func can be registered");
-
- return mlir::success();
+ if (auto func = gpuSymTab.lookup<mlir::gpu::GPUFuncOp>(getKernelName())) {
+ if (!func.isKernel())
+ return emitOpError("only kernel gpu.func can be registered");
+ return mlir::success();
+ } else if (auto func =
+ gpuSymTab.lookup<mlir::LLVM::LLVMFuncOp>(getKernelName())) {
+ if (!func->getAttrOfType<mlir::UnitAttr>(
+ mlir::gpu::GPUDialect::getKernelFuncAttrName()))
+ return emitOpError("only gpu.kernel llvm.func can be registered");
+ return mlir::success();
+ }
+ return emitOpError("device function not found");
}
// Tablegen operators
diff --git a/flang/test/Fir/cuf-invalid.fir b/flang/test/Fir/cuf-invalid.fir
index a5747b8ee4a3b3..8a1eb48576832c 100644
--- a/flang/test/Fir/cuf-invalid.fir
+++ b/flang/test/Fir/cuf-invalid.fir
@@ -175,3 +175,18 @@ module attributes {gpu.container_module} {
llvm.return
}
}
+
+// -----
+
+module attributes {gpu.container_module} {
+ gpu.module @cuda_device_mod {
+ llvm.func @_QPsub_device1() {
+ llvm.return
+ }
+ }
+ llvm.func internal @__cudaFortranConstructor() {
+ // expected-error at +1{{'cuf.register_kernel' op only gpu.kernel llvm.func can be registered}}
+ cuf.register_kernel @cuda_device_mod::@_QPsub_device1
+ llvm.return
+ }
+}
More information about the flang-commits
mailing list