2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-01-08 17:29:15 +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
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-22 09:28:27 +01:00
|
|
|
#include "built_ins/built_ins.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2019-10-22 12:09:08 +02:00
|
|
|
#include "core/compiler_interface/compiler_interface.h"
|
2019-05-13 12:53:40 +02:00
|
|
|
#include "core/helpers/basic_math.h"
|
2019-09-05 09:35:56 +02:00
|
|
|
#include "core/helpers/debug_helpers.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-02-22 09:28:27 +01:00
|
|
|
#include "built_ins/aux_translation_builtin.h"
|
|
|
|
|
#include "built_ins/sip.h"
|
2019-12-01 16:13:21 +01:00
|
|
|
#include "compiler_options.h"
|
2020-02-22 09:28:27 +01:00
|
|
|
#include "device/cl_device.h"
|
|
|
|
|
#include "helpers/built_ins_helper.h"
|
|
|
|
|
#include "helpers/convert_color.h"
|
|
|
|
|
#include "helpers/dispatch_info_builder.h"
|
|
|
|
|
#include "kernel/kernel.h"
|
|
|
|
|
#include "mem_obj/image.h"
|
|
|
|
|
#include "program/program.h"
|
2019-12-01 16:13:21 +01:00
|
|
|
|
2019-02-27 11:39:32 +01:00
|
|
|
#include <cstdint>
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <sstream>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
BuiltIns::BuiltIns() {
|
|
|
|
|
builtinsLib.reset(new BuiltinsLib());
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 16:32:00 +01:00
|
|
|
BuiltIns::~BuiltIns() = default;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-03-09 11:52:14 +01:00
|
|
|
const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) {
|
2017-12-21 00:45:38 +01:00
|
|
|
uint32_t kernelId = static_cast<uint32_t>(type);
|
|
|
|
|
UNRECOVERABLE_IF(kernelId >= static_cast<uint32_t>(SipKernelType::COUNT));
|
|
|
|
|
auto &sipBuiltIn = this->sipKernels[kernelId];
|
|
|
|
|
|
|
|
|
|
auto initializer = [&] {
|
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
|
|
|
|
|
|
std::vector<char> sipBinary;
|
2018-08-01 09:06:46 +02:00
|
|
|
auto compilerInteface = device.getExecutionEnvironment()->getCompilerInterface();
|
2017-12-21 00:45:38 +01:00
|
|
|
UNRECOVERABLE_IF(compilerInteface == nullptr);
|
|
|
|
|
|
2019-08-29 15:10:51 +02:00
|
|
|
auto ret = compilerInteface->getSipKernelBinary(device, type, sipBinary);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-08-29 15:10:51 +02:00
|
|
|
UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success);
|
2017-12-21 00:45:38 +01:00
|
|
|
UNRECOVERABLE_IF(sipBinary.size() == 0);
|
2018-08-14 10:56:42 +02:00
|
|
|
auto program = createProgramForSip(*device.getExecutionEnvironment(),
|
|
|
|
|
nullptr,
|
2018-05-14 11:25:18 +02:00
|
|
|
sipBinary,
|
|
|
|
|
sipBinary.size(),
|
2020-02-20 08:12:44 +01:00
|
|
|
&retVal,
|
|
|
|
|
&device);
|
2017-12-21 00:45:38 +01:00
|
|
|
DEBUG_BREAK_IF(retVal != CL_SUCCESS);
|
|
|
|
|
UNRECOVERABLE_IF(program == nullptr);
|
|
|
|
|
|
2018-03-09 11:52:14 +01:00
|
|
|
program->setDevice(&device);
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
retVal = program->processGenBinary();
|
|
|
|
|
DEBUG_BREAK_IF(retVal != CL_SUCCESS);
|
|
|
|
|
|
2018-03-06 15:29:06 +01:00
|
|
|
sipBuiltIn.first.reset(new SipKernel(type, program));
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
std::call_once(sipBuiltIn.second, initializer);
|
|
|
|
|
UNRECOVERABLE_IF(sipBuiltIn.first == nullptr);
|
|
|
|
|
return *sipBuiltIn.first;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 12:24:17 +02:00
|
|
|
BuiltInOwnershipWrapper::BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
|
|
|
|
|
takeOwnership(inputBuilder, context);
|
|
|
|
|
}
|
|
|
|
|
BuiltInOwnershipWrapper::~BuiltInOwnershipWrapper() {
|
|
|
|
|
if (builder) {
|
|
|
|
|
for (auto &kernel : builder->peekUsedKernels()) {
|
|
|
|
|
kernel->setContext(nullptr);
|
|
|
|
|
kernel->releaseOwnership();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void BuiltInOwnershipWrapper::takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
|
|
|
|
|
UNRECOVERABLE_IF(builder);
|
|
|
|
|
builder = &inputBuilder;
|
|
|
|
|
for (auto &kernel : builder->peekUsedKernels()) {
|
2019-07-02 09:50:49 +02:00
|
|
|
kernel->takeOwnership();
|
2018-08-13 12:24:17 +02:00
|
|
|
kernel->setContext(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|