Skip to content

Commit

Permalink
Merge pull request #1430 from igchor/umf_dynamic_linking
Browse files Browse the repository at this point in the history
Bump UMF version and switch to dynamic linking
  • Loading branch information
pbalcer committed Jul 25, 2024
2 parents e8c9f3d + 0a259f3 commit 3d8fe8d
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .github/docker/ubuntu-22.04.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ARG BASE_DEPS="\
ARG UR_DEPS="\
doxygen \
python3 \
python3-pip"
python3-pip \
libhwloc-dev"

# Unified Runtime's dependencies (installed via pip)
ARG UR_PYTHON_DEPS="\
Expand Down
18 changes: 18 additions & 0 deletions .github/scripts/install_hwloc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# Copyright (C) 2024 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

# install_hwloc.sh - Script for building and installing HWLOC library from source code

set -e

git clone -b hwloc-2.3.0 https://github.com/open-mpi/hwloc.git
pushd hwloc
./autogen.sh
./configure
make -j$(nproc)
sudo make install -j$(nproc)
popd
12 changes: 12 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
sudo apt-get update
sudo apt-get install -y doxygen ${{matrix.compiler.c}}
- name: Install libhwloc
run: .github/scripts/install_hwloc.sh

- name: Install g++-7
if: matrix.compiler.cxx == 'g++-7'
run: |
Expand Down Expand Up @@ -224,11 +227,17 @@ jobs:
Expand-Archive -Path "$WorkingDir\doxygen.zip"
Add-Content $env:GITHUB_PATH "$WorkingDir\doxygen"
- name: Install hwloc
run: vcpkg install hwloc:x64-windows

- name: Configure CMake
env:
VCPKG_PATH: "C:/vcpkg/packages/hwloc_x64-windows"
run: >
cmake
-B${{github.workspace}}/build
${{matrix.toolset}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_POLICY_DEFAULT_CMP0094=NEW
Expand Down Expand Up @@ -267,6 +276,9 @@ jobs:
- name: Install prerequisites
run: python3 -m pip install -r third_party/requirements.txt

- name: Install hwloc
run: brew install hwloc

- name: Configure CMake
run: >
cmake
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
- name: Install pip packages
run: pip install -r third_party/requirements.txt

- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y libhwloc-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON -DUMF_ENABLE_POOL_TRACKING=ON

Expand Down Expand Up @@ -61,8 +66,13 @@ jobs:
- name: Install pip packages
run: python3 -m pip install -r third_party/requirements.txt

- name: Install hwloc
run: vcpkg install hwloc:x64-windows

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_POLICY_DEFAULT_CMP0094=NEW -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON -DUMF_ENABLE_POOL_TRACKING=ON
env:
VCPKG_PATH: "C:/vcpkg/packages/hwloc_x64-windows"
run: cmake -B ${{github.workspace}}/build -DCMAKE_POLICY_DEFAULT_CMP0094=NEW -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON -DUMF_ENABLE_POOL_TRACKING=ON -DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"

- name: Build
run: cmake --build ${{github.workspace}}/build -j $(nproc) --config Release
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
- name: Install pip packages
run: pip install -r third_party/requirements.txt

- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y libhwloc-dev
- name: Configure CMake
run: >
cmake
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ option(UR_USE_MSAN "enable MemorySanitizer" OFF)
option(UR_USE_TSAN "enable ThreadSanitizer" OFF)
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
option(UR_ENABLE_SANITIZER "enable device sanitizer" ON)
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" ON)
option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" ON)
option(UR_BUILD_ADAPTER_L0 "Build the Level-Zero adapter" OFF)
option(UR_BUILD_ADAPTER_OPENCL "Build the OpenCL adapter" OFF)
Expand Down
1 change: 1 addition & 0 deletions source/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ endif()
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
Threads::Threads
cudadrv
${EXTRA_LIBS}
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,

HostMemPool =
umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host])
.second;

Expand All @@ -407,15 +407,15 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
umf::memoryProviderMakeUnique<USMDeviceMemoryProvider>(Context, Device)
.second;
DeviceMemPool = umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Device])
.second;
MemProvider =
umf::memoryProviderMakeUnique<USMSharedMemoryProvider>(Context, Device)
.second;
SharedMemPool = umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Shared])
.second;
Expand Down
6 changes: 6 additions & 0 deletions source/adapters/cuda/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class USMMemoryProvider {
umf_result_t purge_force(void *, size_t) {
return UMF_RESULT_ERROR_NOT_SUPPORTED;
};
umf_result_t allocation_merge(void *, void *, size_t) {
return UMF_RESULT_ERROR_UNKNOWN;
}
umf_result_t allocation_split(void *, size_t, size_t) {
return UMF_RESULT_ERROR_UNKNOWN;
}
virtual const char *get_name() = 0;

virtual ~USMMemoryProvider() = default;
Expand Down
2 changes: 2 additions & 0 deletions source/adapters/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ if("${UR_HIP_PLATFORM}" STREQUAL "AMD")
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
rocmdrv
)

Expand Down Expand Up @@ -174,6 +175,7 @@ elseif("${UR_HIP_PLATFORM}" STREQUAL "NVIDIA")
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
Threads::Threads
cudadrv
cudart
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/hip/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,

HostMemPool =
umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host])
.second;

Expand All @@ -349,7 +349,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
umf::memoryProviderMakeUnique<USMDeviceMemoryProvider>(Context, Device)
.second;
DeviceMemPool = umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Device])
.second;
Expand All @@ -358,7 +358,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
umf::memoryProviderMakeUnique<USMSharedMemoryProvider>(Context, Device)
.second;
SharedMemPool = umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Shared])
.second;
Expand Down
6 changes: 6 additions & 0 deletions source/adapters/hip/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class USMMemoryProvider {
umf_result_t purge_force(void *, size_t) {
return UMF_RESULT_ERROR_NOT_SUPPORTED;
};
umf_result_t allocation_merge(void *, void *, size_t) {
return UMF_RESULT_ERROR_UNKNOWN;
}
umf_result_t allocation_split(void *, size_t, size_t) {
return UMF_RESULT_ERROR_UNKNOWN;
}
virtual const char *get_name() = 0;

virtual ~USMMemoryProvider() = default;
Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ endif()
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
LevelZeroLoader
LevelZeroLoader-Headers
)
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ ur_result_t ur_context_handle_t_::initialize() {
DeviceMemPools.emplace(
std::piecewise_construct, std::make_tuple(Device->ZeDevice),
std::make_tuple(umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::Device])
.second));
Expand All @@ -206,7 +206,7 @@ ur_result_t ur_context_handle_t_::initialize() {
SharedMemPools.emplace(
std::piecewise_construct, std::make_tuple(Device->ZeDevice),
std::make_tuple(umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::Shared])
.second));
Expand All @@ -218,7 +218,7 @@ ur_result_t ur_context_handle_t_::initialize() {
std::piecewise_construct, std::make_tuple(Device->ZeDevice),
std::make_tuple(
umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance
.Configs[usm::DisjointPoolMemType::SharedReadOnly])
.second));
Expand Down Expand Up @@ -271,7 +271,7 @@ ur_result_t ur_context_handle_t_::initialize() {
.second;
HostMemPool =
umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&DisjointPoolConfigInstance.Configs[usm::DisjointPoolMemType::Host])
.second;

Expand Down
8 changes: 4 additions & 4 deletions source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,

HostMemPool =
umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs.Configs[usm::DisjointPoolMemType::Host])
.second;

Expand All @@ -838,7 +838,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
DeviceMemPools.emplace(
std::piecewise_construct, std::make_tuple(device),
std::make_tuple(umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Device])
.second));
Expand All @@ -849,7 +849,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
SharedMemPools.emplace(
std::piecewise_construct, std::make_tuple(device),
std::make_tuple(umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::Shared])
.second));
Expand All @@ -861,7 +861,7 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
std::piecewise_construct, std::make_tuple(device),
std::make_tuple(
umf::poolMakeUniqueFromOps(
&UMF_DISJOINT_POOL_OPS, std::move(MemProvider),
umfDisjointPoolOps(), std::move(MemProvider),
&this->DisjointPoolConfigs
.Configs[usm::DisjointPoolMemType::SharedReadOnly])
.second));
Expand Down
6 changes: 6 additions & 0 deletions source/adapters/level_zero/usm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class USMMemoryProviderBase {
virtual umf_result_t purge_force(void *, size_t) {
return UMF_RESULT_ERROR_NOT_SUPPORTED;
};
umf_result_t allocation_merge(void *, void *, size_t) {
return UMF_RESULT_ERROR_UNKNOWN;
}
umf_result_t allocation_split(void *, size_t, size_t) {
return UMF_RESULT_ERROR_UNKNOWN;
}
virtual const char *get_name() { return ""; };
virtual ~USMMemoryProviderBase() = default;
};
Expand Down
1 change: 1 addition & 0 deletions source/adapters/native_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ find_package(Threads REQUIRED)
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
Threads::Threads
)

Expand Down
1 change: 1 addition & 0 deletions source/adapters/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ target_include_directories(${TARGET_NAME} PRIVATE
target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
Threads::Threads
${OpenCLICDLoaderLibrary}
)
36 changes: 22 additions & 14 deletions source/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

add_ur_library(ur_common STATIC
umf_helpers.hpp
umf_pools/disjoint_pool_config_parser.cpp
ur_pool_manager.hpp
ur_util.cpp
ur_util.hpp
$<$<PLATFORM_ID:Windows>:windows/ur_lib_loader.cpp>
Expand All @@ -26,8 +23,8 @@ if (NOT DEFINED UMF_REPO)
endif()

if (NOT DEFINED UMF_TAG)
# Merge pull request #119 from ldorau/Fix_arena_extent_split_and_arena_extent_merge
set(UMF_TAG 9bf7a0dc4dff76844e10edbb5c6e9d917536ef6d)
# Merge pull request #637 from kswiecicki/fix-dpool-poison-macro
set(UMF_TAG 1c34aae4c804e133c1273f30b1d6441ebb766f2f)
endif()

message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}")
Expand All @@ -38,21 +35,17 @@ FetchContent_Declare(unified-memory-framework
GIT_TAG ${UMF_TAG}
)

if(UR_BUILD_TESTS)
set(UMF_BUILD_TESTS ON CACHE INTERNAL "Build UMF tests")
else()
set(UMF_BUILD_TESTS OFF CACHE INTERNAL "Build UMF tests")
endif()
set(UMF_BUILD_TESTS OFF CACHE INTERNAL "Build UMF tests")
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "Build UMF examples")
# TODO: L0 provider not ready yet
set(UMF_BUILD_LEVEL_ZERO_PROVIDER OFF CACHE INTERNAL "Build Level Zero Provider")
set(UMF_BUILD_SHARED_LIBRARY ${UMF_BUILD_SHARED_LIBRARY} CACHE INTERNAL "Build UMF shared library")
set(UMF_BUILD_LIBUMF_POOL_DISJOINT ON CACHE INTERNAL "Build Disjoint Pool")
set(UMF_BUILD_OS_MEMORY_PROVIDER OFF CACHE INTERNAL "Build OS Provider")

FetchContent_MakeAvailable(unified-memory-framework)
FetchContent_GetProperties(unified-memory-framework)

target_link_libraries(ur_common PUBLIC
unified-memory-framework::umf
unified-memory-framework::headers
unified-memory-framework::disjoint_pool
${CMAKE_DL_LIBS}
${PROJECT_NAME}::headers
)
Expand All @@ -70,3 +63,18 @@ install(TARGETS ur_common
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

add_library(ur_umf INTERFACE)
target_sources(ur_umf INTERFACE
umf_helpers.hpp
umf_pools/disjoint_pool_config_parser.cpp
ur_pool_manager.hpp
)

add_library(${PROJECT_NAME}::umf ALIAS ur_umf)

target_link_libraries(ur_umf INTERFACE
umf::umf
umf::headers
umf::disjoint_pool
)
Loading

0 comments on commit 3d8fe8d

Please sign in to comment.