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.

execute.h 3.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright 2020-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_INCLUDE_EXECUTE_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_EXECUTE_H_
  18. #include <string>
  19. #include <vector>
  20. #include <map>
  21. #include <memory>
  22. #include "include/api/context.h"
  23. #include "include/api/types.h"
  24. #include "include/constants.h"
  25. #include "include/transforms.h"
  26. namespace mindspore {
  27. namespace dataset {
  28. class DeviceResource;
  29. // class to run tensor operations in eager mode
  30. class Execute {
  31. public:
  32. /// \brief Constructor
  33. // FIXME - Temporarily overload Execute to support both TensorOperation and TensorTransform
  34. explicit Execute(std::shared_ptr<TensorOperation> op, MapTargetDevice deviceType = MapTargetDevice::kCpu);
  35. explicit Execute(std::shared_ptr<TensorTransform> op, MapTargetDevice deviceType = MapTargetDevice::kCpu);
  36. explicit Execute(std::reference_wrapper<TensorTransform> op, MapTargetDevice deviceType = MapTargetDevice::kCpu);
  37. explicit Execute(TensorTransform *op, MapTargetDevice deviceType = MapTargetDevice::kCpu);
  38. explicit Execute(std::vector<std::shared_ptr<TensorOperation>> ops,
  39. MapTargetDevice deviceType = MapTargetDevice::kCpu);
  40. explicit Execute(std::vector<std::shared_ptr<TensorTransform>> ops,
  41. MapTargetDevice deviceType = MapTargetDevice::kCpu);
  42. explicit Execute(const std::vector<std::reference_wrapper<TensorTransform>> ops,
  43. MapTargetDevice deviceType = MapTargetDevice::kCpu);
  44. explicit Execute(std::vector<TensorTransform *> ops, MapTargetDevice deviceType = MapTargetDevice::kCpu);
  45. /// \brief Destructor
  46. ~Execute();
  47. /// \brief callable function to execute the TensorOperation in eager mode
  48. /// \param[in] input Tensor to be transformed
  49. /// \param[out] output Transformed tensor
  50. /// \return Status code
  51. Status operator()(const mindspore::MSTensor &input, mindspore::MSTensor *output);
  52. /// \brief callable function to execute the TensorOperation in eager mode
  53. /// \param[in] input_tensor_list List of Tensor to be transformed
  54. /// \param[out] out Result tensor after transform
  55. /// \return - Status
  56. Status operator()(const std::vector<mindspore::MSTensor> &input_tensor_list, std::vector<mindspore::MSTensor> *out);
  57. Status DeviceMemoryRelease();
  58. std::string AippCfgGenerator();
  59. private:
  60. Status ParseTransforms_();
  61. Status validate_device_();
  62. std::vector<std::shared_ptr<TensorTransform>> transforms_;
  63. std::vector<std::shared_ptr<TensorOperation>> ops_;
  64. MapTargetDevice device_type_;
  65. std::shared_ptr<DeviceResource> device_resource_;
  66. struct ExtraInfo;
  67. std::shared_ptr<ExtraInfo> info_;
  68. };
  69. } // namespace dataset
  70. } // namespace mindspore
  71. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_EXECUTE_H_