summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCNugteren <web@cedricnugteren.nl>2015-06-26 08:12:56 +0200
committerCNugteren <web@cedricnugteren.nl>2015-06-26 08:12:56 +0200
commit7c8d16147a2e66de0ba11a18cbdf062bfd7ea66e (patch)
tree5ba2171c0a7648dcddf8b4c2cc2667997860d89c /test
parent75f263ce3aa35f57115670af18719137b3020e79 (diff)
Added the SYR2K routine, tester, and client
Diffstat (limited to 'test')
-rw-r--r--test/correctness/routines/xsyr2k.cc99
-rw-r--r--test/performance/graphs/xsyr2k.r94
-rw-r--r--test/performance/routines/xsyr2k.cc115
3 files changed, 308 insertions, 0 deletions
diff --git a/test/correctness/routines/xsyr2k.cc b/test/correctness/routines/xsyr2k.cc
new file mode 100644
index 00000000..3365e6a8
--- /dev/null
+++ b/test/correctness/routines/xsyr2k.cc
@@ -0,0 +1,99 @@
+
+// =================================================================================================
+// 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 Xsyr2k 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 Xsyr2kTest(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 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);
+ };
+
+ // 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 = clblasXsyr2k(static_cast<clblasOrder>(args.layout),
+ static_cast<clblasUplo>(args.triangle),
+ static_cast<clblasTranspose>(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);
+ return static_cast<StatusCode>(status);
+ };
+
+ // Initializes the arguments relevant for this routine
+ auto args = Arguments<T>{};
+ const auto options = std::vector<std::string>{kArgN, kArgK, kArgLayout,
+ kArgTriangle, kArgATransp,
+ 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 &triangle: {Triangle::kUpper, Triangle::kLower}) {
+ args.triangle = triangle;
+ for (auto &ab_transpose: {Transpose::kNo, Transpose::kYes}) { // No conjugate here since it is
+ args.a_transpose = ab_transpose; // not supported by clBLAS
+ args.b_transpose = ab_transpose;
+ const auto case_name = ToString(layout)+" "+ToString(triangle)+" "+ToString(ab_transpose);
+
+ // 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::Xsyr2kTest<float>(argc, argv, false, "SSYR2K");
+ clblast::Xsyr2kTest<double>(argc, argv, true, "DSYR2K");
+ clblast::Xsyr2kTest<clblast::float2>(argc, argv, true, "CSYR2K");
+ clblast::Xsyr2kTest<clblast::double2>(argc, argv, true, "ZSYR2K");
+ return 0;
+}
+
+// =================================================================================================
diff --git a/test/performance/graphs/xsyr2k.r b/test/performance/graphs/xsyr2k.r
new file mode 100644
index 00000000..0c6c0de2
--- /dev/null
+++ b/test/performance/graphs/xsyr2k.r
@@ -0,0 +1,94 @@
+
+# ==================================================================================================
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
+# project 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 performance script for the Xsyr2k routine
+#
+# ==================================================================================================
+
+# Includes the common functions
+args <- commandArgs(trailingOnly = FALSE)
+thisfile <- (normalizePath(sub("--file=", "", args[grep("--file=", args)])))
+source(file.path(dirname(thisfile), "common.r"))
+
+# ==================================================================================================
+
+# Settings
+routine_name <- "xsyr2k"
+parameters <- c("-n","-k","-layout","-triangle","-transA",
+ "-num_steps","-step","-runs","-precision")
+precision <- 32
+
+# Sets the names of the test-cases
+test_names <- list(
+ "multiples of 128",
+ "multiples of 128 (+1)",
+ "around n=k=512",
+ "around n=k=1536",
+ "layouts and transposing (n=k=1024)",
+ "powers of 2"
+)
+
+# Defines the test-cases
+test_values <- list(
+ list(c(128, 128, 0, 0, 0, 16, 128, num_runs, precision)),
+ list(c(129, 129, 0, 0, 0, 16, 128, num_runs, precision)),
+ list(c(512, 512, 0, 0, 0, 16, 1, num_runs, precision)),
+ list(c(1536, 1536, 0, 0, 0, 16, 1, num_runs, precision)),
+ list(
+ c(1024, 1024, 0, 0, 0, 1, 0, num_runs, precision),
+ c(1024, 1024, 0, 0, 1, 1, 0, num_runs, precision),
+ c(1024, 1024, 0, 1, 0, 1, 0, num_runs, precision),
+ c(1024, 1024, 0, 1, 1, 1, 0, num_runs, precision),
+ c(1024, 1024, 1, 0, 0, 1, 0, num_runs, precision),
+ c(1024, 1024, 1, 0, 1, 1, 0, num_runs, precision),
+ c(1024, 1024, 1, 1, 0, 1, 0, num_runs, precision),
+ c(1024, 1024, 1, 1, 1, 1, 0, num_runs, precision)
+ ),
+ list(
+ c(8, 8, 0, 0, 0, 1, 0, num_runs, precision),
+ c(16, 16, 0, 0, 0, 1, 0, num_runs, precision),
+ c(32, 32, 0, 0, 0, 1, 0, num_runs, precision),
+ c(64, 64, 0, 0, 0, 1, 0, num_runs, precision),
+ c(128, 128, 0, 0, 0, 1, 0, num_runs, precision),
+ c(256, 256, 0, 0, 0, 1, 0, num_runs, precision),
+ c(512, 512, 0, 0, 0, 1, 0, num_runs, precision),
+ c(1024, 1024, 0, 0, 0, 1, 0, num_runs, precision),
+ c(2048, 2048, 0, 0, 0, 1, 0, num_runs, precision),
+ c(4096, 4096, 0, 0, 0, 1, 0, num_runs, precision),
+ c(8192, 8192, 0, 0, 0, 1, 0, num_runs, precision)
+ )
+)
+
+# Defines the x-labels corresponding to the test-cases
+test_xlabels <- list(
+ "matrix sizes (n=k)",
+ "matrix sizes (n=k)",
+ "matrix sizes (n=k)",
+ "matrix sizes (n=k)",
+ "layout (row/col), triangle (u/l), transA (n/y)",
+ "matrix sizes (n=k)"
+)
+
+# Defines the x-axis of the test-cases
+test_xaxis <- list(
+ c("n", ""),
+ c("n", ""),
+ c("n", ""),
+ c("n", ""),
+ list(1:8, c("row,u,n", "row,u,y", "row,l,n", "row,l,y",
+ "col,u,n", "col,u,y", "col,l,n", "col,l,y")),
+ c("n", "x")
+)
+
+# ==================================================================================================
+
+# Start the script
+main(routine_name=routine_name, precision=precision, test_names=test_names, test_values=test_values,
+ test_xlabels=test_xlabels, test_xaxis=test_xaxis, metric_gflops=TRUE)
+
+# ================================================================================================== \ No newline at end of file
diff --git a/test/performance/routines/xsyr2k.cc b/test/performance/routines/xsyr2k.cc
new file mode 100644
index 00000000..8d9871d0
--- /dev/null
+++ b/test/performance/routines/xsyr2k.cc
@@ -0,0 +1,115 @@
+
+// =================================================================================================
+// 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 implements the Xsyr2k command-line interface tester.
+//
+// =================================================================================================
+
+#include <string>
+#include <vector>
+#include <exception>
+
+#include "wrapper_clblas.h"
+#include "performance/client.h"
+
+namespace clblast {
+// =================================================================================================
+
+// The client, used for performance testing. It contains the function calls to CLBlast and to other
+// libraries to compare against.
+template <typename T>
+void PerformanceXsyr2k(const Arguments<T> &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<int>(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<clblasOrder>(args.layout),
+ static_cast<clblasUplo>(args.triangle),
+ static_cast<clblasTranspose>(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<int>(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<size_t>{args.n, args.k,
+ static_cast<size_t>(args.layout),
+ static_cast<size_t>(args.triangle),
+ static_cast<size_t>(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<std::string>{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<std::string>{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<float>(argc, argv, PerformanceXsyr2k<float>, o, true); break;
+ case Precision::kDouble: ClientABC<double>(argc, argv, PerformanceXsyr2k<double>, o, true); break;
+ case Precision::kComplexSingle: ClientABC<float2>(argc, argv, PerformanceXsyr2k<float2>, o, true); break;
+ case Precision::kComplexDouble: ClientABC<double2>(argc, argv, PerformanceXsyr2k<double2>, o, true); break;
+ }
+}
+
+// =================================================================================================
+} // namespace clblast
+
+// Main function (not within the clblast namespace)
+int main(int argc, char *argv[]) {
+ clblast::ClientXsyr2k(argc, argv);
+ return 0;
+}
+
+// =================================================================================================