代码很简单:
就是使用函数:cudaMemGetInfo( &avail, &total );
#include <cuda_runtime.h>
#include <helper_cuda.h>
#include <iostream>
#include <memory>
#include <string>
void checkGpuMem() {
size_t avail;
size_t total;
cudaMemGetInfo( &avail, &total );
size_t used = total - avail;
std::cout << "================="<< std::endl;
std::cout << "Device memory used: " << used << std::endl;
std::cout << "Total memory used: " << total << std::endl;
std::cout << "================="<< std::endl;
}
int main() {
int deviceCount = 0;
cudaError_t error_id = cudaGetDeviceCount(&deviceCount);
// This funct