我正在尝试并行化一个使用 openACC 进行一些图像处理的程序。作为此处理的一部分,我定义了一个自定义结构,类似于:
typedef struct {
RGB *image;
double property;
} Deep;
我在一个数组中访问它Deep *structPointer
。
我遇到了一些手动将整个内容复制structPointer
到 GPU 的文档,这给我留下了以下代码。
Deep *structPointer = (Deep*)
malloc(total_size*sizeof(Deep));
assert(structPointer);
int i;
for (i = 0; i < total_size; i++)
{
structPointer[i].image = randomImage(width, height, max);
}
dP = acc_copyin( stuctPointer, sizeof( Deep )*total_size );
for ( i=0; i < total_size; i++ ) {
dA = acc_copyin( structPointer[i].image, sizeof(RGB)*width*height ); //device address in dA
acc_memcpy_to_device( &dP[i].image, &dA, sizeof(RGB*) );
}
这一切都运行良好,直到我尝试运行一个并行 for 循环,该structPointer
循环property
根据RGB *image
.
伪代码:
#pragma acc parallel loop copyin(inputImage[0:width*height], width, height)
for (i = 0; i < total_size; i++) {
computeProperty(input_image, structPointer+i, width, height)
}
inline void compProperty (const RGB *A, Deep *B, int width, int height)
{
B->property = 10;
}
我得到:
调用 cuStreamSynchronize 返回错误 700:内核执行期间地址非法
的输出cuda-memcheck
是:
> ========= CUDA-MEMCHECK image2.ppm is a PPM file 256 x 256 image, max value= 255
> ========= Program hit CUDA_ERROR_INVALID_CONTEXT (error 201) due to "invalid device context" on CUDA API call to cuCtxAttach.
> ========= Saved host backtrace up to driver entry point at error
> ========= Host Frame:/usr/lib64/libcuda.so (cuCtxAttach + 0x156) [0x13fc36]
> ========= Host Frame:./genimg_acc [0x13639]
> =========
> ========= Program hit CUDA_ERROR_ILLEGAL_ADDRESS (error 700) due to "an illegal memory access was encountered" on CUDA API call to
> cuStreamSynchronize. call to cuStreamSynchronize returned error 700:
> Illegal address during kernel execution
> ========= Saved host backtrace up to driver entry point at error
> ========= Host Frame:/usr/lib64/libcuda.so (cuStreamSynchronize + 0x13d) [0x149a9d]
> ========= Host Frame:./genimg_acc [0x15856]
> =========
> ========= Program hit CUDA_ERROR_ILLEGAL_ADDRESS (error 700) due to "an illegal memory access was encountered" on CUDA API call to
> cuCtxSynchronize.
> ========= Saved host backtrace up to driver entry point at error
> ========= Host Frame:/usr/lib64/libcuda.so (cuCtxSynchronize + 0x127) [0x13ee37]
请注意,程序在没有 openACC 的情况下编译时运行,并且在单线程中运行时将正确处理。