【GPGPU】NVIDIA CUDA ..
49:sage
07/12/15 19:52:50
2次元配列を使用したいのですが
以下のサンプルコードを参考にしてみましたがうまく使えません
よろしければご教示お願いします
/* 2D array test */
#include<stdio.h>
#include<cutil.h>
#define width 4
#define height 4
// device code
__global__ void myKernel(float* devPtr, int pitch)
{
for (int r = 0; r < height; ++r) {
float* row = (float*)((char*)devPtr + r * pitch);
for (int c = 0; c < width; ++c) {
float element = row[c];
}
}
devPtr[1][1]=0.0;
}
int main(){
float* devPtr,an;
size_t pitch;
cudaMallocPitch((void**)&devPtr, &pitch,
width * sizeof(float), height);
myKernel<<<100, 512>>>(devPtr, pitch);
CUDA_SAFE_CALL(cudaMemcpy2D((void**)an,pitch,(void**)&devPtr,pitch,4*sizeof(float),4,cudaMemcpyDeviceToHost));
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
4426日前に更新/252 KB
担当:undef