P4 to Git Change 1221147 by ashi1@ashi1_win50 on 2015/12/15 15:58:09
SWDEV-83467 - [SPIRV] Add support of SPIRV to CPU Modifying runtime and compile time to allow SPIRV binaries to run on CPU since it only runs on HSAIL GPU Added changes to allow conversion of CPU's llvmBinaryIsSpir boolean into compiler library's oclElfSections enum Cpuprogram.cpp's llvmBinaryIsSpir flag renamed to elfSectionType will now support LLVMIR, SPIR, and SPIRV Added SPIRV to compiler lib's elf as new oclElfSections enum cpuprogram.cpp changes also made to gpuprogram.cpp's NullProgram to allow compilation Affected files ... ... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/elf/elf.cpp#33 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/elf/elf.hpp#22 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.cpp#69 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#191 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#266 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#152 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#217 edit
This commit is contained in:
@@ -223,8 +223,8 @@ NullProgram::linkImpl(amd::option::Options* options)
|
||||
clBinary()->elfOut()->addSection(amd::OclElf::SOURCE, section, sz);
|
||||
}
|
||||
if (clBinary()->saveLLVMIR()) {
|
||||
if (clBinary()->loadLlvmBinary(llvmBinary_, llvmBinaryIsSpir_) && (!llvmBinary_.empty())) {
|
||||
clBinary()->elfOut()->addSection(llvmBinaryIsSpir_?amd::OclElf::SPIR:amd::OclElf::LLVMIR,
|
||||
if (clBinary()->loadLlvmBinary(llvmBinary_, elfSectionType_) && (!llvmBinary_.empty())) {
|
||||
clBinary()->elfOut()->addSection(elfSectionType_,
|
||||
llvmBinary_.data(), llvmBinary_.size(), false);
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ NullProgram::linkImpl(amd::option::Options* options)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (clBinary()->loadLlvmBinary(llvmBinary_, llvmBinaryIsSpir_) &&
|
||||
else if (clBinary()->loadLlvmBinary(llvmBinary_, elfSectionType_) &&
|
||||
clBinary()->isRecompilable(llvmBinary_, amd::OclElf::CAL_PLATFORM)) {
|
||||
char *section;
|
||||
size_t sz;
|
||||
@@ -260,7 +260,7 @@ NullProgram::linkImpl(amd::option::Options* options)
|
||||
clBinary()->elfOut()->addSection(amd::OclElf::SOURCE, section, sz);
|
||||
}
|
||||
if (clBinary()->saveLLVMIR()) {
|
||||
clBinary()->elfOut()->addSection(llvmBinaryIsSpir_?amd::OclElf::SPIR:amd::OclElf::LLVMIR,
|
||||
clBinary()->elfOut()->addSection(elfSectionType_,
|
||||
llvmBinary_.data(), llvmBinary_.size(), false);
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,7 @@ NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
bool createLibrary)
|
||||
{
|
||||
std::vector<std::string*> llvmBinaries(inputPrograms.size());
|
||||
std::vector<bool> llvmBinaryIsSpir(inputPrograms.size());
|
||||
std::vector<amd::OclElf::oclElfSections> elfSectionType(inputPrograms.size());
|
||||
std::vector<device::Program*>::const_iterator it
|
||||
= inputPrograms.begin();
|
||||
std::vector<device::Program*>::const_iterator itEnd
|
||||
@@ -533,7 +533,7 @@ NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
return false;
|
||||
}
|
||||
if (!program->clBinary()->loadLlvmBinary(program->llvmBinary_,
|
||||
program->llvmBinaryIsSpir_)) {
|
||||
program->elfSectionType_)) {
|
||||
buildLog_
|
||||
+= "Internal error: Failed loading compiled binary!\n";
|
||||
LogError("Bad OCL Binary");
|
||||
@@ -560,7 +560,7 @@ NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
}
|
||||
|
||||
llvmBinaries[i] = &program->llvmBinary_;
|
||||
llvmBinaryIsSpir[i] = program->llvmBinaryIsSpir_;
|
||||
elfSectionType[i] = program->elfSectionType_;
|
||||
}
|
||||
|
||||
acl_error err;
|
||||
@@ -580,9 +580,16 @@ NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
break;
|
||||
}
|
||||
|
||||
_bif_sections_enum_0_8 aclTypeUsed;
|
||||
if (elfSectionType[i] == amd::OclElf::SPIRV) {
|
||||
aclTypeUsed = aclSPIRV;
|
||||
} else if (elfSectionType[i] == amd::OclElf::SPIR) {
|
||||
aclTypeUsed = aclSPIR;
|
||||
} else {
|
||||
aclTypeUsed = aclLLVMIR;
|
||||
}
|
||||
err = aclInsertSection(dev().compiler(), libs[i],
|
||||
llvmBinaries[i]->data(), llvmBinaries[i]->size(),
|
||||
llvmBinaryIsSpir[i]?aclSPIR:aclLLVMIR);
|
||||
llvmBinaries[i]->data(), llvmBinaries[i]->size(), aclTypeUsed);
|
||||
if (err != ACL_SUCCESS) {
|
||||
LogWarning("aclInsertSection failed");
|
||||
break;
|
||||
@@ -597,7 +604,6 @@ NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
|
||||
if (libs.size() > 0 && err == ACL_SUCCESS) do {
|
||||
unsigned int numLibs = libs.size() - 1;
|
||||
bool resultIsSPIR = (llvmBinaryIsSpir[0] && numLibs == 0);
|
||||
|
||||
if (numLibs > 0) {
|
||||
err = aclLink(dev().compiler(), libs[0], numLibs, &libs[1],
|
||||
@@ -612,15 +618,23 @@ NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
_bif_sections_enum_0_8 aclTypeUsed;
|
||||
if (elfSectionType[0] == amd::OclElf::SPIRV && numLibs == 0) {
|
||||
aclTypeUsed = aclSPIRV;
|
||||
} else if (elfSectionType[0] == amd::OclElf::SPIR && numLibs == 0) {
|
||||
aclTypeUsed = aclSPIR;
|
||||
} else {
|
||||
aclTypeUsed = aclLLVMIR;
|
||||
}
|
||||
const void* llvmir = aclExtractSection(dev().compiler(), libs[0],
|
||||
&size, resultIsSPIR?aclSPIR:aclLLVMIR, &err);
|
||||
&size, aclTypeUsed, &err);
|
||||
if (err != ACL_SUCCESS) {
|
||||
LogWarning("aclExtractSection failed");
|
||||
break;
|
||||
}
|
||||
|
||||
llvmBinary_.assign(reinterpret_cast<const char*>(llvmir), size);
|
||||
llvmBinaryIsSpir_ = false;
|
||||
elfSectionType_ = amd::OclElf::LLVMIR;
|
||||
} while(0);
|
||||
|
||||
std::for_each(libs.begin(), libs.end(), std::ptr_fun(aclBinaryFini));
|
||||
|
||||
Reference in New Issue
Block a user