kernel/api: add nalgebra::linalg try_invert_to api #307
No reviewers
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/artiq-zynq#307
Loading…
Reference in New Issue
No description provided.
Delete Branch ":support_nalgebra"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds support for
nalgebra
crate. The following features were needed to supportnalgebra
innon-std
mode:A fork of
nalgebra
with required attributes is at https://git.m-labs.hk/abdul124/nalgebra/src/branch/artiq-zynqThe PR also adds
nalgebra::linalg::try_invert_to
function to the kernel/api.rs to perform in-place matrix inversion.@ -34,1 +34,4 @@
libboard_artiq = { path = "../libboard_artiq" }
[dependencies.nalgebra]
git = "https://git.m-labs.hk/abdul124/nalgebra.git"
Please create it under M-Labs. Moving it
@ -215,6 +232,9 @@ pub fn resolve(required: &[u8]) -> Option<u32> {
api!(__aeabi_memclr4),
api!(__aeabi_memclr),
// linalg
This should go at the end, after libm.
@ -41,0 +54,4 @@
0 // Return 0 to indicate failure
}
}
Comments are too verbose and basically unnecessary, the code is quite obvious already.
@ -38,6 +40,21 @@ unsafe extern "C" fn rtio_log(fmt: *const c_char, mut args: ...) {
rtio::write_log(buf.as_slice());
}
unsafe extern "C" fn try_invert_to(dim0: i64, dim1: i64, data: *mut f64) -> i8 {
What about other functions?
Also this is function is poorly named. Add a
linalg_
prefix or something, otherwise you have no idea what it can possibly do just looking at the name.The C symbols are a flat namespace.
Updated function name and removed unnecessary comments.
I am testing the other function (
wilkinson_shift
) on standalone. Will create another PR once its implementation is completed.@ -17,6 +19,7 @@ extern "C" {
fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int;
}
#[no_mangle]
Does not belong in this PR.
Isn't no_mangle implied by extern C anyway?
Noted. I will remove it from this PR.
I don't think
no_mangle
is implied byextern C
as discussed here: https://github.com/rust-lang/rfcs/issues/674OK. Please send a separate PR to add it then.
@ -321,1 +340,4 @@
},
// linalg
api!(try_invert_to = linalg_try_invert_to),
linalg_ in both names. Use the short form of the macro.
Sorry the short form won't work, it's only for external functions written in C.
f4246ba3a7
toe34bf4fc36
@ -39,2 +41,4 @@
}
unsafe extern "C" fn linalg_try_invert_to(dim0: i64, dim1: i64, data: *mut f64) -> i8 {
// Provide an interface to nalgebra::linalg::try_invert_to
Obvious/trivial comment, remove.
@ -41,0 +47,4 @@
let mut inverted_matrix = DMatrix::<f64>::zeros(dim0 as usize, dim1 as usize);
if linalg::try_invert_to(matrix, &mut inverted_matrix) {
data_slice.copy_from_slice(inverted_matrix.transpose().as_slice());
transpose?
The
as_slice
function on nalgebra Matrix returns a column-major slice. The transpose is done to get the output in a form compatible (row-by-row) with NDValue.This is what should go in the code comments, not obvious stuff.
If the only change to nalgebra is the addition of
#![feature(const_fn, extended_key_value_attributes, array_methods)]
, can't we just use upstream and some rustc flags to enable those features?I doubt a patch with only that will be accepted upstream, it seems recent rustc has those features stabilized and they do not need gating.
Try setting the environment variable
RUSTFLAGS="-Z const_fn -Z extended_key_value_attributes -Z array_methods"
While adding
-Zextended_key_value_attributes
and-Zarray_methods
to the rust flags insrc/.cargo/config
works,-Zconst_fn
is already specified in some of the other libraries imported in zynq. This causes a double declaration error causes compilation to fail.What libraries and can it be removed from there so we can specify it in cargo?
Here are the first two libraries that have the feature
const_fn
enabled:The
libcortex_a9
b2b3e5c933/libcortex_a9/src/lib.rs (L4)
declares theconst_fn
flag.The
core_io
0320cb152d/src/lib.rs (L6)
crate also already specifies it.While
libcortex_a9
can be changed in the zynq-rs repo, forcore_io
we will need to fork the library and make changes similar to what we are doing fornalgebra
right now.e34bf4fc36
to8ad6fc8f41