You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin_op.h 2.0 kB

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