kdb+ FFI

Kdb+ FFI: Access external libraries more easily from q

22 Nov 2017 | ,
Share on:

By Fintan Quill

Following on from the hugely popular Python library and interface embedPy and PyQ, Kx has released an FFI as part of the Fusion for kdb+ interfaces. As with embedPy and PyQ, this FFI is open-sourced under the Apache 2 license.

The kdb+ FFI is a foreign function interface library for loading and calling dynamic libraries from q code. It has been adapted and expanded upon from a library originally written by Alex Belopolsky of Enlightenment Research. With the kdb+ FFI you can now call your favorite C/C++ libraries directly from q without the overhead of having to compile shared objects and load into q using the 2: command.

In order to use the kdb+ FFI, you need to install kdb+ version 3.4 or later as well as libffi3.1+. Instructions are available for installing libffi using your package manager of choice such as apt-get or brew. The kdb+ FFI package then needs to be downloaded and unpacked. Once unpacked, simply load the ffi.q script into your q process and you’re done!

There are two main functions of note within the interface, .ffi.cf to do a once-off call to a function and .ffi.bind binds a C call to a q function for multiple calls.

What are the advantages of using the kdb+ FFI? Users no longer have to write their own C/C++ code or use compiler toolchains to connect to many common libraries. A second advantage is when interacting with the operating system the kdb+ FFI doesn’t carry the overhead of forking an extra process similar to the system command in q.

Within the project are several examples including:

  • PCRE bindings for regular expressions
  • BLAS bindings for common linear algebra operations
  • Rmath bindings for random number generators and probability functions
  • Callback registration

You can check out the project on the Kx Systems’ Github where you can also send feedback and add to the project.

Happy coding!

Fintan Quill is Global Head of Sales Engineering for Kx and is based in New York City.

SUGGESTED ARTICLES

kdb-for-solar-storm-data

The Exploration of Solar Storm Data Using JupyterQ

7 Jun 2018 | , , ,

At Kx25, the international kdb+ user group conference held on May 18th, I made a presentation that demonstrated how to use a JupyterQ notebook to perform analytics on solar storm data.
My experience working with solar storm data began last year when I was a visiting data scientist at the NASA Frontier Development Lab (FDL) in Mountain View, California. The FDL is hosted by the Search for Extraterrestrial Intelligence Institute (SETI): a not-for-profit research organization founded in 1984, whose purpose is to drive research in the space sciences. Within SETI, FDL is an applied artificial intelligence research accelerator established to maximize new AI technologies and apply them to challenges in the space sciences.

Message from the Kx COO Mark Sykes

29 May 2018 | , , , , , , , , , ,

On May 18th, we hosted Kx25, the largest international kdb+ user event ever. Having the opportunity to get broad feedback from our user community is a hugely important exercise for us. We know that many of our users have built their careers around kdb+, and we recognize our responsibility to them. That is why we work so hard to constantly improve the world class software we deliver. Kx is unique in its facility to both listen, and respond, with significant changes to each new annual release of kdb+ and our supporting range of products, solutions and tools.