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>
|
2016-03-14 22:55:22 +01:00
|
|
|
#include <mutex>
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
#include "internal/utilities.h"
|
|
|
|
#include "internal/database.h"
|
|
|
|
|
|
|
|
namespace clblast {
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
// See comment at top of file for a description of the class
|
2015-07-27 07:18:06 +02:00
|
|
|
template <typename T>
|
2015-05-30 12:30:43 +02:00
|
|
|
class Routine {
|
|
|
|
public:
|
|
|
|
|
2015-06-18 18:44:14 +02:00
|
|
|
// The cache of compiled OpenCL programs, along with some meta-data
|
2015-05-30 12:30:43 +02:00
|
|
|
struct ProgramCache {
|
|
|
|
Program program;
|
|
|
|
std::string device_name;
|
|
|
|
Precision precision;
|
2015-07-19 16:24:14 +02:00
|
|
|
std::string routine_name_;
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// Finds out whether the properties match
|
2015-07-19 16:24:14 +02:00
|
|
|
bool MatchInCache(const std::string &ref_device, const Precision &ref_precision,
|
|
|
|
const std::string &ref_routine) {
|
|
|
|
return (device_name == ref_device &&
|
|
|
|
precision == ref_precision &&
|
|
|
|
routine_name_ == ref_routine);
|
2015-05-30 12:30:43 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-14 22:55:22 +01:00
|
|
|
// The actual cache, implemented as a vector of the above data-type, and its mutex
|
2015-05-30 12:30:43 +02:00
|
|
|
static std::vector<ProgramCache> program_cache_;
|
2016-03-14 22:55:22 +01:00
|
|
|
static std::mutex program_cache_mutex_;
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// Helper functions which check for errors in the status code
|
|
|
|
static constexpr bool ErrorIn(const StatusCode s) { return (s != StatusCode::kSuccess); }
|
|
|
|
|
|
|
|
// Base class constructor
|
2015-07-27 07:18:06 +02:00
|
|
|
explicit Routine(Queue &queue, Event &event, const std::string &name,
|
2015-05-30 12:30:43 +02:00
|
|
|
const std::vector<std::string> &routines, const Precision precision);
|
|
|
|
|
|
|
|
// Set-up phase of the kernel
|
2015-07-19 13:44:37 +02:00
|
|
|
StatusCode SetUp();
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// Runs a kernel given the global and local thread sizes
|
2015-07-27 07:18:06 +02:00
|
|
|
StatusCode RunKernel(Kernel &kernel, std::vector<size_t> &global,
|
2015-05-30 12:30:43 +02:00
|
|
|
const std::vector<size_t> &local);
|
|
|
|
|
|
|
|
// Tests for valid inputs of matrices A, B, and C
|
2015-07-27 07:18:06 +02:00
|
|
|
StatusCode TestMatrixA(const size_t one, const size_t two, const Buffer<T> &buffer,
|
2015-05-30 12:30:43 +02:00
|
|
|
const size_t offset, const size_t ld, const size_t data_size);
|
2015-07-27 07:18:06 +02:00
|
|
|
StatusCode TestMatrixB(const size_t one, const size_t two, const Buffer<T> &buffer,
|
2015-05-30 12:30:43 +02:00
|
|
|
const size_t offset, const size_t ld, const size_t data_size);
|
2015-07-27 07:18:06 +02:00
|
|
|
StatusCode TestMatrixC(const size_t one, const size_t two, const Buffer<T> &buffer,
|
2015-05-30 12:30:43 +02:00
|
|
|
const size_t offset, const size_t ld, const size_t data_size);
|
2015-09-19 17:37:42 +02:00
|
|
|
StatusCode TestMatrixAP(const size_t n, const Buffer<T> &buffer,
|
|
|
|
const size_t offset, const size_t data_size);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// Tests for valid inputs of vectors X and Y
|
2015-07-27 07:18:06 +02:00
|
|
|
StatusCode TestVectorX(const size_t n, const Buffer<T> &buffer, const size_t offset,
|
2015-05-30 12:30:43 +02:00
|
|
|
const size_t inc, const size_t data_size);
|
2015-07-27 07:18:06 +02:00
|
|
|
StatusCode TestVectorY(const size_t n, const Buffer<T> &buffer, const size_t offset,
|
2015-05-30 12:30:43 +02:00
|
|
|
const size_t inc, const size_t data_size);
|
2015-09-14 12:28:50 +02:00
|
|
|
StatusCode TestVectorDot(const size_t n, const Buffer<T> &buffer, const size_t offset,
|
|
|
|
const size_t data_size);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
2015-07-13 08:41:26 +02:00
|
|
|
// Copies/transposes a matrix and padds/unpads it with zeroes. This method is also able to write
|
|
|
|
// to symmetric and triangular matrices through optional arguments.
|
2015-05-30 12:30:43 +02:00
|
|
|
StatusCode PadCopyTransposeMatrix(const size_t src_one, const size_t src_two,
|
|
|
|
const size_t src_ld, const size_t src_offset,
|
2015-07-27 07:18:06 +02:00
|
|
|
const Buffer<T> &src,
|
2015-05-30 12:30:43 +02:00
|
|
|
const size_t dest_one, const size_t dest_two,
|
|
|
|
const size_t dest_ld, const size_t dest_offset,
|
2015-07-27 07:18:06 +02:00
|
|
|
const Buffer<T> &dest,
|
2015-07-13 08:41:26 +02:00
|
|
|
const Program &program, const bool do_pad,
|
2015-06-16 07:43:19 +02:00
|
|
|
const bool do_transpose, const bool do_conjugate,
|
2015-07-13 08:41:26 +02:00
|
|
|
const bool upper = false, const bool lower = false,
|
|
|
|
const bool diagonal_imag_zero = false);
|
2015-05-30 12:30:43 +02:00
|
|
|
|
|
|
|
// Queries the cache and retrieve either a matching program or a boolean whether a match exists.
|
|
|
|
// The first assumes that the program is available in the cache and will throw an exception
|
|
|
|
// otherwise.
|
2015-06-18 18:44:14 +02:00
|
|
|
const Program& GetProgramFromCache() const;
|
2015-05-30 12:30:43 +02:00
|
|
|
bool ProgramIsInCache() const;
|
|
|
|
|
|
|
|
// Non-static variable for the precision. Note that the same variable (but static) might exist in
|
|
|
|
// a derived class.
|
|
|
|
const Precision precision_;
|
|
|
|
|
2015-07-19 13:44:37 +02:00
|
|
|
// The routine's name and its kernel-source in string form
|
|
|
|
const std::string routine_name_;
|
|
|
|
std::string source_string_;
|
|
|
|
|
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_;
|
2015-05-30 12:30:43 +02:00
|
|
|
Event event_;
|
|
|
|
const Context context_;
|
|
|
|
const Device device_;
|
|
|
|
|
|
|
|
// OpenCL device properties
|
|
|
|
const std::string device_name_;
|
2015-07-27 07:18:06 +02:00
|
|
|
const size_t max_work_item_dimensions_;
|
2015-05-30 12:30:43 +02:00
|
|
|
const std::vector<size_t> max_work_item_sizes_;
|
|
|
|
const size_t max_work_group_size_;
|
|
|
|
|
|
|
|
// Connection to the database for all the device-specific parameters
|
|
|
|
const Database db_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
} // namespace clblast
|
|
|
|
|
|
|
|
// CLBLAST_ROUTINE_H_
|
|
|
|
#endif
|