BioPhys-Neural-Agent / src /physics /kuramoto_sync.rs
minseok
๐ŸŒŒ Release BioPhys 6.0 Grand Master: 16GB (14.89GB) Gemma-4 100% Devour, Ecosystem Evolution, Solar MoE, SNN Autoregressive SDK, Dynamic PhaseVM
be99550
Raw
History Blame Contribute Delete
1.38 kB
use rayon::prelude::*;
pub trait SyncStrategy: Sync + Send {
fn apply_sync(packed_phase: u64, sync_pull: u64, mask_2bit: u64) -> u64;
}
pub struct PaletteAStrategy;
impl SyncStrategy for PaletteAStrategy {
#[inline(always)]
fn apply_sync(packed_phase: u64, sync_pull: u64, _mask: u64) -> u64 {
// `--1` ์ƒํƒœ(0b11)๋ฅผ ์ „์ฒด 32๊ฐœ ๋‰ด๋Ÿฐ์— ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๋น„ํŠธ ์—ฐ์‚ฐ ์ˆ˜์ •
let pull_11 = sync_pull | (sync_pull << 1);
(packed_phase & !pull_11) | pull_11
}
}
/// ์‹ฑ๊ธ€ ์Šค๋ ˆ๋“œ ๋™๊ธฐํ™” (๊ธฐ์กด)
pub fn synchronize_phases_fast<T: SyncStrategy>(packed_phases: &mut [u64], context_signal: u64) {
let mask_2bit = 0x5555555555555555;
for phase in packed_phases.iter_mut() {
let phase_difference = *phase ^ context_signal;
let sync_pull = (phase_difference & mask_2bit) >> 1;
*phase = T::apply_sync(*phase, sync_pull, mask_2bit);
}
}
/// [์‹ ๊ทœ] ๋ฉ€ํ‹ฐ์ฝ”์–ด CPU 100% ์ ์œ  ๋™๊ธฐํ™” (Rayon ์ ์šฉ)
pub fn synchronize_phases_par<T: SyncStrategy>(packed_phases: &mut [u64], context_signal: u64) {
let mask_2bit = 0x5555555555555555;
packed_phases.par_iter_mut().for_each(|phase| {
let phase_difference = *phase ^ context_signal;
let sync_pull = (phase_difference & mask_2bit) >> 1;
*phase = T::apply_sync(*phase, sync_pull, mask_2bit);
});
}