[Mlir-commits] [mlir] [mlir] fix overflow warning when generating embedded libdevice (PR #125801)
Zichen Lu
llvmlistbot at llvm.org
Wed Feb 5 01:17:48 PST 2025
https://github.com/MikaOvO updated https://github.com/llvm/llvm-project/pull/125801
>From e0eca7325ab2c1931e5d31b659564692129d7a95 Mon Sep 17 00:00:00 2001
From: Zichen Lu <mikaovo2000 at gmail.com>
Date: Wed, 5 Feb 2025 12:49:23 +0800
Subject: [PATCH] [mlir] fix overflow warning when generating embedded
libdevice
---
mlir/lib/Target/LLVM/CMakeLists.txt | 2 +-
mlir/lib/Target/LLVM/NVVM/Target.cpp | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/Target/LLVM/CMakeLists.txt b/mlir/lib/Target/LLVM/CMakeLists.txt
index 4be147d02d579af..83fbf7a5fe5f32c 100644
--- a/mlir/lib/Target/LLVM/CMakeLists.txt
+++ b/mlir/lib/Target/LLVM/CMakeLists.txt
@@ -125,7 +125,7 @@ function(embed_binary_to_src file output_file symbol)
# Convert hex data for C compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
# Write data to output file
- file(WRITE ${output_file} "const char ${symbol}[] = {${filedata}};\nconst int ${symbol}_size = sizeof(${symbol});\n")
+ file(WRITE ${output_file} "const unsigned char ${symbol}[] = {${filedata}};\nconst int ${symbol}_size = sizeof(${symbol});\n")
endfunction()
set(MLIR_NVVM_EMBED_LIBDEVICE 0 CACHE BOOL "Embed CUDA libdevice.bc in the binary at build time instead of looking it up at runtime")
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 86ff848d6c6c2d3..b7d60ed59db02d1 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -47,7 +47,7 @@ using namespace mlir::NVVM;
#define __DEFAULT_CUDATOOLKIT_PATH__ ""
#endif
-extern "C" const char _mlir_embedded_libdevice[];
+extern "C" const unsigned char _mlir_embedded_libdevice[];
extern "C" const unsigned _mlir_embedded_libdevice_size;
namespace {
@@ -160,7 +160,8 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
// Allocate a resource using one of the UnManagedResourceBlob method to wrap
// the embedded data.
auto unmanagedBlob = UnmanagedAsmResourceBlob::allocateInferAlign(
- ArrayRef<char>{_mlir_embedded_libdevice, _mlir_embedded_libdevice_size});
+ ArrayRef<char>{(const char *)_mlir_embedded_libdevice,
+ _mlir_embedded_libdevice_size});
librariesToLink.push_back(DenseResourceElementsAttr::get(
type, resourceManager.insert("_mlir_embedded_libdevice",
std::move(unmanagedBlob))));
More information about the Mlir-commits
mailing list