CUDA编程基础与实践 (樊哲勇) (Z-Library).pdf

Untitled

Untitled

Untitled

Untitled

Untitled

第一个Cuda程序

#include <stdio.h>

__global__ void hello_from_gpu()
{
    printf("hello from gpu!\\n");
}

int main(void)
{
    hello_from_gpu<<<1, 1>>>();
    cudaDeviceSynchronize();
    return 0;
}

Untitled

Untitled

Untitled

多线程

#include <stdio.h>

__global__ void hello_from_gpu()
{
    printf("hello from gpu!\\n");
}

int main(void)
{
    hello_from_gpu<<<2, 4>>>();
    cudaDeviceSynchronize();
    return 0;
}

Untitled

Untitled

Untitled

Untitled

#include <stdio.h>

__global__ void hello_from_gpu()
{
    const int bid = blockIdx.x;
    const int tid = threadIdx.x;
    printf("hello world form block %d and thread %d!\\n", bid, tid);
}

int main(void)
{
    hello_from_gpu<<<2, 4>>>();
    cudaDeviceSynchronize();
    return 0;
}

Untitled