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.

common_func.h 2.0 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifndef MINDSPORE_LITE_NNACL_COMMON_FUNC_H_
  17. #define MINDSPORE_LITE_NNACL_COMMON_FUNC_H_
  18. #include <stdint.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include "nnacl/op_base.h"
  22. #include "nnacl/conv_parameter.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. int8_t MinInt8(int8_t a, int8_t b);
  27. int8_t MaxInt8(int8_t a, int8_t b);
  28. void ReluFp32(float *data, float *dst, int ele_num);
  29. void Relu6Fp32(float *data, float *dst, int ele_num);
  30. int offset(const int *shape, const int dim0, const int dim1, const int dim2, const int dim3);
  31. int offsetComm(const int *shape, const int dim0, const int dim1, const int dim2);
  32. int offset4d(const int *shape, const int *dims);
  33. static inline bool isAddOverflow(int32_t x, int32_t y) {
  34. int32_t sum = x + y;
  35. return (x > 0 && y > 0 && sum < 0) || (x < 0 && y < 0 && sum > 0);
  36. }
  37. static inline bool isMulOverflow(int32_t x, int32_t y) {
  38. int32_t p = x * y;
  39. return (x != 0) && (p / x != y);
  40. }
  41. #ifdef ENABLE_ARM64
  42. void BiasAdd(const float *bias, float *data, size_t oc4, size_t plan_size);
  43. void BiasAddRelu6(const float *bias, float *data, size_t oc4, size_t plan_size);
  44. void BiasAddRelu(const float *bias, float *data, size_t oc4, size_t plan_size);
  45. void Relu6(float *data, size_t element4);
  46. void Relu(float *data, size_t element4);
  47. #endif
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. #endif /* MINDSPORE_LITE_NNACL_COMMON_FUNC_H_ */