aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test/ProfilingEventTest.cpp
blob: 1e3d1eac7f85ed63bd66b5e33a1a7c7f120fdde7 (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
94
95
96
97
98
99
100
101
102
103
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include <doctest/doctest.h>

#include "ProfilingEvent.hpp"
#include "Profiling.hpp"

#include <thread>

using namespace armnn;

TEST_SUITE("ProfilingEvent")
{
TEST_CASE("ProfilingEventTest")
{
    // Get a reference to the profiler manager.
    armnn::ProfilerManager& profileManager = armnn::ProfilerManager::GetInstance();

    const char* eventName = "EventName";

    Event::Instruments insts1;
    insts1.emplace_back(std::make_unique<WallClockTimer>());
    Event testEvent(eventName,
                    nullptr,
                    nullptr,
                    BackendId(),
                    std::move(insts1));

    CHECK_EQ(testEvent.GetName(), "EventName");

    // start the timer - outer
    testEvent.Start();

    // wait for 10 microseconds
    std::this_thread::sleep_for(std::chrono::microseconds(10));

    // stop the timer - outer
    testEvent.Stop();

    CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0);

    // create a sub event with CpuAcc
    BackendId cpuAccBackendId(Compute::CpuAcc);
    Event::Instruments insts2;
    insts2.emplace_back(std::make_unique<WallClockTimer>());
    Event testEvent2(eventName,
                     profileManager.GetProfiler(),
                     &testEvent,
                     cpuAccBackendId,
                     std::move(insts2));

    CHECK_EQ(&testEvent, testEvent2.GetParentEvent());
    CHECK_EQ(profileManager.GetProfiler(), testEvent2.GetProfiler());
    CHECK(cpuAccBackendId == testEvent2.GetBackendId());
}

TEST_CASE("ProfilingEventTestOnGpuAcc")
{
    // Get a reference to the profiler manager.
    armnn::ProfilerManager& profileManager = armnn::ProfilerManager::GetInstance();

    const char* eventName = "GPUEvent";

    Event::Instruments insts1;
    insts1.emplace_back(std::make_unique<WallClockTimer>());
    Event testEvent(eventName,
                    nullptr,
                    nullptr,
                    BackendId(),
                    std::move(insts1));

    CHECK_EQ(testEvent.GetName(), "GPUEvent");

    // start the timer - outer
    testEvent.Start();

    // wait for 10 microseconds
    std::this_thread::sleep_for(std::chrono::microseconds(10));

    // stop the timer - outer
    testEvent.Stop();

    CHECK_GE(testEvent.GetMeasurements().front().m_Value, 10.0);

    // create a sub event
    BackendId gpuAccBackendId(Compute::GpuAcc);
    Event::Instruments insts2;
    insts2.emplace_back(std::make_unique<WallClockTimer>());
    Event testEvent2(eventName,
                     profileManager.GetProfiler(),
                     &testEvent,
                     gpuAccBackendId,
                     std::move(insts2));

    CHECK_EQ(&testEvent, testEvent2.GetParentEvent());
    CHECK_EQ(profileManager.GetProfiler(), testEvent2.GetProfiler());
    CHECK(gpuAccBackendId == testEvent2.GetBackendId());
}

}