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

Build GPU plugin with CPU's oneDNN #23216

Closed
Closed
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
19 changes: 16 additions & 3 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,26 @@ endif()

ov_dependent_option (ENABLE_INTEL_GPU "GPU OpenCL-based plugin for OpenVINO Runtime" ${ENABLE_INTEL_GPU_DEFAULT} "X86_64 OR AARCH64;NOT APPLE;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" OFF)

if (ANDROID OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) OR (NOT BUILD_SHARED_LIBS AND ENABLE_INTEL_CPU))
if (ANDROID OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
# oneDNN doesn't support old compilers and android builds for now, so we'll build GPU plugin without oneDNN
# also, in case of static build CPU's and GPU's oneDNNs will conflict, so we are disabling GPU's one in this case
set(ENABLE_ONEDNN_FOR_GPU_DEFAULT OFF)
else()
set(ENABLE_ONEDNN_FOR_GPU_DEFAULT ON)
endif()

ov_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENABLE_ONEDNN_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF)

if(BUILD_SHARED_LIBS OR NOT ENABLE_INTEL_CPU)
set(ENABLE_GPU_USE_CPUS_ONEDNN_DEFAULT OFF)
else()
set(ENABLE_GPU_USE_CPUS_ONEDNN_DEFAULT ON)
endif()

# TODO: remove
set(ENABLE_GPU_USE_CPUS_ONEDNN_DEFAULT ON)

ov_dependent_option (ENABLE_GPU_USE_CPUS_ONEDNN "Enable GPU to use oneDNN from CPU" ${ENABLE_GPU_USE_CPUS_ONEDNN_DEFAULT} "ENABLE_ONEDNN_FOR_GPU;ENABLE_INTEL_CPU" OFF)

ov_option (ENABLE_DEBUG_CAPS "enable OpenVINO debug capabilities at runtime" OFF)
ov_dependent_option (ENABLE_GPU_DEBUG_CAPS "enable GPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_GPU" OFF)
ov_dependent_option (ENABLE_CPU_DEBUG_CAPS "enable CPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_CPU" OFF)
Expand Down Expand Up @@ -158,13 +168,16 @@ else()
set(ENABLE_SYSTEM_TBB_DEFAULT ${ENABLE_SYSTEM_LIBS_DEFAULT})
endif()

# don't use system OpenCL during static build to avoid extra shared libs dependencies
set(ENABLE_SYSTEM_OPENCL_DEFAULT ${BUILD_SHARED_LIBS})

ov_dependent_option (ENABLE_SYSTEM_TBB "Enables use of system TBB" ${ENABLE_SYSTEM_TBB_DEFAULT}
"THREADING MATCHES TBB" OFF)
ov_option (ENABLE_SYSTEM_PUGIXML "Enables use of system PugiXML" OFF)
# the option is on by default, because we use only flatc compiler and don't use any libraries
ov_dependent_option(ENABLE_SYSTEM_FLATBUFFERS "Enables use of system flatbuffers" ${ENABLE_SYSTEM_FLATBUFFERS_DEFAULT}
"ENABLE_OV_TF_LITE_FRONTEND" OFF)
ov_dependent_option (ENABLE_SYSTEM_OPENCL "Enables use of system OpenCL" ${ENABLE_SYSTEM_LIBS_DEFAULT}
ov_dependent_option (ENABLE_SYSTEM_OPENCL "Enables use of system OpenCL" ${ENABLE_SYSTEM_OPENCL_DEFAULT}
"ENABLE_INTEL_GPU" OFF)
# the option is turned off by default, because we compile our own static version of protobuf
# with LTO and -fPIC options, while system one does not have such flags
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/openvino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ configure_package_config_file("${OpenVINO_SOURCE_DIR}/cmake/templates/OpenVINOCo

list(APPEND INSTALL_PATH_VARS "OPENVINO_LIB_DIR")
# remove generator expression at the end, because searching in Release / Debug
# will be done by inside OpenVINOConfig.cmak / ACLConfig.cmake
# will be done by inside OpenVINOConfig.cmake / ACLConfig.cmake
string(REPLACE "$<CONFIG>" "" OPENVINO_LIB_DIR "${OV_CPACK_LIBRARYDIR}")

set(OV_TBB_DIR "${OV_TBB_DIR_INSTALL}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void scatter_elem_update_no_reduction(const size_t data_elem_size,
} // namespace

template <typename T>
T reduction_neutral_value(const Reduction reduction_type) {
inline T reduction_neutral_value(const Reduction reduction_type) {
switch (reduction_type) {
case Reduction::MAX:
return std::numeric_limits<T>::lowest();
Expand All @@ -76,7 +76,7 @@ T reduction_neutral_value(const Reduction reduction_type) {
}

template <typename T>
std::function<T(const T, const T)> reduction_functor_for(const Reduction reduction_type) {
inline std::function<T(const T, const T)> reduction_functor_for(const Reduction reduction_type) {
switch (reduction_type) {
case Reduction::MAX:
return [](const T a, const T b) {
Expand All @@ -97,7 +97,7 @@ std::function<T(const T, const T)> reduction_functor_for(const Reduction reducti
}

template <>
std::function<char(const char, const char)> reduction_functor_for<char>(const Reduction reduction_type) {
inline std::function<char(const char, const char)> reduction_functor_for<char>(const Reduction reduction_type) {
switch (reduction_type) {
case Reduction::MAX:
return [](const char a, const char b) {
Expand Down
104 changes: 83 additions & 21 deletions src/plugins/intel_cpu/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,40 @@ if(ENABLE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
endif()

function(ov_add_onednn)
set(CMAKE_DISABLE_FIND_PACKAGE_PythonInterp ON)
set(DNNL_ENABLE_JIT_PROFILING ${BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
if(BUILD_SHARED_LIBS AND ENABLE_PROFILING_ITT)
set(DNNL_ENABLE_ITT_TASKS ON CACHE BOOL "" FORCE)
function(ov_add_onednn_common)
#
# Common oneDNN options
#

if(ENABLE_GPU_USE_CPUS_ONEDNN AND ENABLE_LTO)
# TODO: for some reason, when CPU's oneDNN is compiled with GPU support, we have
# issues because of LTO; so, let's turn off
set(DNNL_ENABLE_JIT_PROFILING_DEFAULT OFF)
set(DNNL_ENABLE_ITT_TASKS_DEFAULT OFF)
else()
set(DNNL_ENABLE_ITT_TASKS OFF CACHE BOOL "" FORCE)
set(DNNL_ENABLE_JIT_PROFILING_DEFAULT ${BUILD_SHARED_LIBS})
if(BUILD_SHARED_LIBS AND ENABLE_PROFILING_ITT)
set(DNNL_ENABLE_ITT_TASKS_DEFAULT ON)
else()
set(DNNL_ENABLE_ITT_TASKS_DEFAULT OFF)
endif()
endif()

set(CMAKE_DISABLE_FIND_PACKAGE_PythonInterp ON)
set(DNNL_ENABLE_JIT_PROFILING ${DNNL_ENABLE_JIT_PROFILING_DEFAULT} CACHE BOOL "" FORCE)
set(DNNL_ENABLE_ITT_TASKS ${DNNL_ENABLE_ITT_TASKS_DEFAULT} CACHE BOOL "" FORCE)
set(DNNL_ENABLE_CONCURRENT_EXEC ON CACHE BOOL "" FORCE)
set(DNNL_ENABLE_PRIMITIVE_CACHE ON CACHE BOOL "" FORCE) # Enable primitive cache for global sharing
set(DNNL_ENABLE_MAX_CPU_ISA ON CACHE BOOL "" FORCE)
set(DNNL_LIBRARY_TYPE "STATIC" CACHE STRING "" FORCE)
set(DNNL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(DNNL_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(DNNL_CPU_RUNTIME "${THREADING}" CACHE STRING "" FORCE)
set(DNNL_GPU_RUNTIME "NONE" CACHE STRING "" FORCE)
set(DNNL_BLAS_VENDOR "NONE" CACHE STRING "" FORCE)
# plugin does not use onednn graph
set(ONEDNN_BUILD_GRAPH OFF CACHE BOOL "" FORCE)
# select needed primitives
set(DNNL_ENABLE_PRIMITIVE "CONVOLUTION;DECONVOLUTION;CONCAT;LRN;INNER_PRODUCT;MATMUL;POOLING;REDUCTION;REORDER;RNN;SOFTMAX" CACHE STRING "" FORCE)
set(DNNL_ENABLE_WORKLOAD "INFERENCE" CACHE STRING "" FORCE)
set(DNNL_LIBRARY_NAME "openvino_onednn_cpu" CACHE STRING "" FORCE)

# Allow to enable oneDNN verbose with CPU_DEBUG_CAPS and rely on oneDNN default configuration otherwise
if(ENABLE_CPU_DEBUG_CAPS)
set(DNNL_VERBOSE ON CACHE STRING "" FORCE)
endif()

if(X86_64)
set(DNNL_TARGET_ARCH "X64" CACHE STRING "" FORCE)
elseif(X86)
Expand All @@ -58,6 +63,55 @@ function(ov_add_onednn)
message(FATAL_ERROR "Unsupported system processor ${CMAKE_SYSTEM_PROCESSOR}")
endif()

# IMPORTANT! when updating this list of supported primitives, align it with oneDNN for GPU list
# https://github.com/openvinotoolkit/openvino/blob/releases/2024/0/src/plugins/intel_gpu/thirdparty/CMakeLists.txt#L15
# It's required, because in case of static build both CPU and GPU share the same oneDNN library
set(DNNL_ENABLE_PRIMITIVE "CONVOLUTION;DECONVOLUTION;CONCAT;LRN;INNER_PRODUCT;MATMUL;POOLING;REDUCTION;REORDER;RNN;SOFTMAX" CACHE STRING "" FORCE)

#
# GPU specific options
#

if(NOT BUILD_SHARED_LIBS AND ENABLE_ONEDNN_FOR_GPU OR ENABLE_GPU_USE_CPUS_ONEDNN)
# build oneDNN to be compatible with Intel GPU plugin
set(DNNL_ENABLE_PRIMITIVE_GPU_ISA "XEHP;XEHPG;XEHPC" CACHE STRING "" FORCE)
set(DNNL_GPU_RUNTIME "OCL" CACHE STRING "" FORCE)
set(DNNL_EXPERIMENTAL_PROFILING ON CACHE BOOL "" FORCE)

# Keep in sync with https://github.com/openvinotoolkit/openvino/blob/releases/2024/0/src/plugins/intel_gpu/CMakeLists.txt#L30
set(INTEL_GPU_TARGET_OCL_VERSION "200" CACHE STRING "Target version of OpenCL which should be used by GPU plugin")

if(INTEL_GPU_TARGET_OCL_VERSION STREQUAL "300")
set(ONEDNN_CL_VERSION "3_0")
elseif(INTEL_GPU_TARGET_OCL_VERSION STREQUAL "220")
set(ONEDNN_CL_VERSION "2_2")
elseif(INTEL_GPU_TARGET_OCL_VERSION STREQUAL "210")
set(ONEDNN_CL_VERSION "2_1")
elseif(INTEL_GPU_TARGET_OCL_VERSION STREQUAL "200")
set(ONEDNN_CL_VERSION "2_0")
elseif(INTEL_GPU_TARGET_OCL_VERSION STREQUAL "120")
set(ONEDNN_CL_VERSION "1_2")
elseif(INTEL_GPU_TARGET_OCL_VERSION STREQUAL "100")
set(ONEDNN_CL_VERSION "1_0")
else()
message(FATAL_ERROR "Unsupported version of OpenCL: ${INTEL_GPU_TARGET_OCL_VERSION}")
endif()

# override OpenCL version default set by oneDNN (1.2)
set(OPENCL_VERSION_${ONEDNN_CL_VERSION} ON)
else()
set(DNNL_GPU_RUNTIME "NONE" CACHE STRING "" FORCE)
endif()

#
# CPU specific options
#

# Allow to enable oneDNN verbose with CPU_DEBUG_CAPS and rely on oneDNN default configuration otherwise
if(ENABLE_CPU_DEBUG_CAPS)
set(DNNL_VERBOSE ON CACHE STRING "" FORCE)
endif()

if(AARCH64 OR ARM)
set(DNNL_USE_ACL ON CACHE BOOL "Use ARM Conpute Library kernels in oneDNN" FORCE)
endif()
Expand All @@ -78,6 +132,15 @@ function(ov_add_onednn)
link_libraries(TBB::tbb)
endif()

# to find our FindACL.cmake
if(DNNL_USE_ACL)
list(APPEND CMAKE_MODULE_PATH "${intel_cpu_thirdparty_SOURCE_DIR}")
endif()

#
# Compilation flags
#

if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG)
ov_add_compiler_flags(-Wno-undef)
ov_add_compiler_flags(-Wno-missing-declarations)
Expand Down Expand Up @@ -110,10 +173,9 @@ function(ov_add_onednn)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-suggest-override")
endif()

# to find our FindACL.cmake
if(DNNL_USE_ACL)
list(APPEND CMAKE_MODULE_PATH "${intel_cpu_thirdparty_SOURCE_DIR}")
endif()
#
# Build and install
#

add_subdirectory(onednn EXCLUDE_FROM_ALL)

Expand All @@ -135,9 +197,9 @@ function(ov_add_onednn)
endif()
endfunction()

ov_add_onednn_common()

if(ENABLE_MLAS_FOR_CPU)
add_subdirectory(mlas)
ov_install_static_lib(mlas ${OV_CPACK_COMP_CORE})
endif()

ov_add_onednn()
3 changes: 1 addition & 2 deletions src/plugins/intel_gpu/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ target_compile_definitions(${TARGET_NAME} PRIVATE CI_BUILD_NUMBER="")
ov_set_threading_interface_for(${TARGET_NAME})

# Workaround to avoid warnings during LTO build
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_RELEASE "-Wno-error=maybe-uninitialized -Wno-maybe-uninitialized")
endif()

Expand All @@ -75,7 +75,6 @@ target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/test_utils/
$<TARGET_PROPERTY:openvino_intel_gpu_kernels,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino_intel_gpu_runtime,INTERFACE_INCLUDE_DIRECTORIES>
${CMAKE_HOME_DIRECTORY}/src/core/reference/include/
${TEST_COMMON_INCLUDE_DIR})

if(WIN32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "test_utils.h"

#include "openvino/reference/scatter_elements_update.hpp"

#include <intel_gpu/primitives/input_layout.hpp>
#include <intel_gpu/primitives/scatter_elements_update.hpp>
#include <intel_gpu/runtime/memory.hpp>
Expand All @@ -15,27 +17,6 @@
using namespace cldnn;
using namespace ::tests;

#ifdef OPENVINO_STATIC_LIBRARY
namespace ov {
namespace reference {
using Reduction = ov::op::v12::ScatterElementsUpdate::Reduction;

template<typename DataType, typename IndicesType>
void scatter_elem_update(const DataType *input_data,
const IndicesType *indices,
const DataType *updates,
const int64_t axis,
DataType *out_buf,
const Shape &data_shape,
const Shape &indices_shape,
const Reduction reduction_type = Reduction::NONE,
const bool use_init_val = true);
}
}
#else
#include "openvino/reference/scatter_elements_update.hpp"
#endif

template <typename T>
void test_d2411_axisF(bool is_caching_test) {
// Dictionary : 2x4x1x1
Expand Down
Loading
Loading