diff --git a/CMakeLists.txt b/CMakeLists.txt index 3911488..ab9f6a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(TIM_VX_BUILD_EXAMPLES "Build demos show general usage" option(TIM_VX_ENABLE_VIPLITE "Enable lite driver api support" OFF) option(TIM_VX_ENABLE_40BIT "Enable large memory support" OFF) option(TIM_VX_ENABLE_PLATFORM "Enable multi devices support" OFF) +option(TIM_VX_DBG_ENABLE_TENSOR_HNDL "Enable built-in tensor from handle: use malloced memory instead of VideoMemory by kernel driver" ON) set(CMAKE_CXX_STANDARD 14) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -23,6 +24,12 @@ if(${TIM_VX_CODE_COVERAGE}) set(CMAKE_C_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage") endif() +if(${TIM_VX_DBG_ENABLE_TENSOR_HNDL}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_TENSOR_HNDL=1") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_TENSOR_HNDL=0") +endif() + include(GNUInstallDirs) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE) diff --git a/src/tim/vx/tensor.cc b/src/tim/vx/tensor.cc index 1b1a98d..ae5914d 100644 --- a/src/tim/vx/tensor.cc +++ b/src/tim/vx/tensor.cc @@ -31,6 +31,10 @@ #include "type_utils.h" #include "vsi_nn_pub.h" +#ifndef ENABLE_TENSOR_HNDL +#define ENABLE_TENSOR_HNDL 1 +#endif + namespace { void PackTensorDtype(tim::vx::TensorSpec& spec, vsi_nn_dtype_t* dtype) { @@ -282,6 +286,10 @@ void TensorImpl::unmap() { bool TensorImpl::Init(void *external_cache) { vsi_nn_tensor_attr_t attr; +#if (!ENABLE_TENSOR_HNDL) + (void)external_cache; +#endif + memset(&attr, 0x00, sizeof(attr)); attr.dim_num = spec_.shape_.size(); attr.is_const = static_cast(spec_.attr_ & TensorAttribute::CONSTANT); @@ -299,6 +307,7 @@ bool TensorImpl::Init(void *external_cache) { PackTensorDtype(spec_, &attr.dtype); +#if(ENABLE_TENSOR_HNDL) if ((spec_.attr_ & TensorAttribute::INPUT) || (spec_.attr_ & TensorAttribute::OUTPUT)) { #ifdef VX_CREATE_TENSOR_SUPPORT_PHYSICAL @@ -322,6 +331,7 @@ bool TensorImpl::Init(void *external_cache) { #endif } else +#endif { id_ = vsi_nn_AddTensor(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, &attr, nullptr);