mirror of
https://github.com/CNugteren/CLBlast.git
synced 2024-07-04 21:36:57 +02:00
Routine: cache the database instance as well
This does not change much, but will become useful in next commits when plugin support is introduced.
This commit is contained in:
parent
6dc18c1c57
commit
50e758a007
|
@ -15,6 +15,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "database/database.hpp"
|
||||||
#include "cache.hpp"
|
#include "cache.hpp"
|
||||||
|
|
||||||
namespace clblast {
|
namespace clblast {
|
||||||
|
@ -88,5 +89,10 @@ template std::string BinaryCache::Get(const BinaryKeyRef &, bool *) const;
|
||||||
template class Cache<ProgramKey, Program>;
|
template class Cache<ProgramKey, Program>;
|
||||||
template Program ProgramCache::Get(const ProgramKeyRef &, bool *) const;
|
template Program ProgramCache::Get(const ProgramKeyRef &, bool *) const;
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
template class Cache<DatabaseKey, Database>;
|
||||||
|
template Database DatabaseCache::Get(const DatabaseKeyRef &, bool *) const;
|
||||||
|
|
||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
} // namespace clblast
|
} // namespace clblast
|
||||||
|
|
|
@ -85,6 +85,20 @@ typedef Cache<ProgramKey, Program> ProgramCache;
|
||||||
extern template class Cache<ProgramKey, Program>;
|
extern template class Cache<ProgramKey, Program>;
|
||||||
extern template Program ProgramCache::Get(const ProgramKeyRef &, bool *) const;
|
extern template Program ProgramCache::Get(const ProgramKeyRef &, bool *) const;
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
class Database;
|
||||||
|
|
||||||
|
// The key struct for the cache of database maps.
|
||||||
|
// Order of fields: precision, device_name, routines (smaller fields first)
|
||||||
|
typedef std::tuple<Precision, std::string, std::vector<std::string>> DatabaseKey;
|
||||||
|
typedef std::tuple<const Precision &, const std::string &, const std::vector<std::string> &> DatabaseKeyRef;
|
||||||
|
|
||||||
|
typedef Cache<DatabaseKey, Database> DatabaseCache;
|
||||||
|
|
||||||
|
extern template class Cache<DatabaseKey, Database>;
|
||||||
|
extern template Database DatabaseCache::Get(const DatabaseKeyRef &, bool *) const;
|
||||||
|
|
||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
} // namespace clblast
|
} // namespace clblast
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,28 @@ Routine::Routine(Queue &queue, EventPointer event, const std::string &name,
|
||||||
event_(event),
|
event_(event),
|
||||||
context_(queue_.GetContext()),
|
context_(queue_.GetContext()),
|
||||||
device_(queue_.GetDevice()),
|
device_(queue_.GetDevice()),
|
||||||
device_name_(device_.Name()),
|
device_name_(device_.Name()) {
|
||||||
db_(queue_, routines, precision_, userDatabase) {
|
|
||||||
|
InitDatabase(routines, userDatabase);
|
||||||
|
InitProgram(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Routine::InitDatabase(const std::vector<std::string> &routines,
|
||||||
|
const std::vector<const Database::DatabaseEntry*> &userDatabase) {
|
||||||
|
|
||||||
|
// Queries the cache to see whether or not the kernel parameter database is already there
|
||||||
|
bool has_db;
|
||||||
|
db_ = DatabaseCache::Instance().Get(DatabaseKeyRef{ precision_, device_name_, routines },
|
||||||
|
&has_db);
|
||||||
|
if (has_db) { return; }
|
||||||
|
|
||||||
|
// Builds the parameter database for this device and routine set and stores it in the cache
|
||||||
|
db_ = Database(queue_, routines, precision_, userDatabase);
|
||||||
|
DatabaseCache::Instance().Store(DatabaseKey{ precision_, device_name_, routines },
|
||||||
|
Database{ db_ });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Routine::InitProgram(std::initializer_list<const char *> source) {
|
||||||
|
|
||||||
// Queries the cache to see whether or not the program (context-specific) is already there
|
// Queries the cache to see whether or not the program (context-specific) is already there
|
||||||
bool has_program;
|
bool has_program;
|
||||||
|
|
|
@ -35,11 +35,22 @@ class Routine {
|
||||||
// Base class constructor. The user database is an optional extra database to override the
|
// Base class constructor. The user database is an optional extra database to override the
|
||||||
// built-in database.
|
// built-in database.
|
||||||
// All heavy preparation work is done inside this constructor.
|
// All heavy preparation work is done inside this constructor.
|
||||||
|
// NOTE: the caller must provide the same userDatabase for each combination of device, precision
|
||||||
|
// and routine list, otherwise the caching logic will break.
|
||||||
explicit Routine(Queue &queue, EventPointer event, const std::string &name,
|
explicit Routine(Queue &queue, EventPointer event, const std::string &name,
|
||||||
const std::vector<std::string> &routines, const Precision precision,
|
const std::vector<std::string> &routines, const Precision precision,
|
||||||
const std::vector<const Database::DatabaseEntry*> &userDatabase,
|
const std::vector<const Database::DatabaseEntry*> &userDatabase,
|
||||||
std::initializer_list<const char *> source);
|
std::initializer_list<const char *> source);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// Initializes program_, fetching cached program or building one
|
||||||
|
void InitProgram(std::initializer_list<const char *> source);
|
||||||
|
|
||||||
|
// Initializes db_, fetching cached database or building one
|
||||||
|
void InitDatabase(const std::vector<std::string> &routines,
|
||||||
|
const std::vector<const Database::DatabaseEntry*> &userDatabase);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Non-static variable for the precision
|
// Non-static variable for the precision
|
||||||
|
@ -61,7 +72,7 @@ class Routine {
|
||||||
Program program_;
|
Program program_;
|
||||||
|
|
||||||
// Connection to the database for all the device-specific parameters
|
// Connection to the database for all the device-specific parameters
|
||||||
const Database db_;
|
Database db_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
|
|
Loading…
Reference in a new issue