Skip to content

[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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/lib/Target/LLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/Target/LLVM/NVVM/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))));
Expand Down