2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-12 00:46:43 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-06-15 19:49:38 +08:00
|
|
|
#include "shared/source/ail/ail_configuration.h"
|
2023-02-06 17:05:43 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2021-05-06 00:00:12 +08:00
|
|
|
#include "shared/source/helpers/string_helpers.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-03-20 18:15:25 +08:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
#include "opencl/source/platform/platform.h"
|
|
|
|
#include "opencl/source/program/program.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T *Program::create(
|
2020-10-21 16:25:03 +08:00
|
|
|
Context *pContext,
|
|
|
|
const ClDeviceVector &deviceVector,
|
2017-12-21 07:45:38 +08:00
|
|
|
const size_t *lengths,
|
|
|
|
const unsigned char **binaries,
|
|
|
|
cl_int *binaryStatus,
|
|
|
|
cl_int &errcodeRet) {
|
2020-10-16 21:00:28 +08:00
|
|
|
auto program = new T(pContext, false, deviceVector);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-10-21 16:25:03 +08:00
|
|
|
cl_int retVal = CL_INVALID_PROGRAM;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-10-21 16:25:03 +08:00
|
|
|
for (auto i = 0u; i < deviceVector.size(); i++) {
|
|
|
|
auto device = deviceVector[i];
|
2022-05-10 01:40:30 +08:00
|
|
|
retVal = program->createProgramFromBinary(binaries[i], lengths[i], *device); // NOLINT(clang-analyzer-core.CallAndMessage)
|
2020-10-21 16:25:03 +08:00
|
|
|
if (retVal != CL_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 22:26:06 +08:00
|
|
|
program->createdFrom = CreatedFrom::BINARY;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
if (binaryStatus) {
|
|
|
|
DEBUG_BREAK_IF(retVal != CL_SUCCESS);
|
|
|
|
*binaryStatus = CL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retVal != CL_SUCCESS) {
|
|
|
|
delete program;
|
|
|
|
program = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcodeRet = retVal;
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T *Program::create(
|
2020-10-23 15:38:45 +08:00
|
|
|
Context *pContext,
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_uint count,
|
|
|
|
const char **strings,
|
|
|
|
const size_t *lengths,
|
|
|
|
cl_int &errcodeRet) {
|
|
|
|
std::string combinedString;
|
|
|
|
size_t combinedStringSize = 0;
|
|
|
|
T *program = nullptr;
|
|
|
|
|
2021-05-06 00:00:12 +08:00
|
|
|
auto retVal = StringHelpers::createCombinedString(
|
2017-12-21 07:45:38 +08:00
|
|
|
combinedString,
|
|
|
|
combinedStringSize,
|
|
|
|
count,
|
|
|
|
strings,
|
|
|
|
lengths);
|
|
|
|
|
|
|
|
if (CL_SUCCESS == retVal) {
|
2022-06-15 19:49:38 +08:00
|
|
|
|
|
|
|
auto &hwInfo = pContext->getDevice(0)->getHardwareInfo();
|
|
|
|
auto ail = AILConfiguration::get(hwInfo.platform.eProductFamily);
|
|
|
|
if (ail) {
|
|
|
|
ail->modifyKernelIfRequired(combinedString);
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:15:39 +08:00
|
|
|
program = new T(pContext, false, pContext->getDevices());
|
2023-01-12 00:46:43 +08:00
|
|
|
if (ail) {
|
2023-03-03 21:23:24 +08:00
|
|
|
if (ail->isFallbackToPatchtokensRequired(combinedString)) {
|
|
|
|
pContext->setContextAsNonZebin();
|
|
|
|
}
|
2023-01-12 00:46:43 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
program->sourceCode.swap(combinedString);
|
2019-03-15 22:26:06 +08:00
|
|
|
program->createdFrom = CreatedFrom::SOURCE;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
errcodeRet = retVal;
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-10-23 15:38:45 +08:00
|
|
|
T *Program::createBuiltInFromSource(
|
2017-12-21 07:45:38 +08:00
|
|
|
const char *nullTerminatedString,
|
|
|
|
Context *context,
|
2020-10-22 18:14:54 +08:00
|
|
|
const ClDeviceVector &deviceVector,
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_int *errcodeRet) {
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
T *program = nullptr;
|
|
|
|
|
|
|
|
if (nullTerminatedString == nullptr) {
|
|
|
|
retVal = CL_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retVal == CL_SUCCESS) {
|
2020-10-23 15:38:45 +08:00
|
|
|
program = new T(context, true, deviceVector);
|
2019-08-29 21:10:51 +08:00
|
|
|
program->sourceCode = nullTerminatedString;
|
2020-02-17 05:49:47 +08:00
|
|
|
program->createdFrom = CreatedFrom::SOURCE;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (errcodeRet) {
|
|
|
|
*errcodeRet = retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
2018-08-08 19:05:16 +08:00
|
|
|
template <typename T>
|
2020-10-23 15:38:45 +08:00
|
|
|
T *Program::createBuiltInFromGenBinary(
|
2018-08-08 19:05:16 +08:00
|
|
|
Context *context,
|
2020-10-23 15:38:45 +08:00
|
|
|
const ClDeviceVector &deviceVector,
|
2018-08-08 19:05:16 +08:00
|
|
|
const void *binary,
|
|
|
|
size_t size,
|
2020-10-23 15:38:45 +08:00
|
|
|
cl_int *errcodeRet) {
|
2018-08-08 19:05:16 +08:00
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
T *program = nullptr;
|
|
|
|
|
|
|
|
if ((binary == nullptr) || (size == 0)) {
|
|
|
|
retVal = CL_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CL_SUCCESS == retVal) {
|
2020-10-16 21:00:28 +08:00
|
|
|
|
2020-10-23 15:38:45 +08:00
|
|
|
program = new T(context, true, deviceVector);
|
|
|
|
for (const auto &device : deviceVector) {
|
|
|
|
if (program->buildInfos[device->getRootDeviceIndex()].packedDeviceBinarySize == 0) {
|
2021-10-21 20:37:31 +08:00
|
|
|
program->replaceDeviceBinary(std::move(makeCopy(binary, size)), size, device->getRootDeviceIndex());
|
2020-10-23 15:38:45 +08:00
|
|
|
}
|
|
|
|
}
|
2020-11-04 18:08:45 +08:00
|
|
|
program->setBuildStatusSuccess(deviceVector, CL_PROGRAM_BINARY_TYPE_EXECUTABLE);
|
2018-08-08 19:05:16 +08:00
|
|
|
program->isCreatedFromBinary = true;
|
2019-03-15 22:26:06 +08:00
|
|
|
program->createdFrom = CreatedFrom::BINARY;
|
2018-08-08 19:05:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (errcodeRet) {
|
|
|
|
*errcodeRet = retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
template <typename T>
|
2020-10-08 17:36:31 +08:00
|
|
|
T *Program::createFromIL(Context *context,
|
2017-12-21 07:45:38 +08:00
|
|
|
const void *il,
|
|
|
|
size_t length,
|
|
|
|
cl_int &errcodeRet) {
|
|
|
|
errcodeRet = CL_SUCCESS;
|
|
|
|
|
|
|
|
if ((il == nullptr) || (length == 0)) {
|
|
|
|
errcodeRet = CL_INVALID_BINARY;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:06:35 +08:00
|
|
|
auto deviceVector = context->getDevices();
|
2020-10-16 21:00:28 +08:00
|
|
|
T *program = new T(context, false, deviceVector);
|
2020-10-22 15:06:35 +08:00
|
|
|
for (const auto &device : deviceVector) {
|
2020-11-04 18:08:45 +08:00
|
|
|
errcodeRet = program->createProgramFromBinary(il, length, *device);
|
2020-10-22 15:06:35 +08:00
|
|
|
if (errcodeRet != CL_SUCCESS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 22:26:06 +08:00
|
|
|
program->createdFrom = CreatedFrom::IL;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
if (errcodeRet != CL_SUCCESS) {
|
|
|
|
delete program;
|
|
|
|
program = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|