The first time I thought about cloud rendering, I thought the Amazon AWS EC2—as I have some free resources there. (I got the AWS credit from this event).
Render using Amazon AWS EC2
#update to the latest kernel version sudo yum update -y sudo reboot #install blender dependencies sudo yum -y install freetype freetype-devel libpng-devel sudo yum -y install mesa-libGLU-devel sudo yum -y install libX11-devel mesa-libGL-devel perl-Time-HiRes sudo yum install xz #install blender from https://builder.blender.org/download/ wget 'https://ftp.nluug.nl/pub/graphics/blender/release/Blender2.82/blender-2.82a-linux64.tar.xz' tar -xvf data.tar.xz
To open Blender software, the basic command is ./blender -b where -b means the software will be running in the background.
The documentation about command line rendering:
- https://docs.blender.org/manual/en/latest/advanced/command_line/render.html
- https://medium.com/@Mikulas/blender-rendering-on-aws-p2-61f7fb8405d8 (using GPU and P2 instances AWS)
Rendering command:
./blender -b file.blend -E CYCLES -s 0 -e 120 -t 8 -a
- ./blender -b: Running Blender software in the background
- file.blend: File that will be processed
- -E CYCLES: Using CYCLES engine for rendering
- -s 0 -e 120: Start from frame 0 to frame 120
- -t 8: Use 8 threads of CPU
- -a: Render using all the setting in the .blend file
This rendering method is quite helpful as I can leave it in the cloud, but the rendering time does not much differ from my laptop—because I only have the access to General Purpose instances in AWS EC2.
However, at least I can leave the rendering process in the cloud without hurt my laptop.
I tried to contact AWS team to increase my limit to use P-type instances that have powerful NVIDIA Tesla K-80 GPU. I’ll update this in the next post.
Render using Google Colaboratory
Google Colaboratory is a platform from Google to execute python script in Jupyter Notebook style + Free GPU.
I used this Google Colab in my previous Deepfake project as it can speed up the process.
As it offers free GPU, I also can use it to speed up my Blender rendering process.
Mount Google Drive
from google.colab import drive drive.mount('/content/drive')
Download Blender
!wget -O 'blender28.tar.xz' -nc 'http://ftp.halifax.rwth-aachen.de/blender/release/Blender2.82/blender-2.82a-linux64.tar.xz' !mkdir blender28 !tar -xf 'blender28.tar.xz' -C ./blender28 --strip-components=1
Adjustment for Google Colab
import os os.environ["LD_PRELOAD"] = "" !apt update !apt remove libtcmalloc-minimal4 !apt install libtcmalloc-minimal4 os.environ["LD_PRELOAD"] = "/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0" !echo $LD_PRELOAD
Blender Dependencies
!apt install libboost-all-dev !apt install libgl1-mesa-dev !apt install libglu1-mesa libsm-dev
Config data for GPU rendering
gpu_enabled = True data = "import re\n"+\ "import bpy\n"+\ "scene = bpy.context.scene\n"+\ "scene.cycles.device = 'GPU'\n"+\ "prefs = bpy.context.preferences\n"+\ "prefs.addons['cycles'].preferences.get_devices()\n"+\ "cprefs = prefs.addons['cycles'].preferences\n"+\ "print(cprefs)\n"+\ "# Attempt to set GPU device types if available\n"+\ "for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):\n"+\ " try:\n"+\ " cprefs.compute_device_type = compute_device_type\n"+\ " print('Device found',compute_device_type)\n"+\ " break\n"+\ " except TypeError:\n"+\ " pass\n"+\ "#for scene in bpy.data.scenes:\n"+\ "# scene.render.tile_x = 64\n"+\ "# scene.render.tile_y = 64\n"+\ "# Enable all CPU and GPU devices\n"+\ "for device in cprefs.devices:\n"+\ " if not re.match('intel', device.name, re.I):\n"+\ " print('Activating',device)\n"+\ " device.use = "+str(gpu_enabled)+"\n"+\ " else:\n"+\ " device.use = "+str(cpu_enabled)+"\n" with open('setgpu.py', 'w') as f: f.write(data)
Rendering
!sudo ./$blender_version/blender -P './setgpu.py' -b '/blender/Plank3.blend' -E CYCLES -o '//render/' -s 0 -e 120 -a
Google Colab based rendering is about two times faster than the normal (my laptop and Amazon general purpose instances)
The more interesting thing about Google Colab is that I can use multiple Google account to create a branch rendering.
For example:
- Account 1: Render frame 0 to 80
- Account 2: Render frame 81 to 160
- Account 3: Render frame 161 to 240
Voila! It results in 3 times faster rendering!
There is another option to do this thing (using multiple resources to render one file) called render farm.
Actually, I already tried the render farm method to use that three resources to render a file, but it is not working as expected as I can’t access the overwrite and placeholder option in Blender software using the command line.
One thought on “Blender Cloud Rendering Using Amazon AWS EC2 and Google Colab”