Files
hpos-data/cuda/occupancy.cu
Pritimay Sarkar fdc249e414 occupancy in cuda
2023-12-29 23:06:26 +05:30

33 lines
744 B
Plaintext

#include <stdio.h>
#include <cuda_runtime.h>
__global__ void myKernel() {
// Kernel code goes here
}
int main() {
// Set the device (GPU)
cudaSetDevice(0);
// Get device properties
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, 0);
// Set kernel parameters (adjust as needed)
int numThreadsPerBlock = 256;
int numBlocks = 16;
// Compute occupancy
int activeWarps;
int maxWarps;
cudaOccupancyMaxActiveBlocksPerMultiprocessor(&activeWarps, myKernel, numThreadsPerBlock, 0);
maxWarps = prop.maxThreadsPerMultiProcessor / prop.warpSize;
// Compute occupancy ratio
float occupancy = (float)activeWarps / maxWarps;
printf("Occupancy: %f\n", occupancy);
return 0;
}