2020-01-27 20:59:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/device/cl_device.h"
|
2020-01-27 20:59:19 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/device/sub_device.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2020-03-16 19:41:25 +08:00
|
|
|
#include "shared/source/os_interface/driver_info.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
|
|
|
#include "shared/source/program/sync_buffer_handler.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/platform/extensions.h"
|
|
|
|
#include "opencl/source/platform/platform.h"
|
2020-01-27 20:59:19 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
2020-01-27 17:36:39 +08:00
|
|
|
ClDevice::ClDevice(Device &device, Platform *platform) : device(device), platformId(platform) {
|
2020-01-27 20:59:19 +08:00
|
|
|
device.incRefInternal();
|
2020-02-06 20:33:30 +08:00
|
|
|
device.setSpecializedDevice(this);
|
2020-03-06 01:13:32 +08:00
|
|
|
deviceExtensions.reserve(1000);
|
|
|
|
name.reserve(100);
|
|
|
|
auto osInterface = getRootDeviceEnvironment().osInterface.get();
|
|
|
|
driverInfo.reset(DriverInfo::create(osInterface));
|
2020-01-27 20:59:19 +08:00
|
|
|
initializeCaps();
|
2020-03-06 01:13:32 +08:00
|
|
|
compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(deviceInfo.deviceExtensions);
|
2020-01-27 20:59:19 +08:00
|
|
|
|
|
|
|
auto numAvailableDevices = device.getNumAvailableDevices();
|
|
|
|
if (numAvailableDevices > 1) {
|
|
|
|
for (uint32_t i = 0; i < numAvailableDevices; i++) {
|
2020-02-06 20:33:30 +08:00
|
|
|
auto &coreSubDevice = static_cast<SubDevice &>(*device.getDeviceById(i));
|
2020-03-06 01:13:32 +08:00
|
|
|
auto pClSubDevice = std::make_unique<ClDevice>(coreSubDevice, platform);
|
|
|
|
pClSubDevice->incRefInternal();
|
|
|
|
pClSubDevice->decRefApi();
|
|
|
|
|
|
|
|
auto &deviceInfo = pClSubDevice->deviceInfo;
|
|
|
|
deviceInfo.parentDevice = this;
|
2020-02-06 20:33:30 +08:00
|
|
|
deviceInfo.partitionMaxSubDevices = 0;
|
|
|
|
deviceInfo.partitionProperties[0] = 0;
|
|
|
|
deviceInfo.partitionAffinityDomain = 0;
|
|
|
|
deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
|
|
|
|
deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA;
|
|
|
|
deviceInfo.partitionType[2] = 0;
|
|
|
|
|
2020-02-28 20:29:32 +08:00
|
|
|
subDevices.push_back(std::move(pClSubDevice));
|
2020-01-27 20:59:19 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-12 16:33:20 +08:00
|
|
|
if (getSharedDeviceInfo().debuggerActive) {
|
2020-02-10 22:57:49 +08:00
|
|
|
auto osInterface = device.getRootDeviceEnvironment().osInterface.get();
|
|
|
|
getSourceLevelDebugger()->notifyNewDevice(osInterface ? osInterface->getDeviceHandle() : 0);
|
|
|
|
}
|
2020-01-27 20:59:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClDevice::~ClDevice() {
|
2020-02-10 22:57:49 +08:00
|
|
|
|
2020-03-12 16:33:20 +08:00
|
|
|
if (getSharedDeviceInfo().debuggerActive) {
|
2020-02-10 22:57:49 +08:00
|
|
|
getSourceLevelDebugger()->notifyDeviceDestruction();
|
|
|
|
}
|
|
|
|
|
2020-01-27 20:59:19 +08:00
|
|
|
syncBufferHandler.reset();
|
|
|
|
for (auto &subDevice : subDevices) {
|
|
|
|
subDevice.reset();
|
|
|
|
}
|
|
|
|
device.decRefInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClDevice::allocateSyncBufferHandler() {
|
|
|
|
TakeOwnershipWrapper<ClDevice> lock(*this);
|
|
|
|
if (syncBufferHandler.get() == nullptr) {
|
|
|
|
syncBufferHandler = std::make_unique<SyncBufferHandler>(this->getDevice());
|
|
|
|
UNRECOVERABLE_IF(syncBufferHandler.get() == nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 19:40:02 +08:00
|
|
|
unsigned int ClDevice::getSupportedClVersion() const {
|
|
|
|
return device.getHardwareInfo().capabilityTable.clVersionSupport;
|
|
|
|
}
|
2020-01-27 20:59:19 +08:00
|
|
|
|
|
|
|
void ClDevice::retainApi() {
|
2020-03-06 01:13:32 +08:00
|
|
|
auto parentDeviceId = deviceInfo.parentDevice;
|
2020-02-28 20:29:32 +08:00
|
|
|
if (parentDeviceId) {
|
|
|
|
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);
|
|
|
|
pParentClDevice->incRefInternal();
|
2020-01-27 20:59:19 +08:00
|
|
|
this->incRefApi();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
unique_ptr_if_unused<ClDevice> ClDevice::releaseApi() {
|
2020-03-06 01:13:32 +08:00
|
|
|
auto parentDeviceId = deviceInfo.parentDevice;
|
2020-02-28 20:29:32 +08:00
|
|
|
if (!parentDeviceId) {
|
2020-01-27 20:59:19 +08:00
|
|
|
return unique_ptr_if_unused<ClDevice>(this, false);
|
|
|
|
}
|
2020-02-28 20:29:32 +08:00
|
|
|
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);
|
|
|
|
pParentClDevice->decRefInternal();
|
2020-01-27 20:59:19 +08:00
|
|
|
return this->decRefApi();
|
|
|
|
}
|
|
|
|
|
2020-03-12 16:33:20 +08:00
|
|
|
const DeviceInfo &ClDevice::getSharedDeviceInfo() const {
|
|
|
|
return device.getDeviceInfo();
|
|
|
|
}
|
|
|
|
|
2020-01-27 20:59:19 +08:00
|
|
|
ClDevice *ClDevice::getDeviceById(uint32_t deviceId) {
|
|
|
|
UNRECOVERABLE_IF(deviceId >= getNumAvailableDevices());
|
|
|
|
if (subDevices.empty()) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
return subDevices[deviceId].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClDevice::getDeviceAndHostTimer(uint64_t *deviceTimestamp, uint64_t *hostTimestamp) const { return device.getDeviceAndHostTimer(deviceTimestamp, hostTimestamp); }
|
|
|
|
bool ClDevice::getHostTimer(uint64_t *hostTimestamp) const { return device.getHostTimer(hostTimestamp); }
|
|
|
|
const HardwareInfo &ClDevice::getHardwareInfo() const { return device.getHardwareInfo(); }
|
|
|
|
EngineControl &ClDevice::getEngine(aub_stream::EngineType engineType, bool lowPriority) { return device.getEngine(engineType, lowPriority); }
|
|
|
|
EngineControl &ClDevice::getDefaultEngine() { return device.getDefaultEngine(); }
|
2020-01-21 16:35:12 +08:00
|
|
|
EngineControl &ClDevice::getInternalEngine() { return device.getInternalEngine(); }
|
2020-02-25 01:25:42 +08:00
|
|
|
std::atomic<uint32_t> &ClDevice::getSelectorCopyEngine() { return device.getSelectorCopyEngine(); }
|
2020-01-27 20:59:19 +08:00
|
|
|
MemoryManager *ClDevice::getMemoryManager() const { return device.getMemoryManager(); }
|
|
|
|
GmmHelper *ClDevice::getGmmHelper() const { return device.getGmmHelper(); }
|
2020-02-25 01:04:30 +08:00
|
|
|
GmmClientContext *ClDevice::getGmmClientContext() const { return device.getGmmClientContext(); }
|
2020-01-27 20:59:19 +08:00
|
|
|
double ClDevice::getProfilingTimerResolution() { return device.getProfilingTimerResolution(); }
|
|
|
|
double ClDevice::getPlatformHostTimerResolution() const { return device.getPlatformHostTimerResolution(); }
|
|
|
|
bool ClDevice::isSimulation() const { return device.isSimulation(); }
|
|
|
|
GFXCORE_FAMILY ClDevice::getRenderCoreFamily() const { return device.getRenderCoreFamily(); }
|
|
|
|
PerformanceCounters *ClDevice::getPerformanceCounters() { return device.getPerformanceCounters(); }
|
|
|
|
PreemptionMode ClDevice::getPreemptionMode() const { return device.getPreemptionMode(); }
|
2020-02-10 22:57:49 +08:00
|
|
|
bool ClDevice::isDebuggerActive() const { return device.isDebuggerActive(); }
|
2020-03-06 01:13:32 +08:00
|
|
|
Debugger *ClDevice::getDebugger() { return device.getDebugger(); }
|
2020-02-10 22:57:49 +08:00
|
|
|
SourceLevelDebugger *ClDevice::getSourceLevelDebugger() { return reinterpret_cast<SourceLevelDebugger *>(device.getDebugger()); }
|
2020-01-27 20:59:19 +08:00
|
|
|
ExecutionEnvironment *ClDevice::getExecutionEnvironment() const { return device.getExecutionEnvironment(); }
|
|
|
|
const RootDeviceEnvironment &ClDevice::getRootDeviceEnvironment() const { return device.getRootDeviceEnvironment(); }
|
|
|
|
const HardwareCapabilities &ClDevice::getHardwareCapabilities() const { return device.getHardwareCapabilities(); }
|
|
|
|
bool ClDevice::isFullRangeSvm() const { return device.isFullRangeSvm(); }
|
|
|
|
bool ClDevice::areSharedSystemAllocationsAllowed() const { return device.areSharedSystemAllocationsAllowed(); }
|
|
|
|
uint32_t ClDevice::getRootDeviceIndex() const { return device.getRootDeviceIndex(); }
|
|
|
|
uint32_t ClDevice::getNumAvailableDevices() const { return device.getNumAvailableDevices(); }
|
|
|
|
|
|
|
|
ClDeviceVector::ClDeviceVector(const cl_device_id *devices,
|
|
|
|
cl_uint numDevices) {
|
|
|
|
for (cl_uint i = 0; i < numDevices; i++) {
|
|
|
|
auto pClDevice = castToObject<ClDevice>(devices[i]);
|
|
|
|
this->push_back(pClDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClDeviceVector::toDeviceIDs(std::vector<cl_device_id> &devIDs) {
|
|
|
|
int i = 0;
|
|
|
|
devIDs.resize(this->size());
|
|
|
|
|
|
|
|
for (auto &it : *this) {
|
|
|
|
devIDs[i] = it;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 17:58:03 +08:00
|
|
|
const std::string &ClDevice::peekCompilerExtensions() const {
|
|
|
|
return compilerExtensions;
|
|
|
|
}
|
2020-03-06 01:13:32 +08:00
|
|
|
|
2020-01-27 20:59:19 +08:00
|
|
|
} // namespace NEO
|