char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Max Krasnyanskyhexagon: L2 cache handling rework (dirty bit tracking with lazy flushing) and more MUL_MAT updates (#25762)b2dd28a3b

char/aliceai-t5-moe
2.0 KiB64 linesraw
1#ifndef HEX_PROFILE_H
2#define HEX_PROFILE_H
3
4#include <stdbool.h>
5#include <stdint.h>
6#include <qurt.h>
7
8#include "hex-utils.h"
9#include "htp-ops.h"
10
11#define HTP_TRACE_EVT_START 0
12#define HTP_TRACE_EVT_STOP  1
13
14#ifndef HEX_NUM_PMU_COUNTERS
15#define HEX_NUM_PMU_COUNTERS 8
16#endif
17
18static inline void hex_get_pmu(uint32_t counters[]) {
19#if __HVX_ARCH__ >= 79
20    asm volatile("%0 = upmucnt0" : "=r"(counters[0]));
21    asm volatile("%0 = upmucnt1" : "=r"(counters[1]));
22    asm volatile("%0 = upmucnt2" : "=r"(counters[2]));
23    asm volatile("%0 = upmucnt3" : "=r"(counters[3]));
24    asm volatile("%0 = upmucnt4" : "=r"(counters[4]));
25    asm volatile("%0 = upmucnt5" : "=r"(counters[5]));
26    asm volatile("%0 = upmucnt6" : "=r"(counters[6]));
27    asm volatile("%0 = upmucnt7" : "=r"(counters[7]));
28#else
29    counters[0] = qurt_pmu_get(QURT_PMUCNT0);
30    counters[1] = qurt_pmu_get(QURT_PMUCNT1);
31    counters[2] = qurt_pmu_get(QURT_PMUCNT2);
32    counters[3] = qurt_pmu_get(QURT_PMUCNT3);
33    counters[4] = qurt_pmu_get(QURT_PMUCNT4);
34    counters[5] = qurt_pmu_get(QURT_PMUCNT5);
35    counters[6] = qurt_pmu_get(QURT_PMUCNT6);
36    counters[7] = qurt_pmu_get(QURT_PMUCNT7);
37#endif
38}
39
40struct htp_thread_trace {
41    uint32_t count;
42    uint32_t max_events;
43    struct htp_trace_desc * events;
44};
45
46static inline void htp_trace_event(struct htp_thread_trace * tr, uint16_t id, uint16_t info, uint32_t type) {
47    if (tr->count < tr->max_events) {
48        uint32_t i = tr->count;
49        tr->events[i].id     = id;
50        tr->events[i].info   = info | (type == HTP_TRACE_EVT_STOP ? 0x8000 : 0);
51        tr->events[i].cycles = (uint32_t) hex_get_cycles();
52        tr->count++;
53    }
54}
55
56static inline void htp_trace_event_start(struct htp_thread_trace * tr, uint16_t id, uint16_t info) {
57    htp_trace_event(tr, id, info, HTP_TRACE_EVT_START);
58}
59
60static inline void htp_trace_event_stop(struct htp_thread_trace * tr, uint16_t id, uint16_t info) {
61    htp_trace_event(tr, id, info, HTP_TRACE_EVT_STOP);
62}
63
64#endif /* HEX_PROFILE_H */