CUDA/Stream Erfahrungen?

#1222368
Lesenswert?

Steht doch alles auf der NVidia Homepage, inkl. Codebeispielen usw.
http://www.nvidia.com/object/cuda_get.html
Von der Syntax ist es praktisch genauso wie C
Beispiel aus dem Englischen Wikipedia:

This example code in C++ loads a texture from an image into an array on
1
the GPU:
2

3
cudaArray* cu_array;
4
texture<float, 2> tex;
5
 
6
// Allocate array
7
cudaMalloc(&cu_array, cudaCreateChannelDesc<float>(), width, height);
8
 
9
// Copy image data to array
10
cudaMemcpy(cu_array, image, width*height, cudaMemcpyHostToDevice);
11
 
12
// Bind the array to the texture
13
cudaBindTexture(tex, cu_array);
14
 
15
// Run kernel
16
dim3 blockDim(16, 16, 1);
17
dim3 gridDim(width / blockDim.x, height / blockDim.y, 1);
18
kernel<<< gridDim, blockDim, 0 >>>(d_odata, width, height);
19
cudaUnbindTexture(tex);
20
 
21
__global__ void kernel(float* odata, int height, int width)
22
{
23
   unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
24
   unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
25
   float c = texfetch(tex, x, y);
26
   odata[y*width+x] = c;
27
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren