-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add AMSEOS wrapper * fix compile issues * minor * format + minor
- Loading branch information
Showing
7 changed files
with
255 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2021-2023 Lawrence Livermore National Security, LLC and other | ||
* AMSLib Project Developers | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#include "eos_ams.hpp" | ||
|
||
#include <vector> | ||
|
||
template <typename FPType> | ||
void callBack(void *cls, | ||
long elements, | ||
const void *const *inputs, | ||
void *const *outputs) | ||
{ | ||
static_cast<EOS<FPType> *>(cls)->Eval(elements, | ||
static_cast<const FPType *>(inputs[0]), | ||
static_cast<const FPType *>(inputs[1]), | ||
static_cast<FPType *>(outputs[0]), | ||
static_cast<FPType *>(outputs[1]), | ||
static_cast<FPType *>(outputs[2]), | ||
static_cast<FPType *>(outputs[3])); | ||
} | ||
|
||
|
||
template <typename FPType> | ||
AMSEOS<FPType>::AMSEOS(EOS<FPType> *model, | ||
const AMSDBType db_type, | ||
const AMSDType dtype, | ||
const AMSExecPolicy exec_policy, | ||
const AMSResourceType res_type, | ||
const AMSUQPolicy uq_policy, | ||
const int k_nearest, | ||
const int mpi_task, | ||
const int mpi_nproc, | ||
const double threshold, | ||
const char *surrogate_path, | ||
const char *uq_path, | ||
const char *db_path) | ||
: model_(model) | ||
{ | ||
AMSConfig conf = {exec_policy, | ||
dtype, | ||
res_type, | ||
db_type, | ||
callBack<FPType>, | ||
(char *)surrogate_path, | ||
(char *)uq_path, | ||
(char *)db_path, | ||
threshold, | ||
uq_policy, | ||
k_nearest, | ||
mpi_task, | ||
mpi_nproc}; | ||
|
||
wf_ = AMSCreateExecutor(conf); | ||
} | ||
|
||
#ifdef __ENABLE_PERFFLOWASPECT__ | ||
__attribute__((annotate("@critical_path(pointcut='around')"))) | ||
#endif | ||
template <typename FPType> | ||
void AMSEOS<FPType>::Eval(const int length, | ||
const FPType *density, | ||
const FPType *energy, | ||
FPType *pressure, | ||
FPType *soundspeed2, | ||
FPType *bulkmod, | ||
FPType *temperature) const | ||
{ | ||
std::vector<const FPType *> inputs = {density, energy}; | ||
std::vector<FPType *> outputs = {pressure, soundspeed2, bulkmod, temperature}; | ||
|
||
#ifdef __ENABLE_MPI__ | ||
AMSDistributedExecute(wf_, | ||
MPI_COMM_WORLD, | ||
(void *)model_, | ||
length, | ||
reinterpret_cast<const void **>(inputs.data()), | ||
reinterpret_cast<void **>(outputs.data()), | ||
inputs.size(), | ||
outputs.size()); | ||
#else | ||
AMSExecute(wf_, | ||
(void *)model_, | ||
length, | ||
reinterpret_cast<const void **>(inputs.data()), | ||
reinterpret_cast<void **>(outputs.data()), | ||
inputs.size(), | ||
outputs.size()); | ||
#endif | ||
} | ||
|
||
template class AMSEOS<double>; | ||
template class AMSEOS<float>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2021-2023 Lawrence Livermore National Security, LLC and other | ||
* AMSLib Project Developers | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#ifndef _AMS_EOS_HPP_ | ||
#define _AMS_EOS_HPP_ | ||
|
||
#include <stdexcept> | ||
|
||
#include "AMS.h" | ||
#include "eos.hpp" | ||
|
||
template <typename FPType> | ||
class AMSEOS : public EOS<FPType> | ||
{ | ||
AMSExecutor wf_; | ||
EOS<FPType> *model_ = nullptr; | ||
|
||
public: | ||
AMSEOS(EOS<FPType> *model, | ||
const AMSDBType db_type, | ||
const AMSDType dtype, | ||
const AMSExecPolicy exec_policy, | ||
const AMSResourceType res_type, | ||
const AMSUQPolicy uq_policy, | ||
const int k_nearest, | ||
const int mpi_task, | ||
const int mpi_nproc, | ||
const double threshold, | ||
const char *surrogate_path, | ||
const char *uq_path, | ||
const char *db_path); | ||
|
||
virtual ~AMSEOS() { delete model_; } | ||
|
||
void Eval(const int length, | ||
const FPType *density, | ||
const FPType *energy, | ||
FPType *pressure, | ||
FPType *soundspeed2, | ||
FPType *bulkmod, | ||
FPType *temperature) const override; | ||
|
||
void Eval_with_filter(const int length, | ||
const FPType *density, | ||
const FPType *energy, | ||
const bool *filter, | ||
FPType *pressure, | ||
FPType *soundspeed2, | ||
FPType *bulkmod, | ||
FPType *temperature) const override | ||
{ | ||
throw std::runtime_error("AMSEOS: Eval_with_filter is not implemented"); | ||
} | ||
}; | ||
|
||
#endif // _AMS_EOS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.