spla
cl_counter.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of spla project */
3 /* https://github.com/JetBrains-Research/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_COUNTER_HPP
29 #define SPLA_CL_COUNTER_HPP
30 
32 
33 #include <memory>
34 #include <vector>
35 
36 namespace spla {
37 
42  class CLCounter {
43  public:
44  explicit CLCounter(uint init = 0);
45 
46  uint get(cl::CommandQueue& queue, cl::Event* event = nullptr);
47  void set(cl::CommandQueue& queue, uint value, cl::Event* event = nullptr);
48  cl::Buffer& buffer();
49 
50  private:
51  cl::Buffer m_buffer;
52  };
53 
59  public:
62 
63  uint get(cl::CommandQueue& queue, cl::Event* event = nullptr);
64  void set(cl::CommandQueue& queue, uint value, cl::Event* event = nullptr);
65  cl::Buffer& buffer();
66 
67  private:
68  std::shared_ptr<CLCounter> m_counter;
69  };
70 
75  class CLCounterPool {
76  public:
77  explicit CLCounterPool(uint pre_allocate = 16);
78 
79  std::shared_ptr<CLCounter> allocate();
80  void release(std::shared_ptr<CLCounter> counter);
81 
82  private:
83  std::vector<std::shared_ptr<CLCounter>> m_counters;
84  };
85 
86 }// namespace spla
87 
88 #endif//SPLA_CL_COUNTER_HPP
Global pool with pre-allocated counters.
Definition: cl_counter.hpp:75
CLCounterPool(uint pre_allocate=16)
Definition: cl_counter.cpp:63
void release(std::shared_ptr< CLCounter > counter)
Definition: cl_counter.cpp:77
std::shared_ptr< CLCounter > allocate()
Definition: cl_counter.cpp:68
Definition: cl_counter.hpp:58
uint get(cl::CommandQueue &queue, cl::Event *event=nullptr)
Definition: cl_counter.cpp:53
~CLCounterWrapper()
Definition: cl_counter.cpp:50
CLCounterWrapper()
Definition: cl_counter.cpp:47
cl::Buffer & buffer()
Definition: cl_counter.cpp:59
void set(cl::CommandQueue &queue, uint value, cl::Event *event=nullptr)
Definition: cl_counter.cpp:56
Unsigned integer reusable counter for operations.
Definition: cl_counter.hpp:42
cl::Buffer & buffer()
Definition: cl_counter.cpp:43
uint get(cl::CommandQueue &queue, cl::Event *event=nullptr)
Definition: cl_counter.cpp:35
CLCounter(uint init=0)
Definition: cl_counter.cpp:32
void set(cl::CommandQueue &queue, uint value, cl::Event *event=nullptr)
Definition: cl_counter.cpp:40
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
Definition: algorithm.hpp:37