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.

softplus.cc 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright 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. #include "ops/softplus.h"
  17. #include <memory>
  18. #include <set>
  19. #include "ops/op_utils.h"
  20. #include "utils/check_convert_utils.h"
  21. #include "utils/tensor_construct_utils.h"
  22. #include "abstract/primitive_infer_map.h"
  23. namespace mindspore {
  24. namespace ops {
  25. // softplus
  26. namespace {
  27. abstract::ShapePtr SoftplusInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
  28. MS_EXCEPTION_IF_NULL(primitive);
  29. auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape());
  30. auto in_shape = shape_map[kShape];
  31. auto min_shape = shape_map[kMinShape];
  32. auto max_shape = shape_map[kMaxShape];
  33. return std::make_shared<abstract::Shape>(in_shape, min_shape, max_shape);
  34. }
  35. TypePtr SoftplusInferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
  36. MS_EXCEPTION_IF_NULL(prim);
  37. auto prim_name = prim->name();
  38. // check
  39. std::set<TypePtr> valid_index_types = {kFloat16, kFloat32};
  40. auto x_type = input_args[0]->BuildType();
  41. (void)CheckAndConvertUtils::CheckTensorTypeValid("x", x_type, valid_index_types, prim_name);
  42. return x_type;
  43. }
  44. } // namespace
  45. AbstractBasePtr SoftplusInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
  46. const std::vector<AbstractBasePtr> &input_args) {
  47. MS_EXCEPTION_IF_NULL(primitive);
  48. return abstract::MakeAbstract(SoftplusInferShape(primitive, input_args), SoftplusInferType(primitive, input_args));
  49. }
  50. REGISTER_PRIMITIVE_EVAL_IMPL(Softplus, prim::kPrimSoftplus, SoftplusInfer, nullptr, true);
  51. } // namespace ops
  52. } // namespace mindspore