diff options
author | CNugteren <web@cedricnugteren.nl> | 2015-06-14 11:15:53 +0200 |
---|---|---|
committer | CNugteren <web@cedricnugteren.nl> | 2015-06-14 11:15:53 +0200 |
commit | 294a3e3d410c87ffcc7fc550e09b6d45c71a0af8 (patch) | |
tree | d68a45bb8312aabba9589bb1c51b2c6ffe0dc504 /src/tuning/xgemv.cc | |
parent | ab0064dab76c83ee9820acb62fa914c493c2563d (diff) |
Split the three variations of the GEMV kernel for maximal tuning freedom
Diffstat (limited to 'src/tuning/xgemv.cc')
-rw-r--r-- | src/tuning/xgemv.cc | 62 |
1 files changed, 42 insertions, 20 deletions
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; } } |