MatrixOperationsCuda is a Rust crate for performing matrix operations using CUDA
## Installation
Add the following to your Cargo.toml
file:
toml
[dependencies]
matrix_operations_cuda = "0.1.0"
To works with matrix_operations_cuda
, you need to install the core matrix_operations from matrix_operations
Add the following to your Cargo.toml
file:
toml
[dependencies]
matrix_operations = "0.1.3"
This crate does NOT include CUDA itself. You need to install on your own. the official installer
This crate allow to use common operations using cuda:
```rust use matrixoperations::matrix; use matrixoperationscuda::{addmatrices, addscalar, CudaEnv, dot, submatrices};
let cudaenv; unsafe { cudaenv = CudaEnv::new(0, 0).unwrap(); }
let m1 = matrix![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]; let m2 = matrix![[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
let m3; unsafe { m3 = dot(&m1, &m2, &cuda_env).unwrap(); }
asserteq!(m3[0], [22.0, 28.0]); asserteq!(m3[1], [49.0, 64.0]);
let m4; unsafe { m4 = addscalar(&m3, 10.0, &cudaenv).unwrap(); }
asserteq!(m4[0], [32.0, 38.0]); asserteq!(m4[1], [59.0, 74.0]);
let m5; unsafe { m5 = submatrices(&m4, &m3, &cudaenv).unwrap(); }
asserteq!(m5[0], [10.0, 10.0]); asserteq!(m5[1], [10.0, 10.0]); ```
You also can import your own module from a .ptx
file or from a module data as Vec<u8>
```rust use cudadriversys::*; use matrixoperationscuda::cudaenv::CudaEnv; use matrixoperationscuda::cudamodule::CudaModule; use matrixoperations::{Matrix, matrix}; use matrixoperationscuda::matrixapply::applyfunctionmatrix;
unsafe { let mut cuda_env = CudaEnv::new(0, 0).unwrap();
let module = CudaModule::new(b"resources/kerneltest.ptx\0").unwrap(); let function = module.loadfunction(b"mulby2\0").unwrap();
let matrix = matrix![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let result = applyfunctionmatrix(&matrix, &cuda_env, function).unwrap();
asserteq!(result[0], [2.0, 4.0, 6.0]); asserteq!(result[1], [8.0, 10.0, 12.0]);
module.free().unwrap(); } ```
Initialize a cuda environment