98 lines
3.2 KiB
ReStructuredText
98 lines
3.2 KiB
ReStructuredText
Minimumgrad
|
||
=================
|
||
|
||
计算逐元素 Minimum 操作的梯度。该算子是 Minimum 算子的反向传播部分。梯度 dy 将被路由到在前向传播中值较小的那个输入。
|
||
|
||
.. math::
|
||
|
||
\text{dx0}_i = \begin{cases}
|
||
\text{dy}_i, & \text{if } \text{Input0}_i < \text{Input1}_i \\
|
||
0, & \text{otherwise}
|
||
\end{cases}
|
||
|
||
\text{dx1}_i = \begin{cases}
|
||
\text{dy}_i, & \text{if } \text{Input1}_i \le \text{Input0}_i \\
|
||
0, & \text{otherwise}
|
||
\end{cases}
|
||
|
||
输入:
|
||
- **Input0** - 前向传播时的第一个输入数据地址。
|
||
- **Input1** - 前向传播时的第二个输入数据地址。
|
||
- **dy** - 后续层反向传播回来的梯度数据地址。
|
||
- **Input0_dims** - Input0 的维度信息数组。
|
||
- **Input1_dims** - Input1 的维度信息数组。
|
||
- **num_dims** - 输入张量的维度数量。
|
||
- **core_mask** - 核掩码(仅共享存储版本需要)。
|
||
|
||
输出:
|
||
- **dx0** - 计算出的关于 Input0 的梯度地址。
|
||
- **dx1** - 计算出的关于 Input1 的梯度地址。
|
||
|
||
支持平台:
|
||
``FT78NE``
|
||
``MT7004``
|
||
|
||
.. note::
|
||
- FT78NE 支持fp32
|
||
- MT7004 支持fp16, fp32
|
||
|
||
**共享存储版本:**
|
||
|
||
.. c:function:: void hp_minimumgrad_s(half* Input0, half* Input1, half* dy, int* Input0_dims, int* Input1_dims, int num_dims, half* dx0, half* dx1, int core_mask)
|
||
.. c:function:: void fp_minimumgrad_s(float* Input0, float* Input1, float* dy, int* Input0_dims, int* Input1_dims, int num_dims, float* dx0, float* dx1, int core_mask)
|
||
|
||
**C调用示例:**
|
||
|
||
.. code-block:: c
|
||
:linenos:
|
||
:emphasize-lines: 17
|
||
|
||
//FT78NE示例
|
||
#include <stdio.h>
|
||
#include <minimumgrad.h> // 假设头文件名为 minimumgrad.h
|
||
|
||
int main(int argc, char* argv[]) {
|
||
// 假设在DDR空间,且形状相同
|
||
float *input0 = (float *)0xA0000000;
|
||
float *input1 = (float *)0xA1000000;
|
||
float *dy = (float *)0xA2000000;
|
||
float *dx0 = (float *)0xB0000000;
|
||
float *dx1 = (float *)0xB1000000;
|
||
|
||
int dims[] = {4, 256};
|
||
int num_dims = 2;
|
||
int core_mask = 0xff;
|
||
|
||
fp_minimumgrad_s(input0, input1, dy, dims, dims, num_dims, dx0, dx1, core_mask);
|
||
return 0;
|
||
}
|
||
|
||
**私有存储版本:**
|
||
|
||
.. c:function:: void hp_minimumgrad_p(half* Input0, half* Input1, half* dy, int* Input0_dims, int* Input1_dims, int num_dims, half* dx0, half* dx1)
|
||
.. c:function:: void fp_minimumgrad_p(float* Input0, float* Input1, float* dy, int* Input0_dims, int* Input1_dims, int num_dims, float* dx0, float* dx1)
|
||
|
||
**C调用示例:**
|
||
|
||
.. code-block:: c
|
||
:linenos:
|
||
:emphasize-lines: 16
|
||
|
||
//FT78NE示例
|
||
#include <stdio.h>
|
||
#include <minimumgrad.h> // 假设头文件名为 minimumgrad.h
|
||
|
||
int main(int argc, char* argv[]) {
|
||
// 假设在L2空间,且形状相同
|
||
float *input0 = (float *)0x10000000;
|
||
float *input1 = (float *)0x11000000;
|
||
float *dy = (float *)0x12000000;
|
||
float *dx0 = (float *)0x13000000;
|
||
float *dx1 = (float *)0x14000000;
|
||
|
||
int dims[] = {4, 256};
|
||
int num_dims = 2;
|
||
|
||
fp_minimumgrad_p(input0, input1, dy, dims, dims, num_dims, dx0, dx1);
|
||
return 0;
|
||
} |