From 01710a66acfac33ec5da17638787a369cf88ce98 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 2 Jan 2019 16:03:55 -0500
Subject: [PATCH] P4 to Git Change 1725166 by gandryey@gera-w8 on 2019/01/02
15:41:59
SWDEV-79445 - OCL generic changes and code clean-up
- Add dynamic switch between HSAIL and LC in ROCr path
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#108 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#48 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.hpp#26 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#95 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#42 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#71 edit
---
rocclr/runtime/device/rocm/rocdevice.cpp | 48 ++++++++++++++---------
rocclr/runtime/device/rocm/rockernel.cpp | 8 ++--
rocclr/runtime/device/rocm/rockernel.hpp | 4 --
rocclr/runtime/device/rocm/rocprogram.cpp | 8 ++--
rocclr/runtime/device/rocm/rocprogram.hpp | 4 --
rocclr/runtime/device/rocm/rocvirtual.cpp | 4 +-
6 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/rocclr/runtime/device/rocm/rocdevice.cpp b/rocclr/runtime/device/rocm/rocdevice.cpp
index 222bafd405..ec5649d1e1 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)
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include "driver/AmdCompiler.h"
-#endif // defined(WITH_LIGHTNING_COMPILER)
+#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include "device/rocm/rocmemory.hpp"
#include "device/rocm/rocglinterop.hpp"
#ifdef WITH_AMDGPU_PRO
@@ -644,10 +644,11 @@ bool Device::create() {
const char* scheduler = nullptr;
-#if defined(WITH_LIGHTNING_COMPILER)
- std::string sch = SchedulerSourceCode;
- scheduler = sch.c_str();
-
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
+ if (settings().useLightning_) {
+ std::string sch = SchedulerSourceCode;
+ scheduler = sch.c_str();
+ }
// create compilation object with cache support
int gfxipMajor = deviceInfo_.gfxipVersion_ / 100;
int gfxipMinor = deviceInfo_.gfxipVersion_ / 10 % 10;
@@ -744,22 +745,33 @@ bool Device::create() {
}
device::Program* NullDevice::createProgram(amd::option::Options* options) {
-#if defined(WITH_COMPILER_LIB)
- return new roc::HSAILProgram(*this);
-#else // !defined(WITH_COMPILER_LIB)
- return NULL;
-#endif // !defined(WITH_COMPILER_LIB)
+ device::Program* program;
+ if (settings().useLightning_) {
+ program = new LightningProgram(*this);
+ } else {
+ program = new HSAILProgram(*this);
+ }
+
+ if (program == nullptr) {
+ LogError("Memory allocation has failed!");
+ }
+
+ return program;
}
device::Program* Device::createProgram(amd::option::Options* options) {
-#if defined(WITH_LIGHTNING_COMPILER)
- if (!compilerHandle_ || !options->oVariables->Legacy) {
- return new roc::LightningProgram(*this);
+ device::Program* program;
+ if (settings().useLightning_) {
+ program = new LightningProgram(*this);
+ } else {
+ program = new HSAILProgram(*this);
}
-#endif // defined(WITH_LIGHTNING_COMPILER)
-#if defined(WITH_COMPILER_LIB)
- return new roc::HSAILProgram(*this);
-#endif // defined(WITH_COMPILER_LIB)
+
+ if (program == nullptr) {
+ LogError("Memory allocation has failed!");
+ }
+
+ return program;
}
hsa_status_t Device::iterateGpuMemoryPoolCallback(hsa_amd_memory_pool_t pool, void* data) {
diff --git a/rocclr/runtime/device/rocm/rockernel.cpp b/rocclr/runtime/device/rocm/rockernel.cpp
index e7f2642457..ad20af284c 100644
--- a/rocclr/runtime/device/rocm/rockernel.cpp
+++ b/rocclr/runtime/device/rocm/rockernel.cpp
@@ -9,13 +9,13 @@
#ifndef WITHOUT_HSA_BACKEND
-#if defined(WITH_LIGHTNING_COMPILER)
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include "driver/AmdCompiler.h"
#include "llvm/Support/AMDGPUMetadata.h"
typedef llvm::AMDGPU::HSAMD::Metadata CodeObjectMD;
typedef llvm::AMDGPU::HSAMD::Kernel::Metadata KernelMD;
-#endif // defined(WITH_LIGHTNING_COMPILER)
+#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
namespace roc {
@@ -31,7 +31,7 @@ Kernel::Kernel(std::string name, Program* prog, const uint64_t& kernelCodeHandle
kernargSegmentByteSize_(kernargSegmentByteSize),
kernargSegmentAlignment_(kernargSegmentAlignment) {}
-#if defined(WITH_LIGHTNING_COMPILER)
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#if defined(USE_COMGR_LIBRARY)
bool LightningKernel::init() {
@@ -261,7 +261,7 @@ bool LightningKernel::init() {
return true;
}
#endif // defined(USE_COMGR_LIBRARY)
-#endif // defined(WITH_LIGHTNING_COMPILER)
+#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#if defined(WITH_COMPILER_LIB)
bool HSAILKernel::init() {
diff --git a/rocclr/runtime/device/rocm/rockernel.hpp b/rocclr/runtime/device/rocm/rockernel.hpp
index 61ff71b652..8bf6ed674c 100644
--- a/rocclr/runtime/device/rocm/rockernel.hpp
+++ b/rocclr/runtime/device/rocm/rockernel.hpp
@@ -49,7 +49,6 @@ class Kernel : public device::Kernel {
size_t kernelDirectiveOffset_;
};
-#if defined(WITH_COMPILER_LIB)
class HSAILKernel : public roc::Kernel {
public:
HSAILKernel(std::string name, Program* prog, const uint64_t& kernelCodeHandle,
@@ -64,9 +63,7 @@ class HSAILKernel : public roc::Kernel {
//! Initializes the metadata required for this kernel
virtual bool init() final;
};
-#endif // defined(WITH_COMPILER_LIB)
-#if defined(WITH_LIGHTNING_COMPILER)
class LightningKernel : public roc::Kernel {
public:
LightningKernel(std::string name, Program* prog, const uint64_t& kernelCodeHandle,
@@ -80,7 +77,6 @@ class LightningKernel : public roc::Kernel {
//! Initializes the metadata required for this kernel
virtual bool init() final;
};
-#endif // defined(WITH_LIGHTNING_COMPILER)
} // namespace roc
diff --git a/rocclr/runtime/device/rocm/rocprogram.cpp b/rocclr/runtime/device/rocm/rocprogram.cpp
index ddb55f6894..0acda80673 100644
--- a/rocclr/runtime/device/rocm/rocprogram.cpp
+++ b/rocclr/runtime/device/rocm/rocprogram.cpp
@@ -7,11 +7,11 @@
#include "utils/options.hpp"
#include "rockernel.hpp"
-#if defined(WITH_LIGHTNING_COMPILER)
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include
#include "driver/AmdCompiler.h"
#include "libraries.amdgcn.inc"
-#endif // defined(WITH_LIGHTNING_COMPILER)
+#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
#include "utils/bif_section_labels.hpp"
#include "amd_hsa_kernel_code.h"
@@ -313,7 +313,7 @@ bool HSAILProgram::setKernels(amd::option::Options* options, void* binary, size_
}
#endif // defined(WITH_COMPILER_LIB)
-#if defined(WITH_LIGHTNING_COMPILER)
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
LightningProgram::LightningProgram(roc::NullDevice& device)
: roc::Program(device) {
isLC_ = true;
@@ -491,7 +491,7 @@ bool LightningProgram::setKernels(amd::option::Options* options, void* binary, s
return true;
}
-#endif // defined(WITH_LIGHTNING_COMPILER)
+#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
} // namespace roc
diff --git a/rocclr/runtime/device/rocm/rocprogram.hpp b/rocclr/runtime/device/rocm/rocprogram.hpp
index 178011ba4a..5fe0c466de 100644
--- a/rocclr/runtime/device/rocm/rocprogram.hpp
+++ b/rocclr/runtime/device/rocm/rocprogram.hpp
@@ -62,7 +62,6 @@ protected:
hsa_code_object_reader_t hsaCodeObjectReader_; //!< Handle to HSA code reader
};
-#if defined(WITH_COMPILER_LIB)
class HSAILProgram : public roc::Program {
public:
HSAILProgram(roc::NullDevice& device);
@@ -78,9 +77,7 @@ private:
bool saveBinaryAndSetType(type_t type);
};
-#endif // defined(WITH_COMPILER_LIB)
-#if defined(WITH_LIGHTNING_COMPILER)
class LightningProgram : public roc::Program {
public:
LightningProgram(roc::NullDevice& device);
@@ -96,7 +93,6 @@ private:
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize) override;
};
-#endif // defined(WITH_LIGHTNING_COMPILER)
/*@}*/} // namespace roc
diff --git a/rocclr/runtime/device/rocm/rocvirtual.cpp b/rocclr/runtime/device/rocm/rocvirtual.cpp
index ab505ce469..38cbde14c9 100644
--- a/rocclr/runtime/device/rocm/rocvirtual.cpp
+++ b/rocclr/runtime/device/rocm/rocvirtual.cpp
@@ -347,9 +347,9 @@ bool VirtualGPU::processMemObjects(const amd::Kernel& kernel, const_address para
"Unsupported address qualifier");
const bool readOnly =
-#if defined(WITH_LIGHTNING_COMPILER)
+#if defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
desc.typeQualifier_ == CL_KERNEL_ARG_TYPE_CONST ||
-#endif // defined(WITH_LIGHTNING_COMPILER)
+#endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY)
(mem->getMemFlags() & CL_MEM_READ_ONLY) != 0;
if (!readOnly) {