From bc42f7987c25309d5fea71b21b34918ad178d646 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 23 Nov 2021 11:34:03 +0800 Subject: [PATCH] Fix build if lowlevel driver doesn't support DMABuffer fd (#224) * Fix build if lowlevel driver doesn't support DMABuffer fd Signed-off-by: xiang.zhang --- src/tim/vx/tensor.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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);