1+ # Copyright (c) 2020 The Regents of the University of California
2+ # All Rights Reserved.
3+ #
4+ # Redistribution and use in source and binary forms, with or without
5+ # modification, are permitted provided that the following conditions are
6+ # met: redistributions of source code must retain the above copyright
7+ # notice, this list of conditions and the following disclaimer;
8+ # redistributions in binary form must reproduce the above copyright
9+ # notice, this list of conditions and the following disclaimer in the
10+ # documentation and/or other materials provided with the distribution;
11+ # neither the name of the copyright holders nor the names of its
12+ # contributors may be used to endorse or promote products derived from
13+ # this software without specific prior written permission.
14+ #
15+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ FROM pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime
27+
28+ # Copied from Gem5 Docker file
29+ ENV DEBIAN_FRONTEND=noninteractive
30+ RUN apt -y update && apt -y upgrade && \
31+ apt -y install build-essential git m4 scons zlib1g zlib1g-dev \
32+ libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev \
33+ python3-dev python-is-python3 doxygen libboost-all-dev \
34+ libhdf5-serial-dev python3-pydot libpng-dev libelf-dev pkg-config pip \
35+ python3-venv black libssl-dev libasan5 libubsan1
36+ RUN pip install mypy pre-commit jupyter
37+
38+ # Pass Access Token securely
39+ ENV PATH=$PATH:/root/.local/bin
40+ ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/opt/conda/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64:$LD_LIBRARY_PATH
41+
42+ # Build Gem5
43+ RUN git clone https://github.com/PSAL-POSTECH/gem5.git --branch TorchSim
44+ RUN cd gem5 && scons build/RISCV/gem5.opt -j $(nproc)
45+ ENV GEM5_PATH=/workspace/gem5/build/RISCV/gem5.opt
46+
47+ # Build LLVM RISC-V
48+ RUN git clone https://github.com/PSAL-POSTECH/llvm-project.git --branch torchsim --depth 1
49+ RUN cd llvm-project && mkdir build && cd build && \
50+ cmake -DLLVM_ENABLE_PROJECTS=mlir -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/riscv-llvm -DLLVM_TARGETS_TO_BUILD=RISCV -G "Unix Makefiles" ../llvm && \
51+ make -j && make install
52+
53+ # Store RISC-V LLVM for TorchSim
54+ ENV TORCHSIM_LLVM_PATH=/riscv-llvm/bin
55+ ENV TORCHSIM_LLVM_INCLUDE_PATH=/riscv-llvm/include
56+ ENV TORCHSIM_DIR=/workspace/PyTorchSim
57+ ENV LLVM_DIR=/riscv-llvm
58+
59+ # Download RISC-V tool chain
60+ RUN apt install -y wget && \
61+ wget https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.12.14/riscv64-glibc-ubuntu-22.04-llvm-nightly-2023.12.14-nightly.tar.gz && \
62+ wget https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.12.14/riscv64-elf-ubuntu-20.04-llvm-nightly-2023.12.14-nightly.tar.gz && \
63+ tar -zxvf riscv64-elf-ubuntu-20.04-llvm-nightly-2023.12.14-nightly.tar.gz && tar -zxvf riscv64-elf-ubuntu-20.04-llvm-nightly-2023.12.14-nightly.tar.gz && \
64+ rm *.tar.gz
65+
66+ ENV RISCV=/workspace/riscv
67+ ENV PATH=$RISCV/bin:$PATH
68+
69+ # Install Spike simulator
70+ RUN apt -y install device-tree-compiler
71+ RUN git clone https://github.com/PSAL-POSTECH/riscv-isa-sim.git --branch TorchSim && cd riscv-isa-sim && mkdir build && cd build && \
72+ ../configure --prefix=$RISCV && make -j && make install
73+
74+ # Install Proxy kernel
75+ RUN git clone https://github.com/riscv-software-src/riscv-pk.git && \
76+ cd riscv-pk && git checkout 4f3debe4d04f56d31089c1c716a27e2d5245e9a1 && mkdir build && cd build && \
77+ ../configure --prefix=$RISCV --host=riscv64-unknown-elf && make -j && make install
78+
79+ # Install torchsim dependency
80+ RUN apt install ninja-build && pip install onnx matplotlib && pip install --user conan==1.56.0
81+
82+ # Prepare ONNXim project
83+ RUN git clone https://github.com/PSAL-POSTECH/PyTorchSim.git --branch tutorial
84+ RUN cd PyTorchSim/TOGSim && \
85+ git submodule update --recursive --init && \
86+ mkdir -p build && \
87+ cd build && \
88+ conan install .. --build=missing && \
89+ cmake .. && \
90+ make -j$(nproc)
0 commit comments