From a3dfe7e4579263cddbcf789125aee44d13d0a3a3 Mon Sep 17 00:00:00 2001 From: foreman Date: Fri, 11 Dec 2015 16:46:21 -0500 Subject: [PATCH] P4 to Git Change 1220218 by yaxunl@yaxunl_stg_win50 on 2015/12/11 16:35:30 SWDEV-83705 - [SPIRV] Fix failure in SPIR-V conformance test compile_and_link. e_rawfile of elf needs to be updated after LLVM section is inserted into the elf containing SPIR-V. Affected files ... ... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/acl.cpp#38 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#87 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/acl.h#11 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifbase.cpp#54 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifbase.hpp#24 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.cpp#13 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.h#23 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#215 edit [ROCm/clr commit: f5acde74f7954a979c5d62e9d3669e8123c1a7cc] --- .../rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp | 9 ++++++++- projects/clr/rocclr/compiler/lib/include/v0_8/acl.h | 3 +++ projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp | 5 +++++ projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h | 2 ++ projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/projects/clr/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp b/projects/clr/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp index bbe5aae1e3..7cad8119ef 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp @@ -1670,6 +1670,10 @@ if_aclLink(aclCompiler *cl, const void *ptr = cl->clAPI.extSec(cl, src_bin, &data_size, aclLLVMIR, &error_code); if (ptr == NULL) ptr = cl->clAPI.extSec(cl, src_bin, &data_size, aclSPIR, &error_code); + if (ptr == NULL) { + error_code = ACL_INVALID_FILE; + goto internal_link_failure; + } char *mod = new char[data_size]; memcpy(mod, ptr, data_size); module = cl->feAPI.toModule(ald, mod, data_size, context, &error_code); @@ -1677,7 +1681,10 @@ if_aclLink(aclCompiler *cl, const void *ptr = cl->clAPI.extSec(cl, libs[x], &data_size, aclLLVMIR, NULL); if (ptr == NULL) ptr = cl->clAPI.extSec(cl, libs[x], &data_size, aclSPIR, NULL); - if (ptr == NULL) continue; + if (ptr == NULL) { + error_code = ACL_INVALID_FILE; + goto internal_link_failure; + } mod = new char[data_size]; memcpy(mod, ptr, data_size); mod_libs[x] = cl->feAPI.toModule(ald, mod, data_size, context, &error_code); diff --git a/projects/clr/rocclr/compiler/lib/include/v0_8/acl.h b/projects/clr/rocclr/compiler/lib/include/v0_8/acl.h index ba2669196c..b70bd14fb7 100644 --- a/projects/clr/rocclr/compiler/lib/include/v0_8/acl.h +++ b/projects/clr/rocclr/compiler/lib/include/v0_8/acl.h @@ -98,6 +98,9 @@ acl_error ACL_API_ENTRY aclWriteToMem(aclBinary *bin, void **mem, size_t *size) ACL_API_0_8; +acl_error ACL_API_ENTRY + aclUpdateRawFile(aclBinary *bin); + aclBinary* ACL_API_ENTRY aclCreateFromBinary(const aclBinary *binary, aclBIFVersion version) ACL_API_0_8; 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 e4714be778..d6427e5e29 100644 --- a/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp +++ b/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.cpp @@ -1043,3 +1043,8 @@ convertBIF31ToBIF30(aclBinary *src) { } return dst; } + +void dump(aclBinary *bin) { + bifbase *elfBin = reinterpret_cast(bin->bin); + elfBin->dump(); +} 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 620e5c3724..06ed8a6105 100644 --- a/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h +++ b/projects/clr/rocclr/compiler/lib/utils/v0_8/libUtils.h @@ -391,4 +391,6 @@ isBcMagic(const char* p) return true; } +void dump(aclBinary *bin); + #endif // _CL_LIB_UTILS_0_8_H_ diff --git a/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp b/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp index 3b915235b4..cc6fcb1178 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp @@ -1821,6 +1821,9 @@ HSAILProgram::linkImpl( buildLog_ += "Error while linking: Could not load SPIR-V" ; return false; } + // Need to update elf raw file since it will be used by + // aclCreateFromBinary. + aclUpdateRawFile(binaryElf_); } else { buildLog_ +="Error while linking : \ Invalid binary (Missing LLVMIR section)" ;