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

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <string.h>
  19. #include "nnacl/op_base.h"
  20. #include "nnacl/conv_parameter.h"
  21. #include "nnacl/nnacl_common.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. int8_t MinInt8(int8_t a, int8_t b);
  26. int8_t MaxInt8(int8_t a, int8_t b);
  27. void ReluFp32(float *data, float *dst, int ele_num);
  28. void Relu6Fp32(float *data, float *dst, int ele_num);
  29. #ifdef ENABLE_AVX
  30. #ifdef WIN32
  31. void ReluFp32C8(float *data, float *dst, int ele_num);
  32. void Relu6Fp32C8(float *data, float *dst, int ele_num);
  33. #endif
  34. #endif
  35. int offset(const int *shape, const int dim0, const int dim1, const int dim2, const int dim3);
  36. int offsetComm(const int *shape, const int dim0, const int dim1, const int dim2);
  37. int offset4d(const int *shape, const int *dims);
  38. static inline bool isAddOverflow(int32_t x, int32_t y) {
  39. int32_t sum = x + y;
  40. return (x > 0 && y > 0 && sum < 0) || (x < 0 && y < 0 && sum > 0);
  41. }
  42. static inline bool isMulOverflow(int32_t x, int32_t y) {
  43. int32_t p = x * y;
  44. return (x != 0) && (p / x != y);
  45. }
  46. static inline int GetStride(int *strides, const int *shape, int length) {
  47. if (length <= 0) {
  48. return 1;
  49. }
  50. int stride = 1;
  51. for (int i = length - 1; i >= 0; --i) {
  52. strides[i] = stride;
  53. stride *= shape[i];
  54. }
  55. return stride;
  56. }
  57. #ifdef ENABLE_ARM64
  58. void BiasAdd(const float *bias, float *data, size_t oc4, size_t plan_size);
  59. void BiasAddRelu6(const float *bias, float *data, size_t oc4, size_t plan_size);
  60. void BiasAddRelu(const float *bias, float *data, size_t oc4, size_t plan_size);
  61. void Relu6(float *data, size_t element4);
  62. void Relu(float *data, size_t element4);
  63. #endif
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* MINDSPORE_LITE_NNACL_COMMON_FUNC_H_ */