Skip to content

Instantly share code, notes, and snippets.

@AlphaGit
Created April 3, 2022 17:38
Show Gist options
  • Save AlphaGit/1305d09fe4e4bd977846a5d5a41ab1e7 to your computer and use it in GitHub Desktop.
Save AlphaGit/1305d09fe4e4bd977846a5d5a41ab1e7 to your computer and use it in GitHub Desktop.
Setting up Blender on P2 instances
sudo apt-get update
# need the same gcc-compiler as the kernel uses, or so NVidia says
sudo apt install -y gcc=4:9.3.0-1ubuntu2 make libgl1-mesa-glx libxi6 libxrender1
# download and install the NVidia drivers
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/470.94/NVIDIA-Linux-x86_64-470.94.run
chmod +x NVIDIA-Linux-x86_64-470.94.run
sudo ./NVIDIA-Linux-x86_64-470.94.run
# manually go through the install options
# install latest Blender
sudo snap install blender --classic
# create the enable-gpu.py script to force the use of GPU
cat << 'EOF' > enable-gpu.py
import bpy
prop = bpy.context.preferences.addons['cycles'].preferences
prop.get_devices()
prop.compute_device_type = 'CUDA'
for device in prop.devices:
if device.type == 'CUDA':
device.use = True
bpy.context.scene.cycles.device = 'GPU'
for scene in bpy.data.scenes:
scene.cycles.device = 'GPU'
EOF
# start a detached screen so you won't lose progress when disconnecting
screen -S myRenderingSession
# start blender rendering
blender -b blenderFile.blend -P enable-gpu.py -a
# if you had lost the connection and need to reconnect to that screen session
screen -d -r
# if you need to start blender again but don't want to start from scratch, but instead, frame 10
blender -b blenderFile.blend -P enable-gpu.py -s 10 -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment