Skip to content

Conversation

@br4sco
Copy link
Contributor

@br4sco br4sco commented Feb 27, 2025

This PR adds new external-based libraries for matrices and vectors. It also refactors and extends the external array library.

arr-ext.mc
This library implements (Ocaml native) and (Bigarray) 1D arrays. The Bigarray-based, or ExtArr arrays as they are called, can hold either double or single precision floats.

cblas-ext.mc
This library implements a (incomplete) high-level CBLAS interface based on ExtArr arrays. It will pick the right implementation based on the kind of the ExtArr array (single or double precision right now).

The CBLAS routines are flexible and take many arguments. Therefore I added a record with default arguments for convenience. They are named the same as the function but suffixed withArg. For example, you call the CBLAS routine gemm that performs the computation y := alpha*A*x + beta*y as:

cblasGemv { cblasGemvArg with beta = 2. } m n a x y

where we change the default value of beta = 0.0 to 2.0.

vec-ext.mc
Implements ExtArr arrays as vectors. Currently, it only implements the operations necessary to define a vector space (addition and scalar multiplication). The implementation uses cblas-ext.mc.

mat-ext.mc
Implements matrices based on ExtArr arrays. It implements operations over matrices using a combination of
cblas-ext.mc and external operations implemented in Owl. All but one operation (matrix exponential) can be used in place or in a referential transparent manner, where the latter performs a copy/data allocation.

Updated Microbenchmarks

I updated the Microbenchmarks and added benchmarks for mat-ext.mc. Some relevant results are as follows on my machine (matrix multiplication with matrices of size 100x100):

for t in mul mul_naive; do echo $t; ./run -e 1245 matrix_$t; echo ""; done 
mul
1. Miking compiler:         0.014660s  0.016695s
2. OCaml native:            0.019750s  0.020799s

mul_naive
1. Miking compiler:         4.854387s  4.443769s
2. OCaml native:            4.039013s  3.961367s

The benchmark mul compares matMul from mat-ext.mc with Owl.Mat.( *@ ) (matrix multiplication). The benchmark mul_naive compares naive matrix multiplication in a triple for-loop between matrices from mat-ext.mc and Bigarray.Array2 arrays.

For comparison, these are the times for naive matrix multiplication using Bigarray-based tensors:

1. Miking compiler:         9.424949s  9.459076s

and native OCaml arrays

2. OCaml native:            0.379540s  0.375307s

@br4sco br4sco force-pushed the external-matrix-vec branch from beaa4bb to 916ac36 Compare February 27, 2025 11:18
@br4sco br4sco force-pushed the external-matrix-vec branch from 916ac36 to 20b3bd6 Compare February 27, 2025 11:46
@br4sco br4sco force-pushed the external-matrix-vec branch from 20b3bd6 to 2af97bf Compare February 27, 2025 12:00
@br4sco br4sco force-pushed the external-matrix-vec branch from 2af97bf to c4842ad Compare February 27, 2025 12:04
@david-broman david-broman merged commit 21f16fa into miking-lang:develop Mar 3, 2025
1 of 2 checks passed
@br4sco br4sco deleted the external-matrix-vec branch March 3, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants