Skip to content
Draft
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
13 changes: 10 additions & 3 deletions src/script_interface/magnetostatics/DipolarDirectSum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@

#include "core/magnetostatics/dipolar_direct_sum.hpp"

#include "script_interface/code_info/CodeInfo.hpp"
#include "script_interface/get_value.hpp"

#include <memory>
#include <string>
#include <vector>

namespace ScriptInterface {
namespace Dipoles {
Expand All @@ -47,11 +49,16 @@ class DipolarDirectSum : public Actor<DipolarDirectSum, ::DipolarDirectSum> {
}

void do_construct(VariantMap const &params) override {
context()->parallel_try_catch([this, &params]() {
auto const gpu = get_value_or(params, "gpu", false);
context()->parallel_try_catch([this, &params, gpu]() {
if (gpu) {
std::vector<std::string> required_features;
required_features.emplace_back("CUDA");
CodeInfo::check_features(required_features);
}
m_actor = std::make_shared<CoreActorClass>(
get_value<double>(params, "prefactor"),
get_value<int>(params, "n_replicas"),
get_value_or(params, "gpu", false));
get_value<int>(params, "n_replicas"), gpu);
});
}
};
Expand Down
6 changes: 6 additions & 0 deletions testsuite/python/dipolar_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def test_exceptions_non_p3m(self):
MDLC(gap_size=2., maxPWerror=0.1, actor=ddsr_gpu)
with self.assertRaisesRegex(ValueError, "Parameter 'n_replicas' must be >= 0"):
DDSR(prefactor=1., n_replicas=-2, gpu=True)
else:
# requesting the GPU implementation without CUDA support compiled
# in must raise a clear error at construction time, rather than
# silently constructing a CPU actor that reports is_gpu() == True
with self.assertRaisesRegex(RuntimeError, "Missing features CUDA"):
DDSR(prefactor=1., gpu=True)
with self.assertRaisesRegex(RuntimeError, "Parameter 'actor' is missing"):
MDLC(gap_size=2., maxPWerror=0.1)
with self.assertRaisesRegex(RuntimeError, "Parameter 'n_replica' is not a valid parameter"):
Expand Down
Loading