21#include <boost/algorithm/string/join.hpp>
23#include <ql/errors.hpp>
41 for (
auto& c : ComputeFrameworkRegistry::instance().getAll())
46 std::set<std::string> result;
48 auto tmp = f->getAvailableDevices();
49 result.insert(tmp.begin(), tmp.end());
60 if (
auto tmp = f->getAvailableDevices(); tmp.find(deviceName) != tmp.end()) {
67 QL_FAIL(
"ComputeEnvironment::selectContext(): device '"
68 << deviceName <<
"' not found. Available devices: " << boost::join(
getAvailableDevices(),
","));
74 std::vector<double*> outputPtr(output.size());
75 std::transform(output.begin(), output.end(), outputPtr.begin(),
76 [](std::vector<double>& v) ->
double* { return &v[0]; });
81 const bool allowOverwrite) {
82 boost::unique_lock<boost::shared_mutex> lock(
mutex_);
83 QL_REQUIRE(allowOverwrite || std::find(
names_.begin(),
names_.end(), name) ==
names_.end(),
84 "FrameworkRegistry::add(): creator for '"
85 << name <<
"' already exists and allowOverwrite is false, can't add it.");
91 boost::shared_lock<boost::shared_mutex> lock(mutex_);
virtual void finalizeCalculation(std::vector< double * > &output)=0
std::set< std::string > getAvailableDevices() const
std::vector< ComputeFramework * > frameworks_
void selectContext(const std::string &deviceName)
std::string currentContextDeviceName_
ComputeContext * currentContext_
ComputeContext & context()
const std::vector< std::function< ComputeFramework *(void)> > & getAll() const
void add(const std::string &name, std::function< ComputeFramework *(void)> creator, const bool allowOverwrite=false)
std::vector< std::string > names_
boost::shared_mutex mutex_
std::vector< std::function< ComputeFramework *(void)> > creators_
interface to compute envs