Lecture 10 Flashcards

1
Q

Cuda Example 1

A
#include 
const int N = 16;
const int blocksize = 16;
\_\_global\_\_
void simple(float *c)
{
c[threadIdx.x] = threadIdx.x;
}
int main()
{
int i;
float *c = new float[N];		
float *cd;
const int size = N*sizeof(float);
cudaMalloc( (void**)&cd, size );
dim3 dimBlock( blocksize, 1 );
dim3 dimGrid( 1, 1 );
simple<<>>(cd);
cudaMemcpy( c, cd, size, cudaMemcpyDeviceToHost );
cudaFree( cd );
for (i = 0; i < N; i++)
		printf("%f ", c[i]);
printf("\n");
delete[] c;
printf("done\n");
return EXIT_SUCCESS;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

modifiers for code

A

__device__ __global__ __host__

How well did you know this?
1
Not at all
2
3
4
5
Perfectly