File: static_tracepoint_elfx86.h

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (144 lines) | stat: -rw-r--r-- 7,673 bytes parent folder | download | duplicates (3)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once

// clang-format off

// Default constraint for the probe arguments as operands.
#ifndef TORCH_SDT_ARG_CONSTRAINT
#define TORCH_SDT_ARG_CONSTRAINT      "nor"
#endif

// Instruction to emit for the probe.
#define TORCH_SDT_NOP                 nop

// Note section properties.
#define TORCH_SDT_NOTE_NAME           "stapsdt"
#define TORCH_SDT_NOTE_TYPE           3

// Semaphore variables are put in this section
#define TORCH_SDT_SEMAPHORE_SECTION   ".probes"

// Size of address depending on platform.
#ifdef __LP64__
#define TORCH_SDT_ASM_ADDR            .8byte
#else
#define TORCH_SDT_ASM_ADDR            .4byte
#endif

// Assembler helper Macros.
#define TORCH_SDT_S(x)                #x
#define TORCH_SDT_ASM_1(x)            TORCH_SDT_S(x) "\n"
#define TORCH_SDT_ASM_2(a, b)         TORCH_SDT_S(a) "," TORCH_SDT_S(b) "\n"
#define TORCH_SDT_ASM_3(a, b, c)      TORCH_SDT_S(a) "," TORCH_SDT_S(b) ","    \
                                      TORCH_SDT_S(c) "\n"
#define TORCH_SDT_ASM_STRING(x)       TORCH_SDT_ASM_1(.asciz TORCH_SDT_S(x))

// Helper to determine the size of an argument.
#define TORCH_SDT_IS_ARRAY_POINTER(x)  ((__builtin_classify_type(x) == 14) ||  \
                                        (__builtin_classify_type(x) == 5))
#define TORCH_SDT_ARGSIZE(x)  (TORCH_SDT_IS_ARRAY_POINTER(x)                   \
                               ? sizeof(void*)                                 \
                               : sizeof(x))

// Format of each probe arguments as operand.
// Size of the argument tagged with TORCH_SDT_Sn, with "n" constraint.
// Value of the argument tagged with TORCH_SDT_An, with configured constraint.
#define TORCH_SDT_ARG(n, x)                                                    \
  [TORCH_SDT_S##n] "n"                ((size_t)TORCH_SDT_ARGSIZE(x)),          \
  [TORCH_SDT_A##n] TORCH_SDT_ARG_CONSTRAINT (x)

// Templates to append arguments as operands.
#define TORCH_SDT_OPERANDS_0()        [__sdt_dummy] "g" (0)
#define TORCH_SDT_OPERANDS_1(_1)      TORCH_SDT_ARG(1, _1)
#define TORCH_SDT_OPERANDS_2(_1, _2)                                           \
  TORCH_SDT_OPERANDS_1(_1), TORCH_SDT_ARG(2, _2)
#define TORCH_SDT_OPERANDS_3(_1, _2, _3)                                       \
  TORCH_SDT_OPERANDS_2(_1, _2), TORCH_SDT_ARG(3, _3)
#define TORCH_SDT_OPERANDS_4(_1, _2, _3, _4)                                   \
  TORCH_SDT_OPERANDS_3(_1, _2, _3), TORCH_SDT_ARG(4, _4)
#define TORCH_SDT_OPERANDS_5(_1, _2, _3, _4, _5)                               \
  TORCH_SDT_OPERANDS_4(_1, _2, _3, _4), TORCH_SDT_ARG(5, _5)
#define TORCH_SDT_OPERANDS_6(_1, _2, _3, _4, _5, _6)                           \
  TORCH_SDT_OPERANDS_5(_1, _2, _3, _4, _5), TORCH_SDT_ARG(6, _6)
#define TORCH_SDT_OPERANDS_7(_1, _2, _3, _4, _5, _6, _7)                       \
  TORCH_SDT_OPERANDS_6(_1, _2, _3, _4, _5, _6), TORCH_SDT_ARG(7, _7)
#define TORCH_SDT_OPERANDS_8(_1, _2, _3, _4, _5, _6, _7, _8)                   \
  TORCH_SDT_OPERANDS_7(_1, _2, _3, _4, _5, _6, _7), TORCH_SDT_ARG(8, _8)
#define TORCH_SDT_OPERANDS_9(_1, _2, _3, _4, _5, _6, _7, _8, _9)               \
  TORCH_SDT_OPERANDS_8(_1, _2, _3, _4, _5, _6, _7, _8), TORCH_SDT_ARG(9, _9)

// Templates to reference the arguments from operands in note section.
#define TORCH_SDT_ARGFMT(no)        %n[TORCH_SDT_S##no]@%[TORCH_SDT_A##no]
#define TORCH_SDT_ARG_TEMPLATE_0    /*No arguments*/
#define TORCH_SDT_ARG_TEMPLATE_1    TORCH_SDT_ARGFMT(1)
#define TORCH_SDT_ARG_TEMPLATE_2    TORCH_SDT_ARG_TEMPLATE_1 TORCH_SDT_ARGFMT(2)
#define TORCH_SDT_ARG_TEMPLATE_3    TORCH_SDT_ARG_TEMPLATE_2 TORCH_SDT_ARGFMT(3)
#define TORCH_SDT_ARG_TEMPLATE_4    TORCH_SDT_ARG_TEMPLATE_3 TORCH_SDT_ARGFMT(4)
#define TORCH_SDT_ARG_TEMPLATE_5    TORCH_SDT_ARG_TEMPLATE_4 TORCH_SDT_ARGFMT(5)
#define TORCH_SDT_ARG_TEMPLATE_6    TORCH_SDT_ARG_TEMPLATE_5 TORCH_SDT_ARGFMT(6)
#define TORCH_SDT_ARG_TEMPLATE_7    TORCH_SDT_ARG_TEMPLATE_6 TORCH_SDT_ARGFMT(7)
#define TORCH_SDT_ARG_TEMPLATE_8    TORCH_SDT_ARG_TEMPLATE_7 TORCH_SDT_ARGFMT(8)
#define TORCH_SDT_ARG_TEMPLATE_9    TORCH_SDT_ARG_TEMPLATE_8 TORCH_SDT_ARGFMT(9)

// Resolvable by name macros
// An attribute that marks a function or variable as needing to be resolvable
// by name. This generally is needed if inline assembly refers to the variable
// by string name.
#ifdef __roar__
#define TORCH_NAME_RESOLVABLE __attribute__((roar_resolvable_by_name))
#else
#define TORCH_NAME_RESOLVABLE
#endif

// Semaphore define, declare and probe note format

#define TORCH_SDT_SEMAPHORE(provider, name)                                    \
  torch_sdt_semaphore_##provider##_##name

#define TORCH_SDT_DEFINE_SEMAPHORE(name)                                       \
  extern "C" {                                                                 \
    TORCH_NAME_RESOLVABLE                                                      \
    volatile unsigned short TORCH_SDT_SEMAPHORE(pytorch, name)                 \
    __attribute__((section(TORCH_SDT_SEMAPHORE_SECTION), used)) = 0;           \
  }

#define TORCH_SDT_DECLARE_SEMAPHORE(name)                                      \
  extern "C" TORCH_NAME_RESOLVABLE volatile unsigned short                     \
    TORCH_SDT_SEMAPHORE(pytorch, name)

#define TORCH_SDT_SEMAPHORE_NOTE_0(provider, name)                             \
  TORCH_SDT_ASM_1(     TORCH_SDT_ASM_ADDR 0) /*No Semaphore*/                  \

#define TORCH_SDT_SEMAPHORE_NOTE_1(provider, name)                             \
  TORCH_SDT_ASM_1(TORCH_SDT_ASM_ADDR TORCH_SDT_SEMAPHORE(provider, name))

// Structure of note section for the probe.
#define TORCH_SDT_NOTE_CONTENT(provider, name, has_semaphore, arg_template)    \
  TORCH_SDT_ASM_1(990: TORCH_SDT_NOP)                                          \
  TORCH_SDT_ASM_3(     .pushsection .note.stapsdt,"","note")                   \
  TORCH_SDT_ASM_1(     .balign 4)                                              \
  TORCH_SDT_ASM_3(     .4byte 992f-991f, 994f-993f, TORCH_SDT_NOTE_TYPE)       \
  TORCH_SDT_ASM_1(991: .asciz TORCH_SDT_NOTE_NAME)                             \
  TORCH_SDT_ASM_1(992: .balign 4)                                              \
  TORCH_SDT_ASM_1(993: TORCH_SDT_ASM_ADDR 990b)                                \
  TORCH_SDT_ASM_1(     TORCH_SDT_ASM_ADDR 0) /*Reserved for Base Address*/     \
  TORCH_SDT_SEMAPHORE_NOTE_##has_semaphore(provider, name)                     \
  TORCH_SDT_ASM_STRING(provider)                                               \
  TORCH_SDT_ASM_STRING(name)                                                   \
  TORCH_SDT_ASM_STRING(arg_template)                                           \
  TORCH_SDT_ASM_1(994: .balign 4)                                              \
  TORCH_SDT_ASM_1(     .popsection)

// Main probe Macro.
#define TORCH_SDT_PROBE(provider, name, has_semaphore, n, arglist)             \
    __asm__ __volatile__ (                                                     \
      TORCH_SDT_NOTE_CONTENT(                                                  \
        provider, name, has_semaphore, TORCH_SDT_ARG_TEMPLATE_##n)             \
      :: TORCH_SDT_OPERANDS_##n arglist                                        \
    )                                                                          \

// Helper Macros to handle variadic arguments.
#define TORCH_SDT_NARG_(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define TORCH_SDT_NARG(...)                                                    \
  TORCH_SDT_NARG_(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define TORCH_SDT_PROBE_N(provider, name, has_semaphore, N, ...)               \
  TORCH_SDT_PROBE(provider, name, has_semaphore, N, (__VA_ARGS__))