occupancy in cuda

This commit is contained in:
Pritimay Sarkar
2023-12-29 23:06:26 +05:30
parent 2fc87dff86
commit fdc249e414

32
cuda/occupancy.cu Normal file
View File

@@ -0,0 +1,32 @@
#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;
}