Skip to content

Commit

Permalink
Merge pull request #236 from intel/develop
Browse files Browse the repository at this point in the history
Add option to set min auto-tuner trial time.
  • Loading branch information
chuckyount authored Aug 22, 2019
2 parents 9683a70 + a877624 commit c81392e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/common/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace yask {
// for numbers above 9 (at least up to 99).

// Format: "major.minor.patch".
const string version = "3.01.05";
const string version = "3.02.00";

string yask_get_version_string() {
return version;
Expand Down
48 changes: 26 additions & 22 deletions src/kernel/lib/auto_tuner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ namespace yask {
STATE_VARS(this);
if (tune_mini_blks())
DEBUG_MSG(_name << ": best-mini-block-size: " <<
target_sizes().makeDimValStr(" * "));
target_sizes().removeDim(step_posn).makeDimValStr(" * "));
else
DEBUG_MSG(_name << ": best-block-size: " <<
target_sizes().makeDimValStr(" * ") << endl <<
target_sizes().removeDim(step_posn).makeDimValStr(" * ") << endl <<
_name << ": mini-block-size: " <<
_settings->_mini_block_sizes.makeDimValStr(" * "));
_settings->_mini_block_sizes.removeDim(step_posn).makeDimValStr(" * "));
DEBUG_MSG(_name << ": sub-block-size: " <<
_settings->_sub_block_sizes.makeDimValStr(" * "));
_settings->_sub_block_sizes.removeDim(step_posn).makeDimValStr(" * "));
}

// Access settings.
Expand Down Expand Up @@ -238,7 +238,7 @@ namespace yask {
timer.clear();
idx_t steps = steps_done;
steps_done = 0;

// Leave if done.
if (done)
return;
Expand All @@ -247,15 +247,22 @@ namespace yask {
if (!nullop)
return;

// Cumulative stats.
// Cumulative stats and rate.
csteps += steps;
ctime += etime;

double rate = (ctime > 0.) ? (double(csteps) / ctime) : 0.;
double min_secs = _settings->_tuner_min_secs;
TRACE_MSG(_name << " eval() callback: " << steps << " step(s) in " <<
etime << " secs; " << csteps << " step(s) in " <<
ctime << " secs (" << rate <<
" steps/sec) cumulative; best-rate = " << best_rate <<
"; min-secs = " << min_secs);

// Still in warmup?
if (in_warmup) {

// Warmup not done?
if (ctime < warmup_secs && csteps < warmup_steps)
if (ctime < max(warmup_secs, min_secs) && csteps < warmup_steps)
return;

// Done.
Expand Down Expand Up @@ -294,12 +301,7 @@ namespace yask {
return;
}

// Calc perf.
double rate = (ctime > 0.) ? (double(csteps) / ctime) : 0.;
TRACE_MSG(_name << ": " <<
makeNumStr(rate) << " steps/sec (" <<
csteps << " steps(s) in " << makeNumStr(ctime) <<
" secs)");
// Determine whether we've done enough.
bool rate_ok = false;

// If the current rate is much less than the best,
Expand All @@ -315,14 +317,6 @@ namespace yask {
if (!rate_ok)
return;

// Print progress and reset vars for next time.
DEBUG_MSG(_name << ": search-dist=" << radius << ": " <<
makeNumStr(rate) << " steps/sec (" <<
csteps << " steps(s) in " << makeNumStr(ctime) <<
" secs) with size " << target_sizes().makeDimValStr(" * "));
csteps = 0;
ctime = 0.;

// Save result.
results[target_sizes()] = rate;
bool is_better = rate > best_rate;
Expand All @@ -332,6 +326,16 @@ namespace yask {
better_neigh_found = true;
}

// Print progress and reset vars for next time.
DEBUG_MSG(_name << ": search-dist=" << radius << ": " <<
makeNumStr(rate) << " steps/sec (" <<
csteps << " steps(s) in " << makeNumStr(ctime) <<
" secs) with size " <<
target_sizes().removeDim(step_posn).makeDimValStr(" * ") <<
(is_better ? " -- best so far" : ""));
csteps = 0;
ctime = 0.;

// At this point, we have gathered perf info on the current settings.
// Now, we need to determine next unevaluated point in search space.
while (true) {
Expand Down
1 change: 0 additions & 1 deletion src/kernel/lib/auto_tuner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace yask {
double warmup_steps = 100;
double warmup_secs = 0.5; // end warmup when either warmup_steps OR warmup_secs is reached.
idx_t min_steps = 100;
double min_secs = 0.25; // eval when either min_steps OR min_secs is reached.
double cutoff = 0.8; // can stop eval if current rate < best rate * cutoff;
idx_t max_radius = 8; // starting search radius.
idx_t min_dist = 4; // min distance to move in any direction per eval.
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ namespace yask {
"Adjust block sizes *during* normal operation to tune for performance. "
"May cause varying performance between steps.",
_do_auto_tune));
parser.add_option(new CommandLineParser::DoubleOption
("auto_tune_min_secs",
"Minimum seconds to run trial during auto-tuning for trial settings to be "
"considered better than the existing best.",
_tuner_min_secs));
parser.add_option(new CommandLineParser::BoolOption
("auto_tune_mini_blocks",
"Apply the auto-tuner to mini-block sizes instead of block sizes. "
Expand Down
1 change: 1 addition & 0 deletions src/kernel/lib/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ namespace yask {
bool _do_auto_tune = false; // whether to do auto-tuning.
bool _tune_mini_blks = false; // auto-tune mini-blks instead of blks.
bool _allow_pack_tuners = false; // allow per-pack tuners when possible.
double _tuner_min_secs = 0.25; // min time to run tuner for new better setting.

// Debug.
bool force_scalar = false; // Do only scalar ops.
Expand Down
42 changes: 41 additions & 1 deletion src/kernel/lib/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,28 @@ namespace yask {
return false;
}

// Get one double value from args[argi].
// On failure, print msg using string from args[argi-1] and exit.
// On success, increment argi and return value.
double CommandLineParser::OptionBase::_double_val(const vector<string>& args,
int& argi)
{
if (size_t(argi) >= args.size() || args[argi].length() == 0) {
THROW_YASK_EXCEPTION("Error: no argument for option '" + args[argi - 1] + "'");
}

const char* nptr = args[argi].c_str();
char* endptr = 0;
double val = strtod(nptr, &endptr);
if (val == HUGE_VAL || val == -HUGE_VAL || *endptr != '\0') {
THROW_YASK_EXCEPTION("Error: argument for option '" + args[argi - 1] +
"' is not a valid floating-point number");
}

argi++;
return val;
}

// Get one idx_t value from args[argi].
// On failure, print msg using string from args[argi-1] and exit.
// On success, increment argi and return value.
Expand Down Expand Up @@ -472,11 +494,29 @@ namespace yask {
(_val ? "true" : "false") << "." << endl;
}

// Check for a double option.
bool CommandLineParser::DoubleOption::check_arg(const std::vector<std::string>& args,
int& argi) {
if (_check_arg(args, argi, _name)) {
_val = _double_val(args, argi);
return true;
}
return false;
}

// Print help on a double option.
void CommandLineParser::DoubleOption::print_help(ostream& os,
int width) const {
_print_help(os, _name + " <floating-point number>", width);
os << _help_leader << _current_value_str <<
_val << "." << endl;
}

// Check for an int option.
bool CommandLineParser::IntOption::check_arg(const std::vector<std::string>& args,
int& argi) {
if (_check_arg(args, argi, _name)) {
_val = (int)_idx_val(args, argi); // TODO: check for under/overflow.
_val = (int)_idx_val(args, argi); // TODO: check for over/underflow.
return true;
}
return false;
Expand Down
19 changes: 19 additions & 0 deletions src/kernel/lib/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ namespace yask {
virtual bool _check_arg(const std::vector<std::string>& args, int& argi,
const std::string& str) const;

// Get one double value from args[argi++].
// Exit on failure.
virtual double _double_val(const std::vector<std::string>& args, int& argi);

// Get one idx_t value from args[argi++].
// Exit on failure.
virtual idx_t _idx_val(const std::vector<std::string>& args, int& argi);
Expand Down Expand Up @@ -407,6 +411,21 @@ namespace yask {
virtual bool check_arg(const std::vector<std::string>& args, int& argi);
};

// An allowed double option.
class DoubleOption : public OptionBase {
double& _val;

public:
DoubleOption(const std::string& name,
const std::string& help_msg,
double& val) :
OptionBase(name, help_msg), _val(val) { }

virtual void print_help(std::ostream& os,
int width) const;
virtual bool check_arg(const std::vector<std::string>& args, int& argi);
};

// An allowed idx_t option.
class IdxOption : public OptionBase {
idx_t& _val;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/yask_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int main(int argc, char** argv)
yk_factory kfac;
yask_output_factory yof;

// Parse options once just to get vars needed for env.
// Parse custom options once just to get vars needed for env.
MySettings opts1(nullptr);
opts1.parse(argc, argv);

Expand Down

0 comments on commit c81392e

Please sign in to comment.