在.ispc文件中使用pthread会产生如下错误:(1) t.ispc:2:13:错误:从导出函数"matrix_mult_pl“export void * matrix_mult_pl( void *arg )返回"varying”或向量类型是非法的。
(2) t.ispc:2:36:错误:变量指针类型参数"arg“在导出函数中非法。导出void * matrix_mult_pl( void *arg )
(3) t.ispc:6:11:错误:语法错误,意外的'int‘。tid = *(int *)(arg);//获取顺序分配的线程ID。^^^
还有更多的错误。编码器附在下面。请研究一下在ISPC中使用pthread的问题。
threads.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 ];
}
}
}
}threads.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并行化来向量化执行?
发布于 2020-05-09 16:06:10
您遇到的问题是因为ISPC默认为varying类型。int x = 0与varying int x = 0相同。这同样适用于指针类型以及void varying * uniform arg,并且你不能在导出的函数中有不同的类型。在移植和第一次开始使用ISPC时,最好明确使用uniform和varying关键字。
https://stackoverflow.com/questions/61415258
复制相似问题