scalometer/include/kernels.hpp

42 lines
1.1 KiB
C++

#ifndef KERNELS_HPP
#define KERNELS_HPP
#include <functional>
#include <string>
#include <unordered_map>
class Kernel {
public:
using StrategyFunction = std::function<void(int, int, int)>;
using PreparationFunction = std::function<void()>;
Kernel(const std::string& name, StrategyFunction strategy_function,
PreparationFunction preparation_function);
void prepare() const;
void execute(int n_threads_or_tasks, int kernel_tripcount) const;
private:
std::string name_;
StrategyFunction strategy_function_;
PreparationFunction preparation_function_;
};
class KernelRegistry {
public:
using KernelBuilder = std::function<Kernel()>;
void register_kernel(const std::string& name, KernelBuilder factory);
Kernel load_kernel(const std::string& name) const;
std::vector<std::string> list_available_kernels() const;
private:
// FIXME: no benchmarking of maps done. The registry is expected to stay
// small, though
std::unordered_map<std::string, KernelBuilder> registry_;
};
void initialize_registry(KernelRegistry* registry, std::string strategy_name);
#endif // KERNELS_HPP