Deep learning with LLVM using PlaidML

Mar 28, 2018 | By: Mars Saxman

Comments on Hacker News

In PlaidML 0.3.0, we have integrated LLVM as a new option for CPU execution.

We’ve kept things simple for now, by supporting execution only on CPUs, but the wide array of instruction sets available through LLVM means that this new hardware interface module offers exciting possibilities for future targets. For example, we could take advantage of LLVM’s support for NVPTX and AMDGPU to run Tile code directly on the GPU, bypassing OpenCL; alternately, we could provide device-independent GPU binaries by compiling out to SPIR-V. In the embedded world, generating ARM code would be an obvious win, and we could make use of Qualcomm DSPs through LLVM’s Hexagon support.

Since PlaidML is all about hardware compatibility, its design includes an internal hardware abstraction layer—the “HAL”—which allows the PlaidML framework and Tile language to efficiently interact with a variety of platforms and runtime environments.

Each HAL implementation module is responsible for translating the Tile compiler’s internal semantic representation into code which can be executed on the target platform. Our primary hardware module works by generating OpenCL source code, which the OpenCL driver then compiles into GPU-specific machine code. With the new llvm_preview_cpu module, we render compiled Tile code into LLVM IR instead; we then run LLVM’s optimization passes and the code generator suitable for the target platform.

In addition to code generation, the HAL is a common interface for buffer management, scheduling, and other features of the runtime environment. The experimental hardware module we’ve added in PlaidML 0.3.0 handles this in a straightforward way, JITing code for the host CPU and distributing tasks across cores with a thread pool.


After installing PlaidML 0.3.0, you’ll see the new module listed as an experimental device option when you run plaidml-setup:

Experimental Config Devices:
   llvm_preview_cpu.0 : LLVM_preview_CPU
   carrizo.0 : Advanced Micro Devices, Inc. Carrizo

Opt in to experimental device support by pressing ‘y’, then select llvm_preview_cpu.0 as your default device:

Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS).
Please choose a default device:

   1 : llvm_preview_cpu.0
   2 : carrizo.0

Default device? (1,2)[1]:1

Selected device:
© 2018 Vertex.AI