[MLIR][GPU][lld] Use LLD bundled in ROCm, removing workaround
Having clarified that executing the SerializeToHsaco pass can depend on a ROCm installation, switch from calling lld as a library to using the copy of lld guaranteed to be included in a ROCm install. This removes the workaround introduced in D119277 Reviewed By: whchung Differential Revision: https://reviews.llvm.org/D119463
This commit is contained in:
parent
82dbe82585
commit
1ce314ce6b
|
@ -7,7 +7,6 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lld/Common/CommonLinkerContext.h"
|
||||
#include "lld/Common/Driver.h"
|
||||
#include "lld/Common/ErrorHandler.h"
|
||||
#include "lld/Common/Memory.h"
|
||||
|
||||
|
@ -44,11 +43,3 @@ void CommonLinkerContext::destroy() {
|
|||
return;
|
||||
delete lctx;
|
||||
}
|
||||
|
||||
// Temporary API that forces global state cleanup between explicit calls to
|
||||
// drivers. See discussion in https://reviews.llvm.org/D119049.
|
||||
void lld::cleanup() {
|
||||
// Delete the global context and clear the global context pointer, so that it
|
||||
// cannot be accessed anymore.
|
||||
CommonLinkerContext::destroy();
|
||||
}
|
||||
|
|
|
@ -52,11 +52,6 @@ namespace wasm {
|
|||
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
|
||||
llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
|
||||
}
|
||||
|
||||
// Temporary API that forces global state cleanup between explicit calls to
|
||||
// drivers above. DO NOT USE - this will be replaced by safeLldMain(). See
|
||||
// discussion in https://reviews.llvm.org/D119049.
|
||||
void cleanup();
|
||||
} // namespace lld
|
||||
|
||||
#endif
|
||||
|
|
|
@ -126,11 +126,6 @@ if(MLIR_ENABLE_ROCM_RUNNER)
|
|||
"Building mlir with ROCm support requires the AMDGPU backend")
|
||||
endif()
|
||||
|
||||
# Ensure lld is enabled.
|
||||
if (NOT "lld" IN_LIST LLVM_ENABLE_PROJECTS)
|
||||
message(SEND_ERROR "lld is not enabled. Please revise LLVM_ENABLE_PROJECTS")
|
||||
endif()
|
||||
|
||||
set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs")
|
||||
target_compile_definitions(obj.MLIRGPUTransforms
|
||||
PRIVATE
|
||||
|
@ -138,21 +133,9 @@ if(MLIR_ENABLE_ROCM_RUNNER)
|
|||
MLIR_GPU_TO_HSACO_PASS_ENABLE=1
|
||||
)
|
||||
|
||||
target_include_directories(obj.MLIRGPUTransforms
|
||||
PRIVATE
|
||||
${MLIR_SOURCE_DIR}/../lld/include
|
||||
)
|
||||
|
||||
target_link_libraries(MLIRGPUOps
|
||||
PRIVATE
|
||||
lldELF
|
||||
MLIRExecutionEngine
|
||||
MLIRROCDLToLLVMIRTranslation
|
||||
)
|
||||
|
||||
# Link lldELF also to libmlir.so. Create an alias that starts with LLVM
|
||||
# because LINK_COMPONENTS elements are implicitly prefixed with LLVM.
|
||||
add_library(LLVMAliasTolldELF ALIAS lldELF)
|
||||
set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS AliasTolldELF)
|
||||
|
||||
endif()
|
||||
|
|
|
@ -52,8 +52,6 @@
|
|||
|
||||
#include "llvm/Transforms/IPO/Internalize.h"
|
||||
|
||||
#include "lld/Common/Driver.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
using namespace mlir;
|
||||
|
@ -435,20 +433,15 @@ SerializeToHsacoPass::createHsaco(const SmallVectorImpl<char> &isaBinary) {
|
|||
}
|
||||
llvm::FileRemover cleanupHsaco(tempHsacoFilename);
|
||||
|
||||
{
|
||||
static std::mutex mutex;
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
// Invoke lld. Expect a true return value from lld.
|
||||
bool r = lld::elf::link({"ld.lld", "-shared", tempIsaBinaryFilename.c_str(),
|
||||
"-o", tempHsacoFilename.c_str()},
|
||||
llvm::outs(), llvm::errs(), /*exitEarly=*/false,
|
||||
/*disableOutput=*/false);
|
||||
// Allow for calling the driver again in the same process.
|
||||
lld::cleanup();
|
||||
if (!r) {
|
||||
emitError(loc, "lld invocation error");
|
||||
return {};
|
||||
}
|
||||
std::string theRocmPath = getRocmPath();
|
||||
llvm::SmallString<32> lldPath(std::move(theRocmPath));
|
||||
llvm::sys::path::append(lldPath, "llvm", "bin", "ld.lld");
|
||||
int lldResult = llvm::sys::ExecuteAndWait(
|
||||
lldPath,
|
||||
{"ld.lld", "-shared", tempIsaBinaryFilename, "-o", tempHsacoFilename});
|
||||
if (lldResult != 0) {
|
||||
emitError(loc, "lld invocation error");
|
||||
return {};
|
||||
}
|
||||
|
||||
// Load the HSA code object.
|
||||
|
|
Loading…
Reference in New Issue