1be168c0dSopenharmony_ci/**
2be168c0dSopenharmony_ci * Copyright 2021 Huawei Technologies Co., Ltd
3be168c0dSopenharmony_ci *
4be168c0dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
5be168c0dSopenharmony_ci * you may not use this file except in compliance with the License.
6be168c0dSopenharmony_ci * You may obtain a copy of the License at
7be168c0dSopenharmony_ci *
8be168c0dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
9be168c0dSopenharmony_ci *
10be168c0dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
11be168c0dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
12be168c0dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13be168c0dSopenharmony_ci * See the License for the specific language governing permissions and
14be168c0dSopenharmony_ci * limitations under the License.
15be168c0dSopenharmony_ci */
16be168c0dSopenharmony_ci
17be168c0dSopenharmony_ci/**
18be168c0dSopenharmony_ci * @addtogroup MindSpore
19be168c0dSopenharmony_ci * @{
20be168c0dSopenharmony_ci *
21be168c0dSopenharmony_ci * @brief 提供MindSpore Lite的模型推理相关接口。
22be168c0dSopenharmony_ci *
23be168c0dSopenharmony_ci * @Syscap SystemCapability.Ai.MindSpore
24be168c0dSopenharmony_ci * @since 9
25be168c0dSopenharmony_ci */
26be168c0dSopenharmony_ci
27be168c0dSopenharmony_ci/**
28be168c0dSopenharmony_ci * @file tensor.h
29be168c0dSopenharmony_ci *
30be168c0dSopenharmony_ci * @brief 提供了张量相关的接口,可用于创建和修改张量信息。
31be168c0dSopenharmony_ci *
32be168c0dSopenharmony_ci * @library libmindspore_lite_ndk.so
33be168c0dSopenharmony_ci * @since 9
34be168c0dSopenharmony_ci */
35be168c0dSopenharmony_ci#ifndef MINDSPORE_INCLUDE_C_API_TENSOE_C_H
36be168c0dSopenharmony_ci#define MINDSPORE_INCLUDE_C_API_TENSOE_C_H
37be168c0dSopenharmony_ci
38be168c0dSopenharmony_ci#include <stddef.h>
39be168c0dSopenharmony_ci#include "mindspore/status.h"
40be168c0dSopenharmony_ci#include "mindspore/types.h"
41be168c0dSopenharmony_ci#include "mindspore/data_type.h"
42be168c0dSopenharmony_ci#include "mindspore/format.h"
43be168c0dSopenharmony_ci
44be168c0dSopenharmony_ci#ifdef __cplusplus
45be168c0dSopenharmony_ciextern "C" {
46be168c0dSopenharmony_ci#endif
47be168c0dSopenharmony_ci
48be168c0dSopenharmony_citypedef void *OH_AI_TensorHandle;
49be168c0dSopenharmony_ci
50be168c0dSopenharmony_ci/**
51be168c0dSopenharmony_ci * @brief Create a tensor object.
52be168c0dSopenharmony_ci * @param name The name of the tensor.
53be168c0dSopenharmony_ci * @param type The data type of the tensor.
54be168c0dSopenharmony_ci * @param shape The shape of the tensor.
55be168c0dSopenharmony_ci * @param shape_num The num of the shape.
56be168c0dSopenharmony_ci * @param data The data pointer that points to allocated memory.
57be168c0dSopenharmony_ci * @param data_len The length of the memory, in bytes.
58be168c0dSopenharmony_ci * @return Tensor object handle.
59be168c0dSopenharmony_ci * @since 9
60be168c0dSopenharmony_ci */
61be168c0dSopenharmony_ciOH_AI_API OH_AI_TensorHandle OH_AI_TensorCreate(const char *name, OH_AI_DataType type, const int64_t *shape,
62be168c0dSopenharmony_ci                                                size_t shape_num, const void *data, size_t data_len);
63be168c0dSopenharmony_ci
64be168c0dSopenharmony_ci/**
65be168c0dSopenharmony_ci * @brief Destroy the tensor object.
66be168c0dSopenharmony_ci * @param tensor Tensor object handle address.
67be168c0dSopenharmony_ci * @since 9
68be168c0dSopenharmony_ci */
69be168c0dSopenharmony_ciOH_AI_API void OH_AI_TensorDestroy(OH_AI_TensorHandle *tensor);
70be168c0dSopenharmony_ci
71be168c0dSopenharmony_ci/**
72be168c0dSopenharmony_ci * @brief Obtain a deep copy of the tensor.
73be168c0dSopenharmony_ci * @param tensor Tensor object handle.
74be168c0dSopenharmony_ci * @return Tensor object handle.
75be168c0dSopenharmony_ci * @since 9
76be168c0dSopenharmony_ci */
77be168c0dSopenharmony_ciOH_AI_API OH_AI_TensorHandle OH_AI_TensorClone(OH_AI_TensorHandle tensor);
78be168c0dSopenharmony_ci
79be168c0dSopenharmony_ci/**
80be168c0dSopenharmony_ci * @brief Set the name for the tensor.
81be168c0dSopenharmony_ci * @param tensor Tensor object handle.
82be168c0dSopenharmony_ci * @param name The name of the tensor.
83be168c0dSopenharmony_ci * @since 9
84be168c0dSopenharmony_ci */
85be168c0dSopenharmony_ciOH_AI_API void OH_AI_TensorSetName(OH_AI_TensorHandle tensor, const char *name);
86be168c0dSopenharmony_ci
87be168c0dSopenharmony_ci/**
88be168c0dSopenharmony_ci * @brief Obtain the name of the tensor.
89be168c0dSopenharmony_ci * @param tensor Tensor object handle.
90be168c0dSopenharmony_ci * @return The name of the tensor.
91be168c0dSopenharmony_ci * @since 9
92be168c0dSopenharmony_ci */
93be168c0dSopenharmony_ciOH_AI_API const char *OH_AI_TensorGetName(const OH_AI_TensorHandle tensor);
94be168c0dSopenharmony_ci
95be168c0dSopenharmony_ci/**
96be168c0dSopenharmony_ci * @brief Set the data type for the tensor.
97be168c0dSopenharmony_ci * @param tensor Tensor object handle.
98be168c0dSopenharmony_ci * @param type The data type of the tensor.
99be168c0dSopenharmony_ci * @since 9
100be168c0dSopenharmony_ci */
101be168c0dSopenharmony_ciOH_AI_API void OH_AI_TensorSetDataType(OH_AI_TensorHandle tensor, OH_AI_DataType type);
102be168c0dSopenharmony_ci
103be168c0dSopenharmony_ci/**
104be168c0dSopenharmony_ci * @brief Obtain the data type of the tensor.
105be168c0dSopenharmony_ci * @param tensor Tensor object handle.
106be168c0dSopenharmony_ci * @return The date type of the tensor.
107be168c0dSopenharmony_ci * @since 9
108be168c0dSopenharmony_ci */
109be168c0dSopenharmony_ciOH_AI_API OH_AI_DataType OH_AI_TensorGetDataType(const OH_AI_TensorHandle tensor);
110be168c0dSopenharmony_ci
111be168c0dSopenharmony_ci/**
112be168c0dSopenharmony_ci * @brief Set the shape for the tensor.
113be168c0dSopenharmony_ci * @param tensor Tensor object handle.
114be168c0dSopenharmony_ci * @param shape The shape array.
115be168c0dSopenharmony_ci * @param shape_num Dimension of shape.
116be168c0dSopenharmony_ci * @since 9
117be168c0dSopenharmony_ci */
118be168c0dSopenharmony_ciOH_AI_API void OH_AI_TensorSetShape(OH_AI_TensorHandle tensor, const int64_t *shape, size_t shape_num);
119be168c0dSopenharmony_ci
120be168c0dSopenharmony_ci/**
121be168c0dSopenharmony_ci * @brief Obtain the shape of the tensor.
122be168c0dSopenharmony_ci * @param tensor Tensor object handle.
123be168c0dSopenharmony_ci * @param shape_num Dimension of shape.
124be168c0dSopenharmony_ci * @return The shape array of the tensor.
125be168c0dSopenharmony_ci * @since 9
126be168c0dSopenharmony_ci */
127be168c0dSopenharmony_ciOH_AI_API const int64_t *OH_AI_TensorGetShape(const OH_AI_TensorHandle tensor, size_t *shape_num);
128be168c0dSopenharmony_ci
129be168c0dSopenharmony_ci/**
130be168c0dSopenharmony_ci * @brief Set the format for the tensor.
131be168c0dSopenharmony_ci * @param tensor Tensor object handle.
132be168c0dSopenharmony_ci * @param format The format of the tensor.
133be168c0dSopenharmony_ci * @since 9
134be168c0dSopenharmony_ci */
135be168c0dSopenharmony_ciOH_AI_API void OH_AI_TensorSetFormat(OH_AI_TensorHandle tensor, OH_AI_Format format);
136be168c0dSopenharmony_ci
137be168c0dSopenharmony_ci/**
138be168c0dSopenharmony_ci * @brief Obtain the format of the tensor.
139be168c0dSopenharmony_ci * @param tensor Tensor object handle.
140be168c0dSopenharmony_ci * @return The format of the tensor.
141be168c0dSopenharmony_ci * @since 9
142be168c0dSopenharmony_ci */
143be168c0dSopenharmony_ciOH_AI_API OH_AI_Format OH_AI_TensorGetFormat(const OH_AI_TensorHandle tensor);
144be168c0dSopenharmony_ci
145be168c0dSopenharmony_ci/**
146be168c0dSopenharmony_ci * @brief Obtain the data for the tensor.
147be168c0dSopenharmony_ci * @param tensor Tensor object handle.
148be168c0dSopenharmony_ci * @param data A pointer to the data of the tensor.
149be168c0dSopenharmony_ci * @since 9
150be168c0dSopenharmony_ci */
151be168c0dSopenharmony_ciOH_AI_API void OH_AI_TensorSetData(OH_AI_TensorHandle tensor, void *data);
152be168c0dSopenharmony_ci
153be168c0dSopenharmony_ci/**
154be168c0dSopenharmony_ci * @brief Obtain the data pointer of the tensor.
155be168c0dSopenharmony_ci * @param tensor Tensor object handle.
156be168c0dSopenharmony_ci * @return The data pointer of the tensor.
157be168c0dSopenharmony_ci * @since 9
158be168c0dSopenharmony_ci */
159be168c0dSopenharmony_ciOH_AI_API const void *OH_AI_TensorGetData(const OH_AI_TensorHandle tensor);
160be168c0dSopenharmony_ci
161be168c0dSopenharmony_ci/**
162be168c0dSopenharmony_ci * @brief Obtain the mutable data pointer of the tensor. If the internal data is empty, it will allocate memory.
163be168c0dSopenharmony_ci * @param tensor Tensor object handle.
164be168c0dSopenharmony_ci * @return The data pointer of the tensor.
165be168c0dSopenharmony_ci * @since 9
166be168c0dSopenharmony_ci */
167be168c0dSopenharmony_ciOH_AI_API void *OH_AI_TensorGetMutableData(const OH_AI_TensorHandle tensor);
168be168c0dSopenharmony_ci
169be168c0dSopenharmony_ci/**
170be168c0dSopenharmony_ci * @brief Obtain the element number of the tensor.
171be168c0dSopenharmony_ci * @param tensor Tensor object handle.
172be168c0dSopenharmony_ci * @return The element number of the tensor.
173be168c0dSopenharmony_ci * @since 9
174be168c0dSopenharmony_ci */
175be168c0dSopenharmony_ciOH_AI_API int64_t OH_AI_TensorGetElementNum(const OH_AI_TensorHandle tensor);
176be168c0dSopenharmony_ci
177be168c0dSopenharmony_ci/**
178be168c0dSopenharmony_ci * @brief Obtain the data size fo the tensor.
179be168c0dSopenharmony_ci * @param tensor Tensor object handle.
180be168c0dSopenharmony_ci * @return The data size of the tensor.
181be168c0dSopenharmony_ci * @since 9
182be168c0dSopenharmony_ci */
183be168c0dSopenharmony_ciOH_AI_API size_t OH_AI_TensorGetDataSize(const OH_AI_TensorHandle tensor);
184be168c0dSopenharmony_ci
185be168c0dSopenharmony_ci/**
186be168c0dSopenharmony_ci * @brief Set the data for the tensor with user-allocated data buffer.
187be168c0dSopenharmony_ci *
188be168c0dSopenharmony_ci * The main purpose of this interface is providing a way of using memory already allocated by user as the Model's
189be168c0dSopenharmony_ci * input, but not which allocated inside the Model object. It can reduce one copy. \n
190be168c0dSopenharmony_ci * Note: The tensor won't free the data provided by invoker. Invoker has the responsibility to free it. And this
191be168c0dSopenharmony_ci * free action should not be preformed before destruction of the tensor. \n
192be168c0dSopenharmony_ci *
193be168c0dSopenharmony_ci * @param tensor Tensor object handle.
194be168c0dSopenharmony_ci * @param data A pointer to the user data buffer.
195be168c0dSopenharmony_ci * @param data the byte size of the user data buffer.
196be168c0dSopenharmony_ci * @return OH_AI_STATUS_SUCCESS if success, or detail error code if failed.
197be168c0dSopenharmony_ci * @since 10
198be168c0dSopenharmony_ci */
199be168c0dSopenharmony_ciOH_AI_API OH_AI_Status OH_AI_TensorSetUserData(OH_AI_TensorHandle tensor, void *data, size_t data_size);
200be168c0dSopenharmony_ci
201be168c0dSopenharmony_ci#ifdef __cplusplus
202be168c0dSopenharmony_ci}
203be168c0dSopenharmony_ci#endif
204be168c0dSopenharmony_ci#endif  // MINDSPORE_INCLUDE_C_API_TENSOE_C_H
205