SigmoidCrossEntropyWithLogitsGrad
=================================

计算 **Sigmoid Cross Entropy With Logits** 的梯度。  
该算子以 logits 和 labels 为输入，输出对 logits 的梯度值。

数学表达式为：

.. math::

    \sigma(x) = \frac{1}{1 + e^{-x}}

    \quad

    dst_i = \sigma(x_i) - y_i

其中：
    - :math:`x_i` 表示第 *i* 个 logit（Input0）
    - :math:`y_i` 表示第 *i* 个标签（Input1）

为提高数值稳定性，计算中对正负 logits 采用不同形式：

.. math::

    \sigma(x) =
    \begin{cases}
        \dfrac{1}{1 + e^{-x}}, & x > 0 \\
        \dfrac{e^{x}}{1 + e^{x}}, & x \le 0
    \end{cases}

输入：
    - **Input0** - logits 输入数据地址。
    - **Input1** - 标签（labels）数据地址。
    - **length** - 计算长度。
    - **core_mask** - 核掩码（仅适用于共享存储版本）。

输出：
    - **output** - 梯度计算结果地址。

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

.. note::
    - FT78NE 支持 ``fp32`` 类型
    - MT7004 支持 ``fp16``、``fp32`` 类型
    - 输入 logits 与 labels 必须具有相同长度
    - 输出为对 logits 的梯度，不包含对 labels 的梯度

**共享存储版本:**

.. c:function:: void fp_sigmoidcrossentropywithlogitsgrad_s(float* Input0, float* Input1, float* output, int length, int core_mask)
.. c:function:: void hp_sigmoidcrossentropywithlogitsgrad_s(half* Input0, half* Input1, half* output, int length, int core_mask)

**C调用示例：**

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

    // FT78NE 示例
    #include <stdio.h>
    #include <sigmoid_cross_entropy.h>

    int main(int argc, char* argv[]) {
        float *logits = (float *)0xA0000000;   // DDR 空间
        float *labels = (float *)0xA0100000;
        float *output = (float *)0xC0000000;

        int length = 1024;
        int core_mask = 0xff;

        fp_sigmoidcrossentropywithlogitsgrad_s(logits, labels, output, length, core_mask);

        return 0;
    }


**私有存储版本:**

.. c:function:: void fp_sigmoidcrossentropywithlogitsgrad_p(float* Input0, float* Input1, float* output, int length)
.. c:function:: void hp_sigmoidcrossentropywithlogitsgrad_p(half* Input0, half* Input1, half* output, int length)

**C调用示例：**

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

    // FT78NE 示例（私有存储）
    #include <stdio.h>
    #include <sigmoid_cross_entropy.h>

    int main(int argc, char* argv[]) {
        float *logits = (float *)0x10810000;   // L2 空间
        float *labels = (float *)0x10820000;
        float *output = (float *)0x10830000;

        int length = 1024;
        fp_sigmoidcrossentropywithlogitsgrad_p( logits, labels, output, length);

        return 0;
    }
