summaryrefslogtreecommitdiff
path: root/source/application/main/include/BufAttributes.hpp
blob: 070013af9f696b78a595043d18d9f45f71dc73d5 (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
68
69
70
71
72
/*
 * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef BUF_ATTRIBUTES_HPP
#define BUF_ATTRIBUTES_HPP

#if defined(ARM_NPU)
    /* When Arm NPU is defined, we use the config set by NPU mem parameters */
    #include "ethosu_mem_config.h"
    #define BYTE_ALIGNMENT              ETHOS_U_MEM_BYTE_ALIGNMENT
#else /* defined(ARM_NPU) */
    /* otherwise, we use the default ones here. */
    #define ACTIVATION_BUF_SECTION      section(".bss.NoInit.activation_buf_sram")
    #define ACTIVATION_BUF_SECTION_NAME ("SRAM")
    #define BYTE_ALIGNMENT              16
#endif /* defined(ARM_NPU) */

#ifdef __has_attribute
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
#else   /* __has_attribute */
#define HAVE_ATTRIBUTE(x) 0
#endif  /* __has_attribute */

#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))

/* We want all buffers/sections to be aligned to 16 byte.  */
#define ALIGNMENT_REQ               aligned(BYTE_ALIGNMENT)

#define MODEL_SECTION               section("nn_model")

/* Label section name */
#define LABEL_SECTION               section("labels")

#ifndef ACTIVATION_BUF_SZ
    #warning  "ACTIVATION_BUF_SZ needs to be defined. Using default value"
    #define ACTIVATION_BUF_SZ       0x00200000
#endif  /* ACTIVATION_BUF_SZ */

/* IFM section name. */
#define IFM_BUF_SECTION             section("ifm")

/* Form the attributes, alignment is mandatory. */
#define MAKE_ATTRIBUTE(x)           __attribute__((ALIGNMENT_REQ, x))
#define MODEL_TFLITE_ATTRIBUTE      MAKE_ATTRIBUTE(MODEL_SECTION)
#define ACTIVATION_BUF_ATTRIBUTE    MAKE_ATTRIBUTE(ACTIVATION_BUF_SECTION)
#define IFM_BUF_ATTRIBUTE           MAKE_ATTRIBUTE(IFM_BUF_SECTION)
#define LABELS_ATTRIBUTE            MAKE_ATTRIBUTE(LABEL_SECTION)

#else /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */

#define MODEL_TFLITE_ATTRIBUTE
#define ACTIVATION_BUF_ATTRIBUTE
#define IFM_BUF_ATTRIBUTE
#define LABELS_ATTRIBUTE

#endif /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */

#endif /* BUF_ATTRIBUTES_HPP */