Skip to content

Commit 38f889e

Browse files
committed
Add L0 support for gpu
1 parent 5028f18 commit 38f889e

File tree

70 files changed

+2962
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2962
-136
lines changed

.github/workflows/android_arm64.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/json
129129
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/gtest
130130
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/gflags
131+
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/level_zero
131132
popd
132133
133134
- name: Clone vcpkg

.github/workflows/linux_riscv.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ jobs:
150150
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/telemetry
151151
git submodule update --init -- ${OPENVINO_REPO}/src/plugins/intel_cpu
152152
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/flatbuffers/flatbuffers
153+
git submodule update --init -- ${OPENVINO_REPO}/thirdparty/level_zero
153154
popd
154155
155156
#

cmake/features.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ else()
4141
set(ENABLE_ONEDNN_FOR_GPU_DEFAULT ON)
4242
endif()
4343

44+
set(OV_GPU_DEFAULT_RT "L0")
45+
if (ENABLE_INTEL_GPU)
46+
ov_option_enum (GPU_RT_TYPE "Type of GPU runtime. Supported value: OCL and L0" ${OV_GPU_DEFAULT_RT} ALLOWED_VALUES L0 OCL)
47+
if (GPU_RT_TYPE STREQUAL "L0")
48+
# There's no interop with native L0 in onednn API. Temporary disable onednn when L0 runtime is selected
49+
set(ENABLE_ONEDNN_FOR_GPU_DEFAULT OFF)
50+
endif()
51+
endif()
52+
4453
ov_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENABLE_ONEDNN_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF)
4554

4655
ov_dependent_option (ENABLE_INTEL_NPU "NPU plugin for OpenVINO runtime" ON "X86_64;WIN32 OR LINUX" OFF)

src/inference/include/openvino/runtime/intel_gpu/remote_properties.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using gpu_handle_param = void*;
2424
enum class ContextType {
2525
OCL = 0, //!< Pure OpenCL context
2626
VA_SHARED = 1, //!< Context shared with a video decoding device
27+
ZE = 2, //!< Pure Level0 context
2728
};
2829

2930
/** @cond INTERNAL */
@@ -33,6 +34,8 @@ inline std::ostream& operator<<(std::ostream& os, const ContextType& context_typ
3334
return os << "OCL";
3435
case ContextType::VA_SHARED:
3536
return os << "VA_SHARED";
37+
case ContextType::ZE:
38+
return os << "ZE";
3639
default:
3740
OPENVINO_THROW("Unsupported context type");
3841
}
@@ -43,6 +46,8 @@ inline std::istream& operator>>(std::istream& is, ContextType& context_type) {
4346
is >> str;
4447
if (str == "OCL") {
4548
context_type = ContextType::OCL;
49+
} else if (str == "ZE") {
50+
context_type = ContextType::ZE;
4651
} else if (str == "VA_SHARED") {
4752
context_type = ContextType::VA_SHARED;
4853
} else {

src/plugins/intel_gpu/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ endif()
88

99
set (TARGET_NAME "openvino_intel_gpu_plugin")
1010

11+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake)
12+
1113
if(OV_COMPILER_IS_INTEL_LLVM)
1214
# For windows we need to disable warning as error option to make FindSYCL.cmake work
1315
if (WIN32)
@@ -77,6 +79,7 @@ target_include_directories(${TARGET_NAME} PRIVATE
7779
${CMAKE_CURRENT_SOURCE_DIR}/include/)
7880

7981
ov_set_threading_interface_for(${TARGET_NAME})
82+
ov_gpu_set_runtime_interface_for(${TARGET_NAME})
8083

8184
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
8285

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
5+
function(ov_gpu_set_runtime_interface_for TARGET_NAME)
6+
if(GPU_RT_TYPE STREQUAL "L0")
7+
target_compile_definitions(${TARGET_NAME} PUBLIC OV_GPU_WITH_ZE_RT=1)
8+
target_link_libraries(${TARGET_NAME} PUBLIC LevelZero::LevelZero)
9+
elseif(GPU_RT_TYPE STREQUAL "OCL")
10+
target_compile_definitions(${TARGET_NAME} PUBLIC OV_GPU_WITH_OCL_RT=1)
11+
target_link_libraries(${TARGET_NAME} PUBLIC OpenCL::NewHeaders OpenCL::OpenCL)
12+
else()
13+
message(FATAL_ERROR "Invalid GPU runtime type: `${GPU_RT_TYPE}` Only `L0` and `OCL` are supported")
14+
endif()
15+
endfunction()

src/plugins/intel_gpu/include/intel_gpu/plugin/remote_context.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# define NOMINMAX
99
#endif
1010

11+
#include "intel_gpu/runtime/engine_configuration.hpp"
1112
#include "openvino/runtime/intel_gpu/remote_properties.hpp"
1213
#include "openvino/runtime/iremote_context.hpp"
1314

@@ -22,6 +23,26 @@
2223

2324
namespace ov::intel_gpu {
2425

26+
inline std::pair<cldnn::engine_types, cldnn::runtime_types> get_device_query_params() {
27+
#ifdef OV_GPU_WITH_ZE_RT
28+
auto runtime_type = cldnn::runtime_types::ze;
29+
#ifdef OV_GPU_WITH_SYCL
30+
auto engine_type = cldnn::engine_types::sycl;
31+
#else
32+
auto engine_type = cldnn::engine_types::ze;
33+
#endif
34+
#else
35+
auto runtime_type = cldnn::runtime_types::ocl;
36+
#ifdef OV_GPU_WITH_SYCL
37+
auto engine_type = cldnn::engine_types::sycl;
38+
#else
39+
auto engine_type = cldnn::engine_types::ocl;
40+
#endif
41+
#endif
42+
43+
return {engine_type, runtime_type};
44+
}
45+
2546
class RemoteContextImpl : public ov::IRemoteContext {
2647
public:
2748
using Ptr = std::shared_ptr<RemoteContextImpl>;
@@ -93,7 +114,11 @@ class RemoteContextImpl : public ov::IRemoteContext {
93114
ov::intel_gpu::gpu_handle_param m_va_display = nullptr;
94115
ov::intel_gpu::gpu_handle_param m_external_queue = nullptr;
95116

117+
#ifdef OV_GPU_WITH_ZE_RT
118+
ContextType m_type = ContextType::ZE;
119+
#else
96120
ContextType m_type = ContextType::OCL;
121+
#endif
97122
std::string m_device_name = "";
98123
static const size_t cache_capacity = 100;
99124
cldnn::LruCache<size_t, cldnn::memory::ptr> m_memory_cache = cldnn::LruCache<size_t, cldnn::memory::ptr>(cache_capacity);

src/plugins/intel_gpu/include/intel_gpu/runtime/device.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,28 @@ struct device {
3333
virtual ~device() = default;
3434
};
3535

36+
// The priority return by this function impacts the order of devices reported by GPU plugin and devices enumeration
37+
// Lower priority value means lower device ID
38+
// Current behavior is: Intel iGPU < Intel dGPU < any other GPU
39+
// Order of Intel dGPUs is undefined and depends on the OCL impl
40+
// Order of other vendor GPUs is undefined and depends on the OCL impl
41+
inline size_t get_device_priority(const cldnn::device_info& info) {
42+
if (info.vendor_id == cldnn::INTEL_VENDOR_ID && info.dev_type == cldnn::device_type::integrated_gpu) {
43+
return 0;
44+
} else if (info.vendor_id == cldnn::INTEL_VENDOR_ID) {
45+
return 1;
46+
} else {
47+
return std::numeric_limits<size_t>::max();
48+
}
49+
}
50+
51+
inline std::vector<device::ptr> sort_devices(const std::vector<device::ptr>& devices_list) {
52+
std::vector<device::ptr> sorted_list = devices_list;
53+
std::stable_sort(sorted_list.begin(), sorted_list.end(), [](device::ptr d1, device::ptr d2) {
54+
return get_device_priority(d1->get_info()) < get_device_priority(d2->get_info());
55+
});
56+
57+
return sorted_list;
58+
}
59+
3660
} // namespace cldnn

src/plugins/intel_gpu/include/intel_gpu/runtime/device_info.hpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ struct gfx_version {
4646
< std::tie(r.major, r.minor, r.revision); // same order
4747
}
4848

49-
bool operator==(const gfx_version& other) {
49+
bool operator==(const gfx_version& other) const {
5050
return major == other.major &&
5151
minor == other.minor &&
5252
revision == other.revision;
5353
}
5454

55-
bool operator!=(const gfx_version& other) {
55+
bool operator!=(const gfx_version& other) const {
5656
return !(*this == other);
5757
}
5858
};
@@ -63,14 +63,14 @@ struct pci_bus_info {
6363
uint32_t pci_device = 0;
6464
uint32_t pci_function = 0;
6565

66-
bool operator==(const pci_bus_info& other) {
66+
bool operator==(const pci_bus_info& other) const {
6767
return pci_domain == other.pci_domain &&
6868
pci_bus == other.pci_bus &&
6969
pci_device == other.pci_device &&
7070
pci_function == other.pci_function;
7171
}
7272

73-
bool operator!=(const pci_bus_info& other) {
73+
bool operator!=(const pci_bus_info& other) const {
7474
return !(*this == other);
7575
}
7676
};
@@ -105,6 +105,8 @@ struct device_info {
105105
bool supports_imad; ///< Does engine support int8 mad.
106106
bool supports_immad; ///< Does engine support int8 multi mad.
107107

108+
bool supports_mutable_command_list; ///< Does the target runtime/device support mutable command list feature
109+
108110
bool supports_usm; ///< Does engine support unified shared memory.
109111
bool has_separate_cache; ///< Does the target hardware has separate cache for usm_device and usm_host
110112

@@ -129,8 +131,45 @@ struct device_info {
129131

130132
pci_bus_info pci_info; ///< PCI bus information for the device
131133

134+
uint64_t timer_resolution; ///< Resolution of device timer used for profiling in cycles/sec
135+
uint32_t kernel_timestamp_valid_bits; ///< Number of valid bits in the kernel timestamp values
136+
uint32_t compute_queue_group_ordinal; ///< Ordinal of the command queue group with compute support
137+
uint32_t device_memory_ordinal; ///< Ordinal of the selected global device memory
138+
132139
ov::device::UUID uuid; ///< UUID of the gpu device
133140
ov::device::LUID luid; ///< LUID of the gpu device
141+
142+
inline bool is_same_device(const device_info &other) const {
143+
// Relying solely on the UUID is not reliable in all the cases (particularly on legacy platforms),
144+
// where the UUID may be missing or incorrectly generated
145+
// Therefore, we also validate other attributes
146+
if (uuid.uuid != other.uuid.uuid)
147+
return false;
148+
149+
if (pci_info != other.pci_info)
150+
return false;
151+
152+
if (sub_device_idx != other.sub_device_idx)
153+
return false;
154+
155+
if (vendor_id != other.vendor_id ||
156+
dev_name != other.dev_name ||
157+
driver_version != other.driver_version)
158+
return false;
159+
160+
if (dev_type != other.dev_type ||
161+
gfx_ver != other.gfx_ver ||
162+
arch != other.arch)
163+
return false;
164+
165+
if (ip_version != other.ip_version || device_id != other.device_id)
166+
return false;
167+
168+
if (execution_units_count != other.execution_units_count || max_global_mem_size != other.max_global_mem_size)
169+
return false;
170+
171+
return true;
172+
}
134173
};
135174

136175
/// @}

src/plugins/intel_gpu/include/intel_gpu/runtime/engine_configuration.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
#pragma once
66

7-
#include <string>
7+
#include <ostream>
88

99
namespace cldnn {
1010

1111
/// @brief Defines available engine types
1212
enum class engine_types : int32_t {
1313
ocl,
14-
sycl
14+
sycl,
15+
ze
1516
};
1617

1718
inline std::ostream& operator<<(std::ostream& os, const engine_types& type) {
1819
switch (type) {
1920
case engine_types::ocl: os << "ocl"; break;
2021
case engine_types::sycl: os << "sycl"; break;
22+
case engine_types::ze: os << "ze"; break;
2123
default: os << "unknown"; break;
2224
}
2325

@@ -27,11 +29,13 @@ inline std::ostream& operator<<(std::ostream& os, const engine_types& type) {
2729
/// @brief Defines available runtime types
2830
enum class runtime_types : int32_t {
2931
ocl,
32+
ze,
3033
};
3134

3235
inline std::ostream& operator<<(std::ostream& os, const runtime_types& type) {
3336
switch (type) {
3437
case runtime_types::ocl: os << "ocl"; break;
38+
case runtime_types::ze: os << "ze"; break;
3539
default: os << "unknown"; break;
3640
}
3741

0 commit comments

Comments
 (0)