Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test parts of API with libFuzzer. #731

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f778e6f
[ur][L0] add external level zero adapter
pbalcer Jun 2, 2023
80e168e
[level-zero] fix build script and failing tests
pbalcer Jun 5, 2023
a55b54a
Merge commit '7e16bb37cbb12450637e595749c3617151cbe851' into adapters
pbalcer Jun 29, 2023
09994ff
update level-zero
pbalcer Jun 29, 2023
ed6e5b4
add cuda adapter
pbalcer Jun 29, 2023
44e5ed2
suppress git warnings about applying cuda patch twice
pbalcer Jul 5, 2023
912e808
Merge commit 'c7b0caf4e3ce5330bd0669db6e8e498b48e8ad27' into adapters
Jul 12, 2023
2b50550
[UR] update adapter to use newer sycl plugin version
Jul 12, 2023
7c2db62
[UR] Fix L0 plugin file names
Jul 12, 2023
43f4216
[UR] Bump L0 Loader version
Jul 12, 2023
df020c0
Merge pull request #707 from veselypeta/adapters
veselypeta Jul 13, 2023
40c5086
[UR][HIP] Add ur hip target build to ur repo
omarahmed1111 Jul 14, 2023
4dcc3e2
Merge pull request #721 from omarahmed1111/add-hip-build-to-ur
omarahmed1111 Jul 14, 2023
896a732
update sycl adapters tag and add adapter CI
pbalcer Jul 18, 2023
8af5a83
Merge pull request #725 from pbalcer/adapters-ci
pbalcer Jul 18, 2023
e97c22d
[adapters] only export get proc table symbols in adapters
pbalcer Jul 18, 2023
16a0354
Merge pull request #727 from pbalcer/adapters-map
pbalcer Jul 21, 2023
1895883
[ur] Fix adapters linker script path on Linux
kbenzie Jul 28, 2023
d582c12
Merge pull request #752 from kbenzie/benie/fix-linux-adapters-map
kbenzie Jul 31, 2023
fcded3d
[UR] Implement CUDA native handle tests
Jul 14, 2023
41bcb88
Merge pull request #756 from veselypeta/petr/adapter-testing
veselypeta Aug 1, 2023
99ac337
Merge commit '5513ee2f96c4a56b0ae1c1de307505b2f83984ca' into adapters
pbalcer Aug 1, 2023
ca91dc9
[UR] Add license to missing files
Aug 1, 2023
68c9230
Merge pull request #760 from veselypeta/petr/fix-license
pbalcer Aug 1, 2023
759e753
[ADAPTERS] update to latest from sycl
pbalcer Aug 1, 2023
fb05463
Merge pull request #759 from pbalcer/adapters-update
pbalcer Aug 2, 2023
1984c1d
Test parts of API with libFuzzer.
PatKamin Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
build_type: Release
compiler: {c: clang, cxx: clang++}
libbacktrace: '-DVAL_USE_LIBBACKTRACE_BACKTRACE=OFF'
fuzztest: ON
- os: 'ubuntu-22.04'
build_type: Release
compiler: {c: gcc, cxx: g++}
Expand All @@ -25,6 +26,7 @@ jobs:
build_type: Release
compiler: {c: clang, cxx: clang++}
libbacktrace: '-DVAL_USE_LIBBACKTRACE_BACKTRACE=ON'
fuzztest: ON
- os: 'ubuntu-20.04'
build_type: Release
compiler: {c: gcc-7, cxx: g++-7}
Expand Down Expand Up @@ -70,7 +72,6 @@ jobs:
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUR_ENABLE_TRACING=ON
-DUR_DEVELOPER_MODE=ON
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DUR_BUILD_TESTS=ON
-DUR_FORMAT_CPP_STYLE=ON
Expand All @@ -89,6 +90,60 @@ jobs:
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|umf|loader|validation|tracing|unit|urtrace"

- name: Fuzz test
working-directory: ${{github.workspace}}/build
if: matrix.fuzztest == 'ON'
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "fuzz"

adapter-build:
name: Build - Adapters on Ubuntu
strategy:
matrix:
os: ['ubuntu-22.04']
adapter: [CUDA, HIP, L0]
build_type: [Debug, Release]
compiler: [{c: gcc, cxx: g++}, {c: clang, cxx: clang++}]

runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3

- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y doxygen ${{matrix.compiler.c}}

- name: Install pip packages
run: pip install -r third_party/requirements.txt

- name: Install CUDA specific dependencies
if: matrix.adapter == 'CUDA'
run: |
sudo apt-get install nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc

- name: Install HIP specific dependencies
if: matrix.adapter == 'HIP'
run: |
wget https://repo.radeon.com/amdgpu-install/5.6/ubuntu/jammy/amdgpu-install_5.6.50600-1_all.deb
sudo apt install ./amdgpu-install_5.6.50600-1_all.deb
sudo amdgpu-install --usecase=rocm

- name: Configure CMake
run: >
cmake
-B${{github.workspace}}/build
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUR_ENABLE_TRACING=ON
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DUR_BUILD_TESTS=ON
-DUR_FORMAT_CPP_STYLE=ON
-DUR_BUILD_ADAPTER_${{matrix.adapter}}=ON

- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc)

windows-build:
name: Build - Windows
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ out/
# IDE Files
/.vscode
/.devcontainer

# External content
/external
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
option(UR_BUILD_TOOLS "build ur tools" ON)
option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" OFF)
option(UR_BUILD_ADAPTER_L0 "build level 0 adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_CUDA "build cuda adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_HIP "build hip adapter from SYCL" OFF)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -88,7 +91,7 @@ if(UR_ENABLE_TRACING)
set(XPTI_DIR ${xpti_SOURCE_DIR})
set(XPTI_ENABLE_TESTS OFF CACHE INTERNAL "Turn off xptifw tests")

FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "sycl-nightly/20230304" "xptifw")
FetchContentSparse_Declare(xptifw https://github.com/intel/llvm.git "sycl-nightly/20230703" "xptifw")

FetchContent_MakeAvailable(xptifw)

Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@
[![Bandit](https://github.com/oneapi-src/unified-runtime/actions/workflows/bandit.yml/badge.svg)](https://github.com/oneapi-src/unified-runtime/actions/workflows/bandit.yml)
[![Coverity](https://scan.coverity.com/projects/28213/badge.svg)](https://scan.coverity.com/projects/oneapi-src-unified-runtime)

## Adapters
Adapter implementations for Unified Runtime currently reside in the [SYCL repository](https://github.com/intel/llvm/tree/sycl/sycl/plugins/unified_runtime/ur). This branch contains scripts to automatically
fetch and build them directly in the UR tree. The adapters are disabled by default,
see cmake options for details.

<!-- TODO: add general description and purpose of the project -->

## Table of contents

1. [Contents of the repo](#contents-of-the-repo)
2. [Integration](#integration)
- [Unified Runtime](#unified-runtime)
- [Adapters](#adapters)
- [Table of contents](#table-of-contents)
- [Contents of the repo](#contents-of-the-repo)
- [Integration](#integration)
- [Weekly tags](#weekly-tags)
3. [Third-Party tools](#third-party-tools)
4. [Building](#building)
- [Third-Party tools](#third-party-tools)
- [Building](#building)
- [Windows](#windows)
- [Linux](#linux)
- [CMake standard options](#cmake-standard-options)
- [Additional make targets](#additional-make-targets)
5. [Contributions](#contributions)
- [Contributions](#contributions)
- [Adapter naming convention](#adapter-naming-convention)
- [Source code generation](#source-code-generation)
- [Documentation](#documentation)
Expand Down Expand Up @@ -112,6 +120,10 @@ List of options provided by CMake:
| UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF |
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
| UR_BUILD_ADAPTER_L0 | Fetch and use level-zero adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_CUDA | Fetch and use cuda adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |

### Additional make targets

Expand Down
34 changes: 21 additions & 13 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,30 @@ endfunction()

include(FetchContent)

function(FetchSource GIT_REPOSITORY GIT_TAG GIT_DIR DEST)
message(STATUS "Fetching sparse source ${GIT_DIR} from ${GIT_REPOSITORY} ${GIT_TAG}")
IF(NOT EXISTS ${DEST})
file(MAKE_DIRECTORY ${DEST})
execute_process(COMMAND git init
WORKING_DIRECTORY ${DEST})
execute_process(COMMAND git checkout -b main
WORKING_DIRECTORY ${DEST})
execute_process(COMMAND git remote add origin ${GIT_REPOSITORY}
WORKING_DIRECTORY ${DEST})
execute_process(COMMAND git config core.sparsecheckout true
WORKING_DIRECTORY ${DEST})
file(APPEND ${DEST}/.git/info/sparse-checkout ${GIT_DIR}/)
endif()
execute_process(COMMAND git fetch --depth=1 origin refs/tags/${GIT_TAG}:refs/tags/${GIT_TAG}
WORKING_DIRECTORY ${DEST})
execute_process(COMMAND git checkout --quiet ${GIT_TAG}
WORKING_DIRECTORY ${DEST})
endfunction()

# A wrapper around FetchContent_Declare that supports git sparse checkout.
# This is useful for including subprojects from large repositories.
function(FetchContentSparse_Declare name GIT_REPOSITORY GIT_TAG GIT_DIR)
set(content-build-dir ${CMAKE_BINARY_DIR}/content-${name})
message(STATUS "Fetching sparse content ${GIT_DIR} from ${GIT_REPOSITORY} ${GIT_TAG}")
IF(NOT EXISTS ${content-build-dir})
file(MAKE_DIRECTORY ${content-build-dir})
execute_process(COMMAND git init -b main
WORKING_DIRECTORY ${content-build-dir})
execute_process(COMMAND git remote add origin ${GIT_REPOSITORY}
WORKING_DIRECTORY ${content-build-dir})
execute_process(COMMAND git config core.sparsecheckout true
WORKING_DIRECTORY ${content-build-dir})
file(APPEND ${content-build-dir}/.git/info/sparse-checkout ${GIT_DIR}/)
endif()
execute_process(COMMAND git pull --depth=1 origin ${GIT_TAG}
WORKING_DIRECTORY ${content-build-dir})
FetchSource(${GIT_REPOSITORY} ${GIT_TAG} ${GIT_DIR} ${content-build-dir})
FetchContent_Declare(${name} SOURCE_DIR ${content-build-dir}/${GIT_DIR})
endfunction()
43 changes: 43 additions & 0 deletions source/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,47 @@
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

function(add_ur_adapter name)
add_ur_library(${name} ${ARGN})
if(MSVC)
set(TARGET_LIBNAME ${name})
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)

set(ADAPTER_VERSION_SCRIPT ${name}.def)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../adapter.def.in ${ADAPTER_VERSION_SCRIPT} @ONLY)
set_target_properties(${name} PROPERTIES
LINK_FLAGS "/DEF:${ADAPTER_VERSION_SCRIPT}"
)
elseif(APPLE)
target_compile_options(${name} PRIVATE "-fvisibility=hidden")
else()
set(TARGET_LIBNAME lib${name}_${PROJECT_VERSION_MAJOR}.0)
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)

set(ADAPTER_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/${name}.map)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../adapter.map.in ${ADAPTER_VERSION_SCRIPT} @ONLY)
target_link_options(${name} PRIVATE "-Wl,--version-script=${ADAPTER_VERSION_SCRIPT}")
endif()
endfunction()

add_subdirectory(null)

if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP)
# fetch adapter sources from SYCL
set(SYCL_ADAPTER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external")
FetchSource(https://github.com/intel/llvm.git nightly-2023-08-01 "sycl/plugins/unified_runtime/ur" ${SYCL_ADAPTER_DIR})
endif()

if(UR_BUILD_ADAPTER_L0)
add_subdirectory(level_zero)
endif()

if(UR_BUILD_ADAPTER_CUDA)
add_subdirectory(cuda)
endif()

if(UR_BUILD_ADAPTER_HIP)
add_subdirectory(hip)
endif()
20 changes: 20 additions & 0 deletions source/adapters/adapter.def.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
LIBRARY @TARGET_LIBNAME@
EXPORTS
urGetBindlessImagesExpProcAddrTable
urGetCommandBufferExpProcAddrTable
urGetContextProcAddrTable
urGetDeviceProcAddrTable
urGetEnqueueProcAddrTable
urGetEventProcAddrTable
urGetGlobalProcAddrTable
urGetKernelProcAddrTable
urGetMemProcAddrTable
urGetPhysicalMemProcAddrTable
urGetPlatformProcAddrTable
urGetProgramProcAddrTable
urGetQueueProcAddrTable
urGetSamplerProcAddrTable
urGetUSMExpProcAddrTable
urGetUsmP2PExpProcAddrTable
urGetUSMProcAddrTable
urGetVirtualMemProcAddrTable
23 changes: 23 additions & 0 deletions source/adapters/adapter.map.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@TARGET_LIBNAME@ {
global:
urGetBindlessImagesExpProcAddrTable;
urGetCommandBufferExpProcAddrTable;
urGetContextProcAddrTable;
urGetDeviceProcAddrTable;
urGetEnqueueProcAddrTable;
urGetEventProcAddrTable;
urGetGlobalProcAddrTable;
urGetKernelProcAddrTable;
urGetMemProcAddrTable;
urGetPhysicalMemProcAddrTable;
urGetPlatformProcAddrTable;
urGetProgramProcAddrTable;
urGetQueueProcAddrTable;
urGetSamplerProcAddrTable;
urGetUSMExpProcAddrTable;
urGetUsmP2PExpProcAddrTable;
urGetUSMProcAddrTable;
urGetVirtualMemProcAddrTable;
local:
*;
};
80 changes: 80 additions & 0 deletions source/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (C) 2022 Intel Corporation
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(CUDA_DIR "${SYCL_ADAPTER_DIR}/sycl/plugins/unified_runtime/ur/adapters/cuda")

set(TARGET_NAME ur_adapter_cuda)

add_ur_adapter(${TARGET_NAME}
SHARED
${CUDA_DIR}/ur_interface_loader.cpp
${CUDA_DIR}/adapter.hpp
${CUDA_DIR}/adapter.cpp
${CUDA_DIR}/command_buffer.hpp
${CUDA_DIR}/command_buffer.cpp
${CUDA_DIR}/common.hpp
${CUDA_DIR}/common.cpp
${CUDA_DIR}/context.hpp
${CUDA_DIR}/context.cpp
${CUDA_DIR}/device.hpp
${CUDA_DIR}/device.cpp
${CUDA_DIR}/enqueue.cpp
${CUDA_DIR}/event.hpp
${CUDA_DIR}/event.cpp
${CUDA_DIR}/kernel.hpp
${CUDA_DIR}/kernel.cpp
${CUDA_DIR}/memory.hpp
${CUDA_DIR}/memory.cpp
${CUDA_DIR}/platform.hpp
${CUDA_DIR}/platform.cpp
${CUDA_DIR}/program.hpp
${CUDA_DIR}/program.cpp
${CUDA_DIR}/queue.hpp
${CUDA_DIR}/queue.cpp
${CUDA_DIR}/sampler.hpp
${CUDA_DIR}/sampler.cpp
${CUDA_DIR}/tracing.cpp
${CUDA_DIR}/usm.cpp
${CUDA_DIR}/usm_p2p.cpp
${CUDA_DIR}/../../ur.cpp
${CUDA_DIR}/../../ur.hpp
)

set_target_properties(${TARGET_NAME} PROPERTIES
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
)

find_package(Threads REQUIRED)
find_package(CUDA 10.1 REQUIRED)

# Make imported library global to use it within the project.
add_library(cudadrv SHARED IMPORTED GLOBAL)

if (WIN32)
set_target_properties(
cudadrv PROPERTIES
IMPORTED_IMPLIB ${CUDA_CUDA_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS}
)
else()
set_target_properties(
cudadrv PROPERTIES
IMPORTED_LOCATION ${CUDA_CUDA_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS}
)
endif()

target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::unified_malloc_framework
Threads::Threads
cudadrv
)

target_include_directories(${TARGET_NAME} PRIVATE
${CUDA_DIR}/../../../
)
Loading