Eltwise
=================

输入两个等长数组以及控制参数，根据控制参数的值决定对两个数组做对位相加、对位相乘或取最大值操作。

.. math::

   \mathbf{output_i} =
   \begin{cases}
   \mathbf{Input0_i} \cdot \mathbf{Input1_i}, & \text{if } \text{eltwise\_mode} = \text{Eltwise\_PROD} \\[6pt]
   \mathbf{Input0_i} + \mathbf{Input1_i}, & \text{if } \text{eltwise\_mode} = \text{Eltwise\_SUM} \\[6pt]
   \max(\mathbf{Input0_i}, \mathbf{Input1_i}), & \text{if } \text{eltwise\_mode} = \text{Eltwise\_MAXIMUM}
   \end{cases}

输入：
    - **Input0** - 第一个输入数据地址。
    - **Input1** - 第二个输入数据地址。
    - **length** - 计算长度。
    - **core_mask(int, 可选)** - 核掩码（仅适用于共享存储版本）。
    
输出：
    - **output** - 计算结果地址。

支持平台：
    ``FT78NE``
    ``MT7004``

.. note::
    - FT78NE 支持int8, int16, int32, fp32, fp64, cplx64(除最大值), cplx128(除最大值)
    - MT7004 支持fp16, fp32, int16, int32, cplx64(除最大值)

**共享存储版本：**

.. c:function:: void i8_eltwise_s(int8_t* Input0, int8_t* Input1, int8_t* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void i16_eltwise_s(int16_t* Input0, int16_t* Input1, int16_t* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void i32_eltwise_s(int* Input0, int* Input1, int* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void hp_eltwise_s(half* Input0, half* Input1, half* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void fp_eltwise_s(float* Input0, float* Input1, float* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void dp_eltwise_s(double* Input0, double* Input1, double* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void c64_eltwise_s(float* Input0, float* Input1, float* output,int length, int eltwise_mode_, int core_mask)
.. c:function:: void c128_eltwise_s(double* Input0, double* Input1, double* output, int length, int eltwise_mode_, int core_mask)

    **C调用示例：**

    .. code-block:: c
        :linenos:
        :emphasize-lines: 14

        //FT78NE示例
        #include <stdio.h>
        #include <eltwise.h>
        #define Eltwise_PROD 0
        #define Eltwise_SUM 1
        #define Eltwise_MAXIMUM 2
        int main(int argc, char* argv[]) {
            float *input0 = (float *)0xA0000000;   //input在DDR空间
            float *input1 = (float *)0xB0000000;
            float *output = (float *)0xC0000000;
            int length = 1000;
            int eltwise_mode_ = Eltwise_SUM;
            int core_mask = 0xff;
            fp_eltwise_s(input0, input1, output, length, eltwise_mode_, core_mask);
            return 0;
        }


**私有存储版本：**

.. c:function:: void i8_eltwise_p(int8_t *Input0, int8_t *Input1, int8_t *output, int eltwise_mode_, int length)
.. c:function:: void i16_eltwise_p(int16_t *Input0, int16_t *Input1, int16_t *output, int eltwise_mode_, int length)
.. c:function:: void i32_eltwise_p(int32_t *Input0, int32_t *Input1, int32_t *output, int eltwise_mode_, int length)
.. c:function:: void hp_eltwise_p(half* Input0, half* Input1, bool* output, int eltwise_mode_,int length)
.. c:function:: void fp_eltwise_p(float* Input0, float* Input1, float* output, int eltwise_mode_,int length)
.. c:function:: void dp_eltwise_p(double* Input0, double* Input1, double* output, int eltwise_mode_,int length)
.. c:function:: void c64_eltwise_p(float *Input0, float *Input1, float *output, int eltwise_mode_, int length)
.. c:function:: void c128_eltwise_p(double *Input0, double *Input1, double *output, int eltwise_mode_, int length)

    **C调用示例：**

    .. code-block:: c
        :linenos:
        :emphasize-lines: 14

        //FT78NE示例
        #include <stdio.h>
        #include <eltwise.h>
        #define Eltwise_PROD 0
        #define Eltwise_SUM 1
        #define Eltwise_MAXIMUM 2

        int main(int argc, char* argv[]) {
            float *input0 = (float *)0x10810000;   //input在L2空间
            float *input1 = (float *)0x10820000;
            float *output = (float *)0x10830000;
            int length = 1000;
            int eltwise_mode_ = Eltwise_SUM;
            fp_eltwise_p(input0, input1, output, eltwise_mode_, length);
            return 0;
        }