summaryrefslogtreecommitdiffstats
path: root/openmp/offload/src/offload_timer_target.cpp
blob: 30a4c91240283a6d04de4974f4bad2a193cce96c (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
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.txt for details.
//
//===----------------------------------------------------------------------===//


#include "offload_timer.h"
#include "offload_target.h"

#ifdef __INTEL_COMPILER
#include <ia32intrin.h>
#else // __INTEL_COMPILER
#include <x86intrin.h>
#endif // __INTEL_COMPILER



int timer_enabled = 0;

#ifdef TIMING_SUPPORT

#if defined(LINUX) || defined(FREEBSD)
static __thread OffloadTargetTimerData timer_data;
#else // WINNT
static __declspec(thread) OffloadTargetTimerData timer_data;
#endif // defined(LINUX) || defined(FREEBSD)


void offload_timer_start(
    OffloadTargetPhase p_type
)
{
    timer_data.phases[p_type].start = _rdtsc();
}

void offload_timer_stop(
    OffloadTargetPhase p_type
)
{
    timer_data.phases[p_type].total += _rdtsc() -
                                       timer_data.phases[p_type].start;
}

void offload_timer_init()
{
    memset(&timer_data, 0, sizeof(OffloadTargetTimerData));
}

void offload_timer_fill_target_data(
    void *buf
)
{
    uint64_t *data = (uint64_t*) buf;

    timer_data.frequency = mic_frequency;
    memcpy(data++, &(timer_data.frequency), sizeof(uint64_t));

    for (int i = 0; i < c_offload_target_max_phase; i++) {
        memcpy(data++, &(timer_data.phases[i].total), sizeof(uint64_t));
    }
}

#endif // TIMING_SUPPORT
OpenPOWER on IntegriCloud