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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifdef ENABLE_ANDROID
  31. std::shared_ptr<tensor::MSTensor> Execute::operator()(std::shared_ptr<tensor::MSTensor> input) {
  32. // Build the op
  33. if (op_ == nullptr) {
  34. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  35. return nullptr;
  36. }
  37. std::shared_ptr<Tensor> de_input = std::dynamic_pointer_cast<tensor::DETensor>(input)->tensor();
  38. if (de_input == nullptr) {
  39. MS_LOG(ERROR) << "Input Tensor is not valid";
  40. return nullptr;
  41. }
  42. std::shared_ptr<TensorOp> transform = op_->Build();
  43. std::shared_ptr<Tensor> de_output;
  44. Status rc = transform->Compute(de_input, &de_output);
  45. if (rc.IsError()) {
  46. // execution failed
  47. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  48. return nullptr;
  49. }
  50. return std::make_shared<tensor::DETensor>(std::move(de_output));
  51. }
  52. #endif
  53. std::shared_ptr<dataset::Tensor> Execute::operator()(std::shared_ptr<dataset::Tensor> input) {
  54. // Build the op
  55. if (op_ == nullptr) {
  56. MS_LOG(ERROR) << "Input TensorOperation is not valid";
  57. return nullptr;
  58. }
  59. if (input == nullptr) {
  60. MS_LOG(ERROR) << "Input Tensor is not valid";
  61. return nullptr;
  62. }
  63. // will add validate params once API is set
  64. std::shared_ptr<TensorOp> transform = op_->Build();
  65. std::shared_ptr<Tensor> de_output;
  66. Status rc = transform->Compute(input, &de_output);
  67. if (rc.IsError()) {
  68. // execution failed
  69. MS_LOG(ERROR) << "Operation execution failed : " << rc.ToString();
  70. return nullptr;
  71. }
  72. return de_output;
  73. }
  74. } // namespace dataset
  75. } // namespace mindspore