最終更新:
mikk_ni3_92 2008年04月16日(水) 15:03:10履歴
現在地 >> メニュー >> CUDA >> CUDA::画像処理の流れ
SDKのサンプル「simple Texture」をみると次のような感じになってる。
float* h_data; //ここに画像データが入る
・・・ ・・・
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat); //32ビット float
cudaArray* cu_array; //配列データ
CUDA_SAFE_CALL( cudaMallocArray( &cu_array, &channelDesc, width, height )); //メモリ確保
CUDA_SAFE_CALL( cudaMemcpyToArray( cu_array, 0, 0, h_data, size, cudaMemcpyHostToDevice)); //コピー
texture<float, 2, cudaReadModeElementType> tex;
・・・ ・・・
tex.addressMode[0] = cudaAddressModeWrap; //クランプとかワープとかの指定
tex.addressMode[1] = cudaAddressModeWrap;
tex.filterMode = cudaFilterModeLinear; //フィルタ
tex.normalized = true; // 正規化された座標でアクセス
CUDA_SAFE_CALL( cudaBindTextureToArray( tex, cu_array, channelDesc));// 配列をテクスチャにバインド
GPU内では、tex2D()を利用して画素値をひろってこれる。
サンプルより
[例]
unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; //IDを拾ってくるなど
unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
float u = x / (float) width; //0〜1の範囲にスケール変換
float v = y / (float) height;
・・・ ・・・
g_odata[y*width + x] = tex2D(tex, tu, tv);
SDKのサンプル「simple Texture」をみると次のような感じになってる。
- 画像の読み込み
- 配列データのメモリを確保して画像データコピー。テクスチャ型にバインド
- テクスチャ型を利用して、GPUで計算。
- GPUでの計算結果をうけとる
float* h_data; //ここに画像データが入る
・・・ ・・・
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat); //32ビット float
cudaArray* cu_array; //配列データ
CUDA_SAFE_CALL( cudaMallocArray( &cu_array, &channelDesc, width, height )); //メモリ確保
CUDA_SAFE_CALL( cudaMemcpyToArray( cu_array, 0, 0, h_data, size, cudaMemcpyHostToDevice)); //コピー
texture<float, 2, cudaReadModeElementType> tex;
・・・ ・・・
tex.addressMode[0] = cudaAddressModeWrap; //クランプとかワープとかの指定
tex.addressMode[1] = cudaAddressModeWrap;
tex.filterMode = cudaFilterModeLinear; //フィルタ
tex.normalized = true; // 正規化された座標でアクセス
CUDA_SAFE_CALL( cudaBindTextureToArray( tex, cu_array, channelDesc));// 配列をテクスチャにバインド
GPU内では、tex2D()を利用して画素値をひろってこれる。
サンプルより
[例]
unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; //IDを拾ってくるなど
unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
float u = x / (float) width; //0〜1の範囲にスケール変換
float v = y / (float) height;
・・・ ・・・
g_odata[y*width + x] = tex2D(tex, tu, tv);