FT_DSP.gitlink.net/master/html/_sources/functionlib/dsplib/slice.rst.txt

97 lines
4.3 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

SliceFusion
=================
从输入张量中提取一个子集切片。根据给定的起始索引begin和切片大小size在每个维度上截取数据。
.. math::
output[i_0, i_1, \dots, i_{n-1}] = input[begin_0 + i_0, begin_1 + i_1, \dots, begin_{n-1} + i_{n-1}]
其中 $n$ 为维度数ndim且满足 $0 \le i_k < size_k$。
输入:
- **input** - 输入张量数据地址。
- **input_shape** - 输入张量的形状数组地址。
- **ndim** - 输入张量的维度数。
- **begin** - 切片起始索引数组地址(长度为 ndim
- **size** - 切片大小数组地址(长度为 ndim
- **core_mask(int, 可选)** - 核掩码(仅适用于共享存储版本)。
输出:
- **output** - 计算结果存储地址(输出张量形状即为 size
支持平台:
``FT78NE``
``MT7004``
.. note::
- FT78NE 支持 int8, int16, int32, fp32, fp64, cplx64, cplx128
- MT7004 支持 fp16, fp32, int16, int32, cplx64
- 切片操作不改变数据数值,仅改变数据的空间排布,常用于特征提取或张量分解。
**共享存储版本:**
.. c:function:: void i8_slice_s(int8_t* input, int8_t* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void i16_slice_s(int16_t* input, int16_t* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void i32_slice_s(int32_t* input, int32_t* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void hp_slice_s(half* input, half* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void fp_slice_s(float* input, float* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void dp_slice_s(double* input, double* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void c64_slice_s(float* input, float* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
.. c:function:: void c128_slice_s(double* input, double* output, int* input_shape, int ndim, int* begin, int* size, int core_mask)
**C调用示例**
.. code-block:: c
:linenos:
:emphasize-lines: 14
// FT78NE 示例(多核并行切片)
#include <stdio.h>
#include "78NE/utils.h"
int main() {
float *input = (float *)0xA0000000;
float *output = (float *)0xB0000000;
int input_shape[] = {16, 32, 64, 128};
int begin[] = {2, 4, 8, 16};
int size[] = {8, 12, 20, 32};
int ndim = 4;
int core_mask = 0xFF; // 使用8核并行
fp_slice_s(input, output, input_shape, ndim, begin, size, core_mask);
return 0;
}
**私有存储版本:**
.. c:function:: void i8_slice_p(int8_t* input, int8_t* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void i16_slice_p(int16_t* input, int16_t* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void i32_slice_p(int32_t* input, int32_t* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void hp_slice_p(half* input, half* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void fp_slice_p(float* input, float* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void dp_slice_p(double* input, double* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void c64_slice_p(float* input, float* output, int* input_shape, int ndim, int* begin, int* size)
.. c:function:: void c128_slice_p(double* input, double* output, int* input_shape, int ndim, int* begin, int* size)
**C调用示例**
.. code-block:: c
:linenos:
:emphasize-lines: 12
// MT7004 示例(单核私有存储切片)
#include <stdio.h>
int main() {
float *input = (float *)0x10000000;
float *output = (float *)0x10010000;
int input_shape[] = {4, 8, 16, 32};
int begin[] = {1, 2, 3, 4};
int size[] = {2, 3, 6, 8};
int ndim = 4;
fp_slice_p(input, output, input_shape, ndim, begin, size);
return 0;
}