32#include <pybind11/complex.h>
36 auto &m = root_module;
38 py::module shamalgs_module = m.def_submodule(
"algs",
"algorithmic library");
40 py::class_<std::mt19937>(shamalgs_module,
"rng");
42 py::class_<shamalgs::impl_param>(shamalgs_module,
"impl_param")
48 &shamalgs::impl_param::impl_name,
49 py::return_value_policy::reference_internal)
51 "params", &shamalgs::impl_param::params, py::return_value_policy::reference_internal)
55 return shambase::format(
56 "impl_param(impl_name=\"{}\", params=\"{}\")",
61 return shambase::format(
62 "impl_param(impl_name=\"{}\", params=\"{}\")",
67 shamalgs_module.def(
"gen_seed", [](
u64 seed) {
68 return std::mt19937(seed);
71 shamalgs_module.def(
"mock_gaussian", [](std::mt19937 &eng) {
72 return shamalgs::random::mock_gaussian<f64>(eng);
74 shamalgs_module.def(
"mock_gaussian_f64_2", [](std::mt19937 &eng) {
75 return shamalgs::random::mock_gaussian_multidim<f64_2>(eng);
77 shamalgs_module.def(
"mock_gaussian_f64_3", [](std::mt19937 &eng) {
78 return shamalgs::random::mock_gaussian_multidim<f64_3>(eng);
80 shamalgs_module.def(
"mock_unit_vector_f64_3", [](std::mt19937 &eng) {
81 return shamalgs::random::mock_unit_vector<f64_3>(eng);
84 shamalgs_module.def(
"mock_buffer_f64", [](
u64 seed,
u32 len,
f64 min_bound,
f64 max_bound) {
85 return shamalgs::random::mock_buffer_usm<f64>(
86 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
88 shamalgs_module.def(
"mock_buffer_u8", [](
u64 seed,
u32 len,
u8 min_bound,
u8 max_bound) {
89 return shamalgs::random::mock_buffer_usm<u8>(
90 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
92 shamalgs_module.def(
"mock_buffer_u32", [](
u64 seed,
u32 len,
u32 min_bound,
u32 max_bound) {
93 return shamalgs::random::mock_buffer_usm<u32>(
94 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
97 "mock_buffer_f64_2", [](
u64 seed,
u32 len, f64_2 min_bound, f64_2 max_bound) {
98 return shamalgs::random::mock_buffer_usm<f64_2>(
99 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
102 "mock_buffer_f64_3", [](
u64 seed,
u32 len, f64_3 min_bound, f64_3 max_bound) {
103 return shamalgs::random::mock_buffer_usm<f64_3>(
104 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
124 "set_impl_is_all_true", [](
const std::string &impl,
const std::string ¶m =
"") {
128 shamalgs_module.def(
"get_current_impl_is_all_true", []() {
132 shamalgs_module.def(
"get_default_impl_list_is_all_true", []() {
140 shamsys::instance::get_compute_scheduler_ptr(), buf, start_id, end_id);
148 shamsys::instance::get_compute_scheduler_ptr(), buf, 0, len);
158 shamsys::instance::get_compute_scheduler_ptr(), buf, 0, len);
164 "set_impl_reduction", [](
const std::string &impl,
const std::string ¶m =
"") {
168 shamalgs_module.def(
"get_current_impl_reduction", []() {
172 shamalgs_module.def(
"get_default_impl_list_reduction", []() {
196 "set_impl_scan_exclusive_sum_in_place",
197 [](
const std::string &impl,
const std::string ¶m =
"") {
201 shamalgs_module.def(
"get_current_impl_scan_exclusive_sum_in_place", []() {
205 shamalgs_module.def(
"get_default_impl_list_scan_exclusive_sum_in_place", []() {
212 "segmented_sort_in_place",
214 shamalgs::primitives::segmented_sort_in_place(buf, offsets);
218 "benchmark_segmented_sort_in_place",
220 auto buf_copy = buf.
copy();
221 auto offsets_copy = offsets.
copy();
223 buf_copy.synchronize();
224 offsets_copy.synchronize();
229 shamalgs::primitives::segmented_sort_in_place(buf_copy, offsets_copy);
230 buf_copy.synchronize();
231 offsets_copy.synchronize();
238 "set_impl_segmented_sort_in_place",
239 [](
const std::string &impl,
const std::string ¶m =
"") {
243 shamalgs_module.def(
"get_current_impl_segmented_sort_in_place", []() {
247 shamalgs_module.def(
"get_default_impl_list_segmented_sort_in_place", []() {
252 py::class_<shamalgs::primitives::ImplControl>(shamalgs_module,
"ImplControl")
256 return impl_control.get_alg_name();
261 return impl_control.was_configured(shamsys::instance::get_compute_scheduler_ptr());
266 return impl_control.get_config(shamsys::instance::get_compute_scheduler_ptr());
271 impl_control.set_config(shamsys::instance::get_compute_scheduler_ptr(), config);
274 "get_default_config",
276 return impl_control.get_default_config(
277 shamsys::instance::get_compute_scheduler_ptr());
280 return impl_control.get_avail_configs(shamsys::instance::get_compute_scheduler_ptr());
284 "compute_histogram_impl",
286 return shamalgs::primitives::impl::compute_histogram_impl_control;
288 py::return_value_policy::reference);
291 "compute_histogram_basic_f64",
295 return shamalgs::primitives::compute_histogram_basic<f64>(
296 shamsys::instance::get_compute_scheduler_ptr(),
302 "compute_histogram_basic_f32",
306 return shamalgs::primitives::compute_histogram_basic<f32>(
307 shamsys::instance::get_compute_scheduler_ptr(),
314 "benchmark_compute_histogram_basic_f64",
323 auto result = shamalgs::primitives::compute_histogram_basic<f64>(
324 shamsys::instance::get_compute_scheduler_ptr(),
328 result.synchronize();
336 "benchmark_compute_histogram_basic_f32",
345 auto result = shamalgs::primitives::compute_histogram_basic<f32>(
346 shamsys::instance::get_compute_scheduler_ptr(),
350 result.synchronize();
360 [](
const std::vector<std::string> &inputs, std::string delimiter,
bool hash_based) {
364 py::arg(
"delimiter") =
"\n",
365 py::arg(
"hash_based") =
false);
368 "all_string_histogram",
369 [](
const std::vector<std::string> &inputs, std::string delimiter,
bool hash_based) {
371 inputs, std::move(delimiter), hash_based);
374 py::arg(
"delimiter") =
"\n",
375 py::arg(
"hash_based") =
false);
Header file describing a Node Instance.
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
A buffer allocated in USM (Unified Shared Memory).
void synchronize() const
Wait for all the events associated with the buffer to be completed.
DeviceBuffer< T, target > copy() const
Copy the current buffer.
Class Timer measures the time elapsed since the timer was started.
f64 elapsed_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
void start()
Starts the timer.
void stop()
Stops the timer and stores the elapsed time in nanoseconds.
Boolean reduction algorithm for checking if all elements are non-zero.
std::vector< shamalgs::impl_param > get_default_impl_list_segmented_sort_in_place()
Get list of available segmented sort in place implementations.
void set_impl_reduction(const std::string &impl, const std::string ¶m="")
Set the implementation for reduction.
std::vector< shamalgs::impl_param > get_default_impl_list_reduction()
Get list of available reduction implementations.
std::vector< shamalgs::impl_param > get_default_impl_list_scan_exclusive_sum_in_place()
Get list of available scan_exclusive_sum_in_place implementations.
void set_impl_segmented_sort_in_place(const std::string &impl, const std::string ¶m="")
Set the implementation for segmented sort in place.
void set_impl_is_all_true(const std::string &impl, const std::string ¶m="")
Set the implementation for is_all_true.
shamalgs::impl_param get_current_impl_scan_exclusive_sum_in_place()
Get the current implementation for scan_exclusive_sum_in_place.
shamalgs::impl_param get_current_impl_segmented_sort_in_place()
Get the current implementation for segmented sort in place.
shamalgs::impl_param get_current_impl_reduction()
Get the current implementation for reduction.
void set_impl_scan_exclusive_sum_in_place(const std::string &impl, const std::string ¶m="")
Set the implementation for scan_exclusive_sum_in_place.
std::vector< shamalgs::impl_param > get_default_impl_list_is_all_true()
Get list of available is_all_true implementations.
shamalgs::impl_param get_current_impl_is_all_true()
Get the current implementation for is_all_true.
T sum(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Compute the sum of elements in a device buffer within a specified range.
bool is_all_true(sycl::buffer< T > &buf, u32 cnt)
Check if all elements in a sycl::buffer are non-zero.
void scan_exclusive_sum_in_place(sham::DeviceBuffer< T > &buf1, u32 len)
Compute exclusive prefix sum in-place on a device buffer.
f64 timeitfor(Func &&f, f64 max_duration=1)
Measures the average time it takes to execute a function until a maximum duration is reached.
Pybind11 include and definitions.
#define ON_PYTHON_INIT
Register a Python module init function using static initialization.
In-place exclusive scan (prefix sum) algorithm for device buffers.
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
std::unordered_map< std::string, int > string_histogram(const std::vector< std::string > &inputs, std::string delimiter, bool hash_based)
Constructs a histogram from a vector of strings, counting occurrences of each unique string.
std::unordered_map< std::string, int > all_string_histogram(const std::vector< std::string > &inputs, std::string delimiter, bool hash_based)
same as string_histogram but with result return on every rank