From e6ff7010a99fdbf2df31727a94ffaaf2f868f3ba Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 28 Oct 2016 04:59:38 -0400
Subject: [PATCH] P4 to Git Change 1333223 by lmoriche@lmoriche_opencl_lc on
2016/10/28 04:53:46
SWDEV-105604 - [OCL-LC-PAL] OpenCL program manager for LC on PAL
- Try to find the LLVM_BIN from the current module's path
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#8 edit
---
rocclr/runtime/device/pal/palcompiler.cpp | 48 ++++++++++++++++++-----
1 file changed, 39 insertions(+), 9 deletions(-)
diff --git a/rocclr/runtime/device/pal/palcompiler.cpp b/rocclr/runtime/device/pal/palcompiler.cpp
index fc1ef69007..51b8d8a500 100644
--- a/rocclr/runtime/device/pal/palcompiler.cpp
+++ b/rocclr/runtime/device/pal/palcompiler.cpp
@@ -24,6 +24,9 @@
#include
#include
#endif // defined(ATI_OS_LINUX)
+#if defined(ATI_OS_WIN)
+#include
+#endif // defined(ATI_OS_WIN)
//CLC_IN_PROCESS_CHANGE
extern int openclFrontEnd(const char* cmdline, std::string*, std::string* typeInfo = nullptr);
@@ -156,6 +159,28 @@ HSAILProgram::compileImpl(
#if defined(WITH_LIGHTNING_COMPILER)
static std::string llvmBin_(amd::Os::getEnvironment("LLVM_BIN"));
+#if defined(ATI_OS_WIN)
+static BOOL CALLBACK
+checkLLVM_BIN(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex)
+{
+ if (llvmBin_.empty()) {
+ HMODULE hm = NULL;
+ if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+ | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ (LPCSTR) &amd::Device::init, &hm)) {
+ char path[1024];
+ GetModuleFileNameA(hm, path, sizeof(path));
+ llvmBin_ = path;
+ size_t pos = llvmBin_.rfind('\\');
+ if (pos != std::string::npos) {
+ llvmBin_.resize(pos);
+ }
+ }
+ }
+ return TRUE;
+}
+#endif // defined (ATI_OS_WINDOWS)
+
#if defined(ATI_OS_LINUX)
static pthread_once_t once = PTHREAD_ONCE_INIT;
@@ -172,6 +197,19 @@ checkLLVM_BIN()
}
}
}
+}
+#endif // defined(ATI_OS_LINUX)
+
+std::auto_ptr
+LightningProgram::newCompilerInstance()
+{
+#if defined(ATI_OS_WIN)
+ static INIT_ONCE initOnce;
+ InitOnceExecuteOnce(&initOnce, checkLLVM_BIN, NULL, NULL);
+#endif // defined(ATI_OS_WIN)
+#if defined(ATI_OS_LINUX)
+ pthread_once(&once, checkLLVM_BIN);
+#endif // defined(ATI_OS_LINUX)
#if defined(DEBUG)
std::string clangExe(llvmBin_ + "/clang");
struct stat buf;
@@ -180,15 +218,7 @@ checkLLVM_BIN()
LogWarning(msg.c_str());
}
#endif // defined(DEBUG)
-}
-#endif // defined(ATI_OS_LINUX)
-
-std::auto_ptr
-LightningProgram::newCompilerInstance()
-{
-#if defined(ATI_OS_LINUX)
- pthread_once(&once, checkLLVM_BIN);
-#endif // defined(ATI_OS_LINUX)
+
return std::auto_ptr(
amd::opencl_driver::CompilerFactory().CreateAMDGPUCompiler(llvmBin_));
}