Skip to content

Commit

Permalink
ApraPipes Build Automation Scripts (#301)
Browse files Browse the repository at this point in the history
* initial commit

* refactored linux cuda.sh

* addressed PR comments
  • Loading branch information
venkat0907 authored Sep 1, 2023
1 parent 0d03309 commit 9ec490e
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 72 deletions.
83 changes: 12 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,16 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
### Cudnn
* Download [Cudnn](https://developer.nvidia.com/rdp/cudnn-archive#a-collapse765-102) and extract files where cuda is installed. Note: Please be aware that this process requires some effort. Here are the necessary steps:
* Download the correct tar/zip file matching your cuda version. _Do not download the exe/installer/deb package._
* Download the correct zip file matching your cuda version. _Do not download the exe/installer/deb package._
* Windows:
* Download [this file](https://developer.nvidia.com/compute/cudnn/secure/8.3.2/local_installers/10.2/cudnn-windows-x86_64-8.3.2.44_cuda10.2-archive.zip).
* Extract the downloaded file and copy files to ```C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2``` using an __administrative command prompt__ as follows
```
cd .\extracted_folder
cd include
copy *.h "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include\"
cd ..\lib
copy *.lib "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64\"
cd ..\bin
copy *.dll "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin\"
```
* Download [this file](https://developer.nvidia.com/compute/cudnn/secure/8.3.2/local_installers/10.2/cudnn-windows-x86_64-8.3.2.44_cuda10.2-archive.zip).
### Prerequisites
* Install Visual Studio 2019 Community
* Install Desktop development C++
* .NET Desktop development
* Universal Windows Development Platform
* Install choco:
Open Windows PowerShell as Administrator and run:
```
Set-ExecutionPolicy AllSigned
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
```
* Install build dependencies using choco:
```
choco feature enable -n allowEmptyChecksums && choco install 7zip git python3 cmake pkgconfiglite -y && pip3 install ninja && pip3 install meson
```
* Clone with submodules and LFS.
```
git clone --recursive https://github.com/Apra-Labs/ApraPipes.git
Expand All @@ -85,6 +67,8 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
<summary>Build</summary>
### Build Without Cuda
Open PowerShell as an administrator and execute the following commands
If your windows system does not have an NVIDIA GPU use this script
```
build_windows_no_cuda.bat
Expand Down Expand Up @@ -137,39 +121,11 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
20.04 - [CUDA Toolkit 11.7](https://developer.nvidia.com/cuda-11-7-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04)
### Cudnn
* Download [Cudnn](https://developer.nvidia.com/rdp/cudnn-archive#a-collapse765-102) and extract files where cuda is installed. Note: Please be aware that this process requires some effort. Here are the necessary steps:
* Download [Cudnn](https://developer.nvidia.com/rdp/cudnn-archive#a-collapse765-102)
* Linux:
* Download [this file](https://developer.nvidia.com/compute/cudnn/secure/8.3.2/local_installers/10.2/cudnn-linux-x86_64-8.3.2.44_cuda10.2-archive.tar.xz)
* extract the files
```
xz -d cudnn-linux-x86_64-8.3.2.44_cuda10.2-archive.tar.xz
tar xvf cudnn-linux-x86_64-8.3.2.44_cuda10.2-archive.tar
```
* copy files retaining the links
```
cd ./cudnn-linux-x86_64-8.3.2.44_cuda10.2-archive
sudo cp -P include/* /usr/local/cuda/include/
sudo cp -P lib/* /usr/local/cuda/lib64/
```
* To add Cuda to path append following lines to ~/.bashrc.
```
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
```
* Reload ~/.bashrc:
```
source ~/.bashrc:
```
* Verify by checking nvcc --version and nvidia-smi both must point to correct versions of cuda and nvidia driver in the system.
### Prerequisites
* Run the following to get latest build tools
```
sudo apt-get update && sudo apt-get -y install autoconf automake autopoint build-essential git-core git-lfs libass-dev libfreetype6-dev libgnutls28-dev libmp3lame-dev libsdl2-dev libssl-dev libtool libsoup-gnome2.4-dev libncurses5-dev libva-dev libvdpau-dev libvorbis-dev libxdamage-dev libxcursor-dev libxinerama-dev libx11-dev libgles2-mesa-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev ninja-build pkg-config texinfo wget yasm zlib1g-dev nasm gperf bison curl zip unzip tar python3-pip flex && pip3 install meson
```
* Note: start a new terminal as pip3 settings do not get effective on the same shell
* CMake minimum version 3.24 - Follow [this article](https://anglehit.com/how-to-install-the-latest-version-of-cmake-via-command-line/) to update cmake
* Clone with submodules and LFS.
```
git clone --recursive https://github.com/Apra-Labs/ApraPipes.git
```
Expand All @@ -185,11 +141,11 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
### Build Without Cuda
If your windows system does not have an NVIDIA GPU use this script
```
./build_linux_no_cuda.sh
sudo ./build_linux_no_cuda.sh
```
### Build With Cuda
```
./build_linux_cuda.sh
sudo ./build_linux_cuda.sh
```
Build can take ~2 hours depending on the machine configuration.
Expand Down Expand Up @@ -229,26 +185,11 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
### Prerequisites
* Setup the board with [Jetpack 4.4](https://docs.nvidia.com/sdk-manager/install-with-sdkm-jetson/index.html) or higher as supported.
* Run the following commands to build required libraries.
```
sudo apt-get update && sudo apt-get -y install git-lfs libncurses5-dev ninja-build nasm curl libudev-dev libssl-dev && sudo snap install cmake --classic
```
* Append following lines to ~/.bashrc.
```
export VCPKG_FORCE_SYSTEM_BINARIES=1
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
```
* Reload ~/.bashrc:
```
source ~/.bashrc:
```
* Clone with submodules and LFS.
```
git clone --recursive https://github.com/Apra-Labs/ApraPipes.git
```
* Run `./bootstrap-vcpkg.sh` in vcpkg/ directory
* Run `./vcpkg integrate install`
</details>
<details>
Expand All @@ -261,7 +202,7 @@ Aprapipes is automatically built and tested on Ubuntu (18.04 and 20.04), Jetson
```
* ApraPipes builds CUDA version on Jerson Boads.
```
./build_jetson.sh
sudo ./build_jetson.sh
```
Build can take ~12 hours on Jetson Nano.
Expand Down
8 changes: 8 additions & 0 deletions build_jetson.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
chmod +x build_scripts/build_dependencies_jetson_cuda.sh
./build_scripts/build_dependencies_jetson_cuda.sh

cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
cd ..

CMAKE_THCOUNT=$(sh ./checkProc.sh)
mkdir -p _build
cd _build
Expand Down
4 changes: 3 additions & 1 deletion build_linux_cuda.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cp base/vcpkg.cuda.json base/vcpkg.json
chmod +x build_scripts/build_dependencies_linux_cuda.sh
./build_scripts/build_dependencies_linux_cuda.sh

cd vcpkg
./bootstrap-vcpkg.sh
vcpkg integrate install
Expand Down
4 changes: 4 additions & 0 deletions build_linux_no_cuda.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
chmod +x build_scripts/build_dependencies_linux_no_cuda.sh
./build_scripts/build_dependencies_linux_no_cuda.sh

chmod +x base/fix-vcpkg-json.sh
./base/fix-vcpkg-json.sh true false false

cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
Expand Down
44 changes: 44 additions & 0 deletions build_scripts/build_dependencies_jetson_cuda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# List of required dependencies
dependencies=("git-lfs" "libncurses5-dev" "ninja-build" "nasm" "curl" "libudev-dev" "libssl-dev")

missing_dependencies=()

# Check and collect missing dependencies
for dependency in "${dependencies[@]}"; do
if ! dpkg -s "$dependency" 2>&1; then
missing_dependencies+=("$dependency")
fi
done

# If there are missing dependencies, install them
if [ "${#missing_dependencies[@]}" -gt 0 ]; then
echo "Installing missing dependencies..."
apt-get update -qq
apt-get -y install "${missing_dependencies[@]}"
fi

# Install Cmake if not present
if ! cmake --version; then
echo "CMake is not installed. Installing CMake..."
snap install cmake --classic
fi

if [ ! -d "/usr/local/cuda/include" ] || [ ! -d "/usr/local/cuda/lib64" ]; then
echo "ERROR: CUDA Toolkit is not properly installed. Please install CUDA Toolkit."
exit 1
fi

if nvcc --version; then
TARGET_USER="$SUDO_USER"
TARGET_HOME=$(eval echo ~$TARGET_USER)
echo 'export VCPKG_FORCE_SYSTEM_BINARIES=1' | sudo -u $TARGET_USER tee -a $TARGET_HOME/.bashrc
echo 'export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}' | sudo -u $TARGET_USER tee -a $TARGET_HOME/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' | sudo -u $TARGET_USER tee -a $TARGET_HOME/.bashrc
echo "Appended paths to ~/.bashrc and saved changes."
source ~/.bashrc
echo "Reloaded ~/.bashrc"
fi

echo "Dependencies verified and installed successfully."
78 changes: 78 additions & 0 deletions build_scripts/build_dependencies_linux_cuda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# List of required dependencies
dependencies=( "curl" "zip" "unzip" "tar" "autoconf" "automake" "autopoint" "build-essential"
"flex" "git-core" "git-lfs" "libass-dev" "libfreetype6-dev" "libgnutls28-dev" "libmp3lame-dev"
"libsdl2-dev" "libssl-dev" "libtool" "libsoup-gnome2.4-dev" "libncurses5-dev" "libva-dev" "libvdpau-dev"
"libvorbis-dev" "libxcb1-dev" "libxdamage-dev" "libxcursor-dev" "libxinerama-dev" "libx11-dev" "libgles2-mesa-dev" "libxcb-shm0-dev" "libxcb-xfixes0-dev"
"ninja-build" "pkg-config" "texinfo" "wget" "yasm" "zlib1g-dev" "nasm" "gperf" "bison" "python3" "python3-pip")

missing_dependencies=()

# Check and collect missing dependencies
for dependency in "${dependencies[@]}"; do
if ! dpkg -s "$dependency" >/dev/null 2>&1; then
missing_dependencies+=("$dependency")
fi
done

# If there are missing dependencies, install them
if [ "${#missing_dependencies[@]}" -gt 0 ]; then
echo "Installing missing dependencies..."
apt-get update -qq
apt-get -y install "${missing_dependencies[@]}"
fi

# Install Meson if not present
if ! meson --version &>/dev/null; then
echo "meson is not installed. Installing meson..."
pip3 install meson
fi

# Install Cmake if not present
if ! cmake --version &>/dev/null; then
echo "CMake is not installed. Installing CMake..."
pip3 install cmake --upgrade
fi

# Install jq if not present
if ! jq --version &>/dev/null; then
echo "jq is not installed. Installing jq..."
apt install jq
fi

if [ ! -d "/usr/local/cuda/include" ] || [ ! -d "/usr/local/cuda/lib64" ]; then
echo "ERROR: CUDA Toolkit is not properly installed. Please install CUDA Toolkit."
exit 1
fi

if ! nvcc --version &>/dev/null; then
userName=$(whoami)
cudnn_archives="/home/$userName/Downloads/cudnn-*.tar.xz"

for archive in $cudnn_archives; do
if [ -e "$archive" ]; then
echo "Extracting $archive..."
tar xf "$archive" -C /home/$userName/Downloads/
fi
done

echo "Copying files..."
cp -r /home/$userName/Downloads/cudnn-*/include/* /usr/local/cuda/include/
cp -r /home/$userName/Downloads/cudnn-*/lib/* /usr/local/cuda/lib64/

TARGET_USER="$SUDO_USER"
TARGET_HOME=$(eval echo ~$TARGET_USER)

# Append lines to the target user's ~/.bashrc
echo 'export PATH=/usr/local/cuda/bin:${PATH}' | sudo -u $TARGET_USER tee -a $TARGET_HOME/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}' | sudo -u $TARGET_USER tee -a $TARGET_HOME/.bashrc

# Reload .bashrc
source $TARGET_HOME/.bashrc

echo "Appended line to ~/.bashrc and saved changes."
echo "Reloaded ~/.bashrc"
fi

echo "Dependencies verified and installed successfully."
44 changes: 44 additions & 0 deletions build_scripts/build_dependencies_linux_no_cuda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# List of required dependencies
dependencies=( "curl" "zip" "unzip" "tar" "autoconf" "automake" "autopoint" "build-essential"
"flex" "git-core" "git-lfs" "libass-dev" "libfreetype6-dev" "libgnutls28-dev" "libmp3lame-dev"
"libsdl2-dev" "libssl-dev" "libtool" "libsoup-gnome2.4-dev" "libncurses5-dev" "libva-dev" "libvdpau-dev"
"libvorbis-dev" "libxcb1-dev" "libxdamage-dev" "libxcursor-dev" "libxinerama-dev" "libx11-dev" "libgles2-mesa-dev" "libxcb-shm0-dev" "libxcb-xfixes0-dev"
"ninja-build" "pkg-config" "texinfo" "wget" "yasm" "zlib1g-dev" "nasm" "gperf" "bison" "python3" "python3-pip")

missing_dependencies=()

# Check and collect missing dependencies
for dependency in "${dependencies[@]}"; do
if ! dpkg -s "$dependency" >/dev/null 2>&1; then
missing_dependencies+=("$dependency")
fi
done

# If there are missing dependencies, install them
if [ "${#missing_dependencies[@]}" -gt 0 ]; then
echo "Installing missing dependencies..."
apt-get update -qq
apt-get -y install "${missing_dependencies[@]}"
fi

# Install Meson if not present
if ! meson --version &>/dev/null; then
echo "meson is not installed. Installing meson..."
pip3 install meson
fi

# Install Cmake if not present
if ! cmake --version &>/dev/null; then
echo "CMake is not installed. Installing CMake..."
pip3 install cmake --upgrade
fi

# Install jq if not present
if ! jq --version &>/dev/null; then
echo "jq is not installed. Installing jq..."
apt install jq
fi

echo "Dependencies verified and installed successfully."
36 changes: 36 additions & 0 deletions build_scripts/build_dependencies_windows_cuda.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Set execution policy and install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

# Enable feature and install dependencies
choco feature enable -n allowEmptyChecksums
choco install 7zip git python3 cmake pkgconfiglite -y

# Install required Python packages
pip3 install ninja
pip3 install meson

# Install cmake
pip3 install cmake --upgrade

$cudaVersion = (Get-ChildItem "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\" -Directory | Where-Object { $_.Name -match 'v\d+\.\d+' }).Name

if (-not (Test-Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\$cudaVersion\bin\nvcc.exe")) {
Write-Host "CUDA Toolkit is not installed. Please install CUDA Toolkit and CuDNN as specified in the Read-me."
Exit 1
} else {
$userName = $env:UserName
$zipFilePath = "C:\Users\$userName\Downloads\cudnn-*.zip"

Write-Host "Extracting zip file..."

Expand-Archive -Path $zipFilePath -DestinationPath C:\Users\$userName\Downloads\ -Force

Write-Host "Copying files..."
Copy-Item -Path "C:\Users\$userName\Downloads\cudnn-*\include\*.h" -Destination "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\$cudaVersion\include\" -Recurse
Copy-Item -Path "C:\Users\$userName\Downloads\cudnn-*\lib\*.lib" -Destination "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\$cudaVersion\lib\x64\" -Recurse
Copy-Item -Path "C:\Users\$userName\Downloads\cudnn-*\bin\*.dll" -Destination "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\$cudaVersion\bin\" -Recurse
}

Write-Host "Dependencies verified and installed successfully."
17 changes: 17 additions & 0 deletions build_scripts/build_dependencies_windows_no_cuda.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Set execution policy and install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

# Enable feature and install dependencies
choco feature enable -n allowEmptyChecksums
choco install 7zip git python3 cmake pkgconfiglite -y

# Install required Python packages
pip3 install ninja
pip3 install meson

# Install cmake
pip3 install cmake --upgrade

Write-Host "Dependencies verified and installed successfully."
Loading

0 comments on commit 9ec490e

Please sign in to comment.