blob: a3b5890453c099f023e11b650d96728c44eb5b9b [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
Isabella Gottardi118f73e2021-09-16 17:54:35 +010021#if defined(ARM_NPU)
22 /* When Arm NPU is defined, we use the config set by NPU mem parameters */
23 #include "ethosu_mem_config.h"
24 #define BYTE_ALIGNMENT ETHOS_U_MEM_BYTE_ALIGNMENT
25#else /* defined(ARM_NPU) */
26 /* otherwise, we use the default ones here. */
27 #define ACTIVATION_BUF_SECTION section(".bss.NoInit.activation_buf_sram")
28 #define ACTIVATION_BUF_SECTION_NAME ("SRAM")
29 #define BYTE_ALIGNMENT 16
30#endif /* defined(ARM_NPU) */
31
alexander3c798932021-03-26 21:42:19 +000032#ifdef __has_attribute
33#define HAVE_ATTRIBUTE(x) __has_attribute(x)
34#else /* __has_attribute */
35#define HAVE_ATTRIBUTE(x) 0
36#endif /* __has_attribute */
37
38#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
39
40/* We want all buffers/sections to be aligned to 16 byte. */
Isabella Gottardi118f73e2021-09-16 17:54:35 +010041#define ALIGNMENT_REQ aligned(BYTE_ALIGNMENT)
alexander3c798932021-03-26 21:42:19 +000042
alexander3c798932021-03-26 21:42:19 +000043#define MODEL_SECTION section("nn_model")
44
45/* Label section name */
46#define LABEL_SECTION section("labels")
47
48#ifndef ACTIVATION_BUF_SZ
49 #warning "ACTIVATION_BUF_SZ needs to be defined. Using default value"
50 #define ACTIVATION_BUF_SZ 0x00200000
51#endif /* ACTIVATION_BUF_SZ */
52
53#ifndef ACTIVATION_BUF_SRAM_SZ
54 #warning "ACTIVATION_BUF_SRAM_SZ needs to be defined. Using default value = 0"
55 #define ACTIVATION_BUF_SRAM_SZ 0x00000000
56#endif /* ACTIVATION_BUF_SRAM_SZ */
57
alexander3c798932021-03-26 21:42:19 +000058/* IFM section name. */
59#define IFM_BUF_SECTION section("ifm")
60
61/* Form the attributes, alignment is mandatory. */
62#define MAKE_ATTRIBUTE(x) __attribute__((ALIGNMENT_REQ, x))
63#define MODEL_TFLITE_ATTRIBUTE MAKE_ATTRIBUTE(MODEL_SECTION)
64#define ACTIVATION_BUF_ATTRIBUTE MAKE_ATTRIBUTE(ACTIVATION_BUF_SECTION)
65#define IFM_BUF_ATTRIBUTE MAKE_ATTRIBUTE(IFM_BUF_SECTION)
66#define LABELS_ATTRIBUTE MAKE_ATTRIBUTE(LABEL_SECTION)
67
68#else /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
69
70#define MODEL_TFLITE_ATTRIBUTE
71#define ACTIVATION_BUF_ATTRIBUTE
72#define IFM_BUF_ATTRIBUTE
73#define LABELS_ATTRIBUTE
74
75#endif /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
76
77#endif /* BUF_ATTRIBUTES_HPP */