After days of cursing and swearing I managed to get my Unity app running and rendering on a “headless” Linux box — machine without a physical display. And eventually even on Amazon cloud!

In the end all complications turned out to be not due to Unity, but rather issues configuring OS and drivers. Once I managed to get OpenGL sample glxgears running without monitor, Unity run as well.

TL;DR: Bring me ready to use Amazon disk image that uses GPU.

Why would anyone want to run Unity apps without monitor?

If you are working with Machine Learning — teaching agents to play Unity games or drive in Udacity Self-Driving Car Simulator by looking at the pixels. If you are augmenting training sets with synthetic images or simply rendering lots of frames for your movie — you might want to run on a remote server, in the cloud or at the very least hide annoying windows from your own desktop.

You still need rendering loop to run and GPU to work, so usual approach to run Unity as a server will not work.

Linux to the rescue!

Running Unity app with graphics on a server without monitor

Presuming you have Linux box (I tested on Ubuntu14.04) and have NVIDIA drivers installed and working already.

The rest is very simple — configure virtual display, run X server and make sure to launch application on the same display as X:

Running Unity app offscreen on your local machine

Useful to hide annoying windows while your DeepQ agents are learning.

Install XDummy and VirtualGL. XDummy will create new virtual display offscreen and VirtualGL will trap incoming OpenGL calls executing them on real GPU. See instructions:

Run Unity app with graphics on Amazon Cloud!

Now the most interesting and rewarding part — running Unity on Amazon Elastic Compute Cloud (Amazon EC2).

Amazon provides several options with GPUs: older g2 instances and faster p2 instances. So far I tested the following on g2.2xlarge single GPU instance with Ubuntu 14.04.

The most complex part is to find correct NVIDIA driver that can support GPUs on the cloud. So far I found 367.57 and 340.46 working with GRID K520 GPU that sits inside g2 instance. There is one problem with installer however — it forgets to add Bus ID to configuration — need to manually patch the file.

You will need to disable Nouveau drivers that come with Ubuntu. They do no good for poor K520.

Other than that — build and install X server, setup virtual display and launch X.

Your application should be ready to launch on the same display as X. See full instructions:

If you want to know more details about NVIDIA driver installation, follow: https://askubuntu.com/questions/429596/how-to-choose-the-vga-when-setting-up-the-x-server/534622#534622

Ready to use Amazon boot image

If you can’t be bothered with the steps above, it’s OK. I created boot disk image (AMI) that can run Unity or any other OpenGL application on Amazon for you.

Image contains Ubuntu 14.04, NVIDIA drivers 367.57. On boot it launches X server with virtual display. All OpenGL calls will be executed on GPU of course.

Image is called: Ubuntu 14.04 with Virtual Display setup for GPU accelerated OpenGL and is available in the following locations: us-west-1, us-west-2 and us-east.

To find it on Amazon cloud simply type “Ubuntu GPU” in the AMI search field or use the link: https://console.aws.amazon.com/ec2/v2/home?region=us-west-1#LaunchInstanceWizard:ami=ami-921c40f2

PS: For testing purposes you can download my small Unity app which renders some boxes, captures screenshots and writes them to disk: https://www.dropbox.com/s/abycjktjzmkrmb4/auto.zip?dl=0