2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-01-14 14:32:11 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-12-13 16:48:57 +01:00
|
|
|
#include "core/debug_settings/debug_settings_manager.h"
|
2020-01-27 13:59:19 +01:00
|
|
|
#include "core/memory_manager/memory_constants.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/context/context.h"
|
2020-01-27 13:59:19 +01:00
|
|
|
#include "runtime/device/cl_device.h"
|
2019-10-27 19:48:26 +01:00
|
|
|
#include "runtime/helpers/string_helpers.h"
|
2020-01-14 14:32:11 +01:00
|
|
|
#include "runtime/platform/platform.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/program/program.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-12-01 16:13:21 +01:00
|
|
|
#include "compiler_options.h"
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
T *Program::create(
|
|
|
|
|
cl_context context,
|
|
|
|
|
cl_uint numDevices,
|
|
|
|
|
const cl_device_id *deviceList,
|
|
|
|
|
const size_t *lengths,
|
|
|
|
|
const unsigned char **binaries,
|
|
|
|
|
cl_int *binaryStatus,
|
|
|
|
|
cl_int &errcodeRet) {
|
|
|
|
|
auto pContext = castToObject<Context>(context);
|
|
|
|
|
DEBUG_BREAK_IF(!pContext);
|
|
|
|
|
|
2018-08-06 09:46:57 +02:00
|
|
|
auto program = new T(*pContext->getDevice(0)->getExecutionEnvironment(), pContext, false);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
auto retVal = program->createProgramFromBinary(binaries[0], lengths[0]);
|
|
|
|
|
|
2019-03-15 15:26:06 +01:00
|
|
|
program->createdFrom = CreatedFrom::BINARY;
|
|
|
|
|
|
2017-12-21 00:45:38 +01: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(
|
|
|
|
|
cl_context context,
|
|
|
|
|
cl_uint count,
|
|
|
|
|
const char **strings,
|
|
|
|
|
const size_t *lengths,
|
|
|
|
|
cl_int &errcodeRet) {
|
|
|
|
|
std::string combinedString;
|
|
|
|
|
size_t combinedStringSize = 0;
|
|
|
|
|
T *program = nullptr;
|
|
|
|
|
auto pContext = castToObject<Context>(context);
|
|
|
|
|
DEBUG_BREAK_IF(!pContext);
|
|
|
|
|
|
|
|
|
|
auto retVal = createCombinedString(
|
|
|
|
|
combinedString,
|
|
|
|
|
combinedStringSize,
|
|
|
|
|
count,
|
|
|
|
|
strings,
|
|
|
|
|
lengths);
|
|
|
|
|
|
|
|
|
|
if (CL_SUCCESS == retVal) {
|
2018-08-06 09:46:57 +02:00
|
|
|
program = new T(*pContext->getDevice(0)->getExecutionEnvironment(), pContext, false);
|
2017-12-21 00:45:38 +01:00
|
|
|
program->sourceCode.swap(combinedString);
|
2019-03-15 15:26:06 +01:00
|
|
|
program->createdFrom = CreatedFrom::SOURCE;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errcodeRet = retVal;
|
|
|
|
|
return program;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
T *Program::create(
|
|
|
|
|
const char *nullTerminatedString,
|
|
|
|
|
Context *context,
|
2020-01-14 14:32:11 +01:00
|
|
|
ClDevice &device,
|
2018-05-28 16:16:06 +02:00
|
|
|
bool isBuiltIn,
|
2017-12-21 00:45:38 +01:00
|
|
|
cl_int *errcodeRet) {
|
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
|
T *program = nullptr;
|
|
|
|
|
|
|
|
|
|
if (nullTerminatedString == nullptr) {
|
|
|
|
|
retVal = CL_INVALID_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (retVal == CL_SUCCESS) {
|
2018-08-06 09:46:57 +02:00
|
|
|
program = new T(*device.getExecutionEnvironment());
|
2019-08-29 15:10:51 +02:00
|
|
|
program->sourceCode = nullTerminatedString;
|
2017-12-21 00:45:38 +01:00
|
|
|
program->context = context;
|
2018-05-28 16:16:06 +02:00
|
|
|
program->isBuiltIn = isBuiltIn;
|
|
|
|
|
if (program->context && !program->isBuiltIn) {
|
2017-12-21 00:45:38 +01:00
|
|
|
program->context->incRefInternal();
|
|
|
|
|
}
|
|
|
|
|
program->pDevice = &device;
|
|
|
|
|
program->numDevices = 1;
|
2019-09-05 11:31:12 +02:00
|
|
|
if (is32bit || DebugManager.flags.DisableStatelessToStatefulOptimization.get() || device.areSharedSystemAllocationsAllowed()) {
|
2019-12-01 16:13:21 +01:00
|
|
|
CompilerOptions::concatenateAppend(program->internalOptions, CompilerOptions::greaterThan4gbBuffersRequired);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errcodeRet) {
|
|
|
|
|
*errcodeRet = retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return program;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
template <typename T>
|
|
|
|
|
T *Program::create(
|
|
|
|
|
const char *nullTerminatedString,
|
|
|
|
|
Context *context,
|
|
|
|
|
Device &device,
|
|
|
|
|
bool isBuiltIn,
|
|
|
|
|
cl_int *errcodeRet) {
|
|
|
|
|
return Program::create<T>(nullTerminatedString, context, *platform()->clDeviceMap[&device], isBuiltIn, errcodeRet);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-08 13:05:16 +02:00
|
|
|
template <typename T>
|
|
|
|
|
T *Program::createFromGenBinary(
|
2018-08-14 10:56:42 +02:00
|
|
|
ExecutionEnvironment &executionEnvironment,
|
2018-08-08 13:05:16 +02:00
|
|
|
Context *context,
|
|
|
|
|
const void *binary,
|
|
|
|
|
size_t size,
|
|
|
|
|
bool isBuiltIn,
|
|
|
|
|
cl_int *errcodeRet) {
|
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
|
T *program = nullptr;
|
|
|
|
|
|
|
|
|
|
if ((binary == nullptr) || (size == 0)) {
|
|
|
|
|
retVal = CL_INVALID_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CL_SUCCESS == retVal) {
|
2018-08-06 09:46:57 +02:00
|
|
|
program = new T(executionEnvironment, context, isBuiltIn);
|
2018-08-08 13:05:16 +02:00
|
|
|
program->numDevices = 1;
|
2019-08-29 15:10:51 +02:00
|
|
|
program->genBinary = makeCopy(binary, size);
|
|
|
|
|
program->genBinarySize = size;
|
2018-08-08 13:05:16 +02:00
|
|
|
program->isCreatedFromBinary = true;
|
|
|
|
|
program->programBinaryType = CL_PROGRAM_BINARY_TYPE_EXECUTABLE;
|
|
|
|
|
program->isProgramBinaryResolved = true;
|
|
|
|
|
program->buildStatus = CL_BUILD_SUCCESS;
|
2019-03-15 15:26:06 +01:00
|
|
|
program->createdFrom = CreatedFrom::BINARY;
|
2018-08-08 13:05:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errcodeRet) {
|
|
|
|
|
*errcodeRet = retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return program;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template <typename T>
|
|
|
|
|
T *Program::createFromIL(Context *ctx,
|
|
|
|
|
const void *il,
|
|
|
|
|
size_t length,
|
|
|
|
|
cl_int &errcodeRet) {
|
|
|
|
|
errcodeRet = CL_SUCCESS;
|
|
|
|
|
|
|
|
|
|
if ((il == nullptr) || (length == 0)) {
|
|
|
|
|
errcodeRet = CL_INVALID_BINARY;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 09:46:57 +02:00
|
|
|
T *program = new T(*ctx->getDevice(0)->getExecutionEnvironment(), ctx, false);
|
2017-12-21 00:45:38 +01:00
|
|
|
errcodeRet = program->createProgramFromBinary(il, length);
|
2019-03-15 15:26:06 +01:00
|
|
|
program->createdFrom = CreatedFrom::IL;
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
if (errcodeRet != CL_SUCCESS) {
|
|
|
|
|
delete program;
|
|
|
|
|
program = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return program;
|
|
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|