ubuntu 18.04 cuda 11.01 gpgpu-sim 裸机编译

1,环境

ubuntu 18.04

x86_64

cuda 11.01

gpgpu-sim master

commit 90ec3399763d7c8512cfe7dc193473086c38ca38

2,预备环境

一个比较新的 ubuntu 18.04,为了迎合 cuda 11.01 的版本需求

安装如下软件:

bash 复制代码
sudo apt-get install -y     xutils-dev bison zlib1g-dev flex libglu1-mesa-dev doxygen graphviz     python-pmw python-ply python-numpy python-matplotlib python-pip libpng-dev

3,安装cuda sdk 11.01

下载:

bash 复制代码
wget https://developer.download.nvidia.com/compute/cuda/11.0.1/local_installers/cuda_11.0.1_450.36.06_linux.run

安装在目录 /home/hanmeimei/cuda/cuda

bash 复制代码
 bash cuda_11.0.1_450.36.06_linux.run --silent --toolkit --toolkitpath=/home/hanmeimei/cuda/cuda

设置环境变量:

bash 复制代码
export CUDA_INSTALL_PATH=/home/hanmeimei/cuda/cuda

4,下载编译 gpgpu-sim master

bash 复制代码
git clone https://github.com/gpgpu-sim/gpgpu-sim_distribution.git

cd gpgpu-sim_distribution/

设置环境:

bash 复制代码
 . setup_environment

make -j

5. 编译运行 cuda app

此时 nvcc 是刚才安装的 nvcc

vim vectorAdd.cu

cpp 复制代码
#include <iostream>
#include <cuda_runtime.h>
 
#define N 16384
 
// write kernel function of vector addition
__global__ void vecAdd(float *a, float *b, float *c, int n)
{
    int i = threadIdx.x + blockDim.x * blockIdx.x;
    if (i < n)
        c[i] = a[i] + b[i];
}
 
int main()
{
    float *a, *b, *c;
    float *d_a, *d_b, *d_c;
    int size = N * sizeof(float);
 
    // allocate space for device copies of a, b, c
    cudaMalloc((void **)&d_a, size);
    cudaMalloc((void **)&d_b, size);
    cudaMalloc((void **)&d_c, size);
 
    // allocate space for host copies of a, b, c and setup input values
    a = (float *)malloc(size);
    b = (float *)malloc(size);
    c = (float *)malloc(size);
 
    for (int i = 0; i < N; i++)
    {
        a[i] = i;
        b[i] = i * i;
    }
 
    // copy inputs to device
    cudaMemcpy(d_a, a, size, cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, b, size, cudaMemcpyHostToDevice);
 
    // launch vecAdd() kernel on GPU
    vecAdd<<<(N + 255) / 256, 256>>>(d_a, d_b, d_c, N);
 
    cudaDeviceSynchronize();
 
    // copy result back to host
    cudaMemcpy(c, d_c, size, cudaMemcpyDeviceToHost);
 
    // verify result
    for (int i = 0; i < N; i++)
    {
        if (a[i] + b[i] != c[i])
        {
            std::cout << "Error: " << a[i] << " + " << b[i] << " != " << c[i] << std::endl;
            break;
        }
    }
 
    std::cout << "Done!" << std::endl;
 
    // clean up
    free(a);
    free(b);
    free(c);
    cudaFree(d_a);
    cudaFree(d_b);
    cudaFree(d_c);
 
    return 0;
}

编译:

bash 复制代码
nvcc vectorAdd.cu --cudart shared -o vectorAdd

拷贝 配置文件:

bash 复制代码
cp gpgpu-sim_distribution/configs/tested-cfgs/SM7_QV100/config_volta_islip.icnt ./
bash 复制代码
 cp gpgpu-sim_distribution/configs/tested-cfgs/SM7_QV100/gpgpusim.config ./

运行app;

./vectorAdd

运行结束:

相关推荐
luoganttcc5 天前
ubuntu.24安装cuda
cuda
扫地的小何尚8 天前
NVIDIA RTX 系统上使用 llama.cpp 加速 LLM
人工智能·aigc·llama·gpu·nvidia·cuda·英伟达
吃肉夹馍不要夹馍10 天前
CublasLt 极简入门
cuda·cublas·gemm·cublaslt
Code-world-112 天前
Ubuntu系统安装NVIDIA驱动、CUDA、PyTorch等GPU深度学习环境
linux·pytorch·深度学习·cuda·深度强化学习
狼刀流23 天前
(8) cuda分析工具
python·cuda
CodeLearing24 天前
【CUDA代码实践03】m维网格n维线程块对二维矩阵的索引
线性代数·矩阵·cuda
坐望云起1 个月前
Ubuntu20.04 更新Nvidia驱动 + 安装CUDA12.1 + cudnn8.9.7
linux·ubuntu·nvidia·cuda·onnx·1024程序员节
狼刀流1 个月前
(5)cuda中的grid、block
c++·cuda·1024程序员节
Mundaneman1 个月前
架构发展史
架构·cuda
张大饼的最爱1 个月前
CUDA 共享内存 shared memory
cuda·cuda c