diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2021-01-21 19:56:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 19:56:18 +0100 |
commit | a5ef06ec57a1c05aeb4564020022002c2ac53bb5 (patch) | |
tree | 7444f022d3eb82f9263eaf6f524ee731e9cb00d0 | |
parent | 70016e869881df837402def4904b2888247e02d9 (diff) | |
parent | dc82a1fbc89ada39f80513a2ce97ce62ebb1e9ec (diff) |
Merge pull request #410 from jamesjer/master
Use reference types to prevent unnecessary copying
-rw-r--r-- | src/kernel_preprocessor.cpp | 2 | ||||
-rw-r--r-- | src/tuning/tuning.cpp | 8 | ||||
-rw-r--r-- | src/tuning/tuning_api.cpp | 2 | ||||
-rw-r--r-- | test/test_utilities.cpp | 4 |
4 files changed, 8 insertions, 8 deletions
diff --git a/src/kernel_preprocessor.cpp b/src/kernel_preprocessor.cpp index bc2ab540..abe0cd76 100644 --- a/src/kernel_preprocessor.cpp +++ b/src/kernel_preprocessor.cpp @@ -218,7 +218,7 @@ void ArrayToRegister(std::string &source_line, const DefinesIntMap& defines, const std::unordered_map<std::string, size_t>& arrays_to_registers, const size_t num_brackets) { - for (const auto array_name_map : arrays_to_registers) { // only if marked to be promoted + for (const auto& array_name_map : arrays_to_registers) { // only if marked to be promoted // Outside of a function if (num_brackets == 0) { diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp index be6b233e..4160faf7 100644 --- a/src/tuning/tuning.cpp +++ b/src/tuning/tuning.cpp @@ -62,7 +62,7 @@ void PrintTimingsToFileAsJSON(const std::string &filename, fprintf(file, " \"parameters\": {"); auto num_configs = result.config.size(); auto p = size_t{0}; - for (const auto parameter : result.config) { + for (const auto& parameter : result.config) { fprintf(file, "\"%s\": %zu", parameter.first.c_str(), parameter.second); if (p < num_configs -1 ) { fprintf(file, ","); } ++p; @@ -336,7 +336,7 @@ void Tuner(int argc, char* argv[], const int V, printf(" %6.1lf |", settings.metric_amount / (time_ms * 1.0e6)); printf(" %sresults match%s |\n", kPrintSuccess.c_str(), kPrintEnd.c_str()); } - catch (CLCudaAPIBuildError) { + catch (CLCudaAPIBuildError&) { const auto status_code = DispatchExceptionCatchAll(true); printf(" %scompilation error: %5d%s |", kPrintError.c_str(), static_cast<int>(status_code), kPrintEnd.c_str()); @@ -365,7 +365,7 @@ void Tuner(int argc, char* argv[], const int V, // Computes and prints some other statistics auto average_ms = 0.0; - for (const auto result : results) { average_ms += result.score; } + for (const auto& result : results) { average_ms += result.score; } average_ms /= results.size(); printf("\n"); printf("* Got average result of %.2lf ms", average_ms); @@ -380,7 +380,7 @@ void Tuner(int argc, char* argv[], const int V, printf("* Best parameters: "); auto best_string = std::string{""}; auto i = size_t{0}; - for (const auto config : best_configuration->config) { + for (const auto& config : best_configuration->config) { best_string += "" + config.first + "=" + ToString(config.second); if (i < best_configuration->config.size() - 1) { best_string += " "; } ++i; diff --git a/src/tuning/tuning_api.cpp b/src/tuning/tuning_api.cpp index 2cc9b786..8c83409c 100644 --- a/src/tuning/tuning_api.cpp +++ b/src/tuning/tuning_api.cpp @@ -374,7 +374,7 @@ StatusCode TunerAPI(Queue &queue, const Arguments<T> &args, const int V, if (best_time_ms == 0.0) { return StatusCode::kUnexpectedError; } // Stores the best parameters - for (const auto config : best_configuration->config) { + for (const auto& config : best_configuration->config) { parameters[config.first] = config.second; } return StatusCode::kSuccess; diff --git a/test/test_utilities.cpp b/test/test_utilities.cpp index c43200b9..8029d259 100644 --- a/test/test_utilities.cpp +++ b/test/test_utilities.cpp @@ -131,7 +131,7 @@ void OverrideParametersFromJSONFiles(const std::vector<std::string>& file_names, // Retrieves the best parameters for each file from disk BestParametersCollection all_parameters; - for (const auto json_file_name : file_names) { + for (const auto& json_file_name : file_names) { GetBestParametersFromJSONFile(json_file_name, all_parameters, precision); } @@ -199,7 +199,7 @@ void GetBestParametersFromJSONFile(const std::string& file_name, // Creates the list of parameters fprintf(stdout, "* Found parameters for kernel '%s': { ", kernel_family.c_str()); - for (const auto config : config_split) { + for (const auto& config : config_split) { const auto params_split = split(config, '='); if (params_split.size() != 2) { break; } const auto parameter_name = params_split[0]; |