2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ML_TENSORS_DATA_MANAGER_H__
18 #define __ML_TENSORS_DATA_MANAGER_H__
20 #include <unordered_map>
22 #include "common/logger.h"
23 #include "common/platform_result.h"
26 using common::PlatformResult;
27 using common::ErrorCode;
34 struct TensorRawData {
35 // TensorRawData does not take ownership of data, remember to handle it outside
39 unsigned int shape[ML_TENSOR_RANK_LIMIT];
44 TensorsData(ml_tensors_data_h handle, int id, TensorsInfo* tensors_info);
47 ml_tensors_data_h Handle();
51 ml_tensor_type_e GetTensorType(int index);
52 PlatformResult GetTensorRawData(int index, int location[ML_TENSOR_RANK_LIMIT],
53 int size[ML_TENSOR_RANK_LIMIT], TensorRawData* tensor_raw_data);
54 PlatformResult SetTensorRawData(int index, int location[ML_TENSOR_RANK_LIMIT],
55 int size[ML_TENSOR_RANK_LIMIT], TensorRawData& tensor_raw_data);
57 PlatformResult NativeDestroy();
60 TensorsData(TensorsData const&) = delete;
61 TensorsData& operator=(TensorsData const&) = delete;
63 ml_tensors_data_h handle_;
65 TensorsInfo* tensors_info_;
68 class TensorsDataManager {
71 ~TensorsDataManager();
73 TensorsData* CreateTensorsData(TensorsInfo* tensors_info);
74 TensorsData* GetTensorsData(int id);
76 PlatformResult DisposeTensorsData(int id);
77 PlatformResult DisposeTensorsData(TensorsData* t);
80 TensorsDataManager(TensorsDataManager const&) = delete;
81 TensorsDataManager& operator=(TensorsDataManager const&) = delete;
83 std::unordered_map<int, std::unique_ptr<TensorsData>> map_;
89 #endif // __ML_TENSORS_DATA_MANAGER_H__