RsqrtGrad
=================

计算 Rsqrt（平方根倒数）操作的梯度。该算子是 Rsqrt 算子的反向传播（backward pass）部分。

.. math::

    \text{output}_i = -\frac{1}{2} \times \text{input1}_i \times \text{input0}_i^3

其中 `input0` 是前向传播时 Rsqrt 的输出（即 :math:`y = \frac{1}{\sqrt{x}}`），`input1` 是来自后一层的上游梯度 :math:`dy`，`output` 是对原始输入 :math:`x` 的梯度 :math:`dx`。

输入：
    - **input0** - 前向传播时 Rsqrt 的输出数据地址（即 :math:`y = \frac{1}{\sqrt{x}}`）。
    - **input1** - 来自后一层的上游梯度数据地址（即 :math:`dy`）。
    - **size** - 计算长度。
    - **core_mask** - 核掩码（仅共享存储版本需要）。

输出：
    - **output** - 计算出的对原始输入的梯度数据地址（即 :math:`dx`）。

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

.. note::
    - FT78NE 支持fp32
    - MT7004 支持fp16, fp32

**共享存储版本:**

.. c:function:: void fp_rsqrt_grad_s(float* input0, float* input1, float* output, int size, int core_mask)
.. c:function:: void hp_rsqrt_grad_s(half* input0, half* input1, half* output, int size, int core_mask)

**C调用示例：**

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

    //MT7004示例
    #include <stdio.h>
    #include <rsqrtgrad.h>

    int main(int argc, char* argv[]) {
        // 假设在DDR空间
        float *input1 = (float *)0xA0000000;   // Rsqrt的输出 y = 1/sqrt(x)
        float *input2 = (float *)0xA1000000;   // 上游梯度 dy
        float *output = (float *)0xB0000000;  // 输出梯度 dx
        
        int size = 1000;
        int core_mask = 0xff;
        
        fp_rsqrt_grad_s(input1, input2, output, size, core_mask);
        return 0;
    }

**私有存储版本:**

.. c:function:: void fp_rsqrt_grad_p(float* input1, float* input2, float* output, int size)
.. c:function:: void hp_rsqrt_grad_p(half* input1, half* input2, half* output, int size)

**C调用示例：**

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

    //MT7004示例
    #include <stdio.h>
    #include <rsqrtgrad.h>

    int main(int argc, char* argv[]) {
        // 假设在L2空间
        float *input1 = (float *)0x10000000;   // Rsqrt的输出 y = 1/sqrt(x)
        float *input2 = (float *)0x10001000;   // 上游梯度 dy
        float *output = (float *)0x10002000;   // 输出梯度 dx
        
        int size = 1000;
        
        fp_rsqrt_grad_p(input1, input2, output, size);
        return 0;
    }

