/* * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/device/device.h" #include "shared/source/helpers/constants.h" #include "opencl/source/cl_device/cl_device.h" #include "opencl/source/context/context.h" #include "opencl/source/helpers/string_helpers.h" #include "opencl/source/platform/platform.h" #include "opencl/source/program/program.h" #include "compiler_options.h" namespace NEO { template 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); DEBUG_BREAK_IF(!pContext); auto device = pContext->getDevice(0); auto program = new T(*device->getExecutionEnvironment(), pContext, false, &device->getDevice()); auto retVal = program->createProgramFromBinary(binaries[0], lengths[0], device->getRootDeviceIndex()); program->createdFrom = CreatedFrom::BINARY; if (binaryStatus) { DEBUG_BREAK_IF(retVal != CL_SUCCESS); *binaryStatus = CL_SUCCESS; } if (retVal != CL_SUCCESS) { delete program; program = nullptr; } errcodeRet = retVal; return program; } template 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); DEBUG_BREAK_IF(!pContext); auto retVal = createCombinedString( combinedString, combinedStringSize, count, strings, lengths); if (CL_SUCCESS == retVal) { program = new T(*pContext->getDevice(0)->getExecutionEnvironment(), pContext, false, &pContext->getDevice(0)->getDevice()); program->sourceCode.swap(combinedString); program->createdFrom = CreatedFrom::SOURCE; } errcodeRet = retVal; return program; } template T *Program::create( const char *nullTerminatedString, Context *context, ClDevice &device, bool isBuiltIn, cl_int *errcodeRet) { cl_int retVal = CL_SUCCESS; T *program = nullptr; if (nullTerminatedString == nullptr) { retVal = CL_INVALID_VALUE; } if (retVal == CL_SUCCESS) { program = new T(*device.getExecutionEnvironment(), context, isBuiltIn, &device.getDevice()); program->sourceCode = nullTerminatedString; program->createdFrom = CreatedFrom::SOURCE; } if (errcodeRet) { *errcodeRet = retVal; } return program; } template T *Program::create( const char *nullTerminatedString, Context *context, Device &device, bool isBuiltIn, cl_int *errcodeRet) { return Program::create(nullTerminatedString, context, *device.getSpecializedDevice(), isBuiltIn, errcodeRet); } template T *Program::createFromGenBinary( ExecutionEnvironment &executionEnvironment, Context *context, const void *binary, size_t size, bool isBuiltIn, cl_int *errcodeRet, Device *device) { cl_int retVal = CL_SUCCESS; T *program = nullptr; if ((binary == nullptr) || (size == 0)) { retVal = CL_INVALID_VALUE; } if (CL_SUCCESS == retVal) { program = new T(executionEnvironment, context, isBuiltIn, device); program->numDevices = 1; program->replaceDeviceBinary(makeCopy(binary, size), size, device->getRootDeviceIndex()); program->isCreatedFromBinary = true; program->programBinaryType = CL_PROGRAM_BINARY_TYPE_EXECUTABLE; program->buildStatus = CL_BUILD_SUCCESS; program->createdFrom = CreatedFrom::BINARY; } if (errcodeRet) { *errcodeRet = retVal; } return program; } template T *Program::createFromIL(Context *context, const void *il, size_t length, cl_int &errcodeRet) { errcodeRet = CL_SUCCESS; if ((il == nullptr) || (length == 0)) { errcodeRet = CL_INVALID_BINARY; return nullptr; } auto device = context->getDevice(0); T *program = new T(*device->getExecutionEnvironment(), context, false, &device->getDevice()); errcodeRet = program->createProgramFromBinary(il, length, device->getRootDeviceIndex()); program->createdFrom = CreatedFrom::IL; if (errcodeRet != CL_SUCCESS) { delete program; program = nullptr; } return program; } } // namespace NEO