Skip to content

Commit

Permalink
Fixed GPU plugin static build with oneDNN (openvinotoolkit#19811)
Browse files Browse the repository at this point in the history
* Fixed GPU plugin static build with oneDNN

* Fixed issue with absolute paths inside installed OpenVINOConfig.cmake

* Fixed absolute paths in installed OpenVINOConfig.cmake

* Changed components for installation
  • Loading branch information
ilya-lavrenov authored Sep 18, 2023
1 parent e9aaf9a commit 253ca8c
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 39 deletions.
4 changes: 4 additions & 0 deletions cmake/developer_package/plugins/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ function(ov_add_plugin)
# install rules
if(NOT OV_PLUGIN_SKIP_INSTALL OR NOT BUILD_SHARED_LIBS)
string(TOLOWER "${OV_PLUGIN_DEVICE_NAME}" install_component)
if(NOT BUILD_SHARED_LIBS)
# in case of static libs everything is installed to 'core'
set(install_component ${OV_CPACK_COMP_CORE})
endif()

if(OV_PLUGIN_PSEUDO_DEVICE)
set(plugin_hidden HIDDEN)
Expand Down
2 changes: 1 addition & 1 deletion cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()

ie_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)
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))
# 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)
Expand Down
63 changes: 52 additions & 11 deletions cmake/templates/OpenVINOConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ macro(_ov_find_tbb)
PATHS ${_tbb_bind_dir}
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)
if(TARGET TBBbind::tbbbind_2_5)
# To solve https://cmake.org/cmake/help/latest/policy/CMP0111.html warnings
set_property(TARGET TBBbind::tbbbind_2_5 PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
endif()
unset(_tbb_bind_dir)
endif()
unset(install_tbbbind)
Expand Down Expand Up @@ -343,11 +347,15 @@ endmacro()
macro(_ov_find_intel_cpu_dependencies)
set(_OV_ENABLE_CPU_ACL "@DNNL_USE_ACL@")
if(_OV_ENABLE_CPU_ACL)
set(_ov_in_install_tree "@PACKAGE_ARM_COMPUTE_LIB_DIR@")
set(_ov_in_install_tree "@PACKAGE_OPENVINO_LIB_DIR@")
if(_ov_in_install_tree)
set_and_check(ARM_COMPUTE_LIB_DIR "@PACKAGE_ARM_COMPUTE_LIB_DIR@")
set_and_check(ARM_COMPUTE_LIB_DIR "@PACKAGE_OPENVINO_LIB_DIR@")
set(ACL_DIR "${CMAKE_CURRENT_LIST_DIR}")
else()
if(NOT TARGET arm_compute::arm_compute)
# for case when build tree is used separately, e.g. OpenVINODeveloperPackageConfig.cmake
set_and_check(ARM_COMPUTE_LIB_DIR "@PACKAGE_CMAKE_ARCHIVE_OUTPUT_DIRECTORY@")
endif()
set_and_check(ACL_DIR "@PACKAGE_FIND_ACL_PATH@")
endif()

Expand All @@ -363,16 +371,50 @@ macro(_ov_find_intel_gpu_dependencies)
set(_OV_ENABLE_INTEL_GPU "@ENABLE_INTEL_GPU@")
set(_OV_ENABLE_SYSTEM_OPENCL "@ENABLE_SYSTEM_OPENCL@")
if(_OV_ENABLE_INTEL_GPU AND _OV_ENABLE_SYSTEM_OPENCL)
set(_OV_OpenCLICDLoader_FOUND "@OpenCLICDLoader_FOUND@")
if(_OV_OpenCLICDLoader_FOUND)
_ov_find_dependency(OpenCLICDLoader)
else()
_ov_find_dependency(OpenCL)
endif()
unset(_OV_OpenCLICDLoader_FOUND)
_ov_find_dependency(OpenCL)
endif()
unset(_OV_ENABLE_INTEL_GPU)
unset(_OV_ENABLE_SYSTEM_OPENCL)

set(_OV_ENABLE_ONEDNN_FOR_GPU "@ENABLE_ONEDNN_FOR_GPU@")
if(_OV_ENABLE_ONEDNN_FOR_GPU AND NOT TARGET onednn_gpu_tgt)
set(_OV_DNNL_GPU_LIBRARY_NAME "@DNNL_GPU_LIBRARY_NAME@")

set(_ov_in_install_tree "@PACKAGE_OPENVINO_LIB_DIR@")
if(_ov_in_install_tree)
set(onednn_gpu_lib "${CMAKE_STATIC_LIBRARY_PREFIX}${_OV_DNNL_GPU_LIBRARY_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set_and_check(onednn_gpu_lib_root "@PACKAGE_OPENVINO_LIB_DIR@")
if(WIN32)
if(OV_GENERATOR_MULTI_CONFIG)
set(extra_args PATH_SUFFIXES ${CMAKE_CONFIGURATION_TYPES})
else()
set(extra_args PATH_SUFFIXES ${CMAKE_BUILD_TYPE})
endif()
endif()

find_library(onednn_gpu_lib_path
NAMES ${_OV_DNNL_GPU_LIBRARY_NAME}
PATHS ${onednn_gpu_lib_root}
${extra_args})

if(NOT onednn_gpu_lib_path)
message(FATAL_ERROR "Internal error: failed to find '${_OV_DNNL_GPU_LIBRARY_NAME}' in '${onednn_gpu_lib_root}'")
endif()

unset(extra_args)
unset(onednn_gpu_lib)
else()
set_and_check(onednn_gpu_lib_path "@PACKAGE_ONEDNN_GPU_LIB_PATH@")
endif()

set_target_properties(openvino::onednn_gpu_tgt PROPERTIES
INTERFACE_LINK_LIBRARIES "${onednn_gpu_lib_path}")

unset(onednn_gpu_lib_path)
unset(_ov_in_install_tree)
unset(_OV_DNNL_GPU_LIBRARY_NAME)
endif()
unset(_OV_ENABLE_ONEDNN_FOR_GPU)
endmacro()

macro(_ov_find_intel_gna_dependencies)
Expand Down Expand Up @@ -455,6 +497,7 @@ set(_OV_ENABLE_OPENVINO_BUILD_SHARED "@BUILD_SHARED_LIBS@")

if(NOT TARGET openvino)
set(_ov_as_external_package ON)
include("${CMAKE_CURRENT_LIST_DIR}/OpenVINOTargets.cmake")
endif()

if(NOT _OV_ENABLE_OPENVINO_BUILD_SHARED)
Expand Down Expand Up @@ -487,8 +530,6 @@ set(_ov_imported_libs openvino::runtime openvino::runtime::c
openvino::frontend::pytorch openvino::frontend::tensorflow_lite)

if(_ov_as_external_package)
include("${CMAKE_CURRENT_LIST_DIR}/OpenVINOTargets.cmake")

foreach(target IN LISTS _ov_imported_libs)
if(TARGET ${target})
get_target_property(imported_configs ${target} IMPORTED_CONFIGURATIONS)
Expand Down
15 changes: 8 additions & 7 deletions src/cmake/openvino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ if(ENABLE_INTEL_GNA)
list(APPEND PATH_VARS "GNA_PATH")
endif()
if(DNNL_USE_ACL)
list(APPEND BUILD_PATH_VARS "FIND_ACL_PATH")
list(APPEND BUILD_PATH_VARS "FIND_ACL_PATH;CMAKE_ARCHIVE_OUTPUT_DIRECTORY")
set(FIND_ACL_PATH "${intel_cpu_thirdparty_SOURCE_DIR}")
endif()
if(ENABLE_ONEDNN_FOR_GPU)
list(APPEND BUILD_PATH_VARS "ONEDNN_GPU_LIB_PATH")
endif()

set(PUBLIC_HEADERS_DIR "${OpenVINO_SOURCE_DIR}/src/inference/include")
set(IE_INCLUDE_DIR "${PUBLIC_HEADERS_DIR}/ie")
Expand All @@ -177,12 +180,10 @@ configure_package_config_file("${OpenVINO_SOURCE_DIR}/cmake/templates/OpenVINOCo

# install tree

if(DNNL_USE_ACL)
list(APPEND INSTALL_PATH_VARS "ARM_COMPUTE_LIB_DIR")
# remove generator expression at the end, because searching in Release / Debug will be
# done by ACLConfig.cmake itself
string(REPLACE "$<CONFIG>" "" ARM_COMPUTE_LIB_DIR "${OV_CPACK_LIBRARYDIR}")
endif()
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
string(REPLACE "$<CONFIG>" "" OPENVINO_LIB_DIR "${OV_CPACK_LIBRARYDIR}")

set(IE_INCLUDE_DIR "${OV_CPACK_INCLUDEDIR}/ie")
set(IE_TBB_DIR "${IE_TBB_DIR_INSTALL}")
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ function(ov_add_onednn)
add_subdirectory(onednn EXCLUDE_FROM_ALL)

# install static libraries
ov_install_static_lib(dnnl cpu)
ov_install_static_lib(dnnl ${OV_CPACK_COMP_CORE})

if(DNNL_USE_ACL AND NOT BUILD_SHARED_LIBS)
# use ACLConfig.cmake in OpenVINOConfig.cmake in case of static build
# we cannot use 'ov_install_static_lib' for imported targets,
# but for this we need to install library files
install(FILES $<TARGET_PROPERTY:arm_compute::arm_compute,IMPORTED_LOCATION>
DESTINATION ${OV_CPACK_ARCHIVEDIR}
COMPONENT cpu)
COMPONENT ${OV_CPACK_COMP_CORE})
install(FILES "${intel_cpu_thirdparty_SOURCE_DIR}/ACLConfig.cmake"
DESTINATION ${OV_CPACK_OPENVINO_CMAKEDIR}
COMPONENT core_dev)
COMPONENT ${OV_CPACK_COMP_CORE_DEV})
endif()
endfunction()

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

ov_add_onednn()
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ elseif((NOT ANDROID) AND (UNIX))
target_link_libraries(${TARGET_NAME} PRIVATE pthread)
endif()

ov_install_static_lib(${TARGET_NAME} gpu)
ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE})

if(ENABLE_SSE42)
ie_sse42_optimization_flags(sse4_2_flags)
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ add_custom_command(
TARGET ${TARGET_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/cache/cache.json ${TUNING_CACHE_PATH}/cache.json)

if(BUILD_SHARED_LIBS)
set(CACHE_JSON_INSTALL_DIR ${OV_CPACK_PLUGINSDIR})
set(CACHE_JSON_COMPONENT gpu)
else()
set(CACHE_JSON_INSTALL_DIR ${OV_CPACK_ARCHIVEDIR})
set(CACHE_JSON_COMPONENT ${OV_CPACK_COMP_CORE})
endif()

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cache/cache.json
DESTINATION ${OV_CPACK_PLUGINSDIR}
COMPONENT gpu)
DESTINATION ${CACHE_JSON_INSTALL_DIR}
COMPONENT ${CACHE_JSON_COMPONENT})

ov_install_static_lib(${TARGET_NAME} gpu)
ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE})
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ elseif((NOT ANDROID) AND (UNIX))
target_link_libraries(${TARGET_NAME} PRIVATE pthread)
endif()

ov_install_static_lib(${TARGET_NAME} gpu)
ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE})
29 changes: 22 additions & 7 deletions src/plugins/intel_gpu/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
if(ENABLE_ONEDNN_FOR_GPU)
function(build_onednn_gpu)
include(ExternalProject)
set(ONEDNN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_build/")
set(ONEDNN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_install/")
set(ONEDNN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_build")
set(ONEDNN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_install" CACHE PATH "Installation path for oneDNN GPU library")
set(ONEDNN_PREFIX_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_root")
set(ONEDNN_ENABLED_PRIMITIVES "CONCAT;CONVOLUTION;DECONVOLUTION;INNER_PRODUCT;MATMUL;REORDER;POOLING;REDUCTION")
set(ONEDNN_ENABLED_ISA "XEHP;XEHPG;XEHPC")
set(DNNL_GPU_LIBRARY_NAME "openvino_onednn_gpu" CACHE STRING "Name of oneDNN library for Intel GPU Plugin")

if(X86_64)
set(ONEDNN_TARGET_ARCH "X64" CACHE STRING "" FORCE)
Expand Down Expand Up @@ -79,6 +80,9 @@ if(ENABLE_ONEDNN_FOR_GPU)
list(APPEND cmake_extra_args "-DOpenCL_INCLUDE_DIR=${OpenCL_INCLUDE_DIR}")
endif()

set(onednn_gpu_lib "${CMAKE_STATIC_LIBRARY_PREFIX}${DNNL_GPU_LIBRARY_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(ONEDNN_GPU_LIB_PATH ${ONEDNN_INSTALL_DIR}/lib/${onednn_gpu_lib} CACHE FILEPATH "Path to oneDNN GPU library")

ExternalProject_Add(onednn_gpu_build
# Directory Options:
PREFIX "${ONEDNN_PREFIX_DIR}"
Expand All @@ -99,7 +103,7 @@ if(ENABLE_ONEDNN_FOR_GPU)
"-DDNNL_TARGET_ARCH=${ONEDNN_TARGET_ARCH}"
"-DDNNL_CPU_RUNTIME=NONE"
"-DDNNL_GPU_RUNTIME=OCL"
"-DDNNL_LIBRARY_NAME=openvino_onednn_gpu"
"-DDNNL_LIBRARY_NAME=${DNNL_GPU_LIBRARY_NAME}"
"-DCMAKE_INSTALL_PREFIX=${ONEDNN_INSTALL_DIR}"
"-DDNNL_ENABLE_CONCURRENT_EXEC=ON"
"-DDNNL_ENABLE_PRIMITIVE_CACHE=OFF"
Expand All @@ -124,18 +128,29 @@ if(ENABLE_ONEDNN_FOR_GPU)
# Thus we pass it via CMAKE_CACHE_ARGS
"-DDNNL_ENABLE_PRIMITIVE:STRING=${ONEDNN_ENABLED_PRIMITIVES}"
"-DDNNL_ENABLE_PRIMITIVE_GPU_ISA:STRING=${ONEDNN_ENABLED_ISA}"
# Build Step Options:
BUILD_BYPRODUCTS ${ONEDNN_GPU_LIB_PATH}
# Target Options:
EXCLUDE_FROM_ALL ON
)

add_library(onednn_gpu_tgt INTERFACE)
set_target_properties(onednn_gpu_tgt PROPERTIES
INTERFACE_LINK_DIRECTORIES "${ONEDNN_INSTALL_DIR}/lib"
INTERFACE_LINK_LIBRARIES "openvino_onednn_gpu"
INTERFACE_INCLUDE_DIRECTORIES "${ONEDNN_INSTALL_DIR}/include"
INTERFACE_LINK_LIBRARIES $<BUILD_INTERFACE:${ONEDNN_GPU_LIB_PATH}>
INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${ONEDNN_INSTALL_DIR}/include>
INTERFACE_COMPILE_DEFINITIONS ENABLE_ONEDNN_FOR_GPU
)
add_dependencies(onednn_gpu_tgt onednn_gpu_build)
# TODO: install onednn_gpu in static builds

if(NOT BUILD_SHARED_LIBS)
ov_install_static_lib(onednn_gpu_tgt ${OV_CPACK_COMP_CORE})

# we need to install library explicitly and set_target_properties in OpenVINOConfig.cmake for 'onednn_gpu_tgt'
# to point to installation location of this file
install(FILES "${ONEDNN_GPU_LIB_PATH}"
DESTINATION ${OV_CPACK_ARCHIVEDIR}
COMPONENT ${OV_CPACK_COMP_CORE})
endif()
endfunction()
build_onednn_gpu()
endif()
2 changes: 1 addition & 1 deletion src/plugins/template/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ openvino_developer_export_targets(COMPONENT core TARGETS interpreter_backend)

# install

ov_install_static_lib(interpreter_backend template)
ov_install_static_lib(interpreter_backend ${OV_CPACK_COMP_CORE})
4 changes: 2 additions & 2 deletions src/plugins/template/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${TEMPLATE_PLUGIN_SOURCE_DIR}/include")

# link common Inference Engine libraries
# link common OpenVINO Runtime libraries
target_link_libraries(${TARGET_NAME} PRIVATE
openvino::interpreter_backend
openvino::reference)
Expand All @@ -42,4 +42,4 @@ endif()
# [cmake:plugin]

install(TARGETS ${TARGET_NAME}
LIBRARY DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL)
LIBRARY DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL)
2 changes: 1 addition & 1 deletion thirdparty/ocl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ set(opencl_root_hints "${OpenCL_INCLUDE_DIR}" PARENT_SCOPE)

# installation

ov_install_static_lib(OpenCL gpu)
ov_install_static_lib(OpenCL ${OV_CPACK_COMP_CORE})

0 comments on commit 253ca8c

Please sign in to comment.