summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-11-22 20:53:20 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2017-11-22 20:53:20 +0100
commit9527c89c3087b4c92bd988340c3b25c1c5e70d8f (patch)
tree9bc6963f4050461f405d7da48b4f632eb5346137
parent8c9ecd97366980200a58a4b8cd77bd7f8b859abc (diff)
Made parameter override in the clients a command-line argument and added support for multi-kernel routines
-rw-r--r--src/utilities/utilities.cpp2
-rw-r--r--src/utilities/utilities.hpp1
-rw-r--r--test/performance/client.cpp11
-rw-r--r--test/test_utilities.cpp74
-rw-r--r--test/test_utilities.hpp11
5 files changed, 71 insertions, 28 deletions
diff --git a/src/utilities/utilities.cpp b/src/utilities/utilities.cpp
index 1546fbf5..7acba0bb 100644
--- a/src/utilities/utilities.cpp
+++ b/src/utilities/utilities.cpp
@@ -108,6 +108,7 @@ std::string ToString(double value) {
result << std::fixed << std::setprecision(2) << value;
return result.str();
}
+template <> std::string ToString<std::string>(std::string value) { return value; }
// If not possible directly: special cases for complex data-types
template <>
@@ -273,6 +274,7 @@ template float GetArgument<float>(const std::vector<std::string>&, std::string&,
template double GetArgument<double>(const std::vector<std::string>&, std::string&, const std::string&, const double);
template float2 GetArgument<float2>(const std::vector<std::string>&, std::string&, const std::string&, const float2);
template double2 GetArgument<double2>(const std::vector<std::string>&, std::string&, const std::string&, const double2);
+template std::string GetArgument<std::string>(const std::vector<std::string>&, std::string&, const std::string&, const std::string);
template Layout GetArgument<Layout>(const std::vector<std::string>&, std::string&, const std::string&, const Layout);
template Transpose GetArgument<Transpose>(const std::vector<std::string>&, std::string&, const std::string&, const Transpose);
template Side GetArgument<Side>(const std::vector<std::string>&, std::string&, const std::string&, const Side);
diff --git a/src/utilities/utilities.hpp b/src/utilities/utilities.hpp
index e26721b3..a4f4fab0 100644
--- a/src/utilities/utilities.hpp
+++ b/src/utilities/utilities.hpp
@@ -236,6 +236,7 @@ struct Arguments {
size_t step = 1;
size_t num_steps = 0;
size_t num_runs = 10;
+ std::vector<std::string> tuner_files = {};
#ifdef CLBLAST_REF_CUBLAS
void* cublas_handle; // cublasHandle_t
#endif
diff --git a/test/performance/client.cpp b/test/performance/client.cpp
index b2b579b1..8b18b9a9 100644
--- a/test/performance/client.cpp
+++ b/test/performance/client.cpp
@@ -146,6 +146,13 @@ Arguments<U> Client<T,U>::ParseArguments(int argc, char *argv[], const size_t le
args.no_abbrv = CheckArgument(command_line_args, help, kArgNoAbbreviations);
warm_up_ = CheckArgument(command_line_args, help, kArgWarmUp);
+ // Parse the optional JSON file name arguments
+ const auto tuner_files_default = std::string{"<none>"};
+ const auto tuner_files_string = GetArgument(command_line_args, help, kArgTunerFiles, tuner_files_default);
+ if (tuner_files_string != tuner_files_default) {
+ args.tuner_files = split(tuner_files_string, ',');
+ }
+
// Prints the chosen (or defaulted) arguments to screen. This also serves as the help message,
// which is thus always displayed (unless silence is specified).
if (!args.silent) { fprintf(stdout, "%s\n", help.c_str()); }
@@ -196,8 +203,8 @@ void Client<T,U>::PerformanceTest(Arguments<U> &args, const SetMetric set_sizes)
if (args.compare_cublas) { cublasSetup(args); }
#endif
- // Optionally overrides parameters if "CLBLAST_JSON_FILE_OVERRIDE" environmental variable is set
- OverrideParametersFromJSONFiles(device(), args.precision);
+ // Optionally overrides parameters if tuner files are given (semicolon separated)
+ OverrideParametersFromJSONFiles(args.tuner_files, device(), args.precision);
// Prints the header of the output table
PrintTableHeader(args);
diff --git a/test/test_utilities.cpp b/test/test_utilities.cpp
index b7aef0a0..fb85e4a2 100644
--- a/test/test_utilities.cpp
+++ b/test/test_utilities.cpp
@@ -14,6 +14,7 @@
#include <string>
#include <vector>
#include <cctype>
+#include <algorithm>
#include "test/test_utilities.hpp"
@@ -115,22 +116,46 @@ void FloatToHalfBuffer(std::vector<half>& result, const std::vector<float>& sour
// =================================================================================================
-void OverrideParametersFromJSONFiles(const cl_device_id device, const Precision precision) {
- const auto json_file_name = std::getenv("CLBLAST_JSON_FILE_OVERRIDE");
- if (json_file_name == nullptr) { return; }
- const auto json_file_name_string = std::string{json_file_name};
- OverrideParametersFromJSONFile(json_file_name_string, device, precision);
+void OverrideParametersFromJSONFiles(const std::vector<std::string>& file_names,
+ const cl_device_id device, const Precision precision) {
+
+ // Retrieves the best parameters for each file from disk
+ BestParametersCollection all_parameters = {};
+ for (const auto json_file_name : file_names) {
+ GetBestParametersFromJSONFile(json_file_name, all_parameters);
+ }
+
+ // Applies the parameter override
+ for (const auto &best_parameters : all_parameters) {
+ const auto kernel_family = best_parameters.first;
+ const auto parameters = best_parameters.second;
+ const auto status = OverrideParameters(device, kernel_family, precision, parameters);
+ if (status == StatusCode::kSuccess) {
+ fprintf(stdout, "* Applying parameter override successfully for '%s'\n",
+ kernel_family.c_str());
+ } else {
+ fprintf(stdout, "* Error while applying parameter override for '%s'\n",
+ kernel_family.c_str());
+ }
+ }
+
+ if (file_names.size() > 0) {
+ fprintf(stdout, "\n");
+ }
}
-void OverrideParametersFromJSONFile(const std::string& file_name,
- const cl_device_id device, const Precision precision) {
+void GetBestParametersFromJSONFile(const std::string& file_name,
+ BestParametersCollection& all_parameters) {
std::ifstream json_file(file_name);
- if (!json_file) { return; }
+ if (!json_file) {
+ fprintf(stdout, "* Could not open file '%s'\n", file_name.c_str());
+ return;
+ }
fprintf(stdout, "* Reading override-parameters from '%s'\n", file_name.c_str());
std::string line;
- auto kernel_name = std::string{};
+ auto kernel_family = std::string{};
while (std::getline(json_file, line)) {
const auto line_split = split(line, ':');
if (line_split.size() != 2) { continue; }
@@ -139,20 +164,29 @@ void OverrideParametersFromJSONFile(const std::string& file_name,
if (line_split[0] == " \"kernel_family\"") {
const auto value_split = split(line_split[1], '\"');
if (value_split.size() != 3) { break; }
- kernel_name = value_split[1];
- kernel_name[0] = toupper(kernel_name[0]); // because of a tuner - database naming mismatch
+ kernel_family = value_split[1];
+ kernel_family[0] = toupper(kernel_family[0]); // because of a tuner - database naming mismatch
+ kernel_family.erase(std::remove(kernel_family.begin(), kernel_family.end(), '_'), kernel_family.end());
+ kernel_family.erase(std::remove(kernel_family.begin(), kernel_family.end(), '1'), kernel_family.end());
+ kernel_family.erase(std::remove(kernel_family.begin(), kernel_family.end(), '2'), kernel_family.end());
+ kernel_family.erase(std::remove(kernel_family.begin(), kernel_family.end(), '3'), kernel_family.end());
}
// Retrieves the best-parameters and sets the override
- if (line_split[0] == " \"best_parameters\"" && kernel_name != "") {
+ if (line_split[0] == " \"best_parameters\"" && kernel_family != std::string{""}) {
const auto value_split = split(line_split[1], '\"');
if (value_split.size() != 3) { break; }
const auto config_split = split(value_split[1], ' ');
if (config_split.size() == 0) { break; }
+ // Loads an existing list of parameters for this kernel family (if present)
+ BestParameters parameters;
+ if (all_parameters.count(kernel_family) == 1) {
+ parameters = all_parameters.at(kernel_family);
+ }
+
// Creates the list of parameters
- fprintf(stdout, "* Found parameters for kernel '%s': { ", kernel_name.c_str());
- std::unordered_map<std::string,size_t> parameters;
+ fprintf(stdout, "* Found parameters for kernel '%s': { ", kernel_family.c_str());
for (const auto config : config_split) {
const auto params_split = split(config, '=');
if (params_split.size() != 2) { break; }
@@ -165,21 +199,15 @@ void OverrideParametersFromJSONFile(const std::string& file_name,
}
fprintf(stdout, "}\n");
- // Applies the parameter override
- const auto status = OverrideParameters(device, kernel_name, precision, parameters);
- if (status != StatusCode::kSuccess) { break; }
-
- // Ends this function (success)
- fprintf(stdout, "* Applying parameter override successfully\n");
- fprintf(stdout, "\n");
+ // Sets the new (possibly extended) parameter map as the final result
+ all_parameters[kernel_family] = parameters;
json_file.close();
return;
}
}
// Ends this function (failure)
- fprintf(stdout, "* Failed to extract parameters from the file, continuing regularly\n");
- fprintf(stdout, "\n");
+ fprintf(stdout, "* Failed to extract parameters from this file, continuing\n");
json_file.close();
}
diff --git a/test/test_utilities.hpp b/test/test_utilities.hpp
index c91e9d1b..97697e50 100644
--- a/test/test_utilities.hpp
+++ b/test/test_utilities.hpp
@@ -32,6 +32,7 @@ constexpr auto kArgComparecublas = "cublas";
constexpr auto kArgStepSize = "step";
constexpr auto kArgNumSteps = "num_steps";
constexpr auto kArgWarmUp = "warm_up";
+constexpr auto kArgTunerFiles = "tuner_files";
// The test-specific arguments in string form
constexpr auto kArgFullTest = "full_test";
@@ -131,9 +132,13 @@ inline std::vector<std::string> split(const std::string &s, char delimiter) {
// =================================================================================================
-void OverrideParametersFromJSONFiles(const cl_device_id device, const Precision precision);
-void OverrideParametersFromJSONFile(const std::string& file_name,
- const cl_device_id device, const Precision precision);
+using BestParameters = std::unordered_map<std::string,size_t>;
+using BestParametersCollection = std::unordered_map<std::string, BestParameters>;
+
+void OverrideParametersFromJSONFiles(const std::vector<std::string>& file_names,
+ const cl_device_id device, const Precision precision);
+void GetBestParametersFromJSONFile(const std::string& file_name,
+ BestParametersCollection& all_parameters);
// =================================================================================================
} // namespace clblast