Debian Codegraph @

shared/source/built_ins/kernels/copy_kernel_timestamps.builtin_kernel

raw
1 /*
2 * Copyright (C) 2020-2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 R"===(
9 void SetDstData(__global ulong* dst, uint currentOffset, ulong contextStart, ulong globalStart, ulong contextEnd, ulong globalEnd, uint useOnlyGlobalTimestamps) {
10 dst[currentOffset] = globalStart;
11 dst[currentOffset + 1] = globalEnd;
12 if (useOnlyGlobalTimestamps != 0) {
13 dst[currentOffset + 2] = globalStart;
14 dst[currentOffset + 3] = globalEnd;
15 } else {
16 dst[currentOffset + 2] = contextStart;
17 dst[currentOffset + 3] = contextEnd;
18 }
19 }
20
21 ulong GetTimestampValue(ulong srcPtr, ulong timestampSizeInDw, uint index) {
22 if(timestampSizeInDw == 1) {
23 __global uint *src = (__global uint *) srcPtr;
24 return src[index];
25 } else if(timestampSizeInDw == 2) {
26 __global ulong *src = (__global ulong *) srcPtr;
27 return src[index];
28 }
29
30 return 0;
31 }
32
33 __kernel void QueryKernelTimestamps(__global ulong* srcEvents, __global ulong* dst, uint useOnlyGlobalTimestamps) {
34 uint gid = get_global_id(0);
35 uint currentOffset = gid * 4;
36 dst[currentOffset] = 0;
37 dst[currentOffset + 1] = 0;
38 dst[currentOffset + 2] = 0;
39 dst[currentOffset + 3] = 0;
40
41 uint eventOffsetData = 3 * gid;
42
43 ulong srcPtr = srcEvents[eventOffsetData];
44 ulong packetUsed = srcEvents[eventOffsetData + 1];
45 ulong timestampSizeInDw = srcEvents[eventOffsetData + 2];
46
47 ulong contextStart = GetTimestampValue(srcPtr, timestampSizeInDw, 0);
48 ulong globalStart = GetTimestampValue(srcPtr, timestampSizeInDw, 1);
49 ulong contextEnd = GetTimestampValue(srcPtr, timestampSizeInDw, 2);
50 ulong globalEnd = GetTimestampValue(srcPtr, timestampSizeInDw, 3);
51
52 if(packetUsed > 1) {
53 for(uint i = 1; i < packetUsed; i++) {
54 uint timestampsOffsets = 4 * i;
55 if(contextStart > GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets)) {
56 contextStart = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets);
57 }
58 if(globalStart > GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 1)) {
59 globalStart = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 1);
60 }
61 if(contextEnd < GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 2)) {
62 contextEnd = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 2);
63 }
64 if(globalEnd < GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 3)) {
65 globalEnd = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 3);
66 }
67 }
68 }
69
70 SetDstData(dst, currentOffset, contextStart, globalStart, contextEnd, globalEnd, useOnlyGlobalTimestamps);
71 }
72
73 __kernel void QueryKernelTimestampsWithOffsets(__global ulong* srcEvents, __global ulong* dst, __global ulong *offsets, uint useOnlyGlobalTimestamps) {
74 uint gid = get_global_id(0);
75 uint currentOffset = offsets[gid] / 8;
76 dst[currentOffset] = 0;
77 dst[currentOffset + 1] = 0;
78 dst[currentOffset + 2] = 0;
79 dst[currentOffset + 3] = 0;
80
81 uint eventOffsetData = 3 * gid;
82
83 ulong srcPtr = srcEvents[eventOffsetData];
84 ulong packetUsed = srcEvents[eventOffsetData + 1];
85 ulong timestampSizeInDw = srcEvents[eventOffsetData + 2];
86
87 ulong contextStart = GetTimestampValue(srcPtr, timestampSizeInDw, 0);
88 ulong globalStart = GetTimestampValue(srcPtr, timestampSizeInDw, 1);
89 ulong contextEnd = GetTimestampValue(srcPtr, timestampSizeInDw, 2);
90 ulong globalEnd = GetTimestampValue(srcPtr, timestampSizeInDw, 3);
91
92 if(packetUsed > 1) {
93 for(uint i = 1; i < packetUsed; i++) {
94 uint timestampsOffsets = 4 * i;
95 if(contextStart > GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets)) {
96 contextStart = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets);
97 }
98 if(globalStart > GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 1)) {
99 globalStart = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 1);
100 }
101 if(contextEnd < GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 2)) {
102 contextEnd = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 2);
103 }
104 if(globalEnd < GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 3)) {
105 globalEnd = GetTimestampValue(srcPtr, timestampSizeInDw, timestampsOffsets + 3);
106 }
107 }
108 }
109
110 SetDstData(dst, currentOffset, contextStart, globalStart, contextEnd, globalEnd, useOnlyGlobalTimestamps);
111 }
112 )==="