Skip to content

Commit 78e2ae5

Browse files
authored
Merge pull request #1875 from kswiecicki/static-linking-loader
Add option to build loader as a static library
2 parents d3b42cd + ce8bb9a commit 78e2ae5

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
required: false
1212
type: string
1313
default: ""
14+
static_loader:
15+
required: false
16+
type: string
17+
default: OFF
1418

1519
permissions:
1620
contents: read
@@ -29,14 +33,19 @@ jobs:
2933
strategy:
3034
matrix:
3135
adapter: [
32-
{name: "${{inputs.name}}", platform: "${{inputs.platform}}"},
36+
{name: "${{inputs.name}}", platform: "${{inputs.platform}}", static_Loader: "${{inputs.static_loader}}"},
3337
]
3438
build_type: [Debug, Release]
3539
compiler: [{c: gcc, cxx: g++}, {c: clang, cxx: clang++}]
3640
# TODO: The latest L0 loader segfaults when built with clang.
3741
exclude:
3842
- adapter: {name: L0, platform: ""}
3943
compiler: {c: clang, cxx: clang++}
44+
# Exclude these configurations to avoid overloading the runners.
45+
- adapter: {static_Loader: ON}
46+
build_type: Release
47+
- adapter: {static_Loader: ON}
48+
compiler: {c: clang, cxx: clang++}
4049

4150
runs-on: ${{matrix.adapter.name}}
4251

@@ -63,6 +72,7 @@ jobs:
6372
-DUR_DEVELOPER_MODE=ON
6473
-DUR_BUILD_TESTS=ON
6574
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
75+
-DUR_STATIC_LOADER=${{matrix.adapter.static_Loader}}
6676
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
6777
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
6878
${{ matrix.adapter.name == 'HIP' && '-DUR_CONFORMANCE_AMD_ARCH=gfx1030' || '' }}

.github/workflows/cmake.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,20 @@ jobs:
121121
uses: ./.github/workflows/build-fuzz-reusable.yml
122122
with:
123123
test_label: "fuzz-short"
124-
124+
125125
level-zero:
126126
name: Level Zero
127127
uses: ./.github/workflows/build-hw-reusable.yml
128128
with:
129129
name: L0
130130

131+
level-zero-static:
132+
name: Level Zero static
133+
uses: ./.github/workflows/build-hw-reusable.yml
134+
with:
135+
name: L0
136+
static_loader: ON
137+
131138
opencl:
132139
name: OpenCL
133140
uses: ./.github/workflows/build-hw-reusable.yml

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
4949
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
5050
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
5151
option(UR_BUILD_XPTI_LIBS "Build the XPTI libraries when tracing is enabled" ON)
52+
option(UR_STATIC_LOADER "Build loader as a static library" OFF)
5253
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")
5354
set(UR_DPCXX_BUILD_FLAGS "" CACHE STRING "Build flags to pass to DPC++ when compiling device programs")
5455
set(UR_SYCL_LIBRARY_DIR "" CACHE PATH
@@ -134,6 +135,15 @@ if(UR_ENABLE_TRACING)
134135
set_target_properties(xptifw PROPERTIES
135136
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
136137
)
138+
139+
if (UR_STATIC_LOADER)
140+
install(TARGETS xpti xptifw
141+
EXPORT ${PROJECT_NAME}-targets
142+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
143+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
144+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
145+
)
146+
endif()
137147
endif()
138148

139149
if (MSVC)
@@ -179,7 +189,7 @@ endif()
179189
if(UR_FORMAT_CPP_STYLE)
180190
find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)
181191

182-
if(CLANG_FORMAT)
192+
if(CLANG_FORMAT)
183193
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
184194
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")
185195

source/common/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ add_ur_library(ur_common STATIC
1212
$<$<PLATFORM_ID:Windows>:windows/ur_lib_loader.cpp>
1313
$<$<PLATFORM_ID:Linux,Darwin>:linux/ur_lib_loader.cpp>
1414
)
15+
1516
add_library(${PROJECT_NAME}::common ALIAS ur_common)
1617

1718
target_include_directories(ur_common PUBLIC
18-
${CMAKE_CURRENT_SOURCE_DIR}
19-
${CMAKE_SOURCE_DIR}/include
19+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
20+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
2021
)
2122

2223
message(STATUS "Download Unified Memory Framework from github.com")
@@ -62,3 +63,10 @@ if (UNIX)
6263
find_package(Threads REQUIRED)
6364
target_link_libraries(ur_common PUBLIC Threads::Threads)
6465
endif()
66+
67+
install(TARGETS ur_common
68+
EXPORT ${PROJECT_NAME}-targets
69+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
70+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
71+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
72+
)

source/loader/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ configure_file(
99
@ONLY
1010
)
1111

12+
set(LOADER_LIB_TYPE SHARED)
13+
if(UR_STATIC_LOADER)
14+
set(LOADER_LIB_TYPE STATIC)
15+
endif()
16+
1217
add_ur_library(ur_loader
13-
SHARED
18+
${LOADER_LIB_TYPE}
1419
""
1520
${CMAKE_CURRENT_BINARY_DIR}/UrLoaderVersion.rc
1621
)
1722

1823
if (MSVC)
1924
set(TARGET_LIBNAME ur_loader)
2025
string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME)
21-
26+
2227
set(LOADER_VERSION_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/ur_loader.def)
2328
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader.def.in ${LOADER_VERSION_SCRIPT} @ONLY)
2429
set_target_properties(ur_loader PROPERTIES

0 commit comments

Comments
 (0)