Skip to content

Commit 68b5a76

Browse files
committed
[Offload] Allow setting null arguments in olLaunchKernel
1 parent 11c7a0c commit 68b5a76

File tree

6 files changed

+41
-13
lines changed

6 files changed

+41
-13
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/liboffload/include/generated/OffloadAPI.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,20 +692,22 @@ typedef struct ol_kernel_launch_size_args_t {
692692
///
693693
/// @details
694694
/// - If a queue is not specified, kernel execution happens synchronously
695+
/// - ArgumentsData may be set to NULL (to indicate no parameters)
695696
///
696697
/// @returns
697698
/// - ::OL_RESULT_SUCCESS
698699
/// - ::OL_ERRC_UNINITIALIZED
699700
/// - ::OL_ERRC_DEVICE_LOST
700701
/// - ::OL_ERRC_INVALID_ARGUMENT
701702
/// + `Queue == NULL && EventOut != NULL`
703+
/// - ::OL_ERRC_INVALID_ARGUMENT
704+
/// + `ArgumentsSize > 0 && ArgumentsData == NULL`
702705
/// - ::OL_ERRC_INVALID_DEVICE
703706
/// + If Queue is non-null but does not belong to Device
704707
/// - ::OL_ERRC_INVALID_NULL_HANDLE
705708
/// + `NULL == Device`
706709
/// + `NULL == Kernel`
707710
/// - ::OL_ERRC_INVALID_NULL_POINTER
708-
/// + `NULL == ArgumentsData`
709711
/// + `NULL == LaunchSizeArgs`
710712
OL_APIEXPORT ol_result_t OL_APICALL olLaunchKernel(
711713
// [in][optional] handle of the queue
@@ -714,7 +716,7 @@ OL_APIEXPORT ol_result_t OL_APICALL olLaunchKernel(
714716
ol_device_handle_t Device,
715717
// [in] handle of the kernel
716718
ol_kernel_handle_t Kernel,
717-
// [in] pointer to the kernel argument struct
719+
// [in][optional] pointer to the kernel argument struct
718720
const void *ArgumentsData,
719721
// [in] size of the kernel argument struct
720722
size_t ArgumentsSize,

offload/liboffload/include/generated/OffloadEntryPoints.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,12 @@ olLaunchKernel_val(ol_queue_handle_t Queue, ol_device_handle_t Device,
838838
"validation failure: Queue == NULL && EventOut != NULL");
839839
}
840840

841+
if (ArgumentsSize > 0 && ArgumentsData == NULL) {
842+
return createOffloadError(
843+
error::ErrorCode::INVALID_ARGUMENT,
844+
"validation failure: ArgumentsSize > 0 && ArgumentsData == NULL");
845+
}
846+
841847
if (NULL == Device) {
842848
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
843849
"validation failure: NULL == Device");
@@ -848,11 +854,6 @@ olLaunchKernel_val(ol_queue_handle_t Queue, ol_device_handle_t Device,
848854
"validation failure: NULL == Kernel");
849855
}
850856

851-
if (NULL == ArgumentsData) {
852-
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
853-
"validation failure: NULL == ArgumentsData");
854-
}
855-
856857
if (NULL == LaunchSizeArgs) {
857858
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
858859
"validation failure: NULL == LaunchSizeArgs");

offload/unittests/OffloadAPI/device_code/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ endif()
6161

6262
add_offload_test_device_code(foo.c foo)
6363
add_offload_test_device_code(bar.c bar)
64+
add_offload_test_device_code(noargs.c noargs)
6465

6566
add_custom_target(OffloadUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
6667

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, 64, &Mem));
@@ -65,6 +77,13 @@ TEST_P(olLaunchKernelTest, Success) {
6577
ASSERT_SUCCESS(olMemFree(Mem));
6678
}
6779

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

0 commit comments

Comments
 (0)