Skip to content

Commit fa06e95

Browse files
authored
Merge pull request #1427 from PatKamin/fix-fuzztest-kernel
[CI] Fix kernel execution in fuzztests and run fuzztests on L0 in CI
2 parents 731376d + d5a90ad commit fa06e95

File tree

7 files changed

+158
-127
lines changed

7 files changed

+158
-127
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
name: Build - Fuzztests on L0 HW - Reusable
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
test_label:
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
fuzztest-build-hw:
16+
name: Build and run fuzz tests on L0 HW
17+
if: github.repository == 'oneapi-src/unified-runtime' # run only on upstream; forks won't have the HW
18+
strategy:
19+
matrix:
20+
build_type: [Debug, Release]
21+
compiler: [{c: clang, cxx: clang++}]
22+
23+
runs-on: 'FUZZTESTS'
24+
# In order to use sanitizers, vm.mmap_rnd_bits=28 must be set in the system,
25+
# otherwise random SEGV at the start of the test occurs.
26+
# Alternatively, clang 18.1.0 onwards with fixed sanitizers behavior can be used,
27+
# if available.
28+
# TODO: Remove this advice once clang 18.1.0 is available in the system (like ie. as an apt package).
29+
30+
steps:
31+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
32+
33+
- name: Install pip packages
34+
run: pip install -r third_party/requirements.txt
35+
36+
- name: Download DPC++
37+
run: |
38+
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/nightly-2024-01-29/sycl_linux.tar.gz
39+
mkdir dpcpp_compiler
40+
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz -C dpcpp_compiler
41+
42+
- name: Build level zero with gcc
43+
run: |
44+
git clone -b v1.17.6 --depth=1 https://github.com/oneapi-src/level-zero.git ${{github.workspace}}/level-zero
45+
cd ${{github.workspace}}/level-zero
46+
cmake -B build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
47+
cmake --build build -j $(nproc)
48+
49+
- name: Configure CMake
50+
run: >
51+
cmake
52+
-B${{github.workspace}}/build
53+
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
54+
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
55+
-DUR_ENABLE_TRACING=ON
56+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
57+
-DUR_BUILD_TESTS=ON
58+
-DUR_USE_ASAN=ON
59+
-DUR_USE_UBSAN=ON
60+
-DUR_BUILD_ADAPTER_L0=ON
61+
-DUR_LEVEL_ZERO_LOADER_LIBRARY=${{github.workspace}}/level-zero/build/lib/libze_loader.so
62+
-DUR_LEVEL_ZERO_INCLUDE_DIR=${{github.workspace}}/level-zero/include/
63+
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
64+
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
65+
66+
- name: Build
67+
run: cmake --build ${{github.workspace}}/build -j $(nproc)
68+
69+
- name: Fuzz test
70+
working-directory: ${{github.workspace}}/build
71+
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "${{inputs.test_label}}" --verbose
72+
73+
- name: Get information about platform
74+
if: ${{ always() }}
75+
run: .github/scripts/get_system_info.sh

.github/workflows/cmake.yml

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -116,51 +116,12 @@ jobs:
116116
working-directory: ${{github.workspace}}/build
117117
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "umf|loader|validation|tracing|unit|urtrace"
118118

119-
fuzztest-build:
120-
name: Build and run quick fuzztest scenarios
121-
strategy:
122-
matrix:
123-
build_type: [Debug, Release]
124-
compiler: [{c: clang, cxx: clang++}]
125-
126-
runs-on: 'ubuntu-22.04'
127-
128-
steps:
129-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
130-
131-
- name: Install pip packages
132-
run: pip install -r third_party/requirements.txt
133-
134-
- name: Download DPC++
135-
run: |
136-
sudo apt install libncurses5
137-
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/sycl-nightly%2F20230626/dpcpp-compiler.tar.gz
138-
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz
139-
140-
- name: Setup DPC++
141-
run: |
142-
source ${{github.workspace}}/dpcpp_compiler/startup.sh
143-
144-
- name: Configure CMake
145-
run: >
146-
cmake
147-
-B${{github.workspace}}/build
148-
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
149-
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
150-
-DUR_ENABLE_TRACING=ON
151-
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
152-
-DUR_BUILD_TESTS=ON
153-
-DUR_USE_ASAN=ON
154-
-DUR_USE_UBSAN=ON
155-
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
156-
157-
- name: Build
158-
run: cmake --build ${{github.workspace}}/build -j $(nproc)
159-
160-
- name: Fuzz test
161-
working-directory: ${{github.workspace}}/build
162-
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz-short" --verbose
163-
119+
fuzztest:
120+
name: Fuzz tests short
121+
uses: ./.github/workflows/build-fuzz-reusable.yml
122+
with:
123+
test_label: "fuzz-short"
124+
164125
level-zero:
165126
name: Level Zero
166127
uses: ./.github/workflows/build-hw-reusable.yml

.github/workflows/nightly.yml

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,8 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
long-fuzz-test:
13-
name: Run long fuzz tests
14-
strategy:
15-
matrix:
16-
build_type: [Debug, Release]
17-
compiler: [{c: clang, cxx: clang++}]
18-
19-
runs-on: 'ubuntu-22.04'
20-
21-
steps:
22-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
23-
24-
- name: Install pip packages
25-
run: pip install -r third_party/requirements.txt
26-
27-
- name: Download DPC++
28-
run: |
29-
wget -O ${{github.workspace}}/dpcpp_compiler.tar.gz https://github.com/intel/llvm/releases/download/nightly-2024-01-29/sycl_linux.tar.gz
30-
mkdir dpcpp_compiler
31-
tar -xvf ${{github.workspace}}/dpcpp_compiler.tar.gz -C dpcpp_compiler
32-
33-
- name: Configure CMake
34-
run: >
35-
cmake
36-
-B${{github.workspace}}/build
37-
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
38-
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
39-
-DUR_ENABLE_TRACING=ON
40-
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
41-
-DUR_BUILD_TESTS=ON
42-
-DUR_USE_ASAN=ON
43-
-DUR_USE_UBSAN=ON
44-
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
45-
46-
- name: Build
47-
run: >
48-
LD_LIBRARY_PATH=${{github.workspace}}/dpcpp_compiler/lib
49-
cmake --build ${{github.workspace}}/build -j $(nproc)
50-
51-
- name: Fuzz long test
52-
working-directory: ${{github.workspace}}/build
53-
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz-long"
12+
fuzztest:
13+
name: Fuzz tests long
14+
uses: ./.github/workflows/build-fuzz-reusable.yml
15+
with:
16+
test_label: "fuzz-long"

source/adapters/level_zero/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ if (NOT UR_LEVEL_ZERO_LOADER_LIBRARY STREQUAL "")
1919
file(COPY ${UR_LEVEL_ZERO_LOADER_LIBRARY} DESTINATION ${LEVEL_ZERO_COPY_DIR} FOLLOW_SYMLINK_CHAIN)
2020
endif()
2121
if (NOT UR_LEVEL_ZERO_INCLUDE_DIR STREQUAL "")
22-
set(LEVEL_ZERO_INCLUDE_DIR ${LEVEL_ZERO_COPY_DIR}/level_zero)
22+
set(LEVEL_ZERO_INCLUDE_DIR ${LEVEL_ZERO_COPY_DIR})
2323
message(STATUS "Level Zero Adapter: Copying Level Zero headers to local build tree")
24-
file(COPY ${UR_LEVEL_ZERO_INCLUDE_DIR}/level_zero DESTINATION ${LEVEL_ZERO_COPY_DIR})
24+
file(COPY ${UR_LEVEL_ZERO_INCLUDE_DIR}/ DESTINATION ${LEVEL_ZERO_COPY_DIR})
2525
endif()
2626

2727
if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)

test/fuzz/CMakeLists.txt

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
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
55

66
function(add_fuzz_test name label)
77
set(TEST_TARGET_NAME fuzztest-${name})
8-
add_ur_executable(${TEST_TARGET_NAME}
9-
urFuzz.cpp)
10-
target_link_libraries(${TEST_TARGET_NAME}
11-
PRIVATE
12-
${PROJECT_NAME}::loader
13-
${PROJECT_NAME}::headers
14-
${PROJECT_NAME}::common
15-
-fsanitize=fuzzer)
16-
add_test(NAME ${TEST_TARGET_NAME}
17-
COMMAND ${TEST_TARGET_NAME} ${ARGN} -verbosity=1
18-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
198

20-
set(ENV_VARS UR_ENABLE_LAYERS=UR_LAYER_FULL_VALIDATION)
21-
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
9+
set(ENV_VARS "")
10+
if(UR_USE_UBSAN)
2211
list(APPEND ENV_VARS
23-
UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\"
24-
NEOReadDebugKeys=1
25-
DisableDeepBind=1)
26-
else()
27-
list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_null>\")
12+
UBSAN_OPTIONS=print_stacktrace=1)
2813
endif()
2914
if(UR_ENABLE_TRACING)
3015
list(APPEND ENV_VARS
@@ -33,17 +18,42 @@ function(add_fuzz_test name label)
3318
XPTI_SUBSCRIBERS=$<TARGET_FILE:collector>
3419
UR_ENABLE_LAYERS=UR_LAYER_TRACING)
3520
endif()
21+
22+
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
23+
list(APPEND ENV_VARS
24+
UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\")
25+
if(UR_USE_ASAN)
26+
list(APPEND ENV_VARS
27+
NEOReadDebugKeys=1
28+
DisableDeepBind=1)
29+
endif()
30+
else()
31+
list(APPEND ENV_VARS UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_null>\")
32+
endif()
33+
34+
add_test(NAME ${TEST_TARGET_NAME}
35+
COMMAND fuzztest-base ${ARGN} -verbosity=1 -detect_leaks=0
36+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
37+
3638
set_tests_properties(${TEST_TARGET_NAME} PROPERTIES
3739
LABELS ${label}
3840
ENVIRONMENT "${ENV_VARS}")
39-
# TODO: Should we check if this sanitizer flag is available?
40-
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")
42-
target_include_directories(${TEST_TARGET_NAME} PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
43-
44-
add_dependencies(${TEST_TARGET_NAME} generate_device_binaries)
4541
endfunction()
4642

43+
# Create a single binary
44+
add_ur_executable(fuzztest-base
45+
urFuzz.cpp)
46+
target_link_libraries(fuzztest-base
47+
PRIVATE
48+
${PROJECT_NAME}::loader
49+
${PROJECT_NAME}::headers
50+
${PROJECT_NAME}::common
51+
-fsanitize=fuzzer)
52+
target_compile_options(fuzztest-base PRIVATE -g -fsanitize=fuzzer)
53+
target_compile_definitions(fuzztest-base PRIVATE -DKERNEL_IL_PATH="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/fill/spir64.bin.0")
54+
target_include_directories(fuzztest-base PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
55+
add_dependencies(fuzztest-base generate_device_binaries)
56+
4757
# Add long test
4858
add_fuzz_test(base fuzz-long -max_total_time=600 -seed=1)
4959

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)