Skip to content

add Level Zero memory provider #237

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

Merged
merged 1 commit into from
Mar 4, 2024
Merged
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
7 changes: 6 additions & 1 deletion .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build build -j $(nproc)
Expand Down Expand Up @@ -133,6 +134,7 @@ jobs:
if: matrix.compiler.cxx == 'g++-7'
run: sudo apt-get install -y ${{matrix.compiler.cxx}}

# TODO enable building Level Zero provider in all workflows
- name: Configure build
run: >
cmake
Expand All @@ -149,6 +151,7 @@ jobs:
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} -j $(nproc)
Expand Down Expand Up @@ -221,6 +224,7 @@ jobs:
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_OS_MEMORY_PROVIDER=${{matrix.os_provider}}
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS
Expand Down Expand Up @@ -250,7 +254,8 @@ jobs:
-DCMAKE_BUILD_TYPE=Release
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} -j $(sysctl -n hw.logicalcpu)
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_ENABLE_POOL_TRACKING=OFF
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{github.workspace}}/build -j $(nproc)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=${{matrix.pool_scalable}}
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build
run: cmake --build ${{github.workspace}}/build --config Release -j
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/gpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This workflow builds and tests providers using GPU memory. It requires
# "level_zero" labeled self-hosted runners installed on systems with the
# appropriate GPU and drivers.
name: GPU

on: [workflow_call]

permissions:
contents: read

jobs:
# TODO: add support for Windows
ubuntu-build:
name: Build - Ubuntu

strategy:
matrix:
os: ['ubuntu-22.04']
build_type: [Release]
compiler: [{c: gcc, cxx: g++}]
shared_library: ['ON', 'OFF']
runs-on: level_zero

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Configure build
run: >
cmake
-B ${{github.workspace}}/build
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
-DUMF_BUILD_BENCHMARKS=ON
-DUMF_BUILD_TESTS=ON
-DUMF_FORMAT_CODE_STYLE=ON
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_ENABLE_POOL_TRACKING=ON

- name: Build UMF
run: cmake --build ${{github.workspace}}/build -j $(nproc)

- name: Run tests
working-directory: ${{github.workspace}}/build
run: ctest --output-on-failure --test-dir test
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build
run: cmake --build ${{github.workspace}}/build --config Debug -j$(nproc)
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pr_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{matrix.jemalloc}}
-DUMF_BUILD_TESTS=ON
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
${{matrix.extra_build_options}}

- name: Build
Expand Down Expand Up @@ -94,6 +95,7 @@ jobs:
-DUMF_FORMAT_CODE_STYLE=ON
-DUMF_BUILD_OS_MEMORY_PROVIDER=OFF
-DUMF_BUILD_TESTS=OFF
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Check clang-format
run: cmake --build build --target clang-format-check
Expand All @@ -113,3 +115,6 @@ jobs:
ProxyLib:
needs: [Build]
uses: ./.github/workflows/proxy_lib.yml
GPU:
needs: [Build]
uses: ./.github/workflows/gpu.yml
1 change: 1 addition & 0 deletions .github/workflows/proxy_lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{github.workspace}}/build -j $(nproc)
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
-DUSE_UBSAN=${{matrix.sanitizers.ubsan}}
-DUSE_TSAN=${{matrix.sanitizers.tsan}}
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} -j $(nproc)
Expand Down Expand Up @@ -98,6 +99,7 @@ jobs:
-DUSE_UBSAN=${{matrix.sanitizers.ubsan}}
-DUSE_TSAN=${{matrix.sanitizers.tsan}}
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} -j $(nproc)
Expand Down Expand Up @@ -145,6 +147,7 @@ jobs:
-DUSE_ASAN=${{matrix.sanitizers.asan}}
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} --config Debug -j $Env:NUMBER_OF_PROCESSORS
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ project(unified-memory-framework VERSION 0.1.0 LANGUAGES C)
# Build Options
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_BUILD_OS_MEMORY_PROVIDER "Build OS memory provider" ON)
option(UMF_BUILD_LEVEL_ZERO_PROVIDER "Build Level Zero memory provider" ON)
option(UMF_BUILD_LIBUMF_POOL_DISJOINT "Build the libumf_pool_disjoint static library" OFF)
option(UMF_BUILD_LIBUMF_POOL_JEMALLOC "Build the libumf_pool_jemalloc static library" OFF)
option(UMF_BUILD_LIBUMF_POOL_SCALABLE "Build the libumf_pool_scalable static library" OFF)
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![SpellCheck](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/spellcheck.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/spellcheck.yml)
[![GitHubPages](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/docs.yml)
[![Benchmarks](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/benchmarks.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/benchmarks.yml)
[![GPU](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/gpu.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/gpu.yml)
[![Nightly](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/nightly.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-memory-framework/actions/workflows/nightly.yml)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/oneapi-src/unified-memory-framework/badge)](https://securityscorecards.dev/viewer/?uri=github.com/oneapi-src/unified-memory-framework)

Expand All @@ -31,6 +32,10 @@ For development and contributions:
For building tests, multithreaded benchmarks and Disjoint Pool:
- C++ compiler with C++17 support

For Level Zero memory provider and its tests:
- Level Zero headers and libraries
- compatible GPU with installed driver

### Linux

Executable and binaries will be in **build/bin**
Expand Down Expand Up @@ -84,6 +89,7 @@ List of options provided by CMake:
| - | - | - | - |
| UMF_BUILD_SHARED_LIBRARY | Build UMF as shared library | ON/OFF | OFF |
| UMF_BUILD_OS_MEMORY_PROVIDER | Build OS memory provider | ON/OFF | ON |
| UMF_BUILD_LIBUMF_PROVIDER_LEVEL_ZERO | Build Level Zero memory provider | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_DISJOINT | Build the libumf_pool_disjoint static library | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_JEMALLOC | Build the libumf_pool_jemalloc static library | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_SCALABLE | Build the libumf_pool_scalable static library | ON/OFF | OFF |
Expand Down Expand Up @@ -123,6 +129,18 @@ A memory provider that provides memory from an operating system.
4) Required packages for tests:
- libnuma-dev

#### Level Zero memory provider (Linux-only yet)

A memory provider that provides memory from L0 device.

##### Requirements

1) System with Level Zero compatible GPU
2) Linux OS
3) The `UMF_BUILD_LIBUMF_PROVIDER_LEVEL_ZERO` option turned `ON`
4) Required packages:
- level-zero-dev (TODO: check this)

### Memory pool managers

#### proxy_pool (part of libumf)
Expand Down
4 changes: 4 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ if (UMF_BUILD_OS_MEMORY_PROVIDER)
endif()
endif()

if (UMF_BUILD_OS_MEMORY_PROVIDER)
target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
endif()

if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)

Expand Down
41 changes: 41 additions & 0 deletions include/umf/providers/provider_level_zero.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#ifndef UMF_PROVIDER_LEVEL_ZERO_H
#define UMF_PROVIDER_LEVEL_ZERO_H

#include "umf/memory_provider.h"

#ifdef __cplusplus
extern "C" {
#endif

/// @brief USM memory allocation type
typedef enum umf_usm_memory_type_t {
UMF_MEMORY_TYPE_UNKNOWN = 0,
UMF_MEMORY_TYPE_HOST,
UMF_MEMORY_TYPE_DEVICE,
UMF_MEMORY_TYPE_SHARED,
} umf_usm_memory_type_t;

/// @brief Level Zero Memory Provider settings struct
typedef struct level_zero_memory_provider_params_t {
void *level_zero_context_handle;
void *level_zero_device_handle;
umf_usm_memory_type_t memory_type;
uint32_t level_zero_host_mem_alloc_flags;
uint32_t level_zero_device_mem_alloc_flags;
uint32_t level_zero_device_local_mem_ordinal;
} level_zero_memory_provider_params_t;

umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void);

#ifdef __cplusplus
}
#endif

#endif /* UMF_PROVIDER_LEVEL_ZERO_H */
12 changes: 12 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ if(UMF_BUILD_OS_MEMORY_PROVIDER)
endif()
endif()

if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
# Currently, Level Zero provider is only built for Linux
# TODO add fetch content or PkgConfig/find_package for Level Zero
set(UMF_SOURCES_LINUX ${UMF_SOURCES_LINUX}
provider/provider_level_zero.c)

if(LINUX)
set(UMF_COMPILE_DEFINITIONS ${UMF_COMPILE_DEFINITIONS}
"UMF_BUILD_LEVEL_ZERO_PROVIDER=1")
endif()
endif()

if(LINUX)
set(UMF_SOURCES ${UMF_SOURCES} ${UMF_SOURCES_LINUX})
elseif(WINDOWS)
Expand Down
1 change: 1 addition & 0 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ UMF_1.0 {
global:
umfFree;
umfGetLastFailedMemoryProvider;
umfLevelZeroMemoryProviderOps;
umfMemoryProviderAlloc;
umfMemoryProviderAllocationMerge;
umfMemoryProviderAllocationSplit;
Expand Down
1 change: 0 additions & 1 deletion src/pool/pool_scalable.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "umf/pools/pool_scalable.h"
Expand Down
Loading