From 5ec0d059a3e43617edf0b659e7797ee8a458002f Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 15 Nov 2017 21:58:49 -0500 Subject: [PATCH] P4 to Git Change 1483021 by lmoriche@lmoriche_opencl_dev2 on 2017/11/15 21:49:30 SWDEV-118564 - [OCL-LC-ROCm] Disable HSAILProgram and HSAILKernel if the compiler library is not available. Affected files ... ... //depot/stg/opencl/drivers/opencl/opencldefs#222 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#214 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#39 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#76 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#31 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.hpp#18 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#76 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#31 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#89 edit --- rocclr/runtime/device/device.cpp | 4 ++++ rocclr/runtime/device/rocm/roccompiler.cpp | 2 ++ rocclr/runtime/device/rocm/rocdevice.cpp | 10 ++++++++++ rocclr/runtime/device/rocm/rockernel.cpp | 7 ++++++- rocclr/runtime/device/rocm/rockernel.hpp | 2 ++ rocclr/runtime/device/rocm/rocprogram.cpp | 11 ++++++++++- rocclr/runtime/device/rocm/rocprogram.hpp | 2 ++ rocclr/runtime/platform/program.cpp | 4 ++++ 8 files changed, 40 insertions(+), 2 deletions(-) diff --git a/rocclr/runtime/device/device.cpp b/rocclr/runtime/device/device.cpp index b8c1d362d3..ec060bcb63 100644 --- a/rocclr/runtime/device/device.cpp +++ b/rocclr/runtime/device/device.cpp @@ -1232,6 +1232,7 @@ bool Program::setBinary(const char* binaryIn, size_t size) { } bool Program::createBIFBinary(aclBinary* bin) { +#if defined(WITH_COMPILER_LIB) acl_error err; char* binaryIn = NULL; size_t size; @@ -1243,6 +1244,9 @@ bool Program::createBIFBinary(aclBinary* bin) { clBinary()->saveBIFBinary(binaryIn, size); aclFreeMem(bin, binaryIn); return true; +#else // !defined(WITH_COMPILER_LIB) + return false; +#endif // !defined(WITH_COMPILER_LIB) } ClBinary::ClBinary(const amd::Device& dev, BinaryImageFormat bifVer) diff --git a/rocclr/runtime/device/rocm/roccompiler.cpp b/rocclr/runtime/device/rocm/roccompiler.cpp index d66213945d..6c10254e71 100644 --- a/rocclr/runtime/device/rocm/roccompiler.cpp +++ b/rocclr/runtime/device/rocm/roccompiler.cpp @@ -46,6 +46,7 @@ static void logFunction(const char* msg, size_t size) { static int programsCount = 0; +#if defined(WITH_COMPILER_LIB) bool HSAILProgram::compileImpl(const std::string& sourceCode, const std::vector& headers, const char** headerIncludeNames, amd::option::Options* options) { @@ -160,6 +161,7 @@ bool HSAILProgram::compileImpl(const std::string& sourceCode, saveBinaryAndSetType(TYPE_COMPILED); return true; } +#endif // defined(WITH_COMPILER_LIB) #if defined(WITH_LIGHTNING_COMPILER) bool LightningProgram::compileImpl(const std::string& sourceCode, diff --git a/rocclr/runtime/device/rocm/rocdevice.cpp b/rocclr/runtime/device/rocm/rocdevice.cpp index 04a011d275..673d217c5e 100644 --- a/rocclr/runtime/device/rocm/rocdevice.cpp +++ b/rocclr/runtime/device/rocm/rocdevice.cpp @@ -190,6 +190,7 @@ Device::~Device() { } } bool NullDevice::initCompiler(bool isOffline) { +#if defined(WITH_COMPILER_LIB) // Initialize the compiler handle if has already not been initialized // This is destroyed in Device::teardown acl_error error; @@ -207,10 +208,12 @@ bool NullDevice::initCompiler(bool isOffline) { #endif // !defined(WITH_LIGHTNING_COMPILER) } } +#endif // defined(WITH_COMPILER_LIB) return true; } bool NullDevice::destroyCompiler() { +#if defined(WITH_COMPILER_LIB) if (compilerHandle_ != nullptr) { acl_error error = aclCompilerFini(compilerHandle_); if (error != ACL_SUCCESS) { @@ -218,6 +221,7 @@ bool NullDevice::destroyCompiler() { return false; } } +#endif // defined(WITH_COMPILER_LIB) return true; } @@ -665,7 +669,11 @@ 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* Device::createProgram(amd::option::Options* options) { @@ -674,7 +682,9 @@ device::Program* Device::createProgram(amd::option::Options* options) { return new roc::LightningProgram(*this); } #endif // defined(WITH_LIGHTNING_COMPILER) +#if defined(WITH_COMPILER_LIB) return new roc::HSAILProgram(*this); +#endif // defined(WITH_COMPILER_LIB) } 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 56fcf2e651..085379c188 100644 --- a/rocclr/runtime/device/rocm/rockernel.cpp +++ b/rocclr/runtime/device/rocm/rockernel.cpp @@ -498,6 +498,7 @@ static inline cl_kernel_arg_type_qualifier GetOclTypeQual(const aclArgData* argI return rv; } +#if defined(WITH_COMPILER_LIB) void HSAILKernel::initArguments(const aclArgData* aclArg) { device::Kernel::parameters_t params; @@ -560,6 +561,7 @@ void HSAILKernel::initArguments(const aclArgData* aclArg) { } createSignature(params); } +#endif // defined(WITH_COMPILER_LIB) #if defined(WITH_LIGHTNING_COMPILER) void LightningKernel::initArguments(const KernelMD& kernelMD) { @@ -726,6 +728,7 @@ bool LightningKernel::init() { } #endif // defined(WITH_LIGHTNING_COMPILER) +#if defined(WITH_COMPILER_LIB) bool HSAILKernel::init() { acl_error errorCode; // compile kernel down to ISA @@ -830,6 +833,7 @@ bool HSAILKernel::init() { } return true; } +#endif // defined(WITH_COMPILER_LIB) #if defined(WITH_LIGHTNING_COMPILER) void LightningKernel::initPrintf(const std::vector& printfInfoStrings) { @@ -923,6 +927,7 @@ void LightningKernel::initPrintf(const std::vector& printfInfoStrin } #endif // defined(WITH_LIGHTNING_COMPILER) +#if defined(WITH_COMPILER_LIB) void HSAILKernel::initPrintf(const aclPrintfFmt* aclPrintf) { PrintfInfo info; uint index = 0; @@ -986,7 +991,7 @@ void HSAILKernel::initPrintf(const aclPrintfFmt* aclPrintf) { info.arguments_.clear(); } } - +#endif // defined(WITH_COMPILER_LIB) Kernel::~Kernel() { while (!hsailArgList_.empty()) { diff --git a/rocclr/runtime/device/rocm/rockernel.hpp b/rocclr/runtime/device/rocm/rockernel.hpp index 39f4be559b..782ca66c4e 100644 --- a/rocclr/runtime/device/rocm/rockernel.hpp +++ b/rocclr/runtime/device/rocm/rockernel.hpp @@ -148,6 +148,7 @@ class Kernel : public device::Kernel { std::vector printf_; }; +#if defined(WITH_COMPILER_LIB) class HSAILKernel : public roc::Kernel { public: HSAILKernel(std::string name, Program* prog, const uint64_t& kernelCodeHandle, @@ -169,6 +170,7 @@ class HSAILKernel : public roc::Kernel { //! Initializes HSAIL Printf metadata and info void initPrintf(const aclPrintfFmt* aclPrintf); }; +#endif // defined(WITH_COMPILER_LIB) #if defined(WITH_LIGHTNING_COMPILER) class LightningKernel : public roc::Kernel { diff --git a/rocclr/runtime/device/rocm/rocprogram.cpp b/rocclr/runtime/device/rocm/rocprogram.cpp index 2218e3ae8c..b7b72e3bea 100644 --- a/rocclr/runtime/device/rocm/rocprogram.cpp +++ b/rocclr/runtime/device/rocm/rocprogram.cpp @@ -190,6 +190,7 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options binary_t binary = this->binary(); // If the binary already exists if ((binary.first != nullptr) && (binary.second > 0)) { +#if defined(WITH_COMPILER_LIB) if (aclValidateBinaryImage(binary.first, binary.second, BINARY_TYPE_ELF)) { acl_error errorCode; binaryElf_ = aclReadFromMem(binary.first, binary.second, &errorCode); @@ -198,6 +199,7 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options return continueCompileFrom; } } +#endif // defined(WITH_COMPILER_LIB) // save the current options std::string sCurCompileOptions = compileOptions_; @@ -227,6 +229,7 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options if (compileOptions_.empty()) break; std::string sBinOptions; +#if defined(WITH_COMPILER_LIB) if (binaryElf_ != nullptr) { const oclBIFSymbolStruct* symbol = findBIF30SymStruct(symOpenclCompilerOptions); assert(symbol && "symbol not found"); @@ -242,7 +245,9 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options break; } sBinOptions = std::string((char*)opts, symSize); - } else { + } else +#endif // defined(WITH_COMPILER_LIB) + { sBinOptions = sCurOptions; } @@ -282,6 +287,7 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options return continueCompileFrom; } +#if defined(WITH_COMPILER_LIB) std::string HSAILProgram::codegenOptions(amd::option::Options* options) { std::string optionsStr; @@ -294,6 +300,7 @@ std::string HSAILProgram::codegenOptions(amd::option::Options* options) { return optionsStr; } +#endif // defined(WITH_COMPILER_LIB) std::string Program::preprocessorOptions(amd::option::Options* options) { std::string optionsStr; @@ -368,6 +375,7 @@ std::string Program::preprocessorOptions(amd::option::Options* options) { return optionsStr; } +#if defined(WITH_COMPILER_LIB) HSAILProgram::HSAILProgram(roc::NullDevice& device) : roc::Program(device) { } @@ -816,6 +824,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { buildLog_ += aclGetCompilerLog(device().compiler()); return true; } +#endif // defined(WITH_COMPILER_LIB) #if defined(WITH_LIGHTNING_COMPILER) LightningProgram::LightningProgram(roc::NullDevice& device) : roc::Program(device) { diff --git a/rocclr/runtime/device/rocm/rocprogram.hpp b/rocclr/runtime/device/rocm/rocprogram.hpp index e1154014c3..188cef4c0e 100644 --- a/rocclr/runtime/device/rocm/rocprogram.hpp +++ b/rocclr/runtime/device/rocm/rocprogram.hpp @@ -122,6 +122,7 @@ 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); @@ -149,6 +150,7 @@ private: bool saveBinaryAndSetType(type_t type); }; +#endif // defined(WITH_COMPILER_LIB) #if defined(WITH_LIGHTNING_COMPILER) class LightningProgram : public roc::Program { diff --git a/rocclr/runtime/platform/program.cpp b/rocclr/runtime/platform/program.cpp index 2c0b3c3039..e5e987fff5 100644 --- a/rocclr/runtime/platform/program.cpp +++ b/rocclr/runtime/platform/program.cpp @@ -76,6 +76,7 @@ cl_int Program::addDeviceProgram(Device& device, const void* image, size_t lengt emptyOptions = true; } +#if defined(WITH_COMPILER_LIB) if (image != NULL && length != 0 && aclValidateBinaryImage(image, length, BINARY_TYPE_ELF)) { acl_error errorCode; aclBinary* binary = aclReadFromMem(image, length, &errorCode); @@ -102,6 +103,7 @@ cl_int Program::addDeviceProgram(Device& device, const void* image, size_t lengt isHSAILTarget(*aclutGetTargetInfo(binary)); aclBinaryFini(binary); } +#endif // defined(WITH_COMPILER_LIB) options->oVariables->BinaryIsSpirv = isSPIRV_; device::Program* program = rootDev.createProgram(options); if (program == NULL) { @@ -296,6 +298,7 @@ cl_int Program::link(const std::vector& devices, size_t numInputs, // Check the binary's target for the first found device program. // TODO: Revise these binary's target checks // and possibly remove them after switching to HSAIL by default. +#if defined(WITH_COMPILER_LIB) if (!found && binary.first != NULL && binary.second > 0 && aclValidateBinaryImage(binary.first, binary.second, BINARY_TYPE_ELF)) { acl_error errorCode = ACL_SUCCESS; @@ -315,6 +318,7 @@ cl_int Program::link(const std::vector& devices, size_t numInputs, } aclBinaryFini(aclBin); } +#endif // defined(WITH_COMPILER_LIB) found = true; } if (inputDevPrograms.size() == 0) {