Merge pull request #93388 from danieldk/more-local-rocr-ext-dir

rocm-runtime: make ROCR_EXT_DIR handling more local
This commit is contained in:
Daniël de Kok 2020-07-18 10:42:17 +02:00 committed by GitHub
commit ae33b7daec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,24 +1,23 @@
diff --git a/src/core/util/lnx/os_linux.cpp b/src/core/util/lnx/os_linux.cpp
index fdbe19a..42d4ef8 100644
--- a/src/core/util/lnx/os_linux.cpp
+++ b/src/core/util/lnx/os_linux.cpp
@@ -161,8 +161,17 @@ static_assert(sizeof(Mutex) == sizeof(pthread_mutex_t*), "OS abstraction size mi
static_assert(sizeof(Thread) == sizeof(os_thread*), "OS abstraction size mismatch");
diff --git a/src/core/runtime/runtime.cpp b/src/core/runtime/runtime.cpp
index dd6a15c..fb6de49 100644
--- a/src/core/runtime/runtime.cpp
+++ b/src/core/runtime/runtime.cpp
@@ -1358,7 +1358,17 @@ void Runtime::LoadExtensions() {
core::HsaApiTable::HSA_EXT_FINALIZER_API_TABLE_ID);
LibHandle LoadLib(std::string filename) {
- void* ret = dlopen(filename.c_str(), RTLD_LAZY);
- if (ret == nullptr) debug_print("LoadLib(%s) failed: %s\n", filename.c_str(), dlerror());
+ std::string extDirFilename = GetEnvVar("ROCR_EXT_DIR") + "/" + filename;
+ void* ret = dlopen(extDirFilename.c_str(), RTLD_LAZY);
+
+ // Attempt to load from the directory hardcoded by rocrExtDir.
+ if (ret == nullptr) {
+ std::string runpathFilename = std::string("@rocrExtDir@") + "/" + filename;
+ ret = dlopen(runpathFilename.c_str(), RTLD_LAZY);
+
+ if (ret == nullptr) debug_print("LoadLib(%s) failed: %s\n", filename.c_str(), dlerror());
// Update Hsa Api Table with handle of Image extension Apis
- extensions_.LoadImage(kImageLib[os_index(os::current_os)]);
+ //
+ // Use ROCR_EXT_DIR when it is non-empty. Otherwise, try to load the
+ // library from the OpenGL driver path.
+ std::string extDirVar = os::GetEnvVar("ROCR_EXT_DIR");
+ if (!extDirVar.empty()) {
+ extensions_.LoadImage(extDirVar + "/" + kImageLib[os_index(os::current_os)]);
+ } else {
+ std::string globalDriverDir("@rocrExtDir@");
+ extensions_.LoadImage(globalDriverDir + "/" + kImageLib[os_index(os::current_os)]);
+ }
+
return *(LibHandle*)&ret;
hsa_api_table_.LinkExts(&extensions_.image_api,
core::HsaApiTable::HSA_EXT_IMAGE_API_TABLE_ID);
}