-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir] fix overflow warning when generating embedded libdevice #125801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir] fix overflow warning when generating embedded libdevice #125801
Conversation
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-mlir Author: Zichen Lu (MikaOvO) ChangesWhen building mlir with
which is followed by a large number of characters in stdout. Fix this to avoid stdout outputting a large number of characters (3e5). Full diff: https://github.com/llvm/llvm-project/pull/125801.diff 2 Files Affected:
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..58051db7bd066ea 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 {
@@ -159,8 +159,9 @@ 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});
+ auto unmanagedBlob =
+ UnmanagedAsmResourceBlob::allocateInferAlign(ArrayRef<char>{
+ (char *)_mlir_embedded_libdevice, _mlir_embedded_libdevice_size});
librariesToLink.push_back(DenseResourceElementsAttr::get(
type, resourceManager.insert("_mlir_embedded_libdevice",
std::move(unmanagedBlob))));
|
mlir/lib/Target/LLVM/NVVM/Target.cpp
Outdated
ArrayRef<char>{_mlir_embedded_libdevice, _mlir_embedded_libdevice_size}); | ||
auto unmanagedBlob = | ||
UnmanagedAsmResourceBlob::allocateInferAlign(ArrayRef<char>{ | ||
(char *)_mlir_embedded_libdevice, _mlir_embedded_libdevice_size}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(char *)_mlir_embedded_libdevice, _mlir_embedded_libdevice_size}); | |
(const char *)_mlir_embedded_libdevice, _mlir_embedded_libdevice_size}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, could you help merge this PR?
0f7dd06
to
4ce95fe
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
4ce95fe
to
e0eca73
Compare
…125801) When building mlir with `-DMLIR_NVVM_EMBED_LIBDEVICE=ON`, there will be a warning ``` build/tools/mlir/lib/Target/LLVM/libdevice_embedded.c:1: warning: overflow in conversion from ‘int’ to ‘char’ changes value from ‘143’ to ‘-113’ [-Woverflow] ``` which is followed by a large number of characters in stdout. Fix this to avoid stdout outputting a large number of characters (3e5).
When building mlir with
-DMLIR_NVVM_EMBED_LIBDEVICE=ON
, there will be a warningwhich is followed by a large number of characters in stdout.
Fix this to avoid stdout outputting a large number of characters (3e5).