2024-12-13 00:33:08 +01:00
|
|
|
#ifndef KERNELS_HPP
|
|
|
|
#define KERNELS_HPP
|
|
|
|
|
|
|
|
#include <functional>
|
2024-12-13 12:01:35 +01:00
|
|
|
#include <string>
|
2024-12-13 00:33:08 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
class Kernel {
|
2024-12-13 12:01:35 +01:00
|
|
|
public:
|
2024-12-13 00:33:08 +01:00
|
|
|
using StrategyFunction = std::function<void(int, int, int)>;
|
|
|
|
using PreparationFunction = std::function<void()>;
|
|
|
|
|
2024-12-13 12:01:35 +01:00
|
|
|
Kernel(const std::string& name, StrategyFunction strategy_function,
|
|
|
|
PreparationFunction preparation_function);
|
2024-12-13 00:33:08 +01:00
|
|
|
|
|
|
|
void prepare() const;
|
|
|
|
void execute(int n_threads_or_tasks, int kernel_tripcount) const;
|
|
|
|
|
2024-12-13 12:01:35 +01:00
|
|
|
private:
|
2024-12-13 00:33:08 +01:00
|
|
|
std::string name_;
|
|
|
|
StrategyFunction strategy_function_;
|
|
|
|
PreparationFunction preparation_function_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class KernelRegistry {
|
2024-12-13 12:01:35 +01:00
|
|
|
public:
|
2024-12-13 00:33:08 +01:00
|
|
|
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;
|
|
|
|
|
2024-12-13 12:01:35 +01:00
|
|
|
private:
|
|
|
|
// FIXME: no benchmarking of maps done. The registry is expected to stay
|
|
|
|
// small, though
|
2024-12-13 00:33:08 +01:00
|
|
|
std::unordered_map<std::string, KernelBuilder> registry_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void initialize_registry(KernelRegistry* registry, std::string strategy_name);
|
|
|
|
|
2024-12-13 12:01:35 +01:00
|
|
|
#endif // KERNELS_HPP
|