support DMAbuffer (#214)
Signed-off-by: Chen Xin <jack.chen@verisilicon.com>
This commit is contained in:
parent
8ea83f137c
commit
8b1ec74f07
|
|
@ -26,13 +26,12 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace tim {
|
namespace tim {
|
||||||
namespace vx {
|
namespace vx {
|
||||||
|
|
||||||
class Tensor;
|
class Tensor;
|
||||||
struct TensorSpec;
|
struct TensorSpec;
|
||||||
|
struct DmaBufferDesc;
|
||||||
class Operation;
|
class Operation;
|
||||||
|
|
||||||
class Graph {
|
class Graph {
|
||||||
|
|
@ -43,6 +42,8 @@ class Graph {
|
||||||
virtual std::shared_ptr<Tensor> CreateTensor(const TensorSpec& spec,
|
virtual std::shared_ptr<Tensor> CreateTensor(const TensorSpec& spec,
|
||||||
const void* data = nullptr) = 0;
|
const void* data = nullptr) = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<Tensor> CreateTensor(const TensorSpec& spec,
|
||||||
|
const DmaBufferDesc& dmafd) = 0;
|
||||||
/// Create a placeholder tensor for optional inputs of operations
|
/// Create a placeholder tensor for optional inputs of operations
|
||||||
virtual std::shared_ptr<Tensor> CreateTensorPlaceHolder() = 0;
|
virtual std::shared_ptr<Tensor> CreateTensorPlaceHolder() = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,10 @@ struct TensorSpec {
|
||||||
Quantization quantization_;
|
Quantization quantization_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DmaBufferDesc {
|
||||||
|
int64_t fd;
|
||||||
|
};
|
||||||
|
|
||||||
class Tensor {
|
class Tensor {
|
||||||
public:
|
public:
|
||||||
virtual ~Tensor() {}
|
virtual ~Tensor() {}
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,11 @@ std::shared_ptr<Tensor> GraphImpl::CreateTensor(const TensorSpec& spec,
|
||||||
return std::make_shared<TensorImpl>(this, spec, data);
|
return std::make_shared<TensorImpl>(this, spec, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Tensor> GraphImpl::CreateTensor(const TensorSpec& spec,
|
||||||
|
const DmaBufferDesc& dmafd) {
|
||||||
|
return std::make_shared<TensorImpl>(this, spec, dmafd);
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Tensor> GraphImpl::CreateTensorPlaceHolder() {
|
std::shared_ptr<Tensor> GraphImpl::CreateTensorPlaceHolder() {
|
||||||
if (!tensor_placeholder_) {
|
if (!tensor_placeholder_) {
|
||||||
tensor_placeholder_ = std::make_shared<TensorPlaceholder>(this);
|
tensor_placeholder_ = std::make_shared<TensorPlaceholder>(this);
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@ class GraphImpl : public Graph {
|
||||||
/// Implement parents' virtual functions
|
/// Implement parents' virtual functions
|
||||||
std::shared_ptr<Tensor> CreateTensor(const TensorSpec& spec,
|
std::shared_ptr<Tensor> CreateTensor(const TensorSpec& spec,
|
||||||
const void* data = nullptr) override;
|
const void* data = nullptr) override;
|
||||||
|
std::shared_ptr<Tensor> CreateTensor(const TensorSpec& spec,
|
||||||
|
const DmaBufferDesc& dmafd) override;
|
||||||
std::shared_ptr<Tensor> CreateTensorPlaceHolder() override;
|
std::shared_ptr<Tensor> CreateTensorPlaceHolder() override;
|
||||||
bool Compile() override;
|
bool Compile() override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,14 @@ TensorImpl::TensorImpl(Graph* graph, const TensorSpec& spec, const void* data)
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TensorImpl::TensorImpl(Graph* graph, const TensorSpec& spec, const DmaBufferDesc& dmafd)
|
||||||
|
: graph_(reinterpret_cast<GraphImpl*>(graph)),
|
||||||
|
id_(VSI_NN_TENSOR_ID_NA),
|
||||||
|
spec_(spec),
|
||||||
|
fd_(dmafd.fd) {
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
TensorImpl::~TensorImpl() {}
|
TensorImpl::~TensorImpl() {}
|
||||||
|
|
||||||
bool TensorImpl::CopyDataToTensor(const void* data, uint32_t size_in_bytes) {
|
bool TensorImpl::CopyDataToTensor(const void* data, uint32_t size_in_bytes) {
|
||||||
|
|
@ -183,8 +191,11 @@ bool TensorImpl::Init() {
|
||||||
|
|
||||||
if ((spec_.attr_ & TensorAttribute::INPUT) ||
|
if ((spec_.attr_ & TensorAttribute::INPUT) ||
|
||||||
(spec_.attr_ & TensorAttribute::OUTPUT)) {
|
(spec_.attr_ & TensorAttribute::OUTPUT)) {
|
||||||
id_ = vsi_nn_AddTensorFromHandle(graph_->graph(), VSI_NN_TENSOR_ID_AUTO,
|
id_ = vsi_nn_AddTensorFromHandle(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, // DMABUF's fd is created by TensorFromHandle as input or output,
|
||||||
&attr, nullptr);
|
&attr, fd_ != -1 ? (uint8_t*)fd_ : nullptr);// and cannot be set to const
|
||||||
|
if (fd_ != -1) {
|
||||||
|
attr.vsi_memory_type = VSI_MEMORY_TYPE_DMABUF;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
id_ = vsi_nn_AddTensor(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, &attr,
|
id_ = vsi_nn_AddTensor(graph_->graph(), VSI_NN_TENSOR_ID_AUTO, &attr,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ namespace vx {
|
||||||
class TensorImpl : public Tensor {
|
class TensorImpl : public Tensor {
|
||||||
public:
|
public:
|
||||||
TensorImpl(Graph* graph, const TensorSpec& spec, const void* data = nullptr);
|
TensorImpl(Graph* graph, const TensorSpec& spec, const void* data = nullptr);
|
||||||
|
TensorImpl(Graph* graph, const TensorSpec& spec, const DmaBufferDesc& dmafd);
|
||||||
~TensorImpl();
|
~TensorImpl();
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
|
|
@ -56,6 +57,7 @@ class TensorImpl : public Tensor {
|
||||||
vsi_nn_tensor_id_t id_;
|
vsi_nn_tensor_id_t id_;
|
||||||
TensorSpec spec_;
|
TensorSpec spec_;
|
||||||
const void* data_;
|
const void* data_;
|
||||||
|
int64_t fd_{-1};
|
||||||
};
|
};
|
||||||
|
|
||||||
class TensorPlaceholder : public Tensor {
|
class TensorPlaceholder : public Tensor {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue