From ed73e4b58d64fe4b8d193842d029a9b6c4b4bb7a Mon Sep 17 00:00:00 2001 From: Patryk Kaminski Date: Fri, 16 Feb 2024 13:04:19 +0100 Subject: [PATCH] Fix kernel not triggering in fuzz tests --- .github/workflows/cmake.yml | 1 + .github/workflows/nightly.yml | 1 + test/fuzz/CMakeLists.txt | 2 +- test/fuzz/urFuzz.cpp | 37 +++++++++++++++++++++++++---------- test/fuzz/utils.hpp | 6 +++++- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6025a7438d..29930ba7b6 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -154,6 +154,7 @@ jobs: -DUR_BUILD_ADAPTER_L0=ON -DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++ -DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib + -DUR_CONFORMANCE_TARGET_TRIPLES=spir64 - name: Build run: cmake --build ${{github.workspace}}/build -j $(nproc) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 580240a058..cf3274907a 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -45,6 +45,7 @@ jobs: -DUR_BUILD_ADAPTER_L0=ON -DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++ -DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib + -DUR_CONFORMANCE_TARGET_TRIPLES=spir64 - name: Build run: | diff --git a/test/fuzz/CMakeLists.txt b/test/fuzz/CMakeLists.txt index 897075c53d..9ed6e323dd 100644 --- a/test/fuzz/CMakeLists.txt +++ b/test/fuzz/CMakeLists.txt @@ -38,7 +38,7 @@ function(add_fuzz_test name label) ENVIRONMENT "${ENV_VARS}") # TODO: Should we check if this sanitizer flag is available? target_compile_options(${TEST_TARGET_NAME} PRIVATE -g -fsanitize=fuzzer) - target_compile_definitions(${TEST_TARGET_NAME} PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/bar/sycl_spir641.spv") + target_compile_definitions(${TEST_TARGET_NAME} PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0") target_include_directories(${TEST_TARGET_NAME} PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR}) add_dependencies(${TEST_TARGET_NAME} generate_device_binaries) diff --git a/test/fuzz/urFuzz.cpp b/test/fuzz/urFuzz.cpp index f91ca23633..d1a15c4c55 100644 --- a/test/fuzz/urFuzz.cpp +++ b/test/fuzz/urFuzz.cpp @@ -353,36 +353,53 @@ int ur_program_create_with_il(TestState &state) { } std::vector il_bin; - ur_program_handle_t program = nullptr; - ur_kernel_handle_t kernel = nullptr; - ur_queue_handle_t queue = nullptr; - ur_event_handle_t event = nullptr; + ur_program_handle_t program; + ur_kernel_handle_t kernel; + ur_queue_handle_t queue; + ur_event_handle_t event; auto &context = state.contexts[state.context_num]->handle; auto &device = state.devices[state.device_num]; std::string kernel_name = - uur::device_binaries::program_kernel_map["bar"][0]; + uur::device_binaries::program_kernel_map["fill"][0]; il_bin = state.load_kernel_source(); if (il_bin.empty()) { return -1; } + constexpr int vec_size = 64; + std::vector vec(vec_size, 0); + urProgramCreateWithIL(context, il_bin.data(), il_bin.size(), nullptr, &program); urProgramBuild(context, program, nullptr); + + ur_mem_handle_t memory_buffer; + urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, vec_size * sizeof(int), + nullptr, &memory_buffer); urKernelCreate(program, kernel_name.data(), &kernel); + urKernelSetArgMemObj(kernel, 0, nullptr, memory_buffer); + urQueueCreate(context, device, nullptr, &queue); - const uint32_t nDim = 3; - const size_t gWorkOffset[] = {0, 0, 0}; - const size_t gWorkSize[] = {128, 128, 128}; + urEnqueueMemBufferWrite(queue, memory_buffer, true, 0, + vec_size * sizeof(int), vec.data(), 0, nullptr, + &event); + urEventWait(1, &event); + urEventRelease(event); - urEnqueueKernelLaunch(queue, kernel, nDim, gWorkOffset, gWorkSize, nullptr, - 0, nullptr, &event); + constexpr uint32_t nDim = 3; + const size_t gWorkOffset[] = {0, 0, 0}; + const size_t gWorkSize[] = {vec_size * 4, 1, 1}; + const size_t lWorkSize[] = {1, 1, 1}; + urEnqueueKernelLaunch(queue, kernel, nDim, gWorkOffset, gWorkSize, + lWorkSize, 0, nullptr, &event); urEventWait(1, &event); urEventRelease(event); + urQueueFinish(queue); + urMemRelease(memory_buffer); urQueueRelease(queue); urKernelRelease(kernel); urProgramRelease(program); diff --git a/test/fuzz/utils.hpp b/test/fuzz/utils.hpp index a65fc2e381..c6911d0b06 100644 --- a/test/fuzz/utils.hpp +++ b/test/fuzz/utils.hpp @@ -105,7 +105,11 @@ struct TestState { uint8_t context_num; TestState(std::unique_ptr data_provider) - : data_provider(std::move(data_provider)) {} + : data_provider(std::move(data_provider)) { + num_adapters = 0; + num_platforms = 0; + num_devices = 0; + } template int get_next_input_data(IntType *data) { if (data_provider->remaining_bytes() < sizeof(IntType)) {