Snitch Runtime
Loading...
Searching...
No Matches
sync_decls.h
1// Copyright 2023 ETH Zurich and University of Bologna.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#pragma once
6
7#include <limits.h>
8#include <stdint.h>
9
10typedef struct {
11 uint32_t volatile cnt;
12 uint32_t volatile iteration;
14
15typedef struct {
16 volatile uint32_t *barrier_ptr;
17 uint32_t size;
18 uint32_t mask;
19 uint32_t base;
20 uint32_t is_participant;
22
24
25// NOTE: these numeric values must match FlooNoC's encoding
26typedef enum {
27 SNRT_COLLECTIVE_UNICAST = 0,
28 SNRT_COLLECTIVE_MULTICAST = 1,
29 SNRT_REDUCTION_BARRIER = 2,
30 SNRT_NUM_BUILTIN_COLLECTIVE_OPS = 6,
31 // Other reduction opcodes are generated through snrt_reduction_op()
32} snrt_collective_opcode_t;
33
34typedef enum {
35 SNRT_REDUCTION_MAX = 0,
36 SNRT_REDUCTION_MIN = 1,
37 SNRT_REDUCTION_SUM = 2,
38 SNRT_REDUCTION_PROD = 3,
39} snrt_reduction_op_type_t;
40
41typedef enum {
42 SNRT_REDUCTION_FP8 = 0,
43 SNRT_REDUCTION_FP16 = 1,
44 SNRT_REDUCTION_FP16ALT = 2,
45 SNRT_REDUCTION_FP32 = 3,
46 SNRT_REDUCTION_FP64 = 4,
47 SNRT_NUM_REDUCTION_DATA_TYPES = 5,
48} snrt_reduction_data_type_t;
49
50// Minimum number of bits required to encode a reduction data type
51#define SNRT_REDUCTION_DATA_TYPE_BITS \
52 ((int)(sizeof(unsigned int) * CHAR_BIT) - \
53 __builtin_clz(SNRT_NUM_REDUCTION_DATA_TYPES - 1))
54
55typedef union {
56 struct __attribute__((__packed__)) {
57 snrt_collective_opcode_t opcode : SNRT_COLLECTIVE_OPCODE_WIDTH;
58 uint64_t mask : (64 - SNRT_COLLECTIVE_OPCODE_WIDTH);
59 } f;
60 uint64_t w;
62
63extern volatile uint32_t _snrt_mutex;
64extern volatile snrt_barrier_t _snrt_barrier;
65extern volatile uint32_t _reduction_result;
66
67inline volatile uint32_t *snrt_mutex();
68
69inline void snrt_mutex_acquire(volatile uint32_t *pmtx);
70
71inline void snrt_mutex_ttas_acquire(volatile uint32_t *pmtx);
72
73inline void snrt_mutex_release(volatile uint32_t *pmtx);
74
75inline void snrt_cluster_hw_barrier();
76
77inline void snrt_global_sw_barrier(snrt_comm_t comm = NULL);
78
79inline void snrt_global_barrier(snrt_comm_t comm = NULL);
80
81inline uint32_t snrt_global_all_to_all_reduction(uint32_t value);
82
83inline void snrt_wait_writeback(uint32_t val);
84
85inline uint64_t snrt_get_collective_mask(snrt_comm_t comm);
86
87inline void snrt_enable_multicast(uint64_t mask);
88
89inline void snrt_disable_multicast();
90
91inline snrt_collective_opcode_t snrt_reduction_op(
92 snrt_reduction_op_type_t op, snrt_reduction_data_type_t type);
93
94inline void snrt_enable_reduction(uint64_t mask,
95 snrt_collective_opcode_t collective_opcode);
96
97inline void snrt_enable_reduction(uint64_t mask, snrt_reduction_op_type_t op,
98 snrt_reduction_data_type_t type);
99
100inline void snrt_disable_reduction();
Definition sync_decls.h:10
Definition sync_decls.h:15
Definition sync_decls.h:55