1 /** 2 * Copyright 2021-2023 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/kernels/ir/vision/invert_ir.h" 17 18 #ifndef ENABLE_ANDROID 19 #include "minddata/dataset/kernels/image/invert_op.h" 20 #endif 21 #if !defined(BUILD_LITE) && defined(ENABLE_D) 22 #include "minddata/dataset/kernels/image/dvpp/ascend910b/dvpp_invert_op.h" 23 #endif 24 #include "minddata/dataset/kernels/ir/validators.h" 25 #include "minddata/dataset/util/validators.h" 26 27 namespace mindspore { 28 namespace dataset { 29 namespace vision { 30 #ifndef ENABLE_ANDROID 31 // InvertOperation InvertOperation(const std::string & device_target)32InvertOperation::InvertOperation(const std::string &device_target) : device_target_(device_target) {} 33 34 InvertOperation::~InvertOperation() = default; 35 Name() const36std::string InvertOperation::Name() const { return kInvertOperation; } 37 ValidateParams()38Status InvertOperation::ValidateParams() { 39 // device target 40 if (device_target_ != "CPU" && device_target_ != "Ascend") { 41 std::string err_msg = "Invert: Invalid device target. It's not CPU or Ascend."; 42 LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg); 43 } 44 return Status::OK(); 45 } 46 Build()47std::shared_ptr<TensorOp> InvertOperation::Build() { 48 if (device_target_ == "CPU") { 49 return std::make_shared<InvertOp>(); 50 #if !defined(BUILD_LITE) && defined(ENABLE_D) 51 } else if (device_target_ == "Ascend") { 52 std::shared_ptr<DvppInvertOp> dvpp_tensor_op = std::make_shared<DvppInvertOp>(); 53 return dvpp_tensor_op; 54 #endif 55 } else { 56 MS_LOG(ERROR) << "Invert: Invalid device target. It's not CPU or Ascend."; 57 return nullptr; 58 } 59 } 60 to_json(nlohmann::json * out_json)61Status InvertOperation::to_json(nlohmann::json *out_json) { 62 RETURN_UNEXPECTED_IF_NULL(out_json); 63 (*out_json)["device_target"] = device_target_; 64 return Status::OK(); 65 } 66 from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)67Status InvertOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) { 68 RETURN_UNEXPECTED_IF_NULL(operation); 69 RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "device_target", kInvertOperation)); 70 std::string device_target = op_params["device_target"]; 71 *operation = std::make_shared<vision::InvertOperation>(device_target); 72 return Status::OK(); 73 } 74 Type()75MapTargetDevice InvertOperation::Type() { 76 if (device_target_ == "CPU") { 77 return MapTargetDevice::kCpu; 78 } else if (device_target_ == "Ascend") { 79 return MapTargetDevice::kAscend910B; 80 } else { 81 MS_LOG(ERROR) << "Invert: Invalid device target. It's not CPU or Ascend."; 82 } 83 return MapTargetDevice::kInvalid; 84 } 85 #endif 86 } // namespace vision 87 } // namespace dataset 88 } // namespace mindspore 89