2 // Copyright (c) 2016 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 #include "cldnn_defs.h"
21 #include "profiling.hpp"
28 /// @addtogroup cpp_api C++ API
31 /// @addtogroup cpp_event Events Support
34 /// @brief Represents an clDNN Event object
37 /// @brief Create an event which can be set to 'completed' by user.
38 static event create_user_event(const engine& engine)
40 return check_status<cldnn_event>("create user event failed", [&](status_t* status) { return cldnn_create_user_event(engine.get(), status); });
43 /// @brief Construct from C API handler @ref ::cldnn_event.
44 event(cldnn_event impl) : _impl(impl)
46 if (_impl == nullptr) throw std::invalid_argument("implementation pointer should not be null");
49 event(const event& other) : _impl(other._impl)
54 event& operator=(const event& other)
56 if (_impl == other._impl) return *this;
68 friend bool operator==(const event& lhs, const event& rhs) { return lhs._impl == rhs._impl; }
69 friend bool operator!=(const event& lhs, const event& rhs) { return !(lhs == rhs); }
71 /// @brief Wait for event completion.
72 void wait() const { check_status<void>("wait event failed", [=](status_t* status) { cldnn_wait_for_event(_impl, status); }); }
74 /// @brief Set event status to 'completed'.
75 void set() const { check_status<void>("set event failed", [=](status_t* status) { cldnn_set_event(_impl, status); }); }
77 /// @brief Register call back to be called on event completion.
78 void set_event_handler(cldnn_event_handler handler, void* param) const
80 check_status<void>("set event handler failed", [=](status_t* status) { cldnn_add_event_handler(_impl, handler, param, status); });
83 /// @brief Get profiling info for the event associated with network output.
84 std::vector<instrumentation::profiling_interval> get_profiling_info() const
86 using namespace instrumentation;
89 status_t err_invalid_arg = CLDNN_SUCCESS;
90 cldnn_get_event_profiling_info(_impl, nullptr, 0, &size_ret, &err_invalid_arg);
97 std::vector<cldnn_profiling_interval> profiling_info_ref(size_ret);
99 check_status<void>("get event profiling info failed", [&](status_t* status)
101 cldnn_get_event_profiling_info(_impl, profiling_info_ref.data(), profiling_info_ref.size(), &size_ret, status);
103 assert(profiling_info_ref.size() == size_ret);
105 std::vector<profiling_interval> result(profiling_info_ref.size());
107 std::begin(profiling_info_ref),
108 std::end(profiling_info_ref),
110 [](const cldnn_profiling_interval& ref) -> profiling_interval
114 std::make_shared<profiling_period_basic>(std::chrono::nanoseconds(ref.nanoseconds))
121 /// @brief Returns C API event handler.
122 cldnn_event get() const { return _impl; }
127 check_status<void>("retain event failed", [=](status_t* status) { cldnn_retain_event(_impl, status); });
131 check_status<void>("retain event failed", [=](status_t* status) { cldnn_release_event(_impl, status); });
134 CLDNN_API_CLASS(event)