Vortex GPGPU仿真

1 Vortex 介绍

Vortex GPGPU:基于RISC-V指令集的GPU-CSDN博客

2 环境配置

官网支持的OS环境有:ubuntu18.04、ubuntu20.04、centos7

本文介绍Docker Ubuntu 18.04环境下编译并仿真,在ubuntu20.04环境下依赖库版本不太对。

2.1 下载源码

源码仓库在:https://github.com/vortexgpgpu/vortex

git clone --recursive https://github.com/vortexgpgpu/vortex.git

子仓库ramulator编译会报错,vortex源码中提供了patch来修复这个错误:

cd vortex/third_party/ramulator
git apply ../../miscs/patch/ramulator.patch 
cd ../../../

2.2 创建Docker环境

使用Dockerfile构建一个ubuntu 18.04的环境,Dockerfile如下:

# vortex运行在20.04或者18.04下
# 资料:https://github.com/vortexgpgpu/vortex

# 构建此镜像使用:
# docker image build --build-arg VORTEX_SOURCE_PATH=/home/zac/git/vortex/vortex -t vortex:latest .

FROM ubuntu:18.04
LABEL maintainer="qihangkong@outlook.com"

ENV VORTEX_WORKSPACE=/root/vortex

WORKDIR ${VORTEX_WORKSPACE}
# COPY vortex/ci/toolchain_install.sh /root/

# 设置无交互模式
ENV DEBIAN_FRONTEND=noninteractive

# 设置encoding为 utf-8
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/*
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

# 安装依赖库
RUN apt-get update && \
    apt-get install -y build-essential zlib1g-dev \
    libtinfo-dev libncurses5 uuid-dev \
    libboost-serialization-dev libpng-dev \
    libhwloc-dev software-properties-common \
    wget python \
    && rm -rf /var/lib/apt/lists/*

RUN add-apt-repository ppa:ubuntu-toolchain-r/test
# 编译用到gcc11
RUN apt-get update && apt-get install -y gcc-11 g++-11 && rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11

# 安装toolchain,vortex/ci/toolchain_install.sh 脚本安装的工具有点问题
# 这里使用我备份的:from https://github.com/vortexgpgpu/vortex_tutorials/blob/main/VM_Imgs/VM_README.md

# RUN cd /root; wget https://share.weiyun.com/5KeCbY7D ; tar -xvf toolchains.tar.gz; rm -f toolchains.tar.gz
RUN echo 'export TOOLDIR=/root/vortex/toolchains' >> /root/source.me && \
    echo 'export VORTEX_HOME=$TOOLDIR/vortex'  >> /root/source.me && \
    echo 'export LLVM_VORTEX=$TOOLDIR/llvm-vortex'  >> /root/source.me && \
    echo 'export LLVM_POCL=$TOOLDIR/llvm-pocl'  >> /root/source.me && \
    echo 'export POCL_CC_PATH=$TOOLDIR/pocl/compiler'  >> /root/source.me && \
    echo 'export POCL_RT_PATH=$TOOLDIR/pocl/runtime'  >> /root/source.me && \
    echo 'export RISCV_TOOLCHAIN_PATH=$TOOLDIR/riscv-gnu-toolchain'  >> /root/source.me && \
    echo 'export VERILATOR_ROOT=$TOOLDIR/verilator'  >> /root/source.me && \
    echo 'export SV2V_PATH=$TOOLDIR/sv2v'  >> /root/source.me && \
    echo 'export YOSYS_PATH=$TOOLDIR/yosys'  >> /root/source.me && \
    echo ' ' >> /root/source.me && \
    echo 'export PATH=$YOSYS_PATH/bin:$SV2V_PATH/bin:$VERILATOR_ROOT/bin:$PATH' >> /root/source.me

# RUN cd /root; ./toolchain_install.sh --all
# RUN cd /root; rm -f toolchain_install.sh

将Dockerfile文件保存到当前路径下执行:

docker image build -t vortex:1804 .

2.3 下载Toolchain

vortex仓库提供脚本来下载安装预编译的工具链,但是在测试中发现工具链有点问题,所以我打包可一个 VortexVM镜像 中的工具链:https://share.weiyun.com/5KeCbY7D

下载到 vortex目录下(Dockerfile中设置TOOLChain的路径为/root/vortex/toolchains):

cd vortex 
# 下载 toolchains.tar.gz 到此目录下 
tar -xvf toolchains.tar.gz

3 编译

运行Docker容器,此处将vortex仓库目录映射到/root/vortex路径下,上面的toolchain解压到/root/vortex/toolchains下:

docker run -it -v ./vortex:/root/vortex vortex:1804

进入Docker的终端中执行 make:

zac@zac-us:~/git/vortex$ docker run -it -v ./vortex:/root/vortex vortex:1804 
root@bf68503960d2:~/vortex# source ../source.me
root@bf68503960d2:~/vortex# make

正确编译完成之后日志如下:

...... 
make[3]: Leaving directory '/root/vortex/tests/opencl/convolution'
make[2]: Leaving directory '/root/vortex/tests/opencl'
make -C riscv
make[2]: Entering directory '/root/vortex/tests/riscv'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/root/vortex/tests/riscv'
make -C unittest
make[2]: Entering directory '/root/vortex/tests/unittest'
make -C vx_malloc
make[3]: Entering directory '/root/vortex/tests/unittest/vx_malloc'
g++ -std=c++11 -Wall -Wextra -pedantic -Wfatal-errors -I/root/vortex/runtime/common -O2 -DNDEBUG main.cpp  -o vx_malloc
make[3]: Leaving directory '/root/vortex/tests/unittest/vx_malloc'
make[2]: Leaving directory '/root/vortex/tests/unittest'
make[1]: Leaving directory '/root/vortex/tests'
root@2b43e23aed84:~/vortex#

4 运行

上面已经设置好了环境变量,可以直接运行如下:

./ci/blackbox.sh --cores=2 --app=vecadd

运行结果显示:

root@2b43e23aed84:~/vortex# ./ci/blackbox.sh --cores=2 --app=vecadd
CONFIGS=-DNUM_CLUSTERS=1 -DNUM_CORES=2 -DNUM_WARPS=4 -DNUM_THREADS=4
running: CONFIGS=-DNUM_CLUSTERS=1 -DNUM_CORES=2 -DNUM_WARPS=4 -DNUM_THREADS=4     make -C ./ci/../runtime/simx
running: make -C ./ci/../tests/opencl/vecadd run-simx
make: Entering directory '/root/vortex/tests/opencl/vecadd'
LD_LIBRARY_PATH=/root/vortex/toolchains/pocl/runtime/lib:/root/vortex/runtime/simx: ./vecadd -n64
Workload size=64
Create context
Allocate device buffers
Create program from kernel source
Upload source buffers
Execute the kernel
Elapsed time: 59 ms
Download destination buffer
Verify result
PASSED!
PERF: instrs=3539, cycles=25118, IPC=0.140895
make: Leaving directory '/root/vortex/tests/opencl/vecadd'

参考资料:

  • https://github.com/vortexgpgpu/vortex/blob/master/README.md

  • https://github.com/vortexgpgpu/vortex_tutorials

  • https://blog.csdn.net/u014756627/article/details/132591618?spm=1001.2014.3001.5501

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马师傅哈哈哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值