diff options
author | Ivan Shapovalov <intelfx@intelfx.name> | 2016-07-12 13:33:25 +0300 |
---|---|---|
committer | Ivan Shapovalov <intelfx@intelfx.name> | 2016-07-22 11:15:52 +0300 |
commit | e4e1f05079273f60f4f15280b3f103810c7eb31f (patch) | |
tree | f9c10e42be8d0e8fd48db1b9feb59e01b89ab272 /src/database | |
parent | ae3299da302ba2c26f1e3490a1a7ee389d91feee (diff) |
clblast::Database, clblast::Routine: implement "database overlays" provided by routine implementation
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/database.cpp | 45 | ||||
-rw-r--r-- | src/database/database.hpp | 10 |
2 files changed, 34 insertions, 21 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp index 6ec93731..ea1557b9 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -44,7 +44,7 @@ const std::vector<Database::DatabaseEntry> Database::database = { // Constructor, computing device properties and populating the parameter-vector from the database Database::Database(const Queue &queue, const std::vector<std::string> &kernels, - const Precision precision): + const Precision precision, const std::vector<DatabaseEntry> &overlay): parameters_{} { // Finds information of the current device @@ -53,10 +53,23 @@ Database::Database(const Queue &queue, const std::vector<std::string> &kernels, auto device_vendor = device.Vendor(); auto device_name = device.Name(); + // Set the short vendor name + for (auto &combination : kVendorNames) { + if (device_vendor == combination.first) { + device_vendor = combination.second; + } + } + // Iterates over all kernels to include, and retrieves the parameters for each of them for (auto &kernel: kernels) { - auto search_result = Search(kernel, device_type, device_vendor, device_name, precision); - parameters_.insert(search_result.begin(), search_result.end()); + auto search_result = ParametersPtr{}; + + for (auto db: { &overlay, &database }) { + search_result = Search(kernel, device_type, device_vendor, device_name, precision, *db); + if (search_result) { parameters_.insert(search_result->begin(), search_result->end()); break; } + } + + if (!search_result) { throw std::runtime_error("Database error, could not find a suitable entry"); } } } @@ -74,27 +87,21 @@ std::string Database::GetDefines() const { // ================================================================================================= // Searches the database for the right kernel and precision -Database::Parameters Database::Search(const std::string &this_kernel, - const std::string &this_type, - const std::string &this_vendor, - const std::string &this_device, - const Precision this_precision) const { - // Set the short vendor name - auto this_short_vendor = this_vendor; - for (auto &combination : kVendorNames) { - if (this_vendor == combination.first) { - this_short_vendor = combination.second; - } - } +Database::ParametersPtr Database::Search(const std::string &this_kernel, + const std::string &this_type, + const std::string &this_vendor, + const std::string &this_device, + const Precision this_precision, + const std::vector<DatabaseEntry> &this_database) const { // Selects the right kernel - for (auto &db: database) { + for (auto &db: this_database) { if (db.kernel == this_kernel && db.precision == this_precision) { // Searches for the right vendor and device type, or selects the default if unavailable. This // assumes that the default vendor / device type is last in the database. for (auto &vendor: db.vendors) { - if ((vendor.name == this_short_vendor || vendor.name == kDeviceVendorAll) && + if ((vendor.name == this_vendor || vendor.name == kDeviceVendorAll) && (vendor.type == this_type || vendor.type == kDeviceTypeAll)) { // Searches for the right device. If the current device is unavailable, selects the vendor @@ -104,7 +111,7 @@ Database::Parameters Database::Search(const std::string &this_kernel, if (device.name == this_device || device.name == "default") { // Sets the parameters accordingly - return device.parameters; + return &device.parameters; } } } @@ -113,7 +120,7 @@ Database::Parameters Database::Search(const std::string &this_kernel, } // If we reached this point, something is wrong - throw std::runtime_error("Database error, could not find a suitable entry"); + return nullptr; } // ================================================================================================= diff --git a/src/database/database.hpp b/src/database/database.hpp index 0987cbed..5a61fad9 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -32,6 +32,7 @@ class Database { // Type alias for the database parameters using Parameters = std::unordered_map<std::string,size_t>; + using ParametersPtr = const Parameters*; // Structures for content inside the database struct DatabaseDevice { @@ -78,9 +79,9 @@ class Database { static const DatabaseEntry PadtransposeHalf, PadtransposeSingle, PadtransposeDouble, PadtransposeComplexSingle, PadtransposeComplexDouble; static const std::vector<DatabaseEntry> database; - // The constructor + // The constructor with a user-provided database overlay explicit Database(const Queue &queue, const std::vector<std::string> &routines, - const Precision precision); + const Precision precision, const std::vector<DatabaseEntry> &overlay); // Accessor of values by key size_t operator[](const std::string key) const { return parameters_.find(key)->second; } @@ -93,6 +94,11 @@ class Database { const std::string &this_vendor, const std::string &this_device, const Precision this_precision) const; + // Alternate search method in a specified database, returning pointer (possibly NULL) + ParametersPtr Search(const std::string &this_kernel, const std::string &this_type, + const std::string &this_vendor, const std::string &this_device, + const Precision this_precision, const std::vector<DatabaseEntry> &db) const; + // Found parameters suitable for this device/kernel Parameters parameters_; }; |