fmlr is an R interface to the fml library. It is a “medium-level” interface for multiple dense matrix types, principally CPU, GPU, and MPI. Each supports multiple fundamental types (int, float, double), and data is held externally to R and operations that modify data generally occur in-place. The interface largely tracks with the core ‘fml’ interface. The interface is written such that generally an ‘fmlr’ R code can be easily translated to an ‘fml’ C++ code.

Differences between fmlr and other matrix interfaces (including the core R interface):

  • Single interface supporting multiple fundamental types (__half, float, double) and backends (CPU, GPU, MPI).
  • Data is always held externally to R (although CPU objects can inherit R data without a copy).
  • Operations modifying data occur in-place (make your own copy if you don’t want the data modified).

For a high-level interface on top of fmlr, see the craze package.

Installation

In principle, installation can be as simple as:

install.packages("fmlr", repos=c("https://hpcran.org", "https://cran.rstudio.com"))

This will build support for the CPU backend. If you want GPU or MPI support, please see the Installation Guide.

Example Use

Calculating singular values on CPU:

suppressMessages(library(fmlr))
x = cpumat(3, 2, type="float")
x$fill_linspace(1, 6)
x$info()
## # cpumat 3x2 type=f
x
## 1.0000 4.0000 
## 2.0000 5.0000 
## 3.0000 6.0000 

s = cpuvec(type="float")
linalg_svd(x, s)

s$info()
## # cpuvec 3 type=f
s
## 9.5080 0.7729 

and on GPU:

c = card()
c
## GPU 0 (GeForce GTX 1070 Ti) 1139/8116 MB - CUDA 10.2

x = gpumat(c, 3, 2, type="float")
x$fill_linspace(1, 6)
x$info()
## # gpumat 3x2 type=f 

s = gpuvec(c, type="float")
linalg_svd(x, s)

s$info()
## # gpuvec 2 type=f 
s
## 9.5080 0.7729 

For more information and examples, see:

fml from C++

A copy of the core fml library is included in the fmlh package. If you wish to link with fml to create your own C++ kernels, you can add LinkingTo: fmlh to your R package DESCRIPTION file, as this very package does.

Before you write your own C++ code using fml, you should check the fml API stability progress, as some things may be subject to change.

Similar Projects

Some similar R projects worth mentioning:

Some related R packages I have worked on:

For C/C++ projects, see the fml README.