A shared folder with AI prompts and code snippets
From workspace: Nvidia
Team: NVIDIA Developer
Total snippets: 4
4 snippets
Introduction to a CUDA hands-on lab exercise for vector addition. Covers GPU memory allocation and cudaMemcpy basics using a simple example. Created by Mark Harris (NVIDIA).
Credit: Mark Harris - NVIDIA Corporation Description: A simple kernel which adds two vectors (1D arrays) with the GPU. This is a good example showing off memory allocation and movement use the CUDA C runtime API, while using a very simple...
Starter CUDA C file with incomplete kernel and memory operations. Students are expected to fix the kernel indexing and complete cudaMemcpy logic for GPU execution.
#include <stdio.h> __global__ void vector_add(int *a, int *b, int *c) { /* insert code to calculate the index properly using blockIdx.x, blockDim.x, threadIdx.x */ int index = /* FIXME */ c[index] = a[index] + b[index]; } /*...
Fully implemented solution to the CUDA vector addition exercise. Demonstrates correct GPU kernel indexing and memory copy commands using cudaMemcpy.
#include <stdio.h> __global__ void vector_add(int *a, int *b, int *c) { /* insert code to calculate the index properly using blockIdx.x, blockDim.x, threadIdx.x */ int index = blockIdx.x * blockDim.x + threadIdx.x; c[index] = a[index]...
A CUDA C program which uses a GPU kernel to add two vectors together. All the memory management on the GPU is done using the runtime API.