-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdynamic_feature_config.hpp
66 lines (51 loc) · 1.99 KB
/
dynamic_feature_config.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef DYNAMIC_FEATURE_CONFIG_HPP_INCLUDED
#define DYNAMIC_FEATURE_CONFIG_HPP_INCLUDED
#include <map>
#include <set>
#include <string>
#include <toolkit/opencl.hpp>
#include <variant>
#include <typeinfo>
///this class provides a gpu compatible struct that's dynamically generated
///but also provides defines so that the struct may be bypassed
///two kernels then get generated: One using the struct, and one using the hardcoded configs
///there are now a *lot* of cases where functionality like this is necessary, and the perf tradeoff is unacceptable
struct dynamic_feature_config
{
bool is_dirty = false;
bool is_static_dirty = false;
std::map<std::string, std::variant<bool, float>> features_enabled;
std::set<std::string> always_static;
template<typename T>
void add_feature(const std::string& feature)
{
add_feature_impl(feature, typeid(T));
}
void remove_feature(const std::string& feature);
bool is_enabled(const std::string& feature);
template<typename T>
void set_feature(const std::string& feature, const T& val)
{
assert(features_enabled.find(feature) != features_enabled.end());
if(val != std::get<T>(features_enabled[feature]))
{
is_dirty = true;
if(always_static.count(feature) == 1)
is_static_dirty = true;
}
features_enabled[feature] = val;
}
void set_always_static(const std::string& feature, bool val);
template<typename T>
T get_feature(const std::string& feature)
{
assert(features_enabled.find(feature) != features_enabled.end());
return std::get<T>(features_enabled[feature]);
}
std::string generate_dynamic_argument_string() const;
std::string generate_static_argument_string() const;
void alloc_and_write_gpu_buffer(cl::command_queue& cqueue, cl::buffer& inout);
private:
void add_feature_impl(const std::string& feature, const std::type_info& inf);
};
#endif // DYNAMIC_FEATURE_CONFIG_HPP_INCLUDED