Loading [MathJax]/extensions/tex2jax.js
BioCMAMC-ST
common.hpp
1#ifndef __COMMON_EXPORT_HPP__
2#define __COMMON_EXPORT_HPP__
3
4#include "Kokkos_Macros.hpp"
5#include <biocma_cst_config.hpp>
6#include <common/alg.hpp>
7#include <common/execinfo.hpp>
8#include <common/traits.hpp>
9#include <string_view>
10
11using ComputeSpace = Kokkos::DefaultExecutionSpace;
12using HostSpace = Kokkos::HostSpace;
13
14#ifdef ENABLE_KOKKOS_PROFILING
15# include <Kokkos_Profiling_ScopedRegion.hpp>
16# define PROFILE_SECTION(__label_section__) \
17 Kokkos::Profiling::ScopedRegion region(__label_section__);
18#else
19# define PROFILE_SECTION(__label_section__) ;
20#endif
21
22#define EIGEN_INDEX(__VALUE__) static_cast<int>(__VALUE__)
23
24#ifndef NDEBUG
25# include <iostream>
26# include <source_location>
27class Canary
28{
29public:
30 Canary() = delete;
31 Canary(const Canary&) = delete;
32 Canary(Canary&&) = delete;
33 Canary& operator=(const Canary&) = delete;
34 Canary& operator=(Canary&&) = delete;
35
36 explicit Canary(std::string_view lbl, std::source_location location) : _lbl(lbl)
37 {
38 // std::cout << "\033[1;31m" << location.function_name() << "\033[0m " << lbl << std::endl;
39 std::cout << location.function_name() << ": " << lbl << std::endl;
40 }
41
43 {
44 std::cout << "END " << _lbl << std::endl;
45 }
46
47private:
48 std::string _lbl;
49};
50# define MkCanary(x) Canary(x, std::source_location());
51#else
52# define MkCanary(x)
53#endif
54
55inline Kokkos::TeamPolicy<ComputeSpace> get_policy_auto(std::size_t range)
56{
57
58 Kokkos::TeamPolicy<ComputeSpace> _policy;
59
60 int recommended_team_size = _policy.team_size_recommended(
61 KOKKOS_LAMBDA(const Kokkos::TeamPolicy<ComputeSpace>::member_type& team_handle) {
62 std::size_t idx =
63 team_handle.league_rank() * team_handle.team_size() + team_handle.team_rank();
64 if (idx >= range)
65 {
66 return;
67 }
68 },
69 Kokkos::ParallelForTag());
70 int league_size = (static_cast<int>(range) + recommended_team_size - 1) / recommended_team_size;
71
72 _policy = Kokkos::TeamPolicy<ComputeSpace>(league_size, recommended_team_size);
73
74 return _policy;
75}
76
77#endif //__COMMON_EXPORT_HPP__
Definition common.hpp:28
Canary & operator=(const Canary &)=delete
~Canary()
Definition common.hpp:42
Canary(Canary &&)=delete
Canary()=delete
Canary(std::string_view lbl, std::source_location location)
Definition common.hpp:36
Canary(const Canary &)=delete
Canary & operator=(Canary &&)=delete
std::string _lbl
Definition common.hpp:48