Skip to content

Commit

Permalink
Enable plugin compilation (openvinotoolkit#3)
Browse files Browse the repository at this point in the history
* Enable to compile gna plugin (only)

* add readme with BKM how to compile plugin

* enable unit tests except deprecated subset
  • Loading branch information
ptomasz1 committed Aug 24, 2023
1 parent b7a2b7a commit 05e54ec
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 50 deletions.
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@
# SPDX-License-Identifier: Apache-2.0
#

if (NOT ENABLE_INTEL_GNA)
return()
endif()
cmake_minimum_required(VERSION 3.22)

project(OpenvinoGnaPlugin)

find_package(OpenVINODeveloperPackage REQUIRED)

set(GNA_LIB_VERSION "03.05.00.1906" CACHE STRING "GNA Library version number")
set(GNA_ROOT_DIR ${OpenVINO_SOURCE_DIR}/temp/gna_${GNA_LIB_VERSION})

set(GNA_PATH ${GNA_ROOT_DIR}/win64/x64)
set(GNA_EXT_DIR ${GNA_ROOT_DIR})

set(GNA_PLUGIN_OUTPUT_DIR ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${GNA_PLUGIN_OUTPUT_DIR}/${BIN_FOLDER})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${GNA_PLUGIN_OUTPUT_DIR}/${BIN_FOLDER})
set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${GNA_PLUGIN_OUTPUT_DIR}/${BIN_FOLDER})
set(CMAKE_PDB_OUTPUT_DIRECTORY ${GNA_PLUGIN_OUTPUT_DIR}/${BIN_FOLDER})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${GNA_PLUGIN_OUTPUT_DIR}/${BIN_FOLDER})

message("OpenVINO source directory = ${OpenVINO_SOURCE_DIR}")
message("GNA package directory = ${GNA_ROOT_DIR}")
message("Artifacts directory = ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

enable_testing()

#deal with setup of legacy projects first...
add_subdirectory(legacy)

set(TARGET_NAME "openvino_intel_gna_plugin")
Expand Down Expand Up @@ -76,13 +98,17 @@ target_compile_definitions(${TARGET_NAME}_test_static
INTEGER_LOW_P
USE_STATIC_IE)

target_link_libraries(${TARGET_NAME}_test_static PUBLIC inference_engine_s inference_engine_transformations libGNA::API)

target_link_libraries(${TARGET_NAME}_test_static
PUBLIC debug inference_engine_sd optimized inference_engine_s
PUBLIC libGNA::API)
target_include_directories(${TARGET_NAME}_test_static
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
$<TARGET_PROPERTY:inference_engine_legacy,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE
$<TARGET_PROPERTY:openvino::conditional_compilation,INTERFACE_INCLUDE_DIRECTORIES>)
$<TARGET_PROPERTY:openvino::conditional_compilation,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>)

set_target_properties(${TARGET_NAME} ${TARGET_NAME}_test_static
PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
Expand Down
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
## Plugin Compilation


#### Assumptions

- OpenVINO version used 2023.0 (**branch releases/2023/0**)
- Commands syntax is bash-based
- There are following (environmental) variables defined:
````bash
export openvino_source_dir = <path to local openvino source directory>
export developer_package_dir = <path to generated developer package directory>
export build_type = <Release|Debug|etc.>
export gna_plugin_source_dir = <path to local gna plugin souce directory>
export gna_plugin_build_dir = <path to generated gna plugin build>
````


#### Prerequisties

Switch to respective version of openvino
````bash
cd $openvino_source_dir
git checkout releases/2023/0
````

Prepare openvino developer package (build openvino)
````bash
cmake -S $openvino_source_dir -B $developer_package_dir -D CMAKE_BUILD_TYPE=$build_type -D ENABLE_TESTS=ON -D ENABLE_FUNCTIONAL_TESTS=ON
cmake --build $developer_package_dir --target ov_dev_targets --config $build_type
````
> **Note**
> - It's important to keep in mind that `CMAKE_BUILD_TYPE` has no effect for multi-configuration generators such as Visual Studio. Therefore in this case config type has to be provided to build command as above.
> - There is yet another target `ie_dev_targets` can be used, but it seems to have identical result as `ov_dev_targets`
Clone **gna.plugin** repository
````bash
git clone https://github.com/intel-innersource/frameworks.ai.gna.plugin.git $gna_plugin_source_dir
````


#### Plugin build

Create **gna.plugin** solution
````bash
cmake -S $gna_plugin_source_dir -B $gna_plugin_build_dir -D OpenVINODeveloperPackage_DIR=$developer_package_dir -D ENABLE_TESTS=ON -D ENABLE_FUNCTIONAL_TESTS=ON
````

It happens often that for development purposes many versions of gna library exist in openvino `temp\` directory. Therefore it is possible to use specific version of the library by defining `GNA_LIB_VERSION` otherwise default version defined in main `CMakeLists.txt` will be applied
````bash
export gna_version=<number of specific gna version>
cmake -S $gna_plugin_source_dir -B $gna_plugin_build_dir -D OpenVINODeveloperPackage_DIR=$developer_package_dir -D ENABLE_TESTS=ON -D ENABLE_FUNCTIONAL_TESTS=ON -D GNA_LIB_VERSION=$gna_version
````


Run build
````bash
cmake --build $gna_plugin_build_dir --config $build_type
````
> **Note**
> Developer package has bo be built for respective configuration type otherwise gna plugin build will fail.
#### Plugin's tests build and run

By default all tests are compiled during plugin build, however there is a possibility to selectively compile selected tests by using `--target` option.

For example to compile unit tests use `ov_gna_unit_tests` target run
````bash
cmake --build $gna_plugin_build_dir --config $build_type --target ov_gna_unit_tests
````

In order to run tests do
````bash
cd $gna_plugin_build_dir
ctest -C $build_type
````

> **Note**
> Currently only `ov_gna_unit_tests` are supported
#### Handy tips

Sometimes it is handy to run cmake project generation in trace mode in order to figure out what happened. In order to do this add cmake's `--trace-source=<name of cmakefile to trace>` option. Besides option `--trace-expand` will expand variable into their values.

For example command below will print out trace messsages from `libGNAConfig.cmake` file
````bash
cmake -S $gna_plugin_source_dir -B $gna_plugin_build_dir -D OpenVINODeveloperPackage_DIR=$developer_package_dir -D OV_ROOT_DIR=$openvino_source_dir --trace-source=libGNAConfig.cmake --trace-expand
````

#### References

https://docs.openvino.ai/2022.1/openvino_docs_ie_plugin_dg_plugin_build.html
https://docs.openvino.ai/2022.3/openvino_docs_ie_plugin_dg_plugin_build.html
6 changes: 3 additions & 3 deletions legacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ ie_faster_build(${TARGET_NAME}_obj
target_include_directories(${TARGET_NAME}_obj PRIVATE
${PUBLIC_HEADERS_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src
$<TARGET_PROPERTY:inference_engine_obj,SOURCE_DIR>/src # For CNNNetworkNGraphImpl
${OpenVINO_SOURCE_DIR}/src/inference/src #For CNNNetworkNGraphImpl. ptomasz1: Dirty hack, but inference_engine_obj is not exported in developer package
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::pugixml,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino_intel_gna_plugin,SOURCE_DIR>/src/ops)

target_compile_definitions(${TARGET_NAME}_obj PRIVATE $<TARGET_PROPERTY:ngraph,INTERFACE_COMPILE_DEFINITIONS>)
target_compile_definitions(${TARGET_NAME}_obj PRIVATE $<TARGET_PROPERTY:openvino::ngraph_reference,INTERFACE_COMPILE_DEFINITIONS>)

target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::itt)

Expand Down Expand Up @@ -69,7 +69,7 @@ target_include_directories(${TARGET_NAME}_s
$<BUILD_INTERFACE:${PUBLIC_HEADERS_DIR}>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
$<TARGET_PROPERTY:inference_engine_obj,SOURCE_DIR>/src # For CNNNetworkNGraphImpl
${OpenVINO_SOURCE_DIR}/src/inference/src #For CNNNetworkNGraphImpl. ptomasz1: Dirty hack, but inference_engine_obj is not exported in developer package
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::pugixml,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino_intel_gna_plugin,SOURCE_DIR>/src/ops)
Expand Down
42 changes: 27 additions & 15 deletions legacy/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,36 @@ endif()

set(TARGET_NAME ov_legacy_transformations_tests)

ov_add_test_target(
NAME ${TARGET_NAME}
ROOT ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDENCIES
LINK_LIBRARIES
gmock
func_test_utils
sharedTestClasses
lptNgraphFunctions
inference_engine_legacy
ADD_CLANG_FORMAT
INCLUDES
$<TARGET_PROPERTY:inference_engine_obj,SOURCE_DIR>/src
LABELS
TRANSFORMATIONS
file(GLOB MODULE_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
)

add_executable(${TARGET_NAME} ${MODULE_SOURCES})

target_include_directories(${TARGET_NAME} PRIVATE
$<TARGET_PROPERTY:inference_engine_legacy_obj,INTERFACE_INCLUDE_DIRECTORIES>
${OV_ROOT_DIR}/src/inference/src #For CNNNetworkNGraphImpl. ptomasz1: Dirty hack, but inference_engine_obj is not exported in developer package
)

target_link_libraries(${TARGET_NAME}
openvino::gmock
openvino::gtest
openvino::gtest_main
openvino::ngraphFunctions
openvino::commonTestUtils
openvino::funcTestUtils
inference_engine_legacy
)

if(WIN32)
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
endif()

set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${OpenVINO_SOURCE_DIR}/temp/tbb/bin;${OpenVINO_SOURCE_DIR}/${BIN_FOLDER}/$<CONFIG>")

add_test(NAME ${TARGET_NAME}_run COMMAND ${TARGET_NAME})
set_tests_properties(${TARGET_NAME}_run PROPERTIES ENVIRONMENT "PATH=${OpenVINO_SOURCE_DIR}/temp/tbb/bin")
set_tests_properties(${TARGET_NAME}_run PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_append:${OpenVINO_SOURCE_DIR}/${BIN_FOLDER}/$<CONFIG>")

1 change: 0 additions & 1 deletion legacy/tests/keep_constant_inputs_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <transformations/opset_conversions/convert_opset3_to_opset2.hpp>

#include "ngraph_functions/subgraph_builders.hpp"
#include "shared_test_classes/base/low_precision_transformations/layer_transformation.hpp"

using namespace testing;
using namespace InferenceEngine;
Expand Down
1 change: 0 additions & 1 deletion legacy/tests/mul_add_conversion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "common_test_utils/ngraph_test_utils.hpp"
#include "common_test_utils/test_common.hpp"
#include "lpt_ngraph_functions/common/builders.hpp"

using namespace testing;

Expand Down
10 changes: 3 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
#

enable_testing()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
ie_add_compiler_flags(/wd4244)
ie_add_compiler_flags(/wd4267)
Expand All @@ -20,13 +18,11 @@ else()
endif()

if(ENABLE_TESTS)
add_subdirectory(deprecated/readers)
add_subdirectory(deprecated/helpers)

add_subdirectory(unit)
add_subdirectory(deprecated/unit)
# add_subdirectory(deprecated/unit)
endif()

if(ENABLE_FUNCTIONAL_TESTS)
add_subdirectory(functional)
# add_subdirectory(deprecated/functional)
# add_subdirectory(functional)
endif()
56 changes: 38 additions & 18 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,52 @@ if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
endif()

# TODO: fix CVS-71010 and remove BUILD_SHARED_LIBS
if(NOT BUILD_SHARED_LIBS)
set(exclude_path EXCLUDED_SOURCE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/(gna_api_stub|gna_wait_test|gna_export_import_test|gna_infer_request_test|gna_plugin_load_network_test|gna_mock_api_initializer|gna_extra_pwl_segments_tests).cpp")
endif()
file(GLOB MODULE_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/**/*.hpp"
)

add_executable(${TARGET_NAME} ${MODULE_SOURCES})

target_link_libraries(${TARGET_NAME}
openvino::gmock
openvino::gtest
openvino::gtest_main
openvino::ngraphFunctions
openvino::commonTestUtils
inference_engine_legacy_s
openvino_intel_gna_plugin_test_static
)

addIeTargetTest(
NAME ${TARGET_NAME}
ROOT ${CMAKE_CURRENT_SOURCE_DIR}
${exclude_path}
LINK_LIBRARIES
PRIVATE
ngraphFunctions
gmock
common_test_utils_s
openvino_intel_gna_plugin_test_static
inference_engine_legacy_s
ADD_CLANG_FORMAT
LABELS
GNA
target_include_directories(${TARGET_NAME}
PRIVATE ${OpenVINO_SOURCE_DIR}/src/inference/src
)

#needed in order to locate inference_engine_s.lib
target_link_directories(${TARGET_NAME}
PRIVATE "${OpenVINO_SOURCE_DIR}/bin/intel64/$<CONFIG>"
)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS -IGNORE:4286)

#FIXME the flag allows to solve linker error 2005 (Symbol already defined)
# by taking into account first occurence of the symbol and ignoring rest of them.
# In this case the problem ocucrs in Release version only.
# Duplicated symbol definitions are generated by all source files include "ie_common.h" header
# Very likely the issue is caused by IE_ASSERT definition in ie_common.h:450-452.
target_link_options(${TARGET_NAME} PRIVATE "/FORCE")
endif()

if(SUGGEST_OVERRIDE_SUPPORTED)
set_source_files_properties(gna_model_serial_test.cpp
PROPERTIES COMPILE_OPTIONS -Wno-suggest-override)
endif()

set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${OpenVINO_SOURCE_DIR}/temp/tbb/bin;${OpenVINO_SOURCE_DIR}/${BIN_FOLDER}/$<CONFIG>")

add_test(NAME ${TARGET_NAME}_run COMMAND ${TARGET_NAME})
set_tests_properties(${TARGET_NAME}_run PROPERTIES ENVIRONMENT "PATH=${OpenVINO_SOURCE_DIR}/temp/tbb/bin")
set_tests_properties(${TARGET_NAME}_run PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_append:${OpenVINO_SOURCE_DIR}/${BIN_FOLDER}/$<CONFIG>")

0 comments on commit 05e54ec

Please sign in to comment.