Skip to content

Commit

Permalink
Faster conversion and bump crate version
Browse files Browse the repository at this point in the history
  • Loading branch information
ac-freeman committed Sep 9, 2024
1 parent f660475 commit 44c43bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "davis-edi-rs"
version = "0.2.5"
version = "0.2.6"
edition = "2021"
authors = ["Andrew C. Freeman"]
description = "A fast, Rust-based, open-source implementation of the paper \"Bringing a Blurry Frame Alive at High Frame-Rate with an Event Camera\" (2019) by Pan et al."
Expand Down
26 changes: 23 additions & 3 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use std::arch::x86_64::{_mm_loadu_pd, _mm_storeu_pd};
use nalgebra::{Dyn, OMatrix};
use opencv::core::{Mat, MatExprTraitConst, MatTrait, CV_64F};
use std::arch::x86_64::*;
use std::arch::x86_64::{_mm256_loadu_pd, _mm256_storeu_pd};



pub(crate) mod event_adder;
pub mod reconstructor;
Expand All @@ -10,9 +15,24 @@ fn omatrix_to_mat(omatrix: &OMatrix<f64, Dyn, Dyn>) -> Mat {
let cols = omatrix.ncols() as i32;
let mut mat = Mat::zeros(rows, cols, CV_64F).unwrap().to_mat().unwrap();

for i in 0..rows {
for j in 0..cols {
*mat.at_2d_mut::<f64>(i, j).unwrap() = omatrix[(i as usize, j as usize)];
unsafe {
let mat_ptr = mat.ptr_mut(0).unwrap() as *mut f64;
let omatrix_ptr = omatrix.transpose().as_slice().as_ptr();

let len = (rows * cols) as isize;
let simd_width = 4; // Number of f64 values processed per SIMD operation

let mut i = 0;
while i <= len - simd_width {
let data = _mm256_loadu_pd(omatrix_ptr.offset(i));
_mm256_storeu_pd(mat_ptr.offset(i), data);
i += simd_width;
}

// Handle remaining elements
while i < len {
*mat_ptr.offset(i) = *omatrix_ptr.offset(i);
i += 1;
}
}

Expand Down

0 comments on commit 44c43bf

Please sign in to comment.