From e51a27e18268a2c899e57f260b2fa1ed6c295587 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 7 Mar 2019 15:48:33 -0500
Subject: [PATCH] P4 to Git Change 1753035 by wchau@wchau_OCL_Linux on
2019/03/07 15:02:39
SWDEV-182054 - Allow building OpenCL-Runtime with COMGR enabled without OpenCL-Driver being present
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/build/Makefile.hip#12 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#184 edit
... //depot/stg/opencl/drivers/opencl/compiler/Makefile#71 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#242 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#335 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#30 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#18 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#126 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#87 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#120 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#51 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#100 edit
---
rocclr/runtime/device/device.cpp | 9 ++++-----
rocclr/runtime/device/device.hpp | 12 +++++++-----
rocclr/runtime/device/devprogram.cpp | 10 ++++------
rocclr/runtime/device/devprogram.hpp | 4 +++-
rocclr/runtime/device/pal/paldevice.cpp | 4 ++--
rocclr/runtime/device/pal/palprogram.cpp | 4 +++-
rocclr/runtime/device/rocm/rocdevice.cpp | 6 ++++--
rocclr/runtime/device/rocm/rockernel.cpp | 2 ++
rocclr/runtime/device/rocm/rocprogram.cpp | 4 +++-
9 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/rocclr/runtime/device/device.cpp b/rocclr/runtime/device/device.cpp
index ec568ba3d4..82cd93f3ff 100644
--- a/rocclr/runtime/device/device.cpp
+++ b/rocclr/runtime/device/device.cpp
@@ -148,7 +148,7 @@ bool Device::init() {
// GPU stack. The order of initialization is signiicant and if changed
// amd::Device::registerDevice() must be accordingly modified.
#if defined(WITH_HSA_DEVICE)
- // @todo remove IS_LIGHTNING check when PAL-LC builds will be deprecated
+ // @todo remove IS_LIGHTNING check when PAL-LC builds will be deprecated
if ((GPU_ENABLE_PAL != 1) || IS_LIGHTNING) {
// Return value of roc::Device::init()
// If returned false, error initializing HSA stack.
@@ -229,6 +229,7 @@ bool Device::ValidateComgr() {
#if defined(USE_COMGR_LIBRARY)
// Check if Lightning compiler was requested
if (settings_->useLightning_) {
+ LogInfo("Loading COMGR library.");
std::call_once(amd::Comgr::initialized, amd::Comgr::LoadLib);
// Use Lightning only if it's available
settings_->useLightning_ = amd::Comgr::IsReady();
@@ -413,7 +414,7 @@ char* Device::getExtensionString() {
return result;
}
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
CacheCompilation::CacheCompilation(std::string targetStr, std::string postfix, bool enableCache,
bool resetCache)
: codeCache_(targetStr, 0, AMD_PLATFORM_BUILD_NUMBER, postfix),
@@ -498,13 +499,11 @@ bool CacheCompilation::compileToLLVMBitcode(amd::opencl_driver::Compiler* C,
StringCache::CachedData cachedData = {bc->Ptr(), bc->Size()};
bcSet.push_back(cachedData);
} else if (input->Type() == DT_CL_HEADER) {
-#if !defined(USE_COMGR_LIBRARY)
FileReference* bcFile = reinterpret_cast(input);
std::string bc;
bcFile->ReadToString(bc);
StringCache::CachedData cachedData = {bc.c_str(), bc.size()};
bcSet.push_back(cachedData);
-#endif // !defined(USE_COMGR_LIBRARY)
} else {
buildLog += "Error: unsupported bitcode type for checking cache.\n";
checkCache = false;
@@ -582,7 +581,7 @@ bool CacheCompilation::compileAndLinkExecutable(amd::opencl_driver::Compiler* C,
return true;
}
-#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#endif // defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
} // namespace amd
diff --git a/rocclr/runtime/device/device.hpp b/rocclr/runtime/device/device.hpp
index e9e5ff1553..2275c14126 100644
--- a/rocclr/runtime/device/device.hpp
+++ b/rocclr/runtime/device/device.hpp
@@ -19,10 +19,10 @@
#include "devkernel.hpp"
#include "amdocl/cl_profile_amd.h"
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
#include "caching/cache.hpp"
#include "driver/AmdCompiler.h"
-#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#endif // defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
#include "acl.h"
#include "hwdebug.hpp"
@@ -69,7 +69,9 @@ class SvmUnmapMemoryCommand;
class TransferBufferFileCommand;
class HwDebugManager;
class Device;
+#ifndef USE_COMGR_LIBRARY
class CacheCompilation;
+#endif
struct KernelParameterDescriptor;
struct Coord3D;
@@ -1328,7 +1330,7 @@ class Device : public RuntimeObject {
// P2P devices that are accessible from the current device
std::vector p2pDevices_;
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
amd::CacheCompilation* cacheCompilation() const { return cacheCompilation_.get(); }
#endif
@@ -1354,7 +1356,7 @@ class Device : public RuntimeObject {
BlitProgram* blitProgram_; //!< Blit program info
static AppProfile appProfile_; //!< application profile
HwDebugManager* hwDebugMgr_; //!< Hardware Debug manager
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
//! Compilation with cache support
std::unique_ptr cacheCompilation_;
#endif
@@ -1372,7 +1374,7 @@ class Device : public RuntimeObject {
std::map* vaCacheMap_; //!< VA cache map
};
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
//! Compilation process with cache support.
class CacheCompilation : public amd::HeapObject {
public:
diff --git a/rocclr/runtime/device/devprogram.cpp b/rocclr/runtime/device/devprogram.cpp
index ebb57e9e55..45f23fd3fd 100644
--- a/rocclr/runtime/device/devprogram.cpp
+++ b/rocclr/runtime/device/devprogram.cpp
@@ -12,7 +12,9 @@
#include "utils/libUtils.h"
#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#ifndef USE_COMGR_LIBRARY
#include "driver/AmdCompiler.h"
+#endif
#include "libraries.amdgcn.inc"
#include "opencl1.2-c.amdgcn.inc"
#include "opencl2.0-c.amdgcn.inc"
@@ -161,6 +163,7 @@ static void checkLLVM_BIN() {
}
#endif // defined(ATI_OS_LINUX)
+#if !defined(USE_COMGR_LIBRARY)
std::unique_ptr Program::newCompilerInstance() {
#if defined(ATI_OS_WIN)
static INIT_ONCE initOnce;
@@ -178,13 +181,10 @@ std::unique_ptr Program::newCompilerInstance() {
}
#endif // defined(DEBUG)
-#if !defined(USE_COMGR_LIBRARY)
return std::unique_ptr(
amd::opencl_driver::CompilerFactory().CreateAMDGPUCompiler(llvmBin_));
-#else
- return std::unique_ptr(nullptr);
-#endif // !defined(USE_COMGR_LIBRARY)
}
+#endif // !defined(USE_COMGR_LIBRARY)
#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
// ================================================================================================
@@ -1082,8 +1082,6 @@ bool Program::linkImpl(const std::vector& inputPrograms,
#if defined(USE_COMGR_LIBRARY)
bool Program::linkImplLC(const std::vector& inputPrograms,
amd::option::Options* options, bool createLibrary) {
- using namespace amd::opencl_driver;
- std::unique_ptr C(newCompilerInstance());
amd_comgr_data_set_t inputs;
diff --git a/rocclr/runtime/device/devprogram.hpp b/rocclr/runtime/device/devprogram.hpp
index e75057f9bf..4f4bbf27c9 100644
--- a/rocclr/runtime/device/devprogram.hpp
+++ b/rocclr/runtime/device/devprogram.hpp
@@ -11,7 +11,9 @@
#include "comgrctx.hpp"
#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#ifndef USE_COMGR_LIBRARY
#include "driver/AmdCompiler.h"
+#endif
//#include "llvm/Support/AMDGPUMetadata.h"
namespace llvm {
@@ -276,7 +278,7 @@ class Program : public amd::HeapObject {
void setType(type_t newType) { type_ = newType; }
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && !defined(USE_COMGR_LIBRARY)
//! Return a new transient compiler instance.
static std::unique_ptr newCompilerInstance();
#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
diff --git a/rocclr/runtime/device/pal/paldevice.cpp b/rocclr/runtime/device/pal/paldevice.cpp
index 8f9121ed7a..0aac80f223 100644
--- a/rocclr/runtime/device/pal/paldevice.cpp
+++ b/rocclr/runtime/device/pal/paldevice.cpp
@@ -280,7 +280,7 @@ bool NullDevice::create(Pal::AsicRevision asicRevision, Pal::GfxIpLevel ipLevel,
info_.wavefrontWidth_ = settings().enableWave32Mode_ ? 32 : 64;
if (settings().useLightning_) {
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
// create compilation object with cache support
int gfxipMajor = hwInfo_->gfxipVersionLC_ / 100;
int gfxipMinor = hwInfo_->gfxipVersionLC_ / 10 % 10;
@@ -967,7 +967,7 @@ bool Device::create(Pal::IDevice* device) {
}
if (settings().useLightning_) {
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
// create compilation object with cache support
int gfxipMajor = hwInfo()->gfxipVersionLC_ / 100;
int gfxipMinor = hwInfo()->gfxipVersionLC_ / 10 % 10;
diff --git a/rocclr/runtime/device/pal/palprogram.cpp b/rocclr/runtime/device/pal/palprogram.cpp
index d191e27124..6862ff6fd7 100644
--- a/rocclr/runtime/device/pal/palprogram.cpp
+++ b/rocclr/runtime/device/pal/palprogram.cpp
@@ -20,8 +20,10 @@
#include "hsa_ext_image.h"
#include "amd_hsa_loader.hpp"
#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
-#include "llvm/Support/AMDGPUMetadata.h"
+#ifndef USE_COMGR_LIBRARY
#include "driver/AmdCompiler.h"
+#endif
+#include "llvm/Support/AMDGPUMetadata.h"
#include "libraries.amdgcn.inc"
#include "gelf.h"
#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
diff --git a/rocclr/runtime/device/rocm/rocdevice.cpp b/rocclr/runtime/device/rocm/rocdevice.cpp
index 83bb540a8e..f2fd3ffc21 100644
--- a/rocclr/runtime/device/rocm/rocdevice.cpp
+++ b/rocclr/runtime/device/rocm/rocdevice.cpp
@@ -19,9 +19,9 @@
#include "device/rocm/rocblit.hpp"
#include "device/rocm/rocvirtual.hpp"
#include "device/rocm/rocprogram.hpp"
-#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#if defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
#include "driver/AmdCompiler.h"
-#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#endif // defined(WITH_LIGHTNING_COMPILER) && ! defined(USE_COMGR_LIBRARY)
#include "device/rocm/rocmemory.hpp"
#include "device/rocm/rocglinterop.hpp"
#ifdef WITH_AMDGPU_PRO
@@ -652,6 +652,7 @@ bool Device::create(bool sramEccEnabled) {
if (settings().useLightning_) {
scheduler = sch.c_str();
}
+#ifndef USE_COMGR_LIBRARY
// create compilation object with cache support
int gfxipMajor = deviceInfo_.gfxipVersion_ / 100;
int gfxipMinor = deviceInfo_.gfxipVersion_ / 10 % 10;
@@ -676,6 +677,7 @@ bool Device::create(bool sramEccEnabled) {
}
cacheCompilation_.reset(compObj);
+#endif // USE_COMGR_LIBRARY
#endif
amd::Context::Info info = {0};
diff --git a/rocclr/runtime/device/rocm/rockernel.cpp b/rocclr/runtime/device/rocm/rockernel.cpp
index 261144c29b..c05197fe5d 100644
--- a/rocclr/runtime/device/rocm/rockernel.cpp
+++ b/rocclr/runtime/device/rocm/rockernel.cpp
@@ -10,7 +10,9 @@
#ifndef WITHOUT_HSA_BACKEND
#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+#ifndef USE_COMGR_LIBRARY
#include "driver/AmdCompiler.h"
+#endif
#include "llvm/Support/AMDGPUMetadata.h"
typedef llvm::AMDGPU::HSAMD::Metadata CodeObjectMD;
diff --git a/rocclr/runtime/device/rocm/rocprogram.cpp b/rocclr/runtime/device/rocm/rocprogram.cpp
index f84dd11b16..e5ec876a17 100644
--- a/rocclr/runtime/device/rocm/rocprogram.cpp
+++ b/rocclr/runtime/device/rocm/rocprogram.cpp
@@ -9,8 +9,10 @@
#include "rockernel.hpp"
#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include
-#include "driver/AmdCompiler.h"
#include "libraries.amdgcn.inc"
+#ifndef USE_COMGR_LIBRARY
+#include "driver/AmdCompiler.h"
+#endif
#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include "utils/bif_section_labels.hpp"