blob: 126172be74b9e227010b2cc897aed6deb2feafc2 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef BUF_ATTRIBUTES_HPP
19#define BUF_ATTRIBUTES_HPP
20
21#ifdef __has_attribute
22#define HAVE_ATTRIBUTE(x) __has_attribute(x)
23#else /* __has_attribute */
24#define HAVE_ATTRIBUTE(x) 0
25#endif /* __has_attribute */
26
27#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
28
29/* We want all buffers/sections to be aligned to 16 byte. */
30#define ALIGNMENT_REQ aligned(16)
31
32/* Model data section name. */
33#define MODEL_SECTION section("nn_model")
34
35/* Label section name */
36#define LABEL_SECTION section("labels")
37
38#ifndef ACTIVATION_BUF_SZ
39 #warning "ACTIVATION_BUF_SZ needs to be defined. Using default value"
40 #define ACTIVATION_BUF_SZ 0x00200000
41#endif /* ACTIVATION_BUF_SZ */
42
43#ifndef ACTIVATION_BUF_SRAM_SZ
44 #warning "ACTIVATION_BUF_SRAM_SZ needs to be defined. Using default value = 0"
45 #define ACTIVATION_BUF_SRAM_SZ 0x00000000
46#endif /* ACTIVATION_BUF_SRAM_SZ */
47
48/**
49 * Activation buffer aka tensor arena section name
50 * We have to place the tensor arena in different region based on its size.
51 * If it fits in SRAM, we place it there, and also mark it by giving it a
52 * different section name. The scatter file places the ZI data in DDR and
53 * the uninitialised region in the SRAM.
54 **/
55#define ACTIVATION_BUF_SECTION_SRAM section(".bss.NoInit.activation_buf")
56#define ACTIVATION_BUF_SECTION_DRAM section("activation_buf")
57
58#if ACTIVATION_BUF_SZ > ACTIVATION_BUF_SRAM_SZ /* Will buffer not fit in SRAM? */
59 #define ACTIVATION_BUF_SECTION ACTIVATION_BUF_SECTION_DRAM
60 #define ACTIVATION_BUF_SECTION_NAME ("DDR")
61#else /* ACTIVATION_BUF_SZ > 0x00200000 */
62 #define ACTIVATION_BUF_SECTION ACTIVATION_BUF_SECTION_SRAM
63 #define ACTIVATION_BUF_SECTION_NAME ("SRAM")
64#endif /* ACTIVATION_BUF_SZ > 0x00200000 */
65
66/* IFM section name. */
67#define IFM_BUF_SECTION section("ifm")
68
69/* Form the attributes, alignment is mandatory. */
70#define MAKE_ATTRIBUTE(x) __attribute__((ALIGNMENT_REQ, x))
71#define MODEL_TFLITE_ATTRIBUTE MAKE_ATTRIBUTE(MODEL_SECTION)
72#define ACTIVATION_BUF_ATTRIBUTE MAKE_ATTRIBUTE(ACTIVATION_BUF_SECTION)
73#define IFM_BUF_ATTRIBUTE MAKE_ATTRIBUTE(IFM_BUF_SECTION)
74#define LABELS_ATTRIBUTE MAKE_ATTRIBUTE(LABEL_SECTION)
75
76#else /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
77
78#define MODEL_TFLITE_ATTRIBUTE
79#define ACTIVATION_BUF_ATTRIBUTE
80#define IFM_BUF_ATTRIBUTE
81#define LABELS_ATTRIBUTE
82
83#endif /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
84
85#endif /* BUF_ATTRIBUTES_HPP */