調用函數test
後,打印出dtr1
陣列。我期望得到所有元素的100
,但我沒有得到它。這是爲什麼?CUDA陣列/表面內存
#include "ImageUtil2D.h"
#define W 10
#define H 10
#define MAX 100000
#define No_THREADS 10
surface<void,2> surfD;
__global__ void test()
{
for(int i=0;i<W;i++)
for(int j=0;j<H;j++)
{
float a=100;
surf2Dwrite(a, surfD, i,j, cudaBoundaryModeTrap);
}
}
int main()
{
int *image = new int[W*H];
float *dtr = new float[W*H];
ImageUtil2D::InitImg(image, dtr, W, H);
const size_t sizef = size_t(W*H)*sizeof(float);
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaArray* cuArrD;
cudaMallocArray(&cuArrD, &channelDesc, W*H, 0, cudaArraySurfaceLoadStore);
//cudaMemcpyToArray(cuArrD, 0, 0, dtr, sizef, cudaMemcpyHostToDevice);
cudaBindSurfaceToArray(surfD, cuArrD);
test<<<1, 1>>>();
float *dtr1=new float[W*H];
cudaMemcpyFromArray(&dtr1, cuArrD, 0, 0, sizef, cudaMemcpyDeviceToHost);
ImageUtil2D::Print(dtr1);
return 0;
}
固定告訴你得到了什麼,而不是 – lurscher 2011-06-16 17:57:17
添加錯誤處理周圍的CUDA API調用和郵政編碼在哪裏以及如何失敗。 – fabrizioM 2011-06-16 20:03:14