diff --git a/cuda/occupancy.cu b/cuda/occupancy.cu new file mode 100644 index 0000000..05d13f2 --- /dev/null +++ b/cuda/occupancy.cu @@ -0,0 +1,32 @@ +#include +#include + +__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; +}