Skip to content

A self-developed version of the user-mode CUDA emulator project and a learning repository for Rust

License

Notifications You must be signed in to change notification settings

Conqueror712/CUDA-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

一、Linux环境选择

首先准备一个带NVIDIA GPU的Linux环境;

笔者这里用的是WSL,N卡是原本Windows上带的。

  • Ubuntu 20.04 LTS
  • RTX 1650

尝试过的其他方法:

  • Windows环境(兼容性问题)
  • Vmware虚拟机环境(虚拟化过程繁琐)
  • 单主机双系统(切换不便,卡顿)
  • 云服务器(成本问题,有些驱动版本需要更新)
  • Mac环境(不支持CUDA)

二、NVIDIA驱动安装

直接用Windows下载.exe文件安装;

另外,安装过程会伴随多次黑屏和重启,并且会需要一段时间,请耐心等待,会自动同步到WSL中;

如果没同步就请apt install nvidia-utils-535-server

值得一提的是,安装之前需要把旧版的带NVIDIA的软件全部卸载(除了NVIDIA Control Panel)

image.png

作为参考,笔者的驱动版本是536.67

check: nvidia-smi

image.png

三、更新依赖

sudo apt update
sudo apt-get update
sudo apt-get install libclang-dev
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

获取权限(可选):sudo su

四、CUDA 12.2下载安装:

方式一:

推荐基于发行版的文档进行安装,这里是Ubuntu,参考文档如下:

https://help.ubuntu.com/community/NvidiaDriversInstallation

方式二:

直接安装:

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda

更新环境变量nano ~/.bashrc --> 以下操作 --> source ~/.bashrc

注意,这一步如果原本机器上没有旧版的CUDA就不用做

export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

注:退出nano的方法可以是Ctrl + X, Y, Enter(三步)

check: nvcc --version

image.png

五、Rust & Cargo下载

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh之后输入1

随后重新加载source $HOME/.cargo/env

check: cargo --version && rustc --version

image.png


六、克隆仓库 + 环境变量

git clone https://github.com/Conqueror712/CUDA-Simulator.git

配置环境变量,用nano写入nano ~/.bashrc,写入后保存source ~/.bashrc

export PATH=/usr/local/cuda-12.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-12.2/bin:$PATH
export LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu/
export BINDGEN_EXTRA_CLANG_ARGS="-I /usr/local/cuda-12.2/include"

七、生成动态链接库

于项目根目录下cargo build --release,生成libcuda.so文件,默认在target/release/

image.png

八、简单测试

  1. cd进入smoketest,用nvcc smoketest.cu编译得到a.out,再运行./a.out

    image.png

  2. 无错误之后方可LD_PRELOAD=/home/<username>/CUDA-Simulator/cargo_demo/target/release/libcuda.so ./a.out查看trace(已经实现的会显示..... --> CUDA_SUCCESS)

    image.png

  3. cargo doc --open在浏览器中打开文档查看函数签名

    image.png

  4. 之后往lib.rs中添加自己的实现即可


FIN

About

A self-developed version of the user-mode CUDA emulator project and a learning repository for Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages