Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "tunings" Command Line Option #333

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 90 additions & 32 deletions src/common/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,40 +612,94 @@ void Executor::setupSuite()
//
// Make a single ordering of tuning names for each variant across kernels.
//
// Determine which tunings to execute from input.
const Svector& selected_tuning_names = run_params.getTuningInput();
const Svector& excluded_tuning_names = run_params.getExcludeTuningInput();
// Constuct set of all possible tunings
set<string> all_tunings;
for (VariantID vid : variant_ids) {
std::unordered_map<std::string, size_t> tuning_names_order_map;
for (const KernelBase* kernel : kernels) {
for (std::string const& tuning_name :
kernel->getVariantTuningNames(vid)) {
if (tuning_names_order_map.find(tuning_name) ==
tuning_names_order_map.end()) {
tuning_names_order_map.emplace(
tuning_name, tuning_names_order_map.size());
}
all_tunings.insert(tuning_name);
}
}
tuning_names[vid].resize(tuning_names_order_map.size());
for (auto const& tuning_name_idx_pair : tuning_names_order_map) {
tuning_names[vid][tuning_name_idx_pair.second] = tuning_name_idx_pair.first;
}
// Check for invalid tuning input
Svector invalid;
for (string const& tuning_name: selected_tuning_names) {
if (all_tunings.find(tuning_name) == all_tunings.end()) {
invalid.push_back(tuning_name);
}
// reorder to put "default" first
auto default_order_iter = tuning_names_order_map.find(KernelBase::getDefaultTuningName());
if (default_order_iter != tuning_names_order_map.end()) {
size_t default_idx = default_order_iter->second;
std::string default_name = std::move(tuning_names[vid][default_idx]);
tuning_names[vid].erase(tuning_names[vid].begin()+default_idx);
tuning_names[vid].emplace(tuning_names[vid].begin(), std::move(default_name));
}
run_params.setInvalidTuningInput(invalid);
// Check for invalid exclude tuning input
invalid.clear();
for (string const& tuning_name: excluded_tuning_names) {
if (all_tunings.find(tuning_name) == all_tunings.end()) {
invalid.push_back(tuning_name);
}
}

//
// If we've gotten to this point, we have good input to run.
//
if ( run_params.getInputState() != RunParams::DryRun &&
run_params.getInputState() != RunParams::CheckRun ) {
run_params.setInputState(RunParams::PerfRun);
run_params.setInvalidExcludeTuningInput(invalid);
// Validate invalid input
if ( !(run_params.getInvalidTuningInput().empty()) ||
!(run_params.getInvalidExcludeTuningInput().empty())) {
run_params.setInputState(RunParams::BadInput);
}

if (run_params.getInputState() != RunParams::BadInput) { // If tunings input is valid
for (VariantID vid : variant_ids) {
std::unordered_map<std::string, size_t> tuning_names_order_map;
for (const KernelBase* kernel : kernels) {
for (std::string const& tuning_name :
kernel->getVariantTuningNames(vid)) {
if (tuning_names_order_map.find(tuning_name) ==
tuning_names_order_map.end()) {
if ((selected_tuning_names.empty() || find(selected_tuning_names.begin(), selected_tuning_names.end(), tuning_name) != selected_tuning_names.end()) // If argument is not provided or name is selected
&&
find(excluded_tuning_names.begin(), excluded_tuning_names.end(), tuning_name) == excluded_tuning_names.end()) { // name does not exist in exclusion list
tuning_names_order_map.emplace(
MrBurmark marked this conversation as resolved.
Show resolved Hide resolved
tuning_name, tuning_names_order_map.size()); // Add tuning name to map
}
}
}
}

tuning_names[vid].resize(tuning_names_order_map.size());
for (auto const& tuning_name_idx_pair : tuning_names_order_map) {
tuning_names[vid][tuning_name_idx_pair.second] = tuning_name_idx_pair.first;
}
// reorder to put "default" first
auto default_order_iter = tuning_names_order_map.find(KernelBase::getDefaultTuningName());
if (default_order_iter != tuning_names_order_map.end()) {
size_t default_idx = default_order_iter->second;
std::string default_name = std::move(tuning_names[vid][default_idx]);
tuning_names[vid].erase(tuning_names[vid].begin()+default_idx);
tuning_names[vid].emplace(tuning_names[vid].begin(), std::move(default_name));
}
}

// Add tunings to Adiak metadata
#if defined(RAJA_PERFSUITE_USE_CALIPER)
std::set<std::string> tunings_set;
for (VariantID vid : variant_ids) {
for (std::string const& tuning_name : tuning_names[vid]) {
tunings_set.emplace(tuning_name);
}
}
adiak::value("tunings", tunings_set);
#endif

//
// If we've gotten to this point, we have good input to run.
//
if ( run_params.getInputState() != RunParams::DryRun &&
run_params.getInputState() != RunParams::CheckRun ) {
run_params.setInputState(RunParams::PerfRun);
}

} // tuning input looks good

} // kernel and variant input both look good

} // if kernel input looks good
Expand Down Expand Up @@ -919,22 +973,26 @@ void Executor::runKernel(KernelBase* kernel, bool print_kernel_name)

if ( run_params.showProgress() ) {
if ( kernel->hasVariantDefined(vid) ) {
getCout() << " Running ";
getCout() << "\tRunning ";
} else {
getCout() << " No ";
getCout() << "\tNo ";
}
getCout() << getVariantName(vid) << " variant" << endl;
}

for (size_t tune_idx = 0; tune_idx < kernel->getNumVariantTunings(vid); ++tune_idx) {

if ( run_params.showProgress() ) {
getCout() << " Running "
<< kernel->getVariantTuningName(vid, tune_idx) << " tuning";
std::string const& tuning_name = kernel->getVariantTuningName(vid, tune_idx);
if (find(tuning_names[vid].begin(), tuning_names[vid].end(), tuning_name) != tuning_names[vid].end()) { // Check if valid tuning
if ( run_params.showProgress() ) {
getCout() << "\t\tRunning " << tuning_name << " tuning";
}
kernel->execute(vid, tune_idx); // Execute kernel
if ( run_params.showProgress() ) {
getCout() << " -- " << kernel->getLastTime() << " sec." << endl;
}
}
kernel->execute(vid, tune_idx);
if ( run_params.showProgress() ) {
getCout() << " -- " << kernel->getLastTime() << " sec." << endl;
else {
MrBurmark marked this conversation as resolved.
Show resolved Hide resolved
getCout() << "\t\tSkipping " << tuning_name << " tuning" << endl;
}
}
} // loop over variants
Expand Down
68 changes: 68 additions & 0 deletions src/common/RunParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ RunParams::RunParams(int argc, char** argv)
invalid_variant_input(),
exclude_variant_input(),
invalid_exclude_variant_input(),
tuning_input(),
invalid_tuning_input(),
exclude_tuning_input(),
invalid_exclude_tuning_input(),
feature_input(),
invalid_feature_input(),
exclude_feature_input(),
Expand Down Expand Up @@ -156,6 +160,24 @@ void RunParams::print(std::ostream& str) const
str << "\n\t" << invalid_exclude_variant_input[j];
}

str << "\n tuning_input = ";
for (size_t j = 0; j < tuning_input.size(); ++j) {
str << "\n\t" << tuning_input[j];
}
str << "\n invalid_tuning_input = ";
for (size_t j = 0; j < invalid_tuning_input.size(); ++j) {
str << "\n\t" << invalid_tuning_input[j];
}

str << "\n exclude_tuning_input = ";
for (size_t j = 0; j < exclude_tuning_input.size(); ++j) {
str << "\n\t" << exclude_tuning_input[j];
}
str << "\n invalid_exclude_tuning_input = ";
for (size_t j = 0; j < invalid_exclude_tuning_input.size(); ++j) {
str << "\n\t" << invalid_exclude_tuning_input[j];
}

str << "\n feature_input = ";
for (size_t j = 0; j < feature_input.size(); ++j) {
str << "\n\t" << feature_input[j];
Expand Down Expand Up @@ -534,6 +556,37 @@ void RunParams::parseCommandLineOptions(int argc, char** argv)
}
}
}
} else if ( std::string(argv[i]) == std::string("--tunings") ||
std::string(argv[i]) == std::string("-t") ) {
michaelmckinsey1 marked this conversation as resolved.
Show resolved Hide resolved

bool done = false;
i++;
while ( i < argc && !done ) {
opt = std::string(argv[i]);
if ( opt.at(0) == '-' ) {
i--;
done = true;
} else {
tuning_input.push_back(opt);
++i;
}
}

} else if ( std::string(argv[i]) == std::string("--exclude-tunings") ||
std::string(argv[i]) == std::string("-et") ) {

bool done = false;
i++;
while ( i < argc && !done ) {
opt = std::string(argv[i]);
if ( opt.at(0) == '-' ) {
i--;
done = true;
} else {
exclude_tuning_input.push_back(opt);
++i;
}
}

} else if ( std::string(argv[i]) == std::string("--features") ||
std::string(argv[i]) == std::string("-f") ) {
Expand Down Expand Up @@ -751,6 +804,21 @@ void RunParams::printHelpMessage(std::ostream& str) const
<< "\t\t --exclude-variants RAJA_CUDA (exclude all RAJA_CUDA kernel variants)\n"
<< "\t\t -ev Base_Seq RAJA_CUDA (exclude Base_Seq and RAJA_CUDA variants)\n\n";

str << "\t --tunings, -t <space-separated strings> [Default is run all]\n"
<< "\t (names of tunings to run)\n"
<< "\t Note: knowing which tunings are available requires knowledge about the variants,\n"
<< "\t since available tunings depend on the given variant (and potentially other args).\n";
str << "\t\t Examples...\n"
<< "\t\t --tunings default (run all default tunings)\n"
<< "\t\t -t default block_128 (run default and block_128 tunings)\n\n";

str << "\t --exclude-tunings, -et <space-separated strings> [Default is exclude none]\n"
<< "\t (names of tunings to exclude)\n"
<< "\t See --tunings for more information.\n";
str << "\t\t Examples...\n"
<< "\t\t --exclude-tunings library (exclude all library tunings)\n"
<< "\t\t -et default library (exclude default and library tunings)\n\n";

str << "\t --seq-data-space, -sds <string> [Default is Host]\n"
<< "\t (names of data space to use)\n";
str << "\t\t Examples...\n"
Expand Down
18 changes: 18 additions & 0 deletions src/common/RunParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ class RunParams {
const std::vector<std::string>& getInvalidExcludeVariantInput() const
{ return invalid_exclude_variant_input; }

const std::vector<std::string>& getTuningInput() const
{ return tuning_input; }
void setInvalidTuningInput( std::vector<std::string>& svec )
{ invalid_tuning_input = svec; }
const std::vector<std::string>& getInvalidTuningInput() const
{ return invalid_tuning_input; }

const std::vector<std::string>& getExcludeTuningInput() const
{ return exclude_tuning_input; }
void setInvalidExcludeTuningInput( std::vector<std::string>& svec )
{ invalid_exclude_tuning_input = svec; }
const std::vector<std::string>& getInvalidExcludeTuningInput() const
{ return invalid_exclude_tuning_input; }

const std::vector<std::string>& getFeatureInput() const
{ return feature_input; }
void setInvalidFeatureInput( std::vector<std::string>& svec )
Expand Down Expand Up @@ -274,6 +288,10 @@ class RunParams {
std::vector<std::string> invalid_variant_input;
std::vector<std::string> exclude_variant_input;
std::vector<std::string> invalid_exclude_variant_input;
std::vector<std::string> tuning_input;
std::vector<std::string> invalid_tuning_input;
std::vector<std::string> exclude_tuning_input;
std::vector<std::string> invalid_exclude_tuning_input;
std::vector<std::string> feature_input;
std::vector<std::string> invalid_feature_input;
std::vector<std::string> exclude_feature_input;
Expand Down