occupancy in cuda
This commit is contained in:
32
cuda/occupancy.cu
Normal file
32
cuda/occupancy.cu
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user