34#include <pybind11/complex.h>
38 auto &m = root_module;
40 py::module shamalgs_module = m.def_submodule(
"algs",
"algorithmic library");
42 py::class_<std::mt19937>(shamalgs_module,
"rng");
44 py::class_<shamalgs::impl_param>(shamalgs_module,
"impl_param")
50 &shamalgs::impl_param::impl_name,
51 py::return_value_policy::reference_internal)
53 "params", &shamalgs::impl_param::params, py::return_value_policy::reference_internal)
58 "impl_param(impl_name=\"{}\", params=\"{}\")",
64 "impl_param(impl_name=\"{}\", params=\"{}\")",
69 shamalgs_module.def(
"gen_seed", [](
u64 seed) {
70 return std::mt19937(seed);
73 shamalgs_module.def(
"mock_gaussian", [](std::mt19937 &eng) {
74 return shamalgs::random::mock_gaussian<f64>(eng);
76 shamalgs_module.def(
"mock_gaussian_f64_2", [](std::mt19937 &eng) {
77 return shamalgs::random::mock_gaussian_multidim<f64_2>(eng);
79 shamalgs_module.def(
"mock_gaussian_f64_3", [](std::mt19937 &eng) {
80 return shamalgs::random::mock_gaussian_multidim<f64_3>(eng);
82 shamalgs_module.def(
"mock_unit_vector_f64_3", [](std::mt19937 &eng) {
83 return shamalgs::random::mock_unit_vector<f64_3>(eng);
86 shamalgs_module.def(
"mock_buffer_f64", [](
u64 seed,
u32 len,
f64 min_bound,
f64 max_bound) {
87 return shamalgs::random::mock_buffer_usm<f64>(
88 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
90 shamalgs_module.def(
"mock_buffer_u8", [](
u64 seed,
u32 len,
u8 min_bound,
u8 max_bound) {
91 return shamalgs::random::mock_buffer_usm<u8>(
92 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
94 shamalgs_module.def(
"mock_buffer_u32", [](
u64 seed,
u32 len,
u32 min_bound,
u32 max_bound) {
95 return shamalgs::random::mock_buffer_usm<u32>(
96 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
99 "mock_buffer_f64_2", [](
u64 seed,
u32 len, f64_2 min_bound, f64_2 max_bound) {
100 return shamalgs::random::mock_buffer_usm<f64_2>(
101 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
104 "mock_buffer_f64_3", [](
u64 seed,
u32 len, f64_3 min_bound, f64_3 max_bound) {
105 return shamalgs::random::mock_buffer_usm<f64_3>(
106 shamsys::instance::get_compute_scheduler_ptr(), seed, len, min_bound, max_bound);
125 shamalgs_module.def(
"set_impl_is_all_true", [](
const std::string &impl) {
129 shamalgs_module.def(
"get_current_impl_is_all_true", []() {
133 shamalgs_module.def(
"get_default_impl_list_is_all_true", []() {
137 shamalgs_module.def(
"is_impl_set_is_all_true", []() {
141 shamalgs_module.def(
"autoselect_impl_is_all_true", []() {
143 shamsys::instance::get_compute_scheduler_ptr());
150 shamsys::instance::get_compute_scheduler_ptr(), buf, start_id, end_id);
158 shamsys::instance::get_compute_scheduler_ptr(), buf, 0, len);
168 shamsys::instance::get_compute_scheduler_ptr(), buf, 0, len);
173 shamalgs_module.def(
"set_impl_reduction", [](
const std::string &impl) {
177 shamalgs_module.def(
"get_current_impl_reduction", []() {
181 shamalgs_module.def(
"get_default_impl_list_reduction", []() {
185 shamalgs_module.def(
"is_impl_set_reduction", []() {
189 shamalgs_module.def(
"autoselect_impl_reduction", []() {
191 shamsys::instance::get_compute_scheduler_ptr());
213 shamalgs_module.def(
"set_impl_scan_exclusive_sum_in_place", [](
const std::string &impl) {
217 shamalgs_module.def(
"get_current_impl_scan_exclusive_sum_in_place", []() {
221 shamalgs_module.def(
"get_default_impl_list_scan_exclusive_sum_in_place", []() {
225 shamalgs_module.def(
"is_impl_set_scan_exclusive_sum_in_place", []() {
229 shamalgs_module.def(
"autoselect_impl_scan_exclusive_sum_in_place", []() {
231 shamsys::instance::get_compute_scheduler_ptr());
237 "segmented_sort_in_place",
239 shamalgs::primitives::segmented_sort_in_place(buf, offsets);
243 "benchmark_segmented_sort_in_place",
245 auto buf_copy = buf.
copy();
246 auto offsets_copy = offsets.
copy();
248 buf_copy.synchronize();
249 offsets_copy.synchronize();
254 shamalgs::primitives::segmented_sort_in_place(buf_copy, offsets_copy);
255 buf_copy.synchronize();
256 offsets_copy.synchronize();
262 shamalgs_module.def(
"set_impl_segmented_sort_in_place", [](
const std::string &impl) {
266 shamalgs_module.def(
"get_current_impl_segmented_sort_in_place", []() {
270 shamalgs_module.def(
"get_default_impl_list_segmented_sort_in_place", []() {
283 "benchmark_sort_by_keys",
285 auto buf_key_copy = buf_key.
copy();
286 auto buf_values_copy = buf_values.
copy();
288 buf_key_copy.synchronize();
289 buf_values_copy.synchronize();
295 buf_key_copy.synchronize();
296 buf_values_copy.synchronize();
302 shamalgs_module.def(
"set_impl_sort_by_keys", [](
const std::string &impl) {
306 shamalgs_module.def(
"get_current_impl_sort_by_keys", []() {
310 shamalgs_module.def(
"get_default_impl_list_sort_by_keys", []() {
314 shamalgs_module.def(
"is_impl_set_sort_by_keys", []() {
318 shamalgs_module.def(
"autoselect_impl_sort_by_keys", []() {
320 shamsys::instance::get_compute_scheduler_ptr());
326 "sort_by_key_pow2_len",
329 shamsys::instance::get_compute_scheduler_ptr(), buf_key, buf_values, len);
333 "benchmark_sort_by_key_pow2_len",
335 auto buf_key_copy = buf_key.
copy();
336 auto buf_values_copy = buf_values.
copy();
338 buf_key_copy.synchronize();
339 buf_values_copy.synchronize();
345 shamsys::instance::get_compute_scheduler_ptr(),
349 buf_key_copy.synchronize();
350 buf_values_copy.synchronize();
356 shamalgs_module.def(
"set_impl_sort_by_key_pow2_len", [](
const std::string &impl) {
360 shamalgs_module.def(
"get_current_impl_sort_by_key_pow2_len", []() {
364 shamalgs_module.def(
"get_default_impl_list_sort_by_key_pow2_len", []() {
368 shamalgs_module.def(
"is_impl_set_sort_by_key_pow2_len", []() {
372 shamalgs_module.def(
"autoselect_impl_sort_by_key_pow2_len", []() {
374 shamsys::instance::get_compute_scheduler_ptr());
380 shamalgs_module.def(
"set_impl_compute_histogram", [](
const std::string &impl) {
384 shamalgs_module.def(
"get_current_impl_compute_histogram", []() {
388 shamalgs_module.def(
"get_default_impl_list_compute_histogram", []() {
392 shamalgs_module.def(
"is_impl_set_compute_histogram", []() {
396 shamalgs_module.def(
"autoselect_impl_compute_histogram", []() {
398 shamsys::instance::get_compute_scheduler_ptr());
403 "compute_histogram_basic_f64",
407 return shamalgs::primitives::compute_histogram_basic<f64>(
408 shamsys::instance::get_compute_scheduler_ptr(),
414 "compute_histogram_basic_f32",
418 return shamalgs::primitives::compute_histogram_basic<f32>(
419 shamsys::instance::get_compute_scheduler_ptr(),
426 "benchmark_compute_histogram_basic_f64",
435 auto result = shamalgs::primitives::compute_histogram_basic<f64>(
436 shamsys::instance::get_compute_scheduler_ptr(),
440 result.synchronize();
448 "benchmark_compute_histogram_basic_f32",
457 auto result = shamalgs::primitives::compute_histogram_basic<f32>(
458 shamsys::instance::get_compute_scheduler_ptr(),
462 result.synchronize();
472 [](
const std::vector<std::string> &inputs, std::string delimiter,
bool hash_based) {
476 py::arg(
"delimiter") =
"\n",
477 py::arg(
"hash_based") =
false);
480 "all_string_histogram",
481 [](
const std::vector<std::string> &inputs, std::string delimiter,
bool hash_based) {
483 inputs, std::move(delimiter), hash_based);
486 py::arg(
"delimiter") =
"\n",
487 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< std::string > get_default_impl_list_sort_by_key_pow2_len()
Get list of available sort by key pow2 len implementations, as config json strings.
void autoselect_impl_sort_by_key_pow2_len(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for sort by key pow2 len.
std::vector< std::string > get_default_impl_list_sort_by_keys()
Get list of available sort by keys implementations, as config json strings.
bool is_impl_set_is_all_true()
Check if an implementation has been selected for is_all_true.
void set_impl_segmented_sort_in_place(const std::string &impl)
Set the implementation for segmented sort in place, from a config json string.
bool is_impl_set_reduction()
Check if an implementation has been selected for reduction.
std::string get_current_impl_sort_by_keys()
Get the current implementation for sort by keys, as a config json string.
void autoselect_impl_reduction(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for reduction.
std::string get_current_impl_reduction()
Get the current implementation for reduction, as a config json string.
void autoselect_impl_compute_histogram(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for compute_histogram.
std::string get_current_impl_segmented_sort_in_place()
Get the current implementation for segmented sort in place, as a config json string.
void set_impl_compute_histogram(const std::string &impl)
Set the implementation for compute_histogram.
std::vector< std::string > get_default_impl_list_scan_exclusive_sum_in_place()
Get list of available scan_exclusive_sum_in_place implementations.
bool is_impl_set_scan_exclusive_sum_in_place()
Check if an implementation has been selected for scan_exclusive_sum_in_place.
std::string get_current_impl_sort_by_key_pow2_len()
Get the current implementation for sort by key pow2 len, as a config json string.
void autoselect_impl_sort_by_keys(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for sort by keys.
bool is_impl_set_sort_by_key_pow2_len()
Check if an implementation has been selected for sort by key pow2 len.
void set_impl_scan_exclusive_sum_in_place(const std::string &impl)
Set the implementation for scan_exclusive_sum_in_place, from a config json string.
std::string get_current_impl_compute_histogram()
Get the current implementation for compute_histogram.
std::vector< std::string > get_default_impl_list_compute_histogram()
Get list of available compute_histogram implementations.
void set_impl_sort_by_keys(const std::string &impl)
Set the implementation for sort by keys, from a config json string.
bool is_impl_set_sort_by_keys()
Check if an implementation has been selected for sort by keys.
void autoselect_impl_is_all_true(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for is_all_true.
void set_impl_is_all_true(const std::string &impl)
Set the implementation for is_all_true, from a config json string.
std::vector< std::string > get_default_impl_list_reduction()
Get list of available reduction implementations, as config json strings.
void set_impl_sort_by_key_pow2_len(const std::string &impl)
Set the implementation for sort by key pow2 len, from a config json string.
void autoselect_impl_scan_exclusive_sum_in_place(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for scan_exclusive_sum_in_place.
std::string get_current_impl_scan_exclusive_sum_in_place()
Get the current implementation for scan_exclusive_sum_in_place.
bool is_impl_set_compute_histogram()
Check if an implementation has been selected for compute_histogram.
void set_impl_reduction(const std::string &impl)
Set the implementation for reduction, from a config json string.
std::string get_current_impl_is_all_true()
Get the current implementation for is_all_true, as a config json string.
std::vector< std::string > get_default_impl_list_is_all_true()
Get list of available is_all_true implementations, as config json strings.
std::vector< std::string > get_default_impl_list_segmented_sort_in_place()
Get list of available segmented sort in place implementations, as config json strings.
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.
void sort_by_keys(sham::DeviceBuffer< Tkey > &buf_key, sham::DeviceBuffer< Tval > &buf_values, u32 len)
Sort key-value pairs using USM buffers (general length).
bool is_all_true(sycl::buffer< T > &buf, u32 cnt)
Check if all elements in a sycl::buffer are non-zero.
void sort_by_key_pow2_len(sycl::queue &q, sycl::buffer< Tkey > &buf_key, sycl::buffer< Tval > &buf_values, u32 len)
Sort key-value pairs using sycl::buffers (power-of-2 optimized).
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