Refine cmake build: add gtest (#47)

Signed-off-by: xiang.zhang <xiang.zhang@verisilicon.com>
This commit is contained in:
Sven 2021-05-17 13:04:45 +08:00 committed by GitHub
parent cc3b8c1fe0
commit 66dd29703e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 64 additions and 17 deletions

View File

@ -1,15 +1,19 @@
cmake_minimum_required (VERSION 3.3)
cmake_minimum_required (VERSION 3.14)
project(tim-vx)
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror -fPIC -Wno-enum-conversion")
set(CMAKE_CXX_FLAGS "--std=c++14 -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror -fPIC")
OPTION(TIM_VX_ENABLE_TEST "Build the unit test" ON)
OPTION(TIM_VX_ENABLE_LAYOUT_INFER "Enable layout inference support" ON)
OPTION(ENABLE_LAYOUT_INFER "add layout inference support" ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror -Wno-enum-conversion")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Werror")
if(NOT DEFINED CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE)
endif()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(OVXLIB_API_ATTR "__attribute__\(\(visibility\(\"default\"\)\)\)")
message(${OVXLIB_API_ATTR})
add_definitions(-DOVXLIB_API=${OVXLIB_API_ATTR})
if(EXTERNAL_VIV_SDK AND EXISTS ${EXTERNAL_VIV_SDK})
# this is for internal development purpose
@ -26,6 +30,18 @@ else()
endif()
endif()
if(TIM_VX_ENABLE_TEST)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
include_directories(${PROJECT_SOURCE_DIR}/include/tim/vx)
include_directories(${OVXDRV_INCLUDE_DIRS})

View File

@ -27,14 +27,25 @@
#include <map>
#include <vector>
#include "tim/vx/context.h"
#include "tim/vx/graph.h"
namespace tim {
namespace vx {
class Context;
class Graph;
class Tensor;
class Operation;
}
namespace transform {
std::pair<std::shared_ptr<vx::Graph>, /* infer graph */
std::map<std::shared_ptr<vx::Tensor>,
std::shared_ptr<vx::Tensor>> /* graph io tensor map */>
std::pair<
/*graph after layout inference*/
std::shared_ptr<vx::Graph>,
/* tensor mapping between original graph and graph after layout infer*/
std::map<
std::shared_ptr<vx::Tensor>,
std::shared_ptr<vx::Tensor>>
>
LayoutInference(const std::shared_ptr<vx::Graph>& src_graph,
std::shared_ptr<vx::Context>& ctx);

View File

@ -18,7 +18,7 @@ include_directories(${PROJECT_SOURCE_DIR}/include/tim/vx)
include_directories(${PROJECT_SOURCE_DIR}/src/tim/vx)
include_directories(${PROJECT_SOURCE_DIR}/src/tim/vx/internal/include)
if(ENABLE_LAYOUT_INFER)
if(TIM_VX_ENABLE_LAYOUT_INFER)
include_directories(${PROJECT_SOURCE_DIR}/)
aux_source_directory(./transform LAYOUT_INFER_FRAMEWORK_SRCS)
@ -30,9 +30,13 @@ if(ENABLE_LAYOUT_INFER)
)
endif()
set(UT_SRC)
aux_source_directory(./vx/ut VX_UT_SRC)
list(APPEND UT_SRC ${VX_UT_SRC})
foreach(src_file ${SRC})
if(${src_file} MATCHES ".*_test\.cc")
list(REMOVE_ITEM SRC ${src_file})
list(APPEND UT_SRC ${src_file})
endif()
endforeach()
@ -45,10 +49,19 @@ target_link_libraries(${TARGET_NAME}-static PRIVATE
-Wl,--whole-archive tim_internal -Wl,--no-whole-archive)
install(TARGETS ${TARGET_NAME} ${TARGET_NAME}-static
DESTINATION ${CMAKE_BINARY_DIR}/install/lib)
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/vx DESTINATION ${CMAKE_BINARY_DIR}/install/include/tim/)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/vx DESTINATION ${CMAKE_INSTALL_PREFIX}/include/tim/)
if(ENABLE_LAYOUT_INFER)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/transform DESTINATION ${CMAKE_BINARY_DIR}/install/include/tim/)
if(TIM_VX_ENABLE_LAYOUT_INFER)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/tim/transform DESTINATION ${CMAKE_INSTALL_PREFIX}/include/tim/)
endif()
if (TIM_VX_ENABLE_TEST)
include(GoogleTest)
add_executable(unit_test ${UT_SRC})
target_link_libraries(unit_test gtest gtest_main ${TARGET_NAME}-static)
install(TARGETS unit_test DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/)
endif()

View File

@ -24,6 +24,7 @@
#include "permute_vector.h"
#include "layout_infer_context.h"
#include "tim/transform/layout_inference.h"
#include "ops/conv2d_layout_inference.h"
#include "ops/reduce_layout_inference.h"
@ -48,6 +49,10 @@
#include <algorithm>
#include <deque>
#include "tim/vx/context.h"
#include "tim/vx/graph.h"
#include "tim/vx/operation.h"
namespace tim {
namespace transform {
namespace layout_inference_impl {

View File

@ -1,6 +1,8 @@
message("src/tim/vx/internal")
set(lib_name "tim_internal")
set(OVXLIB_API_ATTR "__attribute__\(\(visibility\(\"default\"\)\)\)")
add_definitions(-DOVXLIB_API=${OVXLIB_API_ATTR})
aux_source_directory(src INTERNAL_SRC)
aux_source_directory(src/kernel INTERNAL_KERNEL)