stsds / MPCR

Multi-Precision R-package providing an interface for R developers to use multiple precisions for floating point number representation and arithmetic.
GNU General Public License v3.0
2 stars 0 forks source link

MPCR: Multi-Precision Computing in R

Overview

The MPCR package provides new data-structure support for multi- and mixed-precision for R users, supporting 16-bit, 32-bit, and 64-bit operations. This enables optimized memory allocation based on the desired precision, offering significant advantages in-memory optimization and computational efficiency. In addition, MPCR leverages GPU acceleration through CUDA, allowing for high-performance computations on the GPU. This capability includes seamless memory transfers between CPU and GPU, managed automatically by the package, simplifying the setup and usage for end users.

Key Features

1. Multi-Precision Support

MPCR introduces a new data structure that supports three different precisions:

This flexibility allows for optimized memory allocation and performance tuning based on the specific needs of your application.

2. Comprehensive Linear Algebra Support

The package extends support to all basic linear algebra methods across different precisions. You can perform operations like matrix multiplication, inversion, and eigenvalue decomposition with ease, regardless of the chosen precision.

3. Seamless Integration

MPCR maintains a consistent interface with normal R functions, allowing for seamless code integration. You can use MPCR data structures and functions without having to significantly alter your existing codebase, ensuring a user-friendly experience.

4. GPU Acceleration with CUDA

The package now supports CUDA, enabling the allocation of memory and performance of operations on the GPU using CuSolver and CuBLAS. This includes:

5. Installation

To install the MPCR package, you can use the following command:

General Note: The package will automatically be built with CUDA support if CUDA ToolKit is detected, if not, the package will be build with CPU support only.


6. Requirements

7. Getting Started

Example showcasing how MPCR can be used to allocate and perform operations on CPU/GPU. More examples are available in the following directory.

library("MPCR")

values <- c(3.12393, -1.16854, -0.304408, -2.15901,
            -1.16854, 1.86968, 1.04094, 1.35925, -0.304408,
            1.04094, 4.43374, 1.21072, -2.15901, 1.35925, 1.21072, 5.57265)

# placement will indicate on which device the allocation should be made.
# default option : CPU

A <- as.MPCR(values, nrow = 4, ncol = 4, precision = "float",placement="GPU")
B <- as.MPCR(values, nrow = 4, ncol = 4, precision = "float",placement="GPU")

# Set operation placement is the function used to decide whether the up-coming
# operation should be executed on CPU or GPU

# All the up-coming operation will be executed on GPU
# default option : CPU
MPCR.SetOperationPlacement("GPU")

cat("----------------------- CrossProduct C=XY --------------------\n")
crossproduct <- crossprod(x, y)

# Print is a CPU only function, so the data will automatically be transferred to CPU,
# resulting in having a copy on CPU and a copy on GPU for future GPU operation
crossproduct$PrintValues()