95 lines
3.1 KiB
ReStructuredText
95 lines
3.1 KiB
ReStructuredText
LogSoftmax
|
||
=================
|
||
|
||
|
||
|
||
对输入数组沿指定维度进行 Log-Softmax 计算,输出每个元素的对数概率值。
|
||
|
||
.. math::
|
||
|
||
\text{output}_{i} = \log\frac{\exp(\text{input}_{i})}{\sum_j \exp(\text{input}_j)}
|
||
\quad \text{for elements along the given axis}
|
||
|
||
输入:
|
||
- **input_ptr** - 输入数据地址。
|
||
- **axis** - 归一化的轴。
|
||
- **n_dim** - 输入张量维度。
|
||
- **inner_size** - 内部尺寸(轴之后的元素个数)。
|
||
- **outter_size** - 外部尺寸(轴之前的元素个数)。
|
||
- **axis_size** - 归一化轴的元素数量。
|
||
- **core_mask** - 核掩码(仅适用于共享存储版本)。
|
||
- **sum_data** - 中间累加存储地址(用于存放指数和)。
|
||
|
||
输出:
|
||
- **output_ptr** - Log-Softmax 计算结果地址。
|
||
|
||
支持平台:
|
||
``FT78NE``
|
||
``MT7004``
|
||
|
||
.. note::
|
||
- FT78NE 支持fp, int8
|
||
- MT7004 支持hp, fp
|
||
|
||
**共享存储版本:**
|
||
|
||
.. c:function:: void fp_logsoftmax_s(float* input_ptr, float* output_ptr, float* sum_data, int axis, int n_dim, int inner_size, int outter_size, int axis_size, int core_mask)
|
||
.. c:function:: void hp_logsoftmax_s(half* input_ptr, half* output_ptr, half* sum_data, int axis, int n_dim, int inner_size, int outter_size, int axis_size, int core_mask)
|
||
.. c:function:: void i8_logsoftmax_s(int8_t* input_ptr, int8_t* output_ptr, float* sum_data, int axis, int n_dim, int inner_size, int outter_size, int axis_size, int core_mask)
|
||
|
||
**C调用示例:**
|
||
|
||
.. code-block:: c
|
||
:linenos:
|
||
:emphasize-lines: 16
|
||
|
||
//FT78NE示例
|
||
#include <stdio.h>
|
||
#include <logsoftmax.h>
|
||
|
||
int main() {
|
||
float *input = (float *)0xA0000000; // input在DDR空间
|
||
float *output = (float *)0xC0000000;
|
||
float *sum_data = (float *)0xD0000000;
|
||
int axis = 1;
|
||
int n_dim = 3;
|
||
int inner_size = 4;
|
||
int outter_size = 2;
|
||
int axis_size = 3;
|
||
int core_mask = 0xff;
|
||
|
||
fp_logsoftmax_s(input, output, sum_data, axis, n_dim, inner_size, outter_size, axis_size, core_mask);
|
||
return 0;
|
||
}
|
||
|
||
|
||
**私有存储版本:**
|
||
|
||
.. c:function:: void fp_logsoftmax_p(float* input_ptr, float* output_ptr, float* sum_data, int axis, int n_dim, int inner_size, int outter_size, int axis_size)
|
||
.. c:function:: void hp_logsoftmax_p(half* input_ptr, half* output_ptr, half* sum_data, int axis, int n_dim, int inner_size, int outter_size, int axis_size)
|
||
.. c:function:: void i8_logsoftmax_p(int8_t* input_ptr, int8_t* output_ptr, float* sum_data, int axis, int n_dim, int inner_size, int outter_size, int axis_size)
|
||
|
||
**C调用示例:**
|
||
|
||
.. code-block:: c
|
||
:linenos:
|
||
:emphasize-lines: 15
|
||
|
||
//FT78NE示例
|
||
#include <stdio.h>
|
||
#include <logsoftmax.h>
|
||
|
||
int main() {
|
||
float *input = (float *)0x10810000; // input在L2空间
|
||
float *output = (float *)0x10820000;
|
||
float *sum_data = (float *)0x10830000;
|
||
int axis = 1;
|
||
int n_dim = 3;
|
||
int inner_size = 4;
|
||
int outter_size = 2;
|
||
int axis_size = 3;
|
||
|
||
fp_logsoftmax_p(input, output, sum_data, axis, n_dim, inner_size, outter_size, axis_size);
|
||
return 0;
|
||
}
|