xref: /aosp_15_r20/external/libopus/dnn/arm/dnn_arm.h (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1 /* Copyright (c) 2011-2019 Mozilla
2                  2023 Amazon */
3 /*
4    Redistribution and use in source and binary forms, with or without
5    modification, are permitted provided that the following conditions
6    are met:
7 
8    - Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 
11    - Redistributions in binary form must reproduce the above copyright
12    notice, this list of conditions and the following disclaimer in the
13    documentation and/or other materials provided with the distribution.
14 
15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
19    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef DNN_ARM_H
29 #define DNN_ARM_H
30 
31 #include "cpu_support.h"
32 #include "opus_types.h"
33 
34 void compute_linear_dotprod(const LinearLayer *linear, float *out, const float *in);
35 void compute_linear_neon(const LinearLayer *linear, float *out, const float *in);
36 
37 void compute_activation_neon(float *output, const float *input, int N, int activation);
38 void compute_activation_dotprod(float *output, const float *input, int N, int activation);
39 
40 void compute_conv2d_neon(const Conv2dLayer *conv, float *out, float *mem, const float *in, int height, int hstride, int activation);
41 void compute_conv2d_dotprod(const Conv2dLayer *conv, float *out, float *mem, const float *in, int height, int hstride, int activation);
42 
43 #if defined(OPUS_ARM_PRESUME_DOTPROD)
44 
45 #define OVERRIDE_COMPUTE_LINEAR
46 #define compute_linear(linear, out, in, arch) ((void)(arch),compute_linear_dotprod(linear, out, in))
47 
48 #elif defined(OPUS_ARM_PRESUME_NEON_INTR) && !defined(OPUS_ARM_MAY_HAVE_DOTPROD)
49 
50 #define OVERRIDE_COMPUTE_LINEAR
51 #define compute_linear(linear, out, in, arch) ((void)(arch),compute_linear_neon(linear, out, in))
52 
53 #elif defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_DOTPROD) || defined(OPUS_ARM_MAY_HAVE_NEON))
54 
55 extern void (*const DNN_COMPUTE_LINEAR_IMPL[OPUS_ARCHMASK + 1])(
56                     const LinearLayer *linear,
57                     float *out,
58                     const float *in
59                     );
60 #define OVERRIDE_COMPUTE_LINEAR
61 #define compute_linear(linear, out, in, arch) \
62     ((*DNN_COMPUTE_LINEAR_IMPL[(arch) & OPUS_ARCHMASK])(linear, out, in))
63 
64 
65 #endif
66 
67 #if defined(OPUS_ARM_PRESUME_NEON)
68 
69 #define OVERRIDE_COMPUTE_ACTIVATION
70 #define compute_activation(output, input, N, activation, arch) ((void)(arch),compute_activation_neon(output, input, N, activation))
71 #define OVERRIDE_COMPUTE_CONV2D
72 #define compute_conv2d(conv, out, mem, in, height, hstride, activation, arch) ((void)(arch),compute_conv2d_neon(conv, out, mem, in, height, hstride, activation))
73 
74 #elif defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_DOTPROD) || defined(OPUS_ARM_MAY_HAVE_NEON))
75 
76 extern void (*const DNN_COMPUTE_ACTIVATION_IMPL[OPUS_ARCHMASK + 1])(
77                     float *output,
78                     const float *input,
79                     int N,
80                     int activation
81                     );
82 #define OVERRIDE_COMPUTE_ACTIVATION
83 #define compute_activation(output, input, N, activation, arch) \
84     ((*DNN_COMPUTE_ACTIVATION_IMPL[(arch) & OPUS_ARCHMASK])(output, input, N, activation))
85 
86 
87 extern void (*const DNN_COMPUTE_CONV2D_IMPL[OPUS_ARCHMASK + 1])(
88                     const Conv2dLayer *conv,
89                     float *out,
90                     float *mem,
91                     const float *in,
92                     int height,
93                     int hstride,
94                     int activation
95                     );
96 #define OVERRIDE_COMPUTE_CONV2D
97 #define compute_conv2d(conv, out, mem, in, height, hstride, activation, arch) \
98     ((*DNN_COMPUTE_CONV2D_IMPL[(arch) & OPUS_ARCHMASK])(conv, out, mem, in, height, hstride, activation))
99 
100 
101 #endif
102 
103 
104 #endif /* DNN_ARM_H */
105