spla
cl_program.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of spla project */
3 /* https://github.com/SparseLinearAlgebra/spla */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2023 SparseLinearAlgebra */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef SPLA_CL_PROGRAM_HPP
29 #define SPLA_CL_PROGRAM_HPP
30 
31 #include <spla/config.hpp>
32 #include <spla/op.hpp>
33 
35 
36 #include <svector.hpp>
37 
38 #include <string>
39 #include <vector>
40 
41 namespace spla {
42 
52  class CLProgram {
53  public:
54  cl::Kernel make_kernel(const char* name);
55 
56  [[nodiscard]] std::size_t get_defines_count() const { return m_defines.size(); }
57  [[nodiscard]] std::size_t get_functions_count() const { return m_functions.size(); }
58  [[nodiscard]] std::size_t get_sources_count() const { return m_sources.size(); }
59 
60  [[nodiscard]] const std::pair<std::string, std::string>& get_define(int i) const { return m_defines[i]; }
61  [[nodiscard]] const std::pair<std::string, ref_ptr<Op>>& get_function(int i) const { return m_functions[i]; }
62  [[nodiscard]] const std::string& get_source(int i) const { return m_sources[i]; }
63 
64  [[nodiscard]] const std::string& get_source() const { return m_source; }
65  [[nodiscard]] const std::string& get_name() const { return m_name; }
66  [[nodiscard]] const std::string& get_key() const { return m_key; }
67  [[nodiscard]] const cl::Program& get_program() const { return m_program; }
68 
69  private:
70  friend class CLProgramBuilder;
71 
72  ankerl::svector<std::pair<std::string, std::string>, 8> m_defines;
73  ankerl::svector<std::pair<std::string, ref_ptr<Op>>, 8> m_functions;
74  ankerl::svector<std::string, 2> m_sources;
75  std::string m_source;
76  std::string m_name;
77  std::string m_key;
78  cl::Program m_program;
79  };
80 
85 }// namespace spla
86 
87 #endif//SPLA_CL_PROGRAM_HPP
Runtime opencl program builder.
Definition: cl_program_builder.hpp:55
Compiled opencl program from library sources.
Definition: cl_program.hpp:52
std::size_t get_defines_count() const
Definition: cl_program.hpp:56
const cl::Program & get_program() const
Definition: cl_program.hpp:67
const std::string & get_source() const
Definition: cl_program.hpp:64
const std::string & get_name() const
Definition: cl_program.hpp:65
const std::pair< std::string, std::string > & get_define(int i) const
Definition: cl_program.hpp:60
const std::pair< std::string, ref_ptr< Op > > & get_function(int i) const
Definition: cl_program.hpp:61
cl::Kernel make_kernel(const char *name)
Definition: cl_program.cpp:32
const std::string & get_key() const
Definition: cl_program.hpp:66
std::size_t get_sources_count() const
Definition: cl_program.hpp:58
std::size_t get_functions_count() const
Definition: cl_program.hpp:57
const std::string & get_source(int i) const
Definition: cl_program.hpp:62
Definition: algorithm.hpp:37