diff --git a/include/gridtools/common/defs.hpp b/include/gridtools/common/defs.hpp index b46527f53..559dd2253 100644 --- a/include/gridtools/common/defs.hpp +++ b/include/gridtools/common/defs.hpp @@ -8,6 +8,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #pragma once +#include namespace gridtools { using int_t = int; @@ -26,6 +27,22 @@ namespace gridtools { #endif #endif +#if defined(__has_builtin) +#if __has_builtin(__builtin_assume) +#define GT_ASSUME(x) __builtin_assume(x) +#else +#define GT_ASSUME(x) +#endif +#else +#define GT_ASSUME(x) +#endif + +#ifdef NDEBUG +#define GT_PROMISE(x) GT_ASSUME(x) +#else +#define GT_PROMISE(x) assert(x) +#endif + #ifdef __cpp_consteval #define GT_CONSTEVAL consteval #else @@ -53,7 +70,8 @@ namespace gridtools { #endif #if defined(__NVCC__) && (__CUDACC_VER_MAJOR__ == 12 && __CUDACC_VER_MINOR__ >= 1 && __CUDACC_VER_MINOR__ <= 4) -// enables workaround for CTAD/constexpr issues in CUDA 12.1, 12.2, 12.3, 12.4 (https://github.com/GridTools/gridtools/issues/1766) +// enables workaround for CTAD/constexpr issues in CUDA 12.1, 12.2, 12.3, 12.4 +// (https://github.com/GridTools/gridtools/issues/1766) #define GT_NVCC_WORKAROUND_1766 1 #else #define GT_NVCC_WORKAROUND_1766 0 diff --git a/include/gridtools/fn/unstructured.hpp b/include/gridtools/fn/unstructured.hpp index 136930c19..9844185a0 100644 --- a/include/gridtools/fn/unstructured.hpp +++ b/include/gridtools/fn/unstructured.hpp @@ -11,6 +11,7 @@ #include +#include "../common/defs.hpp" #include "../common/hymap.hpp" #include "../meta/logical.hpp" #include "../sid/concept.hpp" @@ -76,7 +77,7 @@ namespace gridtools::fn { template GT_FUNCTION constexpr auto deref(iterator const &it) { - assert(can_deref(it)); + GT_PROMISE(can_deref(it)); decltype(auto) stride = host_device::at_key(sid::get_stride(it.m_strides)); return *sid::shifted(it.m_ptr, stride, it.m_index); }