• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2023 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 
17 #ifndef MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
18 #define MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
19 #include <vector>
20 #include <unordered_map>
21 #include <memory>
22 #include "src/tensor.h"
23 #include "nnacl/tensor_c.h"
24 #include "nnacl/tensor_c_utils.h"
25 #include "src/tensorlist.h"
26 #include "nnacl/infer/common_infer.h"
27 #include "nnacl/tensorlist_c_utils.h"
28 #include "src/litert/cxx_api/tensor/tensor_impl.h"
29 #include "include/api/visible.h"
30 
31 namespace mindspore {
32 namespace lite {
33 void FreeInTensorC(std::vector<TensorC *> *tensors_in, const std::shared_ptr<Allocator> &allocator = nullptr);
34 void FreeOutTensorC(std::vector<TensorC *> *tensors_in, const std::shared_ptr<Allocator> &allocator = nullptr);
35 int Tensor2TensorC(const Tensor *src, TensorC *dst);
36 int TensorC2Tensor(TensorC *src, Tensor *dst, std::shared_ptr<Allocator> allocator = nullptr);
37 int TensorListC2TensorList(const TensorListC *src, TensorList *dst);
38 int GenerateInTensorC(const std::vector<lite::Tensor *> &inputs, std::vector<TensorC *> *in_tensor_c,
39                       const std::shared_ptr<Allocator> &allocator = nullptr);
40 int GenerateOutTensorC(const OpParameter *const parameter, const std::vector<lite::Tensor *> &outputs,
41                        std::vector<TensorC *> *out_tensor_c);
42 MS_API int CheckTensorsInvalid(const std::vector<Tensor *> &tensors);
43 int CheckGraphInputShapes(const std::vector<Tensor *> &inputs,
44                           const std::unordered_map<Tensor *, std::vector<int>> &input_shape_map);
45 std::vector<mindspore::MSTensor> LiteTensorsToMSTensors(const std::vector<lite::Tensor *> &lite_tensors);
46 int MoveCommonTensorData(Tensor *dst_tensor, Tensor *src_tensor);
47 int MoveTensorData(Tensor *dst_tensor, Tensor *src_tensor);
48 int SetTensorData(Tensor *dst_tensor, Tensor *src_tensor);
49 void SetCommonTensorData(Tensor *dst_tensor, Tensor *src_tensor);
50 int MoveTensorListTensorData(TensorList *dst_tensorlist, TensorList *src_tensorlist);
51 int SetTensorListTensorData(TensorList *dst_tensor_list, TensorList *src_tensor_list);
52 int SetTensorShape(Tensor *dst, Tensor *src);
53 bool NeedCastData(Tensor *dst_tensor, Tensor *src_tensor);
54 int CastTensorData(Tensor *dst, Tensor *src, bool support_fp16);
55 int CastCommonTensorData(Tensor *dst, Tensor *src, bool support_fp16);
56 int CastTensorListTensorData(TensorList *dst_tensorlist, TensorList *src_tensorlist, bool support_fp16);
57 TypeId TensorListDataType(Tensor *tensor);
58 TensorList *MallocTensorListDataAccordingToTensorListC(Tensor *tensor, TensorListC *tensor_list_c);
59 int DecodeTensorLsit(Tensor *tensor, const int *src_data, size_t length);
60 Tensor *CreateTensorList(const std::vector<int> &shape, const Category &src_category, const void *src_data);
61 int CopyTensorListTensorDataType(TensorList *dst_tensorlist, TensorList *src_tensorlist);
62 void SetTensorListTensorDataType(const TypeId &data_type, Tensor *tensor);
63 bool IsSameDtype(const Tensor *input_1, const Tensor *input_2);
64 bool IsUnKnownDtype(const Tensor *input);
65 bool IsSameShape(const Tensor *input_1, const Tensor *input_2);
66 int MallocTensorData(Tensor *tensor);
67 int CastConstTensorData(Tensor *tensor, TypeId dst_data_type, bool support_fp16);
68 }  // namespace lite
69 }  // namespace mindspore
70 
71 #endif  // MINDSPORE_LITE_SRC_COMMON_TENSOR_UTIL_H_
72