• 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_CCSRC_MINDDATA_DATASET_KERNELS_PLUGIN_OP_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_PLUGIN_OP_H_
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "minddata/dataset/plugin/include/shared_include.h"
24 
25 #include "minddata/dataset/kernels/tensor_op.h"
26 #include "minddata/dataset/core/tensor.h"
27 #include "minddata/dataset/core/tensor_row.h"
28 #include "minddata/dataset/util/status.h"
29 
30 namespace mindspore {
31 namespace dataset {
32 
33 // a generalized plugin for TensorOp
34 class PluginOp : public TensorOp {
35  public:
36   PluginOp(const std::string &lib_path, const std::string &func_name, const std::string &user_args);
37 
38   ~PluginOp() = default;
39 
40   Status Compute(const TensorRow &input, TensorRow *output) override;
41 
42   Status Init();  // load plugin module
43 
Name()44   std::string Name() const override { return kPluginOp; }
45 
46   // helper function to convert between plugin Tensor and MindData Tensor
47   static Status PluginToTensorRow(const std::vector<plugin::Tensor> &, TensorRow *);
48 
49   static Status TensorRowToPlugin(const TensorRow &, std::vector<plugin::Tensor> *);
50 
51  private:
52   Status init_code_;
53   plugin::TensorOp *plugin_op_;
54   std::string lib_path_;
55   std::string func_name_;
56   std::string user_args_;
57 };
58 
59 }  // namespace dataset
60 }  // namespace mindspore
61 
62 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_PLUGIN_OP_H_
63