Documentation 6b54b78464
Loading...
Searching...
No Matches
codi_host_only.hpp
Go to the documentation of this file.
1/*!
2 * \file codi_host_only.hpp
3 * \brief Keeps CoDiPack out of nvcc's device pass.
4 * \author P. Gomes
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30/*--- Must be the first include of every .cu, before anything can pull in codi.hpp.
31 *
32 * When __CUDA_ARCH__ is defined, i.e. only in the device pass, CoDiPack stamps
33 * "__device__ __host__" on every one of its functions. nvcc then has to generate device
34 * code for the entire tape, which does not work: the tape uses function-scope statics with
35 * dynamic initializers (illegal in device code), takes the address of host statics, and
36 * calls into std::map and std::bitset. The kernels never touch an active type, so none of
37 * that is wanted in the first place.
38 *
39 * CODI_INLINE expands CODI_CUDAFunctionAttributes at each declaration, so emptying the
40 * macro before CoDiPack is parsed leaves it host-only. Including the defining header first
41 * makes the copy in config.h a no-op (it is "#pragma once"), so this definition is the one
42 * that survives. The host pass is unaffected either way, it never defines __CUDA_ARCH__
43 * and so already sees the same host-only declarations as the .cpp translation units. ---*/
44#if defined(CODI_REVERSE_TYPE) || defined(CODI_FORWARD_TYPE)
45#include "codi/tools/cuda/cudaFunctionAttributes.hpp"
46
47#undef CODI_CUDAFunctionAttributes
48#define CODI_CUDAFunctionAttributes
49#endif