Skip to content

Commit fb63047

Browse files
committed
Modify all instances of urPlatformGet to use 1 adapter.
1 parent 4ac7c26 commit fb63047

File tree

16 files changed

+106
-92
lines changed

16 files changed

+106
-92
lines changed

unified-runtime/examples/codegen/codegen.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,21 @@ get_supported_adapters(std::vector<ur_adapter_handle_t> &adapters) {
6464
std::vector<ur_platform_handle_t>
6565
get_platforms(std::vector<ur_adapter_handle_t> &adapters) {
6666
uint32_t platformCount = 0;
67-
ur_check(urPlatformGet(adapters.data(), adapters.size(), 1, nullptr,
68-
&platformCount));
67+
std::vector<ur_platform_handle_t> platforms;
68+
for (auto adapter : adapters) {
69+
uint32_t adapterPlatformCount = 0;
70+
urPlatformGet(adapter, 0, nullptr, &adapterPlatformCount);
6971

72+
platforms.reserve(platformCount + adapterPlatformCount);
73+
urPlatformGet(adapter, adapterPlatformCount, &platforms[platformCount],
74+
&adapterPlatformCount);
75+
platformCount += adapterPlatformCount;
76+
}
7077
if (!platformCount) {
7178
throw std::runtime_error("No platforms available.");
7279
}
80+
platforms.resize(platformCount);
7381

74-
std::vector<ur_platform_handle_t> platforms(platformCount);
75-
ur_check(urPlatformGet(adapters.data(), adapters.size(), platformCount,
76-
platforms.data(), nullptr));
7782
return platforms;
7883
}
7984

unified-runtime/examples/hello_world/hello_world.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,26 @@ int main(int, char *[]) {
4747
return 1;
4848
}
4949

50-
status =
51-
urPlatformGet(adapters.data(), adapterCount, 1, nullptr, &platformCount);
52-
if (status != UR_RESULT_SUCCESS) {
53-
std::cout << "urPlatformGet failed with return code: " << status
54-
<< std::endl;
55-
goto out;
56-
}
50+
for (auto adapter : adapters) {
51+
uint32_t adapterPlatformCount = 0;
52+
status = urPlatformGet(adapter, 0, nullptr, &adapterPlatformCount);
53+
if (status != UR_RESULT_SUCCESS) {
54+
std::cout << "urPlatformGet failed with return code: " << status
55+
<< std::endl;
56+
goto out;
57+
}
5758

58-
platforms.resize(platformCount);
59-
status = urPlatformGet(adapters.data(), adapterCount, platformCount,
60-
platforms.data(), nullptr);
61-
if (status != UR_RESULT_SUCCESS) {
62-
std::cout << "urPlatformGet failed with return code: " << status
63-
<< std::endl;
64-
goto out;
59+
platforms.reserve(platformCount + adapterPlatformCount);
60+
status = urPlatformGet(adapter, adapterPlatformCount,
61+
&platforms[platformCount], &adapterPlatformCount);
62+
if (status != UR_RESULT_SUCCESS) {
63+
std::cout << "urPlatformGet failed with return code: " << status
64+
<< std::endl;
65+
goto out;
66+
}
67+
platformCount += adapterPlatformCount;
6568
}
69+
platforms.resize(platformCount);
6670

6771
for (auto p : platforms) {
6872
ur_api_version_t api_version = {};

unified-runtime/scripts/core/PROG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Initialization and Discovery
6565
${x}PlatformGet(adapter, 0, nullptr, &adapterPlatformCount);
6666
6767
platforms.reserve(totalPlatformCount + adapterPlatformCount);
68-
${x}PlatformGet(adapter, adapterPlatformCount, &platforms[totalPlatformCount], &platformCount);
68+
${x}PlatformGet(adapter, adapterPlatformCount, &platforms[totalPlatformCount], &adapterPlatformCount);
6969
totalPlatformCount += adapterPlatformCount;
7070
}
7171

unified-runtime/test/conformance/platform/urPlatformGet.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,26 @@ struct urPlatformGetTest : ::testing::Test {
1212
};
1313

1414
TEST_F(urPlatformGetTest, Success) {
15-
uint32_t count;
16-
ASSERT_SUCCESS(urPlatformGet(adapters.data(),
17-
static_cast<uint32_t>(adapters.size()), 0,
18-
nullptr, &count));
19-
ASSERT_NE(count, 0);
20-
std::vector<ur_platform_handle_t> platforms(count);
21-
ASSERT_SUCCESS(urPlatformGet(adapters.data(),
22-
static_cast<uint32_t>(adapters.size()), count,
23-
platforms.data(), nullptr));
24-
for (auto platform : platforms) {
25-
ASSERT_NE(nullptr, platform);
15+
for (auto adapter : adapters) {
16+
uint32_t count;
17+
ASSERT_SUCCESS(urPlatformGet(adapter, 0, nullptr, &count));
18+
ASSERT_NE(count, 0);
19+
std::vector<ur_platform_handle_t> platforms(count);
20+
ASSERT_SUCCESS(urPlatformGet(adapter, count, platforms.data(), nullptr));
21+
for (auto platform : platforms) {
22+
ASSERT_NE(nullptr, platform);
23+
}
2624
}
2725
}
2826

2927
TEST_F(urPlatformGetTest, InvalidNumEntries) {
30-
uint32_t count;
31-
ASSERT_SUCCESS(urPlatformGet(adapters.data(),
32-
static_cast<uint32_t>(adapters.size()), 0,
33-
nullptr, &count));
34-
std::vector<ur_platform_handle_t> platforms(count);
35-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
36-
urPlatformGet(adapters.data(),
37-
static_cast<uint32_t>(adapters.size()), 0,
38-
platforms.data(), nullptr));
28+
for (auto adapter : adapters) {
29+
uint32_t count;
30+
ASSERT_SUCCESS(urPlatformGet(adapter, 0, nullptr, &count));
31+
std::vector<ur_platform_handle_t> platforms(count);
32+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
33+
urPlatformGet(adapter, 0, platforms.data(), nullptr));
34+
}
3935
}
4036

4137
TEST_F(urPlatformGetTest, InvalidNullPointer) {
@@ -47,8 +43,8 @@ TEST_F(urPlatformGetTest, InvalidNullPointer) {
4743
}
4844

4945
TEST_F(urPlatformGetTest, NullArgs) {
50-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
51-
urPlatformGet(adapters.data(),
52-
static_cast<uint32_t>(adapters.size()), 0,
53-
nullptr, nullptr));
46+
for (auto adapter : adapters) {
47+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
48+
urPlatformGet(adapter, 0, nullptr, nullptr));
49+
}
5450
}

unified-runtime/test/conformance/source/environment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ uur::PlatformEnvironment::PlatformEnvironment() : AdapterEnvironment() {
8080
void uur::PlatformEnvironment::populatePlatforms() {
8181
for (auto a : adapters) {
8282
uint32_t count = 0;
83-
ASSERT_SUCCESS(urPlatformGet(&a, 1, 0, nullptr, &count));
83+
ASSERT_SUCCESS(urPlatformGet(a, 0, nullptr, &count));
8484
if (count == 0) {
8585
continue;
8686
}
8787
std::vector<ur_platform_handle_t> platform_list(count);
88-
ASSERT_SUCCESS(urPlatformGet(&a, 1, count, platform_list.data(), nullptr));
88+
ASSERT_SUCCESS(urPlatformGet(a, count, platform_list.data(), nullptr));
8989

9090
for (auto p : platform_list) {
9191
platforms.push_back(p);

unified-runtime/test/fuzz/urFuzz.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,22 @@ namespace fuzz {
2121
constexpr int MAX_VECTOR_SIZE = 1024;
2222

2323
int ur_platform_get(TestState &state) {
24-
ur_result_t res = urPlatformGet(state.adapters.data(), state.adapters.size(),
25-
state.num_entries, state.platforms.data(),
26-
&state.num_platforms);
27-
if (res != UR_RESULT_SUCCESS) {
28-
return -1;
24+
uint32_t totalPlatformCount = 0;
25+
for (auto adapter : state.adapters) {
26+
uint32_t adapterPlatformCount = 0;
27+
urPlatformGet(adapter, 0, nullptr, &adapterPlatformCount);
28+
29+
state.platforms.reserve(totalPlatformCount + adapterPlatformCount);
30+
ur_result_t res = urPlatformGet(adapter, adapterPlatformCount,
31+
&state.platforms[totalPlatformCount],
32+
&adapterPlatformCount);
33+
if (res != UR_RESULT_SUCCESS) {
34+
return -1;
35+
}
36+
37+
totalPlatformCount += adapterPlatformCount;
2938
}
39+
3040
if (state.platforms.size() != state.num_platforms) {
3141
state.platforms.resize(state.num_platforms);
3242
}

unified-runtime/test/layers/sanitizer/asan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ TEST(DeviceAsan, Initialization) {
3131
ASSERT_EQ(status, UR_RESULT_SUCCESS);
3232

3333
ur_platform_handle_t platform;
34-
status = urPlatformGet(&adapter, 1, 1, &platform, nullptr);
34+
status = urPlatformGet(adapter, 1, &platform, nullptr);
3535
ASSERT_EQ(status, UR_RESULT_SUCCESS);
3636

3737
ur_device_handle_t device;
@@ -75,7 +75,7 @@ TEST(DeviceAsan, UnsupportedFeature) {
7575
ASSERT_EQ(status, UR_RESULT_SUCCESS);
7676

7777
ur_platform_handle_t platform;
78-
status = urPlatformGet(&adapter, 1, 1, &platform, nullptr);
78+
status = urPlatformGet(adapter, 1, &platform, nullptr);
7979
ASSERT_EQ(status, UR_RESULT_SUCCESS);
8080

8181
ur_device_handle_t device;

unified-runtime/test/layers/tracing/hello_world.out.logged.match

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Platform initialized.
44
---> urAdapterGet
55
<--- urAdapterGet(.NumEntries = 1, .phAdapters = {{.*}}, .pNumAdapters = nullptr) -> UR_RESULT_SUCCESS;
66
---> urPlatformGet
7-
<--- urPlatformGet(.phAdapters = {{.*}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {{.*}}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS;
7+
<--- urPlatformGet(.hAdapter = {{.*}}, .NumEntries = 1, .phPlatforms = {{.*}}, .pNumPlatforms = {{.*}} (1)) -> UR_RESULT_SUCCESS;
88
---> urPlatformGet
9-
<--- urPlatformGet(.phAdapters = {{.*}}, .NumAdapters = 1, .NumEntries = 1, .phPlatforms = {{.*}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS;
9+
<--- urPlatformGet(.hAdapter = {{.*}}, .NumEntries = 1, .phPlatforms = {{.*}}, .pNumPlatforms = nullptr) -> UR_RESULT_SUCCESS;
1010
---> urPlatformGetApiVersion
1111
<--- urPlatformGetApiVersion(.hPlatform = {{.*}}, .pVersion = {{.*}} ({{0\.[0-9]+}})) -> UR_RESULT_SUCCESS;
1212
API version: {{0\.[0-9]+}}

unified-runtime/test/layers/validation/fixtures.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,14 @@ struct valPlatformsTest : valAdaptersTest {
7272
void SetUp() override {
7373
valAdaptersTest::SetUp();
7474

75-
uint32_t count;
76-
ASSERT_EQ(urPlatformGet(adapters.data(),
77-
static_cast<uint32_t>(adapters.size()), 0, nullptr,
78-
&count),
79-
UR_RESULT_SUCCESS);
80-
ASSERT_GT(count, 0);
81-
platforms.resize(count);
82-
ASSERT_EQ(urPlatformGet(adapters.data(),
83-
static_cast<uint32_t>(adapters.size()), count,
84-
platforms.data(), nullptr),
85-
UR_RESULT_SUCCESS);
75+
for (auto adapter : adapters) {
76+
uint32_t count;
77+
ASSERT_EQ(urPlatformGet(adapter, 0, nullptr, &count), UR_RESULT_SUCCESS);
78+
ASSERT_GT(count, 0);
79+
platforms.resize(count);
80+
ASSERT_EQ(urPlatformGet(adapter, count, platforms.data(), nullptr),
81+
UR_RESULT_SUCCESS);
82+
}
8683
}
8784

8885
std::vector<ur_platform_handle_t> platforms;

unified-runtime/test/loader/handles/fixtures.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct LoaderHandleTest : ::testing::Test {
5656
ASSERT_NE(adapter, nullptr);
5757
uint32_t nplatforms = 0;
5858
platform = nullptr;
59-
ASSERT_SUCCESS(urPlatformGet(&adapter, 1, 1, &platform, &nplatforms));
59+
ASSERT_SUCCESS(urPlatformGet(adapter, 1, &platform, &nplatforms));
6060
ASSERT_NE(platform, nullptr);
6161
uint32_t ndevices;
6262
device = nullptr;

0 commit comments

Comments
 (0)