FortranCL错误:forrtl: severe (157): Program Exception - access violation

FortranCL错误:forrtl: severe (157): Program Exception - access violation

!错误代码段:
  double precision :: ax(nx,ny)
  ......
  colume_in_bytes = int(nx, 8)*8_8
  row_in_bytes = int(ny, 8)*8_8
  ......
  cl_ax = clCreateBuffer(context, CL_MEM_READ_ONLY, colume_in_bytes*row_in_bytes, ierr)
  call clEnqueueWriteBuffer(command_queue, cl_ax, cl_bool(.true.),
               0_8,   colume_in_bytes*row_in_bytes, ax(1,1), ierr)

错误原因: “clEnqueueWriteBuffer”该句内存访问冲突,cl_ax被定义为colume_in_bytes*row_in_bytes 即nx*ny *64,而ax只有nx *ny *8大小,假设nx=ny=2,意味着设备需要从 主机端4 *8个字节中读取4 *64个字节存储,越界产生冲突
更正方法:
bytes = int(ny, 8) \* int(nx, 8)*8_8 call clEnqueueWriteBuffer(command_queue, cl_ax, cl_bool(.true.),0_8, bytes, ax(1,1), ierr)

注意:double precision 与real(8) 含义相同,代表双精度,一般情况下在计算机中占8个字节,_8含义为一个字节占8bit

你可能感兴趣的:(出错处理)