[Rack] CUDA on pony
Dr. Jesus
j at hug.gs
Wed Mar 9 19:48:07 UTC 2011
I noticed there's an 8xxx series nvidia GPU in the motherboard
chipset, so I tried installing the CUDA package and it seems to work.
Tools are in /usr/local/cuda/bin.
j at pony:~$ export PATH=$PATH:/usr/local/cuda/bin
j at pony:~$ cat test.cu
#include <stdio.h>
const int N = 16;
const int blocksize = 16;
__global__
void hello(char *a, int *b)
{
a[threadIdx.x] += b[threadIdx.x];
}
int main()
{
char a[N] = "Hello \0\0\0\0\0\0";
int b[N] = {15, 10, 6, 0, -11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char *ad;
int *bd;
const int csize = N*sizeof(char);
const int isize = N*sizeof(int);
printf("%s", a);
cudaMalloc( (void**)&ad, csize );
cudaMalloc( (void**)&bd, isize );
cudaMemcpy( ad, a, csize, cudaMemcpyHostToDevice );
cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice );
dim3 dimBlock( blocksize, 1 );
dim3 dimGrid( 1, 1 );
hello<<<dimGrid, dimBlock>>>(ad, bd);
cudaMemcpy( a, ad, csize, cudaMemcpyDeviceToHost );
cudaFree( ad );
printf("%s\n", a);
return EXIT_SUCCESS;
}
j at pony:~$ nvcc test.cu -o test
j at pony:~$ ./test
Hello Hello
More information about the Rack
mailing list