From 4dd432e70197ec3eed812b1ef43172c8884e68b8 Mon Sep 17 00:00:00 2001 From: Petar Petrovic Date: Wed, 30 Sep 2026 16:59:57 +0200 Subject: [PATCH] [Target] Adopt kernel triple and data layout for device libraries Libraries loaded from disk go through handleBitcodeFile, which gives them our triple and data layout, but packaged device libraries skipped it. When those are built by a newer LLVM than ours (amdgpu-amd-amdhsa triple, extra address spaces in the data layout), the IR linker warned twice for every kernel that calls OCML/OCKL. Run packaged libraries through handleBitcodeFile too. Generated instructions are unchanged. As for libraries loaded from disk, the packaged libraries' llvm.ident and opencl.ocl.version metadata are now dropped, so kernels using OCML/OCKL no longer report OpenCL C as their language. --- mlir/lib/Target/Target.cpp | 5 +++++ mlir/test/Target/packaged-device-libs.mlir | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 mlir/test/Target/packaged-device-libs.mlir diff --git a/mlir/lib/Target/Target.cpp b/mlir/lib/Target/Target.cpp index 9f4bd666e0e4..290cd13d7009 100644 --- a/mlir/lib/Target/Target.cpp +++ b/mlir/lib/Target/Target.cpp @@ -128,6 +128,11 @@ AMDGPUSerializer::loadBitcodeFiles(llvm::Module &module) { ", error message:" + error.getMessage()); return std::nullopt; } + // Packaged libraries can come from a newer LLVM than ours. Give them the + // same handling as libraries loaded from disk so they adopt our triple + // and data layout instead of warning on every kernel that links them. + if (failed(handleBitcodeFile(*library))) + return std::nullopt; // Unset the lib so we don't add it with `appendStandardLibs`. libs = libs & ~lib; bcFiles.push_back(std::move(library)); diff --git a/mlir/test/Target/packaged-device-libs.mlir b/mlir/test/Target/packaged-device-libs.mlir new file mode 100644 index 000000000000..9b41f8276fb0 --- /dev/null +++ b/mlir/test/Target/packaged-device-libs.mlir @@ -0,0 +1,17 @@ +// RUN: rocmlir-opt %s --rocdl-attach-target=chip=gfx942 --gpu-module-to-binary 2>&1 \ +// RUN: | FileCheck %s --implicit-check-not="Linking two modules" + +// The packaged device libraries can be built by a newer LLVM than ours, with a +// different triple spelling and data layout. Linking them must not warn. + +// CHECK: gpu.binary @kernels +module attributes {gpu.container_module} { + gpu.module @kernels { + llvm.func @__ocml_exp_f32(f32) -> f32 + llvm.func @kernel(%arg0: f32, %arg1: !llvm.ptr<1>) attributes {rocdl.kernel} { + %0 = llvm.call @__ocml_exp_f32(%arg0) : (f32) -> f32 + llvm.store %0, %arg1 : f32, !llvm.ptr<1> + llvm.return + } + } +}