2 // Copyright (c) 2019 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "refcounted_obj.h"
19 #include "event_impl.h"
20 #include "meta_utils.h"
28 template<typename Type,
29 typename U = typename std::enable_if<
30 meta::is_any_of<Type, base_event, user_event, base_events>::value>::type>
34 event_pool_impl() = default;
38 event_impl::ptr get_from_pool(std::shared_ptr<gpu_toolkit>& ctx)
40 for (auto& ev : _events)
45 return allocate({ new Type(ctx), false });
50 for (auto& ev : _events)
55 std::vector<event_impl::ptr> _events;
57 event_impl::ptr allocate(const event_impl::ptr& obj)
59 _events.emplace_back(obj);
60 return _events.back();
64 struct base_event_pool : event_pool_impl<base_event>
66 event_impl::ptr get(std::shared_ptr<gpu_toolkit>& ctx, const cl::Event& ev, const uint64_t q_stamp)
68 auto ret = get_from_pool(ctx);
69 dynamic_cast<type*>(ret.get())->attach_ocl_event(ev, q_stamp);
78 struct user_event_pool : event_pool_impl<user_event>
80 event_impl::ptr get(std::shared_ptr<gpu_toolkit>& ctx, bool set = false)
82 auto ret = get_from_pool(ctx);
83 dynamic_cast<type*>(ret.get())->attach_event(set);
92 struct group_event_pool : event_pool_impl<base_events>
94 event_impl::ptr get(std::shared_ptr<gpu_toolkit>& ctx, const std::vector<event_impl::ptr>& deps)
96 auto ret_ev = get_from_pool(ctx);
97 dynamic_cast<type*>(ret_ev.get())->attach_events(deps);
109 events_pool() = default;
111 event_impl::ptr get_from_base_pool(std::shared_ptr<gpu_toolkit> ctx, const cl::Event& ev, const uint64_t q_stamp)
113 return _base_pool.get(ctx, ev, q_stamp);
116 event_impl::ptr get_from_user_pool(std::shared_ptr<gpu_toolkit> ctx, bool set = false)
118 return _user_pool.get(ctx, set);
121 event_impl::ptr get_from_group_pool(std::shared_ptr<gpu_toolkit> ctx, const std::vector<event_impl::ptr>& deps)
123 return _group_pool.get(ctx, deps);
134 base_event_pool _base_pool;
135 user_event_pool _user_pool;
136 group_event_pool _group_pool;