diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2017-11-19 20:05:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-19 20:05:15 +0100 |
commit | da76d7ab81555452a1049eb1a6d130073427067d (patch) | |
tree | 92439d8bee44c34d63f288a73bdc372ba84dc42b /src/tuning/configurations.hpp | |
parent | c41d219ea42087c1b8d933b733b381005123cb91 (diff) | |
parent | defad3d1a249dd5f8c011cf28cc3c888d710d56a (diff) |
Merge pull request #216 from CNugteren/integrated_tuner
Integrated tuner
Diffstat (limited to 'src/tuning/configurations.hpp')
-rw-r--r-- | src/tuning/configurations.hpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/tuning/configurations.hpp b/src/tuning/configurations.hpp new file mode 100644 index 00000000..74679ff6 --- /dev/null +++ b/src/tuning/configurations.hpp @@ -0,0 +1,73 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren <www.cedricnugteren.nl> +// +// This file implements the parameter configurations for the CLBlast auto-tuner (taken from CLTune). +// This is only used for the optional tuner binaries and not part of the core of CLBlast. +// +// ================================================================================================= + +#ifndef CLBLAST_TUNING_CONFIGURATIONS_H_ +#define CLBLAST_TUNING_CONFIGURATIONS_H_ + +#include <vector> +#include <string> +#include <map> + +#include "utilities/utilities.hpp" + +namespace clblast { +// ================================================================================================= + +using Configuration = std::map<std::string, size_t>; +using Parameter = std::pair<std::string, std::vector<size_t>>; +using TransformVector = std::vector<std::vector<std::string>>; + +// Helper structure holding a constraint on parameters. This constraint consists of a constraint +// function object and a vector of parameter names represented as strings. +using ConstraintFunction = std::function<bool(std::vector<size_t>)>; +struct Constraint { + ConstraintFunction valid_if; + std::vector<std::string> parameters; +}; +using Constraints = std::vector<Constraint>; + +// ================================================================================================= + +// Initializes an empty configuration (vector of name/value pairs) and kicks-off the recursive +// function to find all configurations. It also applies the user-defined constraints within. +std::vector<Configuration> SetConfigurations(const std::vector<Parameter> parameters, + const Constraints& constraints); + +// Iterates recursively over all permutations of the user-defined parameters. This code creates +// multiple chains, in which each chain selects a unique combination of values for all parameters. +// At the end of each chain (when all parameters are considered), the function stores the result +// into the configuration list. +void PopulateConfigurations(const std::vector<Parameter> ¶meters, + const size_t index, const Configuration &config, + std::vector<Configuration> &configuration, + const Constraints& constraints); + +// Loops over all user-defined constraints to check whether or not the configuration is valid. +// Assumes initially all configurations are valid, then returns false if one of the constraints has +// not been met. Constraints consist of a user-defined function and a list of parameter names, which +// are replaced by parameter values in this function. +bool ValidConfiguration(const Configuration &config, + const Constraints& constraints); + +// Processes multipliers and dividers to obtain the final thread configuration +std::vector<size_t> SetThreadConfiguration(const Configuration& config, + const std::vector<size_t> base, + const TransformVector& mul_config, + const TransformVector& div_config); + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TUNING_CONFIGURATIONS_H_ +#endif |