Skip to content

argovis/matrust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matlab x rust

This repo contains a MWE for creating a Rust library that can be successfully loaded and run as part of a matlab script on blanca. This mostly follows this blog post, with some additional jiggery-pokery to allow us to build the rust library on our local machine in such a way that it runs properly on blanca.

Method

Creating the rust library

  • After writing your desired functions in pure rust (ie src/lib.rs), wrap them in a foreign function interface wrapper (src/wrapper.rs) that accepts and returns C-compatible types that matlab can cope with.
  • Will also need a header file (bindings.h) for matlab to ingest; this can be autogenerated as part of the regular build process via build.rs.
  • The library needs to be built against the glibc version available on blanca, currently 2.28. Managing glibc versions is a nuisance, so we'll build our library in a containerized environment that has the correct glibc installed in it by default; this container is described in Dockerfile.
  • Build this image, run it as a container with your rust source directory mounted, and build with cargo build --target=x86_64-unknown-linux-gnu (maybe throw a --release flag in there for production builds).
  • Zip up the whole thing (or just the .so and .h files if you're feeling stingy), and send them to blanca.

Calling from matlab

  • After making a project directory (probably under /scratch/alpine/<user>), unzip the rust tarball there, and create a matlab function that loads the library and calls the function (ie matlab/addWithRust.m). Probably the library load / unload should be done not inside every function call in production.
    • Check that the libname and libpath make sense for your example.
  • matlab/demo.m trivially calls this function, and matlab/demo.slurm submits it to the high priority queue.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published