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

Static L0 Loader Support #224

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
160 changes: 160 additions & 0 deletions .github/workflows/build-multi-static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

permissions: read-all

defaults:
run:
shell: bash

jobs:
config:
if: github.repository_owner == 'oneapi-src'
runs-on: ubuntu-latest
outputs:
short-sha: ${{ steps.const.outputs.short-sha }}
ref-slug: ${{ steps.const.outputs.ref-slug }}
steps:
- uses: actions/checkout@v4
with:
clean: true
ref: ${{ github.event.pull_request.head.sha }}
- name: Set constants
id: const
run: |
cat >> ${GITHUB_OUTPUT} <<EOF
short-sha=$(git rev-parse --short=7 ${GITHUB_SHA})
ref-slug=$(echo ${{ github.ref_name }} | tr '/_' '-')
EOF

build:
# Notes on formatting:
#
# GitHub Actions expressions ${{ ... }} are used wherever possible so the
# evaluation results are plainly visible in the web console.
#
# Note the mixed spaces and tabs in the heredocs, see the bash man page
# entry for <<- in the Here Documents section. This allows generated code to
# be indented for readability in the workflow output.
if: github.repository_owner == 'oneapi-src'
needs: [config]
runs-on: ${{ matrix.os.name == 'windows' && 'windows-latest' || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
os: [
{name: ubuntu, vmaj: 20, vmin: '04'},
{name: ubuntu, vmaj: 22, vmin: '04'},
{name: ubuntu, vmaj: 24, vmin: '04'},
{name: ubuntu, vmaj: 24, vmin: '10'},
{name: sles, vmaj: 15, vmin: 2},
{name: sles, vmaj: 15, vmin: 3},
{name: sles, vmaj: 15, vmin: 4},
{name: rhel, vmaj: 8, vmin: 6},
{name: windows}
]
target: [install, package]
arch: ['']
include: [
{os: {name: ubuntu, vmaj: 20, vmin: '04'}, target: install, arch: arm64},
{os: {name: ubuntu, vmaj: 20, vmin: '04'}, target: package, arch: arm64}
]
env:
MSYS_NO_PATHCONV: 1
MOUNT_TARGET: ${{ matrix.os.name == 'windows' && 'C:/project' || '/project' }}
# -j breaks the Visual Studio configuration selection
PARALLEL: ${{ ! (matrix.os.name == 'windows') && '-j' || '' }}
ARCH_SUFFIX: ${{ matrix.arch != '' && format('_{0}', matrix.arch) || '' }}
steps:
- name: Set constants
id: const
env:
OS_STRING: >-
${{ matrix.os.name == 'windows' && 'windows' ||
format('{0}-{1}.{2}',
matrix.os.name,
matrix.os.vmaj,
matrix.os.vmin
)
}}
CCACHE_DIR: ${{ github.workspace }}/ccache
run: |
cat >> ${GITHUB_OUTPUT} <<EOF
os-string=${OS_STRING}
image-name=ghcr.io/${{ github.repository }}/${OS_STRING}
ccache-dir=${CCACHE_DIR}
EOF
- uses: actions/checkout@v4
with:
clean: true
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Create Ccache directory
run: mkdir -p '${{ steps.const.outputs.ccache-dir }}'
- name: Ccache
uses: actions/cache@v4
with:
path: ${{ steps.const.outputs.ccache-dir }}
key: ccache-${{ github.job }}-${{ steps.const.outputs.os-string }}${{ env.ARCH_SUFFIX }}-${{ matrix.target }}-${{ github.sha }}
restore-keys: ccache-${{ github.job }}-${{ steps.const.outputs.os-string }}${{ env.ARCH_SUFFIX }}-${{ matrix.target }}-
- name: Compute image name
run: echo "DOCKER_IMAGE=localhost/${{ github.repository }}/${{ steps.const.outputs.os-string }}" >> ${GITHUB_ENV}
- name: "Registry login: ghcr.io"
run: |
echo ${{ secrets.GITHUB_TOKEN }} |
docker login -u sys-lzdev --password-stdin ghcr.io
- name: Build image
run: |
docker info
docker build \
${{ runner.os == 'Windows' && ' \
--memory 16G ' || ' '
}}\
${{ matrix.os.vmaj != '' && format(' \
--build-arg VMAJ={0} \
--build-arg VMIN={1} ', matrix.os.vmaj, matrix.os.vmin) || ' '
}}\
--pull \
--tag ${DOCKER_IMAGE}:${{ needs.config.outputs.ref-slug }} \
- < .github/docker/${{ matrix.os.name }}.Dockerfile
- name: Build
id: build
run: |
mkdir build
docker run \
--rm \
--interactive \
-v '${{ github.workspace }}':${MOUNT_TARGET} \
-w ${MOUNT_TARGET}/build \
-e CCACHE_BASEDIR=${MOUNT_TARGET} \
-e CCACHE_DIR=${MOUNT_TARGET}/ccache \
-v '${{ steps.const.outputs.ccache-dir }}':${MOUNT_TARGET}/ccache \
${DOCKER_IMAGE}:${{ needs.config.outputs.ref-slug }} \
bash -e -x <<-EOF

cmake \
${{ matrix.os.name != 'windows' && ' \
-G Ninja ' || ' '
}}\
${{ matrix.arch == 'arm64' && ' \
-D CMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-D CMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
-D CMAKE_SYSTEM_PROCESSOR=aarch64 ' || ' '
}}\
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_STATIC=1 \
-D CMAKE_INSTALL_PREFIX=${{ matrix.target == 'install' && '../level-zero-install' || matrix.target == 'package' && '/usr' || '' }} \
-D CPACK_OUTPUT_FILE_PREFIX=${MOUNT_TARGET}/level-zero-package \
..

cmake --build . ${PARALLEL} --target ${{ matrix.target }} ${{ matrix.os.name == 'windows' && '--config Release' || '' }}

ccache --show-stats

EOF
49 changes: 49 additions & 0 deletions .github/workflows/build-quick-static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

permissions: read-all

jobs:
build-linux:
if: github.repository_owner == 'oneapi-src'
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: hendrikmuhs/ccache-action@v1
- name: Build Loader on Latest Ubuntu
run: |
mkdir build
cd build
cmake \
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_L0_LOADER_TESTS=1 \
..
make -j$(nproc)
- env:
ZE_ENABLE_LOADER_DEBUG_TRACE: '1'
ZEL_LIBRARY_PATH: '${{ github.workspace }}/build/lib'
working-directory: build
run: ctest -V

build-windows:
if: github.repository_owner == 'oneapi-src'
runs-on: [windows-latest]
steps:
- uses: actions/checkout@v3
- name: Build Loader on Latest Windows
run: |
mkdir build
cd build
cmake -D BUILD_L0_LOADER_TESTS=1 -D BUILD_STATIC=1 ..
cmake --build . --config Release
- env:
ZE_ENABLE_LOADER_DEBUG_TRACE: '1'
ZEL_LIBRARY_PATH: '${{ github.workspace }}/build/bin/Release'
working-directory: build
run: ctest -C Release -V
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ endif()
include(FetchContent)

if(BUILD_L0_LOADER_TESTS)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest_main)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
if(MSVC)
if (BUILD_STATIC)
set(gtest_force_shared_crt OFF CACHE BOOL "" FORCE)
else()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
endif()

FetchContent_MakeAvailable(googletest)

Expand Down
21 changes: 16 additions & 5 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@ configure_file(
@ONLY)

include(GNUInstallDirs)
add_library(${TARGET_LOADER_NAME}
SHARED
""
${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc
)
if (BUILD_STATIC)
message(STATUS "Building loader as static library")
add_library(${TARGET_LOADER_NAME}
STATIC
""
${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc
)
add_definitions(-DDYNAMIC_LOAD_LOADER="1")
else()
message(STATUS "Building loader as dynamic library")
add_library(${TARGET_LOADER_NAME}
SHARED
""
${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc
)
endif()

add_subdirectory(lib)
add_subdirectory(loader)
Expand Down
12 changes: 6 additions & 6 deletions source/lib/linux/lib_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace ze_lib
{

#ifndef DYNAMIC_LOAD_LOADER
void __attribute__((constructor)) createLibContext() {
context = new context_t;
}

void __attribute__((destructor)) deleteLibContext() {
delete context;
}
}
void __attribute__((destructor)) deleteLibContext() {
delete context;
}
#endif

}
11 changes: 1 addition & 10 deletions source/lib/windows/lib_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@

namespace ze_lib
{
#ifdef DYNAMIC_LOAD_LOADER
export "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_DETACH) {
delete context;
} else if (fdwReason == DLL_PROCESS_ATTACH) {
context = new context_t;
}
return TRUE;
}
#else
#ifndef DYNAMIC_LOAD_LOADER
extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_DETACH) {
delete context;
Expand Down
Loading
Loading