From 473e81471895b35dcec5cb82e6beba134c544006 Mon Sep 17 00:00:00 2001 From: mcian Date: Sun, 23 Jul 2017 14:48:13 +0200 Subject: Code refactoring --- src/tuning/kernels/copy_fast.cpp | 14 ++++- src/tuning/kernels/copy_pad.cpp | 14 ++++- src/tuning/kernels/transpose_fast.cpp | 14 ++++- src/tuning/kernels/transpose_pad.cpp | 14 ++++- src/tuning/kernels/xaxpy.cpp | 14 ++++- src/tuning/kernels/xdot.cpp | 14 ++++- src/tuning/kernels/xgemm.cpp | 106 ++++++++++++++++++++-------------- src/tuning/kernels/xgemm_direct.cpp | 64 +++++++++++++++++++- src/tuning/kernels/xgemv.cpp | 14 ++++- src/tuning/kernels/xger.cpp | 14 ++++- 10 files changed, 229 insertions(+), 53 deletions(-) (limited to 'src/tuning/kernels') diff --git a/src/tuning/kernels/copy_fast.cpp b/src/tuning/kernels/copy_fast.cpp index d3d12bed..5d70c219 100644 --- a/src/tuning/kernels/copy_fast.cpp +++ b/src/tuning/kernels/copy_fast.cpp @@ -49,7 +49,14 @@ class TuneCopy { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // Full Search + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &) { return 1; } // N/A for this kernel static size_t GetSizeY(const Arguments &) { return 1; } // N/A for this kernel @@ -99,6 +106,11 @@ class TuneCopy { return 2 * args.m * args.n * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; // Full search + } }; // ================================================================================================= diff --git a/src/tuning/kernels/copy_pad.cpp b/src/tuning/kernels/copy_pad.cpp index 0e157364..c487aaf5 100644 --- a/src/tuning/kernels/copy_pad.cpp +++ b/src/tuning/kernels/copy_pad.cpp @@ -49,7 +49,14 @@ class TunePad { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // Full Search + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &) { return 1; } // N/A for this kernel static size_t GetSizeY(const Arguments &) { return 1; } // N/A for this kernel @@ -107,6 +114,11 @@ class TunePad { return 2 * args.m * args.n * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; // Full Search + } }; // ================================================================================================= diff --git a/src/tuning/kernels/transpose_fast.cpp b/src/tuning/kernels/transpose_fast.cpp index a1ce4220..e169c831 100644 --- a/src/tuning/kernels/transpose_fast.cpp +++ b/src/tuning/kernels/transpose_fast.cpp @@ -49,7 +49,14 @@ class TuneTranspose { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // Full search + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &) { return 1; } // N/A for this kernel static size_t GetSizeY(const Arguments &) { return 1; } // N/A for this kernel @@ -104,6 +111,11 @@ class TuneTranspose { return 2 * args.m * args.n * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; // Full search + } }; // ================================================================================================= diff --git a/src/tuning/kernels/transpose_pad.cpp b/src/tuning/kernels/transpose_pad.cpp index 490580b5..a1695c9f 100644 --- a/src/tuning/kernels/transpose_pad.cpp +++ b/src/tuning/kernels/transpose_pad.cpp @@ -49,7 +49,14 @@ class TunePadTranspose { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; }// N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // N/A for this kernel + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &) { return 1; } // N/A for this kernel static size_t GetSizeY(const Arguments &) { return 1; } // N/A for this kernel @@ -111,6 +118,11 @@ class TunePadTranspose { return 2 * args.m * args.n * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; // Full search + } }; // ================================================================================================= diff --git a/src/tuning/kernels/xaxpy.cpp b/src/tuning/kernels/xaxpy.cpp index a13e54f2..a8a9457d 100644 --- a/src/tuning/kernels/xaxpy.cpp +++ b/src/tuning/kernels/xaxpy.cpp @@ -53,7 +53,14 @@ class TuneXaxpy { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // Full search + static double DefaultMaxTempAnn(){ return 1.0;} // N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &args) { return args.n; } static size_t GetSizeY(const Arguments &args) { return args.n; } @@ -102,6 +109,11 @@ class TuneXaxpy { return 3 * args.n * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; // Full search + } }; // ================================================================================================= diff --git a/src/tuning/kernels/xdot.cpp b/src/tuning/kernels/xdot.cpp index b85c8521..f70fafb3 100644 --- a/src/tuning/kernels/xdot.cpp +++ b/src/tuning/kernels/xdot.cpp @@ -49,7 +49,14 @@ class TuneXdot { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // Full search + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &args) { return args.n; } static size_t GetSizeY(const Arguments &args) { return args.n; } @@ -108,6 +115,11 @@ class TuneXdot { return (V==1) ? (2*args.n + 1) * GetBytes(args.precision) : 1 * GetBytes(args.precision); } static std::string PerformanceUnit() { return (V==1) ? "GB/s" : "N/A"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; + } }; // ================================================================================================= diff --git a/src/tuning/kernels/xgemm.cpp b/src/tuning/kernels/xgemm.cpp index 6ab64af4..e2032256 100644 --- a/src/tuning/kernels/xgemm.cpp +++ b/src/tuning/kernels/xgemm.cpp @@ -18,9 +18,7 @@ #include "utilities/utilities.hpp" #include "tuning/tuning.hpp" -#define XGEMM_EXEC -bool tStrategyFlag=true; -#define DEFAULT_NUM_OF_STRATEGY 1 + namespace clblast { // ================================================================================================= @@ -45,7 +43,9 @@ class TuneXgemm { // The list of arguments relevant for this routine static std::vector GetOptions() { - return {kArgM, kArgN, kArgK, kArgAlpha, kArgBeta, kArgFraction,tStrategy, psoSwarmSize, psoInfG, psoInfL, psoInfR}; + return {kArgM, kArgN, kArgK, kArgAlpha, kArgBeta, kArgFraction, + kArgHeuristicSelection, kArgMultiSearchStrategy, kArgPsoSwarmSize, + kArgPsoInfGlobal, kArgPsoInfLocal, kArgPsoInfRandom}; } // Tests for valid arguments @@ -58,7 +58,14 @@ class TuneXgemm { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return (V==1) ? 1.0 : 512.0; } // test all or sample randomly static size_t DefaultNumRuns() { return 2; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 2; } // Full search and Random/PSO + 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 size_t{3};} // PSO + static double DefaultMaxTempAnn(){ return 1.0;} + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &) { return 1; } // N/A for this kernel static size_t GetSizeY(const Arguments &) { return 1; } // N/A for this kernel @@ -173,6 +180,29 @@ class TuneXgemm { return 2 * args.m * args.n * args.k; } static std::string PerformanceUnit() { return "GFLOPS"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + + // Multi Search Strategy is enable + if( args.multi_search_strategy){ + if( V == 1){ + return size_t{0}; + } + else{ + return args.heuristic_selection; + } + } + + // Use full-search to explore all parameter combinations or random-search 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 size_t{0}; // Full search + } + else { + return args.heuristic_selection; + } + } }; // ================================================================================================= @@ -196,49 +226,39 @@ void StartVariation(int argc, char *argv[]) { } } +// Test multiple heuristics if kArgMultiSearchStrategy is enabled +// Otherwise, run the heuristic specified in kArgMultiSearchStrategy +void TestHeuristic(int argc, char *argv[]){ -// Main function (not within the clblast namespace) -int main(int argc, char *argv[]) { - -int num_of_strategies = DEFAULT_NUM_OF_STRATEGY; - -if(const char* env_p = std::getenv("CK_TUNER_NUM_OF_STRATEGIES")) -{ - num_of_strategies = atoi(env_p); - printf("CK_TUNER_NUM_OF_STRATEGIES is: %s\n", env_p ); -} -else -{ - printf("CK_TUNER_NUM_OF_STRATEGIES is not defined\n"); -} - -printf("num_of_strategies : %d\n",num_of_strategies ); + auto command_line_args = clblast::RetrieveCommandLineArguments(argc, argv); + auto help = std::string{""}; + auto heuristic_selected = clblast::GetArgument(command_line_args, help, clblast::kArgMultiSearchStrategy, 0); + auto multi_search_strategy = clblast::GetArgument(command_line_args, help, clblast::kArgMultiSearchStrategy, 0); -if( DEFAULT_NUM_OF_STRATEGY != num_of_strategies ) -{ - //FACCIO PRIMA LA FULL SEARCH - StartVariation<1>(argc, argv); + if(multi_search_strategy){ + StartVariation<1>(argc, argv); + StartVariation<2>(argc, argv); + } + else + { + switch(heuristic_selected){ + case 1: + case 2: + case 3: + StartVariation<2>(argc, argv); + break; + case 0: + default: + StartVariation<1>(argc, argv); + break; + } + } } - auto command_line_args = clblast::RetrieveCommandLineArguments(argc, argv); - auto help = std::string{"* Options given/available:\n"}; - auto localtStrategy = clblast::GetArgument(command_line_args, help, clblast::tStrategy, DEFAULT_STRATEGY); - switch(localtStrategy) - { - case FULL_SEARCH_STRATEGY: - StartVariation<1>(argc, argv); - break; - case RANDOM_SEARCH_STRATEGY: - StartVariation<2>(argc, argv); - break; - case PSO_STRATEGY: - StartVariation<3>(argc, argv); - break; - case DVDT_STRATEGY: - StartVariation<2>(argc, argv); - break; - } +// Main function (not within the clblast namespace) +int main(int argc, char *argv[]) { + TestHeuristic(argc, argv); return 0; } diff --git a/src/tuning/kernels/xgemm_direct.cpp b/src/tuning/kernels/xgemm_direct.cpp index e7a35b93..3fb4ff34 100644 --- a/src/tuning/kernels/xgemm_direct.cpp +++ b/src/tuning/kernels/xgemm_direct.cpp @@ -41,7 +41,9 @@ class TuneXgemmDirect { // The list of arguments relevant for this routine static std::vector GetOptions() { - return {kArgM, kArgN, kArgK, kArgAlpha, kArgBeta, kArgFraction}; + return {kArgM, kArgN, kArgK, kArgAlpha, kArgBeta, kArgFraction, + kArgHeuristicSelection, kArgMultiSearchStrategy, kArgPsoSwarmSize, + kArgPsoInfGlobal, kArgPsoInfLocal, kArgPsoInfRandom}; } // Tests for valid arguments @@ -54,7 +56,14 @@ class TuneXgemmDirect { 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 DefaultNumSearchStragegy() { return 2; } // Full search and Random/PSO + 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 size_t{3};} // PSO + static double DefaultMaxTempAnn(){ return 1.0;} + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &) { return 1; } // N/A for this kernel static size_t GetSizeY(const Arguments &) { return 1; } // N/A for this kernel @@ -166,6 +175,29 @@ class TuneXgemmDirect { return 2 * args.m * args.n * args.k; } static std::string PerformanceUnit() { return "GFLOPS"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + + // Multi Search Strategy is enable + if( args.multi_search_strategy){ + if( V == 1){ + return size_t{0}; + } + else{ + return args.heuristic_selection; + } + } + + // Use full-search to explore all parameter combinations or random-search 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 size_t{0}; // Full search + } + else { + return args.heuristic_selection; + } + } }; // ================================================================================================= @@ -188,6 +220,34 @@ void StartVariation(int argc, char *argv[]) { case clblast::Precision::kComplexDouble: clblast::Tuner, double2>(argc, argv); break; } } +// Test multiple heuristics if kArgMultiSearchStrategy is enabled +// Otherwise, run the heuristic specified in kArgMultiSearchStrategy +void TestHeuristic(int argc, char *argv[]){ + + auto command_line_args = clblast::RetrieveCommandLineArguments(argc, argv); + auto help = std::string{""}; + auto heuristic_selected = clblast::GetArgument(command_line_args, help, clblast::kArgMultiSearchStrategy, 0); + auto multi_search_strategy = clblast::GetArgument(command_line_args, help, clblast::kArgMultiSearchStrategy, 0); + + if(multi_search_strategy){ + StartVariation<1>(argc, argv); + StartVariation<2>(argc, argv); + } + else + { + switch(heuristic_selected){ + case 1: + case 2: + case 3: + StartVariation<2>(argc, argv); + break; + case 0: + default: + StartVariation<1>(argc, argv); + break; + } + } +} // Main function (not within the clblast namespace) int main(int argc, char *argv[]) { diff --git a/src/tuning/kernels/xgemv.cpp b/src/tuning/kernels/xgemv.cpp index 9e9a6fe1..7d23eeec 100644 --- a/src/tuning/kernels/xgemv.cpp +++ b/src/tuning/kernels/xgemv.cpp @@ -52,7 +52,14 @@ class TuneXgemv { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; }// N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};} // Full search + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &args) { return args.n; } static size_t GetSizeY(const Arguments &args) { return args.m; } @@ -148,6 +155,11 @@ class TuneXgemv { return (args.m*args.n + 2*args.m + args.n) * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; //Full search + } }; // ================================================================================================= diff --git a/src/tuning/kernels/xger.cpp b/src/tuning/kernels/xger.cpp index c82a29b6..09c5ba3f 100644 --- a/src/tuning/kernels/xger.cpp +++ b/src/tuning/kernels/xger.cpp @@ -49,7 +49,14 @@ class TuneXger { static size_t DefaultBatchCount() { return 1; } // N/A for this kernel static double DefaultFraction() { return 1.0; } // N/A for this kernel static size_t DefaultNumRuns() { return 10; } // run every kernel this many times for averaging - + static size_t DefaultNumSearchStragegy() { return 1; } // N/A for this kernel + static size_t DefaultSwarmSizePSO() { return 8; } // N/A for this kernel + static double DefaultInfluenceGlobalPSO(){ return 0.1; }// N/A for this kernel + static double DefaultInfluenceLocalPSO(){ return 0.3; } // N/A for this kernel + static double DefaultInfluenceRandomPSO(){ return 0.6; }// N/A for this kernel + static size_t DefaultHeuristic(){ return size_t{0};}// Full search + static double DefaultMaxTempAnn(){ return 1.0;}// N/A for this kernel + // Describes how to obtain the sizes of the buffers static size_t GetSizeX(const Arguments &args) { return args.m; } static size_t GetSizeY(const Arguments &args) { return args.n; } @@ -107,6 +114,11 @@ class TuneXger { return (2*args.m*args.n + args.m + args.n) * GetBytes(args.precision); } static std::string PerformanceUnit() { return "GB/s"; } + + // Returns which Heuristic to run + static size_t GetCurrentHeuristic(const Arguments &args){ + return size_t{0}; // Full search + } }; // ================================================================================================= -- cgit v1.2.3