From cdb3bb7166bc75842ff95e14915bff881297fc62 Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Mon, 13 Feb 2017 20:53:06 +0100 Subject: Added first version of the OverrideParameters function --- include/clblast.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/clblast.h') diff --git a/include/clblast.h b/include/clblast.h index 7b2021d8..e7b53d65 100644 --- a/include/clblast.h +++ b/include/clblast.h @@ -17,6 +17,8 @@ #define CLBLAST_CLBLAST_H_ #include // For size_t +#include // For OverrideParameters function +#include // For OverrideParameters function // Includes the normal OpenCL C header #if defined(__APPLE__) || defined(__MACOSX) @@ -617,6 +619,12 @@ StatusCode PUBLIC_API FillCache(const cl_device_id device); // ================================================================================================= +StatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const std::string &kernel_name, + const Precision precision, + const std::unordered_map ¶meters); + +// ================================================================================================= + } // namespace clblast // CLBLAST_CLBLAST_H_ -- cgit v1.2.3 From 08bfb75a9d72b6b373d8f18e8be83fe4ea31015b Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Thu, 16 Feb 2017 21:12:50 +0100 Subject: Added input-sanity checks for the OverrideParameters function --- include/clblast.h | 2 ++ scripts/generator/generator.py | 4 ++-- src/clblast.cpp | 10 ++++++++++ src/database/database.cpp | 9 +++++++++ src/database/database.hpp | 3 +++ 5 files changed, 26 insertions(+), 2 deletions(-) (limited to 'include/clblast.h') diff --git a/include/clblast.h b/include/clblast.h index e7b53d65..1350cb10 100644 --- a/include/clblast.h +++ b/include/clblast.h @@ -97,6 +97,8 @@ enum class StatusCode { kInsufficientMemoryY = -1007, // Vector Y's OpenCL buffer is too small // Custom additional status codes for CLBlast + kInvalidOverrideKernel = -2048, // Trying to override parameters for an invalid kernel + kMissingOverrideParameter = -2047, // Missing override parameter(s) for the target kernel kInvalidLocalMemUsage = -2046, // Not enough local memory available on this device kNoHalfPrecision = -2045, // Half precision (16-bits) not supported by the device kNoDoublePrecision = -2044, // Double precision (64-bits) not supported by the device diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py index aaf1b121..f43464b9 100755 --- a/scripts/generator/generator.py +++ b/scripts/generator/generator.py @@ -41,8 +41,8 @@ FILES = [ "/include/clblast_netlib_c.h", "/src/clblast_netlib_c.cpp", ] -HEADER_LINES = [119, 73, 118, 22, 29, 41, 65, 32] -FOOTER_LINES = [23, 128, 19, 18, 6, 6, 9, 2] +HEADER_LINES = [121, 73, 118, 22, 29, 41, 65, 32] +FOOTER_LINES = [23, 138, 19, 18, 6, 6, 9, 2] # Different possibilities for requirements ald_m = "The value of `a_ld` must be at least `m`." diff --git a/src/clblast.cpp b/src/clblast.cpp index 885b849e..871a4804 100644 --- a/src/clblast.cpp +++ b/src/clblast.cpp @@ -2264,6 +2264,16 @@ StatusCode OverrideParameters(const cl_device_id device, const std::string &kern const auto device_cpp = Device(device); const auto device_name = device_cpp.Name(); + // Retrieves the current database values to verify whether the new ones are complete + auto in_cache = false; + const auto current_database = DatabaseCache::Instance().Get(DatabaseKeyRef{ precision, device_name, kernel_name }, &in_cache); + if (!in_cache) { return StatusCode::kInvalidOverrideKernel; } + for (const auto ¤t_param : current_database.GetParameterNames()) { + if (parameters.find(current_param) == parameters.end()) { + return StatusCode::kMissingOverrideParameter; + } + } + // Clears the existing program & binary cache for routines with the target kernel const auto routine_names = Routine::routines_by_kernel.at(kernel_name); for (const auto &routine_name : routine_names) { diff --git a/src/database/database.cpp b/src/database/database.cpp index 8019d558..02d0b139 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -103,6 +103,15 @@ std::string Database::GetDefines() const { return defines; } +// Retrieves the names of all the parameters +std::vector Database::GetParameterNames() const { + auto parameter_names = std::vector(); + for (auto ¶meter: *parameters_) { + parameter_names.push_back(parameter.first); + } + return parameter_names; +} + // ================================================================================================= // Searches a particular database for the right kernel and precision diff --git a/src/database/database.hpp b/src/database/database.hpp index b6760ec3..b34e0d8a 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -85,6 +85,9 @@ class Database { // Obtain a list of OpenCL pre-processor defines based on the parameters std::string GetDefines() const; + // Retrieves the names of all the parameters + std::vector GetParameterNames() const; + private: // Search method for a specified database, returning pointer (possibly a nullptr) ParametersPtr Search(const std::string &this_kernel, const std::string &this_type, -- cgit v1.2.3 From cda449a5c39041b2a0e6893ee254e145447b78ca Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Thu, 16 Feb 2017 21:14:48 +0100 Subject: Added a C interface to the OverrideParameters function; added some in-line comments to the API --- include/clblast.h | 3 +++ include/clblast_c.h | 16 ++++++++++++++++ scripts/generator/generator.py | 4 ++-- src/clblast.cpp | 1 + src/clblast_c.cpp | 21 +++++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) (limited to 'include/clblast.h') diff --git a/include/clblast.h b/include/clblast.h index 1350cb10..d9637d15 100644 --- a/include/clblast.h +++ b/include/clblast.h @@ -621,6 +621,9 @@ StatusCode PUBLIC_API FillCache(const cl_device_id device); // ================================================================================================= +// Overrides tuning parameters for a specific device-precision-routine combination. The next time +// (and all further times) the target routine is called it will re-compile and use the new +// parameters. StatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const std::string &kernel_name, const Precision precision, const std::unordered_map ¶meters); diff --git a/include/clblast_c.h b/include/clblast_c.h index 72f50d83..cd657f3b 100644 --- a/include/clblast_c.h +++ b/include/clblast_c.h @@ -96,6 +96,8 @@ typedef enum CLBlastStatusCode_ { CLBlastInsufficientMemoryY = -1007, // Vector Y's OpenCL buffer is too small // Custom additional status codes for CLBlast + CLBlastInvalidOverrideKernel = -2048, // Trying to override parameters for an invalid kernel + CLBlastMissingOverrideParameter = -2047, // Missing override parameter(s) for the target kernel CLBlastInvalidLocalMemUsage = -2046, // Not enough local memory available on this device CLBlastNoHalfPrecision = -2045, // Half precision (16-bits) not supported by the device CLBlastNoDoublePrecision = -2044, // Double precision (64-bits) not supported by the device @@ -117,6 +119,11 @@ typedef enum CLBlastDiagonal_ { CLBlastDiagonalNonUnit = 131, CLBlastDiagonalUnit = 132 } CLBlastDiagonal; typedef enum CLBlastSide_ { CLBlastSideLeft = 141, CLBlastSideRight = 142 } CLBlastSide; +// Precision enum (values in bits) +typedef enum CLBlastPrecision_ { CLBlastPrecisionHalf = 16, CLBlastPrecisionSingle = 32, + CLBlastPrecisionDouble = 64, CLBlastPrecisionComplexSingle = 3232, + CLBlastPrecisionComplexDouble = 6464 } CLBlastPrecision; + // ================================================================================================= // BLAS level-1 (vector-vector) routines // ================================================================================================= @@ -1338,6 +1345,15 @@ CLBlastStatusCode PUBLIC_API CLBlastFillCache(const cl_device_id device); // ================================================================================================= +// Overrides tuning parameters for a specific device-precision-routine combination. The next time +// (and all further times) the target routine is called it will re-compile and use the new +// parameters. +CLBlastStatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const char* kernel_name, + const CLBlastPrecision precision, const size_t num_parameters, + const char** parameters_names, const size_t* parameters_values); + +// ================================================================================================= + #ifdef __cplusplus } // extern "C" #endif diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py index f43464b9..9bc48502 100755 --- a/scripts/generator/generator.py +++ b/scripts/generator/generator.py @@ -41,8 +41,8 @@ FILES = [ "/include/clblast_netlib_c.h", "/src/clblast_netlib_c.cpp", ] -HEADER_LINES = [121, 73, 118, 22, 29, 41, 65, 32] -FOOTER_LINES = [23, 138, 19, 18, 6, 6, 9, 2] +HEADER_LINES = [121, 73, 125, 23, 29, 41, 65, 32] +FOOTER_LINES = [26, 139, 28, 38, 6, 6, 9, 2] # Different possibilities for requirements ald_m = "The value of `a_ld` must be at least `m`." diff --git a/src/clblast.cpp b/src/clblast.cpp index 871a4804..a8e4d084 100644 --- a/src/clblast.cpp +++ b/src/clblast.cpp @@ -2255,6 +2255,7 @@ StatusCode FillCache(const cl_device_id device) { // ================================================================================================= +// Overrides the tuning parameters for this device-precision-kernel combination StatusCode OverrideParameters(const cl_device_id device, const std::string &kernel_name, const Precision precision, const std::unordered_map ¶meters) { diff --git a/src/clblast_c.cpp b/src/clblast_c.cpp index e4f2b3ed..79b6a640 100644 --- a/src/clblast_c.cpp +++ b/src/clblast_c.cpp @@ -12,6 +12,7 @@ // ================================================================================================= #include +#include #include "utilities/utilities.hpp" #include "clblast_c.h" @@ -3484,3 +3485,23 @@ CLBlastStatusCode CLBlastFillCache(const cl_device_id device) { } // ================================================================================================= + +// Overrides the tuning parameters for this device-precision-kernel combination +CLBlastStatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const char* kernel_name, + const CLBlastPrecision precision, const size_t num_parameters, + const char** parameters_names, const size_t* parameters_values) { + try { + const auto kernel_name_cpp = std::string(kernel_name); + const auto precision_cpp = static_cast(precision); + auto parameters = std::unordered_map(); + for (auto i = size_t{0}; i < num_parameters; ++i) { + const auto parameter_name = std::string(parameters_names[i]); + const auto parameter_value = parameters_values[i]; + parameters[parameter_name] = parameter_value; + } + const auto status = clblast::OverrideParameters(device, kernel_name_cpp, precision_cpp, parameters); + return static_cast(status); + } catch (...) { return static_cast(clblast::DispatchExceptionForC()); } +} + +// ================================================================================================= -- cgit v1.2.3 From d6538dfc25a14251e49da0f95007e03b2b3fe3be Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Sat, 18 Feb 2017 10:59:38 +0100 Subject: Fixed the naming of the C API of OverrideParameters and fixed the description --- include/clblast.h | 5 ++--- include/clblast_c.h | 11 +++++------ src/clblast_c.cpp | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) (limited to 'include/clblast.h') diff --git a/include/clblast.h b/include/clblast.h index d9637d15..9fdd5df1 100644 --- a/include/clblast.h +++ b/include/clblast.h @@ -621,9 +621,8 @@ StatusCode PUBLIC_API FillCache(const cl_device_id device); // ================================================================================================= -// Overrides tuning parameters for a specific device-precision-routine combination. The next time -// (and all further times) the target routine is called it will re-compile and use the new -// parameters. +// Overrides tuning parameters for a specific device-precision-kernel combination. The next time +// the target routine is called it will re-compile and use the new parameters from then on. StatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const std::string &kernel_name, const Precision precision, const std::unordered_map ¶meters); diff --git a/include/clblast_c.h b/include/clblast_c.h index cd657f3b..d4b0b004 100644 --- a/include/clblast_c.h +++ b/include/clblast_c.h @@ -1345,12 +1345,11 @@ CLBlastStatusCode PUBLIC_API CLBlastFillCache(const cl_device_id device); // ================================================================================================= -// Overrides tuning parameters for a specific device-precision-routine combination. The next time -// (and all further times) the target routine is called it will re-compile and use the new -// parameters. -CLBlastStatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const char* kernel_name, - const CLBlastPrecision precision, const size_t num_parameters, - const char** parameters_names, const size_t* parameters_values); +// Overrides tuning parameters for a specific device-precision-kernel combination. The next time +// the target routine is called it will re-compile and use the new parameters from then on. +CLBlastStatusCode PUBLIC_API CLBlastOverrideParameters(const cl_device_id device, const char* kernel_name, + const CLBlastPrecision precision, const size_t num_parameters, + const char** parameters_names, const size_t* parameters_values); // ================================================================================================= diff --git a/src/clblast_c.cpp b/src/clblast_c.cpp index 79b6a640..de431fa4 100644 --- a/src/clblast_c.cpp +++ b/src/clblast_c.cpp @@ -3487,9 +3487,9 @@ CLBlastStatusCode CLBlastFillCache(const cl_device_id device) { // ================================================================================================= // Overrides the tuning parameters for this device-precision-kernel combination -CLBlastStatusCode PUBLIC_API OverrideParameters(const cl_device_id device, const char* kernel_name, - const CLBlastPrecision precision, const size_t num_parameters, - const char** parameters_names, const size_t* parameters_values) { +CLBlastStatusCode PUBLIC_API CLBlastOverrideParameters(const cl_device_id device, const char* kernel_name, + const CLBlastPrecision precision, const size_t num_parameters, + const char** parameters_names, const size_t* parameters_values) { try { const auto kernel_name_cpp = std::string(kernel_name); const auto precision_cpp = static_cast(precision); -- cgit v1.2.3