Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 14 additions & 44 deletions .github/workflows/build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ py_venv_path="$project_root/.venv"
cinnamon_path="$project_root/cinnamon"
llvm_path="$project_root/llvm"
torch_mlir_path="$project_root/torch-mlir"
upmem_path="$project_root/upmem"

verbose=0
reconfigure=0
Expand Down Expand Up @@ -135,33 +134,18 @@ if [[ $setup_python_venv -eq 1 ]]; then
supported_python_executable=python3.12
fi

reconfigure_python_venv=0
if [ ! -d "$py_venv_path" ]; then
status "Creating Python venv"
$supported_python_executable -m venv "$py_venv_path"
source "$py_venv_path/bin/activate"
reconfigure_python_venv=1
status "Installing Python dependencies"
# https://pytorch.org/get-started/locally/
if [[ $enable_cuda -eq 1 ]]; then
torch_source=https://download.pytorch.org/whl/cu124
elif [[ $enable_roc -eq 1 ]]; then
torch_source=https://download.pytorch.org/whl/rocm6.1
else
status "Enabling Python venv"
source "$py_venv_path/bin/activate"
torch_source=https://download.pytorch.org/whl/cpu
fi

if [ $reconfigure -eq 1 ] || [ $reconfigure_python_venv -eq 1 ]; then
status "Installing Python dependencies"
# https://pytorch.org/get-started/locally/
if [[ $enable_cuda -eq 1 ]]; then
torch_source=https://download.pytorch.org/whl/cu124
elif [[ $enable_roc -eq 1 ]]; then
torch_source=https://download.pytorch.org/whl/rocm6.1
else
torch_source=https://download.pytorch.org/whl/cpu
fi
verbose_cmd pip install torch torchvision torchaudio --index-url $torch_source

verbose_cmd pip install --upgrade pip
verbose_cmd pip install torch torchvision torchaudio --index-url $torch_source
verbose_cmd pip install pybind11
verbose_cmd pip install build
fi
elif [[ $setup_python_venv -eq 0 ]]; then
warning "Skipping Python venv setup"
warning "Make sure to have a correct Python environment set up"
Expand All @@ -187,7 +171,7 @@ if [[ $checkout_and_build_llvm -eq 1 ]]; then

if [ $reconfigure -eq 1 ] || [ $reconfigure_llvm -eq 1 ]; then
status "Configuring LLVM"
cmake -S llvm -B build \
cmake -G Ninja -S llvm -B build \
-Wno-dev \
-DLLVM_ENABLE_PROJECTS="mlir;llvm;clang" \
-DLLVM_TARGETS_TO_BUILD="host" \
Expand All @@ -203,7 +187,7 @@ if [[ $checkout_and_build_llvm -eq 1 ]]; then
fi

status "Building LLVM"
cmake --build build --target all llc opt
ninja -C build all llc opt

export PATH=$llvm_path/build/bin:$PATH
elif [[ $checkout_and_build_llvm -eq 0 ]]; then
Expand Down Expand Up @@ -270,20 +254,6 @@ elif [[ $checkout_and_build_torch_mlir -eq 0 ]]; then
warning "The following steps will need TORCH_MLIR_DIR to be set in their respective <STEP>_CMAKE_OPTIONS"
fi

if [[ $checkout_upmem -eq 1 ]]; then
if [ ! -d "$upmem_path" ]; then
status "Downloading UpMem SDK"
upmem_archive="upmem.tar.gz"
curl http://sdk-releases.upmem.com/2024.1.0/ubuntu_22.04/upmem-2024.1.0-Linux-x86_64.tar.gz --output "$upmem_archive"
mkdir "$upmem_path"
tar xf "$upmem_archive" -C "$upmem_path" --strip-components=1
rm "$upmem_archive"
fi
elif [[ $checkout_upmem -eq 0 ]]; then
warning "Skipping UpMem checkout"
warning "The following steps will need UPMEM_DIR to be set in their respective <STEP>_CMAKE_OPTIONS"
fi

cd "$cinnamon_path"

if [ ! -d "build" ] || [ $reconfigure -eq 1 ]; then
Expand All @@ -302,18 +272,18 @@ if [ ! -d "build" ] || [ $reconfigure -eq 1 ]; then
fi

if [[ $checkout_upmem -eq 1 ]]; then
dependency_paths="$dependency_paths -DUPMEM_DIR=$upmem_path"
dependency_paths="$dependency_paths -DUPMEM_DIR=/opt/upmem/"
fi

cmake -S . -B "build" \
cmake -G Ninja -S . -B "build" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
$dependency_paths \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
$CINNAMON_CMAKE_OPTIONS
fi

status "Building Cinnamon"
cmake --build build --target all
ninja -C build all

if [[ $setup_python_venv -eq 1 ]] && [[ -n "$llvm_path" ]] && [[ -n "$torch_mlir_path" ]]; then
status "Building Cinnamon Python package"
Expand Down Expand Up @@ -349,4 +319,4 @@ if [[ $setup_python_venv -eq 1 ]] && [[ -n "$llvm_path" ]] && [[ -n "$torch_mlir
elif [[ $setup_python_venv -eq 0 ]]; then
warning "Skipping Cinnamon Python package build"
warning "Make sure to have a correct Python environment set up"
fi
fi
67 changes: 67 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# syntax=docker/dockerfile:1.7

FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

# Required OS packages.
RUN apt-get update && apt-get install -y \
build-essential \
ca-certificates \
clang \
coinor-cbc \
coinor-libcbc-dev \
lld \
cmake \
ninja-build \
git \
gdb \
curl \
wget \
pkg-config \
bash-completion \
python3 \
python3-dev \
python3-venv \
python3-pip \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Setup the virtual environment.
RUN python3 -m venv /opt/venv && \
/opt/venv/bin/pip install --upgrade pip setuptools wheel && \
/opt/venv/bin/pip install "pybind11<3" numpy pytest build

# Install Rust.
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y

# Install the `just` tool.
RUN arch="$(dpkg --print-architecture)" && \
case "$arch" in \
amd64) JUST_ARCH=x86_64-unknown-linux-musl ;; \
arm64) JUST_ARCH=aarch64-unknown-linux-musl ;; \
*) echo "Unsupported arch: $arch" && exit 1 ;; \
esac && \
wget -qO- "https://github.com/casey/just/releases/download/1.51.0/just-1.51.0-${JUST_ARCH}.tar.gz" \
| tar xz -C /usr/local/bin just

# Install UPMEM.
RUN wget \
https://github.com/kagandikmen/upmem-sdk/raw/refs/heads/master/2024.2.0/upmem-2024.2.0-Linux-x86_64.tar.gz \
-O upmem.tar.gz && \
mkdir -p /opt/upmem && \
tar xf upmem.tar.gz -C /opt/upmem --strip-components=1 && \
rm upmem.tar.gz

# Setup .bashrc
RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc
RUN echo 'source /opt/venv/bin/activate' >> $HOME/.bashrc

# Setup environment variables.
ENV VIRTUAL_ENV=/opt/venv
ENV PATH=/opt/venv/bin:/usr/local/bin:${PATH}
ENV GUROBI_ROOT=/opt/gurobi1302/linux64
ENV UPMEM_HOME=/opt/upmem

WORKDIR /workspace/cinnamon
CMD ["/bin/bash"]
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,44 @@ Emerging compute-near-memory (CNM) and compute-in-memory (CIM) architectures hav

This is an example of how you can build the framework locally.

### Prerequisites
### Docker image

This repository conveniently ships a `Dockerfile` with all the required system
packages. To use it, clone the repository and, from its root,

1. Build the image

```
docker build -t cinnamon-dev .
```

2. Start a container

```
docker run \
--rm \
-it \
-v \
"$PWD":/workspace/cinnamon \
-w /workspace/cinnamon \
cinnamon-dev
```

3. Build Cinnamon inside the container

```
just configure -no-torch-mlir
```

As the container is mapped to the root of the project, it can be safely exited
without losing data.

Notice that it is assumed that you have the [Gurobi Optimizer](https://www.gurobi.com/)
installed in your machine in `/opt/gurobi1302/`.

### Manual installation

#### Prerequisites

CINM depends on a patched version of `LLVM 19.1.3`. This is built automatically.
Additionally, a number of software packages are required to build it:
Expand All @@ -37,7 +74,7 @@ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 70 --slave /
# Or use another compiler or gcc/g++ version supporting the C++ 20 standard.
```

### Download and Build
#### Download and Build

The repository contains a `justfile` that installs all needed dependencies and builds the sources.

Expand Down
3 changes: 1 addition & 2 deletions cinnamon/lib/Dialect/Bits/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ LINK_LIBS PUBLIC
MLIRTransformUtils
)

# set(GUROBI_ROOT "/home/tianruiz/gurobi/linux64")
set(GUROBI_ROOT "/opt/gurobi1300/linux64")
set(GUROBI_ROOT "/opt/gurobi1302/linux64")

target_include_directories(BitsTransforms PRIVATE
"${GUROBI_ROOT}/include"
Expand Down