Sunday, July 7, 2019

CUDA GPU Simulator Container

I was searching for a GPU simulator to experiment with CUDA on my laptop, which has no GPU. GPGPU-Sim [1,2] is a cycle-level GPU performance simulator for general purpose computation on GPU. The procedure for installing GPGPU-Sim seemed a little complicated on my MacBook (macOS). Therefore, I proceeded with using docker on my MacBook running an Ubuntu 18.04 docker image and installed CUDA and GPGPU-Sim in it. The procedure for using the GPU simulator with docker to run CUDA programs is listed below.

Software versions in gpgpu-sim container v0.2:

CUDA version: 10.1
gcc/g++ version: 7.5.0
Files: [Dockerfile] [script.sh]

Software versions in gpgpu-sim container v0.1:

CUDA version: 9.1
gcc/g++ version: 6.5.0

How to run:


  • To run the GPGPU-Sim docker image for the first time (use sudo if permission problems arise):

docker run -w /root -it srirajpaul/gpgpu-sim:0.2 /bin/bash

(This command will download and start the docker image containing the CUDA and GPGPU-Sim)

  • To test whether CUDA is working (within the docker container):

cd test
nvcc --cudart shared vec_add.cu -o vec_add
./vec_add

(Remember that the flag '--cudart shared' is required to load the GPGPU-Sim replacement libraries instead of the actual CUDA ones while executing the CUDA program)

  • To stop and exit from the docker container:

exit

  • To start and run the docker container for the second time onwards:

docker start <container-id>
docker attach <container-id>

(The container-id can be obtained using: 'docker container ls -a' )
  • To run directly from the host system, use the exec command:

docker exec -it <container-id> bash -ic 'cd test;sh run.sh'


Note: Tested the GPGPU-Sim installed docker image on Mac OS X, Ubuntu 16.04 and 18.04

[1] Bakhoda, Ali, George L. Yuan, Wilson WL Fung, Henry Wong, and Tor M. Aamodt. "Analyzing CUDA workloads using a detailed GPU simulator." In IEEE International Symposium on Performance Analysis of Systems and Software (ISPASS), Boston, MA, April 19-21, 2009.

[2] Mahmoud Khairy, Zhesheng Shen, Tor M. Aamodt, Timothy G Rogers. "Accel-Sim: An Extensible Simulation Framework for Validated GPU Modeling." In proceedings of the 47th IEEE/ACM International Symposium on Computer Architecture (ISCA), May 29 - June 3, 2020.

4 comments:

Dmitri Krylov said...

Many many thanks, I guess it really can save me, didn't hope to find something like this.
Two questions, could you mamybe advise me plz?
a)A simple one(I'm kinda fresh with dockers, so it might be trivial):
I'm trying to run docker exec nvcc on the same test sample, but residing on in a folder at my host macBook. As a first step I've passed my local directory to docker run as an argument to mount(like docker run -w /root -v "$PWD:$PWD" -it srirajpaul/gpgpu-sim:0.1 /bin/bash).

Then I've just copied your test src to this mounted host local directory and ran nvcc. Everything works fine, of course.

But I need to run the same thing with exec. Docker exec ls -la, for example, runs fine. But when I'm trying to pass nvcc comand to exec, it returns me this:

EMB-T0KPHTDG:NVIDIA ekrydmi$ docker exec -it 6200ba98ed73 nvcc
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"nvcc\": executable file not found in $PATH": unknown

How can I cure it?

I've tried to call exec with which nvcc, with the same reaction.

Finally I've tried to pass env to exec, and here is what I've got:
EMB-T0KPHTDG:NVIDIA ekrydmi$ docker exec -it 6200ba98ed73 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=6200ba98ed73
TERM=xterm
HOME=/root

This is much less then env returns me from inside the docker.
Is it possible to sync the env returns? I guess this is my problem.
Many thanks.

And the second question is just in case: the reason I want to simulate nvcc is because I'm developing some python code using NVIDIA's VPF: https://developer.nvidia.com/blog/vpf-hardware-accelerated-video-processing-framework-in-python/

I'm going to run it on nvidia-gpu machine, but trying to develope the code using a friendly IDE on my local Mac(PyCharm). VPF stuff requires install with cmake, and on nvidia-gpu host, of course, everything runs like a charm. But I can't install it on Mac, since cmake then asks for nvcc location. My hope is to try to feed docker exec call to Cmake at this place. Do you have any experience on something like this? I'd really appreciate any advise.

Again, many thanks,
Dmitri

sriraj said...

Hi Dmitri,
Sorry for the later reply.
The problem is that, it doesn't seem to create a new bash session, and therefore, the .bashrc file using which we set up the environment variables required for CUDA is not executed. We can fix this by starting an interactive bash and passing the command to it.
For example, to execute the run.sh file inside the test folder that builds and executes the CUDA code, we can use the command as follows.

>>>> docker exec -it |container-id| bash -ic 'cd test;sh run.sh'

Not sure whether this can help you to integrate with cmake. But at least you can build and run the CUDA code from the host MacBook.
Hope this helps.
Sriraj

Vardan Akopian said...

Hello Sriraj,

Would you mind sharing the Dockerfile you have used to create these docker images?
I would like to build a new image from the latest version of GPGPU-Sim.

Thanks
-Vardan

sriraj said...

Hello Vardan,
Added the Dockerfile and script. The script does all the work rather than using commands in the Dockerfile since that seemed easier. In the script, you may need to uncomment the wget etc to get the required executables.
Thank you
Sriraj