diff --git a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp index 179d9b4640..792582fd06 100644 --- a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp +++ b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp @@ -1228,6 +1228,20 @@ aclCompileInternal( if (useISA) { ald = cl->beAPI.init(cl, bin, compile_callback, &error_code); error_code = cl->beAPI.finalize(ald, dataStr.data(), dataStr.length()); +#ifdef WITH_TARGET_HSAIL + if (isHSAILTarget(bin->target) && error_code == ACL_SUCCESS) { + amdcl::HSAIL *acl = reinterpret_cast(cl->cgAPI.init(cl, bin, compile_callback, &error_code)); + if ((!checkFlag(aclutGetCaps(bin), capSaveCG) || !acl->Options()->oVariables->BinCG) && !acl->IsGlobalVarInBRIG()) { + oclBIFSymbolID brigSectionSymbolId[] = {symBRIGStrtab, symHSABinary, symBRIGOperands, symDebugInfo}; + int symCount = sizeof(brigSectionSymbolId) / sizeof(brigSectionSymbolId[PRE]); + for(int i=0; iclAPI.remSym(cl, bin, sym->sections[PRE], sym->str[PRE]); + } + } + } +#endif cl->beAPI.fini(ald); if (error_code != ACL_SUCCESS) { goto internal_compile_failure; @@ -2269,6 +2283,19 @@ if_aclQueryInfo(aclCompiler *cl, return ACL_SUCCESS; } return ACL_ERROR; + case RT_CONTAINS_LOADER_MAP: + if (!ptr) { + *size = sizeof(bool); + return ACL_SUCCESS; + } else if (*size >= sizeof(bool)) { + const oclBIFSymbolStruct* sym = findBIF30SymStruct(symBRIGLoaderMap); + assert(sym && "symbol not found"); + std::string symbolName = sym->str[PRE]; + bool contains = elfBin->isSymbol(aclCODEGEN, symbolName.c_str()); + memcpy(ptr, &contains, sizeof(bool)); + return ACL_SUCCESS; + } + return ACL_ERROR; case RT_CONTAINS_ISA: if (!ptr) { *size = sizeof(bool); diff --git a/rocclr/compiler/lib/include/v0_8/aclEnums.h b/rocclr/compiler/lib/include/v0_8/aclEnums.h index 0dc34d24af..43ae7cd89e 100644 --- a/rocclr/compiler/lib/include/v0_8/aclEnums.h +++ b/rocclr/compiler/lib/include/v0_8/aclEnums.h @@ -188,27 +188,28 @@ typedef enum _bif_sections_enum_0_8 { //! An enumeration that defines what are valid queries for aclQueryInfo. typedef enum _rt_query_types_enum_0_8 { - RT_ABI_VERSION = 0, - RT_DEVICE_NAME = 1, - RT_MEM_SIZES = 2, - RT_GPU_FUNC_CAPS = 3, - RT_GPU_FUNC_ID = 4, - RT_GPU_DEFAULT_ID = 5, - RT_WORK_GROUP_SIZE = 6, - RT_WORK_REGION_SIZE = 7, - RT_ARGUMENT_ARRAY = 8, - RT_GPU_PRINTF_ARRAY = 9, - RT_CPU_BARRIER_NAMES= 10, - RT_DEVICE_ENQUEUE = 11, - RT_KERNEL_INDEX = 12, - RT_KERNEL_NAME = 13, - RT_KERNEL_NAMES = 14, - RT_CONTAINS_LLVMIR = 15, - RT_CONTAINS_OPTIONS = 16, - RT_CONTAINS_BRIG = 17, - RT_CONTAINS_HSAIL = 18, - RT_CONTAINS_ISA = 19, - RT_LAST_TYPE = 20 + RT_ABI_VERSION = 0, + RT_DEVICE_NAME = 1, + RT_MEM_SIZES = 2, + RT_GPU_FUNC_CAPS = 3, + RT_GPU_FUNC_ID = 4, + RT_GPU_DEFAULT_ID = 5, + RT_WORK_GROUP_SIZE = 6, + RT_WORK_REGION_SIZE = 7, + RT_ARGUMENT_ARRAY = 8, + RT_GPU_PRINTF_ARRAY = 9, + RT_CPU_BARRIER_NAMES = 10, + RT_DEVICE_ENQUEUE = 11, + RT_KERNEL_INDEX = 12, + RT_KERNEL_NAME = 13, + RT_KERNEL_NAMES = 14, + RT_CONTAINS_LLVMIR = 15, + RT_CONTAINS_OPTIONS = 16, + RT_CONTAINS_BRIG = 17, + RT_CONTAINS_HSAIL = 18, + RT_CONTAINS_ISA = 19, + RT_CONTAINS_LOADER_MAP = 20, + RT_LAST_TYPE = 21 } aclQueryType_0_8; //! An enumeration for the various GPU capabilities diff --git a/rocclr/compiler/lib/utils/bif_section_labels.hpp b/rocclr/compiler/lib/utils/bif_section_labels.hpp index b684661d8b..69d9bb4887 100644 --- a/rocclr/compiler/lib/utils/bif_section_labels.hpp +++ b/rocclr/compiler/lib/utils/bif_section_labels.hpp @@ -37,7 +37,8 @@ typedef enum { symAsmText, symDLL, symLast, - symKernelStats + symKernelStats, + symBRIGLoaderMap } oclBIFSymbolID; struct oclBIFSymbolStruct { @@ -49,7 +50,7 @@ struct oclBIFSymbolStruct { }; // These are the symbols that are defined by the BIF 3.0 spec -static const oclBIFSymbolStruct BIF30[27] = +static const oclBIFSymbolStruct BIF30[28] = { // 0: BIF 3.0 compiler options, .comment section via library support. {symOpenclCompilerOptions, @@ -109,6 +110,8 @@ static const oclBIFSymbolStruct BIF30[27] = {symDLL, {"", ""}, {aclLAST, aclTEXT}}, // 26: BIF 3.0 HSAIL kernel statistics {symKernelStats, { "__HSAIL_", "_kernel_statistics" }, {aclKSTATS, aclLAST}}, + // 27: BIF 3.0 BRIG loader map + {symBRIGLoaderMap, { "__Loader_Map", "" }, {aclCODEGEN, aclLAST}}, }; // BIF30 diff --git a/rocclr/runtime/device/gpu/gpuprogram.cpp b/rocclr/runtime/device/gpu/gpuprogram.cpp index 0756ebad7e..c477183204 100644 --- a/rocclr/runtime/device/gpu/gpuprogram.cpp +++ b/rocclr/runtime/device/gpu/gpuprogram.cpp @@ -1978,21 +1978,20 @@ HSAILProgram::getCompilationStagesFromBinary(std::vector& completeStage if (containsBrig) { completeStages.push_back(from); from = ACL_TYPE_HSAIL_BINARY; - // Here we should check that CG stage was done. - // Right now there are 2 criterions to check it (besides BRIG itself): - // 1. matadata symbols symOpenclKernel for every kernel. - // 2. HSAIL text in aclCODEGEN section. - // Unfortunately there is no appropriate way in Compiler Lib to check 1. - // because kernel names are unknown here, therefore only 2. - if (containsHsailText) { - completeStages.push_back(from); - from = ACL_TYPE_CG; - } - } - else if (containsHsailText) { + } else if (containsHsailText) { completeStages.push_back(from); from = ACL_TYPE_HSAIL_TEXT; } + // Checking Loader Map symbol from CG section + bool containsLoaderMap = true; + errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_LOADER_MAP, NULL, &containsLoaderMap, &boolSize); + if (errorCode != ACL_SUCCESS) { + containsLoaderMap = false; + } + if (containsLoaderMap) { + completeStages.push_back(from); + from = ACL_TYPE_CG; + } // Checking ISA in .text section bool containsShaderIsa = true; errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_ISA, NULL, &containsShaderIsa, &boolSize); @@ -2012,24 +2011,20 @@ HSAILProgram::getCompilationStagesFromBinary(std::vector& completeStage needOptionsCheck = false; break; case ACL_TYPE_HSAIL_BINARY: - case ACL_TYPE_CG: // do not check options, if LLVMIR is absent or might be absent or options are absent - if (curOptions.oVariables->BinLLVMIR || !containsLlvmirText || !containsOpts) { + if (!curOptions.oVariables->BinLLVMIR || !containsLlvmirText || !containsOpts) { needOptionsCheck = false; } break; + case ACL_TYPE_CG: case ACL_TYPE_ISA: // do not check options, if LLVMIR is absent or might be absent or options are absent - if (curOptions.oVariables->BinLLVMIR || !containsLlvmirText || !containsOpts) { + if (!curOptions.oVariables->BinLLVMIR || !containsLlvmirText || !containsOpts) { needOptionsCheck = false; } - if (containsBrig && containsHsailText && curOptions.oVariables->BinHSAIL) { + // do not check options, if BRIG is absent or might be absent or LoaderMap is absent + if (!curOptions.oVariables->BinCG || !containsBrig || !containsLoaderMap) { needOptionsCheck = false; - // recompile from prev. stage, if BRIG || HSAIL are absent - } else { - from = completeStages.back(); - completeStages.pop_back(); - needOptionsCheck = true; } break; // recompilation might be needed @@ -2119,6 +2114,7 @@ HSAILProgram::linkImpl(amd::option::Options* options) acl_error errorCode; aclType continueCompileFrom = ACL_TYPE_LLVMIR_BINARY; bool finalize = true; + bool hsaLoad = true; // If !binaryElf_ then program must have been created using clCreateProgramWithBinary if (!binaryElf_) { continueCompileFrom = getNextCompilationStageFromBinary(options); @@ -2147,23 +2143,24 @@ HSAILProgram::linkImpl(amd::option::Options* options) break; } case ACL_TYPE_CG: + hsaLoad = false; break; case ACL_TYPE_ISA: + hsaLoad = false; finalize = false; break; default: buildLog_ += "Error while BRIG Codegen phase: the binary is incomplete \n" ; return false; } - // ACL_TYPE_CG stage is always being performed - if (!isNull()) { + // ACL_TYPE_CG stage is not performed for offline compilation + if (!isNull() && hsaLoad) { if (!_aclHsaLoader(dev().hsaCompiler(), binaryElf_, this, &AllocateGPUMemory, &DmaMemoryCopy, &GetSamplerObjectParams, &InitializeSamplerObject)) { buildLog_ += "Error while BRIG Codegen phase: loading BRIG globals in the ELF \n"; return false; } } - size_t kernelNamesSize = 0; errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_KERNEL_NAMES, NULL, NULL, &kernelNamesSize); if (errorCode != ACL_SUCCESS) {