From c7b50bb8907c00faee152dccf5be7d1f888e44f9 Mon Sep 17 00:00:00 2001 From: Vladislav Sytchenko Date: Tue, 13 Apr 2021 11:36:32 -0400 Subject: [PATCH] SWDEV-280473 - Support HSAIL shared library build This change makes HSAIL usage similar to that of Comgr. By default, the runtime will statically link against it, however if HSAIL_DYN_DLL is defined, then the runtime will try to dynamically load HSAIL. Currently stick to statically linking to HSAIL. In a feature patch the dynamic loading behaviour will be enabled. Change-Id: I6a78a4375975cf847f236b200404c8cf941d012b --- rocclr/CMakeLists.txt | 9 +- rocclr/device/device.cpp | 12 ++ rocclr/device/device.hpp | 5 +- rocclr/device/devkernel.cpp | 2 +- rocclr/device/devprogram.cpp | 96 ++++----- rocclr/device/gpu/gpubinary.cpp | 2 +- rocclr/device/gpu/gpucompiler.cpp | 44 ++--- rocclr/device/gpu/gpudebugger.hpp | 2 +- rocclr/device/gpu/gpudevice.cpp | 20 +- rocclr/device/gpu/gpudevice.hpp | 2 +- rocclr/device/gpu/gpukernel.cpp | 88 ++++----- rocclr/device/gpu/gpuprogram.cpp | 60 +++--- rocclr/device/gpu/gpuscsi.cpp | 2 +- rocclr/device/hsailctx.cpp | 98 ++++++++++ rocclr/device/hsailctx.hpp | 314 ++++++++++++++++++++++++++++++ rocclr/device/pal/paldevice.cpp | 18 +- rocclr/device/pal/palkernel.cpp | 60 +++--- rocclr/device/pal/palprogram.cpp | 20 +- rocclr/platform/program.cpp | 22 ++- 19 files changed, 662 insertions(+), 214 deletions(-) create mode 100644 rocclr/device/hsailctx.cpp create mode 100644 rocclr/device/hsailctx.hpp diff --git a/rocclr/CMakeLists.txt b/rocclr/CMakeLists.txt index 076b3c01f5..4a6f03e259 100644 --- a/rocclr/CMakeLists.txt +++ b/rocclr/CMakeLists.txt @@ -151,8 +151,6 @@ else () add_subdirectory(device/rocm) endif() -set(COMGR_CPP device/comgrctx.cpp) - set(oclruntime_src thread/thread.cpp thread/monitor.cpp @@ -170,6 +168,8 @@ set(oclruntime_src device/devhcprintf.cpp device/devhcmessages.cpp device/devhostcall.cpp + device/comgrctx.cpp + device/hsailctx.cpp platform/activity.cpp platform/kernel.cpp platform/context.cpp @@ -186,11 +186,9 @@ set(oclruntime_src os/os_posix.cpp compiler/lib/utils/options.cpp elf/elf.cpp - #${CMAKE_CURRENT_SOURCE_DIR}/compiler/tools/caching/cache.cpp ) -add_library(amdrocclr_static STATIC - ${oclruntime_src} ${COMGR_CPP}) +add_library(amdrocclr_static STATIC ${oclruntime_src}) set_target_properties(amdrocclr_static PROPERTIES POSITION_INDEPENDENT_CODE ON) @@ -199,6 +197,7 @@ target_include_directories(amdrocclr_static $ $ $ + $ $ $ $ diff --git a/rocclr/device/device.cpp b/rocclr/device/device.cpp index d997fd4264..2d462e952d 100644 --- a/rocclr/device/device.cpp +++ b/rocclr/device/device.cpp @@ -477,6 +477,18 @@ bool Device::ValidateComgr() { return true; } +bool Device::ValidateHsail() { +#if defined(WITH_COMPILER_LIB) + // Check if HSAIL compiler was requested + if (!settings_->useLightning_) { + std::call_once(amd::Hsail::initialized, amd::Hsail::LoadLib); + // Use Hsail only if it's available + return amd::Hsail::IsReady(); + } +#endif + return true; +} + bool Device::create(const Isa &isa) { assert(!vaCacheAccess_ && !vaCacheMap_); isa_ = &isa; diff --git a/rocclr/device/device.hpp b/rocclr/device/device.hpp index 08ba24d693..6cad0c696a 100644 --- a/rocclr/device/device.hpp +++ b/rocclr/device/device.hpp @@ -35,7 +35,7 @@ #include "devkernel.hpp" #include "amdocl/cl_profile_amd.h" #if defined(WITH_COMPILER_LIB) -#include "acl.h" +#include "hsailctx.hpp" #endif #include "hwdebug.hpp" #include "devsignal.hpp" @@ -1762,6 +1762,9 @@ class Device : public RuntimeObject { //! Checks if OCL runtime can use code object manager for compilation bool ValidateComgr(); + //! Checks if OCL runtime can use hsail for compilation + bool ValidateHsail(); + virtual bool IpcCreate(void* dev_ptr, size_t* mem_size, void* handle, size_t* mem_offset) const { ShouldNotReachHere(); return false; diff --git a/rocclr/device/devkernel.cpp b/rocclr/device/devkernel.cpp index 965c268801..c8079ec9ef 100644 --- a/rocclr/device/devkernel.cpp +++ b/rocclr/device/devkernel.cpp @@ -35,7 +35,7 @@ #include #if defined(WITH_COMPILER_LIB) -#include "acl.h" +#include "hsailctx.hpp" #endif namespace device { diff --git a/rocclr/device/devprogram.cpp b/rocclr/device/devprogram.cpp index 281040cb86..79cb22eb37 100644 --- a/rocclr/device/devprogram.cpp +++ b/rocclr/device/devprogram.cpp @@ -47,7 +47,7 @@ #if defined(WITH_COMPILER_LIB) #include "spirv/spirvUtils.h" -#include "acl.h" +#include "hsailctx.hpp" #endif #ifdef EARLY_INLINE @@ -786,7 +786,7 @@ bool Program::compileImplHSAIL(const std::string& sourceCode, LogPrintfError("HSAIL compiler does not support %s", device().isa().targetId()); return false; } - target = aclGetTargetInfo(arch, hsailName, &errorCode); + target = amd::Hsail::GetTargetInfo(arch, hsailName, &errorCode); // end if asic info is ready // We dump the source code for each program (param: headers) @@ -829,7 +829,7 @@ bool Program::compileImplHSAIL(const std::string& sourceCode, } // Create Binary - binaryElf_ = aclBinaryInit(sizeof(aclBinary), &target, &binOpts_, &errorCode); + binaryElf_ = amd::Hsail::BinaryInit(sizeof(aclBinary), &target, &binOpts_, &errorCode); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: aclBinary init failure\n"; LogWarning("aclBinaryInit failed"); @@ -837,7 +837,7 @@ bool Program::compileImplHSAIL(const std::string& sourceCode, } // Insert opencl into binary - errorCode = aclInsertSection(device().compiler(), binaryElf_, sourceCode.c_str(), + errorCode = amd::Hsail::InsertSection(device().compiler(), binaryElf_, sourceCode.c_str(), strlen(sourceCode.c_str()), aclSOURCE); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Inserting openCl Source to binary\n"; @@ -860,9 +860,9 @@ bool Program::compileImplHSAIL(const std::string& sourceCode, // Compile source to IR compileOptions_.append(ProcessOptionsFlattened(options)); - errorCode = aclCompile(device().compiler(), binaryElf_, compileOptions_.c_str(), ACL_TYPE_OPENCL, + errorCode = amd::Hsail::Compile(device().compiler(), binaryElf_, compileOptions_.c_str(), ACL_TYPE_OPENCL, ACL_TYPE_LLVMIR_BINARY, nullptr /* logFunction */); - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); if (errorCode != ACL_SUCCESS) { LogWarning("aclCompile failed"); buildLog_ += "Error: Compiling CL to IR\n"; @@ -1017,7 +1017,7 @@ bool Program::linkImplHSAIL(const std::vector& inputPrograms, // We cannot do this at present because we need at least // Hsail text to pull the kernels oout void* mem = const_cast(binary.first); - binaryElf_ = aclReadFromMem(mem, binary.second, &errorCode); + binaryElf_ = amd::Hsail::ReadFromMem(mem, binary.second, &errorCode); if (errorCode != ACL_SUCCESS) { LogWarning("Error while linking : Could not read from raw binary"); return false; @@ -1028,22 +1028,22 @@ bool Program::linkImplHSAIL(const std::vector& inputPrograms, // Check if LLVMIR is in the binary size_t boolSize = sizeof(bool); bool containsLLLVMIR = false; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_LLVMIR, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_LLVMIR, nullptr, &containsLLLVMIR, &boolSize); if (errorCode != ACL_SUCCESS || !containsLLLVMIR) { bool spirv = false; size_t boolSize = sizeof(bool); - errorCode = aclQueryInfo( + errorCode = amd::Hsail::QueryInfo( device().compiler(), binaryElf_, RT_CONTAINS_SPIRV, nullptr, &spirv, &boolSize); if (errorCode != ACL_SUCCESS) { spirv = false; } if (spirv) { - errorCode = aclCompile( + errorCode = amd::Hsail::Compile( device().compiler(), binaryElf_, options->origOptionStr.c_str(), ACL_TYPE_SPIRV_BINARY, ACL_TYPE_LLVMIR_BINARY, nullptr); - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error while linking: Could not load SPIR-V"; return false; @@ -1055,16 +1055,16 @@ bool Program::linkImplHSAIL(const std::vector& inputPrograms, } } // Create a new aclBinary for each LLVMIR and save it in a list - aclBIFVersion ver = aclBinaryVersion(binaryElf_); - aclBinary* bin = aclCreateFromBinary(binaryElf_, ver); + aclBIFVersion ver = amd::Hsail::BinaryVersion(binaryElf_); + aclBinary* bin = amd::Hsail::CreateFromBinary(binaryElf_, ver); binaries_to_link.push_back(bin); } - errorCode = aclLink(device().compiler(), binaries_to_link[0], binaries_to_link.size() - 1, + errorCode = amd::Hsail::Link(device().compiler(), binaries_to_link[0], binaries_to_link.size() - 1, binaries_to_link.size() > 1 ? &binaries_to_link[1] : nullptr, ACL_TYPE_LLVMIR_BINARY, "-create-library", nullptr); if (errorCode != ACL_SUCCESS) { - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); buildLog_ += "Error while linking : aclLink failed"; return false; } @@ -1072,11 +1072,11 @@ bool Program::linkImplHSAIL(const std::vector& inputPrograms, binaryElf_ = binaries_to_link[0]; // Free all the other aclBinaries for (size_t i = 1; i < binaries_to_link.size(); i++) { - aclBinaryFini(binaries_to_link[i]); + amd::Hsail::BinaryFini(binaries_to_link[i]); } if (createLibrary) { saveBinaryAndSetType(TYPE_LIBRARY); - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); return true; } @@ -1325,9 +1325,9 @@ bool Program::linkImplHSAIL(amd::option::Options* options) { case ACL_TYPE_HSAIL_TEXT: { std::string curOptions = options->origOptionStr + ProcessOptionsFlattened(options); - errorCode = aclCompile(device().compiler(), binaryElf_, curOptions.c_str(), + errorCode = amd::Hsail::Compile(device().compiler(), binaryElf_, curOptions.c_str(), continueCompileFrom, ACL_TYPE_CG, logFunction); - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error while BRIG Codegen phase: compilation error \n"; return false; @@ -1364,9 +1364,9 @@ bool Program::linkImplHSAIL(amd::option::Options* options) { fin_options.append(" -xnack"); } - errorCode = aclCompile(device().compiler(), binaryElf_, fin_options.c_str(), ACL_TYPE_CG, + errorCode = amd::Hsail::Compile(device().compiler(), binaryElf_, fin_options.c_str(), ACL_TYPE_CG, ACL_TYPE_ISA, logFunction); - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: BRIG finalization to ISA failed.\n"; return false; @@ -1374,7 +1374,7 @@ bool Program::linkImplHSAIL(amd::option::Options* options) { } size_t binSize; - void* binary = const_cast(aclExtractSection( + void* binary = const_cast(amd::Hsail::ExtractSection( device().compiler(), binaryElf_, &binSize, aclTEXT, &errorCode)); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: cannot extract ISA from compiled binary.\n"; @@ -1389,7 +1389,7 @@ bool Program::linkImplHSAIL(amd::option::Options* options) { // Save the binary in the interface class saveBinaryAndSetType(TYPE_EXECUTABLE); - buildLog_ += aclGetCompilerLog(device().compiler()); + buildLog_ += amd::Hsail::GetCompilerLog(device().compiler()); return true; #else @@ -1985,38 +1985,38 @@ bool Program::initClBinary(const char* binaryIn, size_t size, amd::Os::FileDesc binOpts.bitness = ELFDATA2LSB; binOpts.alloc = &::malloc; binOpts.dealloc = &::free; - aclBinary* aclbin_v30 = aclBinaryInit(sizeof(aclBinary), &info(), &binOpts, &err); + aclBinary* aclbin_v30 = amd::Hsail::BinaryInit(sizeof(aclBinary), &info(), &binOpts, &err); if (err != ACL_SUCCESS) { LogWarning("aclBinaryInit failed"); - aclBinaryFini(aclbin_v30); + amd::Hsail::BinaryFini(aclbin_v30); return false; } - err = aclInsertSection(device().compiler(), aclbin_v30, binaryIn, size, - isSPIRV ? aclSPIRV : aclSPIR); + err = amd::Hsail::InsertSection(device().compiler(), aclbin_v30, binaryIn, size, + isSPIRV ? aclSPIRV : aclSPIR); if (ACL_SUCCESS != err) { LogWarning("aclInsertSection failed"); - aclBinaryFini(aclbin_v30); + amd::Hsail::BinaryFini(aclbin_v30); return false; } if (info().arch_id == aclHSAIL || info().arch_id == aclHSAIL64) { - err = aclWriteToMem(aclbin_v30, (void**)const_cast(&bin), &sz); + err = amd::Hsail::WriteToMem(aclbin_v30, (void**)const_cast(&bin), &sz); if (err != ACL_SUCCESS) { LogWarning("aclWriteToMem failed"); - aclBinaryFini(aclbin_v30); + amd::Hsail::BinaryFini(aclbin_v30); return false; } - aclBinaryFini(aclbin_v30); + amd::Hsail::BinaryFini(aclbin_v30); } else { - aclBinary* aclbin_v21 = aclCreateFromBinary(aclbin_v30, aclBIFVersion21); - err = aclWriteToMem(aclbin_v21, (void**)const_cast(&bin), &sz); + aclBinary* aclbin_v21 = amd::Hsail::CreateFromBinary(aclbin_v30, aclBIFVersion21); + err = amd::Hsail::WriteToMem(aclbin_v21, (void**)const_cast(&bin), &sz); if (err != ACL_SUCCESS) { LogWarning("aclWriteToMem failed"); - aclBinaryFini(aclbin_v30); - aclBinaryFini(aclbin_v21); + amd::Hsail::BinaryFini(aclbin_v30); + amd::Hsail::BinaryFini(aclbin_v21); return false; } - aclBinaryFini(aclbin_v30); - aclBinaryFini(aclbin_v21); + amd::Hsail::BinaryFini(aclbin_v30); + amd::Hsail::BinaryFini(aclbin_v21); } #endif // defined(WITH_COMPILER_LIB) } else { @@ -2161,7 +2161,7 @@ Program::file_type_t Program::getCompilationStagesFromBinary( size_t boolSize = sizeof(bool); // Checking llvmir in .llvmir section bool containsSpirv = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_SPIRV, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_SPIRV, nullptr, &containsSpirv, &boolSize); if (errorCode != ACL_SUCCESS) { containsSpirv = false; @@ -2171,7 +2171,7 @@ Program::file_type_t Program::getCompilationStagesFromBinary( from = FILE_TYPE_SPIRV_BINARY; } bool containsSpirText = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_SPIR, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_SPIR, nullptr, &containsSpirText, &boolSize); if (errorCode != ACL_SUCCESS) { containsSpirText = false; @@ -2181,14 +2181,14 @@ Program::file_type_t Program::getCompilationStagesFromBinary( from = FILE_TYPE_SPIR_BINARY; } bool containsLlvmirText = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_LLVMIR, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_LLVMIR, nullptr, &containsLlvmirText, &boolSize); if (errorCode != ACL_SUCCESS) { containsLlvmirText = false; } // Checking compile & link options in .comment section bool containsOpts = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_OPTIONS, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_OPTIONS, nullptr, &containsOpts, &boolSize); if (errorCode != ACL_SUCCESS) { containsOpts = false; @@ -2199,14 +2199,14 @@ Program::file_type_t Program::getCompilationStagesFromBinary( } // Checking HSAIL in .cg section bool containsHsailText = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_HSAIL, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_HSAIL, nullptr, &containsHsailText, &boolSize); if (errorCode != ACL_SUCCESS) { containsHsailText = false; } // Checking BRIG sections bool containsBrig = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_BRIG, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_BRIG, nullptr, &containsBrig, &boolSize); if (errorCode != ACL_SUCCESS) { containsBrig = false; @@ -2221,7 +2221,7 @@ Program::file_type_t Program::getCompilationStagesFromBinary( } // Checking Loader Map symbol from CG section bool containsLoaderMap = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_LOADER_MAP, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_LOADER_MAP, nullptr, &containsLoaderMap, &boolSize); if (errorCode != ACL_SUCCESS) { containsLoaderMap = false; @@ -2232,7 +2232,7 @@ Program::file_type_t Program::getCompilationStagesFromBinary( } // Checking ISA in .text section bool containsShaderIsa = true; - errorCode = aclQueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_ISA, nullptr, + errorCode = amd::Hsail::QueryInfo(device().compiler(), binaryElf_, RT_CONTAINS_ISA, nullptr, &containsShaderIsa, &boolSize); if (errorCode != ACL_SUCCESS) { containsShaderIsa = false; @@ -2290,9 +2290,9 @@ Program::file_type_t Program::getNextCompilationStageFromBinary(amd::option::Opt // 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)) { + if (amd::Hsail::ValidateBinaryImage(binary.first, binary.second, BINARY_TYPE_ELF)) { acl_error errorCode; - binaryElf_ = aclReadFromMem(binary.first, binary.second, &errorCode); + binaryElf_ = amd::Hsail::ReadFromMem(binary.first, binary.second, &errorCode); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error while BRIG Codegen phase: aclReadFromMem failure \n"; return continueCompileFrom; @@ -2338,7 +2338,7 @@ Program::file_type_t Program::getNextCompilationStageFromBinary(amd::option::Opt size_t symSize = 0; acl_error errorCode; - const void* opts = aclExtractSymbol(device().compiler(), binaryElf_, &symSize, + const void* opts = amd::Hsail::ExtractSymbol(device().compiler(), binaryElf_, &symSize, aclCOMMENT, symName.c_str(), &errorCode); if (errorCode != ACL_SUCCESS) { recompile = true; diff --git a/rocclr/device/gpu/gpubinary.cpp b/rocclr/device/gpu/gpubinary.cpp index fb5e5d0eda..69b89a34dd 100644 --- a/rocclr/device/gpu/gpubinary.cpp +++ b/rocclr/device/gpu/gpubinary.cpp @@ -66,7 +66,7 @@ bool ClBinary::loadKernels(NullProgram& program, bool* hasRecompiled) { if (platform == amd::Elf::COMPLIB_PLATFORM) { // BIF 3.0 uint32_t flag; - aclTargetInfo tgtInfo = aclGetTargetInfo("amdil", nullptr, NULL); + aclTargetInfo tgtInfo = amd::Hsail::GetTargetInfo("amdil", nullptr, NULL); if (!elfIn()->getFlags(flag)) { LogError("The OCL binary image loading failed: incorrect format"); return false; diff --git a/rocclr/device/gpu/gpucompiler.cpp b/rocclr/device/gpu/gpucompiler.cpp index d399fd4821..3597aef408 100644 --- a/rocclr/device/gpu/gpucompiler.cpp +++ b/rocclr/device/gpu/gpucompiler.cpp @@ -123,16 +123,16 @@ bool NullProgram::compileImpl(const std::string& src, binOpts.alloc = &::malloc; binOpts.dealloc = &::free; - aclBinary* bin = aclBinaryInit(sizeof(aclBinary), &targInfo, &binOpts, &err); + aclBinary* bin = amd::Hsail::BinaryInit(sizeof(aclBinary), &targInfo, &binOpts, &err); if (err != ACL_SUCCESS) { LogWarning("aclBinaryInit failed"); return false; } if (ACL_SUCCESS != - aclInsertSection(gpuNullDevice().amdilCompiler(), bin, sourceCode.c_str(), sourceCode.size(), aclSOURCE)) { + amd::Hsail::InsertSection(gpuNullDevice().amdilCompiler(), bin, sourceCode.c_str(), sourceCode.size(), aclSOURCE)) { LogWarning("aclInsertSection failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } @@ -206,28 +206,28 @@ bool NullProgram::compileImpl(const std::string& src, pos = newOpt.find("-fno-bin-llvmir"); } - err = aclCompile(gpuNullDevice().amdilCompiler(), bin, newOpt.c_str(), ACL_TYPE_OPENCL, ACL_TYPE_LLVMIR_BINARY, - NULL); + err = amd::Hsail::Compile(gpuNullDevice().amdilCompiler(), bin, newOpt.c_str(), ACL_TYPE_OPENCL, ACL_TYPE_LLVMIR_BINARY, + NULL); - buildLog_ += aclGetCompilerLog(gpuNullDevice().amdilCompiler()); + buildLog_ += amd::Hsail::GetCompilerLog(gpuNullDevice().amdilCompiler()); if (err != ACL_SUCCESS) { LogWarning("aclCompile failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } size_t len = 0; - const void* ir = aclExtractSection(gpuNullDevice().amdilCompiler(), bin, &len, aclLLVMIR, &err); + const void* ir = amd::Hsail::ExtractSection(gpuNullDevice().amdilCompiler(), bin, &len, aclLLVMIR, &err); if (err != ACL_SUCCESS) { LogWarning("aclExtractSection failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } llvmBinary_.assign(reinterpret_cast(ir), len); elfSectionType_ = amd::Elf::LLVMIR; - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); for (size_t i = 0; i < headerFileNames.size(); ++i) { amd::Os::unlink(headerFileNames[i].c_str()); @@ -263,7 +263,7 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) { binOpts.alloc = &::malloc; binOpts.dealloc = &::free; - aclBinary* bin = aclBinaryInit(sizeof(aclBinary), &targInfo, &binOpts, &err); + aclBinary* bin = amd::Hsail::BinaryInit(sizeof(aclBinary), &targInfo, &binOpts, &err); if (err != ACL_SUCCESS) { LogWarning("aclBinaryInit failed"); return CL_BUILD_PROGRAM_FAILURE; @@ -284,9 +284,9 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) { } if (ACL_SUCCESS != - aclInsertSection(gpuNullDevice().amdilCompiler(), bin, llvmBinary_.data(), llvmBinary_.size(), spirFlag)) { + amd::Hsail::InsertSection(gpuNullDevice().amdilCompiler(), bin, llvmBinary_.data(), llvmBinary_.size(), spirFlag)) { LogWarning("aclInsertSection failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return CL_BUILD_PROGRAM_FAILURE; } @@ -308,12 +308,12 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) { type = ACL_TYPE_ISA; } - err = aclCompile(gpuNullDevice().amdilCompiler(), bin, optionStr.c_str(), aclTypeBinaryUsed, type, NULL); - buildLog_ += aclGetCompilerLog(gpuNullDevice().amdilCompiler()); + err = amd::Hsail::Compile(gpuNullDevice().amdilCompiler(), bin, optionStr.c_str(), aclTypeBinaryUsed, type, NULL); + buildLog_ += amd::Hsail::GetCompilerLog(gpuNullDevice().amdilCompiler()); if (err != ACL_SUCCESS) { LogWarning("aclCompile failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return CL_BUILD_PROGRAM_FAILURE; } @@ -321,26 +321,26 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) { acl_error err; char* binaryIn = nullptr; size_t size; - err = aclWriteToMem(bin, reinterpret_cast(&binaryIn), &size); + err = amd::Hsail::WriteToMem(bin, reinterpret_cast(&binaryIn), &size); if (err != ACL_SUCCESS) { LogWarning("aclWriteToMem failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return CL_BUILD_PROGRAM_FAILURE; } clBinary()->saveBIFBinary(binaryIn, size); - aclFreeMem(bin, binaryIn); + amd::Hsail::FreeMem(bin, binaryIn); } size_t len = 0; - const void* amdil = aclExtractSection(gpuNullDevice().amdilCompiler(), bin, &len, aclCODEGEN, &err); + const void* amdil = amd::Hsail::ExtractSection(gpuNullDevice().amdilCompiler(), bin, &len, aclCODEGEN, &err); if (err != ACL_SUCCESS) { LogWarning("aclExtractSection failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return CL_BUILD_PROGRAM_FAILURE; } ilProgram_.assign(reinterpret_cast(amdil), len); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return CL_SUCCESS; } diff --git a/rocclr/device/gpu/gpudebugger.hpp b/rocclr/device/gpu/gpudebugger.hpp index 261406b03e..e0a28494ba 100644 --- a/rocclr/device/gpu/gpudebugger.hpp +++ b/rocclr/device/gpu/gpudebugger.hpp @@ -27,7 +27,7 @@ #include "amd_hsa_kernel_code.h" #include "device/device.hpp" #include "device/hwdebug.hpp" -#include "acl.h" +#include "hsailctx.hpp" static constexpr int NumberReserveVgprs = 4; diff --git a/rocclr/device/gpu/gpudevice.cpp b/rocclr/device/gpu/gpudevice.cpp index 7cc41e241b..37c574af86 100644 --- a/rocclr/device/gpu/gpudevice.cpp +++ b/rocclr/device/gpu/gpudevice.cpp @@ -35,7 +35,7 @@ #include "device/gpu/gpublit.hpp" #include "cz_id.h" -#include "acl.h" +#include "hsailctx.hpp" #include "vdi_common.hpp" #include "CL/cl_gl.h" @@ -256,6 +256,11 @@ bool NullDevice::create(const char* calName, const amd::Isa& isa, CALtarget targ return false; } + if (!ValidateHsail()) { + LogPrintfError("HSAIL initialization failed for offline CAL device %s", isa.targetId()); + return false; + } + gslMemInfo memInfo = {0}; // Report 512MB for all offline devices memInfo.cardMemAvailableBytes = 512 * Mi; @@ -274,7 +279,7 @@ bool NullDevice::create(const char* calName, const amd::Isa& isa, CALtarget targ sizeof(aclCompilerOptions_0_8), library, NULL, NULL, NULL, NULL, NULL, AMD_OCL_SC_LIB}; // Initialize the compiler handle acl_error error; - hsaCompiler_ = aclCompilerInit(&opts, &error); + hsaCompiler_ = amd::Hsail::CompilerInit(&opts, &error); if (error != ACL_SUCCESS) { LogPrintfError("Error initializing the compiler for offline CAL device %s", isa.targetId()); return false; @@ -945,6 +950,11 @@ bool Device::create(CALuint ordinal, CALuint numOfDevices) { return false; } + if (!ValidateHsail()) { + LogError("Hsail initialization failed!"); + return false; + } + engines_.create(m_nEngines, m_engines, settings().numComputeRings_); amd::Context::Info info = {0}; @@ -1022,7 +1032,7 @@ bool Device::create(CALuint ordinal, CALuint numOfDevices) { sizeof(aclCompilerOptions_0_8), library, NULL, NULL, NULL, NULL, NULL, AMD_OCL_SC_LIB}; // Initialize the compiler handle acl_error error; - hsaCompiler_ = aclCompilerInit(&opts, &error); + hsaCompiler_ = amd::Hsail::CompilerInit(&opts, &error); if (error != ACL_SUCCESS) { LogError("Error initializing the compiler"); return false; @@ -1271,9 +1281,9 @@ bool Device::init() { void Device::tearDown() { osExit(); gslExit(); - aclCompilerFini(compiler_); + amd::Hsail::CompilerFini(compiler_); if (hsaCompiler_ != NULL) { - aclCompilerFini(hsaCompiler_); + amd::Hsail::CompilerFini(hsaCompiler_); } } diff --git a/rocclr/device/gpu/gpudevice.hpp b/rocclr/device/gpu/gpudevice.hpp index 30693c716f..4eb61ca61b 100644 --- a/rocclr/device/gpu/gpudevice.hpp +++ b/rocclr/device/gpu/gpudevice.hpp @@ -39,7 +39,7 @@ #include -#include "acl.h" +#include "hsailctx.hpp" #include "vaminterface.h" /*! \addtogroup GPU diff --git a/rocclr/device/gpu/gpukernel.cpp b/rocclr/device/gpu/gpukernel.cpp index 06c1322dff..529ea54140 100644 --- a/rocclr/device/gpu/gpukernel.cpp +++ b/rocclr/device/gpu/gpukernel.cpp @@ -27,7 +27,7 @@ #include "shader/ComputeProgramObject.h" #include "utils/options.hpp" -#include "acl.h" +#include "hsailctx.hpp" #include "SCCommon.h" #include @@ -643,8 +643,8 @@ bool NullKernel::create(const std::string& code, const std::string& metadata, if ((binaryCode == NULL) && (binarySize == 0) && !code.empty()) { acl_error err; - aclTargetInfo info = aclGetTargetInfo(nullDev().settings().use64BitPtr_ ? "amdil64" : "amdil", - nullptr, &err); + aclTargetInfo info = amd::Hsail::GetTargetInfo(nullDev().settings().use64BitPtr_ ? "amdil64" : "amdil", + nullptr, &err); if (err != ACL_SUCCESS) { LogWarning("aclGetTargetInfo failed"); return false; @@ -657,16 +657,16 @@ bool NullKernel::create(const std::string& code, const std::string& metadata, binOpts.alloc = &::malloc; binOpts.dealloc = &::free; - aclBinary* bin = aclBinaryInit(sizeof(aclBinary), &info, &binOpts, &err); + aclBinary* bin = amd::Hsail::BinaryInit(sizeof(aclBinary), &info, &binOpts, &err); if (err != ACL_SUCCESS) { LogWarning("aclBinaryInit failed"); return false; } if (ACL_SUCCESS != - aclInsertSection(nullDev().amdilCompiler(), bin, code.data(), code.size(), aclSOURCE)) { + amd::Hsail::InsertSection(nullDev().amdilCompiler(), bin, code.data(), code.size(), aclSOURCE)) { LogWarning("aclInsertSection failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } @@ -684,37 +684,37 @@ bool NullKernel::create(const std::string& code, const std::string& metadata, // pass kernel name to compiler Opts->setCurrKernelName(name().c_str()); - err = aclCompile(nullDev().amdilCompiler(), bin, options->origOptionStr.c_str(), ACL_TYPE_AMDIL_TEXT, - ACL_TYPE_ISA, NULL); + err = amd::Hsail::Compile(nullDev().amdilCompiler(), bin, options->origOptionStr.c_str(), ACL_TYPE_AMDIL_TEXT, + ACL_TYPE_ISA, NULL); - buildLog_ += aclGetCompilerLog(nullDev().amdilCompiler()); + buildLog_ += amd::Hsail::GetCompilerLog(nullDev().amdilCompiler()); if (err != ACL_SUCCESS) { LogWarning("aclCompile failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } if (!options->oVariables->BinEXE) { // Early exit if binary doesn't contain EXE - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return true; } size_t len; - const void* isa = aclExtractSection(nullDev().amdilCompiler(), bin, &len, aclTEXT, &err); + const void* isa = amd::Hsail::ExtractSection(nullDev().amdilCompiler(), bin, &len, aclTEXT, &err); if (err != ACL_SUCCESS) { LogWarning("aclExtractSection failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } uint calImageSize; if (!createMultiBinary(&calImageSize, reinterpret_cast(&calImage), isa)) { LogWarning("initSrcEncoding failed"); - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); return false; } - aclBinaryFini(bin); + amd::Hsail::BinaryFini(bin); } else if ((binaryCode != NULL) && (binarySize != 0)) { uint size = 0; if (!amuABIMultiBinaryGetSize(&size, const_cast(binaryCode)) || size > binarySize) { @@ -3083,9 +3083,9 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (dev().settings().svmFineGrainSystem_) { options.append(" -sc-xnack-iommu"); } - error = aclCompile(dev().hsaCompiler(), prog().binaryElf(), options.c_str(), ACL_TYPE_CG, - ACL_TYPE_ISA, NULL); - buildLog_ += aclGetCompilerLog(dev().hsaCompiler()); + error = amd::Hsail::Compile(dev().hsaCompiler(), prog().binaryElf(), options.c_str(), ACL_TYPE_CG, + ACL_TYPE_ISA, NULL); + buildLog_ += amd::Hsail::GetCompilerLog(dev().hsaCompiler()); if (error != ACL_SUCCESS) { LogError("Failed to finalize kernel"); return false; @@ -3098,8 +3098,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { // Pull out metadata from the ELF size_t sizeOfArgList; - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, - openClKernelName.c_str(), NULL, &sizeOfArgList); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, + openClKernelName.c_str(), NULL, &sizeOfArgList); if (error != ACL_SUCCESS) { return false; } @@ -3108,20 +3108,20 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (NULL == aclArgList) { return false; } - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, - openClKernelName.c_str(), aclArgList, &sizeOfArgList); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, + openClKernelName.c_str(), aclArgList, &sizeOfArgList); if (error != ACL_SUCCESS) { return false; } size_t sizeOfWorkGroupSize; - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, - openClKernelName.c_str(), NULL, &sizeOfWorkGroupSize); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, + openClKernelName.c_str(), NULL, &sizeOfWorkGroupSize); if (error != ACL_SUCCESS) { return false; } - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, - openClKernelName.c_str(), workGroupInfo_.compileSize_, &sizeOfWorkGroupSize); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, + openClKernelName.c_str(), workGroupInfo_.compileSize_, &sizeOfWorkGroupSize); if (error != ACL_SUCCESS) { return false; } @@ -3139,8 +3139,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { // Pull out printf metadata from the ELF size_t sizeOfPrintfList; - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, - openClKernelName.c_str(), NULL, &sizeOfPrintfList); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, + openClKernelName.c_str(), NULL, &sizeOfPrintfList); if (error != ACL_SUCCESS) { return false; } @@ -3151,8 +3151,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (NULL == aclPrintfList) { return false; } - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, - openClKernelName.c_str(), aclPrintfList, &sizeOfPrintfList); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, + openClKernelName.c_str(), aclPrintfList, &sizeOfPrintfList); if (error != ACL_SUCCESS) { return false; } @@ -3165,8 +3165,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { aclMetadata md; md.enqueue_kernel = false; size_t sizeOfDeviceEnqueue = sizeof(md.enqueue_kernel); - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_DEVICE_ENQUEUE, - openClKernelName.c_str(), &md.enqueue_kernel, &sizeOfDeviceEnqueue); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_DEVICE_ENQUEUE, + openClKernelName.c_str(), &md.enqueue_kernel, &sizeOfDeviceEnqueue); if (error != ACL_SUCCESS) { return false; } @@ -3174,17 +3174,17 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { md.kernel_index = -1; size_t sizeOfIndex = sizeof(md.kernel_index); - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_KERNEL_INDEX, - openClKernelName.c_str(), &md.kernel_index, &sizeOfIndex); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_KERNEL_INDEX, + openClKernelName.c_str(), &md.kernel_index, &sizeOfIndex); if (error != ACL_SUCCESS) { return false; } index_ = md.kernel_index; size_t sizeOfWavesPerSimdHint = sizeof(workGroupInfo_.wavesPerSimdHint_); - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WAVES_PER_SIMD_HINT, - openClKernelName.c_str(), &workGroupInfo_.wavesPerSimdHint_, - &sizeOfWavesPerSimdHint); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WAVES_PER_SIMD_HINT, + openClKernelName.c_str(), &workGroupInfo_.wavesPerSimdHint_, + &sizeOfWavesPerSimdHint); if (error != ACL_SUCCESS) { return false; } @@ -3192,16 +3192,16 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { waveLimiter_.enable(dev().settings().ciPlus_); size_t sizeOfWorkGroupSizeHint = sizeof(workGroupInfo_.compileSizeHint_); - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE_HINT, - openClKernelName.c_str(), workGroupInfo_.compileSizeHint_, - &sizeOfWorkGroupSizeHint); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE_HINT, + openClKernelName.c_str(), workGroupInfo_.compileSizeHint_, + &sizeOfWorkGroupSizeHint); if (error != ACL_SUCCESS) { return false; } size_t sizeOfVecTypeHint; - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, - openClKernelName.c_str(), NULL, &sizeOfVecTypeHint); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, + openClKernelName.c_str(), NULL, &sizeOfVecTypeHint); if (error != ACL_SUCCESS) { return false; } @@ -3211,8 +3211,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (NULL == VecTypeHint) { return false; } - error = aclQueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, - openClKernelName.c_str(), VecTypeHint, &sizeOfVecTypeHint); + error = amd::Hsail::QueryInfo(dev().hsaCompiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, + openClKernelName.c_str(), VecTypeHint, &sizeOfVecTypeHint); if (error != ACL_SUCCESS) { return false; } diff --git a/rocclr/device/gpu/gpuprogram.cpp b/rocclr/device/gpu/gpuprogram.cpp index 07a7d8e78d..33fbe434c0 100644 --- a/rocclr/device/gpu/gpuprogram.cpp +++ b/rocclr/device/gpu/gpuprogram.cpp @@ -43,8 +43,8 @@ namespace gpu { const aclTargetInfo& NullProgram::info() { acl_error err; - info_ = aclGetTargetInfo(gpuNullDevice().settings().use64BitPtr_ ? "amdil64" : "amdil", - nullptr, &err); + info_ = amd::Hsail::GetTargetInfo(gpuNullDevice().settings().use64BitPtr_ ? "amdil64" : "amdil", + nullptr, &err); if (err != ACL_SUCCESS) { LogWarning("aclGetTargetInfo failed"); } @@ -473,7 +473,7 @@ bool NullProgram::linkImpl(const std::vector& inputPrograms, std::vector libs(llvmBinaries.size(), NULL); for (size_t i = 0; i < libs.size(); ++i) { - libs[i] = aclBinaryInit(sizeof(aclBinary), &aclinfo, &binOpts, &err); + libs[i] = amd::Hsail::BinaryInit(sizeof(aclBinary), &aclinfo, &binOpts, &err); if (err != ACL_SUCCESS) { LogWarning("aclBinaryInit failed"); break; @@ -487,8 +487,8 @@ bool NullProgram::linkImpl(const std::vector& inputPrograms, } else { aclTypeUsed = aclLLVMIR; } - err = aclInsertSection(gpuNullDevice().amdilCompiler(), libs[i], llvmBinaries[i]->data(), - llvmBinaries[i]->size(), aclTypeUsed); + err = amd::Hsail::InsertSection(gpuNullDevice().amdilCompiler(), libs[i], llvmBinaries[i]->data(), + llvmBinaries[i]->size(), aclTypeUsed); if (err != ACL_SUCCESS) { LogWarning("aclInsertSection failed"); break; @@ -504,10 +504,10 @@ bool NullProgram::linkImpl(const std::vector& inputPrograms, unsigned int numLibs = libs.size() - 1; if (numLibs > 0) { - err = aclLink(gpuNullDevice().amdilCompiler(), libs[0], numLibs, &libs[1], ACL_TYPE_LLVMIR_BINARY, - "-create-library", NULL); + err = amd::Hsail::Link(gpuNullDevice().amdilCompiler(), libs[0], numLibs, &libs[1], ACL_TYPE_LLVMIR_BINARY, + "-create-library", NULL); - buildLog_ += aclGetCompilerLog(gpuNullDevice().amdilCompiler()); + buildLog_ += amd::Hsail::GetCompilerLog(gpuNullDevice().amdilCompiler()); if (err != ACL_SUCCESS) { LogWarning("aclLink failed"); @@ -524,7 +524,7 @@ bool NullProgram::linkImpl(const std::vector& inputPrograms, } else { aclTypeUsed = aclLLVMIR; } - const void* llvmir = aclExtractSection(gpuNullDevice().amdilCompiler(), libs[0], &size, aclTypeUsed, &err); + const void* llvmir = amd::Hsail::ExtractSection(gpuNullDevice().amdilCompiler(), libs[0], &size, aclTypeUsed, &err); if (err != ACL_SUCCESS) { LogWarning("aclExtractSection failed"); break; @@ -534,7 +534,7 @@ bool NullProgram::linkImpl(const std::vector& inputPrograms, elfSectionType_ = amd::Elf::LLVMIR; } while (0); - std::for_each(libs.begin(), libs.end(), std::ptr_fun(aclBinaryFini)); + std::for_each(libs.begin(), libs.end(), std::ptr_fun(amd::Hsail::BinaryFini)); if (err != ACL_SUCCESS) { buildLog_ += "Error: linking llvm modules failed!"; @@ -1482,12 +1482,12 @@ HSAILProgram::~HSAILProgram() { delete it; } if (rawBinary_ != NULL) { - aclFreeMem(binaryElf_, rawBinary_); + amd::Hsail::FreeMem(binaryElf_, rawBinary_); } acl_error error; // Free the elf binary if (binaryElf_ != NULL) { - error = aclBinaryFini(binaryElf_); + error = amd::Hsail::BinaryFini(binaryElf_); if (error != ACL_SUCCESS) { LogWarning("Error while destroying the acl binary \n"); } @@ -1533,9 +1533,9 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { // 1. if the program is created with binary and contains only hsail text case ACL_TYPE_HSAIL_TEXT: { std::string curOptions = options->origOptionStr + hsailOptions(); - errorCode = aclCompile(gpuNullDevice().hsaCompiler(), binaryElf_, curOptions.c_str(), - continueCompileFrom, ACL_TYPE_CG, NULL); - buildLog_ += aclGetCompilerLog(gpuNullDevice().hsaCompiler()); + errorCode = amd::Hsail::Compile(gpuNullDevice().hsaCompiler(), binaryElf_, curOptions.c_str(), + continueCompileFrom, ACL_TYPE_CG, NULL); + buildLog_ += amd::Hsail::GetCompilerLog(gpuNullDevice().hsaCompiler()); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: BRIG code generation failed.\n"; return false; @@ -1560,9 +1560,9 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { if (gpuNullDevice().settings().svmFineGrainSystem_) { fin_options.append(" -sc-xnack-iommu"); } - errorCode = aclCompile(gpuNullDevice().hsaCompiler(), binaryElf_, fin_options.c_str(), ACL_TYPE_CG, - ACL_TYPE_ISA, NULL); - buildLog_ += aclGetCompilerLog(gpuNullDevice().hsaCompiler()); + errorCode = amd::Hsail::Compile(gpuNullDevice().hsaCompiler(), binaryElf_, fin_options.c_str(), ACL_TYPE_CG, + ACL_TYPE_ISA, NULL); + buildLog_ += amd::Hsail::GetCompilerLog(gpuNullDevice().hsaCompiler()); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: BRIG finalization to ISA failed.\n"; return false; @@ -1579,7 +1579,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { size_t size = 0; hsa_code_object_t code_object; code_object.handle = reinterpret_cast( - aclExtractSection(gpuNullDevice().hsaCompiler(), binaryElf_, &size, aclTEXT, &errorCode)); + amd::Hsail::ExtractSection(gpuNullDevice().hsaCompiler(), binaryElf_, &size, aclTEXT, &errorCode)); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Extracting AMD HSA Code Object from binary failed.\n"; return false; @@ -1592,15 +1592,15 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { } size_t kernelNamesSize = 0; errorCode = - aclQueryInfo(gpuNullDevice().hsaCompiler(), binaryElf_, RT_KERNEL_NAMES, NULL, NULL, &kernelNamesSize); + amd::Hsail::QueryInfo(gpuNullDevice().hsaCompiler(), binaryElf_, RT_KERNEL_NAMES, NULL, NULL, &kernelNamesSize); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Querying of kernel names size from the binary failed.\n"; return false; } if (kernelNamesSize > 0) { char* kernelNames = new char[kernelNamesSize]; - errorCode = aclQueryInfo(gpuNullDevice().hsaCompiler(), binaryElf_, RT_KERNEL_NAMES, NULL, kernelNames, - &kernelNamesSize); + errorCode = amd::Hsail::QueryInfo(gpuNullDevice().hsaCompiler(), binaryElf_, RT_KERNEL_NAMES, NULL, kernelNames, + &kernelNamesSize); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Querying of kernel names from the binary failed.\n"; delete [] kernelNames; @@ -1615,9 +1615,9 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { for (const auto& it : vKernels) { std::string kernelName(it); std::string openclKernelName = Kernel::openclMangledName(kernelName); - errorCode = aclQueryInfo(gpuNullDevice().hsaCompiler(), binaryElf_, RT_NUM_KERNEL_HIDDEN_ARGS, - openclKernelName.c_str(), &md.numHiddenKernelArgs, - &sizeOfnumHiddenKernelArgs); + errorCode = amd::Hsail::QueryInfo(gpuNullDevice().hsaCompiler(), binaryElf_, RT_NUM_KERNEL_HIDDEN_ARGS, + openclKernelName.c_str(), &md.numHiddenKernelArgs, + &sizeOfnumHiddenKernelArgs); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Querying of kernel '" + openclKernelName + "' extra arguments count from AMD HSA Code Object failed. Kernel initialization " @@ -1652,7 +1652,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) { } // Save the binary in the interface class saveBinaryAndSetType(TYPE_EXECUTABLE); - buildLog_ += aclGetCompilerLog(gpuNullDevice().hsaCompiler()); + buildLog_ += amd::Hsail::GetCompilerLog(gpuNullDevice().hsaCompiler()); return true; } @@ -1721,8 +1721,8 @@ void HSAILProgram::fillResListWithKernels(std::vector& memList) c const aclTargetInfo& HSAILProgram::info() { acl_error err; - info_ = aclGetTargetInfo(gpuNullDevice().settings().use64BitPtr_ ? "hsail64" : "hsail", - device().isa().hsailName(), &err); + info_ = amd::Hsail::GetTargetInfo(gpuNullDevice().settings().use64BitPtr_ ? "hsail64" : "hsail", + device().isa().hsailName(), &err); if (err != ACL_SUCCESS) { LogWarning("aclGetTargetInfo failed"); } @@ -1733,11 +1733,11 @@ bool HSAILProgram::saveBinaryAndSetType(type_t type) { // Write binary to memory if (rawBinary_ != NULL) { // Free memory containing rawBinary - aclFreeMem(binaryElf_, rawBinary_); + amd::Hsail::FreeMem(binaryElf_, rawBinary_); rawBinary_ = NULL; } size_t size = 0; - if (aclWriteToMem(binaryElf_, &rawBinary_, &size) != ACL_SUCCESS) { + if (amd::Hsail::WriteToMem(binaryElf_, &rawBinary_, &size) != ACL_SUCCESS) { buildLog_ += "Failed to write binary to memory \n"; return false; } diff --git a/rocclr/device/gpu/gpuscsi.cpp b/rocclr/device/gpu/gpuscsi.cpp index 8eb502e786..748260235f 100644 --- a/rocclr/device/gpu/gpuscsi.cpp +++ b/rocclr/device/gpu/gpuscsi.cpp @@ -21,7 +21,7 @@ #include "device/gpu/gpudefs.hpp" #include "device/gpu/gpuprogram.hpp" #include "device/gpu/gpukernel.hpp" -#include "acl.h" +#include "hsailctx.hpp" #include "SCShadersSi.h" #include "si_ci_vi_merged_offset.h" #include "si_ci_vi_merged_registers.h" diff --git a/rocclr/device/hsailctx.cpp b/rocclr/device/hsailctx.cpp new file mode 100644 index 0000000000..d8cfe0fd09 --- /dev/null +++ b/rocclr/device/hsailctx.cpp @@ -0,0 +1,98 @@ +/* Copyright (c) 2021-present Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#if defined(WITH_COMPILER_LIB) +#include "os/os.hpp" +#include "utils/flags.hpp" +#include "hsailctx.hpp" + +namespace amd { +std::once_flag Hsail::initialized; +HsailEntryPoints Hsail::cep_; +bool Hsail::is_ready_ = false; + +bool Hsail::LoadLib() { +#if defined(HSAIL_DYN_DLL) + ClPrint(amd::LOG_INFO, amd::LOG_CODE, "Loading HSAIL library."); + static constexpr const char* HsailLibName = + LP64_SWITCH(WINDOWS_SWITCH("amdhsail32.dll", "libamdhsail32.so"), + WINDOWS_SWITCH("amdhsail64.dll", "libamdhsail64.so")); + cep_.handle = Os::loadLibrary(HsailLibName); + if (nullptr == cep_.handle) { + return false; + } +#endif + GET_HSAIL_SYMBOL(aclCompilerInit) + GET_HSAIL_SYMBOL(aclCompilerFini) + GET_HSAIL_SYMBOL(aclCompilerVersion) + GET_HSAIL_SYMBOL(aclVersionSize) + GET_HSAIL_SYMBOL(aclGetErrorString) + GET_HSAIL_SYMBOL(aclGetArchInfo) + GET_HSAIL_SYMBOL(aclGetDeviceInfo) + GET_HSAIL_SYMBOL(aclGetTargetInfo) + GET_HSAIL_SYMBOL(aclGetTargetInfoFromChipID) + GET_HSAIL_SYMBOL(aclGetArchitecture) + GET_HSAIL_SYMBOL(aclGetChipOptions) + GET_HSAIL_SYMBOL(aclGetFamily) + GET_HSAIL_SYMBOL(aclGetChip) + GET_HSAIL_SYMBOL(aclBinaryInit) + GET_HSAIL_SYMBOL(aclBinaryFini) + GET_HSAIL_SYMBOL(aclReadFromFile) + GET_HSAIL_SYMBOL(aclReadFromMem) + GET_HSAIL_SYMBOL(aclWriteToFile) + GET_HSAIL_SYMBOL(aclWriteToMem) + GET_HSAIL_SYMBOL(aclCreateFromBinary) + GET_HSAIL_SYMBOL(aclBinaryVersion) + GET_HSAIL_SYMBOL(aclInsertSection) + GET_HSAIL_SYMBOL(aclInsertSymbol) + GET_HSAIL_SYMBOL(aclExtractSection) + GET_HSAIL_SYMBOL(aclExtractSymbol) + GET_HSAIL_SYMBOL(aclRemoveSection) + GET_HSAIL_SYMBOL(aclRemoveSymbol) + GET_HSAIL_SYMBOL(aclQueryInfo) + GET_HSAIL_SYMBOL(aclDbgAddArgument) + GET_HSAIL_SYMBOL(aclDbgRemoveArgument) + GET_HSAIL_SYMBOL(aclCompile) + GET_HSAIL_SYMBOL(aclLink) + GET_HSAIL_SYMBOL(aclGetCompilerLog) + GET_HSAIL_SYMBOL(aclRetrieveType) + GET_HSAIL_SYMBOL(aclSetType) + GET_HSAIL_SYMBOL(aclConvertType) + GET_HSAIL_SYMBOL(aclDisassemble) + GET_HSAIL_SYMBOL(aclGetDeviceBinary) + GET_HSAIL_SYMBOL(aclValidateBinaryImage) + GET_HSAIL_SYMBOL(aclJITObjectImageCreate) + GET_HSAIL_SYMBOL(aclJITObjectImageCopy) + GET_HSAIL_SYMBOL(aclJITObjectImageDestroy) + GET_HSAIL_SYMBOL(aclJITObjectImageFinalize) + GET_HSAIL_SYMBOL(aclJITObjectImageSize) + GET_HSAIL_SYMBOL(aclJITObjectImageData) + GET_HSAIL_SYMBOL(aclJITObjectImageGetGlobalsSize) + GET_HSAIL_SYMBOL(aclJITObjectImageIterateSymbols) + GET_HSAIL_SYMBOL(aclDumpBinary) + GET_HSAIL_SYMBOL(aclGetKstatsSI) + GET_HSAIL_SYMBOL(aclInsertKernelStatistics) + GET_HSAIL_SYMBOL(aclFreeMem) + is_ready_ = true; + return true; +} + +} +#endif diff --git a/rocclr/device/hsailctx.hpp b/rocclr/device/hsailctx.hpp new file mode 100644 index 0000000000..0d2be2adcc --- /dev/null +++ b/rocclr/device/hsailctx.hpp @@ -0,0 +1,314 @@ +/* Copyright (c) 2021-present Advanced Micro Devices, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + +#pragma once + +#include +#if defined(WITH_COMPILER_LIB) +#include "top.hpp" +#include "acl.h" + +namespace amd { +typedef aclCompiler* (*t_aclCompilerInit)(aclCompilerOptions *opts, acl_error *error_code); +typedef acl_error (*t_aclCompilerFini)(aclCompiler *cl); +typedef aclCLVersion (*t_aclCompilerVersion)(aclCompiler *cl, acl_error *error_code); +typedef uint32_t (*t_aclVersionSize)(aclCLVersion num, acl_error *error_code); +typedef const char* (*t_aclGetErrorString)(acl_error error_code); +typedef acl_error (*t_aclGetArchInfo)(const char** arch_names, size_t *arch_size); +typedef acl_error (*t_aclGetDeviceInfo)(const char* arch, const char **names, size_t *device_size); +typedef aclTargetInfo (*t_aclGetTargetInfo)(const char *arch, const char *device, acl_error *error_code); +typedef aclTargetInfo (*t_aclGetTargetInfoFromChipID)(const char *arch, const uint32_t chip_id, acl_error *error_code); +typedef const char* (*t_aclGetArchitecture)(const aclTargetInfo &target); +typedef const uint64_t (*t_aclGetChipOptions)(const aclTargetInfo &target); +typedef const char* (*t_aclGetFamily)(const aclTargetInfo &target); +typedef const char* (*t_aclGetChip)(const aclTargetInfo &target); +typedef aclBinary* (*t_aclBinaryInit)(size_t struct_version, const aclTargetInfo *target, const aclBinaryOptions *options, acl_error *error_code); +typedef acl_error (*t_aclBinaryFini)(aclBinary *bin); +typedef aclBinary* (*t_aclReadFromFile)(const char *str, acl_error *error_code); +typedef aclBinary* (*t_aclReadFromMem)(const void *mem, size_t size, acl_error *error_code); +typedef acl_error (*t_aclWriteToFile)(aclBinary *bin, const char *str); +typedef acl_error (*t_aclWriteToMem)(aclBinary *bin, void **mem, size_t *size); +typedef aclBinary* (*t_aclCreateFromBinary)(const aclBinary *binary, aclBIFVersion version); +typedef aclBIFVersion (*t_aclBinaryVersion)(const aclBinary *binary); +typedef acl_error (*t_aclInsertSection)(aclCompiler *cl, aclBinary *binary, const void *data, size_t data_size, aclSections id); +typedef acl_error (*t_aclInsertSymbol)(aclCompiler *cl, aclBinary *binary, const void *data, size_t data_size, aclSections id, const char *symbol); +typedef const void* (*t_aclExtractSection)(aclCompiler *cl, const aclBinary *binary, size_t *size, aclSections id, acl_error *error_code); +typedef const void* (*t_aclExtractSymbol)(aclCompiler *cl, const aclBinary *binary, size_t *size, aclSections id, const char *symbol, acl_error *error_code); +typedef acl_error (*t_aclRemoveSection)(aclCompiler *cl, aclBinary *binary, aclSections id); +typedef acl_error (*t_aclRemoveSymbol)(aclCompiler *cl, aclBinary *binary, aclSections id, const char *symbol); +typedef acl_error (*t_aclQueryInfo)(aclCompiler *cl, const aclBinary *binary, aclQueryType query, const char *kernel, void *data_ptr, size_t *ptr_size); +typedef acl_error (*t_aclDbgAddArgument)(aclCompiler *cl, aclBinary *binary, const char* kernel, const char* name, bool byVal); +typedef acl_error (*t_aclDbgRemoveArgument)(aclCompiler *cl, aclBinary *binary, const char* kernel, const char* name); +typedef acl_error (*t_aclCompile)(aclCompiler *cl, aclBinary *bin, const char *options, aclType from, aclType to, aclLogFunction compile_callback); +typedef acl_error (*t_aclLink)(aclCompiler *cl, aclBinary *src_bin, unsigned int num_libs, aclBinary **libs, aclType link_mode, const char *options, aclLogFunction link_callback); +typedef const char* (*t_aclGetCompilerLog)(aclCompiler *cl); +typedef const void* (*t_aclRetrieveType)(aclCompiler *cl, const aclBinary *bin, const char *name, size_t *data_size, aclType type, acl_error *error_code); +typedef acl_error (*t_aclSetType)(aclCompiler *cl, aclBinary *bin, const char *name, aclType type, const void *data, size_t size); +typedef acl_error (*t_aclConvertType)(aclCompiler *cl, aclBinary *bin, const char *name, aclType type); +typedef acl_error (*t_aclDisassemble)(aclCompiler *cl, aclBinary *bin, const char *kernel, aclLogFunction disasm_callback); +typedef const void* (*t_aclGetDeviceBinary)(aclCompiler *cl, const aclBinary *bin, const char *kernel, size_t *size, acl_error *error_code); +typedef bool (*t_aclValidateBinaryImage)(const void* binary, size_t length, unsigned type); +typedef aclJITObjectImage (*t_aclJITObjectImageCreate)(aclCompiler *cl, const void* buffer, size_t length, aclBinary* bin, acl_error* error_code); +typedef aclJITObjectImage (*t_aclJITObjectImageCopy)(aclCompiler *cl, const void* buffer, size_t length, acl_error* error_code); +typedef acl_error (*t_aclJITObjectImageDestroy)(aclCompiler *cl, aclJITObjectImage buffer); +typedef acl_error (*t_aclJITObjectImageFinalize)(aclCompiler *cl, aclJITObjectImage image); +typedef size_t (*t_aclJITObjectImageSize)(aclCompiler *cl, aclJITObjectImage image, acl_error* error_code); +typedef const char* (*t_aclJITObjectImageData)(aclCompiler *cl, aclJITObjectImage image, acl_error* error_code); +typedef size_t (*t_aclJITObjectImageGetGlobalsSize)(aclCompiler *cl, aclJITObjectImage image, acl_error* error_code); +typedef acl_error (*t_aclJITObjectImageIterateSymbols)(aclCompiler *cl, aclJITObjectImage image, aclJITSymbolCallback callback, void* data); +typedef void (*t_aclDumpBinary)(const aclBinary *bin); +typedef void (*t_aclGetKstatsSI)(const void* shader, aclKernelStats &kstats); +typedef acl_error (*t_aclInsertKernelStatistics)(aclCompiler *cl, aclBinary *bin); +typedef acl_error (*t_aclFreeMem)(aclBinary *bin, void *mem); + +struct HsailEntryPoints { + void* handle; + t_aclCompilerInit aclCompilerInit; + t_aclCompilerFini aclCompilerFini; + t_aclCompilerVersion aclCompilerVersion; + t_aclVersionSize aclVersionSize; + t_aclGetErrorString aclGetErrorString; + t_aclGetArchInfo aclGetArchInfo; + t_aclGetDeviceInfo aclGetDeviceInfo; + t_aclGetTargetInfo aclGetTargetInfo; + t_aclGetTargetInfoFromChipID aclGetTargetInfoFromChipID; + t_aclGetArchitecture aclGetArchitecture; + t_aclGetChipOptions aclGetChipOptions; + t_aclGetFamily aclGetFamily; + t_aclGetChip aclGetChip; + t_aclBinaryInit aclBinaryInit; + t_aclBinaryFini aclBinaryFini; + t_aclReadFromFile aclReadFromFile; + t_aclReadFromMem aclReadFromMem; + t_aclWriteToFile aclWriteToFile; + t_aclWriteToMem aclWriteToMem; + t_aclCreateFromBinary aclCreateFromBinary; + t_aclBinaryVersion aclBinaryVersion; + t_aclInsertSection aclInsertSection; + t_aclInsertSymbol aclInsertSymbol; + t_aclExtractSection aclExtractSection; + t_aclExtractSymbol aclExtractSymbol; + t_aclRemoveSection aclRemoveSection; + t_aclRemoveSymbol aclRemoveSymbol; + t_aclQueryInfo aclQueryInfo; + t_aclDbgAddArgument aclDbgAddArgument; + t_aclDbgRemoveArgument aclDbgRemoveArgument; + t_aclCompile aclCompile; + t_aclLink aclLink; + t_aclGetCompilerLog aclGetCompilerLog; + t_aclRetrieveType aclRetrieveType; + t_aclSetType aclSetType; + t_aclConvertType aclConvertType; + t_aclDisassemble aclDisassemble; + t_aclGetDeviceBinary aclGetDeviceBinary; + t_aclValidateBinaryImage aclValidateBinaryImage; + t_aclJITObjectImageCreate aclJITObjectImageCreate; + t_aclJITObjectImageCopy aclJITObjectImageCopy; + t_aclJITObjectImageDestroy aclJITObjectImageDestroy; + t_aclJITObjectImageFinalize aclJITObjectImageFinalize; + t_aclJITObjectImageSize aclJITObjectImageSize; + t_aclJITObjectImageData aclJITObjectImageData; + t_aclJITObjectImageGetGlobalsSize aclJITObjectImageGetGlobalsSize; + t_aclJITObjectImageIterateSymbols aclJITObjectImageIterateSymbols; + t_aclDumpBinary aclDumpBinary; + t_aclGetKstatsSI aclGetKstatsSI; + t_aclInsertKernelStatistics aclInsertKernelStatistics; + t_aclFreeMem aclFreeMem; +}; + +#ifdef HSAIL_DYN_DLL +#define DYN(NAME) cep_.NAME +#define GET_HSAIL_SYMBOL(NAME) cep_.NAME = \ + reinterpret_cast(Os::getSymbol(cep_.handle, #NAME)); \ + if (nullptr == cep_.NAME) { return false; } +#else +#define DYN(NAME) NAME +#define GET_HSAIL_SYMBOL(NAME) +#endif + +class Hsail : public amd::AllStatic { +public: + static std::once_flag initialized; + + static bool LoadLib(); + + static bool IsReady() { return is_ready_; } + + static aclCompiler* CompilerInit(aclCompilerOptions *opts, acl_error *error_code) { + return DYN(aclCompilerInit)(opts, error_code); + } + static acl_error CompilerFini(aclCompiler *cl) { + return DYN(aclCompilerFini)(cl); + } + static aclCLVersion CompilerVersion(aclCompiler *cl, acl_error *error_code) { + return DYN(aclCompilerVersion)(cl, error_code); + } + static uint32_t VersionSize(aclCLVersion num, acl_error *error_code) { + return DYN(aclVersionSize)(num, error_code); + } + static const char* GetErrorString(acl_error error_code) { + return DYN(aclGetErrorString)(error_code); + } + static acl_error GetArchInfo(const char** arch_names, size_t *arch_size) { + return DYN(aclGetArchInfo)(arch_names, arch_size); + } + static acl_error GetDeviceInfo(const char* arch, const char **names, size_t *device_size) { + return DYN(aclGetDeviceInfo)(arch, names, device_size); + } + static aclTargetInfo GetTargetInfo(const char *arch, const char *device, acl_error *error_code) { + return DYN(aclGetTargetInfo)(arch, device, error_code); + } + static aclTargetInfo GetTargetInfoFromChipID(const char *arch, const uint32_t chip_id, acl_error *error_code) { + return DYN(aclGetTargetInfoFromChipID)(arch, chip_id, error_code); + } + static const char* GetArchitecture(const aclTargetInfo &target) { + return DYN(aclGetArchitecture)(target); + } + static uint64_t GetChipOptions(const aclTargetInfo &target) { + return DYN(aclGetChipOptions)(target); + } + static const char* GetFamily(const aclTargetInfo &target) { + return DYN(aclGetFamily)(target); + } + static const char* GetChip(const aclTargetInfo &target) { + return DYN(aclGetChip)(target); + } + static aclBinary* BinaryInit(size_t struct_version, const aclTargetInfo *target, const aclBinaryOptions *options, acl_error *error_code) { + return DYN(aclBinaryInit)(struct_version, target, options, error_code); + } + static acl_error BinaryFini(aclBinary *bin) { + return DYN(aclBinaryFini)(bin); + } + static aclBinary* ReadFromFile(const char *str, acl_error *error_code) { + return DYN(aclReadFromFile)(str, error_code); + } + static aclBinary* ReadFromMem(const void *mem, size_t size, acl_error *error_code) { + return DYN(aclReadFromMem)(mem, size, error_code); + } + static acl_error WriteToFile(aclBinary *bin, const char *str) { + return DYN(aclWriteToFile)(bin, str); + } + static acl_error WriteToMem(aclBinary *bin, void **mem, size_t *size) { + return DYN(aclWriteToMem)(bin, mem, size); + } + static aclBinary* CreateFromBinary(const aclBinary *binary, aclBIFVersion version) { + return DYN(aclCreateFromBinary)(binary, version); + } + static aclBIFVersion BinaryVersion(const aclBinary *binary) { + return DYN(aclBinaryVersion)(binary); + } + static acl_error InsertSection(aclCompiler *cl, aclBinary *binary, const void *data, size_t data_size, aclSections id) { + return DYN(aclInsertSection)(cl, binary, data, data_size, id); + } + static const acl_error InsertSymbol(aclCompiler *cl, aclBinary *binary, const void *data, size_t data_size, aclSections id, const char *symbol) { + return DYN(aclInsertSymbol)(cl, binary, data, data_size, id, symbol); + } + static const void* ExtractSection(aclCompiler *cl, const aclBinary *binary, size_t *size, aclSections id, acl_error *error_code) { + return DYN(aclExtractSection)(cl, binary, size, id, error_code); + } + static const void* ExtractSymbol(aclCompiler *cl, const aclBinary *binary, size_t *size, aclSections id, const char *symbol, acl_error *error_code) { + return DYN(aclExtractSymbol)(cl, binary, size, id, symbol, error_code); + } + static acl_error RemoveSection(aclCompiler *cl, aclBinary *binary, aclSections id) { + return DYN(aclRemoveSection)(cl, binary, id); + } + static acl_error RemoveSymbol(aclCompiler *cl, aclBinary *binary, aclSections id, const char *symbol) { + return DYN(aclRemoveSymbol)(cl, binary, id, symbol); + } + static acl_error QueryInfo(aclCompiler *cl, const aclBinary *binary, aclQueryType query, const char *kernel, void *data_ptr, size_t *ptr_size) { + return DYN(aclQueryInfo)(cl, binary, query, kernel, data_ptr, ptr_size); + } + static acl_error DbgAddArgument(aclCompiler *cl, aclBinary *binary, const char* kernel, const char* name, bool byVal) { + return DYN(aclDbgAddArgument)(cl, binary, kernel, name, byVal); + } + static acl_error DbgRemoveArgument(aclCompiler *cl, aclBinary *binary, const char* kernel, const char* name) { + return DYN(aclDbgRemoveArgument)(cl, binary, kernel, name); + } + static acl_error Compile(aclCompiler *cl, aclBinary *bin, const char *options, aclType from, aclType to, aclLogFunction compile_callback) { + return DYN(aclCompile)(cl, bin, options, from, to, compile_callback); + } + static acl_error Link(aclCompiler *cl, aclBinary *src_bin, unsigned int num_libs, aclBinary **libs, aclType link_mode, const char *options, aclLogFunction link_callback) { + return DYN(aclLink)(cl, src_bin, num_libs, libs, link_mode, options, link_callback); + } + static const char* GetCompilerLog(aclCompiler *cl) { + return DYN(aclGetCompilerLog)(cl); + } + static const void* RetrieveType(aclCompiler *cl, const aclBinary *bin, const char *name, size_t *data_size, aclType type, acl_error *error_code) { + return DYN(aclRetrieveType)(cl, bin, name, data_size, type, error_code); + } + static acl_error SetType(aclCompiler *cl, aclBinary *bin, const char *name, aclType type, const void *data, size_t size) { + return DYN(aclSetType)(cl, bin, name, type, data, size); + } + static acl_error ConvertType(aclCompiler *cl, aclBinary *bin, const char *name, aclType type) { + return DYN(aclConvertType)(cl, bin, name, type); + } + static acl_error Disassemble(aclCompiler *cl, aclBinary *bin, const char *kernel, aclLogFunction disasm_callback) { + return DYN(aclDisassemble)(cl, bin, kernel, disasm_callback); + } + static const void* GetDeviceBinary(aclCompiler *cl, const aclBinary *bin, const char *kernel, size_t *size, acl_error *error_code) { + return DYN(aclGetDeviceBinary)(cl, bin, kernel, size, error_code); + } + static const bool ValidateBinaryImage(const void* binary, size_t length, unsigned type) { + return DYN(aclValidateBinaryImage)(binary, length, type); + } + static aclJITObjectImage JITObjectImageCreate(aclCompiler *cl, const void* buffer, size_t length, aclBinary* bin, acl_error* error_code) { + return DYN(aclJITObjectImageCreate)(cl, buffer, length, bin, error_code); + } + static aclJITObjectImage JITObjectImageCopy(aclCompiler *cl, const void* buffer, size_t length, acl_error* error_code) { + return DYN(aclJITObjectImageCopy)(cl, buffer, length, error_code); + } + static acl_error JITObjectImageDestroy(aclCompiler *cl, aclJITObjectImage buffer) { + return DYN(aclJITObjectImageDestroy)(cl, buffer); + } + static acl_error JITObjectImageFinalize(aclCompiler *cl, aclJITObjectImage image) { + return DYN(aclJITObjectImageFinalize)(cl, image); + } + static size_t JITObjectImageSize(aclCompiler *cl, aclJITObjectImage image, acl_error* error_code) { + return DYN(aclJITObjectImageSize)(cl, image, error_code); + } + static const char* JITObjectImageData(aclCompiler *cl, aclJITObjectImage image, acl_error* error_code) { + return DYN(aclJITObjectImageData)(cl, image, error_code); + } + static size_t JITObjectImageGetGlobalsSize(aclCompiler *cl, aclJITObjectImage image, acl_error* error_code) { + return DYN(aclJITObjectImageGetGlobalsSize)(cl, image, error_code); + } + static acl_error JITObjectImageIterateSymbols(aclCompiler *cl, aclJITObjectImage image, aclJITSymbolCallback callback, void* data) { + return DYN(aclJITObjectImageIterateSymbols)(cl, image, callback, data); + } + static void DumpBinary(const aclBinary *bin) { + DYN(aclDumpBinary)(bin); + } + static void GetKstatsSI(const void* shader, aclKernelStats &kstats) { + return DYN(aclGetKstatsSI)(shader, kstats); + } + static acl_error InsertKernelStatistics(aclCompiler *cl, aclBinary *bin) { + return DYN(aclInsertKernelStatistics)(cl, bin); + } + static acl_error FreeMem(aclBinary *bin, void *mem) { + return DYN(aclFreeMem)(bin, mem); + } + +private: + static HsailEntryPoints cep_; + static bool is_ready_; +}; + +} +#endif diff --git a/rocclr/device/pal/paldevice.cpp b/rocclr/device/pal/paldevice.cpp index 7a6b266d0a..837109188f 100644 --- a/rocclr/device/pal/paldevice.cpp +++ b/rocclr/device/pal/paldevice.cpp @@ -35,7 +35,7 @@ #include "palLib.h" #include "palPlatform.h" #include "palDevice.h" -#include "acl.h" +#include "hsailctx.hpp" #include "vdi_common.hpp" @@ -246,6 +246,11 @@ bool NullDevice::create(const char* palName, const amd::Isa& isa, Pal::GfxIpLeve return false; } + if (!ValidateHsail()) { + LogPrintfError("HSAIL initialization failed for offline PAL device %s", isa.targetId()); + return false; + } + if (!amd::Device::create(isa)) { LogPrintfError("Unable to setup device for PAL offline device %s", isa.targetId()); return false; @@ -272,7 +277,7 @@ bool NullDevice::create(const char* palName, const amd::Isa& isa, Pal::GfxIpLeve AMD_OCL_SC_LIB}; // Initialize the compiler handle acl_error error; - compiler_ = aclCompilerInit(&opts, &error); + compiler_ = amd::Hsail::CompilerInit(&opts, &error); if (error != ACL_SUCCESS) { LogPrintfError("Error initializing the compiler for offline PAL device %s", isa.targetId()); return false; @@ -915,6 +920,11 @@ bool Device::create(Pal::IDevice* device) { return false; } + if (!ValidateHsail()) { + LogError("Hsail initialization failed!"); + return false; + } + computeEnginesId_.resize(std::min(numComputeEngines(), settings().numComputeRings_)); amd::Context::Info info = {0}; @@ -972,7 +982,7 @@ bool Device::create(Pal::IDevice* device) { AMD_OCL_SC_LIB}; // Initialize the compiler handle acl_error error; - compiler_ = aclCompilerInit(&opts, &error); + compiler_ = amd::Hsail::CompilerInit(&opts, &error); if (error != ACL_SUCCESS) { LogError("Error initializing the compiler"); return false; @@ -1327,7 +1337,7 @@ void Device::tearDown() { #if defined(WITH_COMPILER_LIB) if (compiler_ != nullptr) { - aclCompilerFini(compiler_); + amd::Hsail::CompilerFini(compiler_); compiler_ = nullptr; } #endif // defined(WITH_COMPILER_LIB) diff --git a/rocclr/device/pal/palkernel.cpp b/rocclr/device/pal/palkernel.cpp index 20b4372e3a..953de42916 100644 --- a/rocclr/device/pal/palkernel.cpp +++ b/rocclr/device/pal/palkernel.cpp @@ -25,7 +25,7 @@ #include "device/pal/palsched.hpp" #include "platform/commandqueue.hpp" #include "utils/options.hpp" -#include "acl.h" +#include "hsailctx.hpp" #include #include #include @@ -134,9 +134,9 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (palNullDevice().settings().svmFineGrainSystem_) { options.append(" -sc-xnack-iommu"); } - error = aclCompile(palNullDevice().compiler(), prog().binaryElf(), options.c_str(), ACL_TYPE_CG, - ACL_TYPE_ISA, nullptr); - buildLog_ += aclGetCompilerLog(palNullDevice().compiler()); + error = amd::Hsail::Compile(palNullDevice().compiler(), prog().binaryElf(), options.c_str(), ACL_TYPE_CG, + ACL_TYPE_ISA, nullptr); + buildLog_ += amd::Hsail::GetCompilerLog(palNullDevice().compiler()); if (error != ACL_SUCCESS) { LogError("Failed to finalize kernel"); return false; @@ -149,8 +149,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { // Pull out metadata from the ELF size_t sizeOfArgList; - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, - openClKernelName.c_str(), nullptr, &sizeOfArgList); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, + openClKernelName.c_str(), nullptr, &sizeOfArgList); if (error != ACL_SUCCESS) { return false; } @@ -159,8 +159,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (nullptr == aclArgList) { return false; } - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, - openClKernelName.c_str(), aclArgList, &sizeOfArgList); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_ARGUMENT_ARRAY, + openClKernelName.c_str(), aclArgList, &sizeOfArgList); if (error != ACL_SUCCESS) { return false; } @@ -169,13 +169,13 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { delete[] aclArgList; size_t sizeOfWorkGroupSize; - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, - openClKernelName.c_str(), nullptr, &sizeOfWorkGroupSize); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, + openClKernelName.c_str(), nullptr, &sizeOfWorkGroupSize); if (error != ACL_SUCCESS) { return false; } - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, - openClKernelName.c_str(), workGroupInfo_.compileSize_, &sizeOfWorkGroupSize); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE, + openClKernelName.c_str(), workGroupInfo_.compileSize_, &sizeOfWorkGroupSize); if (error != ACL_SUCCESS) { return false; } @@ -192,8 +192,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { // Pull out printf metadata from the ELF size_t sizeOfPrintfList; - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, - openClKernelName.c_str(), nullptr, &sizeOfPrintfList); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, + openClKernelName.c_str(), nullptr, &sizeOfPrintfList); if (error != ACL_SUCCESS) { return false; } @@ -204,8 +204,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (nullptr == aclPrintfList) { return false; } - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, - openClKernelName.c_str(), aclPrintfList, &sizeOfPrintfList); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_GPU_PRINTF_ARRAY, + openClKernelName.c_str(), aclPrintfList, &sizeOfPrintfList); if (error != ACL_SUCCESS) { return false; } @@ -218,8 +218,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { aclMetadata md; md.enqueue_kernel = false; size_t sizeOfDeviceEnqueue = sizeof(md.enqueue_kernel); - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_DEVICE_ENQUEUE, - openClKernelName.c_str(), &md.enqueue_kernel, &sizeOfDeviceEnqueue); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_DEVICE_ENQUEUE, + openClKernelName.c_str(), &md.enqueue_kernel, &sizeOfDeviceEnqueue); if (error != ACL_SUCCESS) { return false; } @@ -227,17 +227,17 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { md.kernel_index = -1; size_t sizeOfIndex = sizeof(md.kernel_index); - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_KERNEL_INDEX, - openClKernelName.c_str(), &md.kernel_index, &sizeOfIndex); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_KERNEL_INDEX, + openClKernelName.c_str(), &md.kernel_index, &sizeOfIndex); if (error != ACL_SUCCESS) { return false; } index_ = md.kernel_index; size_t sizeOfWavesPerSimdHint = sizeof(workGroupInfo_.wavesPerSimdHint_); - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WAVES_PER_SIMD_HINT, - openClKernelName.c_str(), &workGroupInfo_.wavesPerSimdHint_, - &sizeOfWavesPerSimdHint); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WAVES_PER_SIMD_HINT, + openClKernelName.c_str(), &workGroupInfo_.wavesPerSimdHint_, + &sizeOfWavesPerSimdHint); if (error != ACL_SUCCESS) { return false; } @@ -245,16 +245,16 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { waveLimiter_.enable(); size_t sizeOfWorkGroupSizeHint = sizeof(workGroupInfo_.compileSizeHint_); - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE_HINT, - openClKernelName.c_str(), workGroupInfo_.compileSizeHint_, - &sizeOfWorkGroupSizeHint); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_WORK_GROUP_SIZE_HINT, + openClKernelName.c_str(), workGroupInfo_.compileSizeHint_, + &sizeOfWorkGroupSizeHint); if (error != ACL_SUCCESS) { return false; } size_t sizeOfVecTypeHint; - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, - openClKernelName.c_str(), NULL, &sizeOfVecTypeHint); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, + openClKernelName.c_str(), NULL, &sizeOfVecTypeHint); if (error != ACL_SUCCESS) { return false; } @@ -264,8 +264,8 @@ bool HSAILKernel::init(amd::hsa::loader::Symbol* sym, bool finalize) { if (NULL == VecTypeHint) { return false; } - error = aclQueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, - openClKernelName.c_str(), VecTypeHint, &sizeOfVecTypeHint); + error = amd::Hsail::QueryInfo(palNullDevice().compiler(), prog().binaryElf(), RT_VEC_TYPE_HINT, + openClKernelName.c_str(), VecTypeHint, &sizeOfVecTypeHint); if (error != ACL_SUCCESS) { return false; } diff --git a/rocclr/device/pal/palprogram.cpp b/rocclr/device/pal/palprogram.cpp index 9765dd5ece..605642785c 100644 --- a/rocclr/device/pal/palprogram.cpp +++ b/rocclr/device/pal/palprogram.cpp @@ -209,12 +209,12 @@ HSAILProgram::~HSAILProgram() { } #if defined(WITH_COMPILER_LIB) if (rawBinary_ != nullptr) { - aclFreeMem(binaryElf_, rawBinary_); + amd::Hsail::FreeMem(binaryElf_, rawBinary_); } acl_error error; // Free the elf binary if (binaryElf_ != nullptr) { - error = aclBinaryFini(binaryElf_); + error = amd::Hsail::BinaryFini(binaryElf_); if (error != ACL_SUCCESS) { LogWarning("Error while destroying the acl binary \n"); } @@ -274,16 +274,16 @@ bool HSAILProgram::setKernels(amd::option::Options* options, void* binary, size_ } size_t kernelNamesSize = 0; - acl_error errorCode = aclQueryInfo(palNullDevice().compiler(), binaryElf_, RT_KERNEL_NAMES, nullptr, - nullptr, &kernelNamesSize); + acl_error errorCode = amd::Hsail::QueryInfo(palNullDevice().compiler(), binaryElf_, RT_KERNEL_NAMES, nullptr, + nullptr, &kernelNamesSize); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Querying of kernel names size from the binary failed.\n"; return false; } if (kernelNamesSize > 0) { char* kernelNames = new char[kernelNamesSize]; - errorCode = aclQueryInfo(palNullDevice().compiler(), binaryElf_, RT_KERNEL_NAMES, nullptr, kernelNames, - &kernelNamesSize); + errorCode = amd::Hsail::QueryInfo(palNullDevice().compiler(), binaryElf_, RT_KERNEL_NAMES, nullptr, kernelNames, + &kernelNamesSize); if (errorCode != ACL_SUCCESS) { buildLog_ += "Error: Querying of kernel names from the binary failed.\n"; delete[] kernelNames; @@ -360,8 +360,8 @@ void HSAILProgram::fillResListWithKernels(VirtualGPU& gpu) const { gpu.addVmMemo const aclTargetInfo& HSAILProgram::info() { #if defined(WITH_COMPILER_LIB) acl_error err; - info_ = aclGetTargetInfo(palNullDevice().settings().use64BitPtr_ ? "hsail64" : "hsail", - device().isa().hsailName(), &err); + info_ = amd::Hsail::GetTargetInfo(palNullDevice().settings().use64BitPtr_ ? "hsail64" : "hsail", + device().isa().hsailName(), &err); if (err != ACL_SUCCESS) { LogWarning("aclGetTargetInfo failed"); } @@ -374,11 +374,11 @@ bool HSAILProgram::saveBinaryAndSetType(type_t type) { // Write binary to memory if (rawBinary_ != nullptr) { // Free memory containing rawBinary - aclFreeMem(binaryElf_, rawBinary_); + amd::Hsail::FreeMem(binaryElf_, rawBinary_); rawBinary_ = nullptr; } size_t size = 0; - if (aclWriteToMem(binaryElf_, &rawBinary_, &size) != ACL_SUCCESS) { + if (amd::Hsail::WriteToMem(binaryElf_, &rawBinary_, &size) != ACL_SUCCESS) { buildLog_ += "Failed to write binary to memory \n"; return false; } diff --git a/rocclr/platform/program.cpp b/rocclr/platform/program.cpp index 1de217a4da..9dd8b0a0ae 100644 --- a/rocclr/platform/program.cpp +++ b/rocclr/platform/program.cpp @@ -23,9 +23,11 @@ #include "platform/program.hpp" #include "platform/context.hpp" #include "utils/options.hpp" +#if defined(WITH_COMPILER_LIB) #include "utils/libUtils.h" #include "utils/bif_section_labels.hpp" -#include "acl.h" +#include "hsailctx.hpp" +#endif #include // for malloc #include // for strcmp @@ -90,7 +92,7 @@ int32_t Program::addDeviceProgram(Device& device, const void* image, size_t leng return CL_INVALID_BINARY; } #if defined(WITH_COMPILER_LIB) - else if (!aclValidateBinaryImage( + else if (!amd::Hsail::ValidateBinaryImage( image, length, language_ == SPIRV ? BINARY_TYPE_SPIRV : BINARY_TYPE_ELF | BINARY_TYPE_LLVM)) { return CL_INVALID_BINARY; } @@ -118,9 +120,9 @@ int32_t Program::addDeviceProgram(Device& device, const void* image, size_t leng } #if defined(WITH_COMPILER_LIB) - if (image != NULL && length != 0 && aclValidateBinaryImage(image, length, BINARY_TYPE_ELF)) { + if (image != NULL && length != 0 && amd::Hsail::ValidateBinaryImage(image, length, BINARY_TYPE_ELF)) { acl_error errorCode; - aclBinary* binary = aclReadFromMem(image, length, &errorCode); + aclBinary* binary = amd::Hsail::ReadFromMem(image, length, &errorCode); if (errorCode != ACL_SUCCESS) { return CL_INVALID_BINARY; } @@ -128,8 +130,8 @@ int32_t Program::addDeviceProgram(Device& device, const void* image, size_t leng assert(symbol && "symbol not found"); std::string symName = std::string(symbol->str[bif::PRE]) + std::string(symbol->str[bif::POST]); size_t symSize = 0; - const void* opts = aclExtractSymbol(device.binCompiler(), binary, &symSize, aclCOMMENT, - symName.c_str(), &errorCode); + const void* opts = amd::Hsail::ExtractSymbol(device.binCompiler(), binary, &symSize, aclCOMMENT, + symName.c_str(), &errorCode); // if we have options from binary and input options was not specified if (opts != NULL && emptyOptions) { std::string sBinOptions = std::string((char*)opts, symSize); @@ -142,7 +144,7 @@ int32_t Program::addDeviceProgram(Device& device, const void* image, size_t leng options->oVariables->Legacy = !device.settings().useLightning_ ? isAMDILTarget(*aclutGetTargetInfo(binary)) : isHSAILTarget(*aclutGetTargetInfo(binary)); - aclBinaryFini(binary); + amd::Hsail::BinaryFini(binary); } #endif // defined(WITH_COMPILER_LIB) options->oVariables->BinaryIsSpirv = language_ == SPIRV; @@ -346,10 +348,10 @@ int32_t Program::link(const std::vector& devices, size_t numInputs, #if defined(WITH_COMPILER_LIB) device::Program::binary_t binary = inputDevPrograms[i]->binary(); if (!found && binary.first != NULL && binary.second > 0 && - aclValidateBinaryImage(binary.first, binary.second, BINARY_TYPE_ELF)) { + amd::Hsail::ValidateBinaryImage(binary.first, binary.second, BINARY_TYPE_ELF)) { acl_error errorCode = ACL_SUCCESS; void* mem = const_cast(binary.first); - aclBinary* aclBin = aclReadFromMem(mem, binary.second, &errorCode); + aclBinary* aclBin = amd::Hsail::ReadFromMem(mem, binary.second, &errorCode); if (errorCode != ACL_SUCCESS) { LogWarning("Error while linking: Could not read from raw binary."); return CL_INVALID_BINARY; @@ -360,7 +362,7 @@ int32_t Program::link(const std::vector& devices, size_t numInputs, } else if (isAMDILTarget(*aclutGetTargetInfo(aclBin))) { parsedOptions.oVariables->Frontend = "edg"; } - aclBinaryFini(aclBin); + amd::Hsail::BinaryFini(aclBin); } #endif // defined(WITH_COMPILER_LIB) found = true;