From dc82a1fbc89ada39f80513a2ce97ce62ebb1e9ec Mon Sep 17 00:00:00 2001 From: Jerry James Date: Wed, 20 Jan 2021 10:21:36 -0700 Subject: Use reference types to prevent unnecessary copying --- src/kernel_preprocessor.cpp | 2 +- src/tuning/tuning.cpp | 8 ++++---- src/tuning/tuning_api.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') 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& 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(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 &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; -- cgit v1.2.3