summaryrefslogtreecommitdiff
path: root/test/correctness/routines/xsymm.cc
blob: 0e02e9ca64f260383c0b0d6da7606136bd3231c8 (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
// =================================================================================================
// This file is part of the CLBlast project. The project is licensed under the MIT license. 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 implements the tests for the Xsymm routine. It is based on the TestABC class.
//
// =================================================================================================

#include "wrapper_clblas.h"
#include "correctness/testabc.h"

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

// The correctness tester, containing the function calls to CLBlast and to clBLAS for comparison.
template <typename T>
void XsymmTest(int argc, char *argv[], const bool silent, const std::string &name) {

  // Creates the CLBlast lambda
  auto clblast_lambda = [](const Arguments<T> &args,
                           const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat,
                           CommandQueue &queue) -> StatusCode {
    auto queue_plain = queue();
    auto event = cl_event{};
    return 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);
  };

  // Creates the clBLAS lambda (for comparison)
  auto clblas_lambda = [](const Arguments<T> &args,
                          const Buffer &a_mat, const Buffer &b_mat, const Buffer &c_mat,
                          CommandQueue &queue) -> StatusCode {
    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);
    return static_cast<StatusCode>(status);
  };

  // Initializes the arguments relevant for this routine
  auto args = Arguments<T>{};
  const auto options = std::vector<std::string>{kArgM, kArgN, kArgLayout,
                                                kArgSide, kArgTriangle,
                                                kArgALeadDim, kArgBLeadDim, kArgCLeadDim,
                                                kArgAOffset, kArgBOffset, kArgCOffset};

  // Creates a tester
  TestABC<T> tester{argc, argv, silent, name, options, clblast_lambda, clblas_lambda};

  // Loops over the test-cases from a data-layout point of view
  for (auto &layout: tester.kLayouts) {
    args.layout = layout;
    for (auto &side: {Side::kLeft, Side::kRight}) {
      args.side = side;
      for (auto &triangle: {Triangle::kUpper, Triangle::kLower}) {
        args.triangle = triangle;
        const auto case_name = ToString(layout)+" "+ToString(side)+" "+ToString(triangle);

        // Runs the tests
        tester.TestRegular(args, case_name, true);
        tester.TestInvalidBufferSizes(args, case_name);
      }
    }
  }
}

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

// Main function (not within the clblast namespace)
int main(int argc, char *argv[]) {
  clblast::XsymmTest<float>(argc, argv, false, "SSYMM");
  clblast::XsymmTest<double>(argc, argv, true, "DSYMM");
  clblast::XsymmTest<clblast::float2>(argc, argv, true, "CSYMM");
  clblast::XsymmTest<clblast::double2>(argc, argv, true, "ZSYMM");
  return 0;
}

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