![]() |
Shamrock 2025.10.0
Astrophysical Code
|
namespace for basic c++ utilities More...
Namespaces | |
| namespace | logs |
| Namespace containing logs utils. | |
Typedefs | |
| template<class T > | |
| using | VectorProperties = sham::VectorProperties< T > |
| template<class T > | |
| using | VecComponent = sham::VecComponent< T > |
| using | exception_gen_callback_t = void(*)(std::string msg) |
| type of the exception generator callback | |
| template<class T > | |
| using | formatter = fmt::formatter< T > |
Formatter alias for fmt::formatter | |
| template<typename T > | |
| using | opt_ref = std::optional< std::reference_wrapper< T > > |
| Optional reference wrapper. | |
| using | printer_t = void(*)(std::string_view) |
| using | flush_t = void(*)() |
Enumerations | |
| enum | ParallelForWrapMode { PARALLEL_FOR , PARALLEL_FOR_ROUND , ND_RANGE } |
Functions | |
| template<class T , int n, std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| i32 | any (sycl::vec< T, n > v) |
| Fallback function for sycl::any SYCL std : Returns 1 if the most significant bit in any component of x is set; otherwise returns 0. if it is something else than the most significant bit it is UB. | |
| template<class T > | |
| void | check_buffer_size (sycl::buffer< T > &buf, u64 max_range, const SourceLocation loc=SourceLocation()) |
| check that the size of a sycl buffer is below or equal to the value of max range throw if it is not the case | |
| std::string | getDevice_type (const sycl::device &Device) |
| Get the Device Type Name. | |
| sycl::nd_range< 1 > | make_range (u32 length, const u32 group_size=32) |
| Generate a sycl nd range out of a group size and length. | |
| template<u32 group_size = default_gsize, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel > | |
| void | parallel_for (sycl::handler &cgh, u32 length, const char *name, LambdaKernel &&ker) |
| template<u32 group_size = default_gsize_2d, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel > | |
| void | parallel_for_2d (sycl::handler &cgh, u32 length_x, u32 length_y, const char *name, LambdaKernel &&ker) |
| template<u32 group_size = default_gsize_3d, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel > | |
| void | parallel_for_3d (sycl::handler &cgh, u32 length_x, u32 length_y, u32 length_z, const char *name, LambdaKernel &&ker) |
| template<ParallelForWrapMode mode = default_loop_mode, class LambdaKernel > | |
| void | parallel_for_gsize (sycl::handler &cgh, u32 length, u32 group_size, const char *name, LambdaKernel &&ker) |
| void | check_queue_state (sycl::queue &q, SourceLocation loc=SourceLocation()) |
| template<class T , class Comp > | |
| void | ptr_insert_sort (T *data, u32 start, u32 end, Comp &&comp) |
| Simple insertion sort on pointer range. | |
| template<class T , int ArrSize, class Comp > | |
| void | odd_even_transpose_sort_segment_flags (T *data, const u8 *segment_boundary, Comp comp) |
| Odd-even transpose sort with segment boundaries. | |
| template<class T > | |
| void | stream_write (std::basic_stringstream< byte > &stream, T &obj) |
| template<class T > | |
| void | stream_read (std::basic_stringstream< byte > &stream, T &obj) |
| void | stream_write_string (std::basic_stringstream< byte > &stream, std::string &s) |
| void | stream_read_string (std::basic_stringstream< byte > &stream, std::string &s) |
| template<class T > | |
| void | stream_write_vector (std::basic_stringstream< byte > &stream, std::vector< T > &vec) |
| write the vector into the bytestream | |
| template<class T > | |
| void | stream_read_vector (std::basic_stringstream< byte > &stream, std::vector< T > &vec) |
| read a vector from the bytestream Note : this appends read objects to the vector without resetting it | |
| template<class T > | |
| void | stream_write_vector_trivial (std::basic_stringstream< byte > &stream, std::vector< T > &vec) |
| template<class T > | |
| void | stream_read_vector_trivial (std::basic_stringstream< byte > &stream, std::vector< T > &vec) |
| read a vector from the bytestream Note : this appends read objects to the vector without resetting it | |
| u64 | fnv1a_hash (const char *data, size_t size) |
| Compute the FNV-1a hash of a given data. | |
| template<class T1 , class FuncMatch , class FuncMissing , class FuncExtra > | |
| void | on_distributeddata_ids_diff (const shambase::DistributedData< T1 > &dd, const std::vector< u64 > &ref_ids, FuncMatch &&func_missing, FuncMissing &&func_match, FuncExtra &&func_extra) |
| Compare two distributed data and apply callbacks based on the difference. | |
| template<class T1 , class T2 , class FuncMatch , class FuncMissing , class FuncExtra > | |
| void | on_distributeddata_diff (const shambase::DistributedData< T1 > &dd, const shambase::DistributedData< T2 > &reference, FuncMatch &&func_missing, FuncMissing &&func_match, FuncExtra &&func_extra) |
| Compare two distributed data and apply callbacks based on the difference. | |
| bool | is_little_endian () |
| Check if the CPU is in little endian. | |
| template<class T > | |
| void | endian_swap (T &a) |
| Swap the endianness of the input value. | |
| template<class T > | |
| T | get_endian_swap (T a) |
| Return a copy of the input value with the endianness swapped. | |
| std::string | exception_format (SourceLocation loc) |
| Format the exception message with the source location information. | |
| void | set_exception_gen_callback (exception_gen_callback_t callback) |
| Set the exception generator callback. | |
| exception_gen_callback_t | get_exception_gen_callback () |
| Get the current exception generator callback. | |
| void | exception_gen_callback (std::string msg) |
| The callback called when an exception is thrown. | |
| template<class ExcptTypes > | |
| ExcptTypes | make_except_with_loc (std::string message, SourceLocation loc=SourceLocation{}) |
| Create an exception with a message and a location. | |
| template<class ExcptTypes > | |
| void | throw_with_loc (std::string message, SourceLocation loc=SourceLocation{}) |
| Throw an exception and append the source location to it. | |
| void | throw_unimplemented (SourceLocation loc=SourceLocation{}) |
| Throw a std::runtime_error saying that the function is unimplemented. | |
| void | throw_unimplemented (std::string message, SourceLocation loc=SourceLocation{}) |
| Throw a std::runtime_error with a message saying that the function is unimplemented. | |
| template<class exception_type > | |
| exception_type | make_except_with_loc_with_ctx (std::string message, context ctx, SourceLocation loc=SourceLocation{}) |
| Make an exception with a message and variadic context groups. | |
| template<i32 power, class T > | |
| constexpr T | pow_constexpr_fast_inv (T a, T a_inv) noexcept |
| FortranIOFile | load_fortran_file (const std::string &fname) |
| Load a Fortran formatted file from disk. | |
| template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| constexpr bool | is_pow_of_two_fast (T v) noexcept |
| determine if v is a power of two Warning : this function return true if v == 0 Source : https://graphics.stanford.edu/~seander/bithacks.html | |
| template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| constexpr bool | is_pow_of_two (T v) noexcept |
| determine if v is a power of two and check if v==0 Source : https://graphics.stanford.edu/~seander/bithacks.html | |
| template<class T , std::enable_if_t< std::is_integral_v< T >||std::is_signed_v< T >, int > = 0> | |
| constexpr bool | sign_differ (T a, T b) noexcept |
| check if the sign of the two integers differs Source : https://graphics.stanford.edu/~seander/bithacks.html | |
| template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| void | xor_swap (T &a, T &b) |
| swap two values using xor Source : https://graphics.stanford.edu/~seander/bithacks.html | |
| template<class T , std::enable_if_t< std::is_integral_v< T >||(!std::is_signed_v< T >), int > = 0> | |
| constexpr T | roundup_pow2 (T v) noexcept |
| round up to the next power of two Source : https://graphics.stanford.edu/~seander/bithacks.html | |
| constexpr u32 | group_count (u32 len, u32 group_size) |
| Calculates the number of groups based on the length and group size. | |
| template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| T | select_bit (T value, T bitnum) |
| Selects and returns the bit at a specific position in the given value. | |
| template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| constexpr T | most_sig_bit_mask () noexcept |
| Generates a mask with only the most significant bit set. | |
| template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0> | |
| constexpr bool | is_most_sig_bit_set (const T x) noexcept |
| Checks if the most significant bit is set in the given value. | |
| template<i32 power, class T > | |
| constexpr T | pow_constexpr (T a) noexcept |
| Calculates the power of a number at compile time. | |
| template<u32 flag> | |
| constexpr bool | is_flag_on (u32 val) |
| template<class T , class AccU8 > | |
| void | store_u8 (AccU8 &acc, u64 idx_write, T a) |
| Store a value of type T in a byte buffer. | |
| template<class T , class AccU8 > | |
| T | load_u8 (AccU8 &acc, u64 ptr_load) |
| load a value of type T from a byte buffer | |
| template<class T , class TAcc > | |
| void | store_conv (TAcc *acc, T a) |
| pointer cast store the value | |
| template<class T , class TAcc > | |
| T | load_conv (TAcc *acc) |
| pointer cast load from a pointer | |
| template<class T > | |
| T & | get_check_ref (const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation()) |
| Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::unique_ptr does not hold anything. | |
| template<class T > | |
| T & | get_check_ref (const std::shared_ptr< T > &ptr, SourceLocation loc=SourceLocation()) |
| Takes a std::shared_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::shared_ptr does not hold anything. | |
| template<class T > | |
| const T & | get_check_ref (const std::optional< T > &ptr, SourceLocation loc=SourceLocation()) |
| Get reference to object held by the unique ptr, and throw if nothing is held. | |
| template<class T > | |
| T & | get_check_ref (std::optional< T > &ptr, SourceLocation loc=SourceLocation()) |
| Same overload but for non const case. | |
| template<class T > | |
| T & | get_check_ref (T *ptr, SourceLocation loc=SourceLocation()) |
| Takes a raw pointer and returns a reference to the object it points to. It throws a std::runtime_error if the pointer is null. | |
| template<class T > | |
| const T & | get_check_ref (const T *ptr, SourceLocation loc=SourceLocation()) |
| same overload but for const pointer | |
| template<typename T > | |
| auto | extract_value (std::optional< T > &o, SourceLocation loc=SourceLocation()) -> T |
| Extracts the content out of an optional. | |
| template<typename T > | |
| auto | extract_pointer (std::unique_ptr< T > &o, SourceLocation loc=SourceLocation()) -> T |
| extract content out of unique_ptr | |
| template<int n, class T > | |
| std::array< T, n > | convert_to_array (std::vector< T > &in) |
| Convert a vector to an array of size n. | |
| template<class U , class T > | |
| constexpr bool | can_narrow (T val) |
| Check if an integer value can be safely narrowed to a target type. | |
| template<class U , class T > | |
| U | narrow_or_throw (T val, SourceLocation &&callsite=SourceLocation{}) |
| template<class T > | |
| constexpr T | get_max () |
| template<class T > | |
| constexpr T | get_min () |
| template<class T > | |
| constexpr T | get_epsilon () |
| template<class T > | |
| constexpr T | get_infty () |
| std::string | popen_fetch_output (const char *command) |
| Run a command and return the output. | |
| void | print (std::string_view sv) |
| Prints a string to the console. | |
| void | println (std::string_view sv) |
| Prints a string to the console followed by a newline. | |
| void | flush () |
| Flushes the output buffer. | |
| void | change_printer (void(*func_printer_normal)(std::string_view), void(*func_printer_ln)(std::string_view), void(*func_flush_func)()) |
| Changes the behavior of the print, println and flush functions. | |
| void | reset_std_behavior () |
| Restores the default behavior of the print and println functions. | |
| bool | is_aligned (const void *ptr, size_t alignment) noexcept |
| Check if a pointer is aligned with the given alignment. | |
| template<class T > | |
| bool | is_aligned (const void *ptr) noexcept |
| Check if a pointer is aligned with the given type. | |
| template<class T , class Container1 , class Container2 > | |
| void | set_diff (Container1 &c1, Container2 &ref, std::vector< T > &missing, std::vector< T > &matching, std::vector< T > &extra) |
| Compute the difference between two containers as three separate vectors. | |
| std::string | fmt_callstack () |
| Get the formatted callstack. | |
| void | set_callstack_process_identifier (std::string identifier) |
| void | add_callstack_gen_info_generator (std::string(*generator)()) |
| template<class T > | |
| std::vector< T > | vector_from_set (const std::set< T > &in) |
| template<class T > | |
| std::set< T > | set_from_vector (const std::vector< T > &in) |
| template<class K , class T > | |
| std::vector< K > | keys_from_map (const std::unordered_map< K, T > &in) |
| __attribute__ ((always_inline)) auto vformat(std | |
| format a string using fmtlib style Cheat sheet : https://hackingcpp.com/cpp/libs/fmt.html | |
| template<class It , typename... Tformat> | |
| std::string | format_array (const It &iter, u32 len, u32 column_count, fmt::format_string< Tformat... > fmt) |
| Format an array of elements into a string. | |
| std::string | readable_sizeof (double size) |
| given a sizeof value return a readble string Example : readable_sizeof(1024*1024*1024) -> "1.00 GB" | |
| void | write_string_to_file (std::string filename, std::string s) |
| dump a string to a file | |
| void | replace_all (std::string &inout, std::string_view what, std::string_view with) |
| replace all occurence of a search string with another | |
| std::string | increase_indent (std::string in, std::string delim="\n ") |
| Increase indentation of a string. | |
| std::string | trunc_str (std::string s, u32 max_len) |
| Truncate a string to a specified length, adding an ellipsis if necessary. | |
| std::string | trunc_str_start (std::string s, u32 max_len) |
| Truncate a string to a specified length, adding an ellipsis at the start if necessary. | |
| bool | contain_substr (std::string str, std::string what) |
| Check if a substring is present in a given string. | |
| std::string | shorten_string (std::string str, u32 len) |
| Shortens a string by removing the last specified number of characters. | |
| std::vector< std::string > | split_str (std::string s, std::string delimiter) |
| Splits a string into a vector of substrings according to a delimiter. | |
| std::string | nanosec_to_time_str (double nanosec) |
| Convert nanoseconds to a human-readable string representation. | |
| template<class Func > | |
| f64 | timeit (Func &&f, u32 relaunch=1) |
| Measures the average time it takes to execute a function. | |
| template<class Func > | |
| f64 | timeitfor (Func &&f, f64 max_duration=1) |
| Measures the average time it takes to execute a function until a maximum duration is reached. | |
| BenchmarkResult | benchmark_pow_len (std::function< f64(u32)> func, u32 start, u32 end, f64 pow_exp) |
| Benchmark a function with input values following a power law. | |
| template<class T > | |
| std::string | get_type_name () |
| template<class signature , class Func > | |
| constexpr void | check_functor_nocapture (Func &&func) |
| Check if a lambda or a function has the correct signature. | |
| template<class RetType , class... Targ, class Func > | |
| constexpr void | check_functor_nocapture_deduce (Func &&func, Targ...) |
| Check if a callable object has the correct deduced signature. | |
| template<class RetType , class... Targ, class Func > | |
| constexpr void | check_functor_signature (Func &&func) |
| Check if a callable object has the correct deduced signature. | |
| template<class... Targ, class Func > | |
| constexpr void | check_functor_signature_noreturn (Func &&func) |
| variant of check_functor_signature that does not check the return type | |
| template<class RetType , class... Targ, class Func > | |
| constexpr void | check_functor_signature_deduce (Func &&func, Targ...) |
| Check if a callable object has the correct deduced signature. | |
| template<class... Targ, class Func > | |
| constexpr void | check_functor_signature_deduce_noreturn (Func &&func, Targ...) |
| variant of check_functor_signature_deduce that does not check the return type | |
| template<class... Targ2, class... Targ, class Func > | |
| constexpr void | check_functor_signature_deduce_noreturn_add_t (Func &&func, Targ...) |
| variant of check_functor_signature_deduce that does not check the return type and where some types can be specified manually | |
| template<class T > | |
| std::shared_ptr< T > | to_shared (T &&t) |
Variables | |
| constexpr u32 | default_gsize = SHAMROCK_LOOP_GSIZE |
| constexpr u32 | default_gsize_2d = 16 |
| constexpr u32 | default_gsize_3d = 4 |
| template<class T > | |
| constexpr u64 | bitsizeof = sizeof(T) * CHAR_BIT |
| Number of bits in a type T. | |
| template<typename T , int num> | |
| constexpr bool | has_bitlen_v = has_bitlen<T, num>::value |
| Helper variable template for has_bitlen. | |
| template<class > | |
| constexpr bool | always_false_v = false |
| Helper variable template that is always false. Especially useful to perform static asserts based on templates. | |
| template<bool val, class type > | |
| constexpr bool | typed_false_v = val |
| Helper variable template that is used to associate a type to a boolean value in the compile logs. | |
| void(* | exception_print_callback )(std::string msg) = nullptr |
| exception print callback func ptr | |
| std::string | _callstack_process_identifier |
| std::vector< std::function< std::string()> > | _callstack_gen_info_generators |
namespace for basic c++ utilities
| using shambase::exception_gen_callback_t = typedef void (*)(std::string msg) |
type of the exception generator callback
Definition at line 42 of file exception.hpp.
| using shambase::formatter = typedef fmt::formatter<T> |
Formatter alias for fmt::formatter
This alias is used to prevent explicit use of the fmt library in the codebase. This way, we can change the formatting library without having to modify all the code that uses it.
| T | Type to format |
Definition at line 35 of file format.hpp.
| using shambase::opt_ref = typedef std::optional<std::reference_wrapper<T> > |
Optional reference wrapper.
Definition at line 26 of file optional.hpp.
| using shambase::VectorProperties = typedef sham::VectorProperties<T> |
| enum shambase::ParallelForWrapMode |
Definition at line 80 of file sycl_utils.hpp.
|
inline |
format a string using fmtlib style Cheat sheet : https://hackingcpp.com/cpp/libs/fmt.html
| T |
| fmt | the format string |
| args | the arguments to format agains |
format a string using C printf style https://cplusplus.com/reference/cstdio/printf/
| T |
| fmt | the format string |
| args | the arguments to format agains |
Definition at line 33 of file string.hpp.
Here is the call graph for this function:| void shambase::add_callstack_gen_info_generator | ( | std::string(*)() | generator | ) |
Definition at line 229 of file stacktrace.cpp.
| i32 shambase::any | ( | sycl::vec< T, n > | v | ) |
Fallback function for sycl::any SYCL std : Returns 1 if the most significant bit in any component of x is set; otherwise returns 0. if it is something else than the most significant bit it is UB.
| T | |
| n |
| v |
Definition at line 38 of file sycl_builtins.hpp.
Here is the call graph for this function:
|
inline |
Benchmark a function with input values following a power law.
This function takes a function and a range of input values, and benchmarks it by executing the function with each of the input values. The input values are generated by starting at the start value and repeatedly multiplying by pow_exp until the end value is reached.
| func | The function to be benchmarked. |
| start | The starting value of the input. |
| end | The ending value of the input. |
| pow_exp | The power of the exponent to increase the input value. |
Definition at line 254 of file time.hpp.
Here is the call graph for this function:Check if an integer value can be safely narrowed to a target type.
This function checks whether an integer value of type T can be represented in the target integer type U without overflow. Works with both signed and unsigned integer types for now.
| U | The target integer type to narrow to |
| T | The source integer type of the value |
| val | The value to check |
Definition at line 54 of file narrowing.hpp.
Here is the call graph for this function:| void shambase::change_printer | ( | void(*)(std::string_view) | func_printer_normal, |
| void(*)(std::string_view) | func_printer_ln, | ||
| void(*)() | func_flush_func | ||
| ) |
Changes the behavior of the print, println and flush functions.
| func_printer_normal | The function to be used for printing a string to the console. |
| func_printer_ln | The function to be used for printing a string to the console followed by a newline. |
| func_flush_func | The function to be used for flushing the output buffer. |
Definition at line 52 of file print.cpp.
Here is the call graph for this function:| void shambase::check_buffer_size | ( | sycl::buffer< T > & | buf, |
| u64 | max_range, | ||
| const SourceLocation | loc = SourceLocation() |
||
| ) |
check that the size of a sycl buffer is below or equal to the value of max range throw if it is not the case
| T |
| buf | |
| max_range | |
| loc |
Definition at line 43 of file sycl_utils.hpp.
Here is the call graph for this function:Check if a lambda or a function has the correct signature.
The function does nothing at runtime, but at compile time it checks if the given lambda or function has the correct signature. If the signature is wrong, the static assert will fail and the correct signature will be indicated in the signature of always_false_v<...>.
Definition at line 262 of file type_traits.hpp.
Here is the call graph for this function:Check if a callable object has the correct deduced signature.
This function deduces the signature of the callable object using the provided return type and argument types, then checks if the callable matches this signature using check_functor.
| RetType | The return type of the callable. |
| Targ | The types of the arguments the callable takes. |
| Func | The type of the callable object to check. |
| func | The callable object to be checked. |
Definition at line 284 of file type_traits.hpp.
Here is the call graph for this function:Check if a callable object has the correct deduced signature.
This function deduces the signature of the callable object using the provided return type and argument types, then checks if the callable matches this signature using check_functor and also checks if the return type matches the deduced return type.
Example :
| RetType | The return type of the callable. |
| Targ | The types of the arguments the callable takes. |
| Func | The type of the callable object to check. |
| func | The callable object to be checked. |
Definition at line 311 of file type_traits.hpp.
Here is the call graph for this function:Check if a callable object has the correct deduced signature.
This function deduces the signature of the callable object using the provided return type and argument types, then checks if the callable matches this signature using check_functor_signature.
| RetType | The return type of the callable. |
| Targ | The types of the arguments the callable takes. |
| Func | The type of the callable object to check. |
| func | The callable object to be checked. |
Definition at line 355 of file type_traits.hpp.
Here is the call graph for this function:
|
constexpr |
variant of check_functor_signature_deduce that does not check the return type
Definition at line 361 of file type_traits.hpp.
Here is the call graph for this function:
|
constexpr |
variant of check_functor_signature_deduce that does not check the return type and where some types can be specified manually
For example when using a type with a reference, this is not properly deduced. This functions allows to specify the type manually with the reference.
Here the function signature will be auto(sycl::handler&, <other types>)
Definition at line 383 of file type_traits.hpp.
Here is the call graph for this function:variant of check_functor_signature that does not check the return type
Definition at line 331 of file type_traits.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 320 of file sycl_utils.hpp.
|
inline |
Check if a substring is present in a given string.
| str | The input string |
| what | The substring to search for |
Definition at line 258 of file string.hpp.
Here is the call graph for this function:
|
inline |
Convert a vector to an array of size n.
| n | The size of the array |
| T | The type of the elements in the array |
| in | The input vector |
| std::invalid_argument | If the input vector size does not match n |
Definition at line 246 of file memory.hpp.
Here is the call graph for this function:Swap the endianness of the input value.
This function will swap the endianness of the input value a.
| T | type of the input value |
| a | input value |
Definition at line 51 of file endian.hpp.
Here is the call graph for this function:| std::string shambase::exception_format | ( | SourceLocation | loc | ) |
Format the exception message with the source location information.
This function formats a string that contains the source location information. It is useful to add this information to the exception message, in order to have a better understanding of where the exception was thrown.
| loc | The location from where the exception was thrown |
Definition at line 24 of file exception.cpp.
Here is the call graph for this function:| void shambase::exception_gen_callback | ( | std::string | msg | ) |
The callback called when an exception is thrown.
This callback is called with the formatted exception message as argument. It is settable with set_exception_gen_callback.
| msg | The formatted exception message |
Definition at line 31 of file exception.cpp.
Here is the call graph for this function:| auto shambase::extract_pointer | ( | std::unique_ptr< T > & | o, |
| SourceLocation | loc = SourceLocation() |
||
| ) | -> T |
extract content out of unique_ptr
| T |
| o |
Definition at line 227 of file memory.hpp.
Here is the call graph for this function:| auto shambase::extract_value | ( | std::optional< T > & | o, |
| SourceLocation | loc = SourceLocation() |
||
| ) | -> T |
Extracts the content out of an optional.
This function that takes an std::optional object and extracts the value from it. If the optional is empty, it throws a runtime error. The extracted value is returned, and the optional is left in an empty state.
| T | the type of the optional |
| o | reference to the optional object |
| loc | The source location where this function is called. |
| std::runtime_error | If the std::unique_ptr does not hold anything. |
Definition at line 211 of file memory.hpp.
Here is the call graph for this function:| void shambase::flush | ( | ) |
| std::string shambase::fmt_callstack | ( | ) |
Get the formatted callstack.
get the formatted callstack
This function returns a formatted string representing the current call stack.
Definition at line 238 of file stacktrace.cpp.
Here is the call graph for this function:Compute the FNV-1a hash of a given data.
| data | |
| size |
Definition at line 31 of file checksum.hpp.
Here is the call graph for this function:
|
inline |
Format an array of elements into a string.
This function takes an iterator to the first element of the array, the length of the array, the number of elements per column, and a format string. It formats each element of the array using the format string and concatenates the formatted elements into a single string.
| It | Iterator type (deduced) |
| Tformat | variadic template type (deduced) |
| iter | iterator to the first element of the array |
| len | length of the array |
| column_count | number of elements per column |
| fmt | format string |
| std::invalid_argument | if the format string is invalid |
Definition at line 111 of file string.hpp.
Here is the call graph for this function:
|
inline |
Get reference to object held by the unique ptr, and throw if nothing is held.
| T |
| ptr |
Definition at line 149 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Takes a std::shared_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::shared_ptr does not hold anything.
| T | The type of the object held by the std::shared_ptr. |
| ptr | A reference to the std::shared_ptr. |
| loc | The source location where this function is called. |
| std::runtime_error | If the std::shared_ptr does not hold anything. |
Definition at line 131 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::unique_ptr does not hold anything.
| T | The type of the object held by the std::unique_ptr. |
| ptr | A reference to the std::unique_ptr. |
| loc | The source location where this function is called. |
| std::runtime_error | If the std::unique_ptr does not hold anything. |
Definition at line 110 of file memory.hpp.
Here is the call graph for this function:
|
inline |
same overload but for const pointer
Definition at line 187 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Same overload but for non const case.
Definition at line 159 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Takes a raw pointer and returns a reference to the object it points to. It throws a std::runtime_error if the pointer is null.
| T | The type of the object pointed to by the raw pointer. |
| ptr | The raw pointer. |
| loc | The source location where this function is called. |
| std::runtime_error | If the raw pointer is null. |
Definition at line 177 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Return a copy of the input value with the endianness swapped.
This function returns a copy of its input value, with the endianness of the value swapped. The input value is not modified.
| T | The type of the input value. |
| a | The input value whose endianness is to be swapped. |
a with its endianness swapped. Definition at line 86 of file endian.hpp.
Here is the call graph for this function:Definition at line 42 of file numeric_limits.hpp.
| exception_gen_callback_t shambase::get_exception_gen_callback | ( | ) |
Get the current exception generator callback.
This function returns the current exception generator callback.
Definition at line 41 of file exception.cpp.
Definition at line 52 of file numeric_limits.hpp.
Definition at line 26 of file numeric_limits.hpp.
Definition at line 34 of file numeric_limits.hpp.
| std::string shambase::get_type_name | ( | ) |
Definition at line 35 of file type_name_info.hpp.
|
inline |
Get the Device Type Name.
| Device |
Definition at line 56 of file sycl_utils.hpp.
Here is the call graph for this function:Calculates the number of groups based on the length and group size.
| len | The total length |
| group_size | The size of each group |
Definition at line 125 of file integer.hpp.
Here is the call graph for this function:
|
inline |
Increase indentation of a string.
| in | the input string |
Definition at line 197 of file string.hpp.
Here is the call graph for this function:Definition at line 188 of file integer.hpp.
|
inline |
Check if the CPU is in little endian.
Check if the CPU is in little endian by checking the endianness of short int
The check is done by reinterpreting a short int with the value 0x0001 as a char array and checking the first byte of this array.
If the first byte is 1, then the CPU is in little endian, false otherwise.
Definition at line 36 of file endian.hpp.
Here is the call graph for this function:Checks if the most significant bit is set in the given value.
| T | The type of the value |
| x | The value to check |
Definition at line 161 of file integer.hpp.
Here is the call graph for this function:determine if v is a power of two and check if v==0 Source : https://graphics.stanford.edu/~seander/bithacks.html
| T | the type |
| v |
Definition at line 49 of file integer.hpp.
determine if v is a power of two Warning : this function return true if v == 0 Source : https://graphics.stanford.edu/~seander/bithacks.html
| T | the type |
| v |
Definition at line 36 of file integer.hpp.
|
inline |
Definition at line 44 of file StlContainerConversion.hpp.
pointer cast load from a pointer
| T | |
| TAcc |
| acc |
Definition at line 94 of file memory.hpp.
|
inline |
Load a Fortran formatted file from disk.
| fname | Filename of the file to load |
| runtime_error | if the file is not found |
Definition at line 404 of file fortran_io.hpp.
Here is the call graph for this function:load a value of type T from a byte buffer
| T | |
| AccU8 |
| acc | |
| ptr_load |
Definition at line 60 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Create an exception with a message and a location.
This function creates an exception with a message that is richer, as it also contains the source location where the exception was thrown.
| ExcptTypes | The type of the exception to create |
| message | The message of the exception |
| loc | The location from where the exception was thrown |
Definition at line 105 of file exception.hpp.
|
inline |
Make an exception with a message and variadic context groups.
This function allows to make an exception with multiple context groups. Each context group has a section name and a list of arguments.
Usage:
| exception_type | The type of the exception to make |
| message | The message of the exception |
| ctx | The context containing the arguments |
| loc | The source location where the exception is thrown |
Definition at line 108 of file exception_ctx.hpp.
Generate a sycl nd range out of a group size and length.
| length | max index value |
| group_size | group size |
Definition at line 74 of file sycl_utils.hpp.
Here is the call graph for this function:
|
inlineconstexprnoexcept |
Generates a mask with only the most significant bit set.
| T | The type of the value |
Definition at line 149 of file integer.hpp.
|
inline |
|
inline |
Definition at line 83 of file narrowing.hpp.
|
inline |
Odd-even transpose sort with segment boundaries.
Sorts array while respecting segment boundaries where comparisons are disabled.
| T | Element type |
| ArrSize | Compile-time array size |
| Comp | Comparator type |
| data | Pointer to data array |
| segment_boundary | Flags indicating segment boundaries (1 = boundary, 0 = no boundary) |
| comp | Comparison function |
Definition at line 79 of file alg_primitives.hpp.
Here is the call graph for this function:
|
inline |
Compare two distributed data and apply callbacks based on the difference.
This function compares the two given distributed data and applies callbacks based on the difference.
The callbacks are:
func_missing: called for each id present in the reference but not in ddfunc_match: called for each id present in both dd and the referencefunc_extra: called for each id present in dd but not in the reference| dd | the distributed data to compare |
| reference | the reference distributed data |
| func_missing | the callback for missing ids |
| func_match | the callback for matching ids |
| func_extra | the callback for extra ids |
Definition at line 352 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Compare two distributed data and apply callbacks based on the difference.
This is the same as on_distributeddata_diff but where one of the distributed data is represented by a vector of its ids.
This function compares the two given distributed data and applies callbacks based on the difference.
The callbacks are:
func_missing: called for each id present in the reference but not in ddfunc_match: called for each id present in both dd and the referencefunc_extra: called for each id present in dd but not in the reference| dd | the distributed data to compare |
| ref_ids | the reference ids |
| func_missing | the callback for missing ids |
| func_match | the callback for matching ids |
| func_extra | the callback for extra ids |
Definition at line 302 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 102 of file sycl_utils.hpp.
|
inline |
Definition at line 151 of file sycl_utils.hpp.
|
inline |
Definition at line 207 of file sycl_utils.hpp.
|
inline |
Definition at line 276 of file sycl_utils.hpp.
Calculates the power of a number at compile time.
| power | The power to raise the number to |
| T | The type of the number |
| a | The number to raise to the power |
Definition at line 174 of file integer.hpp.
Here is the call graph for this function:
|
inlineconstexprnoexcept |
Definition at line 24 of file floats.hpp.
| void shambase::print | ( | std::string_view | sv | ) |
| void shambase::println | ( | std::string_view | sv | ) |
Simple insertion sort on pointer range.
| T | Element type |
| Comp | Comparator type |
| data | Pointer to data array |
| start | Starting index (inclusive) |
| end | Ending index (exclusive) |
| comp | Comparison function |
Definition at line 35 of file alg_primitives.hpp.
Here is the call graph for this function:
|
inline |
given a sizeof value return a readble string Example : readable_sizeof(1024*1024*1024) -> "1.00 GB"
| size | the size |
Definition at line 139 of file string.hpp.
Here is the call graph for this function:
|
inline |
replace all occurence of a search string with another
taken from https://en.cppreference.com/w/cpp/string/basic_string/replace
| inout | the string to modify |
| what | the search string |
| with | the replace string |
Definition at line 183 of file string.hpp.
Here is the call graph for this function:| void shambase::reset_std_behavior | ( | ) |
|
inlineconstexprnoexcept |
round up to the next power of two Source : https://graphics.stanford.edu/~seander/bithacks.html
| T |
| v |
Definition at line 92 of file integer.hpp.
Here is the call graph for this function:
|
inline |
Selects and returns the bit at a specific position in the given value.
| T | The type of the value |
| value | The value from which to select the bit |
| bitnum | The position of the bit to select |
Definition at line 138 of file integer.hpp.
Here is the call graph for this function:| void shambase::set_callstack_process_identifier | ( | std::string | identifier | ) |
Definition at line 223 of file stacktrace.cpp.
|
inline |
Compute the difference between two containers as three separate vectors.
Compute the difference between two containers as three separate vectors. The first vector contains the elements of the first container that are not in the second container. The second vector contains the elements of the second container that are not in the first container. The third vector contains the elements that are present in both containers.
| c1 | The first container. |
| ref | The second container. |
| missing | The elements of the first container that are not in the second. |
| matching | The elements that are present in both containers. |
| extra | The elements of the second container that are not in the first. |
Definition at line 41 of file sets.hpp.
Here is the call graph for this function:| void shambase::set_exception_gen_callback | ( | exception_gen_callback_t | callback | ) |
Set the exception generator callback.
This function sets a callback that is called whenever an exception is thrown. The callback is called with the formatted exception message as argument.
| callback | The callback to set |
Definition at line 37 of file exception.cpp.
Here is the call graph for this function:Definition at line 35 of file StlContainerConversion.hpp.
|
inline |
Shortens a string by removing the last specified number of characters.
| str | The input string |
| len | The number of characters to be removed from the end of the string |
| std::invalid_argument | If the length of the input string is less than the specified length |
Definition at line 273 of file string.hpp.
Here is the call graph for this function:check if the sign of the two integers differs Source : https://graphics.stanford.edu/~seander/bithacks.html
| T |
| a | |
| b |
Definition at line 64 of file integer.hpp.
Here is the call graph for this function:
|
inline |
Splits a string into a vector of substrings according to a delimiter.
| s | The string to be split |
| delimiter | The string to be used as a delimiter for splitting |
Definition at line 290 of file string.hpp.
Here is the call graph for this function:pointer cast store the value
| a | in the pointer |
| T | |
| TAcc |
| acc | |
| a |
Definition at line 80 of file memory.hpp.
Here is the call graph for this function:Store a value of type T in a byte buffer.
Store the given value of type T into the byte buffer at the given index. The address is the starting address of the value to store in the buffer.
| T | type of the value to store |
| AccU8 | type of the byte buffer |
| acc | byte buffer |
| idx_write | index to store the value in the byte buffer |
| a | value to store |
Definition at line 41 of file memory.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 32 of file bytestream.hpp.
|
inline |
Definition at line 42 of file bytestream.hpp.
|
inline |
read a vector from the bytestream Note : this appends read objects to the vector without resetting it
| T |
| stream | |
| vec |
Definition at line 128 of file bytestream.hpp.
Here is the call graph for this function:
|
inline |
read a vector from the bytestream Note : this appends read objects to the vector without resetting it
| T |
| stream | |
| vec |
Definition at line 167 of file bytestream.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 27 of file bytestream.hpp.
|
inline |
Definition at line 36 of file bytestream.hpp.
|
inline |
write the vector into the bytestream
| T |
| stream | |
| vec |
Definition at line 104 of file bytestream.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 146 of file bytestream.hpp.
|
inline |
Throw a std::runtime_error saying that the function is unimplemented.
This function is a convenient way to throw a std::runtime_error saying that the function is unimplemented. It also includes the source location where the exception was thrown.
Usage :
| loc | The location from where the exception was thrown |
| std::runtime_error | The exception with a message saying that the function is unimplemented, and the source location. |
Definition at line 153 of file exception.hpp.
|
inline |
Throw a std::runtime_error with a message saying that the function is unimplemented.
This function is a convenient way to throw a std::runtime_error saying that the function is unimplemented. It also includes the source location where the exception was thrown.
Usage :
| message | The message to add to the exception message |
| loc | The location from where the exception was thrown |
| std::runtime_error | The exception with a message saying that the function is unimplemented, the given message, and the source location. |
Definition at line 175 of file exception.hpp.
|
inline |
Throw an exception and append the source location to it.
This function allows to throw an exception with a message that is richer, as it also contains the source location where the exception was thrown.
Usage :
| ExcptTypes | The type of the exception to throw |
| message | The message of the exception |
| loc | The location from where the exception was thrown |
| ExcptTypes | The exception with a message that also contains the source location. |
Definition at line 132 of file exception.hpp.
Measures the average time it takes to execute a function.
This function measures the average time it takes to execute a function by executing it the specified number of times and dividing the total time by the number of times the function was executed.
| Func | The type of the function to be executed. |
| f | The function to be executed. |
| relaunch | The number of times the function is executed. Default is 1. |
Definition at line 179 of file time.hpp.
Here is the call graph for this function:Measures the average time it takes to execute a function until a maximum duration is reached.
This function measures the average time it takes to execute a function until a maximum duration is reached. It does this by executing the function in a loop until the maximum duration is reached and then dividing the total time by the number of times the function was executed.
| Func | The type of the function to be executed. |
| f | The function to be executed. |
| max_duration | The maximum time the function is allowed to take. Default is 1 second. |
Definition at line 207 of file time.hpp.
Here is the call graph for this function:| std::shared_ptr< T > shambase::to_shared | ( | T && | t | ) |
Definition at line 42 of file ExternalForces.cpp.
|
inline |
Truncate a string to a specified length, adding an ellipsis if necessary.
| s | The string to truncate. |
| max_len | The maximum length of the string. |
| std::invalid_argument | If the maximum length is less than 5. |
This function truncates a string to a specified length by taking the first max_len - 5 characters and appending an ellipsis if the original string is longer than max_len. If max_len is less than 5, an std::invalid_argument exception is thrown.
Definition at line 215 of file string.hpp.
Here is the call graph for this function:
|
inline |
Truncate a string to a specified length, adding an ellipsis at the start if necessary.
| s | The input string. |
| max_len | The maximum length of the string. |
| std::invalid_argument | If the maximum length is less than 5. |
This function truncates a string to a specified length by adding an ellipsis at the start of the string, and taking the last max_len - 4 characters if the original string is longer than max_len. If max_len is less than 5, an std::invalid_argument exception is thrown.
Definition at line 239 of file string.hpp.
Here is the call graph for this function:Definition at line 26 of file StlContainerConversion.hpp.
|
inline |
dump a string to a file
| filename | the filename |
| s | the string to dump |
Definition at line 168 of file string.hpp.
Here is the call graph for this function:
|
inline |
swap two values using xor Source : https://graphics.stanford.edu/~seander/bithacks.html
| T |
| a | |
| b |
Definition at line 77 of file integer.hpp.
Here is the call graph for this function:| std::vector<std::function<std::string()> > shambase::_callstack_gen_info_generators |
Definition at line 227 of file stacktrace.cpp.
| std::string shambase::_callstack_process_identifier |
Definition at line 221 of file stacktrace.cpp.
Helper variable template that is always false. Especially useful to perform static asserts based on templates.
| T | dummy parameter to select the right overload |
Definition at line 234 of file type_traits.hpp.
Number of bits in a type T.
| T | type for which the number of bits is computed |
Definition at line 33 of file type_traits.hpp.
|
constexpr |
Definition at line 94 of file sycl_utils.hpp.
Definition at line 95 of file sycl_utils.hpp.
Definition at line 96 of file sycl_utils.hpp.
exception print callback func ptr
Definition at line 29 of file exception.cpp.
|
inlineconstexpr |
Helper variable template for has_bitlen.
This variable template is true if T has num bits.
| T | type to check |
| num | number of bits |
Definition at line 59 of file type_traits.hpp.
Helper variable template that is used to associate a type to a boolean value in the compile logs.
| val | boolean value to transport |
| type | The dummy type to be associated with the boolean value |
Definition at line 244 of file type_traits.hpp.