Skip to content

Commit 7033592

Browse files
authored
[UR] Fix platform search logic (#18033)
Change #17876 introduced a regression due to how platforms were generated examples and tests. This fixes those issues. A fix for the no_platforms test is also included; which was failing due to `UR_ADAPTERS_FORCE_LOAD=""` being treated as absent. Closes #18032
1 parent c238cf7 commit 7033592

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

unified-runtime/examples/codegen/codegen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ get_platforms(std::vector<ur_adapter_handle_t> &adapters) {
6969
uint32_t adapterPlatformCount = 0;
7070
urPlatformGet(adapter, 0, nullptr, &adapterPlatformCount);
7171

72-
platforms.reserve(platformCount + adapterPlatformCount);
72+
platforms.resize(platformCount + adapterPlatformCount);
7373
urPlatformGet(adapter, adapterPlatformCount, &platforms[platformCount],
7474
&adapterPlatformCount);
7575
platformCount += adapterPlatformCount;
7676
}
7777
if (!platformCount) {
7878
throw std::runtime_error("No platforms available.");
7979
}
80-
platforms.resize(platformCount);
8180

8281
return platforms;
8382
}

unified-runtime/examples/hello_world/hello_world.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int main(int, char *[]) {
5656
goto out;
5757
}
5858

59-
platforms.reserve(platformCount + adapterPlatformCount);
59+
platforms.resize(platformCount + adapterPlatformCount);
6060
status = urPlatformGet(adapter, adapterPlatformCount,
6161
&platforms[platformCount], &adapterPlatformCount);
6262
if (status != UR_RESULT_SUCCESS) {
@@ -66,7 +66,6 @@ int main(int, char *[]) {
6666
}
6767
platformCount += adapterPlatformCount;
6868
}
69-
platforms.resize(platformCount);
7069

7170
for (auto p : platforms) {
7271
ur_api_version_t api_version = {};

unified-runtime/test/loader/platforms/no_platforms.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RUN: UR_ADAPTERS_FORCE_LOAD="" UR_LOG_TEST="level:info;output:stdout;flush:debug" platforms-test
1+
RUN: UR_ADAPTERS_FORCE_LOAD="invalid.so" UR_LOG_TEST="level:info;output:stdout;flush:debug" platforms-test
22

33
REQUIRES: linux
44

unified-runtime/test/loader/platforms/platforms.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ int main(int, char *[]) {
5656
out.error("urPlatformGet failed with return code: {}", status);
5757
goto out;
5858
}
59-
out.info("urPlatformGet found {} platforms", platformCount);
59+
out.info("urPlatformGet found {} platforms", adapterPlatformCount);
6060

61-
platforms.reserve(platformCount + adapterPlatformCount);
61+
platforms.resize(platformCount + adapterPlatformCount);
6262
status = urPlatformGet(adapter, adapterPlatformCount,
6363
&platforms[platformCount], &adapterPlatformCount);
6464
if (status != UR_RESULT_SUCCESS) {
@@ -67,7 +67,6 @@ int main(int, char *[]) {
6767
}
6868
platformCount += adapterPlatformCount;
6969
}
70-
platforms.resize(platformCount);
7170

7271
for (auto p : platforms) {
7372
size_t name_len;

unified-runtime/test/unit/print.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct UrPlatformGet {
6969
struct UrPlatformGetEmptyArray : UrPlatformGet {
7070
UrPlatformGetEmptyArray() : UrPlatformGet() {}
7171
const char *get_expected() {
72-
return ".phAdapters = nullptr, .NumAdapters = 0, .NumEntries = 0, "
72+
return ".hAdapter = nullptr, .NumEntries = 0, "
7373
".phPlatforms = nullptr, .pNumPlatforms = "
7474
"nullptr";
7575
};
@@ -86,7 +86,7 @@ struct UrPlatformGetTwoPlatforms : UrPlatformGet {
8686
pNumPlatforms = &num_platforms;
8787
}
8888
const char *get_expected() {
89-
return ".phAdapters = nullptr, .NumAdapters = 0, .NumEntries = 2, "
89+
return ".hAdapter = nullptr, .NumEntries = 2, "
9090
".phPlatforms = .+ \\{.+, .+\\}, "
9191
".pNumPlatforms = .+ \\(2\\)";
9292
};

0 commit comments

Comments
 (0)