Skip to content

Commit 8665a43

Browse files
committed
Rework kernel environment, hopefully fixing some of the flakiness.
1 parent ecd5c9e commit 8665a43

File tree

11 files changed

+59
-53
lines changed

11 files changed

+59
-53
lines changed

test/conformance/enqueue/urEnqueueKernelLaunchAndMemcpyInOrder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ struct urMultiQueueLaunchMemcpyTest
5454
std::shared_ptr<std::vector<char>> il_binary;
5555
std::vector<ur_program_metadata_t> metadatas{};
5656

57-
uur::KernelsEnvironment::instance->LoadSource(ProgramName, il_binary);
57+
uur::KernelsEnvironment::instance->LoadSource(ProgramName, platform,
58+
il_binary);
5859

5960
for (size_t i = 0; i < devices.size(); i++) {
6061
const ur_program_properties_t properties = {

test/conformance/exp_command_buffer/fixtures.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ struct TestKernel {
256256
ASSERT_SUCCESS(urPlatformGetInfo(Platform, UR_PLATFORM_INFO_BACKEND,
257257
sizeof(Backend), &Backend, nullptr));
258258

259-
ASSERT_NO_FATAL_FAILURE(
260-
uur::KernelsEnvironment::instance->LoadSource(Name, ILBinary));
259+
ASSERT_NO_FATAL_FAILURE(uur::KernelsEnvironment::instance->LoadSource(
260+
Name, Platform, ILBinary));
261261

262262
const ur_program_properties_t Properties = {
263263
UR_STRUCTURE_TYPE_PROGRAM_PROPERTIES, nullptr,

test/conformance/kernel/urKernelCreate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TEST_P(urMultiDeviceKernelCreateTest, WithProgramBuild) {
6666
uur::KernelsEnvironment::instance->GetEntryPointNames("foo")[0];
6767

6868
std::shared_ptr<std::vector<char>> il_binary;
69-
uur::KernelsEnvironment::instance->LoadSource("foo", il_binary);
69+
uur::KernelsEnvironment::instance->LoadSource("foo", platform, il_binary);
7070

7171
for (size_t i = 0; i < devices.size(); i++) {
7272
uur::raii::Program program;
@@ -100,7 +100,7 @@ TEST_P(urMultiDeviceKernelCreateTest, WithProgramCompileAndLink) {
100100
uur::KernelsEnvironment::instance->GetEntryPointNames("foo")[0];
101101

102102
std::shared_ptr<std::vector<char>> il_binary;
103-
uur::KernelsEnvironment::instance->LoadSource("foo", il_binary);
103+
uur::KernelsEnvironment::instance->LoadSource("foo", platform, il_binary);
104104

105105
for (size_t i = 0; i < devices.size(); i++) {
106106
uur::raii::Program program;

test/conformance/memory-migrate/urMemBufferMigrateAcrossDevices.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct urMultiDeviceContextMemBufferTest : urMultiDeviceContextTest {
6363

6464
UUR_RETURN_ON_FATAL_FAILURE(
6565
uur::KernelsEnvironment::instance->LoadSource(program_name,
66-
il_binary));
66+
platform, il_binary));
6767

6868
programs = std::vector<ur_program_handle_t>(num_devices);
6969
kernels = std::vector<ur_kernel_handle_t>(num_devices);

test/conformance/program/urProgramBuild.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ TEST_P(urProgramBuildTest, BuildFailure) {
3434

3535
ur_program_handle_t program = nullptr;
3636
std::shared_ptr<std::vector<char>> il_binary;
37-
uur::KernelsEnvironment::instance->LoadSource("build_failure", il_binary);
37+
uur::KernelsEnvironment::instance->LoadSource("build_failure", platform,
38+
il_binary);
3839
if (!il_binary) {
3940
// The build failure we are testing for happens at SYCL compile time on
4041
// AMD and Nvidia, so no binary exists to check for a build failure

test/conformance/program/urProgramCreateWithIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ struct urProgramCreateWithILTest : uur::urContextTest {
2121
if (backend == UR_PLATFORM_BACKEND_HIP) {
2222
GTEST_SKIP();
2323
}
24-
uur::KernelsEnvironment::instance->LoadSource("foo", il_binary);
24+
uur::KernelsEnvironment::instance->LoadSource("foo", platform,
25+
il_binary);
2526
}
2627

2728
void TearDown() override {

test/conformance/program/urProgramLink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct urProgramLinkErrorTest : uur::urQueueTest {
5757
std::shared_ptr<std::vector<char>> il_binary{};
5858
UUR_RETURN_ON_FATAL_FAILURE(
5959
uur::KernelsEnvironment::instance->LoadSource(
60-
linker_error_program_name, il_binary));
60+
linker_error_program_name, platform, il_binary));
6161
ASSERT_SUCCESS(uur::KernelsEnvironment::instance->CreateProgram(
6262
platform, context, device, *il_binary, nullptr, &program));
6363
ASSERT_SUCCESS(urProgramCompile(context, program, nullptr));

test/conformance/source/environment.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() {
137137
std::string name;
138138
ur_platform_backend_t backend;
139139
};
140-
std::vector<platform_info> platforms;
140+
std::vector<platform_info> discovered_platforms;
141141
for (auto a : adapters) {
142142
uint32_t count = 0;
143143
ASSERT_SUCCESS(urPlatformGet(&a, 1, 0, nullptr, &count));
@@ -146,7 +146,7 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() {
146146
urPlatformGet(&a, 1, count, platform_list.data(), nullptr));
147147

148148
for (auto p : platform_list) {
149-
all_platforms.push_back(p);
149+
platforms.push_back(p);
150150
ur_platform_backend_t backend;
151151
ASSERT_SUCCESS(urPlatformGetInfo(p, UR_PLATFORM_INFO_BACKEND,
152152
sizeof(ur_platform_backend_t),
@@ -160,7 +160,7 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() {
160160
ASSERT_SUCCESS(urPlatformGetInfo(p, UR_PLATFORM_INFO_NAME, size,
161161
platform_name.data(), nullptr));
162162

163-
platforms.push_back(platform_info{
163+
discovered_platforms.push_back(platform_info{
164164
a, p, std::string(platform_name.data()), backend});
165165
}
166166
}
@@ -182,7 +182,7 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() {
182182
}
183183

184184
std::vector<platform_info> platforms_filtered{};
185-
std::copy_if(platforms.begin(), platforms.end(),
185+
std::copy_if(discovered_platforms.begin(), discovered_platforms.end(),
186186
std::inserter(platforms_filtered, platforms_filtered.begin()),
187187
[&](platform_info info) {
188188
if (!default_name.empty() && default_name != info.name) {
@@ -198,8 +198,6 @@ void uur::PlatformEnvironment::selectPlatformFromOptions() {
198198
}
199199
return true;
200200
});
201-
platform = platforms_filtered[0].platform;
202-
adapter = platforms_filtered[0].adapter;
203201
/*
204202
if (platforms_filtered.size() == 0) {
205203
std::stringstream errstr;
@@ -357,17 +355,8 @@ DevicesEnvironment::DevicesEnvironment(int argc, char **argv)
357355
if (!error.empty()) {
358356
return;
359357
}
360-
uint32_t count = 0;
361-
if (urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &count)) {
362-
error = "urDevicesGet() failed to get number of devices.";
363-
return;
364-
}
365-
if (count == 0) {
366-
error = "Could not find any devices associated with the platform";
367-
return;
368-
}
369358

370-
for (auto &platform : all_platforms) {
359+
for (auto &platform : platforms) {
371360
uint32_t platform_device_count = 0;
372361
urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr,
373362
&platform_device_count);
@@ -383,6 +372,10 @@ DevicesEnvironment::DevicesEnvironment(int argc, char **argv)
383372
}
384373
}
385374

375+
if (devices.empty()) {
376+
error = "Could not find any devices to test";
377+
return;
378+
}
386379
// Get the argument (devices_count) to limit test devices count.
387380
// In case, the devices_count is "0", the variable count will not be changed.
388381
// The CTS will run on all devices.
@@ -495,7 +488,7 @@ KernelsEnvironment::parseKernelOptions(int argc, char **argv,
495488
return options;
496489
}
497490

498-
std::string KernelsEnvironment::getTargetName() {
491+
std::string KernelsEnvironment::getTargetName(ur_platform_handle_t platform) {
499492
std::stringstream IL;
500493

501494
if (instance->GetDevices().size() == 0) {
@@ -530,11 +523,12 @@ std::string KernelsEnvironment::getTargetName() {
530523
}
531524

532525
std::string
533-
KernelsEnvironment::getKernelSourcePath(const std::string &kernel_name) {
526+
KernelsEnvironment::getKernelSourcePath(const std::string &kernel_name,
527+
ur_platform_handle_t platform) {
534528
std::stringstream path;
535529
path << kernel_options.kernel_directory << "/" << kernel_name;
536530

537-
std::string target_name = getTargetName();
531+
std::string target_name = getTargetName(platform);
538532
if (target_name.empty()) {
539533
return {};
540534
}
@@ -545,9 +539,10 @@ KernelsEnvironment::getKernelSourcePath(const std::string &kernel_name) {
545539
}
546540

547541
void KernelsEnvironment::LoadSource(
548-
const std::string &kernel_name,
542+
const std::string &kernel_name, ur_platform_handle_t platform,
549543
std::shared_ptr<std::vector<char>> &binary_out) {
550-
std::string source_path = instance->getKernelSourcePath(kernel_name);
544+
std::string source_path =
545+
instance->getKernelSourcePath(kernel_name, platform);
551546

552547
if (source_path.empty()) {
553548
FAIL() << error;
@@ -582,6 +577,16 @@ void KernelsEnvironment::LoadSource(
582577
cached_kernels[kernel_name] = binary_ptr;
583578
binary_out = binary_ptr;
584579
}
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+
}*/
585590

586591
ur_result_t KernelsEnvironment::CreateProgram(
587592
ur_platform_handle_t hPlatform, ur_context_handle_t hContext,

test/conformance/testing/include/uur/environment.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ struct PlatformEnvironment : AdapterEnvironment {
4343

4444
PlatformOptions platform_options;
4545
// List of all discovered platforms
46-
std::vector<ur_platform_handle_t> all_platforms;
47-
// Adapter and platform selected for testing via platform_options
48-
ur_adapter_handle_t adapter = nullptr;
49-
ur_platform_handle_t platform = nullptr;
46+
std::vector<ur_platform_handle_t> platforms;
5047
static PlatformEnvironment *instance;
5148
};
5249

@@ -94,8 +91,13 @@ struct KernelsEnvironment : DevicesEnvironment {
9491
virtual void TearDown() override;
9592

9693
void LoadSource(const std::string &kernel_name,
94+
ur_platform_handle_t platform,
9795
std::shared_ptr<std::vector<char>> &binary_out);
98-
96+
/*
97+
void LoadSource(const std::string &kernel_name,
98+
ur_device_handle_t device,
99+
std::shared_ptr<std::vector<char>> &binary_out);
100+
*/
99101
ur_result_t CreateProgram(ur_platform_handle_t hPlatform,
100102
ur_context_handle_t hContext,
101103
ur_device_handle_t hDevice,
@@ -110,8 +112,9 @@ struct KernelsEnvironment : DevicesEnvironment {
110112
private:
111113
KernelOptions parseKernelOptions(int argc, char **argv,
112114
const std::string &kernels_default_dir);
113-
std::string getKernelSourcePath(const std::string &kernel_name);
114-
std::string getTargetName();
115+
std::string getKernelSourcePath(const std::string &kernel_name,
116+
ur_platform_handle_t platform);
117+
std::string getTargetName(ur_platform_handle_t platform);
115118

116119
KernelOptions kernel_options;
117120
// mapping between kernels (full_path + kernel_name) and their saved source.

test/conformance/testing/include/uur/fixtures.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ struct urDeviceTest : ::testing::Test,
128128
#define UUR_INSTANTIATE_PLATFORM_TEST_SUITE_P(FIXTURE) \
129129
INSTANTIATE_TEST_SUITE_P( \
130130
, FIXTURE, \
131-
::testing::ValuesIn( \
132-
uur::PlatformEnvironment::instance->all_platforms), \
131+
::testing::ValuesIn(uur::PlatformEnvironment::instance->platforms), \
133132
[](const ::testing::TestParamInfo<ur_platform_handle_t> &info) { \
134133
return uur::GetPlatformNameWithID(info.param); \
135134
})
@@ -310,10 +309,9 @@ struct urMemImageTest : urContextTest {
310309
#define UUR_PLATFORM_TEST_SUITE_P(FIXTURE, VALUES, PRINTER) \
311310
INSTANTIATE_TEST_SUITE_P( \
312311
, FIXTURE, \
313-
testing::Combine( \
314-
::testing::ValuesIn( \
315-
uur::PlatformEnvironment::instance->all_platforms), \
316-
VALUES), \
312+
testing::Combine(::testing::ValuesIn( \
313+
uur::PlatformEnvironment::instance->platforms), \
314+
VALUES), \
317315
PRINTER)
318316

319317
#define UUR_DEVICE_TEST_SUITE_P(FIXTURE, VALUES, PRINTER) \
@@ -478,7 +476,8 @@ struct urHostPipeTest : urQueueTest {
478476
}
479477

480478
UUR_RETURN_ON_FATAL_FAILURE(
481-
uur::KernelsEnvironment::instance->LoadSource("foo", il_binary));
479+
uur::KernelsEnvironment::instance->LoadSource("foo", platform,
480+
il_binary));
482481
ASSERT_SUCCESS(uur::KernelsEnvironment::instance->CreateProgram(
483482
platform, context, device, *il_binary, nullptr, &program));
484483
}
@@ -1320,7 +1319,7 @@ struct urProgramTest : urQueueTest {
13201319
}
13211320
UUR_RETURN_ON_FATAL_FAILURE(
13221321
uur::KernelsEnvironment::instance->LoadSource(program_name,
1323-
il_binary));
1322+
platform, il_binary));
13241323

13251324
const ur_program_properties_t properties = {
13261325
UR_STRUCTURE_TYPE_PROGRAM_PROPERTIES, nullptr,
@@ -1361,8 +1360,8 @@ template <class T> struct urProgramTestWithParam : urQueueTestWithParam<T> {
13611360
}
13621361

13631362
UUR_RETURN_ON_FATAL_FAILURE(
1364-
uur::KernelsEnvironment::instance->LoadSource(program_name,
1365-
il_binary));
1363+
uur::KernelsEnvironment::instance->LoadSource(
1364+
program_name, this->platform, il_binary));
13661365
ASSERT_SUCCESS(uur::KernelsEnvironment::instance->CreateProgram(
13671366
this->platform, this->context, this->device, *il_binary, nullptr,
13681367
&program));
@@ -1740,7 +1739,7 @@ struct urMultiDeviceProgramTest : urMultiDeviceQueueTest {
17401739
}
17411740
UUR_RETURN_ON_FATAL_FAILURE(
17421741
uur::KernelsEnvironment::instance->LoadSource(program_name,
1743-
il_binary));
1742+
platform, il_binary));
17441743

17451744
const ur_program_properties_t properties = {
17461745
UR_STRUCTURE_TYPE_PROGRAM_PROPERTIES, nullptr,

test/conformance/testing/include/uur/utils.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ inline std::string GTestSanitizeString(const std::string &str) {
2828
return str_cpy;
2929
}
3030

31-
inline ur_platform_handle_t GetPlatform() {
32-
return PlatformEnvironment::instance->platform;
33-
}
34-
3531
template <class T, class ObjectTy, class InfoTy, class Callable>
3632
ur_result_t GetInfo(ObjectTy object, InfoTy info, Callable cb, T &out_value) {
3733
// first get the size of the info
@@ -193,7 +189,7 @@ inline std::string GetPlatformName(ur_platform_handle_t hPlatform) {
193189

194190
inline std::string GetPlatformNameWithID(ur_platform_handle_t hPlatform) {
195191
auto platform_name = GetPlatformName(hPlatform);
196-
auto &platforms = uur::PlatformEnvironment::instance->all_platforms;
192+
auto &platforms = uur::PlatformEnvironment::instance->platforms;
197193
size_t platform_id =
198194
std::find(platforms.begin(), platforms.end(), hPlatform) -
199195
platforms.begin();

0 commit comments

Comments
 (0)