Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
metaprogramming.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith 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 
44 template <int i>
45 struct integral_constant {
46  SMITH_HOST_DEVICE constexpr operator int() { return i; }
47 };
48 
50 template <typename lambda, int... i>
51 SMITH_HOST_DEVICE constexpr void for_constexpr(const lambda& f, integral_constant<i>... args)
52 {
53  f(args...);
54 }
55 
57 template <int... n, typename lambda, typename... arg_types>
58 SMITH_HOST_DEVICE constexpr void for_constexpr(const lambda& f, std::integer_sequence<int, n...>, arg_types... args)
59 {
60  (detail::for_constexpr(f, args..., integral_constant<n>{}), ...);
61 }
62 
63 } // namespace detail
65 
95 template <int... n, typename lambda>
96 SMITH_HOST_DEVICE constexpr void for_constexpr(const lambda& f)
97 {
98  detail::for_constexpr(f, std::make_integer_sequence<int, n>{}...);
99 }
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
#define SMITH_SUPPRESS_NVCC_HOSTDEVICE_WARNING
Macro to turn off specific nvcc warnings.
Definition: accelerator.hpp:65
#define SMITH_HOST_DEVICE
Macro that evaluates to __host__ __device__ when compiling with nvcc or amdclang and does nothing on ...
Definition: accelerator.hpp:37
constexpr SMITH_HOST_DEVICE void for_constexpr(const 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...}