From d39ccbbfece3529bb09a5e5f038b20d02cb6c1c0 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 17 Apr 2015 10:24:36 -0400
Subject: [PATCH] P4 to Git Change 1141872 by yaxunl@yaxunl_stg_win50 on
2015/04/17 10:17:05
ECR #354633 - SPIR: Making SPIR loading work for HSAIL path.
Fixed arch type when creating elf for SPIR.
Fixed query of elf for contained IR.
Fixed copying elf binary containing SPIR for HSAIL path.
Added translation of kernel name in SPIR loader for HSAIL path.
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#65 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclEnums.h#18 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifbase.cpp#52 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Linker/AMDFixupKernelModule.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Transforms/SPIR/AMDSPIRLoader.cpp#91 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Transforms/SPIR/AMDSPIRLoader.h#15 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#177 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#192 edit
... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/CLEnumCheck.cpp#42 edit
---
.../lib/backends/common/v0_8/if_acl.cpp | 10 ++++++++
rocclr/compiler/lib/include/v0_8/aclEnums.h | 3 ++-
rocclr/runtime/device/device.cpp | 25 +++++++++++++------
rocclr/runtime/device/gpu/gpuprogram.cpp | 15 +++++++++--
4 files changed, 43 insertions(+), 10 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 c000b1cdf3..c3ffe81ab3 100644
--- a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp
+++ b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp
@@ -2245,6 +2245,16 @@ if_aclQueryInfo(aclCompiler *cl,
return ACL_SUCCESS;
}
return ACL_ERROR;
+ case RT_CONTAINS_SPIR:
+ if (!ptr) {
+ *size = sizeof(bool);
+ return ACL_SUCCESS;
+ } else if (*size >= sizeof(bool)) {
+ bool contains = elfBin->isSection(aclSPIR);
+ memcpy(ptr, &contains, sizeof(bool));
+ return ACL_SUCCESS;
+ }
+ return ACL_ERROR;
case RT_CONTAINS_OPTIONS:
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 70fdaf49c0..513acc4e86 100644
--- a/rocclr/compiler/lib/include/v0_8/aclEnums.h
+++ b/rocclr/compiler/lib/include/v0_8/aclEnums.h
@@ -209,7 +209,8 @@ typedef enum _rt_query_types_enum_0_8 {
RT_CONTAINS_HSAIL = 18,
RT_CONTAINS_ISA = 19,
RT_CONTAINS_LOADER_MAP = 20,
- RT_LAST_TYPE = 21
+ RT_CONTAINS_SPIR = 21,
+ RT_LAST_TYPE = 22
} aclQueryType_0_8;
//! An enumeration for the various GPU capabilities
diff --git a/rocclr/runtime/device/device.cpp b/rocclr/runtime/device/device.cpp
index 9fc3b37191..c698e2fd02 100644
--- a/rocclr/runtime/device/device.cpp
+++ b/rocclr/runtime/device/device.cpp
@@ -1070,16 +1070,27 @@ Program::initClBinary(char* binaryIn, size_t size)
aclBinaryFini(aclbin_v30);
return false;
}
- aclBinary* aclbin_v21 = aclCreateFromBinary(aclbin_v30,aclBIFVersion21);
- err = aclWriteToMem(aclbin_v21, reinterpret_cast(&bin), &sz);
- if (err != ACL_SUCCESS) {
- LogWarning("aclWriteToMem failed");
+ if (info().arch_id == aclHSAIL || info().arch_id == aclHSAIL64) {
+ err = aclWriteToMem(aclbin_v30, reinterpret_cast(&bin), &sz);
+ if (err != ACL_SUCCESS) {
+ LogWarning("aclWriteToMem failed");
+ aclBinaryFini(aclbin_v30);
+ return false;
+ }
+ aclBinaryFini(aclbin_v30);
+ }
+ else {
+ aclBinary* aclbin_v21 = aclCreateFromBinary(aclbin_v30,aclBIFVersion21);
+ err = aclWriteToMem(aclbin_v21, reinterpret_cast(&bin), &sz);
+ if (err != ACL_SUCCESS) {
+ LogWarning("aclWriteToMem failed");
+ aclBinaryFini(aclbin_v30);
+ aclBinaryFini(aclbin_v21);
+ return false;
+ }
aclBinaryFini(aclbin_v30);
aclBinaryFini(aclbin_v21);
- return false;
}
- aclBinaryFini(aclbin_v30);
- aclBinaryFini(aclbin_v21);
}
else
{
diff --git a/rocclr/runtime/device/gpu/gpuprogram.cpp b/rocclr/runtime/device/gpu/gpuprogram.cpp
index b788cb76a4..46702cd818 100644
--- a/rocclr/runtime/device/gpu/gpuprogram.cpp
+++ b/rocclr/runtime/device/gpu/gpuprogram.cpp
@@ -1948,6 +1948,15 @@ HSAILProgram::getCompilationStagesFromBinary(std::vector& completeStage
size_t boolSize = sizeof(bool);
//! @todo Should we also check for ACL_TYPE_OPENCL & ACL_TYPE_LLVMIR_TEXT?
// Checking llvmir in .llvmir section
+ bool containsSpirText = true;
+ errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_SPIR, NULL, &containsSpirText, &boolSize);
+ if (errorCode != ACL_SUCCESS) {
+ containsSpirText = false;
+ }
+ if (containsSpirText) {
+ completeStages.push_back(from);
+ from = ACL_TYPE_SPIR_BINARY;
+ }
bool containsLlvmirText = true;
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_LLVMIR, NULL, &containsLlvmirText, &boolSize);
if (errorCode != ACL_SUCCESS) {
@@ -2098,6 +2107,7 @@ HSAILProgram::getNextCompilationStageFromBinary(amd::option::Options* options) {
while (!completeStages.empty()) {
continueCompileFrom = completeStages.back();
if (continueCompileFrom == ACL_TYPE_LLVMIR_BINARY ||
+ continueCompileFrom == ACL_TYPE_SPIR_BINARY ||
continueCompileFrom == ACL_TYPE_DEFAULT) {
break;
}
@@ -2120,6 +2130,7 @@ HSAILProgram::linkImpl(amd::option::Options* options)
continueCompileFrom = getNextCompilationStageFromBinary(options);
}
switch (continueCompileFrom) {
+ case ACL_TYPE_SPIR_BINARY:
// Compilation from ACL_TYPE_LLVMIR_BINARY to ACL_TYPE_CG in cases:
// 1. if the program is not created with binary;
// 2. if the program is created with binary and contains only .llvmir & .comment
@@ -2301,9 +2312,9 @@ HSAILProgram::fillResListWithKernels(
const aclTargetInfo &
HSAILProgram::info(const char * str) {
acl_error err;
- std::string arch = GPU_TARGET_INFO_ARCH;
+ std::string arch = "hsail";
if (dev().settings().use64BitPtr_) {
- arch += "64";
+ arch = "hsail-64";
}
info_ = aclGetTargetInfo(arch.c_str(), ( str && str[0] == '\0' ?
dev().hwInfo()->targetName_ : str ), &err);