Skip to content

RNG should not be static #2941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
laggui opened this issue Mar 21, 2025 · 0 comments
Open

RNG should not be static #2941

laggui opened this issue Mar 21, 2025 · 0 comments

Comments

@laggui
Copy link
Member

laggui commented Mar 21, 2025

Issue initially raised in #2923

pub(crate) static SEED: Mutex<Option<StdRng>> = Mutex::new(None);

pub(crate) static SEED: Mutex<Option<StdRng>> = Mutex::new(None);

After some discussions, the RNG should probably be per-device.

pub trait Backend {
    /// Device type.
    type Device: DeviceOps;

    /// Seed the backend device.
    fn seed(seed: u64, device: &Self::Device);
}

For ndarray specifically, given that the only device is CPU we can probably just make sure it is thread-local

thread_local! {
    pub(crate) static SEED: RefCell<Option<StdRng>> = RefCell::new(None);
}
@laggui laggui mentioned this issue Mar 27, 2025
2 tasks
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

No branches or pull requests

1 participant