From 84508bb5a472e68edfb0abf343b817124a28c02e Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 30 Jan 2015 07:48:28 -0500
Subject: [PATCH] P4 to Git Change 1116855 by emankov@em-hsa-amd on 2015/01/30
07:38:03
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
ECR #333753 - Compiler Lib/ORCA RT/Performance: BRIG in BIF is not needed anymore for finalizing & executing ISA (except cases with program scope global variables).
[Description] The feature is intended to minimize the binary size for execution.
This is half-hearted solution: If -fno-bin-cg is set, then after ISA finalization all BRIG sections are removed from the binary, but if there are program scope global variables in code, the option is ignored and all BRIG sections retain in binary for further globalsÂ’ allocation & initialization. The complete solution awaits Code Objects implementation.
+ Additionally change fixes Bug 10478.
+ Recompilation steps determination is changed in RT.
+ symBRIGLoaderMap is added to bif_section_labels.
+ RT_CONTAINS_LOADER_MAP is added for aclQueryInfo in order to check symBRIGLoaderMap existance in binary.
+ complib tests are added on -fbin-cg/-fno-bin-cg.
+ ocltst -t complib -M CLEnumCheck is updated.
[Side effects] performance improvement, memory consumption reduction
[TODO] Do the same on .hsa bits.
[Testing] pre check-in, make smoke, complib, ocltst: complib, compiler, runtime, binary
[Reviewer] German Andryeyev
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#59 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/brig_loader.cpp#17 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/hsail_be.cpp#36 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/hsail_be.hpp#12 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/scwrapper/scClientAPI.cpp#21 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclEnums.h#16 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/bif_section_labels.hpp#19 edit
... //depot/stg/opencl/drivers/opencl/compiler/loader/libloader/loader.cpp#12 edit
... //depot/stg/opencl/drivers/opencl/compiler/tools/aoc2/aoc2.cpp#64 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#188 edit
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fbin-cg-g/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fbin-cg-g_globals/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fbin-cg/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fbin-cg_globals/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fno-bin-cg-g/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fno-bin-cg-g_globals/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fno-bin-cg/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/options/-fno-bin-cg_globals/HelloWorld_Kernel_cl.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/hsa/tlst/complib.tlst#5 edit
... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/CLEnumCheck.cpp#40 edit
---
.../lib/backends/common/v0_8/if_acl.cpp | 27 +++++++++++
rocclr/compiler/lib/include/v0_8/aclEnums.h | 43 +++++++++---------
.../compiler/lib/utils/bif_section_labels.hpp | 7 ++-
rocclr/runtime/device/gpu/gpuprogram.cpp | 45 +++++++++----------
4 files changed, 75 insertions(+), 47 deletions(-)
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) {