Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
metaprogramming.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include <tuple>
16 #include <utility>
17 #include <type_traits>
18 
20 
24 template <int I, int... n>
25 constexpr auto get(std::integer_sequence<int, n...>)
26 {
27  constexpr int values[sizeof...(n)] = {n...};
28  return values[I];
29 }
30 
32 namespace detail {
33 
34 template <typename T>
35 struct always_false : std::false_type {
36 };
37 
45 template <int i>
46 struct integral_constant {
47  SERAC_HOST_DEVICE constexpr operator int() { return i; }
48 };
49 
51 template <typename lambda, int... i>
52 SERAC_HOST_DEVICE constexpr void for_constexpr(lambda&& f, integral_constant<i>... args)
53 {
54  f(args...);
55 }
56 
58 template <int... n, typename lambda, typename... arg_types>
59 SERAC_HOST_DEVICE constexpr void for_constexpr(lambda&& f, std::integer_sequence<int, n...>, arg_types... args)
60 {
61  (detail::for_constexpr(f, args..., integral_constant<n>{}), ...);
62 }
63 
64 } // namespace detail
66 
96 template <int... n, typename lambda>
97 SERAC_HOST_DEVICE constexpr void for_constexpr(lambda&& f)
98 {
99  detail::for_constexpr(f, std::make_integer_sequence<int, n>{}...);
100 }
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
#define SERAC_SUPPRESS_NVCC_HOSTDEVICE_WARNING
Macro to turn off specific nvcc warnings.
Definition: accelerator.hpp:50
#define SERAC_HOST_DEVICE
Macro that evaluates to __host__ __device__ when compiling with nvcc and does nothing on a host compi...
Definition: accelerator.hpp:38
constexpr SERAC_HOST_DEVICE void for_constexpr(lambda &&f)
multidimensional loop tool that evaluates the lambda body inside the innermost loop.
constexpr auto get(std::integer_sequence< int, n... >)
return the Ith integer in {n...}