1

在 .ispc 文件中使用 pthread 生成错误如下: (1) t.ispc:2:13: Error: Illegal to return a "variating" or vector type from export function "matrix_mult_pl" export void * matrix_mult_pl( void *arg )

(2) t.ispc:2:36: Error: Varying pointer type parameter "arg" 在导出函数中是非法的。导出 void * matrix_mult_pl( void *arg )

(3) t.ispc:6:11: 错误:语法错误,意外'int'。tid = *(int *)(arg); // 获取顺序分配的线程 ID。^^^

以及更多错误。编码器附在下面。请查看在 ISPC 中使用 pthreads 的问题。

线程.c 文件
/**
 * Thread routine.
 * Each thread works on a portion of the 'matrix1'.
 * The start and end of the portion depend on the 'arg' which
 * is the ID assigned to threads sequentially. 
 */
void * matrix_mult_pl( void *arg )
{
  int rows, cols, j, tid, portion_size, row_start, row_end;

  tid = *(int *)(arg); // get the thread ID assigned sequentially.
  portion_size = size / num_threads;
  row_start = tid * portion_size;
  row_end = (tid+1) * portion_size;

  for (rows = row_start; rows < row_end; ++rows) { // hold row index of 'matrix1'
    for (j = 0; j < size; ++j) { // hold column index of 'matrix2'
     // hold value of a cell
      /* one pass to sum the multiplications of corresponding cells
     in the row vector and column vector. */
      for(cols=0; cols<size; cols++) { 
        result_pl[ rows ][ cols ] += matrix1[ rows ][ j ] * matrix2[ j ][ cols ];
      }
    }
  }
}

线程.ispc 文件

export void * matrix_mult_pl( void *arg )
{
  int rows, cols, j, tid, portion_size, row_start, row_end;

  tid = *(int *)(arg); // get the thread ID assigned sequentially.
  portion_size = size / num_threads;
  row_start = tid * portion_size;
  row_end = (tid+1) * portion_size;

  for (rows = row_start; rows < row_end; ++rows) { // hold row index of 'matrix1'
    for (j = 0; j < size; ++j) { // hold column index of 'matrix2'
     // hold value of a cell
      /* one pass to sum the multiplications of corresponding cells
     in the row vector and column vector. */
      for(cols=0; cols<size; cols++) { 
        result_pl[ rows ][ cols ] += matrix1[ rows ][ j ] * matrix2[ j ][ cols ];
      }
    }
  }
}

为什么 ISPC 文件没有通过 pthread 并行化执行向量化?

4

1 回答 1

1

您遇到的问题是因为 ISPC 默认为varying类型。 int x = 0是一样的varying int x = 0。这适用于指针类型,void *arg并且void varying * uniform arg您不能在导出的函数中使用不同的类型。在移植和首次开始使用 ISPC 时,最好使用uniformvarying关键字明确。

于 2020-05-09T08:06:10.297 回答