liveBook · Manning

CUDA kernel launch syntax

As explained in Grokking GPU Programming

CUDA launch syntax specifies the execution configuration used to launch a kernel, including its blocks and threads.

CUDA launches a kernel with triple-angle-bracket syntax: `kernel<<<blocks, threads>>>();`. The first value sets the number of blocks; the second sets threads per block. For `<<<1, 8>>>`, one block runs eight threads, each executing the kernel body independently. A kernel must be launched this way, not called like an ordinary C function. section 2.4

Eight parallel greetings

In `helloKernel<<<1, 8>>>();`, eight threads each print a greeting. This launch uses one block; the same pattern, `<<<1, n>>>`, launches n threads in a single block. section 2.1 section 2.4

#include <stdio.h>
#include <cuda_runtime.h>
 
__global__ void helloKernel() {    #A
    printf("Hello, Parallel World!\n");    #B
}
 
int main() {
    helloKernel<<<1, 8>>>();    #C
    cudaDeviceSynchronize();    #D
    return 0;
}

View the complete program: the kernel definition, its eight-thread launch, and the synchronization call. section 2.1

How Grokking GPU Programming covers it

How deep it goes
Defines both launch values and notes nvcc rewrites the syntax; defers launches with multiple blocks.
Examples
Uses `helloKernel<<<1, 8>>>();` to print a greeting once from each of eight threads.
What you can do after
Configure a single-block kernel launch by choosing its block count and threads per block.
How it connects
Connects kernel launches to blocks, threads, nvcc, and the CUDA runtime.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.