首页 > 编程语言 >查看GPU占用率以及指定GPU加速程序

查看GPU占用率以及指定GPU加速程序

时间:2023-07-28 23:07:31浏览次数:44  
标签:查看 占用率 World Usage GPU hello2 Hello

我的linux下查看方式:

[root@localhost bonelee]# ./hello2 &
[1] 139743
[root@localhost bonelee]# Hello World from CPU!
!nvHello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!

nvidia-smi 就是这个命令
Mon Jun 27 16:59:23 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130                Driver Version: 384.130                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla P100-PCIE...  Off  | 00000000:3B:00.0 Off |                    0 |
| N/A   48C    P0    31W / 250W |      0MiB / 16276MiB |      3%(占用率)      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
[1]+  Done                    ./hello2

 

为了测试GPU占用率,我写了一个代码:

[root@localhost bonelee]# vi hello2.cu
[root@localhost bonelee]# cat hello2.cu
#include <stdio.h>

__global__ void helloFromGPU (void)
{
    printf("Hello World from GPU!\n");
    while(1) {
        int a = 999;
        int b = 999;
        int c;
        c = a+b*a+a>>b;
    }
}

int main(void)
{
// hello from cpu
printf("Hello World from CPU!\n");

helloFromGPU <<<1, 10>>>();

cudaDeviceReset();

return 0;
}

[root@localhost bonelee]# nvcc hello2.cu  -o hello2
hello2.cu(9): warning: variable "c" was set but never used

hello2.cu(9): warning: variable "c" was set but never used

[root@localhost bonelee]# ./hello2
Hello World from CPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
^Z
[1]+  Stopped                 ./hello2
[root@localhost bonelee]# nvidia-smi
Mon Jun 27 17:12:18 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130                Driver Version: 384.130                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla P100-PCIE...  Off  | 00000000:3B:00.0 Off |                    0 |
| N/A   49C    P0    37W / 250W |    299MiB / 16276MiB |    100%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0    145325      C   ./hello2                                     289MiB |
+-----------------------------------------------------------------------------+

  

可以看到GPU占用率是100%。

注:代码说明,上面一行三对尖括号中的1和10 表明了该function将有10个线程

  

查看GPU占用率以及指定GPU加速程序

GPU占用率查看:

方法一:任务管理器

如图,GPU0和GPU1的占用率如下显示。

 

查看GPU占用率以及指定GPU加速程序_Memory

 

 

方法二:GPU-Z软件

 

查看GPU占用率以及指定GPU加速程序_安全分析_02

     

查看GPU占用率以及指定GPU加速程序_安全分析_03

下面两个GPU,上面是GPU0,下面是GPU1

sensors会话框里的GPU Load就是占用率

大家可以查看GPU0和GPU1的使用与否和使用率

 

方法三:终端查看

在运行中输入cmd,打开终端

输入cd C:\Program Files\NVIDIA Corporation\NVSMI

回车

输入nvidia-smi

输出为

 

查看GPU占用率以及指定GPU加速程序_Memory_04

其中GPU下的0和1 指不同GPU,Memory-Usage为占用率

 

为了实时查看,可以输入nvidia-smi.exe -l 3

这样就可以每3秒刷新一次,实时显示了。

 

指定GPU运行程序方法:

第一步:

在程序里写出指定GPU(有两种分配方法):

1、

import os
os.environ["CUDA_VISIBLE_DEVICES"]=‘0’

这样就指定在GPU0下运行程序,如果要指定多个,可以写成os.environ["CUDA_VISIBLE_DEVICES"]=‘0’,‘1’

 

2、(需得是tensorflow)

import tensorflow as tf

tf.device('/gpu=0')

这样就指定在GPU0下运行程序,如果要指定GPU利用率,就添加如下代码: 

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)

sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

 意思是在GPU0下以30%利用率运行程序(实际会偏高一点,但会有控制效果)

 

第二步:

打开新的console,分别在不同console下用不同GPU运行,实现两个程序同时跑。

注意:如果程序不大,也可以在新的console下用同一个GPU运行程序,具体的视GPU占用率而定。

标签:查看,占用率,World,Usage,GPU,hello2,Hello
From: https://blog.51cto.com/u_11908275/6888032

相关文章

  • Git常用命令(Git远程仓库操作命令_查看、添加、克隆、推送)
         就是码云这种Git网址的账户密码 ......
  • AD查看电路原理图
     打开文件    ......
  • 【Azure Cloud Service】云服务升级后,查看配置文件发现编码变为utf-16
    问题描述通过MigratetoARM,把经典云服务升级成云服务(外延支持)后,在查看云服务的配置XML文件,发现文件的编码格式由UTF-8改变为UTF-16 由此,引发了三个问题1)CloudService是否支持UTF-8,UTF-16这两种编码呢?2)为什么CloudService的配置文件会发生改变?3)配置文件发生改......
  • 【Azure Cloud Service】云服务升级后,查看配置文件发现编码变为utf-16
    问题描述通过MigratetoARM,把经典云服务升级成云服务(外延支持)后,在查看云服务的配置XML文件,发现文件的编码格式由UTF-8改变为UTF-16 由此,引发了三个问题1)CloudService是否支持UTF-8,UTF-16这两种编码呢?2)为什么CloudService的配置文件会发生改变?3)配置文件发生改变后,是否......
  • Hive查看所有表/分区更新时间
    业务需求:开始环境可能不太稳定,需要每天手动检查Hive里面的数据是否同步##步骤1.查看分区showpartitionstable_name;2.查看分区更新时间-获取hdfs路径descformattedtable_name;3.通过dfs-ls<hdfspath>命令查看数据文件最新更新时间dfs-lshdfs://hdfs......
  • 65.oracle中查看缓存命中率
    DBBlockGets:请求的数据块在buffer能满足的个数当前模式块意思就是在操作中正好提取的块数目,而不是在一致性读的情况下而产生的块数。正常的情况下,一个查询提取的块是在查询开始的那个时间点上存在的数据块,当前块是在这个时刻存在的数据块,而不是在这个时间点之前或者之后的数据......
  • Vulkan Video实现GPU加速视频编码/解码
    正文字数:929 阅读时长:2分钟Vulkan是一套跨平台的图形API,由Khronos组织牵头进行制定,普遍被看作是OpenGL的后继者,目前版本已经来到1.2.175,仍然在不停地进行更新,其在非Windows平台上面已经逐渐变成了首选使用的图形API。在未来,Vulkan甚至会提供模拟DirectX等其他图形API的功能,有很大......
  • linux安装配置mysql | 查看mysql初始密码 | mysql找回密码
    摘要一、步骤首先要卸载centos7自带的mariadb数据库rpm-qa|grepmari查询rpm-e--nodepsxxx(关于maria都要删除)然后安装mysql创建文件/opt/mysql上传mysql文件,这里上传的是tar文件,没有gz(也可以使用wget指令,不过可能下载的会很慢)解压即可然后按照顺序逐个暗转......
  • linux软件管理:rpm文件及指令 | 软件的安装、卸载、查询、查看
    摘要介绍linux的rpm文件以及rpm指令一、rpm介绍rpm用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中。它生成具有.RPM扩展名的文件。RPM是RedHatPackageManager(RedHat软件包管理工具)的缩写,类似windows的setup.exe(可以理解为rpm文件是一个安装的可执行程序)......
  • linux软件管理:yum指令 | 软件的下载 | 查看安装的软件
    摘要一、yum介绍Yum是一个Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装可以自动处理依赖性关系,并且一次安装所有依赖的软件包。二、yum指令1.查询软件指令功能说明选项`yumlistmore`查询安装的所有软件`yumlistgr......