Razer Blade 15 (2021) for Data Science

Setting up Ubuntu on the Razer Blade 15 (2021)

View the Project on GitHub EtienneMueller/razer-blade-data-science

Razer Blade 15 (2021) for Data Science

Here is how i set up my Razer Blade 15 (Early 2021, RTX 3080, 4k) to work with Ubuntu.

Installation

Which Version?

The Intel WiFi AX210-module is only natively supported from kernel 5.10. Initially it was the easiest to just install the latest version, but as pointed out in the issues older versions (at least 20.04 LTS) also ship with that or a newer kernel version.

Create a bootable USB-Stick with Ubuntu

 

Dual vs. Single Boot

Important: If you want to use Ubuntu as the only OS, but still want to keep the original recovery partition containing Windows (partition 0) DO NOT remove the other partitions. The recovery tool will only install Windows 10 on partition 3 without checking or recreating any partitions. It took me way too long to find this out, but in case that happens to you, you would need to manually create partition 1 (EFI=100MB), partition 2 (MSR=128MB) and a primary partition 3 for the C-Drive, where Windows 10 will be installed.

If you want to keep the original Razer wallpapers, make sure to copy them before formatting Windows. You can find them located under: C:\Windows\Web\Wallpaper

For the single boot setup, boot from the USB stick and install it by formatting the biggest partition as ext4, set mount point to “/” and click install.

For using Ubuntu alongside Windows you can simply choose “Install Ubuntu alongside Windows Boot Manager” (e.g. like described here).

 

Fixes

Suspend Loop Fix

After the lid was closed, the notebook goes back to suspend after a couple of seconds and stays in that loop until a restart. It can be fixed fairly easy by adding GRUB_CMDLINE_LINUX_DEFAULT="quiet splash button.lid_init_state=open" to the grub configuration, as is described in the next section.

 

Grub Settings

Grub Font Size

Depending on whether you want to show the grub bootloader at startup or not, you might want to increase the font size of the grub menu (especially for the 4K display) or to hide it completely.

As the font of grub can be very tiny on a high res display, you can create a bigger one with the following command, as described here. I chose a font size of 42 for the 4K panel.

sudo grub-mkfont --output=/boot/grub/fonts/DejaVuSansMono24.pf2 --size=42 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf

Next, open the grub settings with sudo nano /etc/default/grub and adjust it for either dual boot or single boot.

For Dual Boot

If you want to select the operating system with the UEFI boot manager by pressing F12 at startup, you can use the same settings as for the single boot setup. If you want to use grub I suggest following settings:

GRUB_DEFAULT=saved  # boot the saved OS
GRUB_SAVEDEFAULT=true  # save the last booted OS
GRUB_TIMEOUT=2  # time it is shown (in seconds)
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash button.lid_init_state=open"  # suspend boot loop fix (see above)
GRUB_FONT=/boot/grub/fonts/DejaVuSansMono24.pf2  # choosing the created bigger font for 4k display

The first two lines will boot the last used OS, the third lines set the time in seconds the menu is shown (adjust to your own preferences), fourth line is the suspend loop fix and lastly, the previously created font.

Update grub with sudo update-grub and reboot your system sudo reboot.

For Single Boot

If you are using Ubuntu as a single OS as described before, it will still recognize the system as dual boot due to the recovery partition and always load the grub bootloader on startup (but can be hidden with the following settings). After opening the grub config file with sudo nano /etc/default/grub I used following settings:

GRUB_DEFAULT=0  # boot first entry in the list (Ubuntu)
GRUB_TIMEOUT=1  # time until grub automatically loads the chosen OS (in seconds)
GRUB_DISABLE_OS_PROBER=true  # do not show grub (since it is single boot anyways)
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash button.lid_init_state=open"  # suspend boot loop fix (see above)

First line choses Ubuntu as boot partition. As grub will still run in background, the timeout is set to one second (setting it to zero it will be ignored and then it takes the standard time of ten seconds). The third line hides the display output, and the last line fixes the suspend loop.

Update grub with sudo update-grub and reboot your system sudo reboot.

 

Older Ubuntu Versions

Here are the things I had problems with in Ubuntu 21.04, but worked fine with later versions.

Firefox with Touch

Firefox isn’t scrolling with touch. Open the environment file with:

sudo nano /etc/environment

and add

MOZ_USE_XINPUT2=1

Brightness

The OLED screen doesn’t react on brightness changes (because it doesn’t have a classic backlight as LCD-panels have). Install ICC brightness to solve the problem.

sudo apt install build-essential
sudo apt install liblcms2-dev
sudo make install

Gestures

If you’re coming from a mac, you’ll probably miss the gestures on the touchpad. The best I could find was Touchegg, but much more customizable. For the GUI I used Touché. You might also want to check https://ubuntuhandbook.org/index.php/2021/06/multi-touch-gestures-ubuntu-20-04/

 

Data Science

Now for the interesting part.

CUDA and CuDNN

To work at least TensorFlow 2.6 is needed. The configurations I tested and worked:

Basically staying for the driver, CUDA and TensorFlow on the latest version worked fine for me. Installation procedures were the same for all versions.

Activate Nvidia Proprietary Driver in “Software & Updates” under “Additional Drivers” (nvidia-driver-515 at the time of writing) and reboot. You can display information about the GPU and the CUDA Version (11.7 for me) with:

nvidia-smi

Install the Nvidia Cuda Toolkit next:

sudo apt install nvidia-cuda-toolkit

Download Nvidia CuDNN, extract the tarball and copy the files to the corresponding path:

tar -xf cudnn-linux-x86_64-*.tar.xz

sudo cp cudnn-linux-x86_64-*/include/cudnn*.h /usr/lib/cuda/include/
sudo cp -P cudnn-linux-x86_64-*/lib/libcudnn* /usr/lib/cuda/lib64/
sudo chmod a+r /usr/lib/cuda/include/cudnn*.h /usr/lib/cuda/lib64/libcudnn*
echo 'export LD_LIBRARY_PATH=/usr/lib/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/lib/cuda/include:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

Another reboot and everything should work. In one case, after reboot the Nvidia drivers were greyed out in Software & Updates and TensorFlow was using the CPU. Running sudo ubuntu-drivers install and rebooting solved the problem.

 

Nvidia On-Demand

The RTX 3080 supports Nvidia On-Demand, so your notebook will mainly use the Intel GPU and use the dedicated one only if needed. Go to NVIDIA X Server Settings and set the PRIME Profiles to NVIDIA On-Demand. You can also do this via Terminal with prime-select, for example

sudo prime-select on-demand

(also helpful if Intel only is greyed out)

You can specifiy which applications should use the Nvidia GPU under:

sudo nano /etc/environment

for Vulkan applications add

__NV_PRIME_RENDER_OFFLOAD=1

It can be tested by installing sudo apt install vulkan-tools and run vkcube.

for GLX applications add

__NV_PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia

Testing OpenGL can be done by installing sudo apt install glmark2 and running glmark2.

To check which GPU is currently being used:

glxinfo | grep vendor

For Ubuntu 21.04: In some cases Ubuntu switched back to Wayland for the desktop, which is not supported by Nvidia, so it would always rely on the Intel GPU. To always use Xorg uncomment the line:

sudo nano /etc/gdm3/custom.conf
WaylandEnable=false

With Nvidia On-Demand my battery life increased under light load from two hours to nearly seven hours.

 

Conda and TensorFlow

I like to use Miniconda for my work. Install as usual (if wished):

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc

Create and activate environment:

conda create --name ENV python
conda activate ENV
pip install --upgrade pip

If you need to deactivate and remove environments you can do it with:

conda deactivate
conda env remove -n ENV

Cuda 11.2 and later need at least TensorFlow 2.6:

pip install tensorflow

 

Using TensorCores

To use the TensorCores on your GPU edit your Code:

from tensorflow.keras import mixed_precision
mixed_precision.set_global_policy('mixed_float16')

I get roughly a 30% speedup. Nice.

 

Matlab

Matlab doesn’t scale automatically for the 4K-panel. In the command window run:

s = settings;s.matlab.desktop.DisplayScaleFactor
s.matlab.desktop.DisplayScaleFactor.PersonalValue = 2

 

Carla Autonomous Driving Simulator

Carla is the only application so far that made minor troubles while installing under Ubuntu 21.04.

When adding the repository replace $(lsb_release -sc) with focal:

pip install --user pygame numpy
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1AF1527DE64CB8D9
sudo add-apt-repository "deb [arch=amd64] http://dist.carla.org/carla focal main"
sudo apt update
sudo apt install carla-simulator

 

Nice to Have

Keyboard Backlight

I added support for the Razer Blade Advanced Early 2021 to OpenRazer. As my pull request got merged you can install it simply as described here:

sudo add-apt-repository ppa:openrazer/stable
sudo apt update
sudo apt install openrazer-meta

Don’t forget to add your user to the plugdev group with sudo gpasswd -a $USER plugdev.

For the GUI I use Polychromatic. Install with:

sudo add-apt-repository ppa:polychromatic/stable
sudo apt install polychromatic

Reboot and you’re ready to go!

Weirdly, when the tray applet is running and I put the laptop to sleep and wake again, the backlight is turned off until after login. Not sure if it is a bug, but it makes it difficult logging in in the dark. I just turned the applet of in startup scripts and that solved the problem.

 

Better Sound

PulseEffect got updated and is called EasyEffects now. Installation got a little bit more complicated now.

The Blade has probably the worst sounding speaker I have heard since my first mobile phone in the mid 2000s! Luckily, there is EasyEffects! If you haven’t install Flatpak do so with

sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

and then install EasyEffects

flatpak install flathub com.github.wwmm.easyeffects

You need the run following commands as described here:

sudo apt install pipewire-audio-client-libraries libspa-0.2-bluetooth libspa-0.2-jack
sudo apt install wireplumber pipewire-media-session-

Reboot and run start the application.

I spent way too much time tweaking the equalizer and the outcome is actually pretty good (screenshot still from PulseEffects, EasyEffects looks similar):

PulseEffectsEQ

The .json file in this repo was exported from PulseEffect and does not work properly at the moment, I will look into it. Start service at login from the settings does not work at the moment. A workaround is explained in the issues. Create the file com.github.wwmm.easyeffects.desktop in ~/.config/autostart for example with:

sudo nano ~/.config/autostart/com.github.wwmm.easyeffects.desktop

and add

[Desktop Entry]
Name=EasyEffects
Comment=EasyEffects Service
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=easyeffects com.github.wwmm.easyeffects --gapplication-service
Icon=easyeffects
StartupNotify=false
Terminal=false
Type=Application

 

Face Unlock

The Blade Advanced features an IR camera for Windows Hello. You can use it for face recognition, so you don’t need to type your password after sudo or on the login screen. Install Howdy with

sudo add-apt-repository ppa:boltgolt/howdy
sudo apt update
sudo apt install howdy

and in the setting sudo howdy config change the device path to device_path = /dev/video2 (video0 is the normal camera, video2 the IR sensor) and set ignore_closed_lid = false. Then add your face:

sudo howdy add
sudo howdy test

There seems to be a problem at some times, when the IR light doesn’t turn on. Apparently, by booting from the bios the problem does not occur anymore.

 

4K OLED

I haven’t heard so far, whether the OLED screen suffers of burn-in or not. But it doesn’t hurt to take a little care.

 

Bluetooth for Airpods

With Ubuntu 21.04 it didn’t really work to connect Airpods to the notebook. A fix can be found here.