From a17297937d757d9747adde600f832d1e0c2753c1 Mon Sep 17 00:00:00 2001 From: CNugteren Date: Tue, 23 Jun 2015 22:31:27 +0200 Subject: Added performance-client for AC routines --- test/performance/client.cc | 81 +++++++++++++++++++++++++++++++++++++++++++--- test/performance/client.h | 3 ++ 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/test/performance/client.cc b/test/performance/client.cc index 3b07970c..65ff3218 100644 --- a/test/performance/client.cc +++ b/test/performance/client.cc @@ -115,7 +115,7 @@ void ClientAXY(int argc, char *argv[], Routine3 client_routine, auto a_two = (args.layout == Layout::kRowMajor) ? args.m : args.n; // Computes the vector sizes in case the matrix is transposed - auto a_transposed = (args.a_transpose == Transpose::kYes); + auto a_transposed = (args.a_transpose != Transpose::kNo); auto m_real = (a_transposed) ? args.n : args.m; auto n_real = (a_transposed) ? args.m : args.n; @@ -163,10 +163,83 @@ template void ClientAXY(int, char **, Routine3, const std::vec // ================================================================================================= +// This is the matrix-matrix variant of the set-up/tear-down client routine. +template +void ClientAC(int argc, char *argv[], Routine2 client_routine, + const std::vector &options) { + + // Function to determine how to find the default value of the leading dimension of matrix A + auto default_ld_a = [](const Arguments args) { return args.k; }; + + // Simple command line argument parser with defaults + auto args = ParseArguments(argc, argv, options, default_ld_a); + if (args.print_help) { return; } + + // Prints the header of the output table + PrintTableHeader(args.silent, options); + + // Initializes OpenCL and the libraries + auto platform = Platform(args.platform_id); + auto device = Device(platform, kDeviceType, args.device_id); + auto context = Context(device); + auto queue = CommandQueue(context, device); + if (args.compare_clblas) { clblasSetup(); } + + // Computes whether or not the matrices are transposed. Note that we assume a default of + // column-major and no-transpose. If one of them is different (but not both), then rotated + // is considered true. + auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || + (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); + + // Iterates over all "num_step" values jumping by "step" each time + auto s = size_t{0}; + while(true) { + + // Computes the data sizes + auto a_two = (a_rotated) ? args.n : args.k; + auto a_size = a_two * args.a_ld + args.a_offset; + auto c_size = args.n * args.c_ld + args.c_offset; + + // Populates input host matrices with random data + std::vector a_source(a_size); + std::vector c_source(c_size); + PopulateVector(a_source); + PopulateVector(c_source); + + // Creates the matrices on the device + auto a_buffer = Buffer(context, CL_MEM_READ_WRITE, a_size*sizeof(T)); + auto c_buffer = Buffer(context, CL_MEM_READ_WRITE, c_size*sizeof(T)); + a_buffer.WriteBuffer(queue, a_size*sizeof(T), a_source); + c_buffer.WriteBuffer(queue, c_size*sizeof(T), c_source); + + // Runs the routine-specific code + client_routine(args, a_buffer, c_buffer, queue); + + // Makes the jump to the next step + ++s; + if (s >= args.num_steps) { break; } + args.n += args.step; + args.k += args.step; + args.a_ld += args.step; + args.c_ld += args.step; + } + + // Cleans-up and returns + if (args.compare_clblas) { clblasTeardown(); } +} + +// Compiles the above function +template void ClientAC(int, char **, Routine2, const std::vector&); +template void ClientAC(int, char **, Routine2, const std::vector&); +template void ClientAC(int, char **, Routine2, const std::vector&); +template void ClientAC(int, char **, Routine2, const std::vector&); + +// ================================================================================================= + // This is the matrix-matrix-matrix variant of the set-up/tear-down client routine. template void ClientABC(int argc, char *argv[], Routine3 client_routine, - const std::vector &options) { + const std::vector &options) { // Function to determine how to find the default value of the leading dimension of matrix A auto default_ld_a = [](const Arguments args) { return args.m; }; @@ -188,9 +261,9 @@ void ClientABC(int argc, char *argv[], Routine3 client_routine, // Computes whether or not the matrices are transposed. Note that we assume a default of // column-major and no-transpose. If one of them is different (but not both), then rotated // is considered true. - auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose == Transpose::kYes) || + auto a_rotated = (args.layout == Layout::kColMajor && args.a_transpose != Transpose::kNo) || (args.layout == Layout::kRowMajor && args.a_transpose == Transpose::kNo); - auto b_rotated = (args.layout == Layout::kColMajor && args.b_transpose == Transpose::kYes) || + auto b_rotated = (args.layout == Layout::kColMajor && args.b_transpose != Transpose::kNo) || (args.layout == Layout::kRowMajor && args.b_transpose == Transpose::kNo); auto c_rotated = (args.layout == Layout::kRowMajor); diff --git a/test/performance/client.h b/test/performance/client.h index 5125844a..edcd1b68 100644 --- a/test/performance/client.h +++ b/test/performance/client.h @@ -52,6 +52,9 @@ template void ClientAXY(int argc, char *argv[], Routine3 client_routine, const std::vector &options); template +void ClientAC(int argc, char *argv[], Routine2 client_routine, + const std::vector &options); +template void ClientABC(int argc, char *argv[], Routine3 client_routine, const std::vector &options); -- cgit v1.2.3