summaryrefslogtreecommitdiff
path: root/test/performance/client.h
blob: 5125844af207a8fa2921e3447a2d2282823936c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// =================================================================================================
// 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>
//
// This file provides common function declarations to be used with the test clients.
//
// =================================================================================================

#ifndef CLBLAST_TEST_PERFORMANCE_CLIENT_H_
#define CLBLAST_TEST_PERFORMANCE_CLIENT_H_

#include <string>
#include <vector>

// The libraries to test
#include <clBLAS.h>
#include "clblast.h"

#include "internal/utilities.h"

namespace clblast {
// =================================================================================================

// 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&)>;

// =================================================================================================

// 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 ClientABC(int argc, char *argv[], Routine3<T> client_routine,
               const std::vector<std::string> &options);

// =================================================================================================

// 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);

// 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, std::function<void()> main_computation);

// =================================================================================================

// 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 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);

// =================================================================================================
} // namespace clblast

// CLBLAST_TEST_PERFORMANCE_CLIENT_H_
#endif