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