2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
|
|
|
|
// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
|
|
|
|
// width of 100 characters per line.
|
|
|
|
//
|
|
|
|
// Author(s):
|
|
|
|
// Cedric Nugteren <www.cedricnugteren.nl>
|
|
|
|
//
|
|
|
|
// This file implements all the basic functionality for the BLAS routines. This class serves as a
|
|
|
|
// base class for the actual routines (e.g. Xaxpy, Xgemm). It contains common functionality such as
|
|
|
|
// compiling the OpenCL kernel, connecting to the database, etc.
|
|
|
|
//
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
#ifndef CLBLAST_ROUTINE_H_
|
|
|
|
#define CLBLAST_ROUTINE_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2017-02-13 20:53:06 +01:00
|
|
|
#include <unordered_map>
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2016-10-22 15:36:48 +02:00
|
|
|
#include "utilities/utilities.hpp"
|
2016-06-18 20:20:13 +02:00
|
|
|
#include "cache.hpp"
|
2016-10-22 15:36:48 +02:00
|
|
|
#include "utilities/buffer_test.hpp"
|
2016-06-18 20:20:13 +02:00
|
|
|
#include "database/database.hpp"
|
|
|
|
#include "routines/common.hpp"
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
namespace clblast {
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
// See comment at top of file for a description of the class
|
|
|
|
class Routine {
|
|
|
|
public:
|
|
|
|
|
2018-05-01 20:34:48 +02:00
|
|
|
// Initializes db_, fetching cached database or building one
|
2017-12-28 14:46:45 +01:00
|
|
|
static void InitDatabase(const Device &device, const std::vector<std::string> &kernel_names,
|
|
|
|
const Precision precision, const std::vector<database::DatabaseEntry> &userDatabase,
|
|
|
|
Databases &db) {
|
|
|
|
const auto platform_id = device.PlatformID();
|
|
|
|
for (const auto &kernel_name : kernel_names) {
|
|
|
|
|
|
|
|
// Queries the cache to see whether or not the kernel parameter database is already there
|
|
|
|
bool has_db;
|
|
|
|
db(kernel_name) = DatabaseCache::Instance().Get(DatabaseKeyRef{platform_id, device(), precision, kernel_name},
|
|
|
|
&has_db);
|
|
|
|
if (has_db) { continue; }
|
|
|
|
|
|
|
|
// Builds the parameter database for this device and routine set and stores it in the cache
|
|
|
|
log_debug("Searching database for kernel '" + kernel_name + "'");
|
|
|
|
db(kernel_name) = Database(device, kernel_name, precision, userDatabase);
|
|
|
|
DatabaseCache::Instance().Store(DatabaseKey{platform_id, device(), precision, kernel_name},
|
|
|
|
Database{db(kernel_name)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 17:00:21 +02:00
|
|
|
// Base class constructor. The user database is an optional extra database to override the
|
|
|
|
// built-in database.
|
2016-10-18 03:53:06 +02:00
|
|
|
// All heavy preparation work is done inside this constructor.
|
2016-11-28 02:23:01 +01:00
|
|
|
// NOTE: the caller must provide the same userDatabase for each combination of device, precision
|
|
|
|
// and routine list, otherwise the caching logic will break.
|
2016-04-10 06:22:24 +02:00
|
|
|
explicit Routine(Queue &queue, EventPointer event, const std::string &name,
|
2016-07-12 12:33:25 +02:00
|
|
|
const std::vector<std::string> &routines, const Precision precision,
|
2017-09-06 21:50:42 +02:00
|
|
|
const std::vector<database::DatabaseEntry> &userDatabase,
|
2016-10-18 03:53:06 +02:00
|
|
|
std::initializer_list<const char *> source);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2017-02-13 20:53:06 +01:00
|
|
|
// List of kernel-routine look-ups
|
|
|
|
static const std::vector<std::string> routines_axpy;
|
|
|
|
static const std::vector<std::string> routines_dot;
|
|
|
|
static const std::vector<std::string> routines_ger;
|
|
|
|
static const std::vector<std::string> routines_gemv;
|
|
|
|
static const std::vector<std::string> routines_gemm;
|
|
|
|
static const std::vector<std::string> routines_gemm_syrk;
|
2017-02-26 14:51:45 +01:00
|
|
|
static const std::vector<std::string> routines_trsm;
|
2017-02-13 20:53:06 +01:00
|
|
|
static const std::unordered_map<std::string, const std::vector<std::string>> routines_by_kernel;
|
|
|
|
|
2016-11-28 02:23:01 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
// Initializes program_, fetching cached program or building one
|
|
|
|
void InitProgram(std::initializer_list<const char *> source);
|
|
|
|
|
2015-05-30 12:30:43 +02:00
|
|
|
protected:
|
2016-04-27 16:02:13 +02:00
|
|
|
|
2016-06-18 18:16:14 +02:00
|
|
|
// Non-static variable for the precision
|
2015-05-30 12:30:43 +02:00
|
|
|
const Precision precision_;
|
|
|
|
|
2017-02-12 12:02:39 +01:00
|
|
|
// The routine's name and the corresponding kernels
|
2015-07-19 13:44:37 +02:00
|
|
|
const std::string routine_name_;
|
2017-02-12 12:02:39 +01:00
|
|
|
const std::vector<std::string> kernel_names_;
|
2015-07-19 13:44:37 +02:00
|
|
|
|
2015-05-30 12:30:43 +02:00
|
|
|
// The OpenCL objects, accessible only from derived classes
|
2015-07-27 07:18:06 +02:00
|
|
|
Queue queue_;
|
2016-04-10 06:22:24 +02:00
|
|
|
EventPointer event_;
|
2015-05-30 12:30:43 +02:00
|
|
|
const Context context_;
|
|
|
|
const Device device_;
|
|
|
|
|
2016-11-26 18:53:42 +01:00
|
|
|
// Compiled program (either retrieved from cache or compiled in slow path)
|
2018-05-01 20:34:48 +02:00
|
|
|
std::shared_ptr<Program> program_;
|
2016-11-26 18:53:42 +01:00
|
|
|
|
2015-05-30 12:30:43 +02:00
|
|
|
// Connection to the database for all the device-specific parameters
|
2017-02-12 12:02:39 +01:00
|
|
|
Databases db_;
|
2015-05-30 12:30:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
} // namespace clblast
|
|
|
|
|
|
|
|
// CLBLAST_ROUTINE_H_
|
|
|
|
#endif
|