Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UR][CTS] Add tests for urEnqueueDeviceGlobalRead/Write #690

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/conformance/device_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ macro(add_device_binary SOURCE_FILE)
endmacro()

add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/bar.cpp)
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/device_global.cpp)
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/fill.cpp)
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/fill_2d.cpp)
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/fill_3d.cpp)
Expand Down
23 changes: 23 additions & 0 deletions test/conformance/device_code/device_global.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2023 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <sycl/sycl.hpp>

sycl::ext::oneapi::experimental::device_global<int> dev_var;

int main() {

sycl::queue deviceQueue;
sycl::range<1> numOfItems{1};
deviceQueue.submit([&](sycl::handler &cgh) {
auto kern = [=](sycl::id<1>) {
// just increment
dev_var = dev_var + 1;
};
cgh.parallel_for<class device_global>(numOfItems, kern);
});

return 0;
}
2 changes: 2 additions & 0 deletions test/conformance/enqueue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

add_conformance_test_with_kernels_environment(enqueue
urEnqueueDeviceGlobalVariableRead.cpp
urEnqueueDeviceGlobalVariableWrite.cpp
urEnqueueEventsWait.cpp
urEnqueueEventsWaitWithBarrier.cpp
urEnqueueKernelLaunch.cpp
Expand Down
91 changes: 91 additions & 0 deletions test/conformance/enqueue/urEnqueueDeviceGlobalVariableRead.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (C) 2023 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <uur/fixtures.h>

using urEnqueueDeviceGetGlobalVariableReadTest = uur::urGlobalVariableTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueDeviceGetGlobalVariableReadTest);

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, Success) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only included 1 success case since to assert behaviour you have to use both entry-points.


ASSERT_SUCCESS(urEnqueueDeviceGlobalVariableWrite(
queue, program, global_var.name.c_str(), true, sizeof(global_var.value),
0, &global_var.value, 0, nullptr, nullptr));

size_t global_offset = 0;
size_t n_dimensions = 1;
size_t global_size = 1;

// execute the kernel
ASSERT_SUCCESS(urEnqueueKernelLaunch(queue, kernel, n_dimensions,
&global_offset, &global_size, nullptr,
1, nullptr, nullptr));
ASSERT_SUCCESS(urQueueFinish(queue));

// read global var back to host
ASSERT_SUCCESS(urEnqueueDeviceGlobalVariableRead(
queue, program, global_var.name.c_str(), true, sizeof(global_var.value),
0, &global_var.value, 0, nullptr, nullptr));

// kernel should increment value
ASSERT_EQ(global_var.value, 1);
}

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidNullHandleQueue) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
nullptr, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidNullHandleProgram) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
queue, nullptr, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidNullPointerName) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
queue, program, nullptr, true,
sizeof(global_var.value), 0, &global_var.value, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidNullPointerDst) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, nullptr, 0, nullptr,
nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest,
InvalidEventWaitListNullEvents) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 1,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}

TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidEventWaitListZeroSize) {
ur_event_handle_t evt = nullptr;
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 0,
&evt, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}
TEST_P(urEnqueueDeviceGetGlobalVariableReadTest, InvalidEventWaitInvalidEvent) {
ur_event_handle_t inv_evt = nullptr;
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableRead(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 1,
&inv_evt, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}
68 changes: 68 additions & 0 deletions test/conformance/enqueue/urEnqueueDeviceGlobalVariableWrite.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2023 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <uur/fixtures.h>

using urEnqueueDeviceGetGlobalVariableWriteTest = uur::urGlobalVariableTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueDeviceGetGlobalVariableWriteTest);

TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest, InvalidNullHandleQueue) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
nullptr, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest, InvalidNullHandleProgram) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
queue, nullptr, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest, InvalidNullPointerName) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
queue, program, nullptr, true,
sizeof(global_var.value), 0, &global_var.value, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest, InvalidNullPointerSrc) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, nullptr, 0, nullptr,
nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest,
InvalidEventWaitListNullEvents) {
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 1,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}

TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest,
InvalidEventWaitListZeroSize) {
ur_event_handle_t evt = nullptr;
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 0,
&evt, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}
TEST_P(urEnqueueDeviceGetGlobalVariableWriteTest,
InvalidEventWaitInvalidEvent) {
ur_event_handle_t inv_evt = nullptr;
ASSERT_EQ_RESULT(urEnqueueDeviceGlobalVariableWrite(
queue, program, global_var.name.c_str(), true,
sizeof(global_var.value), 0, &global_var.value, 1,
&inv_evt, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}
16 changes: 16 additions & 0 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,22 @@ struct urKernelExecutionTest : urKernelTest {
std::vector<ur_mem_handle_t> buffer_args;
uint32_t current_arg_index = 0;
};

template <class T> struct GlobalVar {
std::string name;
T value;
};

struct urGlobalVariableTest : uur::urKernelExecutionTest {
void SetUp() override {
program_name = "device_global";
global_var = {"_Z7dev_var", 0};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mangled name here I got from inspecting the SYCL_PI_TRACE with the call - perhaps we could do something similar to the kernel_names header here - but just kept it simple for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me

UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());
}

GlobalVar<int> global_var;
};

} // namespace uur

#endif // UR_CONFORMANCE_INCLUDE_FIXTURES_H_INCLUDED