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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "device/pal/palsched.hpp"
|
||||
#include "platform/commandqueue.hpp"
|
||||
#include "utils/options.hpp"
|
||||
#include "acl.h"
|
||||
#include "hsailctx.hpp"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user