blob: 0146443a55f8eb40e90cc7c9a3f02e67f428b392 [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
alexander3c798932021-03-26 21:42:19 +000053/* IFM section name. */
54#define IFM_BUF_SECTION section("ifm")
55
56/* Form the attributes, alignment is mandatory. */
57#define MAKE_ATTRIBUTE(x) __attribute__((ALIGNMENT_REQ, x))
58#define MODEL_TFLITE_ATTRIBUTE MAKE_ATTRIBUTE(MODEL_SECTION)
59#define ACTIVATION_BUF_ATTRIBUTE MAKE_ATTRIBUTE(ACTIVATION_BUF_SECTION)
60#define IFM_BUF_ATTRIBUTE MAKE_ATTRIBUTE(IFM_BUF_SECTION)
61#define LABELS_ATTRIBUTE MAKE_ATTRIBUTE(LABEL_SECTION)
62
63#else /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
64
65#define MODEL_TFLITE_ATTRIBUTE
66#define ACTIVATION_BUF_ATTRIBUTE
67#define IFM_BUF_ATTRIBUTE
68#define LABELS_ATTRIBUTE
69
70#endif /* HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) */
71
Kshitij Sisodia8bc863d2022-03-24 17:53:34 +000072#endif /* BUF_ATTRIBUTES_HPP */