From 2914a285d43cac7e3a9d4885684229fbf82babb0 Mon Sep 17 00:00:00 2001 From: CNugteren Date: Mon, 29 Jun 2015 20:38:34 +0200 Subject: Re-organized the performance-client infrastructure to avoid code duplication --- test/performance/client.cc | 458 +++++++++++------------------------- test/performance/client.h | 104 ++++---- test/performance/routines/xaxpy.cc | 89 ++----- test/performance/routines/xgemm.cc | 107 ++------- test/performance/routines/xgemv.cc | 99 ++------ test/performance/routines/xsymm.cc | 107 ++------- test/performance/routines/xsyr2k.cc | 107 ++------- test/performance/routines/xsyrk.cc | 105 ++------- 8 files changed, 285 insertions(+), 891 deletions(-) (limited to 'test/performance') 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 -void ClientXY(int argc, char *argv[], Routine2 client_routine, - const std::vector &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 args) { return args.n; }; - - // Simple command line argument parser with defaults - auto args = ParseArguments(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 x_source(x_size); - std::vector 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(int, char **, Routine2, const std::vector&); -template void ClientXY(int, char **, Routine2, const std::vector&); -template void ClientXY(int, char **, Routine2, const std::vector&); -template void ClientXY(int, char **, Routine2, const std::vector&); - -// ================================================================================================= - -// This is the matrix-vector-vector variant of the set-up/tear-down client routine. -template -void ClientAXY(int argc, char *argv[], Routine3 client_routine, - const std::vector &options) { - - // Function to determine how to find the default value of the leading dimension of matrix A - auto default_ld_a = [](const Arguments args) { return args.n; }; - - // Simple command line argument parser with defaults - auto args = ParseArguments(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 a_source(a_size); - std::vector x_source(x_size); - std::vector 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(int, char **, Routine3, const std::vector&); -template void ClientAXY(int, char **, Routine3, const std::vector&); -template void ClientAXY(int, char **, Routine3, const std::vector&); -template void ClientAXY(int, char **, Routine3, const std::vector&); - -// ================================================================================================= - -// This is the matrix-matrix variant of the set-up/tear-down client routine. -template -void ClientAC(int argc, char *argv[], Routine2 client_routine, - const std::vector &options) { - - // Function to determine how to find the default value of the leading dimension of matrix A - auto default_ld_a = [](const Arguments args) { return args.k; }; - - // Simple command line argument parser with defaults - auto args = ParseArguments(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 a_source(a_size); - std::vector 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::Client(const Routine run_routine, const Routine run_reference, + const std::vector &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(int, char **, Routine2, const std::vector&); -template void ClientAC(int, char **, Routine2, const std::vector&); -template void ClientAC(int, char **, Routine2, const std::vector&); -template void ClientAC(int, char **, Routine2, const std::vector&); - -// ================================================================================================= - -// This is the matrix-matrix-matrix variant of the set-up/tear-down client routine. -template -void ClientABC(int argc, char *argv[], Routine3 client_routine, - const std::vector &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 args) { return (symmetric) ? args.n : args.m; }; - - // Simple command line argument parser with defaults - auto args = ParseArguments(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 a_source(a_size); - std::vector b_source(b_size); - std::vector 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(int, char **, Routine3, const std::vector&, const bool); -template void ClientABC(int, char **, Routine3, const std::vector&, const bool); -template void ClientABC(int, char **, Routine3, const std::vector&, const bool); -template void ClientABC(int, char **, Routine3, const std::vector&, 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 -Arguments ParseArguments(int argc, char *argv[], const std::vector &options, - const std::function)> default_ld_a) { +Arguments Client::ParseArguments(int argc, char *argv[], const GetMetric default_a_ld, + const GetMetric default_b_ld, const GetMetric default_c_ld) { auto args = Arguments{}; 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 ParseArguments(int argc, char *argv[], const std::vector ParseArguments(int argc, char *argv[], const std::vector +void Client::PerformanceTest(Arguments &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 x_source(args.x_size); + std::vector y_source(args.y_size); + std::vector a_source(args.a_size); + std::vector b_source(args.b_size); + std::vector 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 main_computation) { +template +double Client::TimedExecution(const size_t num_runs, const Arguments &args, + const Buffers &buffers, CommandQueue &queue, + Routine run_blas, const std::string &library_name) { auto timings = std::vector(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(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 main_computat // ================================================================================================= // Prints the header of the performance table -void PrintTableHeader(const bool silent, const std::vector &args) { +template +void Client::PrintTableHeader(const bool silent, const std::vector &args) { if (!silent) { for (auto i=size_t{0}; i | <-- clBLAS --> |\n"); @@ -419,29 +209,59 @@ void PrintTableHeader(const bool silent, const std::vector &args) { } // Print a performance-result row -void PrintTableRow(const std::vector &args_int, const std::vector &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 +void Client::PrintTableRow(const Arguments& args, const double ms_clblast, + const double ms_clblas) { + + // Creates a vector of relevant variables + auto integers = std::vector{}; + 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(args.layout)); } + else if (o == kArgSide) { integers.push_back(static_cast(args.side)); } + else if (o == kArgTriangle) { integers.push_back(static_cast(args.triangle)); } + else if (o == kArgATransp) { integers.push_back(static_cast(args.a_transpose)); } + else if (o == kArgBTransp) { integers.push_back(static_cast(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{}; + 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()); } @@ -451,5 +271,13 @@ void PrintTableRow(const std::vector &args_int, const std::vector; +template class Client; +template class Client; +template class Client; + // ================================================================================================= } // 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 // -// 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 +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 -using Routine2 = std::function&, - const Buffer&, const Buffer&, - CommandQueue&)>; -template -using Routine3 = std::function&, - const Buffer&, const Buffer&, const Buffer&, - CommandQueue&)>; + // Shorthand for the routine-specific functions passed to the tester + using Routine = std::function&, const Buffers&, CommandQueue&)>; + using SetMetric = std::function&)>; + using GetMetric = std::function&)>; -// ================================================================================================= + // The constructor + Client(const Routine run_routine, const Routine run_reference, + const std::vector &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 -void ClientXY(int argc, char *argv[], Routine2 client_routine, - const std::vector &options); -template -void ClientAXY(int argc, char *argv[], Routine3 client_routine, - const std::vector &options); -template -void ClientAC(int argc, char *argv[], Routine2 client_routine, - const std::vector &options); -template -void ClientABC(int argc, char *argv[], Routine3 client_routine, - const std::vector &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 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 &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 -Arguments ParseArguments(int argc, char *argv[], const std::vector &options, - const std::function)> 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 &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 &args); + + // Prints a row of performance data, including results of two libraries + void PrintTableRow(const Arguments& 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 main_computation); + // The routine-specific functions passed to the tester + const Routine run_routine_; + const Routine run_reference_; + const std::vector 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 &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 +void RunClient(int argc, char *argv[]) { + + // Creates a new client + auto client = Client(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 &args_int, const std::vector &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 // -// This file implements the Xaxpy command-line interface tester. +// This file implements the Xaxpy command-line interface performance tester. // // ================================================================================================= -#include -#include -#include - -#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 -void PerformanceXaxpy(const Arguments &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(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(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{args.n, args.x_inc, args.y_inc, - args.x_offset, args.y_offset}; - const auto output_strings = std::vector{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{kArgN, kArgXInc, kArgYInc, - kArgXOffset, kArgYOffset, kArgAlpha}; - switch(GetPrecision(argc, argv)) { - case Precision::kHalf: throw std::runtime_error("Unsupported precision mode"); - case Precision::kSingle: ClientXY(argc, argv, PerformanceXaxpy, o); break; - case Precision::kDouble: ClientXY(argc, argv, PerformanceXaxpy, o); break; - case Precision::kComplexSingle: ClientXY(argc, argv, PerformanceXaxpy, o); break; - case Precision::kComplexDouble: ClientXY(argc, argv, PerformanceXaxpy, 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, float>(argc, argv); break; + case clblast::Precision::kDouble: + clblast::RunClient, double>(argc, argv); break; + case clblast::Precision::kComplexSingle: + clblast::RunClient, clblast::float2>(argc, argv); break; + case clblast::Precision::kComplexDouble: + clblast::RunClient, 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 // -// This file implements the Xgemm command-line interface tester. +// This file implements the Xgemm command-line interface performance tester. // // ================================================================================================= -#include -#include -#include - -#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 -void PerformanceXgemm(const Arguments &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(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(args.layout), - static_cast(args.a_transpose), - static_cast(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(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{args.m, args.n, args.k, - static_cast(args.layout), - static_cast(args.a_transpose), - static_cast(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{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{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(argc, argv, PerformanceXgemm, o, false); break; - case Precision::kDouble: ClientABC(argc, argv, PerformanceXgemm, o, false); break; - case Precision::kComplexSingle: ClientABC(argc, argv, PerformanceXgemm, o, false); break; - case Precision::kComplexDouble: ClientABC(argc, argv, PerformanceXgemm, 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, float>(argc, argv); break; + case clblast::Precision::kDouble: + clblast::RunClient, double>(argc, argv); break; + case clblast::Precision::kComplexSingle: + clblast::RunClient, clblast::float2>(argc, argv); break; + case clblast::Precision::kComplexDouble: + clblast::RunClient, 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 // -// This file implements the Xgemv command-line interface tester. +// This file implements the Xgemv command-line interface performance tester. // // ================================================================================================= -#include -#include -#include - -#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 -void PerformanceXgemv(const Arguments &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(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(args.layout), - static_cast(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(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{args.m, args.n, - static_cast(args.layout), - static_cast(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{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{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(argc, argv, PerformanceXgemv, o); break; - case Precision::kDouble: ClientAXY(argc, argv, PerformanceXgemv, o); break; - case Precision::kComplexSingle: ClientAXY(argc, argv, PerformanceXgemv, o); break; - case Precision::kComplexDouble: ClientAXY(argc, argv, PerformanceXgemv, 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, float>(argc, argv); break; + case clblast::Precision::kDouble: + clblast::RunClient, double>(argc, argv); break; + case clblast::Precision::kComplexSingle: + clblast::RunClient, clblast::float2>(argc, argv); break; + case clblast::Precision::kComplexDouble: + clblast::RunClient, 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 // -// This file implements the Xsymm command-line interface tester. +// This file implements the Xsymm command-line interface performance tester. // // ================================================================================================= -#include -#include -#include - -#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 -void PerformanceXsymm(const Arguments &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(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(args.layout), - static_cast(args.side), - static_cast(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(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{args.m, args.n, - static_cast(args.layout), - static_cast(args.triangle), - static_cast(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{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{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(argc, argv, PerformanceXsymm, o, false); break; - case Precision::kDouble: ClientABC(argc, argv, PerformanceXsymm, o, false); break; - case Precision::kComplexSingle: ClientABC(argc, argv, PerformanceXsymm, o, false); break; - case Precision::kComplexDouble: ClientABC(argc, argv, PerformanceXsymm, 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, float>(argc, argv); break; + case clblast::Precision::kDouble: + clblast::RunClient, double>(argc, argv); break; + case clblast::Precision::kComplexSingle: + clblast::RunClient, clblast::float2>(argc, argv); break; + case clblast::Precision::kComplexDouble: + clblast::RunClient, 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 // -// This file implements the Xsyr2k command-line interface tester. +// This file implements the Xsyr2k command-line interface performance tester. // // ================================================================================================= -#include -#include -#include - -#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 -void PerformanceXsyr2k(const Arguments &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(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(args.layout), - static_cast(args.triangle), - static_cast(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(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{args.n, args.k, - static_cast(args.layout), - static_cast(args.triangle), - static_cast(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{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{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(argc, argv, PerformanceXsyr2k, o, true); break; - case Precision::kDouble: ClientABC(argc, argv, PerformanceXsyr2k, o, true); break; - case Precision::kComplexSingle: ClientABC(argc, argv, PerformanceXsyr2k, o, true); break; - case Precision::kComplexDouble: ClientABC(argc, argv, PerformanceXsyr2k, 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, float>(argc, argv); break; + case clblast::Precision::kDouble: + clblast::RunClient, double>(argc, argv); break; + case clblast::Precision::kComplexSingle: + clblast::RunClient, clblast::float2>(argc, argv); break; + case clblast::Precision::kComplexDouble: + clblast::RunClient, 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 // -// This file implements the Xsyrk command-line interface tester. +// This file implements the Xsyrk command-line interface performance tester. // // ================================================================================================= -#include -#include -#include - -#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 -void PerformanceXsyrk(const Arguments &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(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(args.layout), - static_cast(args.triangle), - static_cast(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(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{args.n, args.k, - static_cast(args.layout), - static_cast(args.triangle), - static_cast(args.a_transpose), - args.a_ld, args.c_ld, - args.a_offset, args.c_offset}; - const auto output_strings = std::vector{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{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(argc, argv, PerformanceXsyrk, o); break; - case Precision::kDouble: ClientAC(argc, argv, PerformanceXsyrk, o); break; - case Precision::kComplexSingle: ClientAC(argc, argv, PerformanceXsyrk, o); break; - case Precision::kComplexDouble: ClientAC(argc, argv, PerformanceXsyrk, 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, float>(argc, argv); break; + case clblast::Precision::kDouble: + clblast::RunClient, double>(argc, argv); break; + case clblast::Precision::kComplexSingle: + clblast::RunClient, clblast::float2>(argc, argv); break; + case clblast::Precision::kComplexDouble: + clblast::RunClient, clblast::double2>(argc, argv); break; + } return 0; } -- cgit v1.2.3