Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
This setup wouldnāt have been possible without Lee Wei Yeongās Linux know-how and patient guidance. Appreciate Wing Tai for letting me on his eGPU setups before thunderbolt 3 on eGPUs were aĀ thing.
Motivation
At work, colleagues and I remotely access a shared workstation that houses a few graphics cards for computational work like training deep neural networks for our research.
Images and videos are relatively large objects, making remote access feel cumbersome for some workflows.
X11 forwarding, remote desktops, apps with browser interfaces, and repetitively transferring images over winSCP did notĀ satisfy.
Thus, Iāve set up an external graphics card with a laptop to avoid remote access for certain tasks. (But Iād still push large jobs to the shared workstation once Iāve figured out, on my laptop, the tasks to beĀ pushed.)
An external graphics card + laptop combo lets meĀ ā¦
ā¦ work on the same laptop everywhereāāāin office, and on commutes. Plug in external graphics card as needed in theĀ office.
ā¦ carry a lighter load. Carry graphics card & laptop, versus, carry desktop with (perhaps several) graphics cards, to deployment sites.
ā¦ avoid separating/syncing content (e.g. code, datasets) between an office desktop & laptop had I opted for such aĀ setup.
Sections that follow detail my experience in setting up an external Nvidia TITAN X card with a laptop on Ubuntu 16.04. Core ideas in these sections also apply for externally connecting other Nvidia graphics card with an UbuntuĀ machine.
Recipe
Ingredient List:- Lenovo X1 Carbon 5th gen (Supports Thunderbolt 3)- Akitio Node (External GPU case to mount TITAN X in. Supports Thunderbolt 3)- Ubuntu 16.04 (64-bit)- Nvidia GeForce GTX TITAN X graphics card- NVIDIA-Linux-x86_64ā384.90.run - cuda_9.0.176_384.81_linux.run (Optional. Sometimes used in code that pushes computation to Nvidia graphicsĀ cards.)
Should you be eyeing different hardware, remember to check for compatibility. For instance, does the laptop have a port that is compatible with what the external GPU case offers? The Akitio Node is connected to my Lenovo X1 Carbon via a Thunderbolt 3 connection.
Instructions
I began with fresh Ubuntu 16.04 installation.
If you arenāt starting with a fresh Ubuntu install: Be on the lookout for carelessness. An example is having multiple display managers installed and not stopping all of them before driver installation. Although Iāve included reminders in this recipe for those not using a fresh Ubuntu installation, itās a good idea to be on the lookout. You might like to back up before starting.
Letās begin.
Preliminaries
Connect the TITAN X to the Akitio Node. Secure the TITAN X in place with the provided screws to avoid the cardās connection loosening when the case is moved around. Remember to connect the TITAN X to the Akitio Nodeās power supply unitĀ (PSU).
Power up the Akitio Node. The casingās fan should be gentlyĀ turning.
Turn on Lenovo X1. Get it to Ubuntuās login screen before connecting it to the Akitio Node (via Thunderbolt 3).
Check whether TITAN X can be recognized:Open terminal (default shortcut ctrl+alt+t). Newcomers to Ubuntu: enter the following commands one at a time in the terminal. OmitĀ ā$ā.
$ sudo sh -c 'echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized'$ lspci | grep -i nvidia
If the Nvidia GPU can be read, the console should print something like the following screenshot. āVGA compatible controller: NVIDIA Corporation DeviceĀ ā¦ā is the TITANĀ X.
Using different hardware? Your eGPU may not be ādevice 0-3ā Look in the directories under /sys/bus/thunderbolt/devices/*whatever* for vendor_name and device_name to ascertain your eGPUāsĀ path.
Upgrade kernel:
$ sudo apt-get update$ sudo apt-get upgrade
Mine was upgraded to 4.13.0-43-generic.Running $uname -r lets you see your kernelĀ version.
Install packages needed for compiling the Nvidia driverĀ later:
$ sudo apt-get install gcc build-essential$ sudo apt-get install linux-headers-$(uname -r) linux-images-$(uname -r) linux-image-extra-$(uname -r)
Install NvidiaĀ Driver
Not on a freshly installed Ubuntu? Uninstall existing Nvidia drivers. If apt is managing your installed Nvidia driver, run $sudo apt-get purge nvidia*Ā . Forcibly installing over an existing Nvidia driver may causeĀ issues.
Download NVIDIA-Linux-x86_64ā384.90.runĀ .
Blacklist Nouveau:
Nouveau is an open source Nvidia driver that Ubuntu 16.04 ships with by default. Blacklisting Nouveau is required for the guided Nvidia installation later. Hereās how to blacklist it.
$ sudo touch /etc/modprobe.d/blacklist-nouveau.conf
Write these 2 lines into blacklist-nouveau.conf:
blacklist nouveauoptions nouveau modeset=0
Now weāll update the configuration files for the boot process andĀ reboot:
$ sudo update-initramfs -u$ sudo update-grub$ reboot
After rebooting, check if nouveau is indeed blacklisted. Running the following command should printĀ nothing.
$ lsmod | grep -i nouveau
lsmod shows loaded modules. If Nouveau shows up at this stage, check for typos in the blacklisting steps above. (Accidentally spelt it ānoveauā once haha) Remember to āupdate-initramfs -uā, āupdate-grubā, and reboot after correcting typos.
Log out.
At the login screen, press ctrl+alt+F2 to get to a terminal (a black screen asking for you to log in). If ctrl+alt+F2 doesnāt work, try ctrl+alt+F3, try ctrl+alt+F4,Ā ā¦ until you arrive at a blackĀ screen.
Log in by entering your username first, and then your password.
Weāll forgo the fancy graphical desktop temporarily and use this terminal.
Stop the display manager thatās rendering the graphical desktop:
$ sudo service lightdm stop$ service --status-all | grep -i lightdm
The last command should print ā[-] lightdmā. ā[-]ā means notĀ running.
Running $ service --status-all shows the status of all services. ā[+]ā means running. For fun: try going back to the graphical login screen (probably ctrl+alt+F1), you shouldnāt be able to seeĀ one.
Not on Ubuntu or did not begin with a freshly installed Ubuntu? Your display manager may not be lightdm. Possibilities: sddm, gdm, gdm3,Ā etc.
According to Nvidia, OpenGL applications must be stopped too. If youāre on a freshly installed Ubuntu like me, nothing to do here. MovingĀ onā¦
Drop runlevel:
$ sudo init 3
Let the OS recognize the TITAN X (same as the steps in Preliminaries section):
$ sudo sh -c 'echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized'$ lspci | grep -i nvidia
NVIDIA-Linux-x86_64ā384.90.run needs one small change before itāll compile. Weāll now proceed to add 1 line to a source code file inĀ there.
Extract theĀ .runĀ file:
$ cd /path/to/NVIDIA-Linux-x86_64ā384.90.run$ NVIDIA-Linux-x86_64ā384.90.run -x$ cd NVIDIA-Linux-x86_64ā384.90
Add ā#include <linux/sched/task_stack.h>ā to NVIDIA-Linux-x86_64ā384.90/kernel/nvidia-uvm/uvm8_va_block.cĀ . This line tells the C compiler to include a linux header. Compilation undertaken by the installer (later) will fail in the absence of thisĀ line.
Hereās a screenshot with the added line highlighted:
Add ā#include <linux/sched/task_stack.h>ā to NVIDIA-Linux-x86_64ā384.90/kernel/nvidia-uvm/uvm8_va_block.c
āvimā and ānanoā are editors that can be used in the terminal. Itās ok to take longer than you thought at this stage especially if youāre new toĀ this.
When youāre done, letās return to the root of this archive, and launch the installer.
$ cd /path/to/NVIDIA-Linux-x86_64ā384.90$ sudo nvidia-installer --no-opengl-files
--no-opengl-files is recommended by Nvidia when the GPU is solely intended for computationāāālike in my use-case.
Caution: To those who wish to install without --no-opengl-filesĀ , I have not triedĀ this.
The installer will prompt you with options. Here are my choices:- pre-install script fail? Answer: Continue.- DKMS? Answer: No.- 32-bit? Answer: Yes. Answering no shouldnāt cause the installation to break- configure X? Answer: No. Do not answer yes if GPU is solely for computation.
When the installation is done, letās check if it wentĀ well:
$ modprobe nvidia$ nvidia-smi
nvidia-smi should print something like:
Reboot:
$ reboot
For the Akitio Node, every time you log in, youāll have to do 2 things before the GPU can be used:(i) $ sudo sh -c 'echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized' (ii) $ modprobe nvidiaPsst.. create a script to do these automatically upon loggingĀ in.
Congrats. Youāve successfully installed a Nvidia driver. Ubuntu can now read your TITANĀ X.
Install CUDA (Optional)
CUDA may come in handy for tasking computations onĀ GPUs.
Download cuda_9.0.176_384.81_linux.runĀ .
Let the OS recognize the TITANĀ X:
$ sudo sh -c 'echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized'$ modprobe nvidia$ nvidia-smi
Blacklist Nouveau if you havenāt done so. Details in earlier part of thisĀ article.
Stop lightdm. $ sudo service lightdm stopĀ . Details in earlierĀ part.
Drop runlevel. $ sudo init 3Ā . Details in earlierĀ part.
$ cd /path/to/cuda_9.0.176_384.81_linux.run$ chmod +x cuda_9.0.176_384.81_linux.run$ sudo cuda_9.0.176_384.81_linux.run
The installer will prompt you with options. Here are my choices:- license agreement? Press āqā once to scroll to end quickly. Enter āacceptā to accept.- Install Nvidia driver? No. Because we already did this earlier.- Install cuda 9.0 toolkit? Yes.- Install toolkit location? Default- Install symbolic link? Yes- Install samples? Yes- Sample location? Default.
Nearing the end of this installation, you might be shown a message saying āWARNING Incomplete InstallationĀ ā¦ A driver of version of at least 384.00 is required for CUDA 9.0 functionality to work.ā This is not a problem. WeāreĀ fine.
Check installation:
$ cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery$ sudo make all$ ./deviceQuery
deviceQuery should print something like:
Andā¦ weāre done! Congrats on making it thisĀ far.
Food for thought:Some workflows involving a remotely accessed machine and relative large objects can still feel natural. For e.g., quantitatively benchmarking a trained neural net. An eGPU + laptop setup might not improve your workflow.
Recipe: Nvidia Titan X as External GPU on Ubuntu Laptop was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.