summaryrefslogtreecommitdiff
path: root/src/tuning
diff options
context:
space:
mode:
authorCNugteren <web@cedricnugteren.nl>2015-06-14 11:15:53 +0200
committerCNugteren <web@cedricnugteren.nl>2015-06-14 11:15:53 +0200
commit294a3e3d410c87ffcc7fc550e09b6d45c71a0af8 (patch)
treed68a45bb8312aabba9589bb1c51b2c6ffe0dc504 /src/tuning
parentab0064dab76c83ee9820acb62fa914c493c2563d (diff)
Split the three variations of the GEMV kernel for maximal tuning freedom
Diffstat (limited to 'src/tuning')
-rw-r--r--src/tuning/tuning.cc54
-rw-r--r--src/tuning/xgemv.cc62
2 files changed, 71 insertions, 45 deletions
diff --git a/src/tuning/tuning.cc b/src/tuning/tuning.cc
index d617af88..2dcb11d5 100644
--- a/src/tuning/tuning.cc
+++ b/src/tuning/tuning.cc
@@ -75,7 +75,8 @@ template void TunerXY<double2>(int, char**, const Tuner2<double2>&);
// Function to get command-line argument, set-up the input buffers, configure the tuner, and collect
// the results. Used for matrix-vector-vector routines.
template <typename T>
-void TunerAXY(int argc, char* argv[], const Tuner3<T> &tune_function) {
+void TunerAXY(int argc, char* argv[], const size_t num_variations,
+ const Tuner3V<T> &tune_function) {
// Sets the parameters and platform/device for which to tune (command-line options)
auto help = std::string{"* Options given/available:\n"};
@@ -83,11 +84,10 @@ void TunerAXY(int argc, char* argv[], const Tuner3<T> &tune_function) {
args.platform_id = GetArgument(argc, argv, help, kArgPlatform, size_t{0});
args.device_id = GetArgument(argc, argv, help, kArgDevice, size_t{0});
args.precision = GetArgument(argc, argv, help, kArgPrecision, Precision::kSingle);
- args.m = GetArgument(argc, argv, help, kArgM, size_t{1024});
- args.n = GetArgument(argc, argv, help, kArgN, size_t{1024});
+ args.m = GetArgument(argc, argv, help, kArgM, size_t{2048});
+ args.n = GetArgument(argc, argv, help, kArgN, size_t{2048});
args.alpha = GetArgument(argc, argv, help, kArgAlpha, GetScalar<T>());
args.beta = GetArgument(argc, argv, help, kArgBeta, GetScalar<T>());
- args.layout = GetArgument(argc, argv, help, kArgLayout, Layout::kColMajor);
fprintf(stdout, "%s\n", help.c_str());
// Creates input buffers with random data
@@ -98,36 +98,40 @@ void TunerAXY(int argc, char* argv[], const Tuner3<T> &tune_function) {
PopulateVector(x_vec);
PopulateVector(y_vec);
- // Initializes the tuner for the chosen device
- cltune::Tuner tuner(args.platform_id, args.device_id);
+ // Loop over the different variations of the kernel
+ for (auto variation=size_t{1}; variation<=num_variations; ++variation) {
- // Use full-search to explore all parameter combinations.
- tuner.UseFullSearch();
+ // Initializes the tuner for the chosen device
+ cltune::Tuner tuner(args.platform_id, args.device_id);
- // Configures the tuning parameters (kernel specific)
- tune_function(args, a_mat, x_vec, y_vec, tuner);
+ // Use full-search to explore all parameter combinations.
+ tuner.UseFullSearch();
- // Starts the tuning process
- tuner.Tune();
+ // Configures the tuning parameters (kernel specific)
+ tune_function(args, variation, a_mat, x_vec, y_vec, tuner);
- // Prints the results to screen
- auto time_ms = tuner.PrintToScreen();
- tuner.PrintFormatted();
+ // Starts the tuning process
+ tuner.Tune();
- // Also prints the performance of the best-case in terms of GB/s and GFLOPS
- const auto mega_bytes = ((args.m*args.n + 2*args.m + args.n)*GetBytes(args.precision)) * 1.0e-6;
- const auto mega_flops = (2*args.m*args.n) * 1.0e-6;
- if (time_ms != 0.0) {
- printf("[ -------> ] %.1lf ms or %.1lf GB/s or %.1lf GFLOPS\n",
- time_ms, mega_bytes/time_ms, mega_flops/time_ms);
+ // Prints the results to screen
+ auto time_ms = tuner.PrintToScreen();
+ tuner.PrintFormatted();
+
+ // Also prints the performance of the best-case in terms of GB/s and GFLOPS
+ const auto mega_bytes = ((args.m*args.n + 2*args.m + args.n)*GetBytes(args.precision)) * 1.0e-6;
+ const auto mega_flops = (2*args.m*args.n) * 1.0e-6;
+ if (time_ms != 0.0) {
+ printf("[ -------> ] %.1lf ms or %.1lf GB/s or %.1lf GFLOPS\n",
+ time_ms, mega_bytes/time_ms, mega_flops/time_ms);
+ }
}
}
// Compiles the above function
-template void TunerAXY<float>(int, char**, const Tuner3<float>&);
-template void TunerAXY<double>(int, char**, const Tuner3<double>&);
-template void TunerAXY<float2>(int, char**, const Tuner3<float2>&);
-template void TunerAXY<double2>(int, char**, const Tuner3<double2>&);
+template void TunerAXY<float>(int, char**, const size_t, const Tuner3V<float>&);
+template void TunerAXY<double>(int, char**, const size_t, const Tuner3V<double>&);
+template void TunerAXY<float2>(int, char**, const size_t, const Tuner3V<float2>&);
+template void TunerAXY<double2>(int, char**, const size_t, const Tuner3V<double2>&);
// =================================================================================================
diff --git a/src/tuning/xgemv.cc b/src/tuning/xgemv.cc
index e2d54729..dccd250c 100644
--- a/src/tuning/xgemv.cc
+++ b/src/tuning/xgemv.cc
@@ -8,6 +8,10 @@
// Cedric Nugteren <www.cedricnugteren.nl>
//
// This file implements an auto-tuner to tune the Xgemv OpenCL kernel. It uses the CLTune library.
+// Three variations of the kernel are tuned:
+// 1: The full version of the kernel
+// 2: The fast version for non-transposed matrices
+// 3: The fast version for transposed matrices
//
// =================================================================================================
@@ -23,43 +27,60 @@ namespace clblast {
// The Xgemv auto-tuner
template <typename T>
-void XgemvTune(const Arguments<T> &args,
+void XgemvTune(const Arguments<T> &args, const size_t variation,
const std::vector<T> &a_mat, const std::vector<T> &x_vec, std::vector<T> &y_vec,
cltune::Tuner &tuner) {
+ // Sets the kernel name and the layout argument
+ auto kernel_name = (variation == 1) ? "Xgemv" : ((variation == 2) ? "XgemvFast" : "XgemvFastRot");
+ auto a_rotated = (variation == 3) ? 1 : 0;
+
// This points to the Xgemv kernel as found in the CLBlast library
std::string common_source =
#include "../src/kernels/common.opencl"
std::string kernel_source =
#include "../src/kernels/xgemv.opencl"
auto sources = common_source + kernel_source;
- auto id = tuner.AddKernelFromString(sources, "XgemvFast", {args.m}, {1});
+ auto id = tuner.AddKernelFromString(sources, kernel_name, {args.m}, {1});
tuner.SetReferenceFromString(sources, "Xgemv", {args.m}, {64});
- // Sets the tunable parameters and their possible values
- tuner.AddParameter(id, "WGS", {64, 128, 256, 512, 1024, 1536, 2048});
- tuner.AddParameter(id, "WPT", {1, 2, 4, 8});
- tuner.AddParameter(id, "VW", {1, 2, 4, 8});
+ // Helper for the constraints
+ auto MultipleOfX = [] (std::vector<size_t> v) { return IsMultiple(v[0], v[1]); };
+
+ // Sets the tunable parameters, their possible values, the adjusted thread sizes, and constraints
+ if (variation == 1) {
+ tuner.AddParameter(id, "WGS1", {64, 128, 256, 512, 1024, 1536, 2048});
+ tuner.AddParameter(id, "WPT1", {1, 2, 4, 8});
+ tuner.MulLocalSize(id, {"WGS1"});
+ tuner.DivGlobalSize(id, {"WPT1"});
+ }
+ else if (variation == 2) {
+ tuner.AddParameter(id, "WGS2", {64, 128, 256, 512, 1024, 1536, 2048});
+ tuner.AddParameter(id, "WPT2", {1, 2, 4, 8});
+ tuner.AddParameter(id, "VW2", {1, 2, 4, 8});
+ tuner.MulLocalSize(id, {"WGS2"});
+ tuner.DivGlobalSize(id, {"WPT2"});
+ tuner.AddConstraint(id, MultipleOfX, {"WPT2", "VW2"});
+ }
+ else if (variation == 3) {
+ tuner.AddParameter(id, "WGS3", {64, 128, 256, 512, 1024, 1536, 2048});
+ tuner.AddParameter(id, "WPT3", {1, 2, 4, 8});
+ tuner.AddParameter(id, "VW3", {1, 2, 4, 8});
+ tuner.MulLocalSize(id, {"WGS3"});
+ tuner.DivGlobalSize(id, {"WPT3"});
+ tuner.AddConstraint(id, MultipleOfX, {"WGS3", "VW3"});
+ }
// Tests for a specific precision
tuner.AddParameter(id, "PRECISION", {static_cast<size_t>(args.precision)});
tuner.AddParameterReference("PRECISION", static_cast<size_t>(args.precision));
- // Sets the constraints
- auto MultipleOfX = [] (std::vector<size_t> v) { return IsMultiple(v[0], v[1]); };
- tuner.AddConstraint(id, MultipleOfX, {"WGS", "VW"});
- tuner.AddConstraint(id, MultipleOfX, {"WPT", "VW"});
-
- // Modifies the thread-sizes (local) based on the parameters
- tuner.MulLocalSize(id, {"WGS"});
- tuner.DivGlobalSize(id, {"WPT"});
-
// Sets the function's arguments
tuner.AddArgumentScalar(static_cast<int>(args.m));
tuner.AddArgumentScalar(static_cast<int>(args.n));
tuner.AddArgumentScalar(args.alpha);
tuner.AddArgumentScalar(args.beta);
- tuner.AddArgumentScalar(static_cast<int>(args.layout));
+ tuner.AddArgumentScalar(static_cast<int>(a_rotated));
tuner.AddArgumentInput(a_mat);
tuner.AddArgumentScalar(0);
tuner.AddArgumentScalar(static_cast<int>(args.m));
@@ -75,12 +96,13 @@ void XgemvTune(const Arguments<T> &args,
// Main function which calls the common client code with the routine-specific function as argument.
void TunerXgemv(int argc, char *argv[]) {
+ auto num_variations = size_t{3};
switch(GetPrecision(argc, argv)) {
case Precision::kHalf: throw std::runtime_error("Unsupported precision mode");
- case Precision::kSingle: TunerAXY<float>(argc, argv, XgemvTune<float>); break;
- case Precision::kDouble: TunerAXY<double>(argc, argv, XgemvTune<double>); break;
- case Precision::kComplexSingle: TunerAXY<float2>(argc, argv, XgemvTune<float2>); break;
- case Precision::kComplexDouble: TunerAXY<double2>(argc, argv, XgemvTune<double2>); break;
+ case Precision::kSingle: TunerAXY<float>(argc, argv, num_variations, XgemvTune<float>); break;
+ case Precision::kDouble: TunerAXY<double>(argc, argv, num_variations, XgemvTune<double>); break;
+ case Precision::kComplexSingle: TunerAXY<float2>(argc, argv, num_variations, XgemvTune<float2>); break;
+ case Precision::kComplexDouble: TunerAXY<double2>(argc, argv, num_variations, XgemvTune<double2>); break;
}
}