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.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "minddata/dataset/include/constants.h"
  25. #include "minddata/dataset/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. uint32_t device_id = 0);
  36. explicit Execute(std::shared_ptr<TensorTransform> op, MapTargetDevice deviceType = MapTargetDevice::kCpu,
  37. uint32_t device_id = 0);
  38. explicit Execute(std::reference_wrapper<TensorTransform> op, MapTargetDevice deviceType = MapTargetDevice::kCpu,
  39. uint32_t device_id = 0);
  40. explicit Execute(TensorTransform *op, MapTargetDevice deviceType = MapTargetDevice::kCpu, uint32_t device_id = 0);
  41. explicit Execute(std::vector<std::shared_ptr<TensorOperation>> ops,
  42. MapTargetDevice deviceType = MapTargetDevice::kCpu, uint32_t device_id = 0);
  43. explicit Execute(std::vector<std::shared_ptr<TensorTransform>> ops,
  44. MapTargetDevice deviceType = MapTargetDevice::kCpu, uint32_t device_id = 0);
  45. explicit Execute(const std::vector<std::reference_wrapper<TensorTransform>> ops,
  46. MapTargetDevice deviceType = MapTargetDevice::kCpu, uint32_t device_id = 0);
  47. explicit Execute(std::vector<TensorTransform *> ops, MapTargetDevice deviceType = MapTargetDevice::kCpu,
  48. uint32_t device_id = 0);
  49. /// \brief Destructor
  50. ~Execute();
  51. /// \brief callable function to execute the TensorOperation in eager mode
  52. /// \param[in] input Tensor to be transformed
  53. /// \param[out] output Transformed tensor
  54. /// \return Status code
  55. Status operator()(const mindspore::MSTensor &input, mindspore::MSTensor *output);
  56. /// \brief callable function to execute the TensorOperation in eager mode
  57. /// \param[in] input_tensor_list List of Tensor to be transformed
  58. /// \param[out] out Result tensor after transform
  59. /// \return - Status
  60. Status operator()(const std::vector<mindspore::MSTensor> &input_tensor_list, std::vector<mindspore::MSTensor> *out);
  61. Status DeviceMemoryRelease();
  62. std::string AippCfgGenerator();
  63. private:
  64. Status ParseTransforms_();
  65. Status validate_device_();
  66. std::vector<std::shared_ptr<TensorTransform>> transforms_;
  67. std::vector<std::shared_ptr<TensorOperation>> ops_;
  68. MapTargetDevice device_type_;
  69. std::shared_ptr<DeviceResource> device_resource_;
  70. struct ExtraInfo;
  71. std::shared_ptr<ExtraInfo> info_;
  72. };
  73. } // namespace dataset
  74. } // namespace mindspore
  75. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_EXECUTE_H_