Close
blender home screen

How to Build Blender with Cuda and Optix on Ubuntu

Building Blender with source code on Ubuntu is actually very easy to be very honest. I am just writing this short post here to make the instruction a bit more verbose than on Blender Wiki and all at one place.

Tested On:

  • Ubuntu 20.04
  • Cuda 11.3
  • Optix 7.1
  • NVidia RTX 2060

Install Packages Required For Build Process

sudo apt update
sudo apt install build-essential git subversion cmake libx11-dev libxxf86vm-dev libxcursor-dev libxi-dev libxrandr-dev libxinerama-dev libglew-dev

Download Source Code From Github

mkdir ~/blender-git
cd ~/blender-git
git clone https://git.blender.org/blender.git

Download Precompiled Libraries Used By Blender

mkdir ~/blender-git/lib
cd ~/blender-git/lib
svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/linux_centos7_x86_64

This would download around ~15 GB of files.

Now Build Blender!

First go to blender source code root directory and update the code to latest version.

cd ~/blender-git/blender
make update

Important Note: You do not need to worry about your system Python version vs Python supported by Blender. Blender will automatically download separate Python required for it’s build process.

Now, If you want to build blender without Cuda or Optix support just run below command from blender source code root directory:

make

But if you want to make Blender with Cuda, you need to run below command:

make release

Additionally, if you want to build Blender with Cuda as well as with Optix support, just provide Optix SDK include directory path in the command line argument like below:

make release BUILD_CMAKE_ARGS="-DOPTIX_INCLUDE_DIR=/home/user/NVIDIA-OptiX-SDK-7.1.0-linux64-x86_64/include"

Troubleshoot – Control CPU Usage

Limit Number of Parallel Jobs

The build process by default runs parallel jobs equal to number of CPU cores available on your system. You might want to keep some of the CPUs available to other running applications. The number of parallel jobs can be controlled by “-j” option.

First, run your build command as usual make release BUILD_CMAKE_ARGS="-DOPTIX_INCLUDE_DIR=/home/user/NVIDIA-OptiX-SDK-7.1.0-linux64-x86_64/include" but stop the process (CTRL+C) as soon as you see message “Build files have been written to: /path/to/your/build”.

Then go to your build directory, and e.g. to limit them to 8, pass option as below

cd ../build_linux_release
make -j8 install

Troubleshoot – Handling Out of Memory Issues

Now, it might be possible that the build process may take a lot of memory and it may fail. There are multiple ways to workaround that.

Method#1: Build Only For Your GPU

You can just build Blender for your GPU architecture given that you don’t intend to share your build to others with different GPU architecture. Find sm_xx code corresponding to your GPU from below table

Credit: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/

and pass with -DCYCLES_CUDA_BINARIES_ARCH option. e.g. for all Turing GPUs, run below-

make release BUILD_CMAKE_ARGS="-DCYCLES_CUDA_BINARIES_ARCH=sm_75 -DOPTIX_INCLUDE_DIR=/home/user/NVIDIA-OptiX-SDK-7.1.0-linux64-x86_64/include"

Method#2: Run Build Process in Serial Fashion

Another way to limit the memory if you do not want to restrict your build to single GPU architecture is to run build process in a serial way i.e. using only one job with WITH_CYCLES_CUDA_BUILD_SERIAL=ON option as below

make release BUILD_CMAKE_ARGS="-DWITH_CYCLES_CUDA_BUILD_SERIAL=ON -DOPTIX_INCLUDE_DIR=/home/user/NVIDIA-OptiX-SDK-7.1.0-linux64-x86_64/include"

But remember, this might be super slow and take very long time.

That’s it! This should give you the blender build in the same directory where you have blender source code “build_linux_release/bin” or “build_linux/bin” depending on whether you build with Cuda/Optix support or without them, respectively.

Have something to say? Leave a comment!