You are here: Home > Software > Yorick > YDLWrap

YDLWrap

YDLWrap is a Yorick plugin for dynamically calling compiled functions

The interface is fast: I have measured an extra overhead of ~ 15ns (about 15 nanoseconds) on my laptop (Core i7 Q820 at 1.73GHz) for a simple function call like sin(x) compared to the built-in version of the same function.

Example

Here how you can call a function using the symbols compiled into the Yorick excutable itself:

// Load the plugin:
#include "dlwrap.i"
// Open the executable itself:
dll = dlopen();
// Create a function wrapper:
dll_sin = dlwrap(dll, DL_DOUBLE, "sin", DL_DOUBLE);
//                |    |          |      |
//                |    |          |      `-- argument type
//                |    |          `--------- symbol name
//                |    `-------------------- return type
//                `------------------------- dynamic module
// Call the wrapper (like a Yorick function):
a = dll_sin(1.25);

Of course, you can use the function wrappers as many times as you want and open a specific dynamic library

Installation

First, download the source here: ydlwrap-0.0.2.tar.bz2.

You need two external libraries: one for loading dynamic modules, one for dynamically calling compiled functions.

For loading dynamic modules, you can choose:

 sudo apt-get install libltdl-dev
  • play interface (this is the Portability LAYer on top of which Yorick is build; with this interface, unloading of modules is not possible).

For dynamically calling compiled functions, you must use:

sudo apt-get install libffcall1-dev

To use dlopen, add:

-DHAVE_DLOPEN     to macro PKG_CFLAGS in Makefile
-ldl              to macro PKG_DEPLIBS in Makefile

To use libtool, add:

-DHAVE_LIBTOOL    to macro PKG_CFLAGS in Makefile
-lltdl -ldl       to macro PKG_DEPLIBS in Makefile

To use ffcall, add:

-DHAVE_FFCALL     to macro PKG_CFLAGS in Makefile
-lavcall          to macro PKG_DEPLIBS in Makefile

After having edited the Makefile, use Yorick to update the paths:

yorick -batch make.i

Then compile the package (the install step is optional):

make clean
make
make install

Wish List

  • Hide structure definitions in the SYS object.
  • Write a (pseudo) "configure" script to edit the Makefile.
  • For the moment only functions can be obtained, global variables remain inaccessible.
  • Allow compilation of different plugins with different implementations. For instance:
    • dlwrap-ffcall-play.${DLL} for ffcall + Play
    • dlwrap-ffcall-dl.${DLL} for ffcall + system DL
    • dlwrap-ffcall-ltdl.${DLL} for ffcall + GNU Libtool
  • Try other dynamic function calling system like LIBFFI (fix the SIGFPE issue), CINVOKE, etc.

To dynamically call compiled functions, I have tried to use libffi (http://sourceware.org/libffi) but ffi_prep_cif() raises a SIGFPE (perhaps it lefts some dirt in the floating-point registers) which interrupts Yorick. I could not prevent this by using signal(2) to temporarily ignore SIGFPE. The advantage of libffi would be that it may speedup calling functions (argument parsing can be done only once).

  • Implement callback system for object destruction.
  • Add other types to allow for Yorick variables definition: C_INT_OUT, C_LONG_OUT, etc. to mean that the argument is the name of a Yorick variable set with an int, a long, etc. on return, the called function takes a pointer to the corresponding type.

Yeti 6.4.0

Yeti version 6.4.0 has been released (2015-02-06). This version has no new feature compared to 6.3.3 but is now hosted on GitHub. [more]

 

MiRA won 2008' Beauty Contest

MiRA has won the 2008' edition of the Beauty Contest for image reconstruction algorithms from optical interferometry data.