-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathplatform.cpp
265 lines (222 loc) · 8.88 KB
/
platform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "platform.h"
#include "shared/source/built_ins/sip.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/compiler_interface/oclc_extensions.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/helpers/debug_helpers.h"
#include "shared/source/helpers/get_info.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/pin/pin.h"
#include "opencl/source/api/api.h"
#include "opencl/source/cl_device/cl_device.h"
#include "opencl/source/gtpin/gtpin_notify.h"
#include "opencl/source/helpers/get_info_status_mapper.h"
#include "opencl/source/platform/platform_info.h"
#include "opencl/source/sharings/sharing_factory.h"
#include "CL/cl_ext.h"
#include <algorithm>
#include <map>
namespace NEO {
std::vector<std::unique_ptr<Platform>> *platformsImpl = nullptr;
Platform::Platform(ExecutionEnvironment &executionEnvironmentIn) : executionEnvironment(executionEnvironmentIn) {
clDevices.reserve(4);
executionEnvironment.incRefInternal();
}
Platform::~Platform() {
executionEnvironment.prepareForCleanup();
for (auto clDevice : this->clDevices) {
clDevice->getDevice().getRootDeviceEnvironmentRef().debugger.reset(nullptr);
clDevice->getDevice().stopDirectSubmissionAndWaitForCompletion();
clDevice->decRefInternal();
}
gtpinNotifyPlatformShutdown();
executionEnvironment.decRefInternal();
}
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;
size_t paramSize = GetInfo::invalidSourceSize;
auto getInfoStatus = GetInfoStatus::invalidValue;
switch (paramName) {
case CL_PLATFORM_HOST_TIMER_RESOLUTION: {
auto pVal = static_cast<uint64_t>(this->clDevices[0]->getPlatformHostTimerResolution());
paramSize = sizeof(uint64_t);
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &pVal, paramSize);
break;
}
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: {
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;
});
auto pVal = platformInfo->extensionsWithVersion.data();
paramSize = platformInfo->extensionsWithVersion.size() * sizeof(cl_name_version);
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pVal, paramSize);
break;
}
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;
case CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR: {
paramSize = sizeof(this->clDevices[0]->getDeviceInfo().externalMemorySharing);
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &this->clDevices[0]->getDeviceInfo().externalMemorySharing, paramSize);
break;
}
default:
break;
}
// Case for string parameters
if (param) {
paramSize = param->length() + 1;
getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, param->c_str(), paramSize);
}
retVal = changeGetInfoStatusToCLResultType(getInfoStatus);
GetInfo::setParamValueReturnSize(paramValueSizeRet, paramSize, getInfoStatus);
return retVal;
}
bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (devices.empty()) {
return false;
}
if (state == StateInited) {
return true;
}
state = StateIniting;
for (auto &inputDevice : devices) {
ClDevice *pClDevice = nullptr;
auto pDevice = inputDevice.release();
UNRECOVERABLE_IF(!pDevice);
pClDevice = new ClDevice{*pDevice, this};
this->clDevices.push_back(pClDevice);
}
DEBUG_BREAK_IF(this->platformInfo);
this->platformInfo.reset(new PlatformInfo);
this->platformInfo->extensions = this->clDevices[0]->getDeviceInfo().deviceExtensions;
auto preferredPlatformName = this->clDevices[0]->getHardwareInfo().capabilityTable.preferredPlatformName;
if (preferredPlatformName != nullptr) {
this->platformInfo->name = preferredPlatformName;
}
if (debugManager.flags.OverridePlatformName.get() != "unk") {
this->platformInfo->name.assign(debugManager.flags.OverridePlatformName.get().c_str());
}
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;
}
this->fillGlobalDispatchTable();
DEBUG_BREAK_IF(debugManager.flags.CreateMultipleSubDevices.get() > 1 && !this->clDevices[0]->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled());
state = StateInited;
return true;
}
void Platform::tryNotifyGtpinInit() {
auto notifyGTPin = []() {
EnvironmentVariableReader envReader;
if (envReader.getSetting("ZET_ENABLE_PROGRAM_INSTRUMENTATION", false)) {
const std::string gtpinFuncName{"OpenGTPinOCL"};
PinContext::init(gtpinFuncName);
}
};
std::call_once(this->oclInitGTPinOnce, notifyGTPin);
}
void Platform::fillGlobalDispatchTable() {
sharingFactory.fillGlobalDispatchTable();
}
bool Platform::isInitialized() {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
bool ret = (this->state == StateInited);
return ret;
}
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;
}
size_t Platform::getNumDevices() const {
TakeOwnershipWrapper<const Platform> platformOwnership(*this);
if (this->state != StateInited) {
return 0;
}
return clDevices.size();
}
ClDevice **Platform::getClDevices() {
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (this->state != StateInited) {
return nullptr;
}
return clDevices.data();
}
const PlatformInfo &Platform::getPlatformInfo() const {
DEBUG_BREAK_IF(!platformInfo);
return *platformInfo;
}
std::unique_ptr<Platform> (*Platform::createFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> std::unique_ptr<Platform> {
return std::make_unique<Platform>(executionEnvironment);
};
std::vector<DeviceVector> Platform::groupDevices(DeviceVector devices) {
std::map<PRODUCT_FAMILY, size_t> platformsMap;
std::vector<DeviceVector> outDevices;
for (auto &device : devices) {
auto productFamily = device->getHardwareInfo().platform.eProductFamily;
auto result = platformsMap.find(productFamily);
if (result == platformsMap.end()) {
platformsMap.emplace(productFamily, platformsMap.size());
outDevices.emplace_back();
}
auto platformId = platformsMap[productFamily];
outDevices[platformId].push_back(std::move(device));
}
std::sort(outDevices.begin(), outDevices.end(), [](DeviceVector &lhs, DeviceVector &rhs) -> bool {
return lhs[0]->getHardwareInfo().platform.eProductFamily > rhs[0]->getHardwareInfo().platform.eProductFamily; // NOLINT(clang-analyzer-cplusplus.Move)
});
return outDevices;
}
} // namespace NEO