P4 to Git Change 1182078 by yaxunl@yaxunl_stg_win50 on 2015/08/19 07:12:32
ECR #354633 - SPIR-V: Add consumption of SPIR-V to HSAIL path. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#120 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#36 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/icd/OpenCL.def.in#11 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/icd/icd_exports.map.in#7 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/Makefile#35 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/acl.cpp#34 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/aclValidation.cpp#6 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#73 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/build/Makefile.complib#90 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/acl.h#10 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclEnums.h#21 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclTypes.h#7 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifinternal.hpp#11 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/spirv/Makefile#1 add ... //depot/stg/opencl/drivers/opencl/compiler/lib/spirv/build/Makefile#1 add ... //depot/stg/opencl/drivers/opencl/compiler/lib/spirv/build/Makefile.spirv#1 add ... //depot/stg/opencl/drivers/opencl/compiler/lib/spirv/spirvUtils.cpp#1 add ... //depot/stg/opencl/drivers/opencl/compiler/lib/spirv/spirvUtils.h#1 add ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/options.hpp#16 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.h#22 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#182 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#250 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#200 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#64 edit ... //depot/stg/opencl/drivers/opencl/tests/conformance/devel/2.0/test_conformance/spirv/select.zip#1 add ... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/CLEnumCheck.cpp#46 edit ... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/CLEnumCheck.h#4 edit ... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/aclAPI.cpp#20 edit
This commit is contained in:
@@ -32,6 +32,8 @@ extern void DeviceUnload();
|
||||
#endif
|
||||
|
||||
#include "utils/bif_section_labels.hpp"
|
||||
#include "utils/libUtils.h"
|
||||
#include "spirv/spirvUtils.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -41,20 +43,7 @@ extern void DeviceUnload();
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
#if !defined(BCMAG)
|
||||
#define BCMAG "BC"
|
||||
#define SBCMAG 2
|
||||
#endif
|
||||
// Helper predicate returns true if p starts with bit code signature.
|
||||
// TODO: Move it into Compiler Lib back in new 1_0 API
|
||||
inline static bool
|
||||
isBcMagic(const char* p)
|
||||
{
|
||||
if (p==NULL || strncmp(p, BCMAG, SBCMAG) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
namespace device {
|
||||
extern const char* BlitSourceCode;
|
||||
@@ -252,27 +241,6 @@ Device::~Device()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Move it into Compiler Lib in new 1_0 API
|
||||
bool
|
||||
Device::verifyBinaryImage( const void* image, size_t size) const
|
||||
{
|
||||
const char* p = static_cast<const char*>(image);
|
||||
#if defined(HAVE_BLOWFISH_H)
|
||||
int outBufSize;
|
||||
if (amd::isEncryptedBIF(p, (int)size, &outBufSize)) {
|
||||
// For encrypted image, check it later and simply return true here.
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (amd::isElfMagic(p)) {
|
||||
return true;
|
||||
}
|
||||
if (isBcMagic(p)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Device::isAncestor(const Device* sub) const
|
||||
{
|
||||
@@ -1069,7 +1037,8 @@ Program::initClBinary(char* binaryIn, size_t size)
|
||||
int encryptCode = 0;
|
||||
char* decryptedBin = NULL;
|
||||
|
||||
if (isBcMagic(binaryIn))
|
||||
bool isSPIRV = isSPIRVMagic(binaryIn, size);
|
||||
if (isSPIRV || isBcMagic(binaryIn))
|
||||
{
|
||||
acl_error err = ACL_SUCCESS;
|
||||
aclBinaryOptions binOpts = {0};
|
||||
@@ -1087,7 +1056,8 @@ Program::initClBinary(char* binaryIn, size_t size)
|
||||
aclBinaryFini(aclbin_v30);
|
||||
return false;
|
||||
}
|
||||
err = aclInsertSection(device().compiler(), aclbin_v30, binaryIn, size, aclSPIR);
|
||||
err = aclInsertSection(device().compiler(), aclbin_v30, binaryIn, size,
|
||||
isSPIRV?aclSPIRV:aclSPIR);
|
||||
if (ACL_SUCCESS != err) {
|
||||
LogWarning("aclInsertSection failed");
|
||||
aclBinaryFini(aclbin_v30);
|
||||
|
||||
@@ -1648,9 +1648,6 @@ public:
|
||||
const amd::Kernel& kernel,
|
||||
const device::VirtualDevice* vdev) { return true; };
|
||||
|
||||
//! Returns true if the given binary image is valid for this device.
|
||||
bool verifyBinaryImage( const void* image, size_t size) const;
|
||||
|
||||
//! Returns TRUE if the device is available for computations
|
||||
bool isOnline() const { return online_; }
|
||||
//! Returns TRUE if the device is a root device (as opposed to sub-device)
|
||||
|
||||
@@ -1840,6 +1840,16 @@ HSAILProgram::getCompilationStagesFromBinary(std::vector<aclType>& 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 containsSpirv = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_,
|
||||
RT_CONTAINS_SPIRV, NULL, &containsSpirv, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsSpirv = false;
|
||||
}
|
||||
if (containsSpirv) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_SPIRV_BINARY;
|
||||
}
|
||||
bool containsSpirText = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_SPIR, NULL, &containsSpirText, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
@@ -1998,7 +2008,8 @@ HSAILProgram::getNextCompilationStageFromBinary(amd::option::Options* options) {
|
||||
if (recompile) {
|
||||
while (!completeStages.empty()) {
|
||||
continueCompileFrom = completeStages.back();
|
||||
if (continueCompileFrom == ACL_TYPE_LLVMIR_BINARY ||
|
||||
if (continueCompileFrom == ACL_TYPE_SPIRV_BINARY ||
|
||||
continueCompileFrom == ACL_TYPE_LLVMIR_BINARY ||
|
||||
continueCompileFrom == ACL_TYPE_SPIR_BINARY ||
|
||||
continueCompileFrom == ACL_TYPE_DEFAULT) {
|
||||
break;
|
||||
@@ -2032,6 +2043,7 @@ HSAILProgram::linkImpl(amd::option::Options* options)
|
||||
continueCompileFrom = getNextCompilationStageFromBinary(options);
|
||||
}
|
||||
switch (continueCompileFrom) {
|
||||
case ACL_TYPE_SPIRV_BINARY:
|
||||
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;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "platform/program.hpp"
|
||||
#include "platform/context.hpp"
|
||||
#include "utils/options.hpp"
|
||||
#include "acl.h"
|
||||
|
||||
#include <cstdlib> // for malloc
|
||||
#include <cstring> // for strcmp
|
||||
@@ -48,7 +49,9 @@ Program::findSymbol(const char* kernelName) const
|
||||
cl_int
|
||||
Program::addDeviceProgram(Device& device, const void* image, size_t length, int oclVer)
|
||||
{
|
||||
if (image != NULL && !device.verifyBinaryImage(image, length)) {
|
||||
if (image != NULL &&
|
||||
!aclValidateBinaryImage(image, length,
|
||||
isIL_?BINARY_TYPE_SPIRV:BINARY_TYPE_ELF|BINARY_TYPE_LLVM)) {
|
||||
return CL_INVALID_BINARY;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user