Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [[PR583]](https://github.com/lanl/singularity-eos/pull/583) Added GenericIndexer class to provide more complex array indirection

### Fixed (Repair bugs, etc)
- [[PR593]](https://github.com/lanl/singularity-eos/pull/593) Guard tests for AMD GPU for problematic LLVM versions. Also cleaned up code for clarity.
- [[PR567]](https://github.com/lanl/singularity-eos/pull/567) Fixed an OOB array access bug in the Fixed T PTE solver
- [[PR561]](https://github.com/lanl/singularity-eos/pull/561) Fix logic for kokkos-kernels in spackage so that it is only required for closure models on GPU
- [[PR563]](https://github.com/lanl/singularity-eos/pull/563) Fixed DensityFromPressureTemperature for the Carnahan-Starling EOS.
Expand Down
2 changes: 1 addition & 1 deletion singularity-eos/eos/eos_gruneisen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ PORTABLE_INLINE_FUNCTION Real Gruneisen::ComputeRhoMax(const Real s1, const Real
maxbound = std::min(min_extremum, maxbound);
}
} // s3 > 0 ; else
} // discriminant >= 0
} // discriminant >= 0
if (poly(minbound) * poly(maxbound) < 0.) {
// Root is appropriately bounded
using RootFinding1D::regula_falsi;
Expand Down
49 changes: 28 additions & 21 deletions singularity-eos/eos/eos_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class Variant {
}

Variant GetOnDevice() {
return PortsOfCall::visit([](auto &eos) { return eos_variant<EOSs...>(eos.GetOnDevice()); },
eos_);
return PortsOfCall::visit(
[](auto &eos) { return eos_variant<EOSs...>(eos.GetOnDevice()); }, eos_);
}

// Place member functions here
Expand All @@ -88,12 +88,14 @@ class Variant {

template <typename Functor_t>
PORTABLE_INLINE_FUNCTION void EvaluateDevice(const Functor_t f) const {
return PortsOfCall::visit([&f](const auto &eos) { return eos.EvaluateDevice(f); }, eos_);
return PortsOfCall::visit([&f](const auto &eos) { return eos.EvaluateDevice(f); },
eos_);
}

template <typename Functor_t>
void EvaluateHost(Functor_t &f) const {
return PortsOfCall::visit([&f](const auto &eos) { return eos.EvaluateHost(f); }, eos_);
return PortsOfCall::visit([&f](const auto &eos) { return eos.EvaluateHost(f); },
eos_);
}

// EOS modifier object-oriented API
Expand Down Expand Up @@ -336,7 +338,8 @@ class Variant {

PORTABLE_INLINE_FUNCTION
Real RhoPmin(const Real temp) const {
return PortsOfCall::visit([&temp](const auto &eos) { return eos.RhoPmin(temp); }, eos_);
return PortsOfCall::visit([&temp](const auto &eos) { return eos.RhoPmin(temp); },
eos_);
}

PORTABLE_FORCEINLINE_FUNCTION
Expand All @@ -346,7 +349,8 @@ class Variant {

PORTABLE_FORCEINLINE_FUNCTION
Real MinimumTemperature() const {
return PortsOfCall::visit([](const auto &eos) { return eos.MinimumTemperature(); }, eos_);
return PortsOfCall::visit([](const auto &eos) { return eos.MinimumTemperature(); },
eos_);
}

PORTABLE_FORCEINLINE_FUNCTION
Expand All @@ -356,7 +360,8 @@ class Variant {

PORTABLE_FORCEINLINE_FUNCTION
Real MinimumPressure() const {
return PortsOfCall::visit([](const auto &eos) { return eos.MinimumPressure(); }, eos_);
return PortsOfCall::visit([](const auto &eos) { return eos.MinimumPressure(); },
eos_);
}

PORTABLE_FORCEINLINE_FUNCTION
Expand All @@ -373,7 +378,8 @@ class Variant {
}
PORTABLE_INLINE_FUNCTION
Real MeanAtomicNumber() const {
return PortsOfCall::visit([](const auto &eos) { return eos.MeanAtomicNumber(); }, eos_);
return PortsOfCall::visit([](const auto &eos) { return eos.MeanAtomicNumber(); },
eos_);
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real MeanAtomicMassFromDensityTemperature(
Expand Down Expand Up @@ -1235,24 +1241,25 @@ class Variant {
// class/individual EOS's so that the variant state is properly
// carried. Otherwise de-serialization would need to specify a type.
std::size_t DynamicMemorySizeInBytes() const {
return PortsOfCall::visit([](const auto &eos) { return eos.DynamicMemorySizeInBytes(); },
eos_);
return PortsOfCall::visit(
[](const auto &eos) { return eos.DynamicMemorySizeInBytes(); }, eos_);
}
std::size_t DumpDynamicMemory(char *dst) {
return PortsOfCall::visit([dst](auto &eos) { return eos.DumpDynamicMemory(dst); }, eos_);
return PortsOfCall::visit([dst](auto &eos) { return eos.DumpDynamicMemory(dst); },
eos_);
}
std::size_t SetDynamicMemory(char *src,
const SharedMemSettings &stngs = DEFAULT_SHMEM_STNGS) {
return PortsOfCall::visit(
[src, stngs](auto &eos) { return eos.SetDynamicMemory(src, stngs); }, eos_);
}
std::size_t SharedMemorySizeInBytes() const {
return PortsOfCall::visit([](const auto &eos) { return eos.SharedMemorySizeInBytes(); },
eos_);
return PortsOfCall::visit(
[](const auto &eos) { return eos.SharedMemorySizeInBytes(); }, eos_);
}
constexpr bool AllDynamicMemoryIsShareable() const {
return PortsOfCall::visit([](const auto &eos) { return eos.AllDynamicMemoryIsShareable(); },
eos_);
return PortsOfCall::visit(
[](const auto &eos) { return eos.AllDynamicMemoryIsShareable(); }, eos_);
}
std::size_t SerializedSizeInBytes() const {
return sizeof(*this) + DynamicMemorySizeInBytes();
Expand Down Expand Up @@ -1323,8 +1330,8 @@ class Variant {

PORTABLE_INLINE_FUNCTION
unsigned long max_scratch_size(const unsigned int nelements) {
return PortsOfCall::visit([&](const auto &eos) { return eos.max_scratch_size(nelements); },
eos_);
return PortsOfCall::visit(
[&](const auto &eos) { return eos.max_scratch_size(nelements); }, eos_);
}

PORTABLE_FORCEINLINE_FUNCTION
Expand All @@ -1334,14 +1341,14 @@ class Variant {

template <typename T>
PORTABLE_INLINE_FUNCTION bool NeedsLambda() const {
return PortsOfCall::visit([](const auto &eos) { return eos.template NeedsLambda<T>(); },
eos_);
return PortsOfCall::visit(
[](const auto &eos) { return eos.template NeedsLambda<T>(); }, eos_);
}

template <typename T>
PORTABLE_INLINE_FUNCTION bool NeedsLambda(const T &t) const {
return PortsOfCall::visit([](const auto &eos) { return eos.template NeedsLambda<T>(); },
eos_);
return PortsOfCall::visit(
[](const auto &eos) { return eos.template NeedsLambda<T>(); }, eos_);
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions singularity-eos/eos/eos_vinet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ inline void Vinet::InitializeVinet(const Real *d2tod40input) {
for (int ind = VinetInternalParametersSize - 2; ind >= 2;
ind--) { // _VIP[42]=d40=f40 given,first calculated is _VIP[41]=f39
_VIP[ind] = _VIP[ind] - (ind) / _VIP[1] * _VIP[ind + 1]; // prefactors f40 to f0
} // _VIP[n+2]=fn, ind=n+2
} // _VIP[n+2]=fn, ind=n+2
}

PORTABLE_INLINE_FUNCTION void Vinet::Vinet_F_DT_func(const Real rho, const Real T,
Expand All @@ -241,7 +241,7 @@ PORTABLE_INLINE_FUNCTION void Vinet::Vinet_F_DT_func(const Real rho, const Real
sumP = _d2tod40[pref0vp + ind] + onemx * sumP; //_d2tod40[38]=d40
sumB = _d2tod40[pref0vp + ind] * ind + onemx * sumB; //_d2tod40[-2+40]=d40
sumE = _VIP[pref0vip + ind] + onemx * sumE; //_VIP[42]=f40
} //_VIP[2]=f0
} //_VIP[2]=f0
#pragma unroll
for (int ind = 1; ind >= 0; ind--) {
sumE = _VIP[pref0vip + ind] + onemx * sumE;
Expand Down
3 changes: 1 addition & 2 deletions singularity-eos/eos/modifiers/shifted_eos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ class ShiftedEOS : public EosBase<ShiftedEOS<T>> {
singularity::mfuncname::member_func_name(typeid(ShiftedEOS<T>).name(), __func__);
static auto const cname = name.c_str();
const auto shift_val = shift_;
portableFor(
cname, 0, num, PORTABLE_LAMBDA(const int i) { sies[i] += shift_val; });
portableFor(cname, 0, num, PORTABLE_LAMBDA(const int i) { sies[i] += shift_val; });
}

template <typename LambdaIndexer>
Expand Down
18 changes: 13 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,19 @@ if(SINGULARITY_BUILD_CLOSURE)
catch_discover_tests(closure_unit_tests PROPERTIES TIMEOUT 120)

if(SINGULARITY_USE_SPINER)
add_executable(test_pte test_pte.cpp)
target_link_libraries(test_pte PRIVATE Catch2::Catch2
singularity-eos::singularity-eos)
target_include_directories(test_pte PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_test(pte test_pte)
if(SINGULARITY_USE_KOKKOS AND Kokkos_ENABLE_HIP
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0.0")
message(WARNING
"Test PTE appears to encounter a compiler bug for LLVM builds targeting AMD GPUs "
"for compiler versions ${CMAKE_CXX_COMPILER_VERSION} < 19, and the test is disabled. "
"Note this corresponds to rocm versions less than 6.4.")
else()
add_executable(test_pte test_pte.cpp)
target_link_libraries(test_pte PRIVATE Catch2::Catch2
singularity-eos::singularity-eos)
target_include_directories(test_pte PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_test(pte test_pte)
endif()

add_executable(test_pte_2phase test_pte_2phaseVinetSn.cpp)
target_link_libraries(test_pte_2phase PRIVATE Catch2::Catch2
Expand Down
4 changes: 3 additions & 1 deletion test/catch2_define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ int main(int argc, char *argv[]) {
Kokkos::initialize();
#endif
int result;
{ result = Catch::Session().run(argc, argv); }
{
result = Catch::Session().run(argc, argv);
}
#ifdef PORTABILITY_STRATEGY_KOKKOS
Kokkos::finalize();
#endif
Expand Down
55 changes: 30 additions & 25 deletions test/test_pte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ using atomic_view = Kokkos::MemoryTraits<Kokkos::Atomic>;
#endif

template <template <typename... Types> class Method_t>
auto TestPTE(const std::string name, const std::size_t nscratch_vars,
std::size_t &nsuccess) {
void TestPTE(const std::string name, const std::size_t nscratch_vars,
std::size_t &nsuccess, std::vector<Real> &host_vals) {
constexpr Real EPS = 1e-5;
Real time;
nsuccess = 0;
Expand Down Expand Up @@ -236,15 +236,20 @@ auto TestPTE(const std::string name, const std::size_t nscratch_vars,
std::cout << "\n\tTotal = " << tot << "\n" << std::endl;

#ifdef PORTABILITY_STRATEGY_KOKKOS
return rho_v;
#else
Kokkos::deep_copy(rho_vh, rho_v);
#endif // PORTABILITY_STRATEGY_KOKKOS
host_vals.resize(NPTS);
for (int i = 0; i < NPTS; ++i) {
host_vals[i] = rho_hm(i);
}
#ifndef PORTABILITY_STRATEGY_KOKKOS
free(rho_d);
free(vfrac_d);
free(sie_d);
free(temp_d);
free(press_d);
free(scratch_d);
return rho_d;
#endif // PORTABILITY_STRATEGY_KOKKOS
#endif // NOT PORTABILITY_STRATEGY_KOKKOS
}

int main(int argc, char *argv[]) {
Expand All @@ -257,34 +262,34 @@ int main(int argc, char *argv[]) {

// scratch required for PTE solver
std::size_t ns_rt;
std::vector<Real> rho_rt;
auto nscratch_vars_rt = PTESolverRhoTRequiredScratch(NMAT);
auto rho_rt = TestPTE<PTESolverRhoT>("PTESolverRhoT", nscratch_vars_rt, ns_rt);
TestPTE<PTESolverRhoT>("PTESolverRhoT", nscratch_vars_rt, ns_rt, rho_rt);
nsuccess += ns_rt;

// // scratch required for PTE solver
std::size_t ns_pt;
std::vector<Real> rho_pt;
auto nscratch_vars_pt = PTESolverPTRequiredScratch(NMAT);
auto rho_pt = TestPTE<PTESolverPT>("PTESolverPT", nscratch_vars_pt, ns_pt);
TestPTE<PTESolverPT>("PTESolverPT", nscratch_vars_pt, ns_pt, rho_pt);
nsuccess += ns_pt;

int nmatch = 0;
portableReduce(
"Check rho match", 0, NMAT,
PORTABLE_LAMBDA(const int i, int &nm) {
bool they_match = isClose(rho_rt(i), rho_pt(i));
if (!they_match) {
printf("Densities don't match for %d: %.14e %.14e %.14e\n", i, rho_rt(i),
rho_pt(i), rho_rt(i) - rho_pt(i));
}
nm += they_match;
},
nmatch);
printf("Nmatch = %d / %d\n", nmatch, NMAT);

#ifndef PORTABILITY_STRATEGY_KOKKOS
free(rho_rt);
free(rho_pt);
#endif // PORTABILITY_STRATEGY_KOKKOS
int i = 0; // flat index
std::vector<bool> matmatch(NMAT, true);
for (int t = 0; t < NTRIAL; ++t) {
for (int m = 0; m < NMAT; ++m) {
bool they_match = isClose(rho_rt[i], rho_pt[i]);
if (!they_match && matmatch[m]) { // only print once per material
printf("Densities don't match for %d %d: %.14e %.14e %.14e\n", t, m, rho_rt[i],
rho_pt[i], rho_rt[i] - rho_pt[i]);
}
matmatch[m] = matmatch[m] && they_match;
nmatch += they_match;
i++;
}
}
printf("Nmatch = %d / %d\n", nmatch, i);
}
#ifdef PORTABILITY_STRATEGY_KOKKOS
Kokkos::finalize();
Expand Down
19 changes: 9 additions & 10 deletions test/test_spiner_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@
#include <cstdlib>
#include <iostream> // debug

#include <ports-of-call/portability.hpp>
#include <singularity-eos/base/indexable_types.hpp>
#include <singularity-eos/eos/eos_spiner_common.hpp>
#include <singularity-eos/eos/eos_spiner_sie_transforms.hpp>

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
#ifdef SINGULARITY_USE_SPINER_WITH_HDF5
#ifdef SINGULARITY_USE_SPINER

#include <ports-of-call/portability.hpp>
#include <singularity-eos/base/indexable_types.hpp>
#include <singularity-eos/eos/eos_spiner_common.hpp>
#include <singularity-eos/eos/eos_spiner_sie_transforms.hpp>

#ifdef SPINER_USE_HDF5
#include <singularity-eos/base/spiner_table_utils.hpp>
#include <spiner/databox.hpp>
#include <spiner/interpolation.hpp>
#endif

#ifdef SINGULARITY_USE_SPINER
#include <test/eos_unit_test_helpers.hpp>

using namespace singularity;
using namespace transformations;
Expand Down Expand Up @@ -278,3 +276,4 @@ SCENARIO("AllTransform behaves correctly", "[TransformTest]") {
}

#endif // SINGULARITY_USE_SPINER
#endif // SINGULARITY_USE_SPINER_WITH_HDF5