cuda获取gpu当前显存
头文件:cuda_runtime_api.hstatic void gpu_helper(std::string info, bool print_info=false){size_t free_byte;size_t total_byte;cudaError_t cuda_status = cudaMemGetInfo(&free_byte, &total_byte);if (c
·
头文件:cuda_runtime_api.h
static void gpu_helper(std::string info, bool print_info=false)
{
size_t free_byte;
size_t total_byte;
cudaError_t cuda_status = cudaMemGetInfo(&free_byte, &total_byte);
if (cudaSuccess != cuda_status) {
printf("Error: cudaMemGetInfo fails, %s \n", cudaGetErrorString(cuda_status));
exit(1);
}
double free_db = (double)free_byte;
double total_db = (double)total_byte;
double used_db_1 = (total_db - free_db) / 1024.0 / 1024.0;
if (print_info)
std::cout << info << " used GPU memory " << used_db_1 << " MB\n";
}
欢迎来到FlagOS开发社区,这里是一个汇聚了AI开发者、数据科学家、机器学习爱好者以及业界专家的活力平台。我们致力于成为业内领先的Triton技术交流与应用分享的殿堂,为推动人工智能技术的普及与深化应用贡献力量。
更多推荐
所有评论(0)