我正在使用caps openacc編譯器。我想知道可以自己管理記憶的東西嗎?openACC:內存管理
例如與CUDA定期OpenACC的代碼是:
#pragma acc kernels copyin(a,b) copy(c)
for (i = 0; i < SIZE; ++i)
for (j = 0; j < SIZE; ++j)
for (k = 0; k < SIZE; ++k)
c[i][j] += a[i][k] * b[k][j];
我想用這種方式
//allocation
cudaMalloc((void**)&a, num_bytes);
cudaMalloc((void**)&b, num_bytes);
cudaMalloc((void**)&c, num_bytes);
//transfer-in
cudaMemcpy(hostA, a, num_bytes, cudaMemcpyHostToDevice);
cudaMemcpy(hostB, b, num_bytes, cudaMemcpyHostToDevice);
//computation
//i think it will be generated as codelet by CAPS openACC compiler.
#pragma acc kernels
for (i = 0; i < SIZE; ++i)
for (j = 0; j < SIZE; ++j)
for (k = 0; k < SIZE; ++k)
c[i][j] += a[i][k] * b[k][j];
cudaMemcpy(c, hostC, num_bytes, cudaMemcpyDeviceToHost);
cudaFree(&a);cudaFree(&b);cudaFree(&c);
感謝校正分配的,我是從內存張貼在火車上時,我寫我的答案,得到了'device_resident'錯誤的意圖.. 。 – talonmies 2013-05-03 14:58:04