- -
- -
-

SparseFillEmptyRows

-

对稀疏张量按行进行补全操作。当某一行在输入稀疏表示中不存在非零元素时, -使用给定的 default_value 为该行补充一个元素,并生成新的稀疏表示结果。 -同时可选地输出反向索引映射关系。

-

该算子常用于保证稀疏张量在行维度上的完备性。

-
-\[\text{if row } r \text{ is empty:} \quad -(r, 0, \dots) \rightarrow default\_value\]
-
-
输入:
    -
  • indices_ptr - 输入稀疏索引数组地址,大小为 N × rank

  • -
  • values_ptr - 输入稀疏值数组地址。

  • -
  • -
    params - 参数打包成数组。
      -
    • N - 输入稀疏元素个数。

    • -
    • rank - 稀疏张量的秩(索引维度)。

    • -
    • dense_rows - 稠密行数。

    • -
    • default_value - 用于填充空行的默认值,传指针

    • -
    • scratch_ptr - 中间缓冲区,用于存放前缀和信息。

    • -
    • filled_count - 计数数组。

    • -
    -
    -
    -
  • -
  • core_mask - 核掩码(仅共享存储版本需要)。

  • -
-
-
输出:
    -
  • output_y_indices_ptr - 输出稀疏索引数组地址。

  • -
  • output_y_values_ptr - 输出稀疏值数组地址。

  • -
  • output_reverse_index_map_ptr - 反向索引映射输出地址。

  • -
-
-
支持平台:

FT78NE -MT7004

-
-
-
-

备注

-
    -
  • FT78NE 支持fp, dp, int8, int16, int32, cplx64, cplx128

  • -
  • MT7004 支持hp, fp, int16, int32, cplx64

  • -
-
-

共享存储版本:

-
-
-void i8_sparse_fill_empty_rows_s(int *indices_ptr, int8_t *values_ptr, int *output_y_indices_ptr, int8_t *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void i16_sparse_fill_empty_rows_s(int *indices_ptr, int16_t *values_ptr, int *output_y_indices_ptr, int16_t *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void i32_sparse_fill_empty_rows_s(int *indices_ptr, int32_t *values_ptr, int *output_y_indices_ptr, int32_t *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void hp_sparse_fill_empty_rows_s(int *indices_ptr, half *values_ptr, int *output_y_indices_ptr, half *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void fp_sparse_fill_empty_rows_s(int *indices_ptr, float *values_ptr, int *output_y_indices_ptr, float *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void dp_sparse_fill_empty_rows_s(int *indices_ptr, double *values_ptr, int *output_y_indices_ptr, double *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void c64_sparse_fill_empty_rows_s(int *indices_ptr, float *values_ptr, int *output_y_indices_ptr, float *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -
-
-void c128_sparse_fill_empty_rows_s(int *indices_ptr, double *values_ptr, int *output_y_indices_ptr, double *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params, int core_mask)
-
- -

C调用示例:

-
 1//FT78NE示例
- 2#include <stdio.h>
- 3#include <sparsefillemptyrows.h>
- 4
- 5int main(int argc, char* argv[]) {
- 6    int *indices_vec = (int *) 0x81000000; //索引数组
- 7    int *sparse_values = (int *)0x82000000; //值数组
- 8    int *scratch = (int *)0x83000000; //scratch数组
- 9    int *output_indices = (int *)0x84000000; //输出索引数组
-10    int *output_values = (int *)0x85000000; //输出值数组
-11    int *output_reverse_index_map = (int *)0x86000000; //输出反向索引映射数组
-12    int *filled_count = (int *)0x87000000; //填充计数数组
-13
-14    int dims[] = {128, 8, 4};
-15    int rank = 3;
-16    int dense_rows = 128; //dims的第一个维度,即稠密行的数量
-17    int N = 120;
-18    int default_value = 0;
-19
-20    srand(seed++);
-21
-22    int i;
-23    for (i = 0; i < N; i++) {
-24        indices_vec[i * rank] = rand() % dims[0];
-25        indices_vec[i * rank + 1] = rand() % dims[1];
-26        indices_vec[i * rank + 2] = rand() % dims[2];
-27        sparse_values[i] = rand() % 100;
-28    }
-29
-30    compute_scratch(N, rank, dense_rows, indices_vec, scratch);
-31
-32    //
-33    long long params[11];
-34    params[0] = (long long)N;
-35    params[1] = (long long)rank;
-36    params[2] = (long long)dense_rows;
-37    params[3] = (long long)&default_value;
-38    params[4] = (long long)scratch;
-39    params[5] = (long long)filled_count;
-40
-41    int core_mask = 0b1111;
-42    i32_sparse_fill_empty_rows_s(indices_vec, sparse_values, output_indices, output_values, output_reverse_index_map, params, core_mask);
-43
-44    return 0;
-45}
-
-
-

私有存储版本:

-
-
-void i8_sparse_fill_empty_rows_p(int *indices_ptr, int8_t *values_ptr, int *output_y_indices_ptr, int8_t *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void i16_sparse_fill_empty_rows_p(int *indices_ptr, int16_t *values_ptr, int *output_y_indices_ptr, int16_t *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void i32_sparse_fill_empty_rows_p(int *indices_ptr, int32_t *values_ptr, int *output_y_indices_ptr, int32_t *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void hp_sparse_fill_empty_rows_p(int *indices_ptr, half *values_ptr, int *output_y_indices_ptr, half *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void fp_sparse_fill_empty_rows_p(int *indices_ptr, float *values_ptr, int *output_y_indices_ptr, float *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void dp_sparse_fill_empty_rows_p(int *indices_ptr, double *values_ptr, int *output_y_indices_ptr, double *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void c64_sparse_fill_empty_rows_p(int *indices_ptr, float *values_ptr, int *output_y_indices_ptr, float *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -
-
-void c128_sparse_fill_empty_rows_p(int *indices_ptr, double *values_ptr, int *output_y_indices_ptr, double *output_y_values_ptr, int *output_reverse_index_map_ptr, long long *params)
-
- -

C调用示例:

-
 1//FT04示例
- 2#include <stdio.h>
- 3#include <sparsefillemptyrows.h>
- 4
- 5int main(int argc, char* argv[]) {
- 6    int *indices_vec = (int *) 0x10010000; //索引数组
- 7    int *sparse_values = (int *)0x10018000; //值数组
- 8    int *scratch = (int *)0x10020000; //scratch数组
- 9    int *output_indices = (int *)0x10028000; //输出索引数组
-10    int *output_values = (int *)0x10030000; //输出值数组
-11    int *output_reverse_index_map = (int *)0x10038000; //输出反向索引映射数组
-12    int *filled_count = (int *)0x100580000; //填充计数数组
-13
-14    int dims[] = {128, 8, 4};
-15    int rank = 3;
-16    int dense_rows = 128; //dims的第一个维度,即稠密行的数量
-17    int N = 120;
-18    int default_value = 0;
-19
-20    srand(seed++);
-21
-22    int i;
-23    for (i = 0; i < N; i++) {
-24        indices_vec[i * rank] = rand() % dims[0];
-25        indices_vec[i * rank + 1] = rand() % dims[1];
-26        indices_vec[i * rank + 2] = rand() % dims[2];
-27        sparse_values[i] = rand() % 100;
-28    }
-29
-30    compute_scratch(N, rank, dense_rows, indices_vec, scratch);
-31
-32    //
-33    long long params[11];
-34    params[0] = (long long)N;
-35    params[1] = (long long)rank;
-36    params[2] = (long long)dense_rows;
-37    params[3] = (long long)&default_value;
-38    params[4] = (long long)scratch;
-39    params[5] = (long long)filled_count;
-40
-41    i32_sparse_fill_empty_rows_p(indices_vec, sparse_values, output_indices, output_values, output_reverse_index_map, params);
-42
-43    return 0;
-44}
-
-
-
- - -
-