1 2 // ================================================================================================= 3 // This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This 4 // project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- 5 // width of 100 characters per line. 6 // 7 // Author(s): 8 // Cedric Nugteren <www.cedricnugteren.nl> 9 // 10 // This file implements all the basic functionality for the BLAS routines. This class serves as a 11 // base class for the actual routines (e.g. Xaxpy, Xgemm). It contains common functionality such as 12 // compiling the OpenCL kernel, connecting to the database, etc. 13 // 14 // ================================================================================================= 15 16 #ifndef CLBLAST_ROUTINE_H_ 17 #define CLBLAST_ROUTINE_H_ 18 19 #include <string> 20 #include <vector> 21 #include <unordered_map> 22 23 #include "utilities/utilities.hpp" 24 #include "cache.hpp" 25 #include "utilities/buffer_test.hpp" 26 #include "database/database.hpp" 27 #include "routines/common.hpp" 28 29 namespace clblast { 30 // ================================================================================================= 31 32 // See comment at top of file for a description of the class 33 class Routine { 34 public: 35 36 // Base class constructor. The user database is an optional extra database to override the 37 // built-in database. 38 // All heavy preparation work is done inside this constructor. 39 // NOTE: the caller must provide the same userDatabase for each combination of device, precision 40 // and routine list, otherwise the caching logic will break. 41 explicit Routine(Queue &queue, EventPointer event, const std::string &name, 42 const std::vector<std::string> &routines, const Precision precision, 43 const std::vector<database::DatabaseEntry> &userDatabase, 44 std::initializer_list<const char *> source); 45 46 // List of kernel-routine look-ups 47 static const std::vector<std::string> routines_axpy; 48 static const std::vector<std::string> routines_dot; 49 static const std::vector<std::string> routines_ger; 50 static const std::vector<std::string> routines_gemv; 51 static const std::vector<std::string> routines_gemm; 52 static const std::vector<std::string> routines_gemm_syrk; 53 static const std::vector<std::string> routines_trsm; 54 static const std::unordered_map<std::string, const std::vector<std::string>> routines_by_kernel; 55 56 private: 57 58 // Initializes program_, fetching cached program or building one 59 void InitProgram(std::initializer_list<const char *> source); 60 61 // Initializes db_, fetching cached database or building one 62 void InitDatabase(const std::vector<database::DatabaseEntry> &userDatabase); 63 64 protected: 65 66 // Non-static variable for the precision 67 const Precision precision_; 68 69 // The routine's name and the corresponding kernels 70 const std::string routine_name_; 71 const std::vector<std::string> kernel_names_; 72 73 // The OpenCL objects, accessible only from derived classes 74 Queue queue_; 75 EventPointer event_; 76 const Context context_; 77 const Device device_; 78 const cl_platform_id platform_; 79 80 // Compiled program (either retrieved from cache or compiled in slow path) 81 Program program_; 82 83 // Connection to the database for all the device-specific parameters 84 Databases db_; 85 }; 86 87 // ================================================================================================= 88 } // namespace clblast 89 90 // CLBLAST_ROUTINE_H_ 91 #endif 92