Skip to content

Commit afefdaa

Browse files
committed
Refactor kernel triggering in fuzz tests
- Properly set up and trigger the test kernel within the fuzz test. - Change the test kernel used from "bar" to "fill". - Refactor env vars used in test.
1 parent 3bf4675 commit afefdaa

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

test/fuzz/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2023 Intel Corporation
1+
# Copyright (C) 2023-2024 Intel Corporation
22
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -38,7 +38,7 @@ function(add_fuzz_test name label)
3838
ENVIRONMENT "${ENV_VARS}")
3939
# TODO: Should we check if this sanitizer flag is available?
4040
target_compile_options(${TEST_TARGET_NAME} PRIVATE -g -fsanitize=fuzzer)
41-
target_compile_definitions(${TEST_TARGET_NAME} PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/bar/sycl_spir641.spv")
41+
target_compile_definitions(${TEST_TARGET_NAME} PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0")
4242
target_include_directories(${TEST_TARGET_NAME} PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
4343

4444
add_dependencies(${TEST_TARGET_NAME} generate_device_binaries)

test/fuzz/urFuzz.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2023 Intel Corporation
1+
// Copyright (C) 2023-2024 Intel Corporation
22
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -353,36 +353,54 @@ int ur_program_create_with_il(TestState &state) {
353353
}
354354

355355
std::vector<char> il_bin;
356-
ur_program_handle_t program = nullptr;
357-
ur_kernel_handle_t kernel = nullptr;
358-
ur_queue_handle_t queue = nullptr;
359-
ur_event_handle_t event = nullptr;
356+
ur_program_handle_t program;
357+
ur_kernel_handle_t kernel;
358+
ur_queue_handle_t queue;
359+
ur_event_handle_t event;
360360
auto &context = state.contexts[state.context_num]->handle;
361361
auto &device = state.devices[state.device_num];
362+
// TODO: Use some generic utility to retrieve/use kernels
362363
std::string kernel_name =
363-
uur::device_binaries::program_kernel_map["bar"][0];
364+
uur::device_binaries::program_kernel_map["fill"][0];
364365

365366
il_bin = state.load_kernel_source();
366367
if (il_bin.empty()) {
367368
return -1;
368369
}
369370

371+
constexpr int vec_size = 64;
372+
std::vector<int> vec(vec_size, 0);
373+
370374
urProgramCreateWithIL(context, il_bin.data(), il_bin.size(), nullptr,
371375
&program);
372376
urProgramBuild(context, program, nullptr);
377+
378+
ur_mem_handle_t memory_buffer;
379+
urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, vec_size * sizeof(int),
380+
nullptr, &memory_buffer);
373381
urKernelCreate(program, kernel_name.data(), &kernel);
382+
urKernelSetArgMemObj(kernel, 0, nullptr, memory_buffer);
383+
374384
urQueueCreate(context, device, nullptr, &queue);
375385

376-
const uint32_t nDim = 3;
377-
const size_t gWorkOffset[] = {0, 0, 0};
378-
const size_t gWorkSize[] = {128, 128, 128};
386+
urEnqueueMemBufferWrite(queue, memory_buffer, true, 0,
387+
vec_size * sizeof(int), vec.data(), 0, nullptr,
388+
&event);
389+
urEventWait(1, &event);
390+
urEventRelease(event);
379391

380-
urEnqueueKernelLaunch(queue, kernel, nDim, gWorkOffset, gWorkSize, nullptr,
381-
0, nullptr, &event);
392+
constexpr uint32_t nDim = 3;
393+
const size_t gWorkOffset[] = {0, 0, 0};
394+
const size_t gWorkSize[] = {vec_size * 4, 1, 1};
395+
const size_t lWorkSize[] = {1, 1, 1};
382396

397+
urEnqueueKernelLaunch(queue, kernel, nDim, gWorkOffset, gWorkSize,
398+
lWorkSize, 0, nullptr, &event);
383399
urEventWait(1, &event);
384400
urEventRelease(event);
401+
385402
urQueueFinish(queue);
403+
urMemRelease(memory_buffer);
386404
urQueueRelease(queue);
387405
urKernelRelease(kernel);
388406
urProgramRelease(program);

test/fuzz/utils.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2023 Intel Corporation
1+
// Copyright (C) 2023-2024 Intel Corporation
22
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -105,7 +105,11 @@ struct TestState {
105105
uint8_t context_num;
106106

107107
TestState(std::unique_ptr<FuzzedDataProvider> data_provider)
108-
: data_provider(std::move(data_provider)) {}
108+
: data_provider(std::move(data_provider)) {
109+
num_adapters = 0;
110+
num_platforms = 0;
111+
num_devices = 0;
112+
}
109113

110114
template <typename IntType> int get_next_input_data(IntType *data) {
111115
if (data_provider->remaining_bytes() < sizeof(IntType)) {

0 commit comments

Comments
 (0)