Skip to content

Conversation

@clementval
Copy link
Contributor

The operation will be used in the CUF constructor to register the kernel functions. This allow to delay this until codegen when the gpu.binary will be available.

The operation will be used in the CUF constructor to register
the kernel functions. This allow to delay this until codegen when
the gpu.binary will be available.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Oct 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2024

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

The operation will be used in the CUF constructor to register the kernel functions. This allow to delay this until codegen when the gpu.binary will be available.


Full diff: https://github.com/llvm/llvm-project/pull/112268.diff

5 Files Affected:

  • (modified) flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td (+19)
  • (modified) flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp (+37)
  • (added) flang/test/Fir/CUDA/cuda-register-func.fir (+20)
  • (modified) flang/test/Fir/cuf-invalid.fir (+50)
  • (modified) flang/tools/fir-opt/fir-opt.cpp (+1)
diff --git a/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td b/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td
index f643674f1d5d6b..98d1ef529738c7 100644
--- a/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td
+++ b/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td
@@ -288,4 +288,23 @@ def cuf_KernelOp : cuf_Op<"kernel", [AttrSizedOperandSegments,
   let hasVerifier = 1;
 }
 
+def cuf_RegisterKernelOp : cuf_Op<"register_kernel", []> {
+  let summary = "Register a CUDA kernel";
+
+  let arguments = (ins
+    SymbolRefAttr:$name
+  );
+
+  let assemblyFormat = [{
+    $name attr-dict
+  }];
+
+  let hasVerifier = 1;
+
+  let extraClassDeclaration = [{
+    mlir::StringAttr getKernelName();
+    mlir::StringAttr getKernelModuleName();
+  }];
+}
+
 #endif // FORTRAN_DIALECT_CUF_CUF_OPS
diff --git a/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp b/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
index 7fb2dcf4af115c..9e3bbd1f9cbee9 100644
--- a/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
+++ b/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp
@@ -15,6 +15,7 @@
 #include "flang/Optimizer/Dialect/CUF/CUFDialect.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/BuiltinOps.h"
@@ -253,6 +254,42 @@ llvm::LogicalResult cuf::KernelOp::verify() {
   return mlir::success();
 }
 
+//===----------------------------------------------------------------------===//
+// RegisterKernelOp
+//===----------------------------------------------------------------------===//
+
+mlir::StringAttr cuf::RegisterKernelOp::getKernelModuleName() {
+  return getName().getRootReference();
+}
+
+mlir::StringAttr cuf::RegisterKernelOp::getKernelName() {
+  return getName().getLeafReference();
+}
+
+mlir::LogicalResult cuf::RegisterKernelOp::verify() {
+  if (getKernelName() == getKernelModuleName())
+    return emitOpError("expect a module and a kernel name");
+
+  auto mod = getOperation()->getParentOfType<mlir::ModuleOp>();
+  if (!mod)
+    return emitOpError("expect to be in a module");
+
+  mlir::SymbolTable symTab(mod);
+  auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(getKernelModuleName());
+  if (!gpuMod)
+    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();
+}
+
 // Tablegen operators
 
 #define GET_OP_CLASSES
diff --git a/flang/test/Fir/CUDA/cuda-register-func.fir b/flang/test/Fir/CUDA/cuda-register-func.fir
new file mode 100644
index 00000000000000..a428f68eb3bf42
--- /dev/null
+++ b/flang/test/Fir/CUDA/cuda-register-func.fir
@@ -0,0 +1,20 @@
+// RUN: fir-opt %s | FileCheck %s
+
+module attributes {gpu.container_module} {
+  gpu.module @cuda_device_mod {
+    gpu.func @_QPsub_device1() kernel {
+      gpu.return
+    }
+    gpu.func @_QPsub_device2(%arg0: !fir.ref<f32>) kernel {
+      gpu.return
+    }
+  }
+  llvm.func internal @__cudaFortranConstructor() {
+    cuf.register_kernel @cuda_device_mod::@_QPsub_device1
+    cuf.register_kernel @cuda_device_mod::@_QPsub_device2
+    llvm.return
+  }
+}
+
+// CHECK: cuf.register_kernel @cuda_device_mod::@_QPsub_device1
+// CHECK: cuf.register_kernel @cuda_device_mod::@_QPsub_device2
diff --git a/flang/test/Fir/cuf-invalid.fir b/flang/test/Fir/cuf-invalid.fir
index e9aeaa281e2a85..a5747b8ee4a3b3 100644
--- a/flang/test/Fir/cuf-invalid.fir
+++ b/flang/test/Fir/cuf-invalid.fir
@@ -125,3 +125,53 @@ func.func @_QPsub1(%arg0: !fir.ref<!fir.array<?xf32>> {cuf.data_attr = #cuf.cuda
   cuf.data_transfer %20#0 to %11#0, %19 : !fir.shape<1> {transfer_kind = #cuf.cuda_transfer<host_device>} : !fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>
   return
 }
+
+// -----
+
+module attributes {gpu.container_module} {
+  gpu.module @cuda_device_mod {
+    gpu.func @_QPsub_device1() {
+      gpu.return
+    }
+  }
+  llvm.func internal @__cudaFortranConstructor() {
+    // expected-error@+1{{'cuf.register_kernel' op only kernel gpu.func can be registered}}
+    cuf.register_kernel @cuda_device_mod::@_QPsub_device1
+    llvm.return
+  }
+}
+
+// -----
+
+module attributes {gpu.container_module} {
+  gpu.module @cuda_device_mod {
+    gpu.func @_QPsub_device1() {
+      gpu.return
+    }
+  }
+  llvm.func internal @__cudaFortranConstructor() {
+    // expected-error@+1{{'cuf.register_kernel' op device function not found}}
+    cuf.register_kernel @cuda_device_mod::@_QPsub_device2
+    llvm.return
+  }
+}
+
+// -----
+
+module attributes {gpu.container_module} {
+  llvm.func internal @__cudaFortranConstructor() {
+    // expected-error@+1{{'cuf.register_kernel' op gpu module not found}}
+    cuf.register_kernel @cuda_device_mod::@_QPsub_device1
+    llvm.return
+  }
+}
+
+// -----
+
+module attributes {gpu.container_module} {
+  llvm.func internal @__cudaFortranConstructor() {
+    // expected-error@+1{{'cuf.register_kernel' op expect a module and a kernel name}}
+    cuf.register_kernel @_QPsub_device1
+    llvm.return
+  }
+}
diff --git a/flang/tools/fir-opt/fir-opt.cpp b/flang/tools/fir-opt/fir-opt.cpp
index f75fba27c68f08..84a74770cf0303 100644
--- a/flang/tools/fir-opt/fir-opt.cpp
+++ b/flang/tools/fir-opt/fir-opt.cpp
@@ -42,6 +42,7 @@ int main(int argc, char **argv) {
 #endif
   DialectRegistry registry;
   fir::support::registerDialects(registry);
+  registry.insert<mlir::gpu::GPUDialect>();
   fir::support::addFIRExtensions(registry);
   return failed(MlirOptMain(argc, argv, "FIR modular optimizer driver\n",
       registry));

Copy link
Contributor

@Renaud-K Renaud-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@clementval clementval merged commit cbe76a2 into llvm:main Oct 15, 2024
7 checks passed
@clementval clementval deleted the cuf_register_op branch October 15, 2024 03:57
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 15, 2024

LLVM Buildbot has detected a new failure on builder flang-aarch64-libcxx running on linaro-flang-aarch64-libcxx while building flang at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/8418

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
83.240 [167/12/7052] Creating library symlink lib/libFortranSemantics.so
83.383 [162/16/7053] Linking CXX executable tools/flang/unittests/Evaluate/integer.test
83.384 [162/15/7054] Linking CXX executable tools/flang/unittests/Evaluate/logical.test
83.391 [162/14/7055] Linking CXX executable tools/flang/unittests/Evaluate/real.test
83.530 [162/13/7056] Linking CXX executable tools/flang/unittests/Evaluate/folding.test
83.585 [162/12/7057] Linking CXX executable tools/flang/unittests/Evaluate/expression.test
85.714 [162/11/7058] Building CXX object tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFDialect.cpp.o
87.478 [162/10/7059] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CufImplicitDeviceGlobal.cpp.o
88.562 [162/9/7060] Building CXX object tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o
88.719 [161/9/7061] Linking CXX shared library lib/libCUFDialect.so.20.0git
FAILED: lib/libCUFDialect.so.20.0git 
: && /usr/local/bin/c++ -fPIC -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG  -stdlib=libc++ -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/./lib  -Wl,--gc-sections -shared -Wl,-soname,libCUFDialect.so.20.0git -o lib/libCUFDialect.so.20.0git tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFDialect.cpp.o tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib:/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/lib:"  lib/libFIRDialect.so.20.0git  lib/libFIRDialectSupport.so.20.0git  lib/libCUFAttrs.so.20.0git  lib/libLLVMAsmPrinter.so.20.0git  lib/libMLIRTargetLLVMIRExport.so.20.0git  lib/libMLIRDLTIDialect.so.20.0git  lib/libMLIRLLVMIRTransforms.so.20.0git  lib/libMLIRFuncDialect.so.20.0git  lib/libMLIRTransforms.so.20.0git  lib/libMLIRRuntimeVerifiableOpInterface.so.20.0git  lib/libMLIRNVVMDialect.so.20.0git  lib/libMLIRTranslateLib.so.20.0git  lib/libMLIRParser.so.20.0git  lib/libMLIRBytecodeReader.so.20.0git  lib/libMLIRAsmParser.so.20.0git  lib/libMLIRTransformUtils.so.20.0git  lib/libMLIRSubsetOpInterface.so.20.0git  lib/libMLIRValueBoundsOpInterface.so.20.0git  lib/libMLIRDestinationStyleOpInterface.so.20.0git  lib/libMLIRRewrite.so.20.0git  lib/libMLIRRewritePDL.so.20.0git  lib/libMLIRPDLToPDLInterp.so.20.0git  lib/libMLIRPass.so.20.0git  lib/libMLIRAnalysis.so.20.0git  lib/libMLIRLoopLikeInterface.so.20.0git  lib/libMLIRInferIntRangeInterface.so.20.0git  lib/libMLIRPresburger.so.20.0git  lib/libMLIRViewLikeInterface.so.20.0git  lib/libMLIRPDLInterpDialect.so.20.0git  lib/libMLIRPDLDialect.so.20.0git  lib/libLLVMFrontendOpenMP.so.20.0git  lib/libLLVMTransformUtils.so.20.0git  lib/libMLIRLLVMDialect.so.20.0git  lib/libMLIRDataLayoutInterfaces.so.20.0git  lib/libMLIRCallInterfaces.so.20.0git  lib/libMLIRControlFlowInterfaces.so.20.0git  lib/libMLIRFunctionInterfaces.so.20.0git  lib/libMLIRInferTypeOpInterface.so.20.0git  lib/libMLIRMemorySlotInterfaces.so.20.0git  lib/libMLIRSideEffectInterfaces.so.20.0git  lib/libMLIRIR.so.20.0git  lib/libMLIRSupport.so.20.0git  lib/libLLVMBitWriter.so.20.0git  lib/libLLVMAsmParser.so.20.0git  lib/libLLVMBitReader.so.20.0git  lib/libLLVMCore.so.20.0git  lib/libLLVMRemarks.so.20.0git  lib/libLLVMBinaryFormat.so.20.0git  lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/lib && :
/usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o: in function `llvm::DefaultDoCastIfPossible<mlir::gpu::GPUModuleOp, mlir::Operation*, llvm::CastInfo<mlir::gpu::GPUModuleOp, mlir::Operation*, void> >::doCastIfPossible(mlir::Operation*)':
CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x24): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUModuleOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x28): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUModuleOp, void>::id'
/usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o: in function `llvm::DefaultDoCastIfPossible<mlir::gpu::GPUFuncOp, mlir::Operation*, llvm::CastInfo<mlir::gpu::GPUFuncOp, mlir::Operation*, void> >::doCastIfPossible(mlir::Operation*)':
CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x24): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUFuncOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x28): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUFuncOp, void>::id'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
93.279 [161/8/7062] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFAddConstructor.cpp.o
95.667 [161/7/7063] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CufOpConversion.cpp.o
98.962 [161/6/7064] Building CXX object tools/flang/lib/Optimizer/Builder/CMakeFiles/FIRBuilder.dir/FIRBuilder.cpp.o
159.523 [161/5/7065] Building CXX object tools/flang/tools/fir-opt/CMakeFiles/fir-opt.dir/fir-opt.cpp.o
190.893 [161/4/7066] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Allocatable.cpp.o
206.072 [161/3/7067] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertVariable.cpp.o
238.392 [161/2/7068] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertCall.cpp.o
354.255 [161/1/7069] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Bridge.cpp.o
ninja: build stopped: subcommand failed.

clementval added a commit that referenced this pull request Oct 15, 2024
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 15, 2024

LLVM Buildbot has detected a new failure on builder flang-aarch64-latest-gcc running on linaro-flang-aarch64-latest-gcc while building flang at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/130/builds/4881

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
112.621 [580/10/6657] Building CXX object tools/llvm-cvtres/CMakeFiles/llvm-cvtres.dir/llvm-cvtres.cpp.o
114.298 [580/9/6658] Building CXX object tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o

114.661 [580/8/6659] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFAddConstructor.cpp.o
114.805 [574/13/6660] Building CXX object tools/llvm-debuginfo-analyzer/CMakeFiles/llvm-debuginfo-analyzer.dir/llvm-debuginfo-analyzer.cpp.o
114.971 [574/12/6661] Linking CXX executable bin/llvm-cxxfilt
115.011 [574/11/6662] Linking CXX executable bin/llvm-cxxmap
115.031 [574/10/6663] Linking CXX executable bin/llvm-cxxdump
115.048 [574/9/6664] Linking CXX executable bin/llvm-cvtres
115.156 [574/8/6665] Linking CXX shared library lib/libCUFDialect.so.20.0git
FAILED: lib/libCUFDialect.so.20.0git 
: && /usr/local/bin/c++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -O3 -DNDEBUG -fno-semantic-interposition  -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/./lib  -Wl,--gc-sections -shared -Wl,-soname,libCUFDialect.so.20.0git -o lib/libCUFDialect.so.20.0git tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFDialect.cpp.o tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib:/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/lib:"  lib/libFIRDialect.so.20.0git  lib/libFIRDialectSupport.so.20.0git  lib/libCUFAttrs.so.20.0git  lib/libLLVMAsmPrinter.so.20.0git  lib/libMLIRTargetLLVMIRExport.so.20.0git  lib/libMLIRDLTIDialect.so.20.0git  lib/libMLIRLLVMIRTransforms.so.20.0git  lib/libMLIRFuncDialect.so.20.0git  lib/libMLIRTransforms.so.20.0git  lib/libMLIRRuntimeVerifiableOpInterface.so.20.0git  lib/libMLIRNVVMDialect.so.20.0git  lib/libMLIRTranslateLib.so.20.0git  lib/libMLIRParser.so.20.0git  lib/libMLIRBytecodeReader.so.20.0git  lib/libMLIRAsmParser.so.20.0git  lib/libMLIRTransformUtils.so.20.0git  lib/libMLIRSubsetOpInterface.so.20.0git  lib/libMLIRValueBoundsOpInterface.so.20.0git  lib/libMLIRDestinationStyleOpInterface.so.20.0git  lib/libMLIRRewrite.so.20.0git  lib/libMLIRRewritePDL.so.20.0git  lib/libMLIRPDLToPDLInterp.so.20.0git  lib/libMLIRPass.so.20.0git  lib/libMLIRAnalysis.so.20.0git  lib/libMLIRLoopLikeInterface.so.20.0git  lib/libMLIRInferIntRangeInterface.so.20.0git  lib/libMLIRPresburger.so.20.0git  lib/libMLIRViewLikeInterface.so.20.0git  lib/libMLIRPDLInterpDialect.so.20.0git  lib/libMLIRPDLDialect.so.20.0git  lib/libLLVMFrontendOpenMP.so.20.0git  lib/libLLVMTransformUtils.so.20.0git  lib/libMLIRLLVMDialect.so.20.0git  lib/libMLIRDataLayoutInterfaces.so.20.0git  lib/libMLIRCallInterfaces.so.20.0git  lib/libMLIRControlFlowInterfaces.so.20.0git  lib/libMLIRFunctionInterfaces.so.20.0git  lib/libMLIRInferTypeOpInterface.so.20.0git  lib/libMLIRMemorySlotInterfaces.so.20.0git  lib/libMLIRSideEffectInterfaces.so.20.0git  lib/libMLIRIR.so.20.0git  lib/libMLIRSupport.so.20.0git  lib/libLLVMBitWriter.so.20.0git  lib/libLLVMAsmParser.so.20.0git  lib/libLLVMBitReader.so.20.0git  lib/libLLVMCore.so.20.0git  lib/libLLVMRemarks.so.20.0git  lib/libLLVMBinaryFormat.so.20.0git  lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/lib && :
/usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o: in function `cuf::RegisterKernelOp::verify() [clone .localalias]':
CUFOps.cpp:(.text._ZN3cuf16RegisterKernelOp6verifyEv+0x114): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUModuleOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN3cuf16RegisterKernelOp6verifyEv+0x118):
 undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUModuleOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN3cuf16RegisterKernelOp6verifyEv+0x174): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUFuncOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN3cuf16RegisterKernelOp6verifyEv+0x178): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUFuncOp, void>::id'
collect2: error: ld returned 1 exit status

125.832 [574/7/6666] Building CXX object tools/flang/lib/Optimizer/Builder/CMakeFiles/FIRBuilder.dir/FIRBuilder.cpp.o
129.813 [574/6/6667] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CufOpConversion.cpp.o
146.862 [574/5/6668] Building CXX object tools/flang/tools/fir-opt/CMakeFiles/fir-opt.dir/fir-opt.cpp.o
199.559 [574/4/6669] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertCall.cpp.o
242.665 [574/3/6670] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Bridge.cpp.o
243.173 [574/2/6671] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Allocatable.cpp.o
261.112 [574/1/6672] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertVariable.cpp.o
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 15, 2024

LLVM Buildbot has detected a new failure on builder flang-aarch64-sharedlibs running on linaro-flang-aarch64-sharedlibs while building flang at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/80/builds/4930

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
204.462 [187/12/7244] Linking CXX executable bin/opt
204.491 [187/11/7245] Linking CXX executable bin/ParallelJIT
204.491 [187/10/7246] Linking CXX shared library lib/libbenchmark.so.0.0.0
204.496 [186/10/7247] Creating library symlink lib/libbenchmark.so.0 lib/libbenchmark.so
204.600 [185/10/7248] Linking CXX shared library lib/libbenchmark_main.so.0.0.0
204.606 [184/10/7249] Creating library symlink lib/libbenchmark_main.so.0 lib/libbenchmark_main.so
205.836 [184/9/7250] Linking CXX shared library lib/libFortranEvaluate.so.20.0git
205.844 [183/9/7251] Creating library symlink lib/libFortranEvaluate.so
208.986 [182/9/7252] Building CXX object tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFDialect.cpp.o
209.237 [181/9/7253] Linking CXX shared library lib/libCUFDialect.so.20.0git
FAILED: lib/libCUFDialect.so.20.0git 
: && /usr/local/bin/c++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/./lib  -Wl,--gc-sections -shared -Wl,-soname,libCUFDialect.so.20.0git -o lib/libCUFDialect.so.20.0git tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFDialect.cpp.o tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib:/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/lib:"  lib/libFIRDialect.so.20.0git  lib/libFIRDialectSupport.so.20.0git  lib/libCUFAttrs.so.20.0git  lib/libLLVMAsmPrinter.so.20.0git  lib/libMLIRTargetLLVMIRExport.so.20.0git  lib/libMLIRDLTIDialect.so.20.0git  lib/libMLIRLLVMIRTransforms.so.20.0git  lib/libMLIRFuncDialect.so.20.0git  lib/libMLIRTransforms.so.20.0git  lib/libMLIRRuntimeVerifiableOpInterface.so.20.0git  lib/libMLIRNVVMDialect.so.20.0git  lib/libMLIRTranslateLib.so.20.0git  lib/libMLIRParser.so.20.0git  lib/libMLIRBytecodeReader.so.20.0git  lib/libMLIRAsmParser.so.20.0git  lib/libMLIRTransformUtils.so.20.0git  lib/libMLIRSubsetOpInterface.so.20.0git  lib/libMLIRValueBoundsOpInterface.so.20.0git  lib/libMLIRDestinationStyleOpInterface.so.20.0git  lib/libMLIRRewrite.so.20.0git  lib/libMLIRRewritePDL.so.20.0git  lib/libMLIRPDLToPDLInterp.so.20.0git  lib/libMLIRPass.so.20.0git  lib/libMLIRAnalysis.so.20.0git  lib/libMLIRLoopLikeInterface.so.20.0git  lib/libMLIRInferIntRangeInterface.so.20.0git  lib/libMLIRPresburger.so.20.0git  lib/libMLIRViewLikeInterface.so.20.0git  lib/libMLIRPDLInterpDialect.so.20.0git  lib/libMLIRPDLDialect.so.20.0git  lib/libLLVMFrontendOpenMP.so.20.0git  lib/libLLVMTransformUtils.so.20.0git  lib/libMLIRLLVMDialect.so.20.0git  lib/libMLIRDataLayoutInterfaces.so.20.0git  lib/libMLIRCallInterfaces.so.20.0git  lib/libMLIRControlFlowInterfaces.so.20.0git  lib/libMLIRFunctionInterfaces.so.20.0git  lib/libMLIRInferTypeOpInterface.so.20.0git  lib/libMLIRMemorySlotInterfaces.so.20.0git  lib/libMLIRSideEffectInterfaces.so.20.0git  lib/libMLIRIR.so.20.0git  lib/libMLIRSupport.so.20.0git  lib/libLLVMBitWriter.so.20.0git  lib/libLLVMAsmParser.so.20.0git  lib/libLLVMBitReader.so.20.0git  lib/libLLVMCore.so.20.0git  lib/libLLVMRemarks.so.20.0git  lib/libLLVMBinaryFormat.so.20.0git  lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/lib && :
/usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o: in function `llvm::DefaultDoCastIfPossible<mlir::gpu::GPUModuleOp, mlir::Operation*, llvm::CastInfo<mlir::gpu::GPUModuleOp, mlir::Operation*, void> >::doCastIfPossible(mlir::Operation*)':
CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x24): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUModuleOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu11GPUModuleOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x28): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUModuleOp, void>::id'
/usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o: in function `llvm::DefaultDoCastIfPossible<mlir::gpu::GPUFuncOp, mlir::Operation*, llvm::CastInfo<mlir::gpu::GPUFuncOp, mlir::Operation*, void> >::doCastIfPossible(mlir::Operation*)':
CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x24): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUFuncOp, void>::id'
/usr/bin/ld: CUFOps.cpp:(.text._ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_[_ZN4llvm23DefaultDoCastIfPossibleIN4mlir3gpu9GPUFuncOpEPNS1_9OperationENS_8CastInfoIS3_S5_vEEE16doCastIfPossibleES5_]+0x28): undefined reference to `mlir::detail::TypeIDResolver<mlir::gpu::GPUFuncOp, void>::id'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
210.290 [181/8/7254] Linking CXX shared library lib/libFortranSemantics.so.20.0git
211.919 [181/7/7255] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CufImplicitDeviceGlobal.cpp.o
216.534 [181/6/7256] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFAddConstructor.cpp.o
219.391 [181/5/7257] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertVariable.cpp.o
219.642 [181/4/7258] Building CXX object tools/flang/lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CufOpConversion.cpp.o
221.839 [181/3/7259] Building CXX object tools/flang/lib/Optimizer/Builder/CMakeFiles/FIRBuilder.dir/FIRBuilder.cpp.o
267.162 [181/2/7260] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertCall.cpp.o
351.515 [181/1/7261] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Bridge.cpp.o
ninja: build stopped: subcommand failed.

clementval added a commit that referenced this pull request Oct 15, 2024
The operation will be used in the CUF constructor to register the kernel
functions. This allow to delay this until codegen when the gpu.binary
will be available.

Reland of #112268 with correct shared library build support.
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
The operation will be used in the CUF constructor to register the kernel
functions. This allow to delay this until codegen when the gpu.binary
will be available.
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
The operation will be used in the CUF constructor to register the kernel
functions. This allow to delay this until codegen when the gpu.binary
will be available.

Reland of llvm#112268 with correct shared library build support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants