summaryrefslogtreecommitdiff
path: root/inference-engine/thirdparty/clDNN/src/gpu/ocl_base_event.cpp
blob: f6383e4ce374da4d9879bb3c2f736b196edd3a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "ocl_base_event.h"

#include <cassert>

using namespace cldnn;
using namespace gpu;

namespace {
    bool is_event_profiled(const cl::Event& event)
    {
        if (event() != nullptr)
        {
            auto queue = event.getInfo<CL_EVENT_COMMAND_QUEUE>();
            if (queue() != nullptr)
            {
                return (queue.getInfo<CL_QUEUE_PROPERTIES>() & CL_QUEUE_PROFILING_ENABLE) != 0;
            }
        }
        return false;
    }
}

void CL_CALLBACK base_event::ocl_event_completion_callback(cl_event, cl_int, void* me)
{
    reinterpret_cast<base_event*>(me)->_set = true;
    reinterpret_cast<base_event*>(me)->call_handlers();
}

void base_event::set_ocl_callback()
{
    if (_callback_set)
        return;

    if (_event.get() != nullptr)
    {
        _event.setCallback(CL_COMPLETE, ocl_event_completion_callback, this);
        _callback_set = true;
    }
}

void base_event::wait_impl()
{
    if (_event.get() != nullptr)
    {
        _event.wait();
        if (get_context()->logging_enabled())
        {
            get_context()->log(0, "Wait for event: " + std::to_string(_queue_stamp));
        }
    }
}

bool base_event::is_set_impl()
{
    if (_event.get() != nullptr)
    {
        return _event.getInfo<CL_EVENT_COMMAND_EXECUTION_STATUS>() == CL_COMPLETE;
    }
    return true;
}

bool base_event::add_event_handler_impl(cldnn_event_handler, void*)
{
    set_ocl_callback();
    return true;
}

bool base_event::get_profiling_info_impl(std::list<cldnn_profiling_interval>& info)
{
    if (!is_event_profiled(_event))
        return true;

    static const std::vector<profiling_period_ocl_start_stop> profiling_periods
    {
        { "submission", CL_PROFILING_COMMAND_QUEUED, CL_PROFILING_COMMAND_SUBMIT },
        { "starting",   CL_PROFILING_COMMAND_SUBMIT, CL_PROFILING_COMMAND_START },
        { "executing",  CL_PROFILING_COMMAND_START,  CL_PROFILING_COMMAND_END },
    };


    for (auto& period : profiling_periods)
    {
        cl_ulong start;
        cl_ulong end;

        _event.getProfilingInfo(period.start, &start);
        _event.getProfilingInfo(period.stop, &end);

        info.push_back({ period.name, end - start });
    }

    return true;
}