diff --git a/src/tim/vx/tensor.cc b/src/tim/vx/tensor.cc index 1124b6e..c5f59f0 100644 --- a/src/tim/vx/tensor.cc +++ b/src/tim/vx/tensor.cc @@ -23,8 +23,6 @@ *****************************************************************************/ #include "tim/vx/tensor.h" -#include - #include #include "graph_private.h" @@ -191,11 +189,26 @@ bool TensorImpl::Init() { if ((spec_.attr_ & TensorAttribute::INPUT) || (spec_.attr_ & TensorAttribute::OUTPUT)) { - id_ = vsi_nn_AddTensorFromHandle(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, // DMABUF's fd is created by TensorFromHandle as input or output, - &attr, fd_ != -1 ? (uint8_t*)fd_ : nullptr);// and cannot be set to const +#ifdef VX_CREATE_TENSOR_SUPPORT_PHYSICAL if (fd_ != -1) { attr.vsi_memory_type = VSI_MEMORY_TYPE_DMABUF; } + + id_ = vsi_nn_AddTensorFromHandle( + graph_->graph(), + VSI_NN_TENSOR_ID_AUTO, // DMABUF's fd is created by TensorFromHandle as input or output, + &attr, + fd_ != -1 ? (uint8_t*)fd_ : nullptr); // and cannot be set to const +#else + if (-1 == fd) { + id_ = vsi_nn_AddTensorFromHandle(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, + &attr, nullptr); + } else { + id_ = 0xFFFFFFFF; + VSILOGE("Create tensor fail: low-level driver doesn't support dmabuffer"); + } +#endif + } else { id_ = vsi_nn_AddTensor(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, &attr, nullptr);