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):
__half
, float
, double
) and backends (CPU, GPU, MPI).For a high-level interface on top of fmlr, see the craze package.
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.
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:
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.
Some similar R projects worth mentioning:
Some related R packages I have worked on:
For C/C++ projects, see the fml README.