§2024-12-08
cuda_check.cpp
#include <iostream>
#include <cuda_runtime.h>
int main() {
// Check the number of CUDA devices
int deviceCount = 0;
cudaError_t err = cudaGetDeviceCount(&deviceCount);
if (err != cudaSuccess) {
std::cerr << "CUDA error: " << cudaGetErrorString(err) << std::endl;
return 1;
}
if (deviceCount == 0) {
std::cout << "No CUDA devices found." << std::endl;
} else {
std::cout << "Number of CUDA devices: " << deviceCount << std::endl;
for (int i = 0; i < deviceCount; i++) {
cudaDeviceProp deviceProp;
err = cudaGetDeviceProperties(&deviceProp, i);
if (err != cudaSuccess) {
std::cerr << "CUDA error: " << cudaGetErrorString(err) << std::endl;
return 1;
}
std::cout << "\nDevice " << i << ": " << deviceProp.name << std::endl;
std::cout << " Compute capability: " << deviceProp.major << "." << deviceProp.minor << std::endl;
std::cout << " Total global memory: " << deviceProp.totalGlobalMem / (1024 * 1024) << " MB" << std::endl;
std::cout << " Multiprocessors: " << deviceProp.multiProcessorCount << std::endl;
std::cout << " Clock rate: " << deviceProp.clockRate / 1000 << " MHz" << std::endl;
std::cout << " Memory Clock Rate: " << deviceProp.memoryClockRate / 1000 << " MHz" << std::endl;
}
}
return 0;
}
nvcc -o cuda_check cuda_check.cpp
$ ls -l
total 728
-rwxrwxr-x 1 alexlai alexlai 741328 十二 8 12:24 cuda_check
-rw-rw-r-- 1 alexlai alexlai 1459 十二 8 12:23 cuda_check.cpp
$ ./cuda_check
Number of CUDA devices: 1
Device 0: Orin
Compute capability: 8.7
Total global memory: 7619 MB
Multiprocessors: 8
Clock rate: 624 MHz
Memory Clock Rate: 624 MHz