mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 15:12:56 +08:00
Use all passed devices when compiling program
Related-To: NEO-5001 Change-Id: I852c6e57fb7c450ee4dae2d5ff59a206397b2390 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
d539a7f8e4
commit
20f4786423
@@ -1437,10 +1437,6 @@ cl_program CL_API_CALL clCreateProgramWithBuiltInKernels(cl_context context,
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext), numDevices,
|
||||
deviceList, kernelNames, errcodeRet);
|
||||
|
||||
if (numDevices == 0) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
ClDeviceVector deviceVector;
|
||||
for (auto i = 0u; i < numDevices; i++) {
|
||||
@@ -1542,8 +1538,34 @@ cl_int CL_API_CALL clCompileProgram(cl_program program,
|
||||
|
||||
retVal = validateObjects(WithCastToInternal(program, &pProgram), Program::isValidCallback(funcNotify, userData));
|
||||
|
||||
ClDeviceVector deviceVector;
|
||||
const ClDeviceVector *deviceVectorPtr = &deviceVector;
|
||||
|
||||
if (CL_SUCCESS == retVal) {
|
||||
retVal = pProgram->compile(numDevices, deviceList, options,
|
||||
if (deviceList == nullptr) {
|
||||
if (numDevices == 0) {
|
||||
deviceVectorPtr = &pProgram->getDevices();
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (numDevices == 0) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
} else {
|
||||
for (auto i = 0u; i < numDevices; i++) {
|
||||
auto device = castToObject<ClDevice>(deviceList[i]);
|
||||
if (!device || !pProgram->isDeviceAssociated(*device)) {
|
||||
retVal = CL_INVALID_DEVICE;
|
||||
break;
|
||||
}
|
||||
deviceVector.push_back(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CL_SUCCESS == retVal) {
|
||||
retVal = pProgram->compile(*deviceVectorPtr, options,
|
||||
numInputHeaders, inputHeaders, headerIncludeNames);
|
||||
pProgram->invokeCallback(funcNotify, userData);
|
||||
}
|
||||
@@ -1639,13 +1661,19 @@ cl_int CL_API_CALL clGetProgramBuildInfo(cl_program program,
|
||||
"paramName", NEO::FileLoggerInstance().infoPointerToString(paramValue, paramValueSize),
|
||||
"paramValueSize", paramValueSize, "paramValue", paramValue,
|
||||
"paramValueSizeRet", paramValueSizeRet);
|
||||
retVal = validateObjects(program);
|
||||
Program *pProgram = nullptr;
|
||||
ClDevice *pClDevice = nullptr;
|
||||
|
||||
retVal = validateObjects(WithCastToInternal(program, &pProgram), WithCastToInternal(device, &pClDevice));
|
||||
|
||||
if (CL_SUCCESS == retVal) {
|
||||
Program *pProgram = (Program *)(program);
|
||||
|
||||
if (!pProgram->isDeviceAssociated(*pClDevice)) {
|
||||
retVal = CL_INVALID_DEVICE;
|
||||
}
|
||||
}
|
||||
if (CL_SUCCESS == retVal) {
|
||||
retVal = pProgram->getBuildInfo(
|
||||
device,
|
||||
pClDevice,
|
||||
paramName,
|
||||
paramValueSize,
|
||||
paramValue,
|
||||
|
||||
@@ -26,23 +26,18 @@
|
||||
namespace NEO {
|
||||
|
||||
cl_int Program::compile(
|
||||
cl_uint numDevices,
|
||||
const cl_device_id *deviceList,
|
||||
const ClDeviceVector &deviceVector,
|
||||
const char *buildOptions,
|
||||
cl_uint numInputHeaders,
|
||||
const cl_program *inputHeaders,
|
||||
const char **headerIncludeNames) {
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
auto clDevice = this->pDevice->getSpecializedDevice<ClDevice>();
|
||||
UNRECOVERABLE_IF(clDevice == nullptr);
|
||||
auto defaultClDevice = deviceVector[0];
|
||||
UNRECOVERABLE_IF(defaultClDevice == nullptr);
|
||||
auto &defaultDevice = defaultClDevice->getDevice();
|
||||
internalOptions.clear();
|
||||
do {
|
||||
if (((deviceList == nullptr) && (numDevices != 0)) ||
|
||||
((deviceList != nullptr) && (numDevices == 0))) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (numInputHeaders == 0) {
|
||||
if ((headerIncludeNames != nullptr) || (inputHeaders != nullptr)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
@@ -55,14 +50,7 @@ cl_int Program::compile(
|
||||
}
|
||||
}
|
||||
|
||||
// if a device_list is specified, make sure it points to our device
|
||||
// NOTE: a null device_list is ok - it means "all devices"
|
||||
if ((deviceList != nullptr) && validateObject(*deviceList) != CL_SUCCESS) {
|
||||
retVal = CL_INVALID_DEVICE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (buildStatuses[clDevice] == CL_BUILD_IN_PROGRESS) {
|
||||
if (std::any_of(deviceVector.begin(), deviceVector.end(), [&](auto device) { return CL_BUILD_IN_PROGRESS == buildStatuses[device]; })) {
|
||||
retVal = CL_INVALID_OPERATION;
|
||||
break;
|
||||
}
|
||||
@@ -71,8 +59,9 @@ cl_int Program::compile(
|
||||
retVal = CL_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
buildStatuses[clDevice] = CL_BUILD_IN_PROGRESS;
|
||||
for (const auto &device : deviceVector) {
|
||||
buildStatuses[device] = CL_BUILD_IN_PROGRESS;
|
||||
}
|
||||
|
||||
options = (buildOptions != nullptr) ? buildOptions : "";
|
||||
|
||||
@@ -115,7 +104,7 @@ cl_int Program::compile(
|
||||
|
||||
std::vector<uint8_t> compileData = elfEncoder.encode();
|
||||
|
||||
CompilerInterface *pCompilerInterface = pDevice->getCompilerInterface();
|
||||
CompilerInterface *pCompilerInterface = defaultDevice.getCompilerInterface();
|
||||
if (!pCompilerInterface) {
|
||||
retVal = CL_OUT_OF_HOST_MEMORY;
|
||||
break;
|
||||
@@ -124,14 +113,11 @@ cl_int Program::compile(
|
||||
TranslationInput inputArgs = {IGC::CodeType::elf, IGC::CodeType::undefined};
|
||||
|
||||
// set parameters for compilation
|
||||
auto clDevice = this->pDevice->getSpecializedDevice<ClDevice>();
|
||||
UNRECOVERABLE_IF(clDevice == nullptr);
|
||||
|
||||
if (requiresOpenClCFeatures(options)) {
|
||||
CompilerOptions::concatenateAppend(internalOptions, clDevice->peekCompilerExtensionsWithFeatures());
|
||||
CompilerOptions::concatenateAppend(internalOptions, clDevice->peekCompilerFeatures());
|
||||
CompilerOptions::concatenateAppend(internalOptions, defaultClDevice->peekCompilerExtensionsWithFeatures());
|
||||
CompilerOptions::concatenateAppend(internalOptions, defaultClDevice->peekCompilerFeatures());
|
||||
} else {
|
||||
CompilerOptions::concatenateAppend(internalOptions, clDevice->peekCompilerExtensions());
|
||||
CompilerOptions::concatenateAppend(internalOptions, defaultClDevice->peekCompilerExtensions());
|
||||
}
|
||||
|
||||
if (isKernelDebugEnabled()) {
|
||||
@@ -148,9 +134,11 @@ cl_int Program::compile(
|
||||
inputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
|
||||
|
||||
TranslationOutput compilerOuput;
|
||||
auto compilerErr = pCompilerInterface->compile(*this->pDevice, inputArgs, compilerOuput);
|
||||
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
|
||||
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
|
||||
auto compilerErr = pCompilerInterface->compile(defaultDevice, inputArgs, compilerOuput);
|
||||
for (const auto &device : deviceVector) {
|
||||
this->updateBuildLog(device->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
|
||||
this->updateBuildLog(device->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
|
||||
}
|
||||
retVal = asClError(compilerErr);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
break;
|
||||
@@ -166,15 +154,18 @@ cl_int Program::compile(
|
||||
} while (false);
|
||||
|
||||
if (retVal != CL_SUCCESS) {
|
||||
buildStatuses[clDevice] = CL_BUILD_ERROR;
|
||||
for (const auto &device : deviceVector) {
|
||||
buildStatuses[device] = CL_BUILD_ERROR;
|
||||
}
|
||||
programBinaryType = CL_PROGRAM_BINARY_TYPE_NONE;
|
||||
} else {
|
||||
buildStatuses[clDevice] = CL_BUILD_SUCCESS;
|
||||
for (const auto &device : deviceVector) {
|
||||
buildStatuses[device] = CL_BUILD_SUCCESS;
|
||||
}
|
||||
programBinaryType = CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
|
||||
}
|
||||
|
||||
internalOptions.clear();
|
||||
|
||||
return retVal;
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
@@ -180,11 +180,6 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam
|
||||
const void *pSrc = nullptr;
|
||||
size_t srcSize = GetInfo::invalidSourceSize;
|
||||
size_t retSize = 0;
|
||||
cl_device_id device_id = pDevice->getSpecializedDevice<ClDevice>();
|
||||
|
||||
if (device != device_id) {
|
||||
return CL_INVALID_DEVICE;
|
||||
}
|
||||
|
||||
auto pClDev = castToObject<ClDevice>(device);
|
||||
auto rootDeviceIndex = pClDev->getRootDeviceIndex();
|
||||
|
||||
@@ -499,4 +499,7 @@ void Program::invokeCallback(void(CL_CALLBACK *funcNotify)(cl_program program, v
|
||||
}
|
||||
}
|
||||
|
||||
bool Program::isDeviceAssociated(const ClDevice &clDevice) const {
|
||||
return std::any_of(clDevices.begin(), clDevices.end(), [&](auto programDevice) { return programDevice == &clDevice; });
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
@@ -135,7 +135,7 @@ class Program : public BaseObject<_cl_program> {
|
||||
MOCKABLE_VIRTUAL cl_int processGenBinary(uint32_t rootDeviceIndex);
|
||||
MOCKABLE_VIRTUAL cl_int processProgramInfo(ProgramInfo &dst);
|
||||
|
||||
cl_int compile(cl_uint numDevices, const cl_device_id *deviceList, const char *buildOptions,
|
||||
cl_int compile(const ClDeviceVector &deviceVector, const char *buildOptions,
|
||||
cl_uint numInputHeaders, const cl_program *inputHeaders, const char **headerIncludeNames);
|
||||
|
||||
cl_int link(cl_uint numDevices, const cl_device_id *deviceList, const char *buildOptions,
|
||||
@@ -263,6 +263,9 @@ class Program : public BaseObject<_cl_program> {
|
||||
static bool isValidCallback(void(CL_CALLBACK *funcNotify)(cl_program program, void *userData), void *userData);
|
||||
void invokeCallback(void(CL_CALLBACK *funcNotify)(cl_program program, void *userData), void *userData);
|
||||
|
||||
const ClDeviceVector &getDevices() const { return clDevices; }
|
||||
bool isDeviceAssociated(const ClDevice &clDevice) const;
|
||||
|
||||
protected:
|
||||
MOCKABLE_VIRTUAL cl_int createProgramFromBinary(const void *pBinary, size_t binarySize, uint32_t rootDeviceIndex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user