summaryrefslogtreecommitdiff
path: root/test/correctness/testblas.h
blob: 7469700da33c298ecb24fdb8af94605f4ee79d81 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// =================================================================================================
// 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 tests any CLBlast routine. It contains two types of tests: one testing all sorts of
// input combinations, and one deliberatly testing with invalid values.
//
// =================================================================================================

#ifndef CLBLAST_TEST_CORRECTNESS_TESTBLAS_H_
#define CLBLAST_TEST_CORRECTNESS_TESTBLAS_H_

#include <vector>
#include <string>

#include "correctness/tester.h"

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

// See comment at top of file for a description of the class
template <typename T>
class TestBlas: public Tester<T> {
 public:

  // Uses several variables from the Tester class
  using Tester<T>::context_;
  using Tester<T>::queue_;

  // Uses several helper functions from the Tester class
  using Tester<T>::TestStart;
  using Tester<T>::TestEnd;
  using Tester<T>::TestSimilarity;
  using Tester<T>::TestErrorCount;
  using Tester<T>::TestErrorCodes;
  using Tester<T>::GetExampleScalars;
  using Tester<T>::GetOffsets;
  using Tester<T>::PrecisionSupported;

  // Test settings for the regular test. Append to these lists in case more tests are required.
  const std::vector<size_t> kVectorDims = { 7, 93, 4096 };
  const std::vector<size_t> kIncrements = { 1, 2, 7 };
  const std::vector<size_t> kMatrixDims = { 7, 64 };
  const std::vector<size_t> kMatrixVectorDims = { 61, 512 };
  const std::vector<size_t> kOffsets = GetOffsets();
  const std::vector<T> kAlphaValues = GetExampleScalars();
  const std::vector<T> kBetaValues = GetExampleScalars();

  // Test settings for the invalid tests
  const std::vector<size_t> kInvalidIncrements = { 0, 1 };
  const size_t kBufferSize = 64;
  const std::vector<size_t> kMatSizes = {0, kBufferSize*kBufferSize-1, kBufferSize*kBufferSize};
  const std::vector<size_t> kVecSizes = {0, kBufferSize - 1, kBufferSize};

  // The layout/transpose/triangle options to test with
  const std::vector<Layout> kLayouts = {Layout::kRowMajor, Layout::kColMajor};
  const std::vector<Triangle> kTriangles = {Triangle::kUpper, Triangle::kLower};
  const std::vector<Side> kSides = {Side::kLeft, Side::kRight};
  const std::vector<Diagonal> kDiagonals = {Diagonal::kUnit, Diagonal::kNonUnit};
  static const std::vector<Transpose> kTransposes; // Data-type dependent, see .cc-file

  // Shorthand for the routine-specific functions passed to the tester
  using Routine = std::function<StatusCode(const Arguments<T>&, const Buffers&, CommandQueue&)>;
  using ResultGet = std::function<std::vector<T>(const Arguments<T>&, Buffers&, CommandQueue&)>;
  using ResultIndex = std::function<size_t(const Arguments<T>&, const size_t, const size_t)>;
  using ResultIterator = std::function<size_t(const Arguments<T>&)>;

  // Constructor, initializes the base class tester and input data
  TestBlas(int argc, char *argv[], const bool silent,
           const std::string &name, const std::vector<std::string> &options,
           const Routine run_routine, const Routine run_reference, const ResultGet get_result,
           const ResultIndex get_index, const ResultIterator get_id1, const ResultIterator get_id2);

  // The test functions, taking no inputs
  void TestRegular(std::vector<Arguments<T>> &test_vector, const std::string &name);
  void TestInvalid(std::vector<Arguments<T>> &test_vector, const std::string &name);

 private:

  // Source data to test with
  std::vector<T> x_source_;
  std::vector<T> y_source_;
  std::vector<T> a_source_;
  std::vector<T> b_source_;
  std::vector<T> c_source_;
  
  // The routine-specific functions passed to the tester
  Routine run_routine_;
  Routine run_reference_;
  ResultGet get_result_;
  ResultIndex get_index_;
  ResultIterator get_id1_;
  ResultIterator get_id2_;
};

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

// CLBLAST_TEST_CORRECTNESS_TESTBLAS_H_
#endif