npu_data.h Source File

npu_data.h Source File#

SDK qb Runtime Library: npu_data.h Source File
SDK qb Runtime Library v1.4
MCS001-EN
npu_data.h
Go to the documentation of this file.
1// Copyright ⓒ 2019- Mobilint Inc. All rights reserved.
5
6#ifndef QBRUNTIME_NPU_DATA_H_
7#define QBRUNTIME_NPU_DATA_H_
8
9#include <cstdint>
10#include <memory>
11#include <string>
12#include <vector>
13
14#include "qbruntime/export.h"
16#include "qbruntime/type.h"
17
18namespace mobilint {
19
20class Accelerator;
21class Model;
22class ModelImpl;
24class NPUDataImpl;
25
30
51class QBRUNTIME_EXPORT NPUData {
52public:
53 NPUData(const NPUData& other) = default;
54 NPUData& operator=(const NPUData& rhs) = default;
55 NPUData(NPUData&& other) noexcept = default;
56 NPUData& operator=(NPUData&& rhs) noexcept = default;
57 ~NPUData() = default;
58
66
73
83 StatusCode copyFrom(NPUData& src);
84
96 template <typename T>
97 T* data(StatusCode& sc) const {
98 return reinterpret_cast<T*>(rawData(sc));
99 }
100
106 const std::vector<int64_t>& shape() const;
107
114
121 int devNo() const;
122
134 std::string deviceName() const;
135
136private:
137 explicit NPUData(std::shared_ptr<NPUDataImpl> impl);
138
139 void* rawData(StatusCode& sc) const;
140
141 std::shared_ptr<NPUDataImpl> mImpl;
142
143 friend class Model;
144 friend class ModelImpl;
145 friend class ModelVariantHandle;
146};
147
149
150} // namespace mobilint
151
152#endif // QBRUNTIME_NPU_DATA_H_
Represents an accelerator, i.e., an NPU, used for executing models.
Definition acc.h:40
Handle to a specific variant of a loaded model.
Represents an AI model loaded from an MXQ file.
Definition model.h:42
StatusCode launch(Accelerator &acc)
Uploads the data to the NPU memory associated with the given accelerator.
DataType dataType() const
Returns the element data type of the data.
std::string deviceName() const
Returns the hardware name (device type) of the accelerator the data resides on.
const std::vector< int64_t > & shape() const
Returns the shape of the data.
StatusCode copyFrom(NPUData &src)
Copies the data from another NPUData.
int devNo() const
Returns the device number of the accelerator the data resides on.
T * data(StatusCode &sc) const
Returns a typed pointer to the host (CPU) data.
Definition npu_data.h:97
StatusCode cpu()
Brings the data back to host (CPU) memory.
DataType
DataType.
Definition type.h:510
StatusCode
Enumerates status codes for the qbruntime.
Definition status_code.h:28