Skip to content

Commit 2d30aad

Browse files
committed
Merge branch 'sycl' into simplify-device-global
2 parents 5776187 + 0c0c783 commit 2d30aad

File tree

243 files changed

+13719
-3775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+13719
-3775
lines changed

.github/workflows/build-hw-reusable.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
-DUR_ENABLE_TRACING=ON
8383
-DUR_DEVELOPER_MODE=ON
8484
-DUR_BUILD_TESTS=ON
85+
-DUR_CONFORMANCE_TEST_LOADER=OFF
8586
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
8687
-DUR_STATIC_LOADER=${{matrix.adapter.static_Loader}}
8788
-DUR_STATIC_ADAPTER_${{matrix.adapter.name}}=${{matrix.adapter.static_adapter}}

.github/workflows/cmake.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Install apt packages
5050
run: |
5151
sudo apt-get update
52-
sudo apt-get install -y ${{matrix.compiler.c}}
52+
sudo apt-get install -y ${{matrix.compiler.c}} devscripts
5353
5454
- name: Install libhwloc
5555
run: .github/scripts/install_hwloc.sh
@@ -82,6 +82,7 @@ jobs:
8282
8383
- name: Configure CMake
8484
if: matrix.os == 'ubuntu-22.04'
85+
# WEXTRA: https://github.com/oneapi-src/unified-runtime/issues/2109
8586
run: >
8687
cmake
8788
-B${{github.workspace}}/build
@@ -91,13 +92,17 @@ jobs:
9192
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
9293
-DUR_BUILD_TESTS=ON
9394
-DUR_FORMAT_CPP_STYLE=OFF
95+
-DUR_DEVELOPER_MODE=ON
9496
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
97+
-DUR_CONFORMANCE_TEST_LOADER=OFF
9598
${{matrix.libbacktrace}}
9699
${{matrix.pool_tracking}}
97100
${{matrix.latency_tracking}}
98101
99102
- name: Configure CMake
100103
if: matrix.os == 'ubuntu-20.04'
104+
# WEXTRA: https://github.com/oneapi-src/unified-runtime/issues/2109
105+
# Note: Disable Werror, since 20.04 raises different ones than 22.04
101106
run: >
102107
cmake
103108
-B${{github.workspace}}/build
@@ -107,13 +112,19 @@ jobs:
107112
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
108113
-DUR_BUILD_TESTS=ON
109114
-DUR_FORMAT_CPP_STYLE=OFF
115+
-DUR_DEVELOPER_MODE=OFF
110116
${{matrix.libbacktrace}}
111117
${{matrix.pool_tracking}}
112118
${{matrix.latency_tracking}}
113119
114120
- name: Build
115121
run: cmake --build ${{github.workspace}}/build -j $(nproc)
116122

123+
- name: Verify hardening flags have been set
124+
run: cmake --build ${{github.workspace}}/build --target verify-hardening
125+
# https://github.com/oneapi-src/unified-runtime/issues/2120
126+
if: ${{ matrix.compiler.cxx != 'clang++' && matrix.os != 'ubuntu-20.04' }}
127+
117128
- name: Test
118129
working-directory: ${{github.workspace}}/build
119130
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "umf|loader|validation|tracing|unit|urtrace"
@@ -241,20 +252,6 @@ jobs:
241252
steps:
242253
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
243254

244-
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
245-
with:
246-
python-version: 3.9
247-
248-
- name: Install prerequisites
249-
run: python3 -m pip install -r third_party/requirements.txt
250-
251-
- name: Install doxygen
252-
run: |
253-
$WorkingDir = $PWD.Path
254-
Invoke-WebRequest -Uri https://github.com/doxygen/doxygen/releases/download/Release_1_9_8/doxygen-1.9.8.windows.x64.bin.zip -OutFile "$WorkingDir\doxygen.zip"
255-
Expand-Archive -Path "$WorkingDir\doxygen.zip"
256-
Add-Content $env:GITHUB_PATH "$WorkingDir\doxygen"
257-
258255
- name: Install hwloc
259256
run: vcpkg install hwloc:x64-windows
260257

@@ -272,7 +269,8 @@ jobs:
272269
-DUR_ENABLE_TRACING=ON
273270
-DUR_DEVELOPER_MODE=ON
274271
-DUR_BUILD_TESTS=ON
275-
-DUR_FORMAT_CPP_STYLE=ON
272+
-DUR_FORMAT_CPP_STYLE=OFF
273+
-DUR_CONFORMANCE_TEST_LOADER=OFF
276274
${{matrix.adapter.var}}
277275
278276
- name: Build all
@@ -286,7 +284,7 @@ jobs:
286284
name: Build - MacOS
287285
strategy:
288286
matrix:
289-
os: ['macos-12', 'macos-13']
287+
os: ['macos-13']
290288
runs-on: ${{matrix.os}}
291289

292290
steps:

.github/workflows/multi_device.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717
strategy:
1818
matrix:
1919
adapter: [
20-
{name: L0}
20+
{name: L0},
21+
{name: L0_V2}
2122
]
2223
build_type: [Debug, Release]
2324
compiler: [{c: gcc, cxx: g++}] # TODO: investigate why memory-adapter-level_zero hangs with clang
@@ -47,6 +48,7 @@ jobs:
4748
-DUR_DEVELOPER_MODE=ON
4849
-DUR_BUILD_TESTS=ON
4950
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
51+
-DUR_CONFORMANCE_TEST_LOADER=OFF
5052
-DUR_TEST_DEVICES_COUNT=2
5153
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
5254
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
@@ -61,4 +63,4 @@ jobs:
6163

6264
- name: Test adapters
6365
working-directory: ${{github.workspace}}/build
64-
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "enqueue|kernel|program|integration|exp_command_buffer|exp_enqueue_native|exp_launch_properties|exp_usm_p2p" --timeout 180
66+
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "enqueue|kernel|integration|exp_command_buffer|exp_enqueue_native|exp_launch_properties|exp_usm_p2p" --timeout 180

.github/workflows/source-checks.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,59 @@ permissions:
1212
jobs:
1313
source-checks:
1414
name: Source Checks
15-
# TODO: Make this run on Windows (#888)
16-
runs-on: 'ubuntu-22.04'
15+
strategy:
16+
matrix:
17+
os: ['ubuntu-22.04', 'windows-2022']
18+
19+
runs-on: ${{matrix.os}}
1720

1821
steps:
1922
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2023

21-
- name: Install apt packages
24+
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
25+
with:
26+
python-version: 3.9
27+
28+
- name: Install pip packages
29+
run: pip install -r third_party/requirements.txt
30+
31+
- name: "[Lin] Install doxygen"
32+
if: matrix.os == 'ubuntu-22.04'
2233
run: |
2334
sudo apt-get update
2435
sudo apt-get install -y doxygen
2536
26-
- name: Setup PATH
27-
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
28-
29-
- name: Install pip packages
30-
run: pip install -r third_party/requirements.txt
37+
- name: "[Win] Install doxygen"
38+
if: matrix.os == 'windows-2022'
39+
run: |
40+
$WorkingDir = $PWD.Path
41+
Invoke-WebRequest -Uri https://github.com/doxygen/doxygen/releases/download/Release_1_9_8/doxygen-1.9.8.windows.x64.bin.zip -OutFile "$WorkingDir\doxygen.zip"
42+
Expand-Archive -Path "$WorkingDir\doxygen.zip"
43+
Add-Content $env:GITHUB_PATH "$WorkingDir\doxygen"
3144
32-
# Required for CMake
33-
- name: Install libhwloc
45+
- name: "[Lin] Install hwloc"
46+
if: matrix.os == 'ubuntu-22.04'
3447
run: .github/scripts/install_hwloc.sh
3548

49+
- name: "[Win] Install hwloc"
50+
if: matrix.os == 'windows-2022'
51+
run: vcpkg install hwloc:x64-windows
52+
3653
- name: Configure CMake
54+
env:
55+
VCPKG_PATH: "C:/vcpkg/packages/hwloc_x64-windows"
3756
run: >
3857
cmake
3958
-B${{github.workspace}}/build
59+
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
4060
-DUR_ENABLE_TRACING=OFF
4161
-DCMAKE_BUILD_TYPE=Debug
4262
-DUR_BUILD_TESTS=OFF
4363
-DUR_FORMAT_CPP_STYLE=ON
4464
65+
# Verifying license should be enough on a single OS
4566
- name: Verify that each source file contains a license
67+
if: matrix.os == 'ubuntu-22.04'
4668
run: cmake --build ${{github.workspace}}/build --target verify-licenses
4769

4870
- name: Generate source from spec, check for uncommitted diff

CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ option(UR_BUILD_EXAMPLES "Build example applications." ON)
3434
option(UR_BUILD_TESTS "Build unit tests." ON)
3535
option(UR_BUILD_TOOLS "build ur tools" ON)
3636
option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF)
37-
option(UR_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF)
37+
option(UR_DEVELOPER_MODE "treats warnings as errors" OFF)
3838
option(UR_ENABLE_FAST_SPEC_MODE "enable fast specification generation mode" OFF)
3939
option(UR_USE_ASAN "enable AddressSanitizer" OFF)
4040
option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
@@ -68,6 +68,7 @@ set(UR_CONFORMANCE_TARGET_TRIPLES "" CACHE STRING
6868
"List of sycl targets to build CTS device binaries for")
6969
set(UR_CONFORMANCE_AMD_ARCH "" CACHE STRING "AMD device target ID to build CTS binaries for")
7070
option(UR_CONFORMANCE_ENABLE_MATCH_FILES "Enable CTS match files" ON)
71+
option(UR_CONFORMANCE_TEST_LOADER "Also test the loader in the conformance tests" OFF)
7172
set(UR_ADAPTER_LEVEL_ZERO_SOURCE_DIR "" CACHE PATH
7273
"Path to external 'level_zero' adapter source dir")
7374
set(UR_ADAPTER_OPENCL_SOURCE_DIR "" CACHE PATH
@@ -161,6 +162,12 @@ if(UR_ENABLE_TRACING)
161162
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
162163
)
163164

165+
if (NOT MSVC)
166+
# Hardening flags cause issues on Windows
167+
add_ur_target_compile_options(xptifw)
168+
add_ur_target_link_options(xptifw)
169+
endif()
170+
164171
if (UR_STATIC_LOADER)
165172
install(TARGETS xpti xptifw
166173
EXPORT ${PROJECT_NAME}-targets
@@ -218,6 +225,14 @@ if(UR_USE_MSAN)
218225
add_sanitizer_flag(memory)
219226
endif()
220227

228+
if(NOT (UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP
229+
OR UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_OPENCL
230+
OR UR_BUILD_ADAPTER_NATIVE_CPU OR UR_BUILD_ADAPTER_L0_V2
231+
OR UR_BUILD_ADAPTER_ALL))
232+
message(WARNING "No adapters have been enabled; conformance tests will not be ran")
233+
message(STATUS "Consider setting UR_BUILD_ADAPTER_*")
234+
endif()
235+
221236
# Check if clang-format (in correct version) is available for Cpp code formatting.
222237
if(UR_FORMAT_CPP_STYLE)
223238
find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)
@@ -269,6 +284,13 @@ add_custom_target(verify-licenses
269284
COMMENT "Verify all files contain a license."
270285
)
271286

287+
# Add hardening check
288+
add_custom_target(verify-hardening
289+
COMMAND "${PROJECT_SOURCE_DIR}/scripts/check-hardening.sh"
290+
${CMAKE_BINARY_DIR}
291+
COMMENT "Check hardening settings on built binaries and libraries"
292+
)
293+
272294
# Add code formatter target
273295
add_custom_target(cppformat)
274296
# ... and all source files to the formatter

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ List of options provided by CMake:
122122
| UR_BUILD_TESTS | Build the tests | ON/OFF | ON |
123123
| UR_BUILD_TOOLS | Build tools | ON/OFF | ON |
124124
| UR_FORMAT_CPP_STYLE | Format code style | ON/OFF | OFF |
125-
| UR_DEVELOPER_MODE | Treat warnings as errors and enables additional checks | ON/OFF | OFF |
125+
| UR_DEVELOPER_MODE | Treat warnings as errors | ON/OFF | OFF |
126126
| UR_ENABLE_FAST_SPEC_MODE | Enable fast specification generation mode | ON/OFF | OFF |
127127
| UR_USE_ASAN | Enable AddressSanitizer | ON/OFF | OFF |
128128
| UR_USE_TSAN | Enable ThreadSanitizer | ON/OFF | OFF |
@@ -133,6 +133,7 @@ List of options provided by CMake:
133133
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
134134
| UR_CONFORMANCE_AMD_ARCH | AMD device target ID to build CTS binaries for | string | `""` |
135135
| UR_CONFORMANCE_ENABLE_MATCH_FILES | Enable CTS match files | ON/OFF | ON |
136+
| UR_CONFORMANCE_TEST_LOADER | Additionally build and run "loader" tests for the CTS | ON/OFF | OFF |
136137
| UR_BUILD_ADAPTER_L0 | Build the Level-Zero adapter | ON/OFF | OFF |
137138
| UR_BUILD_ADAPTER_OPENCL | Build the OpenCL adapter | ON/OFF | OFF |
138139
| UR_BUILD_ADAPTER_CUDA | Build the CUDA adapter | ON/OFF | OFF |
@@ -154,6 +155,13 @@ List of options provided by CMake:
154155

155156
### Additional make targets
156157

158+
To run tests, do the following:
159+
160+
```bash
161+
$ make
162+
$ make test
163+
```
164+
157165
To run automated code formatting, configure CMake with `UR_FORMAT_CPP_STYLE` option
158166
and then run a custom `cppformat` target:
159167

cmake/helpers.cmake

Lines changed: 40 additions & 16 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
@@ -28,13 +28,14 @@ function(add_cppformat name)
2828
if(${ARGC} EQUAL 0)
2929
return()
3030
else()
31+
# Split args into 2 parts (in Windows the list is probably too long)
32+
list(SUBLIST ARGN 0 250 selected_files_1)
33+
list(SUBLIST ARGN 251 -1 selected_files_2)
3134
add_custom_target(cppformat-${name}
32-
COMMAND ${CLANG_FORMAT}
33-
--style=file
34-
--i
35-
${ARGN}
35+
COMMAND ${CLANG_FORMAT} --style=file --i ${selected_files_1}
36+
COMMAND ${CLANG_FORMAT} --style=file --i ${selected_files_2}
3637
COMMENT "Format CXX source files"
37-
)
38+
)
3839
endif()
3940

4041
add_dependencies(cppformat cppformat-${name})
@@ -57,28 +58,43 @@ macro(add_sanitizer_flag flag)
5758
set(CMAKE_REQUIRED_LIBRARIES ${SAVED_CMAKE_REQUIRED_LIBRARIES})
5859
endmacro()
5960

61+
check_cxx_compiler_flag("-fcf-protection=full" CXX_HAS_FCF_PROTECTION_FULL)
62+
6063
function(add_ur_target_compile_options name)
6164
if(NOT MSVC)
65+
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
6266
target_compile_options(${name} PRIVATE
63-
-fPIC
67+
# Warning options
6468
-Wall
6569
-Wpedantic
6670
-Wempty-body
71+
-Wformat
72+
-Wformat-security
6773
-Wunused-parameter
74+
75+
# Hardening options
76+
-fPIC
77+
-fstack-protector-strong
78+
-fvisibility=hidden # Required for -fsanitize=cfi
79+
# -fsanitize=cfi requires -flto, which breaks a lot of things
80+
# See: https://github.com/oneapi-src/unified-runtime/issues/2120
81+
# -flto
82+
# $<$<CXX_COMPILER_ID:Clang,AppleClang>:-fsanitize=cfi>
83+
$<$<BOOL:${CXX_HAS_FCF_PROTECTION_FULL}>:-fcf-protection=full>
84+
# -fstack-clash-protection is not supported in apple clang or GCC < 8
85+
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,8>>:-fstack-clash-protection>
86+
$<$<CXX_COMPILER_ID:Clang>:-fstack-clash-protection>
87+
88+
# Colored output
6889
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
6990
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>
7091
)
92+
if (UR_DEVELOPER_MODE)
93+
target_compile_options(${name} PRIVATE -Werror -Wextra)
94+
endif()
7195
if (CMAKE_BUILD_TYPE STREQUAL "Release")
72-
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
7396
target_compile_options(${name} PRIVATE -fvisibility=hidden)
7497
endif()
75-
if(UR_DEVELOPER_MODE)
76-
target_compile_options(${name} PRIVATE
77-
-Werror
78-
-fno-omit-frame-pointer
79-
-fstack-protector-strong
80-
)
81-
endif()
8298
elseif(MSVC)
8399
target_compile_options(${name} PRIVATE
84100
$<$<CXX_COMPILER_ID:MSVC>:/MP> # clang-cl.exe does not support /MP
@@ -102,7 +118,15 @@ endfunction()
102118
function(add_ur_target_link_options name)
103119
if(NOT MSVC)
104120
if (NOT APPLE)
105-
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now")
121+
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now,-z,noexecstack")
122+
if (UR_DEVELOPER_MODE)
123+
target_link_options(${name} PRIVATE -Werror -Wextra)
124+
endif()
125+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
126+
target_link_options(${name} PRIVATE
127+
$<$<CXX_COMPILER_ID:GNU>:-pie>
128+
)
129+
endif()
106130
endif()
107131
elseif(MSVC)
108132
target_link_options(${name} PRIVATE

0 commit comments

Comments
 (0)