How to run OpenGL desktop programs on Google Colaboratory. This is a trick make Google Colaboratory using like a VPS.
- Google account
- ngrok account
- Browser that Google Colaboratory works
- ssh clientIf you use Windows, you can install openssh with scoop .
- TurboVNC Viewer
1. Sign up for ngrok.com
- You don’t need to buy paid plans.
2. Change runtime type if you want to use OpenGL
- After you open Google Colaboratory, click “Runtime” -> “Change runtime type” in top menu and change Hardware accelerator to GPU.
3. Copy following code to a cell in Colaboratory
!pip install git+https://github.com/demotomohiro/remocolab.git import remocolab remocolab.setupVNC()
4. Click run bottom in top left
5. Copy ngrok authtoken
- After the message that ask you to copy ngrok authtoken displayed, login to ngrok, click Auth on left side menu, click Copy, return to Google Colaboratory, paste it and push enter key.
6. Select ngrok region
- Probably the region closest to you is fastest.
7. Wait for TurboVNC running
- It setup OpenSSH server, VirtualGL and TurboVNC.
- When it done, passwords of root and colab user, ssh command for local port forwarding and VNC password is displayed.
8. Login to Google Colaboratory using SSH
- Login to the SSH server running on your Colaboratory’s virtual machine by executing the ssh command under “Execute following command on your local machine and login before running TurboVNC viewer:” message.
- Use the password displayed right side of “colab password: “.
- Keep logined while you use VNC.
9. Run TurboVNC Viewer
- Set server address to localhost:1 and connect.
- When password is required, copy & paste the password displayed right side of “VNC password: “.
After connecting VNC server, you will see the screen like this.
You can check the availability of NVIDIA OpenGL implementation with following command.
$ vglrun /opt/VirtualGL/bin/glxinfo | grep NVIDIA
If everything fine, you will see following output.
OpenGL vendor string: NVIDIA Corporation OpenGL core profile version string: 4.6.0 NVIDIA 418.67 OpenGL core profile shading language version string: 4.60 NVIDIA OpenGL version string: 4.6.0 NVIDIA 418.67 OpenGL shading language version string: 4.60 NVIDIA
Run OpenGL programs
Following steps are supposed to be run on remote desktop. TurboVNC Viewer can copy & paste between your PC and remote PC. OpengL programs need to be run with vglrun command or it uses software GLX/OpenGL implementation included in The TurboVNC and rendering can be slow.
If you want to run a program from SSH and display it on the VNC screen, add DISPLAY=:1 to your command like this:
$ DISPLAY=:1 vglrun firefox &
Open terminal and execute following commands.
$ su # apt install firefox # exit $ vglrun firefox
Then, open Shadertoy on the firefox.
Download Unigine Valley from Unigine Valley . Then, extract the file and run it like following command.
$ chmod +x Unigine_Valley-1.0.run $ ./Unigine_Valley-1.0.run $ cd Unigine_Valley-1.0 $ vglrun ./valley
Download the file for Linux 64bit from official Blender site. Then, extract the file and run it like following command.
$ tar xf blender-2.79b-linux-glibc219-x86_64.tar.bz2 $ cd blender-2.79b-linux-glibc219-x86_64 $ vglrun ./blender
Download the file for Linux 64bit from official Godot site. The, extract the file and run it like following command.
$ unzip Godot_v3.1-stable_x11.64.zip $ vglrun ./Godot_v3.1-stable_x11.64
How it works
remocolab download and install OpenSSH, TurboVNC , libjpeg-turbo, VirtualGL and Xfce . It run desktop on Google Colaboratory ‘s virtual machine and make it accessible from your PC using TurboVNC. TurboVNC send desktop screen on the server to the client PC running TurboVNC Viewer , and receive mouse and keyboard input from the client PC. TurboVNC compress desktop screen image using libjpeg-turbo before sending it. These communications are encrypted by using SSH port forwarding. remocolab configures TurboVNC so that connecting to it without using SSH is forbidden. VirtualGL allow OpenGL programs can use Hardware accelerator using a GPU on server like they are executed on normal desktop.
Display smooth animation
Open TurboVNC Viewer Options and change Encoding method to Tight + Medium-Quality JPEG or Tight + Low-Quality JPEG(WAN) . Some noise will appear but looks smoother.
Change remote desktop size
Open TurboVNC Viewer Options, click Connection tab and set Remote desktop size.
Internet of Tomohiro
If you found my articles interesting or useful, please donate using following links:
gosh ,,, !!! You plagiarize people’s articles, bro, you have to report this as soon as possible.
I have left the article source link. https://internet-of-tomohiro.netlify.app/google_colab/vnc.en.html