2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2018-2020 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "platform.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/compiler_interface/compiler_interface.h"
|
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
|
|
|
#include "shared/source/device/root_device.h"
|
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
|
|
|
#include "shared/source/helpers/get_info.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
|
|
#include "shared/source/helpers/string.h"
|
|
|
|
#include "shared/source/os_interface/device_factory.h"
|
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2020-03-06 17:11:44 +08:00
|
|
|
#include "shared/source/source_level_debugger/source_level_debugger.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/api/api.h"
|
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/gtpin/gtpin_notify.h"
|
|
|
|
#include "opencl/source/helpers/built_ins_helper.h"
|
|
|
|
#include "opencl/source/helpers/get_info_status_mapper.h"
|
|
|
|
#include "opencl/source/platform/extensions.h"
|
|
|
|
#include "opencl/source/sharings/sharing_factory.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "CL/cl_ext.h"
|
2019-12-04 19:36:16 +08:00
|
|
|
#include "gmm_client_context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-21 18:48:02 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-03 23:18:21 +08:00
|
|
|
std::vector<std::unique_ptr<Platform>> platformsImpl;
|
2018-06-26 22:15:48 +08:00
|
|
|
|
2020-02-07 19:15:46 +08:00
|
|
|
Platform::Platform(ExecutionEnvironment &executionEnvironmentIn) : executionEnvironment(executionEnvironmentIn) {
|
2020-01-14 21:32:11 +08:00
|
|
|
clDevices.reserve(4);
|
2020-02-07 19:15:46 +08:00
|
|
|
executionEnvironment.incRefInternal();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Platform::~Platform() {
|
2020-01-14 21:32:11 +08:00
|
|
|
for (auto clDevice : this->clDevices) {
|
2020-03-02 17:13:46 +08:00
|
|
|
clDevice->decRefInternal();
|
2018-06-28 14:51:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtpinNotifyPlatformShutdown();
|
2020-02-07 19:15:46 +08:00
|
|
|
executionEnvironment.decRefInternal();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cl_int Platform::getInfo(cl_platform_info paramName,
|
|
|
|
size_t paramValueSize,
|
|
|
|
void *paramValue,
|
|
|
|
size_t *paramValueSizeRet) {
|
|
|
|
auto retVal = CL_INVALID_VALUE;
|
|
|
|
const std::string *param = nullptr;
|
2020-05-18 22:13:59 +08:00
|
|
|
size_t paramSize = GetInfo::invalidSourceSize;
|
|
|
|
auto getInfoStatus = GetInfoStatus::INVALID_VALUE;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
switch (paramName) {
|
2020-05-28 21:11:50 +08:00
|
|
|
case CL_PLATFORM_HOST_TIMER_RESOLUTION: {
|
|
|
|
auto pVal = static_cast<uint64_t>(this->clDevices[0]->getPlatformHostTimerResolution());
|
2017-12-21 07:45:38 +08:00
|
|
|
paramSize = sizeof(uint64_t);
|
2020-05-18 22:13:59 +08:00
|
|
|
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &pVal, paramSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
break;
|
2020-05-28 21:11:50 +08:00
|
|
|
}
|
|
|
|
case CL_PLATFORM_NUMERIC_VERSION: {
|
|
|
|
auto pVal = platformInfo->numericVersion;
|
|
|
|
paramSize = sizeof(pVal);
|
|
|
|
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &pVal, paramSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CL_PLATFORM_EXTENSIONS_WITH_VERSION: {
|
2020-06-09 20:17:19 +08:00
|
|
|
std::call_once(initializeExtensionsWithVersionOnce, [this]() {
|
|
|
|
this->clDevices[0]->getDeviceInfo(CL_DEVICE_EXTENSIONS_WITH_VERSION, 0, nullptr, nullptr);
|
|
|
|
this->platformInfo->extensionsWithVersion = this->clDevices[0]->getDeviceInfo().extensionsWithVersion;
|
|
|
|
});
|
|
|
|
|
2020-05-28 21:11:50 +08:00
|
|
|
auto pVal = platformInfo->extensionsWithVersion.data();
|
|
|
|
paramSize = platformInfo->extensionsWithVersion.size() * sizeof(cl_name_version);
|
|
|
|
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pVal, paramSize);
|
|
|
|
break;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
case CL_PLATFORM_PROFILE:
|
|
|
|
param = &platformInfo->profile;
|
|
|
|
break;
|
|
|
|
case CL_PLATFORM_VERSION:
|
|
|
|
param = &platformInfo->version;
|
|
|
|
break;
|
|
|
|
case CL_PLATFORM_NAME:
|
|
|
|
param = &platformInfo->name;
|
|
|
|
break;
|
|
|
|
case CL_PLATFORM_VENDOR:
|
|
|
|
param = &platformInfo->vendor;
|
|
|
|
break;
|
|
|
|
case CL_PLATFORM_EXTENSIONS:
|
|
|
|
param = &platformInfo->extensions;
|
|
|
|
break;
|
|
|
|
case CL_PLATFORM_ICD_SUFFIX_KHR:
|
|
|
|
param = &platformInfo->icdSuffixKhr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case for string parameters
|
|
|
|
if (param) {
|
|
|
|
paramSize = param->length() + 1;
|
2020-05-18 22:13:59 +08:00
|
|
|
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, param->c_str(), paramSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-05-18 22:13:59 +08:00
|
|
|
retVal = changeGetInfoStatusToCLResultType(getInfoStatus);
|
|
|
|
GetInfo::setParamValueReturnSize(paramValueSizeRet, paramSize, getInfoStatus);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
TakeOwnershipWrapper<Platform> platformOwnership(*this);
|
2020-02-15 00:36:30 +08:00
|
|
|
if (devices.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
if (state == StateInited) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-11 18:39:25 +08:00
|
|
|
state = StateIniting;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-15 00:36:30 +08:00
|
|
|
for (auto &inputDevice : devices) {
|
2020-01-14 21:32:11 +08:00
|
|
|
ClDevice *pClDevice = nullptr;
|
2020-02-15 00:36:30 +08:00
|
|
|
auto pDevice = inputDevice.release();
|
|
|
|
UNRECOVERABLE_IF(!pDevice);
|
|
|
|
pClDevice = new ClDevice{*pDevice, this};
|
2020-03-02 17:13:46 +08:00
|
|
|
this->clDevices.push_back(pClDevice);
|
2020-02-15 00:36:30 +08:00
|
|
|
|
2020-06-01 21:51:36 +08:00
|
|
|
auto hwInfo = pClDevice->getHardwareInfo();
|
|
|
|
if (pClDevice->getPreemptionMode() == PreemptionMode::MidThread || pClDevice->isDebuggerActive()) {
|
|
|
|
auto sipType = SipKernel::getSipKernelType(hwInfo.platform.eRenderCoreFamily, pClDevice->isDebuggerActive());
|
|
|
|
initSipKernel(sipType, *pDevice);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 21:51:36 +08:00
|
|
|
DEBUG_BREAK_IF(this->platformInfo);
|
|
|
|
this->platformInfo.reset(new PlatformInfo);
|
|
|
|
|
|
|
|
this->platformInfo->extensions = this->clDevices[0]->getDeviceInfo().deviceExtensions;
|
|
|
|
|
|
|
|
switch (this->clDevices[0]->getEnabledClVersion()) {
|
|
|
|
case 30:
|
|
|
|
this->platformInfo->version = "OpenCL 3.0 ";
|
|
|
|
this->platformInfo->numericVersion = CL_MAKE_VERSION(3, 0, 0);
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
this->platformInfo->version = "OpenCL 2.1 ";
|
|
|
|
this->platformInfo->numericVersion = CL_MAKE_VERSION(2, 1, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this->platformInfo->version = "OpenCL 1.2 ";
|
|
|
|
this->platformInfo->numericVersion = CL_MAKE_VERSION(1, 2, 0);
|
|
|
|
break;
|
2018-11-19 23:18:06 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
this->fillGlobalDispatchTable();
|
2020-03-02 17:13:46 +08:00
|
|
|
DEBUG_BREAK_IF(DebugManager.flags.CreateMultipleSubDevices.get() > 1 && !this->clDevices[0]->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled());
|
2017-12-21 07:45:38 +08:00
|
|
|
state = StateInited;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Platform::fillGlobalDispatchTable() {
|
|
|
|
sharingFactory.fillGlobalDispatchTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Platform::isInitialized() {
|
|
|
|
TakeOwnershipWrapper<Platform> platformOwnership(*this);
|
|
|
|
bool ret = (this->state == StateInited);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
ClDevice *Platform::getClDevice(size_t deviceOrdinal) {
|
|
|
|
TakeOwnershipWrapper<Platform> platformOwnership(*this);
|
|
|
|
|
|
|
|
if (this->state != StateInited || deviceOrdinal >= clDevices.size()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pClDevice = clDevices[deviceOrdinal];
|
|
|
|
DEBUG_BREAK_IF(pClDevice == nullptr);
|
|
|
|
|
|
|
|
return pClDevice;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t Platform::getNumDevices() const {
|
|
|
|
TakeOwnershipWrapper<const Platform> platformOwnership(*this);
|
|
|
|
|
|
|
|
if (this->state != StateInited) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
return clDevices.size();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
ClDevice **Platform::getClDevices() {
|
2017-12-21 07:45:38 +08:00
|
|
|
TakeOwnershipWrapper<Platform> platformOwnership(*this);
|
|
|
|
|
|
|
|
if (this->state != StateInited) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
return clDevices.data();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const PlatformInfo &Platform::getPlatformInfo() const {
|
|
|
|
DEBUG_BREAK_IF(!platformInfo);
|
|
|
|
return *platformInfo;
|
|
|
|
}
|
|
|
|
|
2020-02-11 18:39:25 +08:00
|
|
|
std::unique_ptr<Platform> (*Platform::createFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> std::unique_ptr<Platform> {
|
|
|
|
return std::make_unique<Platform>(executionEnvironment);
|
|
|
|
};
|
|
|
|
|
2020-02-18 23:02:26 +08:00
|
|
|
std::vector<DeviceVector> Platform::groupDevices(DeviceVector devices) {
|
2020-02-21 18:48:02 +08:00
|
|
|
std::map<PRODUCT_FAMILY, size_t> platformsMap;
|
2020-02-18 23:02:26 +08:00
|
|
|
std::vector<DeviceVector> outDevices;
|
|
|
|
for (auto &device : devices) {
|
|
|
|
auto productFamily = device->getHardwareInfo().platform.eProductFamily;
|
|
|
|
auto result = platformsMap.find(productFamily);
|
|
|
|
if (result == platformsMap.end()) {
|
|
|
|
platformsMap.insert({productFamily, platformsMap.size()});
|
|
|
|
outDevices.push_back(DeviceVector{});
|
|
|
|
}
|
|
|
|
auto platformId = platformsMap[productFamily];
|
|
|
|
outDevices[platformId].push_back(std::move(device));
|
|
|
|
}
|
2020-03-10 19:58:35 +08:00
|
|
|
std::sort(outDevices.begin(), outDevices.end(), [](DeviceVector &lhs, DeviceVector &rhs) -> bool {
|
|
|
|
return lhs[0]->getHardwareInfo().platform.eProductFamily > rhs[0]->getHardwareInfo().platform.eProductFamily;
|
|
|
|
});
|
2020-02-18 23:02:26 +08:00
|
|
|
return outDevices;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|