Skip to content

Commit

Permalink
Merge branch 'main' into umf_critnib
Browse files Browse the repository at this point in the history
  • Loading branch information
pbalcer authored Sep 1, 2023
2 parents 4d9484c + 4ce5cdd commit d2fb004
Show file tree
Hide file tree
Showing 119 changed files with 3,682 additions and 2,046 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ jobs:
- name: Generate source from spec, check for uncommitted diff
if: matrix.os == 'ubuntu-22.04'
run: cmake --build ${{github.workspace}}/build --target check-generated

- name: Verify that each source file contains a license
run: cmake --build ${{github.workspace}}/build --target verify-licenses

- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc)
Expand All @@ -95,6 +98,7 @@ jobs:
matrix:
os: ['windows-2019', 'windows-2022']
build_type: [Debug, Release]
compiler: [{c: cl.exe, cxx: cl.exe}, {c: clang-cl.exe, cxx: clang-cl.exe}]
runs-on: ${{matrix.os}}

steps:
Expand All @@ -111,6 +115,8 @@ jobs:
run: >
cmake
-B${{github.workspace}}/build
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_POLICY_DEFAULT_CMP0094=NEW
-DUR_ENABLE_TRACING=ON
-DUR_DEVELOPER_MODE=ON
Expand Down
65 changes: 40 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
project(unified-runtime VERSION 0.6.0)
project(unified-runtime VERSION 0.8.0)

include(GNUInstallDirs)
include(CheckCXXSourceCompiles)
Expand All @@ -18,24 +18,24 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()

find_package(Python3 COMPONENTS Interpreter)
find_package(Python3 COMPONENTS Interpreter REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

# Build Options
option(UR_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF)
option(UR_BUILD_TESTS "Build unit tests." ON)
option(UR_BUILD_TOOLS "build ur tools" ON)
option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF)
option(UR_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF)
option(UR_USE_ASAN "enable AddressSanitizer" OFF)
option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
option(UR_USE_MSAN "enable MemorySanitizer" OFF)
option(UR_USE_TSAN "enable ThreadSanitizer" OFF)
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
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_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -130,23 +130,15 @@ if(UR_USE_MSAN)
add_sanitizer_flag(memory)
endif()

# Allow custom third_party folder
if(NOT DEFINED THIRD_PARTY_DIR)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
endif()

find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)

set(CLANG_FORMAT_REQUIRED "15.0")
# Check if clang-format (in correct version) is available for Cpp code formatting.
if(UR_FORMAT_CPP_STYLE)
find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)

if(CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")
endif()
if(CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")

# Check if the correct version of clang-format is available
if(UR_FORMAT_CPP_STYLE)
if(CLANG_FORMAT)
set(CLANG_FORMAT_REQUIRED "15.0")
if(NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED))
message(FATAL_ERROR "required clang-format version is ${CLANG_FORMAT_REQUIRED}")
endif()
Expand All @@ -155,8 +147,9 @@ if(UR_FORMAT_CPP_STYLE)
endif()
endif()

# Obtain files for clang-format
# Obtain files for clang-format and license check
set(format_glob)
set(license_glob)
foreach(dir examples include source test tools)
list(APPEND format_glob
"${dir}/*.h"
Expand All @@ -167,14 +160,36 @@ foreach(dir examples include source test tools)
"${dir}/**/*.hpp"
"${dir}/**/*.c"
"${dir}/**/*.cpp")
list(APPEND license_glob
"${dir}/*.yml"
"${dir}/**/*.yml"
"${dir}/*.py"
"${dir}/**/*.py"
"${dir}/**/CMakeLists.txt"
"${dir}/CMakeLists.txt"
)
endforeach()
file(GLOB_RECURSE format_src ${format_glob})
file(GLOB_RECURSE license_src ${license_glob})

# Add license check target
list(FILTER license_src EXCLUDE REGEX "registry.yml")
add_custom_target(verify-licenses
COMMAND ${Python3_EXECUTABLE}
"${PROJECT_SOURCE_DIR}/scripts/verify_license.py"
"--files" ${format_src} ${license_src}
COMMENT "Verify all files contain a license."
)

# Add code formatter target
add_custom_target(cppformat)
# ... and all source files to the formatter
add_cppformat(all-sources ${format_src})

# Add files to the formatter
add_cppformat(src-formatter ${format_src})
# Allow custom third_party folder
if(NOT DEFINED THIRD_PARTY_DIR)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
endif()

add_subdirectory(${THIRD_PARTY_DIR})

Expand Down Expand Up @@ -254,5 +269,5 @@ if(UR_FORMAT_CPP_STYLE)
DEPENDS generate
)
else()
message(WARNING "UR_FORMAT_CPP_STYLE not set. Targets: 'generate' and 'check-generated' and not available")
message(STATUS " UR_FORMAT_CPP_STYLE not set. Targets: 'generate' and 'check-generated' are not available")
endif()
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Weekly tags](#weekly-tags)
3. [Third-Party tools](#third-party-tools)
4. [Building](#building)
- [Requirements](#requirements)
- [Windows](#windows)
- [Linux](#linux)
- [CMake standard options](#cmake-standard-options)
Expand Down Expand Up @@ -71,9 +72,14 @@ Tools can be acquired via instructions in [third_party](/third_party/README.md).

## Building

Requirements:
### Requirements

Required packages:
- C++ compiler with C++17 support
- [CMake](https://cmake.org/) >= 3.14.0
- Python v3.6.6 or later

For development and contributions:
- clang-format-15.0 (can be installed with `python -m pip install clang-format==15.0.7`)

### Windows
Expand Down Expand Up @@ -112,6 +118,7 @@ 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_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |

### Additional make targets

Expand Down
32 changes: 25 additions & 7 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function(add_ur_target_compile_options name)
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>
)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
endif()
Expand All @@ -79,32 +78,51 @@ function(add_ur_target_compile_options name)
endif()
elseif(MSVC)
target_compile_options(${name} PRIVATE
/MP
$<$<CXX_COMPILER_ID:MSVC>:/MP> # clang-cl.exe does not support /MP
/W3
/MD$<$<CONFIG:Debug>:d>
/GS
)
add_link_options(

if(UR_DEVELOPER_MODE)
target_compile_options(${name} PRIVATE /WX /GS)
endif()
endif()
endfunction()

function(add_ur_target_link_options name)
if(NOT MSVC)
if (NOT APPLE)
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now")
endif()
elseif(MSVC)
target_link_options(${name} PRIVATE
/DYNAMICBASE
/HIGHENTROPYVA
/ALLOWISOLATION
/NXCOMPAT
)
endif()
endfunction()

if(UR_DEVELOPER_MODE)
target_compile_options(${name} PRIVATE /WX /GS)
endif()
function(add_ur_target_exec_options name)
if(MSVC)
target_link_options(${name} PRIVATE
/ALLOWISOLATION
)
endif()
endfunction()

function(add_ur_executable name)
add_executable(${name} ${ARGN})
add_ur_target_compile_options(${name})
add_ur_target_exec_options(${name})
add_ur_target_link_options(${name})
endfunction()

function(add_ur_library name)
add_library(${name} ${ARGN})
add_ur_target_compile_options(${name})
add_ur_target_link_options(${name})
endfunction()

include(FetchContent)
Expand Down
2 changes: 1 addition & 1 deletion examples/collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ mkdir build
$ cd build
$ cmake .. -DUR_ENABLE_TRACING=ON
$ make
$ UR_ADAPTERS_FORCE_LOAD=./lib/libur_adapter_null.so XPTI_TRACE_ENABLE=1 XPTI_FRAMEWORK_DISPATCHER=./lib/libxptifw.so XPTI_SUBSCRIBERS=./lib/libcollector.so ./bin/hello_world
$ UR_ADAPTERS_FORCE_LOAD=./lib/libur_adapter_null.so UR_ENABLE_LAYERS=UR_LAYER_TRACING XPTI_TRACE_ENABLE=1 XPTI_FRAMEWORK_DISPATCHER=./lib/libxptifw.so XPTI_SUBSCRIBERS=./lib/libcollector.so ./bin/hello_world
```

See [XPTI framework documentation](https://github.com/intel/llvm/blob/sycl/xptifw/doc/XPTI_Framework.md) for more information.
33 changes: 21 additions & 12 deletions examples/collector/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,41 @@ constexpr uint16_t TRACE_FN_END =
constexpr std::string_view UR_STREAM_NAME = "ur";

/**
* @brief Formats the function parameters and arguments for urInit
* @brief Formats the function parameters and arguments for urAdapterGet
*/
std::ostream &operator<<(std::ostream &os,
const struct ur_init_params_t *params) {
os << ".device_flags = ";
if (*params->pdevice_flags & UR_DEVICE_INIT_FLAG_GPU) {
os << "UR_DEVICE_INIT_FLAG_GPU";
} else {
os << "0";
const struct ur_adapter_get_params_t *params) {
os << ".NumEntries = ";
os << *params->pNumEntries;
os << ", ";
os << ".phAdapters = ";
os << *params->pphAdapters;
if (*params->pphAdapters) {
os << " (" << **params->pphAdapters << ")";
}
os << ", ";
os << ".pNumAdapters = ";
os << *params->ppNumAdapters;
if (*params->ppNumAdapters) {
os << " (" << **params->ppNumAdapters << ")";
}
os << "";
return os;
}

/**
* A map of functions that format the parameters and arguments for each UR function.
* This example only implements a handler for one function, `urInit`, but it's
* This example only implements a handler for one function, `urAdapterGet`, but it's
* trivial to expand it to support more.
*/
static std::unordered_map<
std::string_view,
std::function<void(const xpti::function_with_args_t *, std::ostream &)>>
handlers = {{"urInit", [](const xpti::function_with_args_t *fn_args,
std::ostream &os) {
auto params = static_cast<const struct ur_init_params_t *>(
fn_args->args_data);
handlers = {{"urAdapterGet", [](const xpti::function_with_args_t *fn_args,
std::ostream &os) {
auto params =
static_cast<const struct ur_adapter_get_params_t *>(
fn_args->args_data);
os << params;
}}};

Expand Down
7 changes: 4 additions & 3 deletions examples/hello_world/hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ int main(int argc, char *argv[]) {
ur_result_t status;

// Initialize the platform
status = urInit(0, nullptr);
status = urLoaderInit(0, nullptr);
if (status != UR_RESULT_SUCCESS) {
std::cout << "urInit failed with return code: " << status << std::endl;
std::cout << "urLoaderInit failed with return code: " << status
<< std::endl;
return 1;
}
std::cout << "Platform initialized.\n";
Expand Down Expand Up @@ -119,6 +120,6 @@ int main(int argc, char *argv[]) {
for (auto adapter : adapters) {
urAdapterRelease(adapter);
}
urTearDown(nullptr);
urLoaderTearDown();
return status == UR_RESULT_SUCCESS ? 0 : 1;
}
Loading

0 comments on commit d2fb004

Please sign in to comment.