@@ -69,75 +69,14 @@ AdapterEnvironment::AdapterEnvironment() {
69
69
70
70
PlatformEnvironment *PlatformEnvironment::instance = nullptr ;
71
71
72
- constexpr std::pair<const char *, ur_platform_backend_t > backends[] = {
73
- {" LEVEL_ZERO" , UR_PLATFORM_BACKEND_LEVEL_ZERO},
74
- {" L0" , UR_PLATFORM_BACKEND_LEVEL_ZERO},
75
- {" OPENCL" , UR_PLATFORM_BACKEND_OPENCL},
76
- {" CUDA" , UR_PLATFORM_BACKEND_CUDA},
77
- {" HIP" , UR_PLATFORM_BACKEND_HIP},
78
- {" NATIVE_CPU" , UR_PLATFORM_BACKEND_NATIVE_CPU},
79
- {" UNKNOWN" , UR_PLATFORM_BACKEND_UNKNOWN},
80
- };
81
-
82
- namespace {
83
- /* unused due to platform filtering being commented out
84
- constexpr const char *backend_to_str(ur_platform_backend_t backend) {
85
- for (auto b : backends) {
86
- if (b.second == backend) {
87
- return b.first;
88
- }
89
- }
90
- return "INVALID";
91
- };*/
92
-
93
- ur_platform_backend_t str_to_backend (std::string str) {
94
-
95
- std::transform (str.begin (), str.end (), str.begin (), ::toupper);
96
- for (auto b : backends) {
97
- if (b.first == str) {
98
- return b.second ;
99
- }
100
- }
101
- return UR_PLATFORM_BACKEND_UNKNOWN;
102
- };
103
- } // namespace
104
-
105
- std::ostream &operator <<(std::ostream &out,
106
- const std::vector<ur_platform_handle_t > &platforms) {
107
- for (auto platform : platforms) {
108
- out << " \n * \" " << platform << " \" " ;
109
- }
110
- return out;
111
- }
112
-
113
- std::ostream &operator <<(std::ostream &out,
114
- const std::vector<ur_device_handle_t > &devices) {
115
- for (auto device : devices) {
116
- out << " \n * \" " << device << " \" " ;
117
- }
118
- return out;
119
- }
120
-
121
- uur::PlatformEnvironment::PlatformEnvironment (int argc, char **argv)
122
- : AdapterEnvironment(), platform_options{parsePlatformOptions (argc, argv)} {
72
+ uur::PlatformEnvironment::PlatformEnvironment ()
73
+ : AdapterEnvironment() {
123
74
instance = this ;
124
75
125
- // Check for errors from parsing platform options
126
- if (!error.empty ()) {
127
- return ;
128
- }
129
-
130
- selectPlatformFromOptions ();
76
+ populatePlatforms ();
131
77
}
132
78
133
- void uur::PlatformEnvironment::selectPlatformFromOptions () {
134
- struct platform_info {
135
- ur_adapter_handle_t adapter;
136
- ur_platform_handle_t platform;
137
- std::string name;
138
- ur_platform_backend_t backend;
139
- };
140
- std::vector<platform_info> discovered_platforms;
79
+ void uur::PlatformEnvironment::populatePlatforms () {
141
80
for (auto a : adapters) {
142
81
uint32_t count = 0 ;
143
82
ASSERT_SUCCESS (urPlatformGet (&a, 1 , 0 , nullptr , &count));
@@ -147,96 +86,8 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() {
147
86
148
87
for (auto p : platform_list) {
149
88
platforms.push_back (p);
150
- ur_platform_backend_t backend;
151
- ASSERT_SUCCESS (urPlatformGetInfo (p, UR_PLATFORM_INFO_BACKEND,
152
- sizeof (ur_platform_backend_t ),
153
- &backend, nullptr ));
154
-
155
- size_t size;
156
- ASSERT_SUCCESS (
157
- urPlatformGetInfo (p, UR_PLATFORM_INFO_NAME, 0 , nullptr , &size));
158
- std::vector<char > platform_name{};
159
- platform_name.reserve (size);
160
- ASSERT_SUCCESS (urPlatformGetInfo (p, UR_PLATFORM_INFO_NAME, size,
161
- platform_name.data (), nullptr ));
162
-
163
- discovered_platforms.push_back (platform_info{
164
- a, p, std::string (platform_name.data ()), backend});
165
- }
166
- }
167
-
168
- std::string default_name{};
169
- std::map<ur_platform_backend_t , std::string> backend_platform_names{};
170
- auto stream = std::stringstream{platform_options.platform_name };
171
- for (std::string filter; std::getline (stream, filter, ' ;' );) {
172
- auto split = filter.find (' :' );
173
- if (split == std::string::npos) {
174
- default_name = filter;
175
- } else if (split == filter.length () - 1 ) {
176
- // E.g: `OPENCL:`, ignore it
177
- } else {
178
- backend_platform_names.insert (
179
- {str_to_backend (filter.substr (0 , split)),
180
- filter.substr (split + 1 )});
181
89
}
182
90
}
183
-
184
- std::vector<platform_info> platforms_filtered{};
185
- std::copy_if (discovered_platforms.begin (), discovered_platforms.end (),
186
- std::inserter (platforms_filtered, platforms_filtered.begin ()),
187
- [&](platform_info info) {
188
- if (!default_name.empty () && default_name != info.name ) {
189
- return false ;
190
- }
191
- if (backend_platform_names.count (info.backend ) &&
192
- backend_platform_names[info.backend ] != info.name ) {
193
- return false ;
194
- }
195
- if (platform_options.platform_backend &&
196
- platform_options.platform_backend != info.backend ) {
197
- return false ;
198
- }
199
- return true ;
200
- });
201
- /*
202
- if (platforms_filtered.size() == 0) {
203
- std::stringstream errstr;
204
- errstr << "No platforms were found with the following filters:";
205
- if (platform_options.platform_backend) {
206
- errstr << " --backend="
207
- << backend_to_str(*platform_options.platform_backend);
208
- }
209
- if (!platform_options.platform_name.empty()) {
210
- errstr << " --platform=\"" << platform_options.platform_name
211
- << "\"";
212
- }
213
- if (!platform_options.platform_backend &&
214
- platform_options.platform_name.empty()) {
215
- errstr << " (none)";
216
- }
217
- errstr << "\nAvailable platforms:\n";
218
- for (auto p : platforms) {
219
- errstr << " --backend=" << backend_to_str(p.backend)
220
- << " --platform=\"" << p.name << "\"\n";
221
- }
222
- FAIL() << errstr.str();
223
- } else if (platforms_filtered.size() == 1 ||
224
- platform_options.platforms_count == 1) {
225
- auto &selected = platforms_filtered[0];
226
- platform = selected.platform;
227
- adapter = selected.adapter;
228
- std::cerr << "Selected platform: [" << backend_to_str(selected.backend)
229
- << "] " << selected.name << "\n";
230
- } else if (platforms_filtered.size() > 1) {
231
- std::stringstream errstr;
232
- errstr << "Multiple possible platforms found; please select one of the "
233
- "following or set --platforms_count=1:\n";
234
- for (const auto &p : platforms_filtered) {
235
- errstr << " --backend=" << backend_to_str(p.backend)
236
- << " --platform=\"" << p.name << "\"\n";
237
- }
238
- FAIL() << errstr.str();
239
- }*/
240
91
}
241
92
242
93
void uur::PlatformEnvironment::SetUp () {
@@ -261,96 +112,9 @@ void uur::PlatformEnvironment::TearDown() {
261
112
}
262
113
}
263
114
264
- PlatformEnvironment::PlatformOptions
265
- PlatformEnvironment::parsePlatformOptions (int argc, char **argv) {
266
- PlatformOptions options{};
267
- auto parse_backend = [&](std::string backend_string) {
268
- options.platform_backend = str_to_backend (backend_string);
269
- if (options.platform_backend == UR_PLATFORM_BACKEND_UNKNOWN) {
270
- std::stringstream errstr{error};
271
- errstr << " --backend not valid; expected one of [" ;
272
- bool first = true ;
273
- for (auto b : backends) {
274
- if (!first) {
275
- errstr << " , " ;
276
- }
277
- errstr << b.first ;
278
- first = false ;
279
- }
280
- errstr << " ], but got `" << backend_string << " `" ;
281
- error = errstr.str ();
282
- return false ;
283
- }
284
- return true ;
285
- };
286
-
287
- for (int argi = 1 ; argi < argc; ++argi) {
288
- const char *arg = argv[argi];
289
- if (!(std::strcmp (arg, " -h" ) && std::strcmp (arg, " --help" ))) {
290
- // TODO - print help
291
- break ;
292
- } else if (std::strncmp (
293
- arg, " --platform=" , sizeof (" --platform=" ) - 1 ) == 0 ) {
294
- options.platform_name =
295
- std::string (&arg[std::strlen (" --platform=" )]);
296
- } else if (std::strncmp (arg, " --backend=" , sizeof (" --backend=" ) - 1 ) ==
297
- 0 ) {
298
- std::string backend_string{&arg[std::strlen (" --backend=" )]};
299
- if (!parse_backend (std::move (backend_string))) {
300
- return options;
301
- }
302
- } else if (std::strncmp (arg, " --platforms_count=" ,
303
- sizeof (" --platforms_count=" ) - 1 ) == 0 ) {
304
- options.platforms_count = std::strtoul (
305
- &arg[std::strlen (" --platforms_count=" )], nullptr , 10 );
306
- }
307
- }
308
-
309
- /* If a platform was not provided using the --platform/--backend command line options,
310
- * check if environment variable is set to use as a fallback. */
311
- if (options.platform_name .empty ()) {
312
- auto env_platform = ur_getenv (" UR_CTS_ADAPTER_PLATFORM" );
313
- if (env_platform.has_value ()) {
314
- options.platform_name = env_platform.value ();
315
- }
316
- }
317
- if (!options.platform_backend ) {
318
- auto env_backend = ur_getenv (" UR_CTS_BACKEND" );
319
- if (env_backend.has_value ()) {
320
- if (!parse_backend (env_backend.value ())) {
321
- return options;
322
- }
323
- }
324
- }
325
-
326
- return options;
327
- }
328
-
329
- DevicesEnvironment::DeviceOptions
330
- DevicesEnvironment::parseDeviceOptions (int argc, char **argv) {
331
- DeviceOptions options{};
332
- for (int argi = 1 ; argi < argc; ++argi) {
333
- const char *arg = argv[argi];
334
- if (!(std::strcmp (arg, " -h" ) && std::strcmp (arg, " --help" ))) {
335
- // TODO - print help
336
- break ;
337
- } else if (std::strncmp (arg, " --device=" , sizeof (" --device=" ) - 1 ) ==
338
- 0 ) {
339
- options.device_name = std::string (&arg[std::strlen (" --device=" )]);
340
- } else if (std::strncmp (arg, " --devices_count=" ,
341
- sizeof (" --devices_count=" ) - 1 ) == 0 ) {
342
- options.devices_count = std::strtoul (
343
- &arg[std::strlen (" --devices_count=" )], nullptr , 10 );
344
- }
345
- }
346
- return options;
347
- }
348
-
349
115
DevicesEnvironment *DevicesEnvironment::instance = nullptr ;
350
116
351
- DevicesEnvironment::DevicesEnvironment (int argc, char **argv)
352
- : PlatformEnvironment(argc, argv),
353
- device_options (parseDeviceOptions(argc, argv)) {
117
+ DevicesEnvironment::DevicesEnvironment () : PlatformEnvironment() {
354
118
instance = this ;
355
119
if (!error.empty ()) {
356
120
return ;
@@ -376,65 +140,6 @@ DevicesEnvironment::DevicesEnvironment(int argc, char **argv)
376
140
error = " Could not find any devices to test" ;
377
141
return ;
378
142
}
379
- // Get the argument (devices_count) to limit test devices count.
380
- // In case, the devices_count is "0", the variable count will not be changed.
381
- // The CTS will run on all devices.
382
- /* filter devices with options after accumulating them all
383
- if (device_options.device_name.empty()) {
384
- if (device_options.devices_count >
385
- (std::numeric_limits<uint32_t>::max)()) {
386
- error = "Invalid devices_count argument";
387
- return;
388
- } else if (device_options.devices_count > 0) {
389
- count = (std::min)(
390
- count, static_cast<uint32_t>(device_options.devices_count));
391
- }
392
- devices.resize(count);
393
- if (urDeviceGet(platform, UR_DEVICE_TYPE_ALL, count, devices.data(),
394
- nullptr)) {
395
- error = "urDeviceGet() failed to get devices.";
396
- return;
397
- }
398
- } else {
399
- devices.resize(count);
400
- if (urDeviceGet(platform, UR_DEVICE_TYPE_ALL, count, devices.data(),
401
- nullptr)) {
402
- error = "urDeviceGet() failed to get devices.";
403
- return;
404
- }
405
- for (unsigned i = 0; i < count; i++) {
406
- size_t size;
407
- if (urDeviceGetInfo(devices[i], UR_DEVICE_INFO_NAME, 0, nullptr,
408
- &size)) {
409
- error = "urDeviceGetInfo() failed";
410
- return;
411
- }
412
- std::vector<char> device_name(size);
413
- if (urDeviceGetInfo(devices[i], UR_DEVICE_INFO_NAME, size,
414
- device_name.data(), nullptr)) {
415
- error = "urDeviceGetInfo() failed";
416
- return;
417
- }
418
- if (device_options.device_name == device_name.data()) {
419
- device = devices[i];
420
- devices.clear();
421
- devices.resize(1);
422
- devices[0] = device;
423
- break;
424
- }
425
- }
426
- if (!device) {
427
- std::stringstream ss_error;
428
- ss_error << "Device \"" << device_options.device_name
429
- << "\" not found. Select a single device from below "
430
- "using the "
431
- "--device=NAME command-line options:"
432
- << devices << std::endl
433
- << "or set --devices_count=COUNT.";
434
- error = ss_error.str();
435
- return;
436
- }
437
- }*/
438
143
}
439
144
440
145
void DevicesEnvironment::SetUp () {
@@ -461,7 +166,7 @@ KernelsEnvironment *KernelsEnvironment::instance = nullptr;
461
166
462
167
KernelsEnvironment::KernelsEnvironment (int argc, char **argv,
463
168
const std::string &kernels_default_dir)
464
- : DevicesEnvironment(argc, argv ),
169
+ : DevicesEnvironment(),
465
170
kernel_options (parseKernelOptions(argc, argv, kernels_default_dir)) {
466
171
instance = this ;
467
172
if (!error.empty ()) {
@@ -577,16 +282,6 @@ void KernelsEnvironment::LoadSource(
577
282
cached_kernels[kernel_name] = binary_ptr;
578
283
binary_out = binary_ptr;
579
284
}
580
- /*
581
- void LoadSource(const std::string &kernel_name,
582
- ur_device_handle_t device,
583
- std::shared_ptr<std::vector<char>> &binary_out) {
584
- ur_platform_handle_t platform = nullptr;
585
- if(urDeviceGetInfo(device, UR_DEVICE_INFO_PLATFORM, sizeof(ur_platform_handle_t), &platform, nullptr)) {
586
- FAIL() << "Failed to retrieve platform from device";
587
- }
588
- LoadSource(kernel_name, platform, binary_out);
589
- }*/
590
285
591
286
ur_result_t KernelsEnvironment::CreateProgram (
592
287
ur_platform_handle_t hPlatform, ur_context_handle_t hContext,
0 commit comments