1. 环境准备与工具链配置
在Ubuntu 22.04系统上搭建GPGPU-Sim环境需要特别注意工具链的兼容性问题。我的测试环境搭载了NVIDIA GeForce 940MX显卡(Compute Capability 5.0),以下是详细配置过程:
1.1 基础依赖安装
首先需要安装必要的开发工具和库文件。执行以下命令安装基础依赖:
bash复制sudo apt-get update
sudo apt-get install -y build-essential xutils-dev bison zlib1g-dev flex \
libglu1-mesa-dev doxygen graphviz python-pmw python-ply \
python-numpy libpng-dev python3-matplotlib libxi-dev libxmu-dev git
注意:Ubuntu 22.04默认的Python版本是3.x,但GPGPU-Sim部分脚本仍依赖Python 2.x。如果遇到Python兼容性问题,建议使用virtualenv创建Python 2.7虚拟环境。
1.2 CUDA工具链配置
由于940MX属于Maxwell架构(Compute Capability 5.0),需要安装兼容的CUDA版本。我选择的是CUDA 11.4:
bash复制wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run
sudo sh cuda_11.4.2_470.57.02_linux.run
安装完成后,在~/.bashrc中添加以下环境变量:
bash复制export CUDA_INSTALL_PATH=/usr/local/cuda-11.4
export PATH=/usr/local/cuda-11.4/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH
验证安装:
bash复制nvcc --version
# 应显示:Cuda compilation tools, release 11.4, V11.4.152
1.3 GCC版本管理
GPGPU-Sim对GCC版本有特定要求。Ubuntu 22.04默认使用GCC 11,但编译时可能出现标准库兼容性问题。解决方案是安装GCC-10并设置为默认编译器:
bash复制sudo apt-get install gcc-10 g++-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
2. GPGPU-Sim安装与配置
2.1 源码获取与编译
从官方仓库克隆最新代码并编译:
bash复制git clone https://github.com/gpgpu-sim/gpgpu-sim_distribution.git
cd gpgpu-sim_distribution
source setup_environment
make -j$(nproc)
常见问题:如果编译时出现
__malloc__相关错误,需要在make命令中显式指定GCC-10:bash复制make CC=gcc-10 CXX=g++-10 -j$(nproc)
2.2 配置文件选择
GPGPU-Sim提供了多种预置配置文件。对于940MX(Compute Capability 5.0),建议使用SM50配置文件:
bash复制cp configs/tested-cfgs/SM50_GTX980/* .
关键配置文件说明:
gpgpusim.config:主配置文件,定义缓存大小、线程调度等参数config_fermi_islip.icnt:互连网络配置文件(Maxwell沿用Fermi配置)gpuwattch_gtx980.xml:功耗模型配置文件
2.3 环境变量检查
确保环境变量正确设置:
bash复制echo $LD_LIBRARY_PATH
# 应显示gpgpu-sim的库路径在前,如:~/gpgpu-sim_distribution/lib/...
3. 测试用例编译与运行
3.1 向量加法测试程序
创建vectorAdd.cu测试文件:
cuda复制#include <stdio.h>
#define CHECK(call) { \
const cudaError_t error = call; \
if (error != cudaSuccess) { \
printf("Error: %s:%d, code: %d, reason: %s\n", \
__FILE__, __LINE__, error, cudaGetErrorString(error)); \
exit(1); \
} \
}
__global__ void vector_add(const float *a, const float *b, float *c, int n) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < n)
c[idx] = a[idx] + b[idx];
}
int main() {
int n = 1<<12;
size_t bytes = n * sizeof(float);
float h_a[n], h_b[n], h_c[n];
for (int i = 0; i < n; i++) {
