Skip to content

Instantly share code, notes, and snippets.

@DWarez
DWarez / hello_world.cu
Created May 20, 2024 09:55
A simple CUDA Hello World
#include <stdio.h>
// Macro for checking CUDA errors
#define CUDA_CHECK_ERROR(err) \
if (err != cudaSuccess) { \
printf("CUDA err: %s at line %d\n", cudaGetErrorString(err), __LINE__); \
exit(EXIT_FAILURE); \
}
// Kernel definition
@DWarez
DWarez / bc_tiled.cu
Last active July 10, 2024 13:44
Matrix multiplications CUDA kernels
#include <stdio.h>
#define TILE_WIDTH 7
__global__ void matMulKernel(float* A, float* B, float* C, int Width) {
__shared__ float Ads[TILE_WIDTH][TILE_WIDTH];
__shared__ float Bds[TILE_WIDTH][TILE_WIDTH];
int bx = blockIdx.x;
int by = blockIdx.y;
int tx = threadIdx.x;