intro

this week i wanted to revisit one of my old machine learning projects. that project used the excellent keras library for building the model.

keras by default is configured to use the tensorflow backend. tensorflow currently is heavily dependent on nvidia cuda for gpu acceleration.

however, my workstation has an amd gpu, specifically the rx 580. if i were to use keras with the default tensorflow backend, performance would be very poor because all the heavy calculation would be running on my cpu.

options for acceleration

rocm

amd rocm looks promising and apparently supports my gpu; however i spent some time trying to install it and was not able to. some of the aur packages failed to build.

plaidml

plaidml describes itself as "a framework for making deep learning work everywhere." from what i can gather, it is a tensor compiler that supports a wide range of devices through opencl.

though it isn't officially supported by keras, plaidml also provides a keras backend.

setting up plaidml

plaidml setup was surprisingly easy on my machine.

first, i installed the packages:

pip install plaidml-keras plaidbench

then, i ran plaidml-setup to configure plaidml, and set my gpu as my default device

finally, i tested it on a simple workload by running mobilenet:

plaidbench keras mobilenet

this seemed to work well on my machine. when i ran my keras project, it appeared to be using the gpu. great!

tldr

use plaidml-keras.