
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
github.com/fardream/gen-mkl-wrapper
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
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
Unknown package
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.