(不使用docker,很麻烦)gem5 gcn3 gpu的编译安装运行(nvidia gpu环境下)

这个是错误示例,我没有成功搭建好环境

这个是错误示例,我没有成功搭建好环境

这个是错误示例,我没有成功搭建好环境

不过,使用docker可以成功搭建好环境

另一篇成功的笔记

一、gem5 gcn3的安装

此处略,参考 gem5的常规安装,以及gem5官方的文档:
https://www.gem5.org/documentation/general_docs/gpu_models/GCN3
(官方有一些是在docker容器内部安装和运行gem5的,不过过程是差不多的)

1.1 依赖

1.2 编译

编译命令(参考,具体的python以及scons路径视情况而定)
python3 $(which scons) ./build/GCN3_X86/gem5.opt -j9

1.3 测试运行

先运行官方提供好的文件,即square,一个求平方的demo

  1. 直接下载(地址在https://www.gem5.org/documentation/general_docs/gem5_resources/里可以找到)
$ wget https://dist.gem5.org/dist/v21-1/test-progs/square/square.o
  1. 运行(注意路径)
$ build/GCN3_X86/gem5.opt configs/example/apu_se.py -n 3 -c square.o
  1. 直接运行会报错:
error while loading shared libraries: libamdhip64.so.4: cannot open shared object file: No such file or directory

因为我没有安装amd的hip库,所以这里会报错。

1.4 可能遇到的问题

编译遇到的问题:drm.h:375:8: error: expected unqualified-id before ‘virtual’
参考:https://stackoverflow.com/questions/19034688/extern-c-with-variable-name-virtual

The real issue here is that you are including a wrong drm.h. You are not using a package manager and also do not specify /usr/include/libdrm in the include path. If one of these two is not done, the compiler is going to pick up /usr/include/drm.h or another that has this issue. But the file from libdrm (/usr/include/libdrm/drm.h) has this fixed.

原因:因为虽然安装了libdrm但是,这里的drm.h引用的不对,
sudo find / -name drm.h可以查到所有的drm.h
我的解决办法:将gem5/src/dev/hsa/kfd_ioctl.h中的#include <drm.h>改为#include <libdrm/drm.h>

二、gpu应用程序的编译环境搭建

2.1 前言

按照wiki的教程(http://www.m5sim.org/GPU_Models),应该是要安装rocm组件(1.6.x版本)。
其中,rocm的安装也是有官方教程的(https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation_new.html),但是我这里可用的电脑上的gpu都是nvidia的,照着教程安装总是不顺利。
索性我就抛开文档,直接看demo了,也就是前面的square.o文件,只要我能成功编译square,并且能在gem5 gcn3上运行,应该就没啥问题。看了square的Makefile文件后发现它主要就是用到了一个hipcc的编译器,那我们就尝试安装hip编译器吧。

wiki上的内容(链接看原文)

ROCm tool chain and software stack

In order to build and run applications for ROCm and GCN3 you need several ROCm components. These are:

  • Heterogeneous Compute Compiler (HCC)
  • Radeon Open Compute runtime (ROCr)
  • Radeon Open Compute thunk (ROCt)
  • HIP (optional)
    Only the roc-1.6.x branch of the necessary ROCm components are supported, so be sure to include -b roc-1.6.x when cloning. The recommended compiler to build these components is gcc 5.4.0.

Alternatively, there are deb and yum packages for ROCm archived here: ROCm archive.

When building gem5’s GPU model you must make sure that the src/dev/hsa/kfd_ioctl.h header matches the kfd_ioctl.h header that comes with ROCt. The emulated driver, src/gpu-compute/gpu_compute_driver.[hh|cc] relies on this file to interpret the ioctl() codes that the thunk uses.

Before running any ROCm-based GPU applications in gem5, you need to make sure that the simulated environment is set properly in configs/example/apu_se.py. The LD_LIBRARY_PATH in particular must point to the ROCm installation on your local machine.

2.2 安装hip编译器

注意版本按wiki说的,安装1.6.x,其它版本我没试过。另外,按照我的理解,cuda的sdk可能也要安装,但是我测试的电脑估计是已经装好了。

# clone并切换到roc-1.6.x分支
git clone -b roc-1.6.x https://github.com/ROCm-Developer-Tools/HIP.git

roc-1.6.x分支下的安装教程提示有两种安装方法,一种是从apt仓库安装,一种是源码编译,这里选择源码编译。

cd HIP
mkdir build
cd build
cmake .. 
make
sudo make install

测试安装是否成功

/opt/rocm/hip/bin/hipconfig --full

2.3 编译square

git clone https://github.com/gem5/gem5-resources.git
$ cd gem5-resources/src/gpu/square

修改Makefile
删掉--amdgpu-target=gfx801,gfx803

# 编译,警告信息不用管
$ make

# 在本机运行
$ ./bin/square 
info: running on device TITAN Xp
info: allocate host and device mem (  7.63 MB)
info: launch 'vector_square' kernel
info: check result
PASSED!

2.4 安装cuda运行库

由于我这个电脑是已经装好的,因此跳过该步骤

2.5 在gem5运行square

  1. 修改configs/example/apu_se.py中的环境变量(LD_LIBRARY_PATH
    如下
if args.env:
    with open(args.env, 'r') as f:
        env = [line.rstrip() for line in f]
else:
    env = ['LD_LIBRARY_PATH=%s' % ':'.join([
               os.getenv('ROCM_PATH','/opt/rocm')+'/lib',
               os.getenv('HCC_HOME','/opt/rocm/hcc')+'/lib',
               os.getenv('HSA_PATH','/opt/rocm/hsa')+'/lib',
               os.getenv('HIP_PATH','/opt/rocm/hip')+'/lib',
               os.getenv('ROCM_PATH','/opt/rocm')+'/libhsakmt/lib',
               os.getenv('ROCM_PATH','/opt/rocm')+'/miopen/lib',
               os.getenv('ROCM_PATH','/opt/rocm')+'/miopengemm/lib',
               os.getenv('ROCM_PATH','/opt/rocm')+'/hipblas/lib',
               os.getenv('ROCM_PATH','/opt/rocm')+'/rocblas/lib',
               "/usr/lib/x86_64-linux-gnu",
               "/usr/local/cuda-10.0/lib64/" # /usr/local/cuda-10.0/lib64/libcudart.so.10.0
               # 上面一行是我自己加的

如果不修改的话,会报错

error while loading shared libraries: libcudart.so.10.0: cannot open shared object file: No such file or directory
  1. 运行
$ build/GCN3_X86/gem5.opt configs/example/apu_se.py -n 3 -c ../gem5-resources/src/gpu/square/bin/square

报错

build/GCN3_X86/sim/syscall_emul.cc:66: fatal: syscall sched_get_priority_max (#146) unimplemented.

,可知gem5缺少系统调用的实现,

很烦
很烦
很烦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值