Comments (7)
[dependencies]
blas = "0.22.0"
blas-src = { version = "0.8", features = ["openblas"] }
openblas-src = { version = "0.10", features = ["cblas", "system"] }
from dfdx.
First attempt... the arguments aren't correct though.
extern crate blas_src;
fn matmul<const M: usize, const N: usize, const K: usize>(
a: &[[f32; K]; M],
b: &[[f32; N]; K],
) -> [[f32; N]; M] {
let mut c = [[0.0; N]; M];
unsafe {
let a = std::slice::from_raw_parts(a.as_ptr() as *const f32, 0);
let b = std::slice::from_raw_parts(b.as_ptr() as *const f32, 0);
let c = std::slice::from_raw_parts_mut(c.as_mut_ptr() as *mut f32, 0);
blas::sgemm(
b'T', b'T', M as i32, N as i32, K as i32, 1.0, a, K as i32, b, N as i32, 0.0, c,
M as i32,
)
}
c
}
from dfdx.
Here's a cblas_sys function to call
[dependencies]
cblas-sys = "0.1.4"
libc = "0.2.126"
pub fn mkl_mm<const M: usize, const N: usize, const K: usize>(
a: &[[f32; K]; M],
b: &[[f32; N]; K],
c: &mut [[f32; N]; M],
) {
unsafe {
cblas_sys::cblas_sgemm(
cblas_sys::CblasRowMajor,
cblas_sys::CblasNoTrans,
cblas_sys::CblasNoTrans,
M as libc::c_int,
N as libc::c_int,
K as libc::c_int,
1.0 as libc::c_float,
a.as_ptr() as *const libc::c_float,
K as libc::c_int,
b.as_ptr() as *const libc::c_float,
N as libc::c_int,
0.0 as libc::c_float,
c.as_mut_ptr() as *mut libc::c_float,
N as libc::c_int,
)
}
}
from dfdx.
And custom build.rs
file for linking against MKL is here:
from dfdx.
Note that pytorch & tensorflow both use intel MKL under the hood as far as I can tell (at leats on my machine):
>>> print(*torch.__config__.show().split("\n"), sep="\n")
PyTorch built with:
- C++ Version: 199711
- MSVC 192829337
- Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v2.5.2 (Git Hash a9302535553c73243c632ad3c4c80beec3d19a1e)
- OpenMP 2019
- LAPACK is enabled (usually provided by MKL)
- CPU capability usage: AVX512
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CXX_COMPILER=C:/actions-runner/_work/pytorch/pytorch/builder/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -DUSE_PTHREADPOOL -openmp:experimental -IC:/actions-runner/_work/pytorch/pytorch/builder/windows/mkl/include -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.11.0, USE_CUDA=0, USE_CUDNN=OFF, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF,
from dfdx.
Any possibility to also add support for openblas? I understand that intel-mkl is more widely used for tensorflow and PyTorch by default. Openblas seem to work on any CPU structure despite sightly slower than intel-mkl, for example ARM64 CPUs like KUNPENG920-6426(HiSilicon) , ARM64 apple M1 series and also Fujitsu-A64FX. The ndarray-linalg crate does support both by using different features. Can matrix-mulitply be replaced with this one?
Thanks,
Jianshu
from dfdx.
Good point about support for different cpu structures. I'm definitely open to this. When I first was looking into this stuff configuration for it seemed very confusing (especially with cargo's additive features). I also lack a linux machine to test on, so I'd need help with that.
This will probably be lower on the priorities list for me, but happy to review contributions for this
from dfdx.
Related Issues (20)
- Alloc zero size memory on old model GPU may fail.
- Different results when CPU feature is on vs off HOT 2
- Unnecessary loss of precision when computing loss functions HOT 2
- trait TryConcatAlong not satisfied when using constants HOT 1
- Consider helpers for accessing tensors from tuples and input wrappers HOT 1
- Question / clarification regarding heap allocations HOT 2
- Examples or resources for autodiff with 2 networks?
- Bug: `Sequential` macro provide `forward_mut` as `forward`
- Replace explicit features and paths on generated code
- Send/Sync for Device HOT 1
- Add `OUTPUT_PADDING` to `ConvTrans2D`
- Split `TryConcatAlong` into different traits
- Add `Prodigy` optimizer HOT 1
- Run tests with miri HOT 1
- Reduce test sizes HOT 1
- Unclear how to handle error type in `dfdx::nn::LoadFromNpz::load`
- Add `nn::AdaptiveAvgPool2D`
- How does one update one model from another model? HOT 1
- Unable to build with old CUDA version (`CUDA_COMPUTE_CAP = 52`)
- OpenXLA Support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dfdx.