From fb2d2a6358ae9a3c91dc069954e282cc631d3b3d Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 7 Aug 2015 09:11:37 -0400
Subject: [PATCH] P4 to Git Change 1178107 by emankov@em-hsa-amd on 2015/08/07
09:05:47
ECR #333753 - Compiler Lib: switch Bif Version to 3.1 by default for HSAIL
It is needed due to the latest AMD HSA Code Object introduction in BIF.
TODO (in separate changes):
1. Analyze the changes in sections/symbols and remove (if needed) unused anymore (in BIF31), for example, symISAMeta, check backward compatibility.
2. Move the bif versions/conversions code from libUtils to loader\Bif.
3. Refactor the bif versions/conversions code in order to get rid of copy/paste (templates?).
4. Drop aclBIFVersionCAL.
Testing: pre check-in
Reviewer: Brian Sumner, Nikolay Haustov
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/acl.cpp#33 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclEnums.h#20 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif.hpp#3 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif20.cpp#14 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif20.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif21.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif21.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif30.cpp#26 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif30.hpp#8 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif31.cpp#1 add
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bif31.hpp#1 add
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifbase.cpp#53 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifbase.hpp#23 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/bif_section_labels.hpp#22 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.cpp#11 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.h#21 edit
... //depot/stg/opencl/drivers/opencl/compiler/tools/aoc2/aoc2.cpp#75 edit
... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/binary/BIFAssumptionCheck.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/binary/BIFAssumptionCheck.hpp#5 edit
... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/CLEnumCheck.cpp#45 edit
[ROCm/clr commit: e54e8da337abecdbc042700e7a398420d3c06f53]
---
.../compiler/lib/include/v0_8/aclEnums.h | 13 +-
.../compiler/lib/utils/bif_section_labels.hpp | 67 ++++++++
.../compiler/lib/utils/v0_8/libUtils.cpp | 152 +++++++++++++++++-
.../rocclr/compiler/lib/utils/v0_8/libUtils.h | 24 +++
4 files changed, 247 insertions(+), 9 deletions(-)
diff --git a/projects/clr/rocclr/compiler/lib/include/v0_8/aclEnums.h b/projects/clr/rocclr/compiler/lib/include/v0_8/aclEnums.h
index aa51dbda16..82e3703fd1 100644
--- a/projects/clr/rocclr/compiler/lib/include/v0_8/aclEnums.h
+++ b/projects/clr/rocclr/compiler/lib/include/v0_8/aclEnums.h
@@ -129,12 +129,13 @@ typedef enum _acl_loader_type_enum_0_8 {
// Enumeration for the various acl versions
typedef enum _bif_version_enum_0_8 {
aclBIFVersionError = 0, // Error
- aclBIFVersion20 = 1, // Version 2.0 of the OpenCL BIF
- aclBIFVersion21 = 2, // Version 2.1 of the OpenCL BIF
- aclBIFVersion30 = 3, // Version 3.0 of the OpenCL BIF
- aclBIFVersionLatest = aclBIFVersion30, // Most recent version of the BIF
- aclBIFVersionCAL = 4,
- aclBIFVersionLast = 5
+ aclBIFVersion20 = 1, // Version 2.0 of the OpenCL BIF
+ aclBIFVersion21 = 2, // Version 2.1 of the OpenCL BIF
+ aclBIFVersion30 = 3, // Version 3.0 of the OpenCL BIF
+ aclBIFVersion31 = 4, // Version 3.1 of the OpenCL BIF
+ aclBIFVersionLatest = aclBIFVersion31, // Most recent version of the BIF
+ aclBIFVersionCAL = 5,
+ aclBIFVersionLast = 6
} aclBIFVersion_0_8;
// Enumeration for the various platform types
diff --git a/projects/clr/rocclr/compiler/lib/utils/bif_section_labels.hpp b/projects/clr/rocclr/compiler/lib/utils/bif_section_labels.hpp
index 7106cff7f0..fe729bd4c2 100644
--- a/projects/clr/rocclr/compiler/lib/utils/bif_section_labels.hpp
+++ b/projects/clr/rocclr/compiler/lib/utils/bif_section_labels.hpp
@@ -51,6 +51,73 @@ struct oclBIFSymbolStruct {
aclSections sections[2];
};
+// TODO: analyze the changes since 30 and remove unused anymore symbols,
+// for example, symISAMeta, update convert functions, check backward compatibility.
+// These are the symbols that are defined by the BIF 3.1 spec
+static const oclBIFSymbolStruct BIF31[28] =
+{
+ // 0: BIF 3.0 compiler options, .comment section via library support.
+ {symOpenclCompilerOptions,
+ { "__OpenCL_", "compiler_options" }, {aclCOMMENT, aclCOMMENT}},
+ // 1: BIF 3.0 AMDIL compile options, .comment section via -fbin-amdil.
+ {symAMDILCompilerOptions,
+ { "__AMDIL_", "_compiler_options" }, {aclCOMMENT, aclLAST}},
+ // 2: BIF 3.0 HSAIL compile options, .comment section via -fbin-hsail.
+ {symHSACompilerOptions,
+ { "__HSAIL_", "_compiler_options" }, {aclCOMMENT, aclLAST}},
+ // 3: BIF 3.0 linker options, .comment section via library support.
+ {symOpenclLinkerOptions,
+ { "__OpenCL_", "linker_options" }, {aclCOMMENT, aclCOMMENT}},
+ // 4: BIF 3.0 per kernel metadata, .cg section via -fbin-cg for CPU,
+ // .rodata section via -fbin-exe for GPU
+ {symOpenclMeta, { "__OpenCL_", "_metadata" }, {aclRODATA, aclCODEGEN}},
+ // 5: BIF 3.0 per kernel text(x86 only), .cg section via -fbin-cg.
+ {symOpenclKernel, { "__OpenCL_", "_kernel" }, {aclLAST, aclCODEGEN}},
+ // 6: BIF 3.0 per kernel stub(x86 only), .cg section via -fbin-cg.
+ {symOpenclStub, { "__OpenCL_", "_stub" }, {aclLAST, aclCODEGEN}},
+ // 7: BIF 3.0 per constant buffer data, .rodata section via -fbin-exe.
+ {symOpenclGlobal, { "__OpenCL_", "_global" }, {aclRODATA, aclRODATA}},
+ // 8: BIF 3.0 per kernel ISA metadata, .rodata section via -fbin-exe.
+ {symISAMeta, { "__ISA_", "_metadata" }, {aclRODATA, aclLAST}},
+ // 9: BIF 3.0 per kernel ISA, .text section via -fbin-exe.
+ {symISABinary, { "__ISA_", "_binary" }, {aclTEXT, aclLAST}},
+ // 10: BIF 3.0 per kernel AMDIL source, .internal section via -fbin-amdil.
+ {symAMDILText, { "__AMDIL_", "_text" }, {aclINTERNAL, aclLAST}},
+ // 11: BIF 3.0 per kernel AMDIL binary, .internal section via -fbin-amdil.
+ {symAMDILBinary, { "__AMDIL_", "_binary" }, {aclINTERNAL, aclLAST}},
+ // 12: BIF 3.0 per kernel HSAIL source, .internal section via -fbin-hsail.
+ {symHSAILText, { "__HSAIL_", "_text" }, {aclCODEGEN, aclLAST}},
+ // 13: BIF 3.0 per kernel HSAIL binary, .internal section via -fbin-hsail.
+ {symBRIG, { "__BRIG__", "" }, {aclBRIG, aclLAST}},
+ // 14: BIF 3.0 per function metadata, .internal section via -fbin-amdil.
+ {symAMDILFMeta, { "__AMDIL_", "_fmetadata" }, {aclINTERNAL, aclLAST}},
+ // 15: BIF 3.0 per kernel ISA text, .internal section via disassembly.
+ {symISAText, { "__ISA_", "_text" }, {aclINTERNAL, aclLAST}},
+ // 16: BIF 3.0 BRIG operands declarations, .brig section via -fbin-brig.
+ {symBRIGxxx1, { "","" }, {aclLAST, aclLAST}},
+ // 17: Unused after changes in HSAIL PRM
+ {symBRIGxxx2, { "","" }, {aclLAST, aclLAST}},
+ // 18: BIF 3.0 BRIG strtab declarations, .brig section via -fbin-brig.
+ {symBRIGxxx3, { "","" }, {aclLAST, aclLAST}},
+ // 19: BIF 3.0 per kernel barrier metadata, only valid for X86.
+ {symX86Barrier, { "__X86_", "_barrier" }, {aclLAST, aclLAST}},
+ // 20: BIF 3.0 per kernel header, .internal section via -fbin-amdil.(Legacy from bif2.x)
+ {symAMDILHeader, { "__AMDIL_", "_header"}, {aclINTERNAL, aclLAST}},
+ // 21: BIF 3.0 HSA BRIG or ISA debug info
+ {symDebugInfo, { "__debug_brig__","__debug_isa__"}, {aclHSADEBUG, aclLAST}},
+ // 22: BIF 3.0 debugil text, .internal section via -g
+ {symDebugilText, { "__debugil_text", "" }, {aclINTERNAL, aclLAST}},
+ // 23: BIF 3.0 debugil binary, .internal section, can be converted from
+ // __debugil_text
+ {symDebugilBinary, { "__debugil_binary", "" }, {aclINTERNAL, aclLAST}},
+ {symAsmText, {"", ""}, {aclLAST, aclCODEGEN}},
+ {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}},
+}; // BIF31
+
// These are the symbols that are defined by the BIF 3.0 spec
static const oclBIFSymbolStruct BIF30[28] =
{
diff --git a/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp b/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp
index 71797a2962..55ec087c94 100644
--- a/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp
+++ b/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp
@@ -639,6 +639,28 @@ convertBIF30MachineTo2X(bifbase *elfBin, const aclTargetInfo *tgtInfo)
elfBin->setTarget(machine, pform);
}
// FIXME: This needs to be moved into the elf classes
+static void
+convertBIF2XMachineTo31(bifbase *elfBin)
+{
+ uint16_t machine = 0;
+ aclPlatform pform = aclPlatformLast;
+ if (elfBin == NULL) return;
+ elfBin->getTarget(machine, pform);
+ assert(pform != aclPlatformCompLib
+ && "Platform is specified incorrectly!");
+ if (pform == aclPlatformCPU) {
+ uint16_t type;
+ elfBin->getType(type);
+ machine = (type == ELFCLASS32 ? EM_386 : EM_X86_64);
+ } else if (pform == aclPlatformCAL) {
+ machine = EM_AMDIL;
+ } else {
+ assert(!"Unknown platform found!");
+ }
+ pform = aclPlatformCompLib;
+ elfBin->setTarget(machine, pform);
+}
+
static void
convertBIF2XMachineTo30(bifbase *elfBin)
{
@@ -757,12 +779,15 @@ createELFCopy(aclBinary *src) {
case aclBIFVersion20:
dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif20)));
dstBin = new (dstBin) bif20(srcBin->get20()); break;
- case aclBIFVersion21:
+ case aclBIFVersion21:
dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif21)));
dstBin = new (dstBin) bif21(srcBin->get21()); break;
- case aclBIFVersion30:
+ case aclBIFVersion30:
dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif30)));
dstBin = new (dstBin) bif30(srcBin->get30()); break;
+ case aclBIFVersion31:
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif31)));
+ dstBin = new (dstBin) bif31(srcBin->get31()); break;
}
if (dstBin->hasError()) {
aclBinaryFini(dst);
@@ -815,6 +840,26 @@ convertBIF20ToBIF30(aclBinary *src) {
return dst;
}
+// Create a BIF3.1 elf from a BIF 2.0 elf.
+aclBinary*
+convertBIF20ToBIF31(aclBinary *src) {
+ aclBinary *dst = cloneOclElfNoBIF(src);
+ if (dst != NULL) {
+ bifbase *srcBin = reinterpret_cast(aclutGetBIF(src));
+ assert(srcBin->get20() != NULL && "Passed in an invalid binary!");
+ bif31 *dstBin = NULL;
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif31)));
+ dstBin = new (dstBin) bif31(srcBin->get20());
+ if (dstBin->hasError()) {
+ aclBinaryFini(dst);
+ return NULL;
+ }
+ dst->bin = reinterpret_cast(dstBin);
+ convertBIF2XMachineTo31(dstBin);
+ }
+ return dst;
+}
+
// Create a BIF2.0 elf from a BIF 2.1 elf.
// All sections except for the COMMENT section is copied
// verbatim and the section is set to NONE.
@@ -858,6 +903,27 @@ convertBIF21ToBIF30(aclBinary *src) {
return dst;
}
+// Create a BIF3.1 elf from a BIF 2.1 elf.
+// See BIF spec for 3.1 to 2.1 conversion.
+aclBinary*
+convertBIF21ToBIF31(aclBinary *src) {
+ aclBinary *dst = cloneOclElfNoBIF(src);
+ if (dst != NULL) {
+ bifbase *srcBin = reinterpret_cast(aclutGetBIF(src));
+ assert(srcBin->get21() != NULL && "Passed in an invalid binary!");
+ bif31 *dstBin = NULL;
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif31)));
+ dstBin = new (dstBin) bif31(srcBin->get21());
+ if (dstBin->hasError()) {
+ aclBinaryFini(dst);
+ return NULL;
+ }
+ dst->bin = reinterpret_cast(dstBin);
+ convertBIF2XMachineTo31(dstBin);
+ }
+ return dst;
+}
+
// Create a BIF2.0 elf from a BIF 3.0 elf.
// See BIF spec for 3.0 to 2.0 conversion.
aclBinary*
@@ -879,7 +945,7 @@ convertBIF30ToBIF20(aclBinary *src) {
}
// Create a BIF2.1 elf from a BIF 3.0 elf
-// See BIF spec for 3.0 to 2.0 conversion
+// See BIF spec for 3.0 to 2.1 conversion
// but also include the COMMENT section.
aclBinary*
convertBIF30ToBIF21(aclBinary *src) {
@@ -898,3 +964,83 @@ convertBIF30ToBIF21(aclBinary *src) {
}
return dst;
}
+
+// Create a BIF3.1 elf from a BIF 3.0 elf
+// See BIF spec for 3.0 to 3.1 conversion.
+aclBinary*
+convertBIF30ToBIF31(aclBinary *src) {
+ aclBinary *dst = cloneOclElfNoBIF(src);
+ if (dst != NULL) {
+ bifbase *srcBin = reinterpret_cast(aclutGetBIF(src));
+ assert(srcBin->get30() != NULL && "Passed in an invalid binary!");
+ bif31 *dstBin = NULL;
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif31)));
+ dstBin = new (dstBin) bif31(srcBin->get30());
+ if (dstBin->hasError()) {
+ aclBinaryFini(dst);
+ return NULL;
+ }
+ dst->bin = reinterpret_cast(dstBin);
+ }
+ return dst;
+}
+
+// Create a BIF2.0 elf from a BIF 3.1 elf.
+// See BIF spec for 3.1 to 2.0 conversion.
+aclBinary*
+convertBIF31ToBIF20(aclBinary *src) {
+ aclBinary *dst = cloneOclElfNoBIF(src);
+ if (dst != NULL) {
+ bifbase *srcBin = reinterpret_cast(aclutGetBIF(src));
+ assert(srcBin->get31() != NULL && "Passed in an invalid binary!");
+ bif20 *dstBin = NULL;
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif20)));
+ dstBin = new (dstBin) bif20(srcBin->get31());
+ if (dstBin->hasError()) {
+ aclBinaryFini(dst);
+ return NULL;
+ }
+ dst->bin = reinterpret_cast(dstBin);
+ }
+ return dst;
+}
+
+// Create a BIF2.1 elf from a BIF 3.1 elf
+// See BIF spec for 3.1 to 2.1 conversion.
+aclBinary*
+convertBIF31ToBIF21(aclBinary *src) {
+ aclBinary *dst = cloneOclElfNoBIF(src);
+ if (dst != NULL) {
+ bifbase *srcBin = reinterpret_cast(aclutGetBIF(src));
+ assert(srcBin->get31() != NULL && "Passed in an invalid binary!");
+ bif21 *dstBin = NULL;
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif21)));
+ dstBin = new (dstBin) bif21(srcBin->get31());
+ if (dstBin->hasError()) {
+ aclBinaryFini(dst);
+ return NULL;
+ }
+ dst->bin = reinterpret_cast(dstBin);
+ }
+ return dst;
+}
+
+// Create a BIF3.1 elf from a BIF 3.0 elf
+// See BIF spec for 3.0 to 3.1 conversion.
+aclBinary*
+convertBIF31ToBIF30(aclBinary *src) {
+ aclBinary *dst = cloneOclElfNoBIF(src);
+ if (dst != NULL) {
+ bifbase *srcBin = reinterpret_cast(aclutGetBIF(src));
+ assert(srcBin->get31() != NULL && "Passed in an invalid binary!");
+ bif30 *dstBin = NULL;
+ dstBin = reinterpret_cast(aclutAlloc(src)(sizeof(bif30)));
+ dstBin = new (dstBin) bif30(srcBin->get31());
+ if (dstBin->hasError()) {
+ aclBinaryFini(dst);
+ return NULL;
+ }
+ dst->bin = reinterpret_cast(dstBin);
+ }
+ return dst;
+}
diff --git a/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h b/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h
index 878479f302..2f9775f3ae 100644
--- a/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h
+++ b/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h
@@ -67,6 +67,10 @@ convertBIF20ToBIF21(aclBinary *src);
aclBinary*
convertBIF20ToBIF30(aclBinary *src);
+// Create a BIF3.1 elf from a BIF 2.0 elf
+aclBinary*
+convertBIF20ToBIF31(aclBinary *src);
+
// Create a BIF2.0 elf from a BIF 2.1 elf
aclBinary*
convertBIF21ToBIF20(aclBinary *src);
@@ -75,6 +79,10 @@ convertBIF21ToBIF20(aclBinary *src);
aclBinary*
convertBIF21ToBIF30(aclBinary *src);
+// Create a BIF3.1 elf from a BIF 2.1 elf
+aclBinary*
+convertBIF21ToBIF31(aclBinary *src);
+
// Create a BIF2.0 elf from a BIF 3.0 elf
aclBinary*
convertBIF30ToBIF20(aclBinary *src);
@@ -83,6 +91,22 @@ convertBIF30ToBIF20(aclBinary *src);
aclBinary*
convertBIF30ToBIF21(aclBinary *src);
+// Create a BIF3.1 elf from a BIF 3.0 elf
+aclBinary*
+convertBIF30ToBIF31(aclBinary *src);
+
+// Create a BIF2.0 elf from a BIF 3.1 elf
+aclBinary*
+convertBIF31ToBIF20(aclBinary *src);
+
+// Create a BIF2.1 elf from a BIF 3.1 elf
+aclBinary*
+convertBIF31ToBIF21(aclBinary *src);
+
+// Create a BIF3.0 elf from a BIF 3.1 elf
+aclBinary*
+convertBIF31ToBIF30(aclBinary *src);
+
// get a pointer to the aclBIF irrespective of the
// binary version.
aclBIF*