2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
|
|
|
|
// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
|
|
|
|
// width of 100 characters per line.
|
|
|
|
//
|
|
|
|
// Author(s):
|
|
|
|
// Cedric Nugteren <www.cedricnugteren.nl>
|
|
|
|
//
|
2015-06-29 20:38:34 +02:00
|
|
|
// 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.
|
2015-07-10 07:18:12 +02:00
|
|
|
// Typename T: the data-type of the routine's memory buffers (==precision)
|
|
|
|
// Typename U: the data-type of the alpha and beta arguments
|
2015-06-29 20:38:34 +02:00
|
|
|
//
|
|
|
|
// This file also provides the common interface to the performance client (see the 'RunClient'
|
|
|
|
// function for details).
|
2015-05-30 12:30:43 +02:00
|
|
|
//
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
#ifndef CLBLAST_TEST_PERFORMANCE_CLIENT_H_
|
|
|
|
#define CLBLAST_TEST_PERFORMANCE_CLIENT_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-03-06 16:34:26 +01:00
|
|
|
#include <utility>
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// The libraries to test
|
2016-04-02 20:58:00 +02:00
|
|
|
#ifdef CLBLAST_REF_CLBLAS
|
|
|
|
#include <clBLAS.h>
|
|
|
|
#endif
|
2015-05-30 12:30:43 +02:00
|
|
|
#include "clblast.h"
|
|
|
|
|
|
|
|
#include "internal/utilities.h"
|
|
|
|
|
|
|
|
namespace clblast {
|
|
|
|
// =================================================================================================
|
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// See comment at top of file for a description of the class
|
2015-07-10 07:18:12 +02:00
|
|
|
template <typename T, typename U>
|
2015-06-29 20:38:34 +02:00
|
|
|
class Client {
|
|
|
|
public:
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// Shorthand for the routine-specific functions passed to the tester
|
2016-04-02 20:58:00 +02:00
|
|
|
using Routine = std::function<StatusCode(const Arguments<U>&, Buffers<T>&, Queue&)>;
|
2015-07-10 07:18:12 +02:00
|
|
|
using SetMetric = std::function<void(Arguments<U>&)>;
|
|
|
|
using GetMetric = std::function<size_t(const Arguments<U>&)>;
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// The constructor
|
2016-04-02 20:58:00 +02:00
|
|
|
Client(const Routine run_routine, const Routine run_reference1, const Routine run_reference2,
|
2015-06-29 20:38:34 +02:00
|
|
|
const std::vector<std::string> &options,
|
|
|
|
const GetMetric get_flops, const GetMetric get_bytes);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// 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.
|
2016-06-16 18:07:46 +02:00
|
|
|
Arguments<U> ParseArguments(int argc, char *argv[], const size_t level,
|
|
|
|
const GetMetric default_a_ld,
|
|
|
|
const GetMetric default_b_ld,
|
|
|
|
const GetMetric default_c_ld);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// The main client function, setting-up arguments, matrices, OpenCL buffers, etc. After set-up, it
|
|
|
|
// calls the client routines.
|
2015-07-10 07:18:12 +02:00
|
|
|
void PerformanceTest(Arguments<U> &args, const SetMetric set_sizes);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
private:
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// Runs a function a given number of times and returns the execution time of the shortest instance
|
2016-04-02 20:58:00 +02:00
|
|
|
double TimedExecution(const size_t num_runs, const Arguments<U> &args, Buffers<T> &buffers,
|
2015-07-27 07:18:06 +02:00
|
|
|
Queue &queue, Routine run_blas, const std::string &library_name);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// Prints the header of a performance-data table
|
2016-03-06 16:34:26 +01:00
|
|
|
void PrintTableHeader(const Arguments<U>& args);
|
2015-06-29 20:38:34 +02:00
|
|
|
|
|
|
|
// Prints a row of performance data, including results of two libraries
|
2016-03-06 16:34:26 +01:00
|
|
|
void PrintTableRow(const Arguments<U>& args,
|
|
|
|
const std::vector<std::pair<std::string, double>>& timings);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// The routine-specific functions passed to the tester
|
|
|
|
const Routine run_routine_;
|
2016-04-02 20:58:00 +02:00
|
|
|
const Routine run_reference1_;
|
|
|
|
const Routine run_reference2_;
|
2015-06-29 20:38:34 +02:00
|
|
|
const std::vector<std::string> options_;
|
|
|
|
const GetMetric get_flops_;
|
|
|
|
const GetMetric get_bytes_;
|
|
|
|
};
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
|
2016-04-02 20:58:00 +02:00
|
|
|
// Bogus reference function, in case a comparison library is not available
|
|
|
|
template <typename T, typename U>
|
|
|
|
static StatusCode ReferenceNotAvailable(const Arguments<U> &, Buffers<T> &, Queue &) {
|
|
|
|
return StatusCode::kNotImplemented;
|
|
|
|
}
|
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// 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".
|
2015-07-10 07:18:12 +02:00
|
|
|
template <typename C, typename T, typename U>
|
2015-06-29 20:38:34 +02:00
|
|
|
void RunClient(int argc, char *argv[]) {
|
|
|
|
|
2016-04-02 20:58:00 +02:00
|
|
|
// Sets the reference to test against
|
|
|
|
#ifdef CLBLAST_REF_CLBLAS
|
2016-06-16 18:07:46 +02:00
|
|
|
auto reference1 = C::RunReference1; // clBLAS when available
|
2016-04-02 20:58:00 +02:00
|
|
|
#else
|
2016-06-16 18:07:46 +02:00
|
|
|
auto reference1 = ReferenceNotAvailable<T,U>;
|
2016-04-02 20:58:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CLBLAST_REF_CBLAS
|
2016-06-16 18:07:46 +02:00
|
|
|
auto reference2 = C::RunReference2; // CBLAS when available
|
2016-04-02 20:58:00 +02:00
|
|
|
#else
|
2016-06-16 18:07:46 +02:00
|
|
|
auto reference2 = ReferenceNotAvailable<T,U>;
|
2016-04-02 20:58:00 +02:00
|
|
|
#endif
|
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// Creates a new client
|
2016-04-02 20:58:00 +02:00
|
|
|
auto client = Client<T,U>(C::RunRoutine, reference1, reference2, C::GetOptions(),
|
2015-07-10 07:18:12 +02:00
|
|
|
C::GetFlops, C::GetBytes);
|
2015-06-29 20:38:34 +02:00
|
|
|
|
|
|
|
// Simple command line argument parser with defaults
|
2016-06-16 18:07:46 +02:00
|
|
|
auto args = client.ParseArguments(argc, argv, C::BLASLevel(),
|
|
|
|
C::DefaultLDA, C::DefaultLDB, C::DefaultLDC);
|
2015-06-29 20:38:34 +02:00
|
|
|
if (args.print_help) { return; }
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-06-29 20:38:34 +02:00
|
|
|
// Runs the client
|
|
|
|
client.PerformanceTest(args, C::SetSizes);
|
|
|
|
}
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
} // namespace clblast
|
|
|
|
|
|
|
|
// CLBLAST_TEST_PERFORMANCE_CLIENT_H_
|
|
|
|
#endif
|