From ef2fc31efaadbd8383bafea1d408d97dc126fc4f Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 30 Jan 2024 09:57:09 +0800 Subject: [PATCH] hyperbeam 0.7.1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- build.rs | 2 +- src/beam/fee.rs | 21 ++++++------------ src/beam/mod.rs | 55 +++++++++++++++++++++++++++++++---------------- src/beam/tests.rs | 5 ++++- 6 files changed, 50 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 209f2451..46b87391 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1464,9 +1464,9 @@ dependencies = [ [[package]] name = "mwa_hyperbeam" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "200571cea11982e303e663248228f1a05ed566b93626ec99c7a624b36e65159a" +checksum = "0ce1abd6525d18135eec831432a52f6c05fc0419af8ed499a1d911293328b394" dependencies = [ "cbindgen 0.25.0", "cc", diff --git a/Cargo.toml b/Cargo.toml index 443ef40b..fc6dc1ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ indicatif = { version = "0.17.5", features = ["rayon"] } lazy_static = "1.4.0" log = "0.4.0" marlu = { version = "0.10.1", features = ["serde"] } -mwa_hyperbeam = "0.6.0" +mwa_hyperbeam = "0.7.1" mwalib = "0.16.0" ndarray = { version = "0.15.4", features = ["rayon"] } num-complex = "0.4.1" diff --git a/build.rs b/build.rs index 939908a6..41e95d2f 100644 --- a/build.rs +++ b/build.rs @@ -218,7 +218,7 @@ mod gpu { match env::var("DEBUG").as_deref() { Ok("false") => (), - _ => gpu_target.flag("-ggdb"), + _ => {hip_target.flag("-ggdb");}, }; hip_target diff --git a/src/beam/fee.rs b/src/beam/fee.rs index 374ac3c0..713f0dfc 100644 --- a/src/beam/fee.rs +++ b/src/beam/fee.rs @@ -10,7 +10,7 @@ use log::debug; use marlu::{AzEl, Jones}; use ndarray::prelude::*; -use super::{Beam, BeamError, BeamType, Delays}; +use super::{partial_to_full, validate_delays, Beam, BeamError, BeamType, Delays}; #[cfg(any(feature = "cuda", feature = "hip"))] use super::{BeamGpu, DevicePointer, GpuFloat}; @@ -33,6 +33,8 @@ impl FEEBeam { gains: Option>, file: Option<&Path>, ) -> Result { + validate_delays(&delays, num_tiles)?; + let ideal_delays = delays.get_ideal_delays(); debug!("Ideal dipole delays: {:?}", ideal_delays); @@ -350,11 +352,11 @@ impl BeamGpu for FEEBeamGpu { } fn get_tile_map(&self) -> *const i32 { - self.hyperbeam_object.get_tile_map() + self.hyperbeam_object.get_device_tile_map() } fn get_freq_map(&self) -> *const i32 { - self.hyperbeam_object.get_freq_map() + self.hyperbeam_object.get_device_freq_map() } fn get_num_unique_tiles(&self) -> i32 { @@ -364,15 +366,4 @@ impl BeamGpu for FEEBeamGpu { fn get_num_unique_freqs(&self) -> i32 { self.hyperbeam_object.get_num_unique_freqs() } -} - -/// Assume that the dipole delays for all tiles is the same as the delays for -/// one tile. -fn partial_to_full(delays: Vec, num_tiles: usize) -> Array2 { - let mut out = Array2::zeros((num_tiles, 16)); - let d = Array1::from(delays); - out.outer_iter_mut().for_each(|mut tile_delays| { - tile_delays.assign(&d); - }); - out -} +} \ No newline at end of file diff --git a/src/beam/mod.rs b/src/beam/mod.rs index 8029d591..628a9f8e 100644 --- a/src/beam/mod.rs +++ b/src/beam/mod.rs @@ -415,25 +415,7 @@ pub fn create_beam_object( debug!("Setting up a FEE beam object"); // Check that the delays are sensible. - match &dipole_delays { - Delays::Partial(v) => { - if v.len() != 16 || v.iter().any(|&v| v > 32) { - return Err(BeamError::BadDelays); - } - } - - Delays::Full(a) => { - if a.len_of(Axis(1)) != 16 || a.iter().any(|&v| v > 32) { - return Err(BeamError::BadDelays); - } - if a.len_of(Axis(0)) != num_tiles { - return Err(BeamError::InconsistentDelays { - num_rows: a.len_of(Axis(0)), - num_tiles, - }); - } - } - } + validate_delays(&dipole_delays, num_tiles)?; // Set up the FEE beam struct from the `MWA_BEAM_FILE` environment // variable. @@ -445,3 +427,38 @@ pub fn create_beam_object( } } } + +/// Assume that the dipole delays for all tiles is the same as the delays for +/// one tile. +fn partial_to_full(delays: Vec, num_tiles: usize) -> Array2 { + let mut out = Array2::zeros((num_tiles, 16)); + let d = Array1::from(delays); + out.outer_iter_mut().for_each(|mut tile_delays| { + tile_delays.assign(&d); + }); + out +} + +fn validate_delays(delays: &Delays, num_tiles: usize) -> Result<(), BeamError> { + match delays { + Delays::Partial(v) => { + if v.len() != 16 || v.iter().any(|&v| v > 32) { + return Err(BeamError::BadDelays); + } + } + + Delays::Full(a) => { + if a.len_of(Axis(1)) != 16 || a.iter().any(|&v| v > 32) { + return Err(BeamError::BadDelays); + } + if a.len_of(Axis(0)) != num_tiles { + return Err(BeamError::InconsistentDelays { + num_rows: a.len_of(Axis(0)), + num_tiles, + }); + } + } + } + + Ok(()) +} \ No newline at end of file diff --git a/src/beam/tests.rs b/src/beam/tests.rs index 40b77c58..81c204ce 100644 --- a/src/beam/tests.rs +++ b/src/beam/tests.rs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use approx::{assert_abs_diff_eq, abs_diff_eq}; +use approx::assert_abs_diff_eq; use marlu::{constants::MWA_LAT_RAD, AzEl, Jones}; use mwa_hyperbeam::fee::FEEBeam; use ndarray::prelude::*; @@ -10,6 +10,9 @@ use serial_test::serial; use super::*; +#[cfg(any(feature = "cuda", feature = "hip"))] +use approx::abs_diff_eq; + #[test] fn no_beam_means_no_beam() { let azels = [