数か月間 JCuda を使用してきましたが、多次元配列をデバイス メモリからホスト メモリにコピーできません。面白いことに、反対方向に実行しても問題はありません (多次元配列を使用してカーネルを呼び出すことができ、すべてが正しい値で機能します)。
簡単に言うと、カーネルの結果を short の 2 次元配列に入れます。このような配列の最初の次元はスレッドの数であり、それぞれが異なる場所に書き込むことができるようにします。
ここに例があります:
CUdeviceptr pointer_dev = new CUdeviceptr();
cuMemAlloc(pointer_dev, Sizeof.POINTER); // in this case, as an example, it's an array with one element (one thread), but it doesn't matter
// Invoke kernel with pointer_dev as parameter. Now it should contain some results
CUdeviceptr[] arrayPtr = new CUdeviceptr[1]; // It will point to the result
arrayPtr[0] = new CUdeviceptr();
short[] resultArray = new short[3]; // an array of 3 shorts was allocated in the kernel
cuMemAlloc(arrayPtr[0], 3 * Sizeof.SHORT);
cuMemcpyDtoH(Pointer.to(arrayPtr), pointer_dev, Sizeof.POINTER); // Its seems, using the debugger, that the value of arrayPtr[0] isn't changed here!
cuMemcpyDtoH(Pointer.to(resultArray), arrayPtr[0], 3 * Sizeof.SHORT); // Not the expected values in resultArray, probably because of the previous instruction
私は何を間違っていますか?
編集:
どうやら、この (およびその他の多くの) スレッドで述べられているように、デバイスに割り当てられたメモリをホストにコピーすることを許可しないいくつかの制限があります:リンク
回避策はありますか?CUDA ツールキット v5.0 を使用しています