nvidia-smi
和top
命令来测试CPU和GPU性能。如何在美国GPU服务器Ubuntu 20.04 Linux系统上测试CPU和GPU性能
1、安装必要的软件包
打开终端并登录到Ubuntu 20.04服务器。
运行以下命令以更新软件包列表:
“`
sudo apt update
“`
安装以下软件包,用于测试CPU和GPU性能:
“`
sudo apt install buildessential cmake nvcc
“`
2、下载并编译CUDA工具包
访问NVIDIA官方网站(https://developer.nvidia.com/cudadownloads)下载适用于您的GPU的CUDA工具包。
解压下载的文件到适当的目录中。
进入解压后的目录,并运行以下命令以编译CUDA工具包:
“`
sudo make j$(nproc)
sudo sudo make install
“`
3、安装其他必要的软件包
运行以下命令以安装其他必要的软件包:
“`
sudo apt install g++ libopenblasdev liblapackdev libx11dev libxmudev libglib2.0dev libgtk3dev libboostalldev libeigen3dev libcudnn7=7.6.5.321+cuda10.1 libcudnn7dev=7.6.5.321+cuda10.1 libcufft7=7.6.5.321+cuda10.1 libcufft7dev=7.6.5.321+cuda10.1 libcurand7=7.6.5.321+cuda10.1 libcurand7dev=7.6.5.321+cuda10.1 libnccl2=2.8.31+cuda10.1 libnccl2dev=2.8.31+cuda10.1 libnpp=7.6.5.321+cuda10.1 libnppdev=7.6.5.321+cuda10.1 libnppc=7.6.5.321+cuda10.1 libnppcdev=7.6.5.321+cuda10.1 libnumba=0.49.0 dfsg5+cuda10.1 libnumbadev=0.49.0 dfsg5+cuda10.1 libomp5 libomp5dev libopencvcore3.4 libopencvhighgui3.4 libopencvimgcodecs3.4 libopencvimgproc3.4 libopencvvideoio3.4 libopencvfeatures2d3.4 libopencvcalib3d3.4 libopencvml3.4 libopencvobjdetect3.4 libopencvcontrib3.4 libopencvflann3.4 libopencvstitching3.4 libopencvsuperres3.4 libopencvvideo4.4 libopencvvideoio4.4 libopencvtracking4.4 libopencvtext3.4 libopencvdnn3 python3numpy python3scipy python3matplotlib python3pandas python3sklearn python3tensorflow python3pytorch python3jupyter python3jupyterlab python3sympy python3cython python3h5py python3mpi4py python3pyyaml python3networkx python3nlopt python3pygame python3pyqt5 python3pyqtgraph python3pyqtgraph_notebook python3pyqtgraph_examples python3pyqtgraph_widgets python3pyqtgraph_viewer python3pyqtgraph_mpl_interaction python3pyqtgraph_multiplottool python3pyqtgraph_console python3pyqtgraph_customize python3pyqtgraph_parallel pybind11 tbb cmake qtbase5dev qttools5dev qttools5devtools qtmultimedia5dev qtdeclarative5dev qtquickcontrols25 qmlscene qmltest qtwebengine5 qtxcb qtscript5
4、编写一个简单的程序来测试CPU和GPU性能
在终端中创建一个新的Python文件(例如test_performance.py
),并输入以下代码:
“`python
import numpy as np
import timeit
# CPU性能测试函数
def test_cpu():
return np.sum(np.random.rand(1000, 1000))
# GPU性能测试函数
def test_gpu():
import torch
a = torch.randn(1000, 1000).cuda()
b = torch.randn(1000, 1000).cuda()
return (a + b).sum().item()
# 测试CPU性能并输出结果
start_time = timeit.default_timer()
result_cpu = test_cpu()
end_time = timeit.default_timer()
print("CPU性能测试结果:", result_cpu, "时间:", end_time start_time)
# 测试GPU性能并输出结果
start_time = timeit.default_timer()
result_gpu = test_gpu()
end_time = timeit.default_timer()
print("GPU性能测试结果:", result_gpu, "时间:", end_time start_time)
“`
保存文件后,在终端中运行以下命令执行测试程序:
“`
python test_performance.py
“`
程序将输出CPU和GPU性能测试的结果以及所需的时间。
原创文章,作者:酷盾叔,如若转载,请注明出处:https://www.kdun.com/ask/355110.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复