Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
random.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
18#include "shamalgs/memory.hpp"
20
21namespace shamalgs::random {
22
23 template<class T>
24 sycl::buffer<T> mock_buffer(u64 seed, u32 len, T min_bound, T max_bound) {
26 shamalgs::primitives::mock_vector(seed, len, min_bound, max_bound));
27 }
28
29 template<class T>
30 sham::DeviceBuffer<T> mock_buffer_usm(
31 const sham::DeviceScheduler_ptr &sched, u64 seed, u32 len, T min_bound, T max_bound) {
32 auto vec = shamalgs::primitives::mock_vector(seed, len, min_bound, max_bound);
33 sham::DeviceBuffer<T> ret(len, sched);
34 ret.copy_from_stdvec(vec);
35 return ret;
36 }
37
38#ifndef DOXYGEN
39 #define X(_arg_) \
40 template sycl::buffer<_arg_> mock_buffer( \
41 u64 seed, u32 len, _arg_ min_bound, _arg_ max_bound); \
42 template sham::DeviceBuffer<_arg_> mock_buffer_usm( \
43 const sham::DeviceScheduler_ptr &sched, \
44 u64 seed, \
45 u32 len, \
46 _arg_ min_bound, \
47 _arg_ max_bound);
48
49 X(f32);
50 X(f32_2);
51 X(f32_3);
52 X(f32_4);
53 X(f32_8);
54 X(f32_16);
55 X(f64);
56 X(f64_2);
57 X(f64_3);
58 X(f64_4);
59 X(f64_8);
60 X(f64_16);
61 X(u8);
62 X(u32);
63 X(u32_2);
64 X(u32_3);
65 X(u32_4);
66 X(u32_8);
67 X(u32_16);
68 X(u64);
69 X(u64_2);
70 X(u64_3);
71 X(u64_4);
72 X(u64_8);
73 X(u64_16);
74 X(i64_3);
75 X(i64);
76#endif
77
78} // namespace shamalgs::random
double f64
Alias for double.
float f32
Alias for float.
std::uint8_t u8
8 bit unsigned integer
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int64_t i64
64 bit integer
A buffer allocated in USM (Unified Shared Memory)
Utility functions for generating random mock vectors.
sycl::buffer< T > vec_to_buf(const std::vector< T > &buf)
Convert a std::vector to a sycl::buffer
Definition memory.cpp:29
std::vector< T > mock_vector(u64 seed, u32 len, T min_bound, T max_bound)
Generates a vector of random mock values within specified bounds.
namespace to contain utility related to random number generation in shamalgs
Definition random.hpp:33
main include file for memory algorithms