summaryrefslogtreecommitdiff
path: root/test/performance
diff options
context:
space:
mode:
authorCNugteren <web@cedricnugteren.nl>2015-06-29 20:38:34 +0200
committerCNugteren <web@cedricnugteren.nl>2015-06-29 20:38:34 +0200
commit2914a285d43cac7e3a9d4885684229fbf82babb0 (patch)
tree01c740740d81fe893e88f40d8385d5c6325fabc0 /test/performance
parente5c0edbfd7dcfe96af6cca6c25ca8b346871b014 (diff)
Re-organized the performance-client infrastructure to avoid code duplication
Diffstat (limited to 'test/performance')
-rw-r--r--test/performance/client.cc458
-rw-r--r--test/performance/client.h104
-rw-r--r--test/performance/routines/xaxpy.cc89
-rw-r--r--test/performance/routines/xgemm.cc107
-rw-r--r--test/performance/routines/xgemv.cc99
-rw-r--r--test/performance/routines/xsymm.cc107
-rw-r--r--test/performance/routines/xsyr2k.cc107
-rw-r--r--test/performance/routines/xsyrk.cc105
8 files changed, 285 insertions, 891 deletions
diff --git a/test/performance/client.cc b/test/performance/client.cc
index b089f925..71471dde 100644
--- a/test/performance/client.cc
+++ b/test/performance/client.cc
@@ -21,323 +21,36 @@
namespace clblast {
// =================================================================================================
-// This is the vector-vector variant of the set-up/tear-down client routine.
+// Constructor
template <typename T>
-void ClientXY(int argc, char *argv[], Routine2<T> client_routine,
- const std::vector<std::string> &options) {
-
- // Function to determine how to find the default value of the leading dimension of matrix A.
- // Note: this is not relevant for this client but given anyway.
- auto default_ld_a = [](const Arguments<T> args) { return args.n; };
-
- // Simple command line argument parser with defaults
- auto args = ParseArguments<T>(argc, argv, options, default_ld_a);
- if (args.print_help) { return; }
-
- // Prints the header of the output table
- PrintTableHeader(args.silent, options);
-
- // Initializes OpenCL and the libraries
- auto platform = Platform(args.platform_id);
- auto device = Device(platform, kDeviceType, args.device_id);
- auto context = Context(device);
- auto queue = CommandQueue(context, device);
- if (args.compare_clblas) { clblasSetup(); }
-
- // Iterates over all "num_step" values jumping by "step" each time
- auto s = size_t{0};
- while(true) {
-
- // Computes the data sizes
- auto x_size = args.n*args.x_inc + args.x_offset;
- auto y_size = args.n*args.y_inc + args.y_offset;
-
- // Populates input host vectors with random data
- std::vector<T> x_source(x_size);
- std::vector<T> y_source(y_size);
- PopulateVector(x_source);
- PopulateVector(y_source);
-
- // Creates the vectors on the device
- auto x_buffer = Buffer(context, CL_MEM_READ_WRITE, x_size*sizeof(T));
- auto y_buffer = Buffer(context, CL_MEM_READ_WRITE, y_size*sizeof(T));
- x_buffer.WriteBuffer(queue, x_size*sizeof(T), x_source);
- y_buffer.WriteBuffer(queue, y_size*sizeof(T), y_source);
-
- // Runs the routine-specific code
- client_routine(args, x_buffer, y_buffer, queue);
-
- // Makes the jump to the next step
- ++s;
- if (s >= args.num_steps) { break; }
- args.n += args.step;
- }
-
- // Cleans-up and returns
- if (args.compare_clblas) { clblasTeardown(); }
-}
-
-// Compiles the above function
-template void ClientXY<float>(int, char **, Routine2<float>, const std::vector<std::string>&);
-template void ClientXY<double>(int, char **, Routine2<double>, const std::vector<std::string>&);
-template void ClientXY<float2>(int, char **, Routine2<float2>, const std::vector<std::string>&);
-template void ClientXY<double2>(int, char **, Routine2<double2>, const std::vector<std::string>&);
-
-// =================================================================================================
-
-// This is the matrix-vector-vector variant of the set-up/tear-down client routine.
-template <typename T>
-void ClientAXY(int argc, char *argv[], Routine3<T> client_routine,
- const std::vector<std::string> &options) {
-
- // Function to determine how to find the default value of the leading dimension of matrix A
- auto default_ld_a = [](const Arguments<T> args) { return args.n; };
-
- // Simple command line argument parser with defaults
- auto args = ParseArguments<T>(argc, argv, options, default_ld_a);
- if (args.print_help) { return; }
-
- // Prints the header of the output table
- PrintTableHeader(args.silent, options);
-
- // Initializes OpenCL and the libraries
- auto platform = Platform(args.platform_id);
- auto device = Device(platform, kDeviceType, args.device_id);
- auto context = Context(device);
- auto queue = CommandQueue(context, device);
- if (args.compare_clblas) { clblasSetup(); }
-
- // Iterates over all "num_step" values jumping by "step" each time
- auto s = size_t{0};
- while(true) {
-
- // Computes the second dimension of the matrix taking the rotation into account
- auto a_two = (args.layout == Layout::kRowMajor) ? args.m : args.n;
-
- // Computes the vector sizes in case the matrix is transposed
- auto a_transposed = (args.a_transpose != Transpose::kNo);
- auto m_real = (a_transposed) ? args.n : args.m;
- auto n_real = (a_transposed) ? args.m : args.n;
-
- // Computes the data sizes
- auto a_size = a_two * args.a_ld + args.a_offset;
- auto x_size = n_real*args.x_inc + args.x_offset;
- auto y_size = m_real*args.y_inc + args.y_offset;
-
- // Populates input host vectors with random data
- std::vector<T> a_source(a_size);
- std::vector<T> x_source(x_size);
- std::vector<T> y_source(y_size);
- PopulateVector(a_source);
- PopulateVector(x_source);
- PopulateVector(y_source);
-
- // Creates the vectors on the device
- auto a_buffer = Buffer(context, CL_MEM_READ_WRITE, a_size*sizeof(T));
- auto x_buffer = Buffer(context, CL_MEM_READ_WRITE, x_size*sizeof(T));
- auto y_buffer = Buffer(context, CL_MEM_READ_WRITE, y_size*sizeof(T));
- a_buffer.WriteBuffer(queue, a_size*sizeof(T), a_source);
- x_buffer.WriteBuffer(queue, x_size*sizeof(T), x_source);
- y_buffer.WriteBuffer(queue, y_size*sizeof(T), y_source);
-
- // Runs the routine-specific code
- client_routine(args, a_buffer, x_buffer, y_buffer, queue);
-
- // Makes the jump to the next step
- ++s;
- if (s >= args.num_steps) { break; }
- args.m += args.step;
- args.n += args.step;
- args.a_ld += args.step;
- }
-
- // Cleans-up and returns
- if (args.compare_clblas) { clblasTeardown(); }
-}
-
-// Compiles the above function
-template void ClientAXY<float>(int, char **, Routine3<float>, const std::vector<std::string>&);
-template void ClientAXY<double>(int, char **, Routine3<double>, const std::vector<std::string>&);
-template void ClientAXY<float2>(int, char **, Routine3<float2>, const std::vector<std::string>&);
-template void ClientAXY<double2>(int, char **, Routine3<double2>, const std::vector<std::string>&);
-
-// =================================================================================================
-
-// This is the matrix-matrix variant of the set-up/tear-down client routine.
-template <typename T>
-void ClientAC(int argc, char *argv[], Routine2<T> client_routine,
- const std::vector<std::string> &options) {
-
- // Function to determine how to find the default value of the leading dimension of matrix A
- auto default_ld_a = [](const Arguments<T> args) { return args.k; };
-
- // Simple command line argument parser with defaults
- auto args = ParseArguments<T>(argc, argv, options, default_ld_a);
- if (args.print_help) { return; }
-
- // Prints the header of the output table
- PrintTableHeader(args.silent, options);
-
- // Initializes OpenCL and the libraries
- auto platform = Platform(args.platform_id);
- auto device = Device(platform, kDeviceType, args.device_id);
- auto context = Context(device);
- auto queue = CommandQueue(context, device);
- if (args.compare_clblas) { clblasSetup(); }
-
- // Computes whether or not the matrices are transposed. Note that we assume a default of
- // column-major and no-transpose. If one of them is different (but not both), then rotated
- // is considered true.
- auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) ||
- (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo);
-
- // Iterates over all "num_step" values jumping by "step" each time
- auto s = size_t{0};
- while(true) {
-
- // Computes the data sizes
- auto a_two = (a_rotated) ? args.n : args.k;
- auto a_size = a_two * args.a_ld + args.a_offset;
- auto c_size = args.n * args.c_ld + args.c_offset;
-
- // Populates input host matrices with random data
- std::vector<T> a_source(a_size);
- std::vector<T> c_source(c_size);
- PopulateVector(a_source);
- PopulateVector(c_source);
-
- // Creates the matrices on the device
- auto a_buffer = Buffer(context, CL_MEM_READ_WRITE, a_size*sizeof(T));
- auto c_buffer = Buffer(context, CL_MEM_READ_WRITE, c_size*sizeof(T));
- a_buffer.WriteBuffer(queue, a_size*sizeof(T), a_source);
- c_buffer.WriteBuffer(queue, c_size*sizeof(T), c_source);
-
- // Runs the routine-specific code
- client_routine(args, a_buffer, c_buffer, queue);
-
- // Makes the jump to the next step
- ++s;
- if (s >= args.num_steps) { break; }
- args.n += args.step;
- args.k += args.step;
- args.a_ld += args.step;
- args.c_ld += args.step;
- }
-
- // Cleans-up and returns
- if (args.compare_clblas) { clblasTeardown(); }
+Client<T>::Client(const Routine run_routine, const Routine run_reference,
+ const std::vector<std::string> &options,
+ const GetMetric get_flops, const GetMetric get_bytes):
+ run_routine_(run_routine),
+ run_reference_(run_reference),
+ options_(options),
+ get_flops_(get_flops),
+ get_bytes_(get_bytes) {
}
-// Compiles the above function
-template void ClientAC<float>(int, char **, Routine2<float>, const std::vector<std::string>&);
-template void ClientAC<double>(int, char **, Routine2<double>, const std::vector<std::string>&);
-template void ClientAC<float2>(int, char **, Routine2<float2>, const std::vector<std::string>&);
-template void ClientAC<double2>(int, char **, Routine2<double2>, const std::vector<std::string>&);
-
-// =================================================================================================
-
-// This is the matrix-matrix-matrix variant of the set-up/tear-down client routine.
-template <typename T>
-void ClientABC(int argc, char *argv[], Routine3<T> client_routine,
- const std::vector<std::string> &options, const bool symmetric) {
-
- // Function to determine how to find the default value of the leading dimension of matrix A
- auto default_ld_a = [&symmetric](const Arguments<T> args) { return (symmetric) ? args.n : args.m; };
-
- // Simple command line argument parser with defaults
- auto args = ParseArguments<T>(argc, argv, options, default_ld_a);
- if (args.print_help) { return; }
- if (symmetric) { args.m = args.n; }
-
- // Prints the header of the output table
- PrintTableHeader(args.silent, options);
-
- // Initializes OpenCL and the libraries
- auto platform = Platform(args.platform_id);
- auto device = Device(platform, kDeviceType, args.device_id);
- auto context = Context(device);
- auto queue = CommandQueue(context, device);
- if (args.compare_clblas) { clblasSetup(); }
-
- // Computes whether or not the matrices are transposed. Note that we assume a default of
- // column-major and no-transpose. If one of them is different (but not both), then rotated
- // is considered true.
- auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) ||
- (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo);
- auto b_rotated = (args.layout == Layout::kColMajor && args.b_transpose != Transpose::kNo) ||
- (args.layout == Layout::kRowMajor && args.b_transpose == Transpose::kNo);
- auto c_rotated = (args.layout == Layout::kRowMajor);
-
- // Iterates over all "num_step" values jumping by "step" each time
- auto s = size_t{0};
- while(true) {
-
- // Computes the data sizes
- auto a_two = (a_rotated) ? args.m : args.k;
- auto b_two = (b_rotated) ? args.k : args.n;
- auto c_two = (c_rotated) ? args.m : args.n;
- auto a_size = a_two * args.a_ld + args.a_offset;
- auto b_size = b_two * args.b_ld + args.b_offset;
- auto c_size = c_two * args.c_ld + args.c_offset;
-
- // Populates input host matrices with random data
- std::vector<T> a_source(a_size);
- std::vector<T> b_source(b_size);
- std::vector<T> c_source(c_size);
- PopulateVector(a_source);
- PopulateVector(b_source);
- PopulateVector(c_source);
-
- // Creates the matrices on the device
- auto a_buffer = Buffer(context, CL_MEM_READ_WRITE, a_size*sizeof(T));
- auto b_buffer = Buffer(context, CL_MEM_READ_WRITE, b_size*sizeof(T));
- auto c_buffer = Buffer(context, CL_MEM_READ_WRITE, c_size*sizeof(T));
- a_buffer.WriteBuffer(queue, a_size*sizeof(T), a_source);
- b_buffer.WriteBuffer(queue, b_size*sizeof(T), b_source);
- c_buffer.WriteBuffer(queue, c_size*sizeof(T), c_source);
-
- // Runs the routine-specific code
- client_routine(args, a_buffer, b_buffer, c_buffer, queue);
-
- // Makes the jump to the next step
- ++s;
- if (s >= args.num_steps) { break; }
- args.m += args.step;
- args.n += args.step;
- args.k += args.step;
- args.a_ld += args.step;
- args.b_ld += args.step;
- args.c_ld += args.step;
- }
-
- // Cleans-up and returns
- if (args.compare_clblas) { clblasTeardown(); }
-}
-
-// Compiles the above function
-template void ClientABC<float>(int, char **, Routine3<float>, const std::vector<std::string>&, const bool);
-template void ClientABC<double>(int, char **, Routine3<double>, const std::vector<std::string>&, const bool);
-template void ClientABC<float2>(int, char **, Routine3<float2>, const std::vector<std::string>&, const bool);
-template void ClientABC<double2>(int, char **, Routine3<double2>, const std::vector<std::string>&, const bool);
-
// =================================================================================================
// Parses all arguments available for the CLBlast client testers. Some arguments might not be
// applicable, but are searched for anyway to be able to create one common argument parser. All
// arguments have a default value in case they are not found.
template <typename T>
-Arguments<T> ParseArguments(int argc, char *argv[], const std::vector<std::string> &options,
- const std::function<size_t(const Arguments<T>)> default_ld_a) {
+Arguments<T> Client<T>::ParseArguments(int argc, char *argv[], const GetMetric default_a_ld,
+ const GetMetric default_b_ld, const GetMetric default_c_ld) {
auto args = Arguments<T>{};
auto help = std::string{"Options given/available:\n"};
// These are the options which are not for every client: they are optional
- for (auto &o: options) {
+ for (auto &o: options_) {
// Data-sizes
- if (o == kArgM) { args.m = args.k = GetArgument(argc, argv, help, kArgM, 512UL); }
- if (o == kArgN) { args.n = GetArgument(argc, argv, help, kArgN, 512UL); }
- if (o == kArgK) { args.k = GetArgument(argc, argv, help, kArgK, 512UL); }
+ if (o == kArgM) { args.m = GetArgument(argc, argv, help, kArgM, 512UL); }
+ if (o == kArgN) { args.n = GetArgument(argc, argv, help, kArgN, 512UL); }
+ if (o == kArgK) { args.k = GetArgument(argc, argv, help, kArgK, 512UL); }
// Data-layouts
if (o == kArgLayout) { args.layout = GetArgument(argc, argv, help, kArgLayout, Layout::kRowMajor); }
@@ -353,9 +66,9 @@ Arguments<T> ParseArguments(int argc, char *argv[], const std::vector<std::strin
if (o == kArgYOffset) { args.y_offset = GetArgument(argc, argv, help, kArgYOffset, size_t{0}); }
// Matrix arguments
- if (o == kArgALeadDim) { args.a_ld = GetArgument(argc, argv, help, kArgALeadDim, default_ld_a(args)); }
- if (o == kArgBLeadDim) { args.b_ld = GetArgument(argc, argv, help, kArgBLeadDim, args.n); }
- if (o == kArgCLeadDim) { args.c_ld = GetArgument(argc, argv, help, kArgCLeadDim, args.n); }
+ if (o == kArgALeadDim) { args.a_ld = GetArgument(argc, argv, help, kArgALeadDim, default_a_ld(args)); }
+ if (o == kArgBLeadDim) { args.b_ld = GetArgument(argc, argv, help, kArgBLeadDim, default_b_ld(args)); }
+ if (o == kArgCLeadDim) { args.c_ld = GetArgument(argc, argv, help, kArgCLeadDim, default_c_ld(args)); }
if (o == kArgAOffset) { args.a_offset = GetArgument(argc, argv, help, kArgAOffset, size_t{0}); }
if (o == kArgBOffset) { args.b_offset = GetArgument(argc, argv, help, kArgBOffset, size_t{0}); }
if (o == kArgCOffset) { args.c_offset = GetArgument(argc, argv, help, kArgCOffset, size_t{0}); }
@@ -387,16 +100,92 @@ Arguments<T> ParseArguments(int argc, char *argv[], const std::vector<std::strin
// =================================================================================================
+// This is main performance tester
+template <typename T>
+void Client<T>::PerformanceTest(Arguments<T> &args, const SetMetric set_sizes) {
+
+ // Prints the header of the output table
+ PrintTableHeader(args.silent, options_);
+
+ // Initializes OpenCL and the libraries
+ auto platform = Platform(args.platform_id);
+ auto device = Device(platform, kDeviceType, args.device_id);
+ auto context = Context(device);
+ auto queue = CommandQueue(context, device);
+ if (args.compare_clblas) { clblasSetup(); }
+
+ // Iterates over all "num_step" values jumping by "step" each time
+ auto s = size_t{0};
+ while(true) {
+
+ // Sets the buffer sizes (routine-specific)
+ set_sizes(args);
+
+ // Populates input host matrices with random data
+ std::vector<T> x_source(args.x_size);
+ std::vector<T> y_source(args.y_size);
+ std::vector<T> a_source(args.a_size);
+ std::vector<T> b_source(args.b_size);
+ std::vector<T> c_source(args.c_size);
+ PopulateVector(x_source);
+ PopulateVector(y_source);
+ PopulateVector(a_source);
+ PopulateVector(b_source);
+ PopulateVector(c_source);
+
+ // Creates the matrices on the device
+ auto x_vec = Buffer(context, CL_MEM_READ_WRITE, args.x_size*sizeof(T));
+ auto y_vec = Buffer(context, CL_MEM_READ_WRITE, args.y_size*sizeof(T));
+ auto a_mat = Buffer(context, CL_MEM_READ_WRITE, args.a_size*sizeof(T));
+ auto b_mat = Buffer(context, CL_MEM_READ_WRITE, args.b_size*sizeof(T));
+ auto c_mat = Buffer(context, CL_MEM_READ_WRITE, args.c_size*sizeof(T));
+ x_vec.WriteBuffer(queue, args.x_size*sizeof(T), x_source);
+ y_vec.WriteBuffer(queue, args.y_size*sizeof(T), y_source);
+ a_mat.WriteBuffer(queue, args.a_size*sizeof(T), a_source);
+ b_mat.WriteBuffer(queue, args.b_size*sizeof(T), b_source);
+ c_mat.WriteBuffer(queue, args.c_size*sizeof(T), c_source);
+ auto buffers = Buffers{x_vec, y_vec, a_mat, b_mat, c_mat};
+
+ // Runs the routines and collects the timings
+ auto ms_clblast = TimedExecution(args.num_runs, args, buffers, queue, run_routine_, "CLBlast");
+ auto ms_clblas = TimedExecution(args.num_runs, args, buffers, queue, run_reference_, "clBLAS");
+
+ // Prints the performance of both libraries
+ PrintTableRow(args, ms_clblast, ms_clblas);
+
+ // Makes the jump to the next step
+ ++s;
+ if (s >= args.num_steps) { break; }
+ args.m += args.step;
+ args.n += args.step;
+ args.k += args.step;
+ args.a_ld += args.step;
+ args.b_ld += args.step;
+ args.c_ld += args.step;
+ }
+
+ // Cleans-up and returns
+ if (args.compare_clblas) { clblasTeardown(); }
+}
+
+// =================================================================================================
+
// Creates a vector of timing results, filled with execution times of the 'main computation'. The
// timing is performed using the milliseconds chrono functions. The function returns the minimum
// value found in the vector of timing results. The return value is in milliseconds.
-double TimedExecution(const size_t num_runs, std::function<void()> main_computation) {
+template <typename T>
+double Client<T>::TimedExecution(const size_t num_runs, const Arguments<T> &args,
+ const Buffers &buffers, CommandQueue &queue,
+ Routine run_blas, const std::string &library_name) {
auto timings = std::vector<double>(num_runs);
for (auto &timing: timings) {
auto start_time = std::chrono::steady_clock::now();
// Executes the main computation
- main_computation();
+ auto status = run_blas(args, buffers, queue);
+ if (status != StatusCode::kSuccess) {
+ throw std::runtime_error(library_name+" error: "+ToString(static_cast<int>(status)));
+ }
// Records and stores the end-time
auto elapsed_time = std::chrono::steady_clock::now() - start_time;
@@ -408,7 +197,8 @@ double TimedExecution(const size_t num_runs, std::function<void()> main_computat
// =================================================================================================
// Prints the header of the performance table
-void PrintTableHeader(const bool silent, const std::vector<std::string> &args) {
+template <typename T>
+void Client<T>::PrintTableHeader(const bool silent, const std::vector<std::string> &args) {
if (!silent) {
for (auto i=size_t{0}; i<args.size(); ++i) { fprintf(stdout, "%9s ", ""); }
fprintf(stdout, " | <-- CLBlast --> | <-- clBLAS --> |\n");
@@ -419,29 +209,59 @@ void PrintTableHeader(const bool silent, const std::vector<std::string> &args) {
}
// Print a performance-result row
-void PrintTableRow(const std::vector<size_t> &args_int, const std::vector<std::string> &args_string,
- const bool no_abbrv, const double ms_clblast, const double ms_clblas,
- const unsigned long long flops, const unsigned long long bytes) {
+template <typename T>
+void Client<T>::PrintTableRow(const Arguments<T>& args, const double ms_clblast,
+ const double ms_clblas) {
+
+ // Creates a vector of relevant variables
+ auto integers = std::vector<size_t>{};
+ for (auto &o: options_) {
+ if (o == kArgM) { integers.push_back(args.m); }
+ if (o == kArgN) { integers.push_back(args.n); }
+ else if (o == kArgK) { integers.push_back(args.k); }
+ else if (o == kArgLayout) { integers.push_back(static_cast<size_t>(args.layout)); }
+ else if (o == kArgSide) { integers.push_back(static_cast<size_t>(args.side)); }
+ else if (o == kArgTriangle) { integers.push_back(static_cast<size_t>(args.triangle)); }
+ else if (o == kArgATransp) { integers.push_back(static_cast<size_t>(args.a_transpose)); }
+ else if (o == kArgBTransp) { integers.push_back(static_cast<size_t>(args.b_transpose)); }
+ else if (o == kArgXInc) { integers.push_back(args.x_inc); }
+ else if (o == kArgYInc) { integers.push_back(args.y_inc); }
+ else if (o == kArgXOffset) { integers.push_back(args.x_offset); }
+ else if (o == kArgYOffset) { integers.push_back(args.y_offset); }
+ else if (o == kArgALeadDim) { integers.push_back(args.a_ld); }
+ else if (o == kArgBLeadDim) { integers.push_back(args.b_ld); }
+ else if (o == kArgCLeadDim) { integers.push_back(args.c_ld); }
+ else if (o == kArgAOffset) { integers.push_back(args.a_offset); }
+ else if (o == kArgBOffset) { integers.push_back(args.b_offset); }
+ else if (o == kArgCOffset) { integers.push_back(args.c_offset); }
+ }
+ auto strings = std::vector<std::string>{};
+ for (auto &o: options_) {
+ if (o == kArgAlpha) { strings.push_back(ToString(args.alpha)); }
+ else if (o == kArgBeta) { strings.push_back(ToString(args.beta)); }
+ }
// Computes the GFLOPS and GB/s metrics
+ auto flops = get_flops_(args);
+ auto bytes = get_bytes_(args);
auto gflops_clblast = (ms_clblast != 0.0) ? (flops*1e-6)/ms_clblast : 0;
auto gflops_clblas = (ms_clblas != 0.0) ? (flops*1e-6)/ms_clblas: 0;
auto gbs_clblast = (ms_clblast != 0.0) ? (bytes*1e-6)/ms_clblast : 0;
auto gbs_clblas = (ms_clblas != 0.0) ? (bytes*1e-6)/ms_clblas: 0;
// Outputs the argument values
- for (auto &argument: args_int) {
- if (!no_abbrv && argument >= 1024*1024 && IsMultiple(argument, 1024*1024)) {
+ for (auto &argument: integers) {
+ if (!args.no_abbrv && argument >= 1024*1024 && IsMultiple(argument, 1024*1024)) {
fprintf(stdout, "%8luM;", argument/(1024*1024));
}
- else if (!no_abbrv && argument >= 1024 && IsMultiple(argument, 1024)) {
+ else if (!args.no_abbrv && argument >= 1024 && IsMultiple(argument, 1024)) {
fprintf(stdout, "%8luK;", argument/1024);
}
else {
fprintf(stdout, "%9lu;", argument);
}
}
- for (auto &argument: args_string) {
+ for (auto &argument: strings) {
fprintf(stdout, "%9s;", argument.c_str());
}
@@ -452,4 +272,12 @@ void PrintTableRow(const std::vector<size_t> &args_int, const std::vector<std::s
}
// =================================================================================================
+
+// Compiles the templated class
+template class Client<float>;
+template class Client<double>;
+template class Client<float2>;
+template class Client<double2>;
+
+// =================================================================================================
} // namespace clblast
diff --git a/test/performance/client.h b/test/performance/client.h
index 097ae048..f9f219d0 100644
--- a/test/performance/client.h
+++ b/test/performance/client.h
@@ -7,7 +7,12 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file provides common function declarations to be used with the test clients.
+// This class implements the performance-test client. It is generic for all CLBlast routines by
+// taking a number of routine-specific functions as arguments, such as how to compute buffer sizes
+// or how to get the FLOPS count.
+//
+// This file also provides the common interface to the performance client (see the 'RunClient'
+// function for details).
//
// =================================================================================================
@@ -26,64 +31,71 @@
namespace clblast {
// =================================================================================================
-// Types of devices to consider
-const cl_device_type kDeviceType = CL_DEVICE_TYPE_ALL;
+// See comment at top of file for a description of the class
+template <typename T>
+class Client {
+ public:
-// =================================================================================================
+ // Types of devices to consider
+ const cl_device_type kDeviceType = CL_DEVICE_TYPE_ALL;
-// Shorthand for a BLAS routine with 2 or 3 OpenCL buffers as argument
-template <typename T>
-using Routine2 = std::function<void(const Arguments<T>&,
- const Buffer&, const Buffer&,
- CommandQueue&)>;
-template <typename T>
-using Routine3 = std::function<void(const Arguments<T>&,
- const Buffer&, const Buffer&, const Buffer&,
- CommandQueue&)>;
+ // Shorthand for the routine-specific functions passed to the tester
+ using Routine = std::function<StatusCode(const Arguments<T>&, const Buffers&, CommandQueue&)>;
+ using SetMetric = std::function<void(Arguments<T>&)>;
+ using GetMetric = std::function<size_t(const Arguments<T>&)>;
-// =================================================================================================
+ // The constructor
+ Client(const Routine run_routine, const Routine run_reference,
+ const std::vector<std::string> &options,
+ const GetMetric get_flops, const GetMetric get_bytes);
-// These are the main client functions, setting-up arguments, matrices, OpenCL buffers, etc. After
-// set-up, they call the client routine, passed as argument to this function.
-template <typename T>
-void ClientXY(int argc, char *argv[], Routine2<T> client_routine,
- const std::vector<std::string> &options);
-template <typename T>
-void ClientAXY(int argc, char *argv[], Routine3<T> client_routine,
- const std::vector<std::string> &options);
-template <typename T>
-void ClientAC(int argc, char *argv[], Routine2<T> client_routine,
- const std::vector<std::string> &options);
-template <typename T>
-void ClientABC(int argc, char *argv[], Routine3<T> client_routine,
- const std::vector<std::string> &options, const bool symmetric);
+ // Parses all command-line arguments, filling in the arguments structure. If no command-line
+ // argument is given for a particular argument, it is filled in with a default value.
+ Arguments<T> ParseArguments(int argc, char *argv[], const GetMetric default_a_ld,
+ const GetMetric default_b_ld, const GetMetric default_c_ld);
-// =================================================================================================
+ // The main client function, setting-up arguments, matrices, OpenCL buffers, etc. After set-up, it
+ // calls the client routines.
+ void PerformanceTest(Arguments<T> &args, const SetMetric set_sizes);
-// Parses all command-line arguments, filling in the arguments structure. If no command-line
-// argument is given for a particular argument, it is filled in with a default value.
-template <typename T>
-Arguments<T> ParseArguments(int argc, char *argv[], const std::vector<std::string> &options,
- const std::function<size_t(const Arguments<T>)> default_ld_a);
+ private:
-// Retrieves only the precision command-line argument, since the above function is templated based
-// on the precision
-Precision GetPrecision(int argc, char *argv[]);
+ // Runs a function a given number of times and returns the execution time of the shortest instance
+ double TimedExecution(const size_t num_runs, const Arguments<T> &args, const Buffers &buffers,
+ CommandQueue &queue, Routine run_blas, const std::string &library_name);
-// =================================================================================================
+ // Prints the header of a performance-data table
+ void PrintTableHeader(const bool silent, const std::vector<std::string> &args);
+
+ // Prints a row of performance data, including results of two libraries
+ void PrintTableRow(const Arguments<T>& args, const double ms_clblast, const double ms_clblas);
-// Runs a function a given number of times and returns the execution time of the shortest instance
-double TimedExecution(const size_t num_runs, std::function<void()> main_computation);
+ // The routine-specific functions passed to the tester
+ const Routine run_routine_;
+ const Routine run_reference_;
+ const std::vector<std::string> options_;
+ const GetMetric get_flops_;
+ const GetMetric get_bytes_;
+};
// =================================================================================================
-// Prints the header of a performance-data table
-void PrintTableHeader(const bool silent, const std::vector<std::string> &args);
+// The interface to the performance client. This is a separate function in the header such that it
+// is automatically compiled for each routine, templated by the parameter "C".
+template <typename C, typename T>
+void RunClient(int argc, char *argv[]) {
+
+ // Creates a new client
+ auto client = Client<T>(C::RunRoutine, C::RunReference, C::GetOptions(),
+ C::GetFlops, C::GetBytes);
+
+ // Simple command line argument parser with defaults
+ auto args = client.ParseArguments(argc, argv, C::DefaultLDA, C::DefaultLDB, C::DefaultLDC);
+ if (args.print_help) { return; }
-// Prints a row of performance data, including results of two libraries
-void PrintTableRow(const std::vector<size_t> &args_int, const std::vector<std::string> &args_string,
- const bool abbreviations, const double ms_clblast, const double ms_clblas,
- const unsigned long long flops, const unsigned long long bytes);
+ // Runs the client
+ client.PerformanceTest(args, C::SetSizes);
+}
// =================================================================================================
} // namespace clblast
diff --git a/test/performance/routines/xaxpy.cc b/test/performance/routines/xaxpy.cc
index 23d76099..3ced80ed 100644
--- a/test/performance/routines/xaxpy.cc
+++ b/test/performance/routines/xaxpy.cc
@@ -7,90 +7,29 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file implements the Xaxpy command-line interface tester.
+// This file implements the Xaxpy command-line interface performance tester.
//
// =================================================================================================
-#include <string>
-#include <vector>
-#include <exception>
-
-#include "wrapper_clblas.h"
#include "performance/client.h"
+#include "routines/xaxpy.h"
-namespace clblast {
// =================================================================================================
-// The client, used for performance testing. It contains the function calls to CLBlast and to other
-// libraries to compare against.
-template <typename T>
-void PerformanceXaxpy(const Arguments<T> &args,
- const Buffer &x_vec, const Buffer &y_vec,
- CommandQueue &queue) {
-
- // Creates the CLBlast lambda
- auto clblast_lambda = [&args, &x_vec, &y_vec, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = Axpy(args.n, args.alpha,
- x_vec(), args.x_offset, args.x_inc,
- y_vec(), args.y_offset, args.y_inc,
- &queue_plain, &event);
- clWaitForEvents(1, &event);
- if (status != StatusCode::kSuccess) {
- throw std::runtime_error("CLBlast error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Creates the clBLAS lambda (for comparison)
- auto clblas_lambda = [&args, &x_vec, &y_vec, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = clblasXaxpy(args.n, args.alpha,
- x_vec(), args.x_offset, args.x_inc,
- y_vec(), args.y_offset, args.y_inc,
- 1, &queue_plain, 0, nullptr, &event);
- clWaitForEvents(1, &event);
- if (status != CL_SUCCESS) {
- throw std::runtime_error("clBLAS error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Runs the routines and collect the timings
- auto ms_clblast = TimedExecution(args.num_runs, clblast_lambda);
- auto ms_clblas = TimedExecution(args.num_runs, clblas_lambda);
-
- // Prints the performance of both libraries
- const auto flops = 2 * args.n;
- const auto bytes = (3 * args.n) * sizeof(T);
- const auto output_ints = std::vector<size_t>{args.n, args.x_inc, args.y_inc,
- args.x_offset, args.y_offset};
- const auto output_strings = std::vector<std::string>{ToString(args.alpha)};
- PrintTableRow(output_ints, output_strings, args.no_abbrv,
- ms_clblast, ms_clblas, flops, bytes);
-}
-
-// =================================================================================================
-
-// Main function which calls the common client code with the routine-specific function as argument.
-void ClientXaxpy(int argc, char *argv[]) {
- const auto o = std::vector<std::string>{kArgN, kArgXInc, kArgYInc,
- kArgXOffset, kArgYOffset, kArgAlpha};
- switch(GetPrecision(argc, argv)) {
- case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: ClientXY<float>(argc, argv, PerformanceXaxpy<float>, o); break;
- case Precision::kDouble: ClientXY<double>(argc, argv, PerformanceXaxpy<double>, o); break;
- case Precision::kComplexSingle: ClientXY<float2>(argc, argv, PerformanceXaxpy<float2>, o); break;
- case Precision::kComplexDouble: ClientXY<double2>(argc, argv, PerformanceXaxpy<double2>, o); break;
- }
-}
-
-// =================================================================================================
-} // namespace clblast
-
// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
- clblast::ClientXaxpy(argc, argv);
+ switch(clblast::GetPrecision(argc, argv)) {
+ case clblast::Precision::kHalf:
+ throw std::runtime_error("Unsupported precision mode");
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXaxpy<float>, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXaxpy<double>, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXaxpy<clblast::float2>, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXaxpy<clblast::double2>, clblast::double2>(argc, argv); break;
+ }
return 0;
}
diff --git a/test/performance/routines/xgemm.cc b/test/performance/routines/xgemm.cc
index 76e398e0..36c74b9a 100644
--- a/test/performance/routines/xgemm.cc
+++ b/test/performance/routines/xgemm.cc
@@ -7,108 +7,29 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file implements the Xgemm command-line interface tester.
+// This file implements the Xgemm command-line interface performance tester.
//
// =================================================================================================
-#include <string>
-#include <vector>
-#include <exception>
-
-#include "wrapper_clblas.h"
#include "performance/client.h"
+#include "routines/xgemm.h"
-namespace clblast {
// =================================================================================================
-// The client, used for performance testing. It contains the function calls to CLBlast and to other
-// libraries to compare against.
-template <typename T>
-void PerformanceXgemm(const Arguments<T> &args,
- const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat,
- CommandQueue &queue) {
-
- // Creates the CLBlast lambda
- auto clblast_lambda = [&args, &a_mat, &b_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = Gemm(args.layout, args.a_transpose, args.b_transpose,
- args.m, args.n, args.k,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- b_mat(), args.b_offset, args.b_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- &queue_plain, &event);
- clWaitForEvents(1, &event);
- if (status != StatusCode::kSuccess) {
- throw std::runtime_error("CLBlast error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Creates the clBLAS lambda (for comparison)
- auto clblas_lambda = [&args, &a_mat, &b_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = clblasXgemm(static_cast<clblasOrder>(args.layout),
- static_cast<clblasTranspose>(args.a_transpose),
- static_cast<clblasTranspose>(args.b_transpose),
- args.m, args.n, args.k,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- b_mat(), args.b_offset, args.b_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- 1, &queue_plain, 0, nullptr, &event);
- clWaitForEvents(1, &event);
- if (status != CL_SUCCESS) {
- throw std::runtime_error("clBLAS error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Runs the routines and collect the timings
- auto ms_clblast = TimedExecution(args.num_runs, clblast_lambda);
- auto ms_clblas = TimedExecution(args.num_runs, clblas_lambda);
-
- // Prints the performance of both libraries
- const auto flops = 2 * args.m * args.n * args.k;
- const auto bytes = (args.m*args.k + args.k*args.n + 2*args.m*args.n) * sizeof(T);
- const auto output_ints = std::vector<size_t>{args.m, args.n, args.k,
- static_cast<size_t>(args.layout),
- static_cast<size_t>(args.a_transpose),
- static_cast<size_t>(args.b_transpose),
- args.a_ld, args.b_ld, args.c_ld,
- args.a_offset, args.b_offset, args.c_offset};
- const auto output_strings = std::vector<std::string>{ToString(args.alpha),
- ToString(args.beta)};
- PrintTableRow(output_ints, output_strings, args.no_abbrv,
- ms_clblast, ms_clblas, flops, bytes);
-}
-
-// =================================================================================================
-
-// Main function which calls the common client code with the routine-specific function as argument.
-void ClientXgemm(int argc, char *argv[]) {
- const auto o = std::vector<std::string>{kArgM, kArgN, kArgK, kArgLayout,
- kArgATransp, kArgBTransp,
- kArgALeadDim, kArgBLeadDim, kArgCLeadDim,
- kArgAOffset, kArgBOffset, kArgCOffset,
- kArgAlpha, kArgBeta};
- switch(GetPrecision(argc, argv)) {
- case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: ClientABC<float>(argc, argv, PerformanceXgemm<float>, o, false); break;
- case Precision::kDouble: ClientABC<double>(argc, argv, PerformanceXgemm<double>, o, false); break;
- case Precision::kComplexSingle: ClientABC<float2>(argc, argv, PerformanceXgemm<float2>, o, false); break;
- case Precision::kComplexDouble: ClientABC<double2>(argc, argv, PerformanceXgemm<double2>, o, false); break;
- }
-}
-
-// =================================================================================================
-} // namespace clblast
-
// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
- clblast::ClientXgemm(argc, argv);
+ switch(clblast::GetPrecision(argc, argv)) {
+ case clblast::Precision::kHalf:
+ throw std::runtime_error("Unsupported precision mode");
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXgemm<float>, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXgemm<double>, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXgemm<clblast::float2>, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXgemm<clblast::double2>, clblast::double2>(argc, argv); break;
+ }
return 0;
}
diff --git a/test/performance/routines/xgemv.cc b/test/performance/routines/xgemv.cc
index 43222396..183dd4a1 100644
--- a/test/performance/routines/xgemv.cc
+++ b/test/performance/routines/xgemv.cc
@@ -7,100 +7,29 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file implements the Xgemv command-line interface tester.
+// This file implements the Xgemv command-line interface performance tester.
//
// =================================================================================================
-#include <string>
-#include <vector>
-#include <exception>
-
-#include "wrapper_clblas.h"
#include "performance/client.h"
+#include "routines/xgemv.h"
-namespace clblast {
// =================================================================================================
-// The client, used for performance testing. It contains the function calls to CLBlast and to other
-// libraries to compare against.
-template <typename T>
-void PerformanceXgemv(const Arguments<T> &args,
- const Buffer &a_mat, const Buffer &x_vec, const Buffer &y_vec,
- CommandQueue &queue) {
-
- // Creates the CLBlast lambda
- auto clblast_lambda = [&args, &a_mat, &x_vec, &y_vec, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = Gemv(args.layout, args.a_transpose, args.m, args.n, args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- x_vec(), args.x_offset, args.x_inc, args.beta,
- y_vec(), args.y_offset, args.y_inc,
- &queue_plain, &event);
- clWaitForEvents(1, &event);
- if (status != StatusCode::kSuccess) {
- throw std::runtime_error("CLBlast error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Creates the clBLAS lambda (for comparison)
- auto clblas_lambda = [&args, &a_mat, &x_vec, &y_vec, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = clblasXgemv(static_cast<clblasOrder>(args.layout),
- static_cast<clblasTranspose>(args.a_transpose),
- args.m, args.n, args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- x_vec(), args.x_offset, args.x_inc, args.beta,
- y_vec(), args.y_offset, args.y_inc,
- 1, &queue_plain, 0, nullptr, &event);
- clWaitForEvents(1, &event);
- if (status != CL_SUCCESS) {
- throw std::runtime_error("clBLAS error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Runs the routines and collect the timings
- auto ms_clblast = TimedExecution(args.num_runs, clblast_lambda);
- auto ms_clblas = TimedExecution(args.num_runs, clblas_lambda);
-
- // Prints the performance of both libraries
- const auto flops = 2 * args.m * args.n;
- const auto bytes = (args.m*args.n + 2*args.m + args.n) * sizeof(T);
- const auto output_ints = std::vector<size_t>{args.m, args.n,
- static_cast<size_t>(args.layout),
- static_cast<size_t>(args.a_transpose),
- args.a_ld, args.x_inc, args.y_inc,
- args.a_offset, args.x_offset, args.y_offset};
- const auto output_strings = std::vector<std::string>{ToString(args.alpha),
- ToString(args.beta)};
- PrintTableRow(output_ints, output_strings, args.no_abbrv,
- ms_clblast, ms_clblas, flops, bytes);
-}
-
-// =================================================================================================
-
-// Main function which calls the common client code with the routine-specific function as argument.
-void ClientXgemv(int argc, char *argv[]) {
- const auto o = std::vector<std::string>{kArgM, kArgN, kArgLayout, kArgATransp,
- kArgALeadDim, kArgXInc, kArgYInc,
- kArgAOffset, kArgXOffset, kArgYOffset,
- kArgAlpha, kArgBeta};
- switch(GetPrecision(argc, argv)) {
- case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: ClientAXY<float>(argc, argv, PerformanceXgemv<float>, o); break;
- case Precision::kDouble: ClientAXY<double>(argc, argv, PerformanceXgemv<double>, o); break;
- case Precision::kComplexSingle: ClientAXY<float2>(argc, argv, PerformanceXgemv<float2>, o); break;
- case Precision::kComplexDouble: ClientAXY<double2>(argc, argv, PerformanceXgemv<double2>, o); break;
- }
-}
-
-// =================================================================================================
-} // namespace clblast
-
// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
- clblast::ClientXgemv(argc, argv);
+ switch(clblast::GetPrecision(argc, argv)) {
+ case clblast::Precision::kHalf:
+ throw std::runtime_error("Unsupported precision mode");
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXgemv<float>, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXgemv<double>, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXgemv<clblast::float2>, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXgemv<clblast::double2>, clblast::double2>(argc, argv); break;
+ }
return 0;
}
diff --git a/test/performance/routines/xsymm.cc b/test/performance/routines/xsymm.cc
index d78d4eb8..0c7f5e1e 100644
--- a/test/performance/routines/xsymm.cc
+++ b/test/performance/routines/xsymm.cc
@@ -7,108 +7,29 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file implements the Xsymm command-line interface tester.
+// This file implements the Xsymm command-line interface performance tester.
//
// =================================================================================================
-#include <string>
-#include <vector>
-#include <exception>
-
-#include "wrapper_clblas.h"
#include "performance/client.h"
+#include "routines/xsymm.h"
-namespace clblast {
// =================================================================================================
-// The client, used for performance testing. It contains the function calls to CLBlast and to other
-// libraries to compare against.
-template <typename T>
-void PerformanceXsymm(const Arguments<T> &args,
- const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat,
- CommandQueue &queue) {
-
- // Creates the CLBlast lambda
- auto clblast_lambda = [&args, &a_mat, &b_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = Symm(args.layout, args.side, args.triangle,
- args.m, args.n,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- b_mat(), args.b_offset, args.b_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- &queue_plain, &event);
- clWaitForEvents(1, &event);
- if (status != StatusCode::kSuccess) {
- throw std::runtime_error("CLBlast error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Creates the clBLAS lambda (for comparison)
- auto clblas_lambda = [&args, &a_mat, &b_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = clblasXsymm(static_cast<clblasOrder>(args.layout),
- static_cast<clblasSide>(args.side),
- static_cast<clblasUplo>(args.triangle),
- args.m, args.n,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- b_mat(), args.b_offset, args.b_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- 1, &queue_plain, 0, nullptr, &event);
- clWaitForEvents(1, &event);
- if (status != CL_SUCCESS) {
- throw std::runtime_error("clBLAS error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Runs the routines and collect the timings
- auto ms_clblast = TimedExecution(args.num_runs, clblast_lambda);
- auto ms_clblas = TimedExecution(args.num_runs, clblas_lambda);
-
- // Prints the performance of both libraries
- const auto flops = 2 * args.m * args.n * args.m;
- const auto bytes = (args.m*args.m + args.m*args.n + 2*args.m*args.n) * sizeof(T);
- const auto output_ints = std::vector<size_t>{args.m, args.n,
- static_cast<size_t>(args.layout),
- static_cast<size_t>(args.triangle),
- static_cast<size_t>(args.side),
- args.a_ld, args.b_ld, args.c_ld,
- args.a_offset, args.b_offset, args.c_offset};
- const auto output_strings = std::vector<std::string>{ToString(args.alpha),
- ToString(args.beta)};
- PrintTableRow(output_ints, output_strings, args.no_abbrv,
- ms_clblast, ms_clblas, flops, bytes);
-}
-
-// =================================================================================================
-
-// Main function which calls the common client code with the routine-specific function as argument.
-void ClientXsymm(int argc, char *argv[]) {
- const auto o = std::vector<std::string>{kArgM, kArgN, kArgLayout,
- kArgTriangle, kArgSide,
- kArgALeadDim, kArgBLeadDim, kArgCLeadDim,
- kArgAOffset, kArgBOffset, kArgCOffset,
- kArgAlpha, kArgBeta};
- switch(GetPrecision(argc, argv)) {
- case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: ClientABC<float>(argc, argv, PerformanceXsymm<float>, o, false); break;
- case Precision::kDouble: ClientABC<double>(argc, argv, PerformanceXsymm<double>, o, false); break;
- case Precision::kComplexSingle: ClientABC<float2>(argc, argv, PerformanceXsymm<float2>, o, false); break;
- case Precision::kComplexDouble: ClientABC<double2>(argc, argv, PerformanceXsymm<double2>, o, false); break;
- }
-}
-
-// =================================================================================================
-} // namespace clblast
-
// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
- clblast::ClientXsymm(argc, argv);
+ switch(clblast::GetPrecision(argc, argv)) {
+ case clblast::Precision::kHalf:
+ throw std::runtime_error("Unsupported precision mode");
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXsymm<float>, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXsymm<double>, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXsymm<clblast::float2>, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXsymm<clblast::double2>, clblast::double2>(argc, argv); break;
+ }
return 0;
}
diff --git a/test/performance/routines/xsyr2k.cc b/test/performance/routines/xsyr2k.cc
index 8d9871d0..63b50df6 100644
--- a/test/performance/routines/xsyr2k.cc
+++ b/test/performance/routines/xsyr2k.cc
@@ -7,108 +7,29 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file implements the Xsyr2k command-line interface tester.
+// This file implements the Xsyr2k command-line interface performance tester.
//
// =================================================================================================
-#include <string>
-#include <vector>
-#include <exception>
-
-#include "wrapper_clblas.h"
#include "performance/client.h"
+#include "routines/xsyr2k.h"
-namespace clblast {
// =================================================================================================
-// The client, used for performance testing. It contains the function calls to CLBlast and to other
-// libraries to compare against.
-template <typename T>
-void PerformanceXsyr2k(const Arguments<T> &args,
- const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat,
- CommandQueue &queue) {
-
- // Creates the CLBlast lambda
- auto clblast_lambda = [&args, &a_mat, &b_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = Syr2k(args.layout, args.triangle, args.a_transpose,
- args.n, args.k,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- b_mat(), args.b_offset, args.b_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- &queue_plain, &event);
- clWaitForEvents(1, &event);
- if (status != StatusCode::kSuccess) {
- throw std::runtime_error("CLBlast error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Creates the clBLAS lambda (for comparison)
- auto clblas_lambda = [&args, &a_mat, &b_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = clblasXsyr2k(static_cast<clblasOrder>(args.layout),
- static_cast<clblasUplo>(args.triangle),
- static_cast<clblasTranspose>(args.a_transpose),
- args.n, args.k,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- b_mat(), args.b_offset, args.b_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- 1, &queue_plain, 0, nullptr, &event);
- clWaitForEvents(1, &event);
- if (status != CL_SUCCESS) {
- throw std::runtime_error("clBLAS error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Runs the routines and collect the timings
- auto ms_clblast = TimedExecution(args.num_runs, clblast_lambda);
- auto ms_clblas = TimedExecution(args.num_runs, clblas_lambda);
-
- // Prints the performance of both libraries
- const auto flops = 2 * args.n * args.n * args.k;
- const auto bytes = (args.n*args.k + args.n*args.n) * sizeof(T);
- const auto output_ints = std::vector<size_t>{args.n, args.k,
- static_cast<size_t>(args.layout),
- static_cast<size_t>(args.triangle),
- static_cast<size_t>(args.a_transpose),
- args.a_ld, args.b_ld, args.c_ld,
- args.a_offset, args.b_offset, args.c_offset};
- const auto output_strings = std::vector<std::string>{ToString(args.alpha),
- ToString(args.beta)};
- PrintTableRow(output_ints, output_strings, args.no_abbrv,
- ms_clblast, ms_clblas, flops, bytes);
-}
-
-// =================================================================================================
-
-// Main function which calls the common client code with the routine-specific function as argument.
-void ClientXsyr2k(int argc, char *argv[]) {
- const auto o = std::vector<std::string>{kArgN, kArgK,
- kArgLayout, kArgTriangle, kArgATransp,
- kArgALeadDim, kArgBLeadDim, kArgCLeadDim,
- kArgAOffset, kArgBOffset, kArgCOffset,
- kArgAlpha, kArgBeta};
- switch(GetPrecision(argc, argv)) {
- case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: ClientABC<float>(argc, argv, PerformanceXsyr2k<float>, o, true); break;
- case Precision::kDouble: ClientABC<double>(argc, argv, PerformanceXsyr2k<double>, o, true); break;
- case Precision::kComplexSingle: ClientABC<float2>(argc, argv, PerformanceXsyr2k<float2>, o, true); break;
- case Precision::kComplexDouble: ClientABC<double2>(argc, argv, PerformanceXsyr2k<double2>, o, true); break;
- }
-}
-
-// =================================================================================================
-} // namespace clblast
-
// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
- clblast::ClientXsyr2k(argc, argv);
+ switch(clblast::GetPrecision(argc, argv)) {
+ case clblast::Precision::kHalf:
+ throw std::runtime_error("Unsupported precision mode");
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXsyr2k<float>, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXsyr2k<double>, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXsyr2k<clblast::float2>, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXsyr2k<clblast::double2>, clblast::double2>(argc, argv); break;
+ }
return 0;
}
diff --git a/test/performance/routines/xsyrk.cc b/test/performance/routines/xsyrk.cc
index f36d665a..9022d4f8 100644
--- a/test/performance/routines/xsyrk.cc
+++ b/test/performance/routines/xsyrk.cc
@@ -7,106 +7,29 @@
// Author(s):
// Cedric Nugteren <www.cedricnugteren.nl>
//
-// This file implements the Xsyrk command-line interface tester.
+// This file implements the Xsyrk command-line interface performance tester.
//
// =================================================================================================
-#include <string>
-#include <vector>
-#include <exception>
-
-#include "wrapper_clblas.h"
#include "performance/client.h"
+#include "routines/xsyrk.h"
-namespace clblast {
// =================================================================================================
-// The client, used for performance testing. It contains the function calls to CLBlast and to other
-// libraries to compare against.
-template <typename T>
-void PerformanceXsyrk(const Arguments<T> &args,
- const Buffer &a_mat, const Buffer &c_mat,
- CommandQueue &queue) {
-
- // Creates the CLBlast lambda
- auto clblast_lambda = [&args, &a_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = Syrk(args.layout, args.triangle, args.a_transpose,
- args.n, args.k,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- &queue_plain, &event);
- clWaitForEvents(1, &event);
- if (status != StatusCode::kSuccess) {
- throw std::runtime_error("CLBlast error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Creates the clBLAS lambda (for comparison)
- auto clblas_lambda = [&args, &a_mat, &c_mat, &queue]() {
- auto queue_plain = queue();
- auto event = cl_event{};
- auto status = clblasXsyrk(static_cast<clblasOrder>(args.layout),
- static_cast<clblasUplo>(args.triangle),
- static_cast<clblasTranspose>(args.a_transpose),
- args.n, args.k,
- args.alpha,
- a_mat(), args.a_offset, args.a_ld,
- args.beta,
- c_mat(), args.c_offset, args.c_ld,
- 1, &queue_plain, 0, nullptr, &event);
- clWaitForEvents(1, &event);
- if (status != CL_SUCCESS) {
- throw std::runtime_error("clBLAS error: "+ToString(static_cast<int>(status)));
- }
- };
-
- // Runs the routines and collect the timings
- auto ms_clblast = TimedExecution(args.num_runs, clblast_lambda);
- auto ms_clblas = TimedExecution(args.num_runs, clblas_lambda);
-
- // Prints the performance of both libraries
- const auto flops = args.n * args.n * args.k;
- const auto bytes = (args.n*args.k + args.n*args.n) * sizeof(T);
- const auto output_ints = std::vector<size_t>{args.n, args.k,
- static_cast<size_t>(args.layout),
- static_cast<size_t>(args.triangle),
- static_cast<size_t>(args.a_transpose),
- args.a_ld, args.c_ld,
- args.a_offset, args.c_offset};
- const auto output_strings = std::vector<std::string>{ToString(args.alpha),
- ToString(args.beta)};
- PrintTableRow(output_ints, output_strings, args.no_abbrv,
- ms_clblast, ms_clblas, flops, bytes);
-}
-
-// =================================================================================================
-
-// Main function which calls the common client code with the routine-specific function as argument.
-void ClientXsyrk(int argc, char *argv[]) {
- const auto o = std::vector<std::string>{kArgN, kArgK,
- kArgLayout, kArgTriangle, kArgATransp,
- kArgALeadDim, kArgCLeadDim,
- kArgAOffset, kArgCOffset,
- kArgAlpha, kArgBeta};
- switch(GetPrecision(argc, argv)) {
- case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: ClientAC<float>(argc, argv, PerformanceXsyrk<float>, o); break;
- case Precision::kDouble: ClientAC<double>(argc, argv, PerformanceXsyrk<double>, o); break;
- case Precision::kComplexSingle: ClientAC<float2>(argc, argv, PerformanceXsyrk<float2>, o); break;
- case Precision::kComplexDouble: ClientAC<double2>(argc, argv, PerformanceXsyrk<double2>, o); break;
- }
-}
-
-// =================================================================================================
-} // namespace clblast
-
// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
- clblast::ClientXsyrk(argc, argv);
+ switch(clblast::GetPrecision(argc, argv)) {
+ case clblast::Precision::kHalf:
+ throw std::runtime_error("Unsupported precision mode");
+ case clblast::Precision::kSingle:
+ clblast::RunClient<clblast::TestXsyrk<float>, float>(argc, argv); break;
+ case clblast::Precision::kDouble:
+ clblast::RunClient<clblast::TestXsyrk<double>, double>(argc, argv); break;
+ case clblast::Precision::kComplexSingle:
+ clblast::RunClient<clblast::TestXsyrk<clblast::float2>, clblast::float2>(argc, argv); break;
+ case clblast::Precision::kComplexDouble:
+ clblast::RunClient<clblast::TestXsyrk<clblast::double2>, clblast::double2>(argc, argv); break;
+ }
return 0;
}