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.cc 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright 2020 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. #include "minddata/dataset/include/execute.h"
  17. #ifdef ENABLE_ANDROID
  18. #include "minddata/dataset/include/de_tensor.h"
  19. #endif
  20. #include "minddata/dataset/include/tensor.h"
  21. #include "minddata/dataset/kernels/tensor_op.h"
  22. #ifndef ENABLE_ANDROID
  23. #include "utils/log_adapter.h"
  24. #else
  25. #include "mindspore/lite/src/common/log_adapter.h"
  26. #endif
  27. namespace mindspore {
  28. namespace dataset {
  29. Execute::Execute(std::shared_ptr<TensorOperation> op) : op_(std::move(op)) {}
  30. /// \brief Destructor
  31. Execute::~Execute() = default;
  32. #ifdef ENABLE_ANDROID
  33. std::shared_ptr<tensor::MSTensor> Execute::operator()(std::shared_ptr<tensor::MSTensor> input) {
  34. // Build the op
  35. if (op_ == nullptr) {
  36. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  37. return nullptr;
  38. }
  39. std::shared_ptr<Tensor> de_input = std::dynamic_pointer_cast<tensor::DETensor>(input)->tensor();
  40. if (de_input == nullptr) {
  41. MS_LOG(ERROR) << "Input Tensor is not valid";
  42. return nullptr;
  43. }
  44. std::shared_ptr<TensorOp> transform = op_->Build();
  45. std::shared_ptr<Tensor> de_output;
  46. Status rc = transform->Compute(de_input, &de_output);
  47. if (rc.IsError()) {
  48. // execution failed
  49. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  50. return nullptr;
  51. }
  52. return std::make_shared<tensor::DETensor>(std::move(de_output));
  53. }
  54. #endif
  55. std::shared_ptr<dataset::Tensor> Execute::operator()(std::shared_ptr<dataset::Tensor> input) {
  56. // Build the op
  57. if (op_ == nullptr) {
  58. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  59. return nullptr;
  60. }
  61. if (input == nullptr) {
  62. MS_LOG(ERROR) << "Input Tensor is not valid";
  63. return nullptr;
  64. }
  65. // will add validate params once API is set
  66. std::shared_ptr<TensorOp> transform = op_->Build();
  67. std::shared_ptr<Tensor> de_output;
  68. Status rc = transform->Compute(input, &de_output);
  69. if (rc.IsError()) {
  70. // execution failed
  71. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  72. return nullptr;
  73. }
  74. return de_output;
  75. }
  76. } // namespace dataset
  77. } // namespace mindspore