Skip to content
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
67 changes: 31 additions & 36 deletions backends/openvino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,69 @@
# except in compliance with the License. See the license file in the root
# directory of this source tree for more details.

# Set minimum required CMake version
cmake_minimum_required(VERSION 3.19)

# Set project name
project(openvino_backend_project)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Ensure compile_commands are generated
# Ensure compile_commands.json is generated
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Define common include directories
set(COMMON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

# Include common directories before others to ensure proper order
include_directories(BEFORE ${COMMON_INCLUDE_DIRS})

# Set up EXECUTORCH_ROOT if not already set
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()

# Include utility cmake script from the executorch repository
include(${EXECUTORCH_ROOT}/build/Utils.cmake)

# Update common include directory for ExecuteTorch
# Define common include directories
set(COMMON_INCLUDE_DIRS ${EXECUTORCH_ROOT}/..)

# Set OpenVINO directory and include directories from environment variable
# Include utility CMake scripts from ExecuteTorch
include(${EXECUTORCH_ROOT}/build/Utils.cmake)

# Set OpenVINO directory from environment variable
set(OPENVINO_DIR "$ENV{INTEL_OPENVINO_DIR}")
if(NOT OPENVINO_DIR)
message(FATAL_ERROR "INTEL_OPENVINO_DIR environment variable is not set.")
message(FATAL_ERROR "ERROR: INTEL_OPENVINO_DIR environment variable is not set.")
endif()

# Set OpenVINO include directories
set(OPENVINO_INCLUDE_DIRS
${OPENVINO_DIR}/deployment_tools/inference_engine/include
${OPENVINO_DIR}/runtime/include
${OPENVINO_DIR}/deployment_tools/inference_engine/include
)

# Define OpenVINO library path
# Set OpenVINO library path
set(OPENVINO_LIB_PATH ${OPENVINO_DIR}/runtime/lib/intel64)

# Define OpenVINO libraries
set(OPENVINO_LIB ${OPENVINO_LIB_PATH}/libopenvino.so)
# Try to locate OpenVINO automatically
find_library(OPENVINO_LIB NAMES openvino PATHS ${OPENVINO_LIB_PATH} NO_DEFAULT_PATH)
if(NOT OPENVINO_LIB)
message(FATAL_ERROR "ERROR: OpenVINO library (libopenvino.so) not found in ${OPENVINO_LIB_PATH}")
endif()

# Add the OpenVINO backend library as a shared library
# Define OpenVINO backend as a shared library
add_library(openvino_backend SHARED)

# Enable exceptions and RTTI for OpenVINO backend
target_compile_options(openvino_backend PRIVATE "-frtti" "-fexceptions")
target_compile_options(openvino_backend PRIVATE -frtti -fexceptions)

# Include directories for ExecuteTorch and OpenVINO
target_include_directories(
openvino_backend PUBLIC
${COMMON_INCLUDE_DIRS}
${OPENVINO_INCLUDE_DIRS}
)
# Include ExecuteTorch and OpenVINO directories
target_include_directories(openvino_backend PUBLIC ${COMMON_INCLUDE_DIRS} ${OPENVINO_INCLUDE_DIRS})

# Link OpenVINO libraries and executorch core to the backend
target_link_libraries(openvino_backend PRIVATE
${OPENVINO_LIB}
executorch_core
)
# Link OpenVINO and ExecuteTorch core libraries
target_link_libraries(openvino_backend PRIVATE ${OPENVINO_LIB} executorch_core)

# Add source files to the OpenVINO backend library
target_sources(openvino_backend PRIVATE
${CMAKE_CURRENT_LIST_DIR}/runtime/OpenvinoBackend.cpp
)
# Add source files for OpenVINO backend
target_sources(openvino_backend PRIVATE ${CMAKE_CURRENT_LIST_DIR}/runtime/OpenvinoBackend.cpp)

# Set additional link options for shared library
# Set runtime library path for OpenVINO
target_link_options(openvino_backend PRIVATE -Wl,-rpath=${OPENVINO_LIB_PATH})

# Install the OpenVINO backend library to the lib directory
# Install OpenVINO backend library to the lib directory
install(TARGETS openvino_backend DESTINATION lib)

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ main() {
# Configure the project with CMake
# Note: Add any additional configuration options you need here
cmake -DCMAKE_INSTALL_PREFIX="${build_dir}" \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_OPENVINO=ON \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
Expand Down
83 changes: 38 additions & 45 deletions examples/openvino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# except in compliance with the License. See the license file in the root
# directory of this source tree for more details.

set(CMAKE_CXX_STANDARD 17)

cmake_minimum_required(VERSION 3.19)
project(openvino_runner_example)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Source root directory for executorch.
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
Expand All @@ -26,31 +28,20 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

set(_common_compile_options -Wno-deprecated-declarations -fPIC)

# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)

#
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
#
set(EXECUTORCH_SRCS_FILE
"${CMAKE_CURRENT_BINARY_DIR}/../../../build/executorch_srcs.cmake"
)
set(EXECUTORCH_SRCS_FILE "${CMAKE_CURRENT_BINARY_DIR}/../../../build/executorch_srcs.cmake")
extract_sources(${EXECUTORCH_SRCS_FILE})
include(${EXECUTORCH_SRCS_FILE})

set(_openvino_executor_runner__srcs ${CMAKE_CURRENT_LIST_DIR}/../openvino/executor_runner/openvino_executor_runner.cpp)

# preprocess executor runner src files
list(PREPEND _openvino_executor_runner__srcs
${CMAKE_CURRENT_LIST_DIR}/../openvino/executor_runner/openvino_executor_runner.cpp
set(_openvino_executor_runner__srcs
${CMAKE_CURRENT_LIST_DIR}/../openvino/executor_runner/openvino_executor_runner.cpp
)

find_package(executorch CONFIG REQUIRED)
target_include_directories(executorch INTERFACE ${_common_include_directories})
target_compile_options(executorch INTERFACE ${_common_compile_options})
include_directories(${EXECUTORCH_INCLUDE_DIRS})

# portable_ops_lib
# Portable Ops Library
gen_selected_ops(LIB_NAME "openvino_portable_ops_lib" INCLUDE_ALL_OPS "ON")
generate_bindings_for_kernels(
LIB_NAME "openvino_portable_ops_lib" FUNCTIONS_YAML
Expand All @@ -59,43 +50,45 @@ generate_bindings_for_kernels(
gen_operators_lib(
LIB_NAME "openvino_portable_ops_lib" KERNEL_LIBS portable_kernels DEPS executorch
)
target_compile_options(
openvino_portable_ops_lib INTERFACE -DET_EVENT_TRACER_ENABLED
)
target_include_directories(
openvino_portable_ops_lib PUBLIC ${_common_include_directories}
)
target_compile_options(openvino_portable_ops_lib INTERFACE -DET_EVENT_TRACER_ENABLED)
target_include_directories(openvino_portable_ops_lib PUBLIC ${_common_include_directories})


# build executor runner
# Build Executor Runner
add_executable(openvino_executor_runner ${_openvino_executor_runner__srcs})
target_include_directories(
openvino_executor_runner PUBLIC ${_common_include_directories}
openvino_executor_runner PUBLIC ${_common_include_directories} ${EXECUTORCH_ROOT}/cmake-openvino-out/third-party/gflags/include
)

# Set the path to the library directory
set(LIBRARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../cmake-openvino-out/lib/")

# List the libraries you want to link (without the 'lib' prefix and file extension)
set(LIBRARIES_TO_LINK ${LIBRARY_DIR}/libopenvino_backend.so
${LIBRARY_DIR}/libexecutorch.a
${LIBRARY_DIR}/libexecutorch_core.a
${EXECUTORCH_ROOT}/third-party/gflags/build/lib/libgflags_nothreads.a
${LIBRARY_DIR}/libpthreadpool.a
${LIBRARY_DIR}/libextension_data_loader.a
${LIBRARY_DIR}/libextension_runner_util.a
)
# Set Library Directory
set(LIBRARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../cmake-openvino-out/lib/;${CMAKE_CURRENT_LIST_DIR}/../../cmake-openvino-out/third-party/gflags")
message(STATUS "Library directory path: ${LIBRARY_DIR}")

# Add the library directory to the link search path
link_directories(${LIBRARY_DIR})
# Locate OpenVINO Backend Library
find_library(OPENVINO_BACKEND_LIB NAMES openvino_backend PATHS ${LIBRARY_DIR} NO_DEFAULT_PATH)
if(NOT OPENVINO_BACKEND_LIB)
message(FATAL_ERROR "OpenVINO backend library not found in ${LIBRARY_DIR}")
endif()

# Link all libraries at once
target_link_libraries(openvino_executor_runner PRIVATE ${LIBRARIES_TO_LINK} openvino_portable_ops_lib)
# Locate OpenVINO Backend Library
find_library(GFLAGS_LIB NAMES gflags_nothreads PATHS ${LIBRARY_DIR} NO_DEFAULT_PATH)
if(NOT GFLAGS_LIB)
message(FATAL_ERROR "Gflags library not found in ${LIBRARY_DIR}")
endif()

set_target_properties(
openvino_executor_runner PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"
# Link Libraries
target_link_libraries(openvino_executor_runner PRIVATE
${OPENVINO_BACKEND_LIB}
${GFLAGS_LIB}
executorch
executorch_core
openvino_portable_ops_lib
extension_data_loader
extension_runner_util
pthreadpool
)

# Ensure Proper RPATH Handling
set_target_properties(openvino_executor_runner PROPERTIES INSTALL_RPATH "$ORIGIN")

get_filename_component(
EXECUTORCH_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ main() {
# Configure the project with CMake
# Note: Add any additional configuration options you need here
cmake -DCMAKE_INSTALL_PREFIX="${build_dir}" \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_OPENVINO=ON \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
Expand All @@ -27,7 +28,7 @@ main() {


# Build the project
cmake --build cmake-openvino-out --target install --config Release -j5
cmake --build cmake-openvino-out --target install --config Release -j$(nproc)

## Build example
local example_dir=examples/openvino
Expand All @@ -41,7 +42,7 @@ main() {
-B"${example_build_dir}" \
$EXECUTORCH_ROOT/$example_dir

cmake --build "${example_build_dir}" -j5
cmake --build "${example_build_dir}" -j$(nproc)

# Switch back to the original directory
cd - > /dev/null
Expand Down