Blender 2.83 on Oracle Cloud Infrastructure — Part 2
In the first part of this set of articles I talked about the benefits of running Blender as a headless (ie. no user interface) renderer on Oracle Cloud Infrastructure (OCI). In this article I’ll walk you through the process of installing Blender on an OCI GPU instance, running a sample render, and downloading the results back to your local machine.
NOTE: This may appear to be a long article, but it is only because I have included step-by-step instructions and screenshots to make it as easy as possible to follow along.
If you want to follow along you will need access to an OCI tenancy (aka: an Oracle Cloud account). Oracle does provides a 30 day trial account at no cost, but the free trial accounts do not have access to the GPU instances. While the cost per GPU of a single instance is $1.275 per hour, you don’t need to run it 24x7, simply on demand. Using the Cost Estimator tool at Oracle, I estimated that my costs to have access to the NVidia GPU instance for 2 hours a day for 31 days a month would cost me $84 / month USD! Considering a single render on a render farm often costs upwards of several hundred dollars, this is a huge savings! Of course, you really should be rendering something fairly often as an individual user to make the best use of this service. You can also scale up and down the number of GPUs you are using on a daily basis, so you have direct control over your costs. Turning all of your GPUs off for an entire month drops the monthly charge to a mere $5 USD. I spend more than that at a single visit to my local coffee shop!
First — A Little Housekeeping
So let’s get to it. Assuming you have an Oracle cloud account (which you can register for at oracle.com and clicking on the View Accounts link on the top right of the page, as shown in the screenshot.
If you do get a Free Tier account, you will have to convert to a paid account before you will have access to the GPU instances.
When you log into your account (also called a tenancy) You will start at the landing screen. For my account, my home region is US West (San Jose). However, I need to access the GPU instances, which are only in US East (Ashburn), so I need to subscribe to that region also. There is no additional cost for subscribing to other regions. So if your home region isn’t already set to US East (Ashburn), click on your current region name in the top right part of the page To subscribe to another region, click on the region name and select Manage Regions from the popup menu.
This will bring up a list of regions to which you can subscribe. In my case, US East (Ashburn) was not listed on the first page, so I needed to go to the next page to find it. Once you locate the region, click on the associated Subscribe button.
After you subscribe to the region, you will be able to quickly change to it using the Region drop down menu at the top of the OCI web page. So now that you know how to access a region that supports the GPU shapes, let’s move on to creating compartments.
I think of a compartment like a folder on a hard drive. You use folders on a hard drive to help organize your files. Similarly, you will use compartments to organize your “assets” (ie. servers, load balancers, etc). Compartments are also used to help secure your assets, but that topic is out of scope for this article.
Every Oracle Cloud Infrastructure tenancy has a root compartment by default. Within the root compartment you will create a “Blender” compartment to contain your GPU instances. To do this, you use the main menu in Oracle Cloud Infrastructure (the three horizontal lines on the left side of your browser, scroll down to the bottom) and click on the Identity -> Compartments menu item.
Click on the Create Compartment button and name your compartment Blender (or whatever you prefer). Your parent compartment should be your root compartment. Click on the Create Compartment button to finish the creation process.
Now — We Create Our Blender Server
With the housekeeping out of the way, lets create a server that we can use to render Blender models in the cloud. Our first step is to create a Virtual Cloud Network (VCN) where our Blender servers will live.
Using the main menu on the OCI web portal, scroll to the top and select Networking -> Virtual Cloud Networks
Ensure that you are in the Blender compartment that you just created by selecting it in the dropdown box.
Once that is done, press the Start VCN Wizard button. Do NOT press the Create VCN button as that is meant for more detailed VCN creation that is out of scope for this tutorial. I’m trying to keep this simple!
Choose the VCN with Internet Connectivity option and then press the Start VCN Wizard button.
Name your VCN BlenderFarm and press the Next button.
Don’t worry about the details on the confirmation screen (ignore the man behind the curtain?) and press the Create button.
You can view the VCN details after it is created if you like, but there is really no need. Next, we need to create a server in our cloud to host a Blender instance. Use the main menu to select Compute ->Instances.
Now things start to get interesting! Click on the Create Instance button to create your Blender render instance.
Name your instance blender1 and then click on the Change Shape button.
You will want to change the shape to one that supports a GPU architecture. There are several to choose from, one in the Virtual Machine section and two under the Bare Metal section. I’m trying to keep things cheap and simple so I opt for the Virtual Machine. Click on the Specialty and Legacy tab and select the VM.GPU2.1 shape. Press Select Shape when you are ready.
Scroll down a bit and ensure that the ASSIGN A PUBLIC IP ADDRESS radio button is selected. Continue scrolling down.
You will need to specify an SSH key for this compute instance so you can SSH to it to install the Blender software. If you have no idea what SSH is, how to access the SSH keys or how to create SSH keys, take a moment to check out this tutorial to get you going. You don’t need to do the whole tutorial, just the Practice 1 section on creating SSH keys. Then return here and continue on.
Select the CHOOSE SSH KEY FILES option and then drag and drop you public key (not the private one) onto the page’s drop target. Once that is done, press the Create button
It will take a couple of minutes to complete the creation of your new blender1 compute instance. When it is complete, the large icon will turn green, as shown in the following screenshot. Then locate and copy the public IP address.
Configuring the Compute Instance
At this point you have a compute instance, but it is completely unconfigured for Blender. In this section I will show you how to install blender for use in “headless mode” (ie. no user interface, just the command line).
The first thing we need to do is to connect to our new compute instance using SSH. Using your command line (Linux or Mac) or GitBash tool (Windows) enter the command:
ssh opc@<your public IP address>
For example, if your public IP address for your blender1 instance was 150.136.55.237 you would type in:
ssh opc@150.136.55.237
If you used an SSH key other than id_rsa, you will need to specify that key’s filename (using the -i command) along with the command like so:
ssh -i ~/.ssh/my_key_file_name opc@<your public IP address>
Remember, you would pass in your private key file, not the public key file (the one that ends in .pub is the public key). The first time you do this, you will be prompted to accept the connection. Type in yes when prompted.
$ ssh opc@150.136.55.237The authenticity of host ‘150.136.55.237 (150.136.55.237)’ can’t be established.ECDSA key fingerprint is SHA256:yY9ngish+UNqS90n/R8LDO9ezE36vZ631jRG87WgKj0.Are you sure you want to continue connecting (yes/no/[fingerprint])? yesWarning: Permanently added ‘150.136.55.237’ (ECDSA) to the list of known hosts.
Now you are connected to your blender1 compute instance via SSH and you can execute commands as if you were logged into the machine locally. The first thing you will want to do is to download Blender for Linux by entering the following command:
curl -o blender.tar \
https://mirror.clarkson.edu/blender/release/Blender2.83/blender-2.83.3-linux64.tar.xz
The curl command will take a few seconds (like 2) to download blender onto your blender1 instance. Now you need to uncompress the file into the blender1 drive. Enter the following command:
tar -xvf blender.tar
It will actually take a few moments to fully uncompress the file. It will create a directory in your home directory called blender-2.83.3-linux64/. Now we want to add that directory to our %PATH% variable so we can invoke blender without having to provide the entire file path each time. To do this we will need to modify our .bash_profile file. Type in the following command to start the built-in vi editor.
vi .bash_profile
Don’t overlook the period at the start of the file name!
Your default .bash_profile will look like the following:
# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/binexport PATH
Now vi can be a little tricky by today’s standards, so follow along exactly. If anything doesn’t work out perfectly, you can exit vi by entering the key sequence of:
ESC : q
Only do that if things aren’t working as you expect though. So with vi running and its cursor at the top left corner of the file press the a key to go into “append” mode. This will allow you to add characters to the file.
Now press the down arrow on your keyboard 9 times so it is on the line that says PATH=$PATH:$HOME/.local/bin:$HOME/bin
Press the right arrow key until the cursor is at the very end of the line. Now type the following:
:$HOME/blender-2.83.3-linux64
At this point, press the ESCAPE key to get out of “append” mode. The press the :w keys (that’s the full colon key followed immediately by the w key) to write the file to disk. Finally press the :q keys to quit the vi editor.
I promise that’s as close as you’ll come to writing real code in this tutorial. Finally, to load your changes to the PATH environment variable, enter the following command:
source .bash_profile
Now every time to SSH into your instance, blender will be ready to go.
We have 1 more session with vi though. We need to create a rendersettings.py file that will configure blender, from the command line, to use the CUDA rendering drivers. Let me give you the code for the rendersettings.py file first. Copy the following code to your clipboard, then continue the tutorial.
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’
Note: Mega-kudos to Fajrul Falah on Medium.com for his article on using AWS to render as it was his code that I copied and used here!
So fire up vi again using the following command line:
vi rendersettings.py
When the vi editor loads, press the a key again to go into “append” mode. Paste in the contents of the clipboard (using GitBash on Windows I had to right-click in the vi editor and choose the Paste menu option. On the Mac I could just use Command+v.
Once again, press the ESCAPE key to get out of “append” mode. Then type in the keys :w and :q to write the file to disk and quit the vi editor.
Wasn’t That Fun?
No, no it wasn’t. It was probably especially painful for those of you who do not write code for a living. But I have a great tip for you so you never have to do it again! After this next step, you’ll just be able to create pre-configured blender compute instances with ease. Let’s do that now.
What we want to do is to create a custom image. A custom image is an exact copy of a compute instance. It’s like a cookie cutter that can be used to create any number of identical instances. All of the configuration we just did will go into the custom image and in the future, when we want to create a new blender instance we can do so with ease. I’ll show you that process also, though it’s very similar to the process we went through to create our initial image.
Exit your SSH connection by typing exit on the command line.
[opc@blender1 ~]$ exit
logout
Connection to 150.136.55.237 closed.
jeff@DESKTOP-5DNQ4HE MINGW64 ~
$
Now, back in your Oracle Cloud Infrastructure interface, you want to find your running blender1 instance by using the main menu and navigating to Compute -> Instances. Click on your blender1 instance to view its details page. Then click on the More Actions button and select Custom Image.
Name the custom image Blender-2.83.3 and press the Create Image button. The big green icon will turn yellow as the instance is taken offline to make the image. Once it returns back to green, the original blender1 instance will be running again. Wait for the icon to turn green again before proceeding.
Now that the custom image is created, I want to show you how to delete the current compute instance that we’ve been using and create a new one based on the custom image. I know you’re probably chomping at the bit to do a render, but these instances, while dirt cheap if you use them for an hour or two, can really add up over the course of the month if you leave them running. So if you’re cheap like me, you’ll want to follow along with these few steps before we get to the rendering. Compared to what you just configured, this will be a breeze!
Still in the OCI web console, looking at the details page for your blender1 instance, select the More Actions button again and select Terminate from the popup menu. When you terminate an instance, a dialog box will prompt you to delete the boot volume associated with the instance. Check the checkbox before pressing the Terminate Instance button.
It is important to terminate the instance and not stop it. Stopping the instance is like turning it off, but you still get billed for it. Terminating the instance erases it completely and stops the billing. If you run the instance for 2 hours, you only get billed for the 2 hours. At $1.275 per GPU per hour that would be a mere $2.55 for a single GPU instance. Pretty cheap!
Be sure your current instance of blender1 is fully terminated before reading on!
Using the Custom Image
Now that we have a custom image, lets see how that changes the process for creating a compute instance.
Once again, use the main menu to navigate to the Compute -> Instances menu item. When the page loads, click on the Create Instance button to create our new instance. Name this instance blender2 (just to make it obvious in our list of instances later) and press the Change Image button.
When the Browse All Images dialog appears, select the Custom Images tab at the top. Next, check the checkbox next to the Blender-2.83.3 image. Finally, click on the Select Image button.
Scroll down to the Shape section of the page and you will see that the BM.GPU2.2 shape is automatically selected. This is the Bare Metal platform that has 2 GPUs associated with it. As you will see in Part 3 of this series, the number of GPUs does make a big difference in the performance of Blender rendering. However, for our purposes, press the Change Shape button. We will change to the Virtual Machine with a single GPU.
First, select the Virtual Machine tab at the top of the page. This will then show us a list of shapes that match our image’s requirements. Most of them will be greyed out because they don’t support GPUs.
Scroll down the list until you see the VM.GPU2.1 shape and check its checkbox. Finally, press the Select Shape button at the bottom of the page to confirm your choice.
Note: The billing rate for the BM.GPU2.2 shape is the exact same as the VM.GPU2.1 shape: $1.275 per GPU per hour. So. it’s per GPU charge is the same. However, since it has 2 GPU’s instead of 1, the billing rate is doubled. This is perfectly acceptable when you want to render a scene as quickly as possible, but for our tutorial, I’m keeping it cheap!
Scroll down a bit and ensure that the ASSIGN A PUBLIC IP ADDRESS option it selected.
Scroll down further to add your id_rsa.pub file as the SSH key, just as you did before. Press the Create button when ready.
Wait for the instance to finish the creation process. When it does, start an SSH session with it (using the new IP address of the blender2 instance, it’s going to be different!).
Once you have the SSH session running, enter the following command:
blender -b --factory-startup -noaudio -v
It should invoke Blender in headless mode and give you a response like the following:
This confirms that Blender is correctly installed and configured.
Before we move on, I’d like to review that last command line for Blender so you know what we told Blender to do.
First is the -b option. This tells Blender to run in the background. When Blender gets this argument, it will not try to create a user interface.
Next is the — factory-startup option. It has a double dash in front of it (Medium.com’s editor tool automatically is converting it here into a single, long dash, but just know it’s really 2 dashes next to each other). This tells Blender to ignore the startup.blend file that it would usually use to load configuration information. We want this option because it gives us a known starting point for how Blender is configured.
Next is the -noadio option. We use this option because the virtual machine image does not have an audio card. Without this option, Blender will look for an audio card and issue an error message when it doesn’t find one.
Finally is the -v option. This tells Blender to display its version information.
With that done, you’re all set to move onto Part 3 where we will download a sample Blender file to run our benchmarks on. You’ve made it through the technical part. Now it’s time to render!