diff options
Diffstat (limited to 'src/tuning/kernels/xgemm_direct.cpp')
-rw-r--r-- | src/tuning/kernels/xgemm_direct.cpp | 184 |
1 files changed, 88 insertions, 96 deletions
diff --git a/src/tuning/kernels/xgemm_direct.cpp b/src/tuning/kernels/xgemm_direct.cpp index 03b40a50..619fb37a 100644 --- a/src/tuning/kernels/xgemm_direct.cpp +++ b/src/tuning/kernels/xgemm_direct.cpp @@ -27,78 +27,103 @@ template <typename T, int V> class TuneXgemmDirect { public: - // The representative kernel and the source code - static std::string KernelFamily() { return (V==1) ? "xgemm_direct_1" : "xgemm_direct_2"; } - static std::string KernelName() { return "XgemmDirectTN"; } - static std::string GetSources() { - return - #include "../src/kernels/common.opencl" - #include "../src/kernels/level3/xgemm_direct_part1.opencl" - #include "../src/kernels/level3/xgemm_direct_part2.opencl" - #include "../src/kernels/level3/xgemm_direct_part3.opencl" - ; + // Settings for this kernel (default command-line arguments) + static TunerDefaults GetTunerDefaults() { + auto settings = TunerDefaults(); + settings.options = {kArgM, kArgN, kArgK, kArgAlpha, kArgBeta, kArgFraction, + kArgHeuristicSelection, kArgPsoSwarmSize, + kArgPsoInfGlobal, kArgPsoInfLocal, kArgPsoInfRandom}; + settings.default_m = 256; + settings.default_n = 256; + settings.default_k = 256; + settings.default_fraction = (V==1) ? 1.0 : 32.0; // test all or sample randomly + settings.default_num_runs = 4; + settings.default_heuristic = static_cast<size_t>(cltune::SearchMethod::RandomSearch); + return settings; } - // The list of arguments relevant for this routine - static std::vector<std::string> GetOptions() { - return {kArgM, kArgN, kArgK, kArgAlpha, kArgBeta, kArgFraction, - kArgHeuristicSelection, kArgPsoSwarmSize, - kArgPsoInfGlobal, kArgPsoInfLocal, kArgPsoInfRandom}; - } + // Settings for this kernel (general) + static TunerSettings GetTunerSettings(const Arguments<T> &args) { + auto settings = TunerSettings(); + + // Identification of the kernel + settings.kernel_family = (V==1) ? "xgemm_direct_1" : "xgemm_direct_2"; + settings.kernel_name = "XgemmDirectTN"; + settings.sources = +#include "../src/kernels/common.opencl" +#include "../src/kernels/level3/xgemm_direct_part1.opencl" +#include "../src/kernels/level3/xgemm_direct_part2.opencl" +#include "../src/kernels/level3/xgemm_direct_part3.opencl" + ; - // Tests for valid arguments - static void TestValidArguments(const Arguments<T> &) { } + // Buffer sizes + settings.size_a = args.m * args.k; + settings.size_b = args.n * args.k; + settings.size_c = args.m * args.n; - // Sets the default values for the arguments - static size_t DefaultM() { return 256; } - static size_t DefaultN() { return 256; } - static size_t DefaultK() { return 256; } - static size_t DefaultBatchCount() { return 1; } // N/A for this kernel - static double DefaultFraction() { return (V==1) ? 1.0 : 32.0; } // test all or sample randomly - static size_t DefaultNumRuns() { return 4; } // run every kernel this many times for averaging - static size_t DefaultSwarmSizePSO() { return 8; } - static double DefaultInfluenceGlobalPSO(){ return 0.1; } - static double DefaultInfluenceLocalPSO(){ return 0.3; } - static double DefaultInfluenceRandomPSO(){ return 0.6; } - static size_t DefaultHeuristic(){ return static_cast<size_t>(cltune::SearchMethod::RandomSearch);} - static double DefaultMaxTempAnn(){ return 1.0;} - - // Describes how to obtain the sizes of the buffers - static size_t GetSizeX(const Arguments<T> &) { return 1; } // N/A for this kernel - static size_t GetSizeY(const Arguments<T> &) { return 1; } // N/A for this kernel - static size_t GetSizeA(const Arguments<T> &args) { return args.m * args.k; } - static size_t GetSizeB(const Arguments<T> &args) { return args.n * args.k; } - static size_t GetSizeC(const Arguments<T> &args) { return args.m * args.n; } - static size_t GetSizeTemp(const Arguments<T> &) { return 1; } // N/A for this kernel - - // Sets the tuning parameters and their possible values - static void SetParameters(cltune::Tuner &tuner, const size_t id) { + // Sets the base thread configuration + settings.global_size = {args.m, args.n}; + settings.global_size_ref = settings.global_size; + settings.local_size = {1, 1}; + settings.local_size_ref = {8, 8}; + + // Transforms the thread configuration based on the parameters + settings.mul_local = {{"MDIMCD", "NDIMCD"}}; + settings.mul_global = {{"MDIMCD", "NDIMCD"}}; + settings.div_global = {{"WGD", "WGD"}}; + + // Sets the tuning parameters and their possible values if (V==1) { // limited subset of tuning parameters - but explorable exhaustively - tuner.AddParameter(id, "WGD", {8, 16, 32}); - tuner.AddParameter(id, "MDIMCD", {8, 16, 32}); - tuner.AddParameter(id, "NDIMCD", {8, 16, 32}); - tuner.AddParameter(id, "MDIMAD", {8, 16, 32}); - tuner.AddParameter(id, "NDIMBD", {8, 16, 32}); - tuner.AddParameter(id, "KWID", {2}); - tuner.AddParameter(id, "VWMD", {1, 2, 4, 8}); - tuner.AddParameter(id, "VWND", {1, 2, 4, 8}); - tuner.AddParameter(id, "PADA", {1}); - tuner.AddParameter(id, "PADB", {1}); - } // a lot more tuning parameters - has to be sampled randomly, too much to test all + settings.parameters = { + {"WGD", {8, 16, 32}}, + {"MDIMCD", {8, 16, 32}}, + {"NDIMCD", {8, 16, 32}}, + {"MDIMAD", {8, 16, 32}}, + {"NDIMBD", {8, 16, 32}}, + {"KWID", {2}}, + {"VWMD", {1, 2, 4, 8}}, + {"VWND", {1, 2, 4, 8}}, + {"PADA", {1}}, + {"PADB", {1}}, + }; + } + else { // a lot more tuning parameters - has to be sampled randomly, too much to test all + settings.parameters = { + {"WGD", {8, 16, 32, 64, 128}}, + {"MDIMCD", {8, 16, 32}}, + {"NDIMCD", {8, 16, 32}}, + {"MDIMAD", {8, 16, 32}}, + {"NDIMBD", {8, 16, 32}}, + {"KWID", {2, 8, 16}}, + {"VWMD", {1, 2, 4, 8}}, + {"VWND", {1, 2, 4, 8}}, + {"PADA", {0, 1}}, + {"PADB", {0, 1}}, + }; + } + + // Describes how to compute the performance metrics + settings.metric_amount = 2 * args.m * args.n * args.k; + settings.performance_unit = "GFLOPS"; + + // Returns which search heuristic to use + if (V==1) { settings.heuristic = static_cast<size_t>(cltune::SearchMethod::FullSearch); } else { - tuner.AddParameter(id, "WGD", {8, 16, 32, 64, 128}); - tuner.AddParameter(id, "MDIMCD", {8, 16, 32}); - tuner.AddParameter(id, "NDIMCD", {8, 16, 32}); - tuner.AddParameter(id, "MDIMAD", {8, 16, 32}); - tuner.AddParameter(id, "NDIMBD", {8, 16, 32}); - tuner.AddParameter(id, "KWID", {2, 8, 16}); - tuner.AddParameter(id, "VWMD", {1, 2, 4, 8}); - tuner.AddParameter(id, "VWND", {1, 2, 4, 8}); - tuner.AddParameter(id, "PADA", {0, 1}); - tuner.AddParameter(id, "PADB", {0, 1}); + // Use full-search to explore all parameter combinations or another strategy to search only a + // part of the parameter values. The fraction is set as a command-line argument. + if (args.fraction == 1.0 || args.fraction == 0.0) { + settings.heuristic = static_cast<size_t>(cltune::SearchMethod::FullSearch); + } else { + settings.heuristic = args.heuristic_selection; + } } + + return settings; } + // Tests for valid arguments + static void TestValidArguments(const Arguments<T> &) { } + // Sets the constraints static void SetConstraints(cltune::Tuner &tuner, const size_t id) { auto MultipleOfX = [] (std::vector<size_t> v) { return IsMultiple(v[0], v[1]); }; @@ -132,19 +157,6 @@ class TuneXgemmDirect { tuner.SetLocalMemoryUsage(id, LocalMemorySize, {"WGD", "PADA", "PADB"}); } - // Sets the base thread configuration - static std::vector<size_t> GlobalSize(const Arguments<T> &args) { return {args.m, args.n}; } - static std::vector<size_t> GlobalSizeRef(const Arguments<T> &args) { return GlobalSize(args); } - static std::vector<size_t> LocalSize() { return {1, 1}; } - static std::vector<size_t> LocalSizeRef() { return {8, 8}; } - - // Transforms the thread configuration based on the parameters - using TransformVector = std::vector<std::vector<std::string>>; - static TransformVector MulLocal() { return {{"MDIMCD", "NDIMCD"}}; } - static TransformVector DivLocal() { return {}; } - static TransformVector MulGlobal() { return {{"MDIMCD", "NDIMCD"}}; } - static TransformVector DivGlobal() { return {{"WGD", "WGD"}}; } - // Sets the kernel's arguments static void SetArguments(cltune::Tuner &tuner, const Arguments<T> &args, std::vector<T> &, std::vector<T> &, @@ -168,26 +180,6 @@ class TuneXgemmDirect { tuner.AddArgumentScalar(0); // a_conjugate tuner.AddArgumentScalar(0); // b_conjugate } - - // Describes how to compute the performance metrics - static size_t GetMetric(const Arguments<T> &args) { - return 2 * args.m * args.n * args.k; - } - static std::string PerformanceUnit() { return "GFLOPS"; } - - // Returns which Heuristic to run - static size_t GetHeuristic(const Arguments<T> &args){ - if (V==1) { return static_cast<size_t>(cltune::SearchMethod::FullSearch); } - else { - // Use full-search to explore all parameter combinations or another strategy to search only a - // part of the parameter values. The fraction is set as a command-line argument. - if (args.fraction == 1.0 || args.fraction == 0.0) { - return static_cast<size_t>(cltune::SearchMethod::FullSearch); - } else { - return args.heuristic_selection; - } - } - } }; // ================================================================================================= |