[Offload] Allow setting null arguments in olLaunchKernel (#141958)
This commit is contained in:
@@ -43,19 +43,21 @@ def : Function {
|
||||
let name = "olLaunchKernel";
|
||||
let desc = "Enqueue a kernel launch with the specified size and parameters.";
|
||||
let details = [
|
||||
"If a queue is not specified, kernel execution happens synchronously"
|
||||
"If a queue is not specified, kernel execution happens synchronously",
|
||||
"ArgumentsData may be set to NULL (to indicate no parameters)"
|
||||
];
|
||||
let params = [
|
||||
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN_OPTIONAL>,
|
||||
Param<"ol_device_handle_t", "Device", "handle of the device to execute on", PARAM_IN>,
|
||||
Param<"ol_kernel_handle_t", "Kernel", "handle of the kernel", PARAM_IN>,
|
||||
Param<"const void*", "ArgumentsData", "pointer to the kernel argument struct", PARAM_IN>,
|
||||
Param<"const void*", "ArgumentsData", "pointer to the kernel argument struct", PARAM_IN_OPTIONAL>,
|
||||
Param<"size_t", "ArgumentsSize", "size of the kernel argument struct", PARAM_IN>,
|
||||
Param<"const ol_kernel_launch_size_args_t*", "LaunchSizeArgs", "pointer to the struct containing launch size parameters", PARAM_IN>,
|
||||
Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL>
|
||||
];
|
||||
let returns = [
|
||||
Return<"OL_ERRC_INVALID_ARGUMENT", ["`Queue == NULL && EventOut != NULL`"]>,
|
||||
Return<"OL_ERRC_INVALID_ARGUMENT", ["`ArgumentsSize > 0 && ArgumentsData == NULL`"]>,
|
||||
Return<"OL_ERRC_INVALID_DEVICE", ["If Queue is non-null but does not belong to Device"]>,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ macro(add_offload_test_device_code test_filename test_name)
|
||||
add_custom_command(OUTPUT ${BIN_PATH}
|
||||
COMMAND
|
||||
${CMAKE_C_COMPILER} --target=nvptx64-nvidia-cuda
|
||||
${ARGN}
|
||||
-march=${LIBOMPTARGET_DEP_CUDA_ARCH}
|
||||
--cuda-path=${CUDA_ROOT}
|
||||
${SRC_PATH} -o ${BIN_PATH}
|
||||
@@ -21,6 +22,7 @@ macro(add_offload_test_device_code test_filename test_name)
|
||||
add_custom_command(OUTPUT ${BIN_PATH}
|
||||
COMMAND
|
||||
${CMAKE_C_COMPILER} --target=amdgcn-amd-amdhsa -nogpulib
|
||||
${ARGN}
|
||||
-mcpu=${LIBOMPTARGET_DEP_AMDGPU_ARCH}
|
||||
${SRC_PATH} -o ${BIN_PATH}
|
||||
DEPENDS ${SRC_PATH}
|
||||
@@ -61,6 +63,9 @@ endif()
|
||||
|
||||
add_offload_test_device_code(foo.c foo)
|
||||
add_offload_test_device_code(bar.c bar)
|
||||
# By default, amdhsa will add a number of "hidden" arguments to the kernel defintion
|
||||
# O3 disables this, and results in a kernel function with actually no arguments as seen by liboffload
|
||||
add_offload_test_device_code(noargs.c noargs -O3)
|
||||
|
||||
add_custom_target(OffloadUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
|
||||
|
||||
|
||||
3
offload/unittests/OffloadAPI/device_code/noargs.c
Normal file
3
offload/unittests/OffloadAPI/device_code/noargs.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <gpuintrin.h>
|
||||
|
||||
__gpu_kernel void noargs() { (void)0; }
|
||||
@@ -10,14 +10,14 @@
|
||||
#include <OffloadAPI.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
struct olLaunchKernelTest : OffloadQueueTest {
|
||||
void SetUp() override {
|
||||
struct LaunchKernelTestBase : OffloadQueueTest {
|
||||
void SetUpKernel(const char *kernel) {
|
||||
RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
|
||||
ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin));
|
||||
ASSERT_TRUE(TestEnvironment::loadDeviceBinary(kernel, Device, DeviceBin));
|
||||
ASSERT_GE(DeviceBin->getBufferSize(), 0lu);
|
||||
ASSERT_SUCCESS(olCreateProgram(Device, DeviceBin->getBufferStart(),
|
||||
DeviceBin->getBufferSize(), &Program));
|
||||
ASSERT_SUCCESS(olGetKernel(Program, "foo", &Kernel));
|
||||
ASSERT_SUCCESS(olGetKernel(Program, kernel, &Kernel));
|
||||
LaunchArgs.Dimensions = 1;
|
||||
LaunchArgs.GroupSizeX = 64;
|
||||
LaunchArgs.GroupSizeY = 1;
|
||||
@@ -43,8 +43,20 @@ struct olLaunchKernelTest : OffloadQueueTest {
|
||||
ol_kernel_launch_size_args_t LaunchArgs{};
|
||||
};
|
||||
|
||||
struct olLaunchKernelTest : LaunchKernelTestBase {
|
||||
void SetUp() override {
|
||||
RETURN_ON_FATAL_FAILURE(LaunchKernelTestBase::SetUpKernel("foo"));
|
||||
}
|
||||
};
|
||||
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelTest);
|
||||
|
||||
struct olLaunchKernelNoArgsTest : LaunchKernelTestBase {
|
||||
void SetUp() override {
|
||||
RETURN_ON_FATAL_FAILURE(LaunchKernelTestBase::SetUpKernel("noargs"));
|
||||
}
|
||||
};
|
||||
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelNoArgsTest);
|
||||
|
||||
TEST_P(olLaunchKernelTest, Success) {
|
||||
void *Mem;
|
||||
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
|
||||
@@ -66,6 +78,13 @@ TEST_P(olLaunchKernelTest, Success) {
|
||||
ASSERT_SUCCESS(olMemFree(Mem));
|
||||
}
|
||||
|
||||
TEST_P(olLaunchKernelNoArgsTest, Success) {
|
||||
ASSERT_SUCCESS(
|
||||
olLaunchKernel(Queue, Device, Kernel, nullptr, 0, &LaunchArgs, nullptr));
|
||||
|
||||
ASSERT_SUCCESS(olWaitQueue(Queue));
|
||||
}
|
||||
|
||||
TEST_P(olLaunchKernelTest, SuccessSynchronous) {
|
||||
void *Mem;
|
||||
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
|
||||
|
||||
Reference in New Issue
Block a user