• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MINDSPORE_INCLUDE_C_API_TENSOE_C_H
17 #define MINDSPORE_INCLUDE_C_API_TENSOE_C_H
18 
19 #include <stddef.h>
20 #include "include/c_api/types_c.h"
21 #include "include/c_api/data_type_c.h"
22 #include "include/c_api/format_c.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef void *OH_AI_TensorHandle;
29 
30 /// \brief Create a tensor object.
31 ///
32 /// \param[in] name The name of the tensor.
33 /// \param[in] type The data type of the tensor.
34 /// \param[in] shape The shape of the tensor.
35 /// \param[in] shape_num The num of the shape.
36 /// \param[in] data The data pointer that points to allocated memory.
37 /// \param[in] data_len The length of the memory, in bytes.
38 ///
39 /// \return Tensor object handle.
40 OH_AI_API OH_AI_TensorHandle OH_AI_TensorCreate(const char *name, OH_AI_DataType type, const int64_t *shape,
41                                                 size_t shape_num, const void *data, size_t data_len);
42 
43 /// \brief Destroy the tensor object.
44 ///
45 /// \param[in] tensor Tensor object handle address.
46 OH_AI_API void OH_AI_TensorDestroy(OH_AI_TensorHandle *tensor);
47 
48 /// \brief Obtain a deep copy of the tensor.
49 ///
50 /// \param[in] tensor Tensor object handle.
51 ///
52 /// \return Tensor object handle.
53 OH_AI_API OH_AI_TensorHandle OH_AI_TensorClone(OH_AI_TensorHandle tensor);
54 
55 /// \brief Set the name for the tensor.
56 ///
57 /// \param[in] tensor Tensor object handle.
58 /// \param[in] name The name of the tensor.
59 OH_AI_API void OH_AI_TensorSetName(OH_AI_TensorHandle tensor, const char *name);
60 
61 /// \brief Obtain the name of the tensor.
62 ///
63 /// \param[in] tensor Tensor object handle.
64 ///
65 /// \return The name of the tensor.
66 OH_AI_API const char *OH_AI_TensorGetName(const OH_AI_TensorHandle tensor);
67 
68 /// \brief Set the data type for the tensor.
69 ///
70 /// \param[in] tensor Tensor object handle.
71 /// \param[in] type The data type of the tensor.
72 OH_AI_API void OH_AI_TensorSetDataType(OH_AI_TensorHandle tensor, OH_AI_DataType type);
73 
74 /// \brief Obtain the data type of the tensor.
75 ///
76 /// \param[in] tensor Tensor object handle.
77 ///
78 /// \return The date type of the tensor.
79 OH_AI_API OH_AI_DataType OH_AI_TensorGetDataType(const OH_AI_TensorHandle tensor);
80 
81 /// \brief Set the shape for the tensor.
82 ///
83 /// \param[in] tensor Tensor object handle.
84 /// \param[in] shape The shape array.
85 /// \param[in] shape_num Dimension of shape.
86 OH_AI_API void OH_AI_TensorSetShape(OH_AI_TensorHandle tensor, const int64_t *shape, size_t shape_num);
87 
88 /// \brief Obtain the shape of the tensor.
89 ///
90 /// \param[in] tensor Tensor object handle.
91 /// \param[out] shape_num Dimension of shape.
92 ///
93 /// \return The shape array of the tensor.
94 OH_AI_API const int64_t *OH_AI_TensorGetShape(const OH_AI_TensorHandle tensor, size_t *shape_num);
95 
96 /// \brief Set the format for the tensor.
97 ///
98 /// \param[in] tensor Tensor object handle.
99 /// \param[in] format The format of the tensor.
100 OH_AI_API void OH_AI_TensorSetFormat(OH_AI_TensorHandle tensor, OH_AI_Format format);
101 
102 /// \brief Obtain the format of the tensor.
103 ///
104 /// \param[in] tensor Tensor object handle.
105 ///
106 /// \return The format of the tensor.
107 OH_AI_API OH_AI_Format OH_AI_TensorGetFormat(const OH_AI_TensorHandle tensor);
108 
109 /// \brief Obtain the data for the tensor.
110 ///
111 /// \param[in] tensor Tensor object handle.
112 /// \param[in] data A pointer to the data of the tensor.
113 OH_AI_API void OH_AI_TensorSetData(OH_AI_TensorHandle tensor, void *data);
114 
115 /// \brief Obtain the data pointer of the tensor.
116 ///
117 /// \param[in] tensor Tensor object handle.
118 ///
119 /// \return The data pointer of the tensor.
120 OH_AI_API const void *OH_AI_TensorGetData(const OH_AI_TensorHandle tensor);
121 
122 /// \brief Obtain the mutable data pointer of the tensor. If the internal data is empty, it will allocate memory.
123 ///
124 /// \param[in] tensor Tensor object handle.
125 ///
126 /// \return The data pointer of the tensor.
127 OH_AI_API void *OH_AI_TensorGetMutableData(const OH_AI_TensorHandle tensor);
128 
129 /// \brief Obtain the element number of the tensor.
130 ///
131 /// \param[in] tensor Tensor object handle.
132 ///
133 /// \return The element number of the tensor.
134 OH_AI_API int64_t OH_AI_TensorGetElementNum(const OH_AI_TensorHandle tensor);
135 
136 /// \brief Obtain the data size fo the tensor.
137 ///
138 /// \param[in] tensor Tensor object handle.
139 ///
140 /// \return The data size of the tensor.
141 OH_AI_API size_t OH_AI_TensorGetDataSize(const OH_AI_TensorHandle tensor);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 #endif  // MINDSPORE_INCLUDE_C_API_TENSOE_C_H
147