Skip to content

Commit 6e8f368

Browse files
committed
undefine macros so they don't leak
1 parent 651b422 commit 6e8f368

14 files changed

+212
-148
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
build*
1+
build*
2+
cmake/blt*

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
set( hpcReact_headers
3+
common/macros.hpp
34
common/CArrayWrapper.hpp
45
reactions/EquilibriumReactions.hpp
56
reactions/KineticReactions.hpp

src/common/CArrayWrapper.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

33
#if defined( __CUDACC__ ) || defined( __HIPCC__ )
4-
#define HOST_DEVICE __host__ __device__
4+
#define HPCREACT_HOST_DEVICE __host__ __device__
55
#else
6-
#define HOST_DEVICE
6+
#define HPCREACT_HOST_DEVICE
77
#endif
88

99
/**
@@ -38,28 +38,28 @@ struct CArrayWrapper< T, 1, DIM0 >
3838
* @param dim The index (must be in range [0, DIM0)).
3939
* @return Reference to the element at the specified index.
4040
*/
41-
HOST_DEVICE inline T & operator()( int const dim ) { return data[dim]; }
41+
HPCREACT_HOST_DEVICE inline T & operator()( int const dim ) { return data[dim]; }
4242

4343
/**
4444
* @brief Read-only access to an element by index (const overload).
4545
* @param dim The index (must be in range [0, DIM0)).
4646
* @return Const reference to the element at the specified index.
4747
*/
48-
HOST_DEVICE inline T const & operator()( int const dim ) const { return data[dim]; }
48+
HPCREACT_HOST_DEVICE inline T const & operator()( int const dim ) const { return data[dim]; }
4949

5050
/**
5151
* @brief Subscript operator for read/write access.
5252
* @param dim The index (must be in range [0, DIM0)).
5353
* @return Reference to the element at the specified index.
5454
*/
55-
HOST_DEVICE inline T & operator[]( int const dim ) { return data[dim]; }
55+
HPCREACT_HOST_DEVICE inline T & operator[]( int const dim ) { return data[dim]; }
5656

5757
/**
5858
* @brief Subscript operator for read-only access (const overload).
5959
* @param dim The index (must be in range [0, DIM0)).
6060
* @return Const reference to the element at the specified index.
6161
*/
62-
HOST_DEVICE inline T const & operator[]( int const dim ) const { return data[dim]; }
62+
HPCREACT_HOST_DEVICE inline T const & operator[]( int const dim ) const { return data[dim]; }
6363

6464
/// The underlying 1D C-style array.
6565
T data[DIM0];
@@ -84,7 +84,7 @@ struct CArrayWrapper< T, 2, DIM0, DIM1 >
8484
* @param dim1 Index in the second dimension (range [0, DIM1)).
8585
* @return Reference to the element at the specified 2D location.
8686
*/
87-
HOST_DEVICE inline T & operator()( int const dim0, int const dim1 )
87+
HPCREACT_HOST_DEVICE inline T & operator()( int const dim0, int const dim1 )
8888
{
8989
return data[dim0][dim1];
9090
}
@@ -95,7 +95,7 @@ struct CArrayWrapper< T, 2, DIM0, DIM1 >
9595
* @param dim1 Index in the second dimension (range [0, DIM1)).
9696
* @return Const reference to the element at the specified 2D location.
9797
*/
98-
HOST_DEVICE inline T const & operator()( int const dim0, int const dim1 ) const
98+
HPCREACT_HOST_DEVICE inline T const & operator()( int const dim0, int const dim1 ) const
9999
{
100100
return data[dim0][dim1];
101101
}
@@ -107,7 +107,7 @@ struct CArrayWrapper< T, 2, DIM0, DIM1 >
107107
*
108108
* This allows usage like `obj[dim0][dim1]`.
109109
*/
110-
HOST_DEVICE inline T ( & operator[]( int const dim0 ))[DIM1]
110+
HPCREACT_HOST_DEVICE inline T ( & operator[]( int const dim0 ))[DIM1]
111111
{
112112
return data[dim0];
113113
}
@@ -117,7 +117,7 @@ struct CArrayWrapper< T, 2, DIM0, DIM1 >
117117
* @param dim0 The row index (range [0, DIM0)).
118118
* @return Const reference to an array of type T[DIM1].
119119
*/
120-
HOST_DEVICE inline T const (&operator[]( int const dim0 ) const)[DIM1]
120+
HPCREACT_HOST_DEVICE inline T const (&operator[]( int const dim0 ) const)[DIM1]
121121
{
122122
return data[dim0];
123123
}
@@ -150,7 +150,7 @@ struct CArrayWrapper< T, 3, DIM0, DIM1, DIM2 >
150150
* @note Currently, this function incorrectly indexes data[dim0][dim1], missing dim2.
151151
* It should be `data[dim0][dim1][dim2]`. Please correct if intended.
152152
*/
153-
HOST_DEVICE inline T & operator()( int const dim0, int const dim1, int const dim2 )
153+
HPCREACT_HOST_DEVICE inline T & operator()( int const dim0, int const dim1, int const dim2 )
154154
{
155155
// NOTE: This looks like a bug in your original code. Should be data[dim0][dim1][dim2].
156156
return data[dim0][dim1][dim2];
@@ -163,7 +163,7 @@ struct CArrayWrapper< T, 3, DIM0, DIM1, DIM2 >
163163
* @param dim2 Index in the third dimension (range [0, DIM2)).
164164
* @return Const reference to the element at the specified 3D location.
165165
*/
166-
HOST_DEVICE inline T const & operator()( int const dim0, int const dim1, int const dim2 ) const
166+
HPCREACT_HOST_DEVICE inline T const & operator()( int const dim0, int const dim1, int const dim2 ) const
167167
{
168168
// NOTE: Same potential bug as above. Should be data[dim0][dim1][dim2].
169169
return data[dim0][dim1][dim2];
@@ -176,7 +176,7 @@ struct CArrayWrapper< T, 3, DIM0, DIM1, DIM2 >
176176
*
177177
* This allows usage like `obj[dim0][dim1][dim2]`.
178178
*/
179-
HOST_DEVICE inline T ( & operator[]( int const dim0 ))[DIM1][DIM2]
179+
HPCREACT_HOST_DEVICE inline T ( & operator[]( int const dim0 ))[DIM1][DIM2]
180180
{
181181
return data[dim0];
182182
}
@@ -186,7 +186,7 @@ struct CArrayWrapper< T, 3, DIM0, DIM1, DIM2 >
186186
* @param dim0 The slice index (range [0, DIM0)).
187187
* @return Const reference to an array of type T[DIM1][DIM2].
188188
*/
189-
HOST_DEVICE inline T const (&operator[]( int const dim0 ) const)[DIM1][DIM2]
189+
HPCREACT_HOST_DEVICE inline T const (&operator[]( int const dim0 ) const)[DIM1][DIM2]
190190
{
191191
return data[dim0];
192192
}
@@ -196,4 +196,4 @@ struct CArrayWrapper< T, 3, DIM0, DIM1, DIM2 >
196196
};
197197

198198

199-
#undef HOST_DEVICE
199+
#undef HPCREACT_HOST_DEVICE

src/common/TypeDefs.hpp

Whitespace-only changes.

src/common/macros.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#ifndef HPCREACT_MACROS_HPP
3+
#define HPCREACT_MACROS_HPP
4+
5+
#if defined( __CUDACC__ ) || defined( __HIPCC__ )
6+
#define HPCREACT_USE_DEVICE
7+
#define HPCREACT_HOST_DEVICE __host__ __device__
8+
#else
9+
#define HPCREACT_HOST_DEVICE
10+
#endif
11+
12+
13+
#if defined( HPCREACT_USE_DEVICE )
14+
#define HPCREACT_GLOBAL __global__
15+
#else
16+
#define HPCREACT_GLOBAL
17+
#endif
18+
19+
/// This macro is used to ignore warnings that that a variable is
20+
/// unused.
21+
#define HPCREACT_UNUSED_VAR( ... ) (void)( __VA_ARGS__ )
22+
23+
#endif // HPCREACT_MACROS_HPP

src/common/macrosCleanup.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#undef HPCREACT_USE_DEVICE
2+
#undef HPCREACT_HOST_DEVICE
3+
#undef HPCREACT_GLOBAL
4+
#undef HPCREACT_UNUSED_VAR
5+
#undef UNDEFINE_PREPROCESSOR_VARS
6+
#undef HPCREACT_MACROS_HPP

src/reactions/EquilibriumReactions.hpp

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#include "ReactionsBase.hpp"
8-
8+
#include "common/macros.hpp"
99

1010
namespace hpcReact
1111
{
@@ -52,44 +52,51 @@ class EquilibriumReactions : public ReactionsBase< REAL_TYPE,
5252
static constexpr RealType m_newtonTol = 1e-6;
5353

5454
template< typename PARAMS_DATA >
55-
static void setInitialGuess( RealConstDataArrayView1d & primarySpeciesTotalConcentration,
56-
RealDataArrayView1d & primarySpeciesConcentration );
55+
static HPCREACT_HOST_DEVICE inline void
56+
setInitialGuess( RealConstDataArrayView1d & primarySpeciesTotalConcentration,
57+
RealDataArrayView1d & primarySpeciesConcentration );
5758

5859
template< typename PARAMS_DATA >
59-
static void assembleEquilibriumReactionSystem( RealType const temperature,
60-
RealConstDataArrayView1d & primarySpeciesTotalConcentration,
61-
RealConstDataArrayView1d & primarySpeciesConcentration,
62-
RealDataArrayView1d & secondarySpeciesConcentration,
63-
RealDataArrayView2d & matrix,
64-
RealDataArrayView1d & rhs );
60+
static HPCREACT_HOST_DEVICE inline void
61+
assembleEquilibriumReactionSystem( RealType const temperature,
62+
RealConstDataArrayView1d & primarySpeciesTotalConcentration,
63+
RealConstDataArrayView1d & primarySpeciesConcentration,
64+
RealDataArrayView1d & secondarySpeciesConcentration,
65+
RealDataArrayView2d & matrix,
66+
RealDataArrayView1d & rhs );
6567

6668
template< typename PARAMS_DATA >
67-
static void computeSecondarySpeciesConcAndDerivative( RealType const temperature,
68-
PARAMS_DATA const & params,
69-
RealConstDataArrayView1d & log10PrimaryActCoeff,
70-
RealConstDataArrayView1d & dLog10PrimaryActCoeff_dIonicStrength,
71-
RealConstDataArrayView1d & log10SecActCoeff,
72-
RealConstDataArrayView1d & dLog10SecActCoeff_dIonicStrength,
73-
RealConstDataArrayView1d & primarySpeciesConcentration,
74-
RealDataArrayView1d & secondarySpeciesConcentration,
75-
RealDataArrayView2d & dLog10SecConc_dLog10PrimaryConc );
69+
static HPCREACT_HOST_DEVICE inline void
70+
computeSecondarySpeciesConcAndDerivative( RealType const temperature,
71+
PARAMS_DATA const & params,
72+
RealConstDataArrayView1d & log10PrimaryActCoeff,
73+
RealConstDataArrayView1d & dLog10PrimaryActCoeff_dIonicStrength,
74+
RealConstDataArrayView1d & log10SecActCoeff,
75+
RealConstDataArrayView1d & dLog10SecActCoeff_dIonicStrength,
76+
RealConstDataArrayView1d & primarySpeciesConcentration,
77+
RealDataArrayView1d & secondarySpeciesConcentration,
78+
RealDataArrayView2d & dLog10SecConc_dLog10PrimaryConc );
7679

7780
template< typename PARAMS_DATA >
78-
static void computeTotalConcAndDerivative( RealType const temperature,
79-
PARAMS_DATA const & params,
80-
RealConstDataArrayView1d & primarySpeciesConcentration,
81-
RealConstDataArrayView1d & secondarySpeciesConcentration,
82-
RealConstDataArrayView2d & dLog10SecConc_dLog10PrimaryConc,
83-
RealDataArrayView1d & totalConc,
84-
RealDataArrayView2d & dTotalConc_dLog10PrimaryConc );
81+
static HPCREACT_HOST_DEVICE inline void
82+
computeTotalConcAndDerivative( RealType const temperature,
83+
PARAMS_DATA const & params,
84+
RealConstDataArrayView1d & primarySpeciesConcentration,
85+
RealConstDataArrayView1d & secondarySpeciesConcentration,
86+
RealConstDataArrayView2d & dLog10SecConc_dLog10PrimaryConc,
87+
RealDataArrayView1d & totalConc,
88+
RealDataArrayView2d & dTotalConc_dLog10PrimaryConc );
8589

8690
template< typename PARAMS_DATA >
87-
static void updatePrimarySpeciesConcentrations( RealConstDataArrayView1d solution,
88-
RealDataArrayView1d & primarySpeciesConcentration );
91+
static HPCREACT_HOST_DEVICE inline void
92+
updatePrimarySpeciesConcentrations( RealConstDataArrayView1d solution,
93+
RealDataArrayView1d & primarySpeciesConcentration );
8994

9095

9196

9297
};
9398

9499

95100
} // namespace hpcReact
101+
102+
#include "common/macrosCleanup.hpp"

0 commit comments

Comments
 (0)