Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/fardream/gen-mkl-wrapper

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/fardream/gen-mkl-wrapper

  • v0.3.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

Generates wrappers for Math Kernel Library routines

Installation

The package relies on modernc.org/cc/v4 as AST parser, which is a pure go implementation. The binary can be installed with go install:

go install github.com/fardream/gen-mkl-wrapper@latest

Wrappers

Math Kernel Library by Intel is widely used library of common mathematical routines, which provides support for various BLAS and LAPACK routines and many many more. Due to its root in Fortran and C, many routines' names contain the type its operates on, for example, the Cholesky Decomposition is

lapack_int LAPACKE_spotrf (int matrix_layout , char uplo , lapack_int n , float * a , lapack_int lda ); // for float, or 32-bit float point number.
lapack_int LAPACKE_dpotrf (int matrix_layout , char uplo , lapack_int n , double * a , lapack_int lda ); // for double, or 64-bit float point number.

For C++ or rust, it may be desired to dispatch the method based on the type. This becomes extremely handy when implementing something based on MKL for both 32-bit and 64-bit float point number.

In C++, below is valid

lapack_int LAPACKE_potrf (int matrix_layout , char uplo , lapack_int n , float * a , lapack_int lda ); // for float, or 32-bit float point number.
lapack_int LAPACKE_potrf (int matrix_layout , char uplo , lapack_int n , double * a , lapack_int lda ); // for double, or 64-bit float point number.

Similarly in rust, the below is valid

pub trait MKLRoutines {
    fn LAPACKE_potrf(matrix_layout: i32, uplo: i8, n: i32, a: *mut Self, lda: i32) -> i32;
}

impl MKLRoutines for f64 {
    // for f64, or 64-bit float point number.
    fn LAPACKE_potrf(matrix_layout: i32, uplo: i8, n: i32, a: *mut Self, lda: i32) -> i32 {
        unsafe {
            LAPACKE_dpotrf(matrix_layout, uplo, n, a, lda)
        }
    }
}

impl MKLRoutines for f32 {
    // for f32, or 32-bit float point number.
    fn LAPACKE_potrf(matrix_layout: i32, uplo: i8, n: i32, a: *mut Self, lda: i32) -> i32 {
        unsafe {
            LAPACKE_spotrf(matrix_layout, uplo, n, a, lda)
        }
    }
}

This simply binary does just the above - provided with a list of routines names, it will generate the rust trait or C++ polymorphic functions to those routines.

Those generated functions can be called from template/generic functions

template <typename T>
void SomeFunctionForFloatPoint(T* x) {
    // ... other codes
    LAPACKE_potrf(LAPACK_ROW_MAJOR, 'U', n, x, lda);
    // ... other codes
}

or

pub fn some_function_for_float<T: MKLRoutines>(x:&mut [T]) {
    // ... other codes
    unsafe { T::LAPACKE_potrf(LAPACK_ROW_MAJOR as i32, 'U' as i8, n x.as_mut_ptr(), lda) };
    // ... other codes
}

FAQs

Package last updated on 11 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc