Skip to content

Commit 79ebf96

Browse files
authored
Merge pull request #504 from eagles-project/jeff-cohere/bfbhash
Generates bit-for-bit hashes for each validation driver using EAMxx's bfbhash approach.
2 parents acb940f + 9a57921 commit 79ebf96

33 files changed

+272
-112
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ include_directories(${PROJECT_BINARY_DIR}/src)
8080

8181
link_directories("${MAM4XX_HAERO_DIR}/${CMAKE_INSTALL_LIBDIR}")
8282

83+
# emit compile_commands.json for use with clangd
84+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
85+
8386
# Code coverage
8487
if (ENABLE_COVERAGE)
8588
message(STATUS "Enabling code coverage instrumentation")

src/validation/aero_emissions/aero_emissions_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,5 @@ int main(int argc, char **argv) {
8888
ensemble->write(output_file);
8989

9090
// Clean up.
91-
delete ensemble;
92-
validation::finalize();
91+
validation::finalize(ensemble);
9392
}

src/validation/aero_model/aero_model_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,5 @@ int main(int argc, char **argv) {
7878
ensemble->write(output_file);
7979

8080
// Clean up.
81-
delete ensemble;
82-
validation::finalize();
81+
validation::finalize(ensemble);
8382
}

src/validation/aerosol_optics/aerosol_optics_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,5 @@ int main(int argc, char **argv) {
9999
ensemble->write(output_file);
100100

101101
// Clean up.
102-
delete ensemble;
103-
validation::finalize();
102+
validation::finalize(ensemble);
104103
}

src/validation/aging/aging_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,5 @@ int main(int argc, char **argv) {
6868
ensemble->write(output_file);
6969

7070
// Clean up.
71-
delete ensemble;
72-
validation::finalize();
71+
validation::finalize(ensemble);
7372
}

src/validation/bfbhash.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef MAM4XX_BFBHASH_HPP
2+
#define MAM4xx_BFBHASH_HPP
3+
4+
// This was copied from Andrew Bradley's original implementation at
5+
// E3SM/components/eamxx/src/share/util/eamxx_bfbhash.hpp.
6+
7+
#include <cstdint>
8+
9+
#include <ekat_comm.hpp>
10+
#include <ekat_kokkos_types.hpp>
11+
12+
namespace mam4 {
13+
namespace bfbhash {
14+
15+
typedef std::uint64_t HashType;
16+
17+
KOKKOS_INLINE_FUNCTION void hash(const HashType v, HashType &accum) {
18+
constexpr auto first_bit = 1ULL << 63;
19+
accum += ~first_bit & v; // no overflow
20+
accum ^= first_bit & v; // handle most significant bit
21+
}
22+
23+
KOKKOS_INLINE_FUNCTION void hash(const double v_, HashType &accum) {
24+
static_assert(sizeof(double) == sizeof(HashType),
25+
"HashType must have size sizeof(double).");
26+
HashType v;
27+
std::memcpy(&v, &v_, sizeof(HashType));
28+
hash(v, accum);
29+
}
30+
31+
KOKKOS_INLINE_FUNCTION void hash(const float v, HashType &accum) {
32+
hash(double(v), accum);
33+
}
34+
35+
// For Kokkos::parallel_reduce.
36+
template <typename ExecSpace = Kokkos::HostSpace> struct HashReducer {
37+
typedef HashReducer reducer;
38+
typedef HashType value_type;
39+
typedef Kokkos::View<value_type *, ExecSpace, Kokkos::MemoryUnmanaged>
40+
result_view_type;
41+
42+
KOKKOS_INLINE_FUNCTION HashReducer(value_type &value_) : value(value_) {}
43+
KOKKOS_INLINE_FUNCTION void join(value_type &dest,
44+
const value_type &src) const {
45+
hash(src, dest);
46+
}
47+
KOKKOS_INLINE_FUNCTION void init(value_type &val) const { val = 0; }
48+
KOKKOS_INLINE_FUNCTION value_type &reference() const { return value; }
49+
KOKKOS_INLINE_FUNCTION bool references_scalar() const { return true; }
50+
KOKKOS_INLINE_FUNCTION result_view_type view() const {
51+
return result_view_type(&value, 1);
52+
}
53+
54+
private:
55+
value_type &value;
56+
};
57+
58+
} // namespace bfbhash
59+
} // namespace mam4
60+
61+
#endif

src/validation/calcsize/calcsize_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,5 @@ int main(int argc, char **argv) {
7676
ensemble->write(output_file);
7777

7878
// Clean up.
79-
delete ensemble;
80-
validation::finalize();
79+
validation::finalize(ensemble);
8180
}

src/validation/coagulation/coagulation_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,5 @@ int main(int argc, char **argv) {
7878
ensemble->write(output_file);
7979

8080
// // Clean up.
81-
delete ensemble;
82-
validation::finalize();
81+
validation::finalize(ensemble);
8382
}

src/validation/convproc/convproc_driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,5 @@ int main(int argc, char **argv) {
126126
ensemble->write(output_file);
127127

128128
// Clean up.
129-
delete ensemble;
130-
validation::finalize();
129+
validation::finalize(ensemble);
131130
}

0 commit comments

Comments
 (0)