Skip to content

Commit

Permalink
cuda: add code to print total VRAM for each device
Browse files Browse the repository at this point in the history
  • Loading branch information
danbev committed Oct 10, 2024
1 parent 3b52a86 commit a942f49
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gpu/cuda/src/minimal.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cuda_runtime.h>

#include <stdio.h>

__global__ void myKernel() {}
Expand Down Expand Up @@ -32,6 +33,18 @@ int main() {

printf("CUDA device count: %d\n", count);

// Get and print total VRAM for each device
for (int i = 0; i < count; i++) {
cudaSetDevice(i);
size_t free_mem, total_mem;
err = cudaMemGetInfo(&free_mem, &total_mem);
if (err != cudaSuccess) {
printf("cudaMemGetInfo failed for device %d: %s\n", i, cudaGetErrorString(err));
} else {
printf("Device %d - Total VRAM: %.2f GB\n", i, total_mem / (1024.0 * 1024.0 * 1024.0));
}
}

myKernel<<<1,1>>>();
err = cudaGetLastError();
if (err != cudaSuccess) {
Expand Down

0 comments on commit a942f49

Please sign in to comment.