• 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 
17 #ifndef MINDSPORE_LITE_SRC_RUNTIME_SCHEMA_TENSOR_WRAPPER_H_
18 #define MINDSPORE_LITE_SRC_RUNTIME_SCHEMA_TENSOR_WRAPPER_H_
19 
20 #include <utility>
21 #include <string>
22 #include "src/common/version_manager.h"
23 #include "schema/model_generated.h"
24 #ifdef ENABLE_LITE_HELPER
25 #include "src/common/helper/infer_helpers.h"
26 #endif
27 
28 namespace mindspore {
29 namespace lite {
30 class SchemaTensorWrapper {
31  public:
32   SchemaTensorWrapper() = default;
~SchemaTensorWrapper()33   virtual ~SchemaTensorWrapper() {
34     if (if_own_data_) {
35       free(data_);
36       data_ = nullptr;
37     }
38     this->data_ = nullptr;
39   }
40 
41 #ifdef ENABLE_LITE_HELPER
42   bool Init(const schema::Tensor &tensor, SCHEMA_VERSION schema_version, const std::string &base_path,
43             mindspore::infer::helper::InferHelpers *infer_helpers = nullptr);
44 #else
45   bool Init(const schema::Tensor &tensor, SCHEMA_VERSION schema_version, const std::string &base_path);
46 #endif
47 
handler()48   const schema::Tensor *handler() const { return this->handler_; }
49 
data()50   const void *data() const { return this->data_; }
51 
length()52   size_t length() const { return this->length_; }
53 
ReleaseData()54   std::pair<bool, void *> ReleaseData() {
55     std::pair<bool, void *> ret = std::make_pair(this->if_own_data_, this->data_);
56     this->if_own_data_ = false;
57     return ret;
58   }
59 
60  private:
61   const schema::Tensor *handler_ = nullptr;
62   size_t length_ = 0;
63   void *data_ = nullptr;
64   bool if_own_data_ = true;
65 };
66 }  // namespace lite
67 }  // namespace mindspore
68 #endif  // MINDSPORE_LITE_SRC_RUNTIME_SCHEMA_TENSOR_WRAPPER_H_
69