Examples

Thread creation - calling a kernel function

Kernel function must be called with an execution configuration:

#define ASCII_SIZE 256

__global__ void myFirstKernel(char *ascii) {
    ascii[threadIdx.x] = threadIdx.x;
}


int main(void) {
    char ascii_h[ASCII_SIZE];
    char *ascii_d;
    
    cudaMalloc( &ascii_d, ASCII_SIZE);
    myFirstKErnel<<< 1, ASCII_SIZE >>>(ascii_d);
    cudaMemcpy(ascii_h, ascii_d, ASCII_SIZE, cudaMemcpyDeviceToHost);
    cudaFree(ascii_d);
    return 0;
}

Device properties

Device property

Description

char name[256]

ASCII string identifying device

size_t totalGlobalMem

Global memory available on device in bytes

int maxThreadsPerBlock

Maximum number of threads per block

intmultiProcessonCount

Number of multiprocessors on device

Vector multiplication with CUDA

Last updated