Skip to content

Commit 3bda2c9

Browse files
committed
[L0] Use all devices from a context in urProgramBuild
Using just the first device makes creating a kernel from that program for any other devices impossible. urEnqueueKernelLaunch fails with UR_ERROR_INVALID_QUEUE.
1 parent 4a60029 commit 3bda2c9

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

source/adapters/level_zero/program.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
114114
const char *Options ///< [in][optional] pointer to build options
115115
///< null-terminated string.
116116
) {
117-
return urProgramBuildExp(Program, 1, Context->Devices.data(), Options);
117+
return urProgramBuildExp(Program, Context->Devices.size(),
118+
Context->Devices.data(), Options);
118119
}
119120

120121
UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp(

test/conformance/kernel/urKernelCreate.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
#include <uur/fixtures.h>
7+
#include <uur/raii.h>
78

89
struct urKernelCreateTest : uur::urProgramTest {
910
void SetUp() override {
@@ -51,3 +52,40 @@ TEST_P(urKernelCreateTest, InvalidKernelName) {
5152
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_NAME,
5253
urKernelCreate(program, invalid_name.data(), &kernel));
5354
}
55+
56+
using urMultiDeviceKernelCreateTest = uur::urMultiDeviceQueueTest;
57+
58+
TEST_F(urMultiDeviceKernelCreateTest, Success) {
59+
constexpr size_t global_offset = 0;
60+
constexpr size_t n_dimensions = 1;
61+
constexpr size_t global_size = 100;
62+
constexpr size_t local_size = 100;
63+
64+
auto kernelName =
65+
uur::KernelsEnvironment::instance->GetEntryPointNames("foo")[0];
66+
67+
std::shared_ptr<std::vector<char>> il_binary;
68+
uur::KernelsEnvironment::instance->LoadSource("foo", il_binary);
69+
70+
auto &devices = uur::KernelsEnvironment::instance->devices;
71+
for (size_t i = 0; i < devices.size(); i++) {
72+
uur::raii::Program program;
73+
uur::raii::Kernel kernel;
74+
75+
const ur_program_properties_t properties = {
76+
UR_STRUCTURE_TYPE_PROGRAM_PROPERTIES, nullptr, 0, nullptr};
77+
ASSERT_SUCCESS(uur::KernelsEnvironment::instance->CreateProgram(
78+
platform, context, devices[i], *il_binary, &properties,
79+
program.ptr()));
80+
81+
ASSERT_SUCCESS(urProgramBuild(context, program.get(), nullptr));
82+
ASSERT_SUCCESS(
83+
urKernelCreate(program.get(), kernelName.data(), kernel.ptr()));
84+
85+
ASSERT_SUCCESS(urEnqueueKernelLaunch(
86+
queues[i], kernel.get(), n_dimensions, &global_offset, &local_size,
87+
&global_size, 0, nullptr, nullptr));
88+
89+
ASSERT_SUCCESS(urQueueFinish(queues[i]));
90+
}
91+
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,27 @@ struct urGlobalVariableTest : uur::urKernelExecutionTest {
15001500
GlobalVar<int> global_var;
15011501
};
15021502

1503+
struct urMultiDeviceQueueTest : urMultiDeviceContextTest {
1504+
void SetUp() override {
1505+
UUR_RETURN_ON_FATAL_FAILURE(urMultiDeviceContextTest::SetUp());
1506+
queues.reserve(DevicesEnvironment::instance->devices.size());
1507+
for (const auto &device : DevicesEnvironment::instance->devices) {
1508+
ur_queue_handle_t queue = nullptr;
1509+
ASSERT_SUCCESS(urQueueCreate(context, device, 0, &queue));
1510+
queues.push_back(queue);
1511+
}
1512+
}
1513+
1514+
void TearDown() override {
1515+
for (const auto &queue : queues) {
1516+
EXPECT_SUCCESS(urQueueRelease(queue));
1517+
}
1518+
UUR_RETURN_ON_FATAL_FAILURE(urMultiDeviceContextTest::TearDown());
1519+
}
1520+
1521+
std::vector<ur_queue_handle_t> queues;
1522+
};
1523+
15031524
} // namespace uur
15041525

15051526
#endif // UR_CONFORMANCE_INCLUDE_FIXTURES_H_INCLUDED

0 commit comments

Comments
 (0)