Skip to content

Commit 269c29a

Browse files
authored
[Offload] Allow setting null arguments in olLaunchKernel (#141958)
1 parent 4455d9d commit 269c29a

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

offload/liboffload/API/Kernel.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ def : Function {
4343
let name = "olLaunchKernel";
4444
let desc = "Enqueue a kernel launch with the specified size and parameters.";
4545
let details = [
46-
"If a queue is not specified, kernel execution happens synchronously"
46+
"If a queue is not specified, kernel execution happens synchronously",
47+
"ArgumentsData may be set to NULL (to indicate no parameters)"
4748
];
4849
let params = [
4950
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN_OPTIONAL>,
5051
Param<"ol_device_handle_t", "Device", "handle of the device to execute on", PARAM_IN>,
5152
Param<"ol_kernel_handle_t", "Kernel", "handle of the kernel", PARAM_IN>,
52-
Param<"const void*", "ArgumentsData", "pointer to the kernel argument struct", PARAM_IN>,
53+
Param<"const void*", "ArgumentsData", "pointer to the kernel argument struct", PARAM_IN_OPTIONAL>,
5354
Param<"size_t", "ArgumentsSize", "size of the kernel argument struct", PARAM_IN>,
5455
Param<"const ol_kernel_launch_size_args_t*", "LaunchSizeArgs", "pointer to the struct containing launch size parameters", PARAM_IN>,
5556
Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL>
5657
];
5758
let returns = [
5859
Return<"OL_ERRC_INVALID_ARGUMENT", ["`Queue == NULL && EventOut != NULL`"]>,
60+
Return<"OL_ERRC_INVALID_ARGUMENT", ["`ArgumentsSize > 0 && ArgumentsData == NULL`"]>,
5961
Return<"OL_ERRC_INVALID_DEVICE", ["If Queue is non-null but does not belong to Device"]>,
6062
];
6163
}

offload/unittests/OffloadAPI/device_code/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ macro(add_offload_test_device_code test_filename test_name)
77
add_custom_command(OUTPUT ${BIN_PATH}
88
COMMAND
99
${CMAKE_C_COMPILER} --target=nvptx64-nvidia-cuda
10+
${ARGN}
1011
-march=${LIBOMPTARGET_DEP_CUDA_ARCH}
1112
--cuda-path=${CUDA_ROOT}
1213
${SRC_PATH} -o ${BIN_PATH}
@@ -21,6 +22,7 @@ macro(add_offload_test_device_code test_filename test_name)
2122
add_custom_command(OUTPUT ${BIN_PATH}
2223
COMMAND
2324
${CMAKE_C_COMPILER} --target=amdgcn-amd-amdhsa -nogpulib
25+
${ARGN}
2426
-mcpu=${LIBOMPTARGET_DEP_AMDGPU_ARCH}
2527
${SRC_PATH} -o ${BIN_PATH}
2628
DEPENDS ${SRC_PATH}
@@ -61,6 +63,9 @@ endif()
6163

6264
add_offload_test_device_code(foo.c foo)
6365
add_offload_test_device_code(bar.c bar)
66+
# By default, amdhsa will add a number of "hidden" arguments to the kernel defintion
67+
# O3 disables this, and results in a kernel function with actually no arguments as seen by liboffload
68+
add_offload_test_device_code(noargs.c noargs -O3)
6469

6570
add_custom_target(OffloadUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
6671

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <gpuintrin.h>
2+
3+
__gpu_kernel void noargs() { (void)0; }

offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
#include <OffloadAPI.h>
1111
#include <gtest/gtest.h>
1212

13-
struct olLaunchKernelTest : OffloadQueueTest {
14-
void SetUp() override {
13+
struct LaunchKernelTestBase : OffloadQueueTest {
14+
void SetUpKernel(const char *kernel) {
1515
RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
16-
ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin));
16+
ASSERT_TRUE(TestEnvironment::loadDeviceBinary(kernel, Device, DeviceBin));
1717
ASSERT_GE(DeviceBin->getBufferSize(), 0lu);
1818
ASSERT_SUCCESS(olCreateProgram(Device, DeviceBin->getBufferStart(),
1919
DeviceBin->getBufferSize(), &Program));
20-
ASSERT_SUCCESS(olGetKernel(Program, "foo", &Kernel));
20+
ASSERT_SUCCESS(olGetKernel(Program, kernel, &Kernel));
2121
LaunchArgs.Dimensions = 1;
2222
LaunchArgs.GroupSizeX = 64;
2323
LaunchArgs.GroupSizeY = 1;
@@ -43,8 +43,20 @@ struct olLaunchKernelTest : OffloadQueueTest {
4343
ol_kernel_launch_size_args_t LaunchArgs{};
4444
};
4545

46+
struct olLaunchKernelTest : LaunchKernelTestBase {
47+
void SetUp() override {
48+
RETURN_ON_FATAL_FAILURE(LaunchKernelTestBase::SetUpKernel("foo"));
49+
}
50+
};
4651
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelTest);
4752

53+
struct olLaunchKernelNoArgsTest : LaunchKernelTestBase {
54+
void SetUp() override {
55+
RETURN_ON_FATAL_FAILURE(LaunchKernelTestBase::SetUpKernel("noargs"));
56+
}
57+
};
58+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelNoArgsTest);
59+
4860
TEST_P(olLaunchKernelTest, Success) {
4961
void *Mem;
5062
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
@@ -66,6 +78,13 @@ TEST_P(olLaunchKernelTest, Success) {
6678
ASSERT_SUCCESS(olMemFree(Mem));
6779
}
6880

81+
TEST_P(olLaunchKernelNoArgsTest, Success) {
82+
ASSERT_SUCCESS(
83+
olLaunchKernel(Queue, Device, Kernel, nullptr, 0, &LaunchArgs, nullptr));
84+
85+
ASSERT_SUCCESS(olWaitQueue(Queue));
86+
}
87+
6988
TEST_P(olLaunchKernelTest, SuccessSynchronous) {
7089
void *Mem;
7190
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,

0 commit comments

Comments
 (0)