A code generator for modern numerical development: meet Kalray’s Metalibm

A code generator for modern numerical development: meet Kalray’s Metalibm

Fork me on GitHubUnderstanding the challenge of numerical code development

The time of static numerical libraries is behind us. Every application has different needs, be it speed rather than precision, throughput rather than latency or custom specifications rather than agreed standards. Still, most numeric codes share the same basic blocks tweaked and assembled to best suit the needs of the final application.

Large companies may have the luxury to employ dozens of highly skilled developers to manually develop, test and optimize numerical code for specific needs; smaller companies, however, do not. They must rely on automation to meet the demand.

Metalibm: from a research project to an open source framework

Metalibm is a French research project funded by the ANR and developed jointly by INRIA, UPMC, LIRMM and CERN. It stemmed from an original idea by Christoph Lauter, whereupon Florent de Dinechin suggested new solutions for mathematical libraries and filter code generation.

Kalray has chosen to make its contribution to Metalibm public and open source: meet Kalray’s Metalibm, a code generation framework developed for designing, validating and benchmarking mathematical functions (e.g. exponential, trigonometric functions). Code generators such as Metalibm facilitate development factorization, implementation testing and profiling, and they accelerate development and release time.

Figure 1. Metalibm generation flow

Metalibm uses an implementation description language based on Python (MDL). MDL is more expressive and accurate than most programming languages to describe numerical kernel implementations. From MDL, Metalibm generates an intermediate representation which allows easy implementation of optimization. For final code generation, Metalibm provides a set of backends (currently generic C code and various variant of x86 backends are available; llvm-ir backend is under development1).

The division between IR and backends allows to share implementation description among several targets, in conjunction with variant specific code transformations. Metalibm can generate many different implementations from a single initial description. It can also generate a numerical and performance testbench to help the developer check his implementation against a reference, and to profile the generated code.

Try it / Fork it on GitHub

Feel free to try Metalibm from our github and to contribute to its development. We will be happy to hear your feedback and help you make the most of this new development tool.

1 If you own a version of the Kalray AccessCore license, a Metalibm backend for Kalray cores is available upon request.


[1] Contributions to computer arithmetic and applications to embedded systems, N. Brunie, Phd, 2014

[2] Code generators for mathematical functions, N. Brunie, F. De Dinechin, O. Kupriianova, C. Lauter, ARITH 22, 2015