xref: /aosp_15_r20/external/executorch/backends/arm/runtime/VelaBinStream.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright 2023-2024 Arm Limited and/or its affiliates.
3  *
4  * This source code is licensed under the BSD-style license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 /*
9  * Minimal reading function for vela_bin_stream wire format. This is an
10  * implementation detail of the arm_backend AoT flow and ArmBackendEthosU
11  * and subject to change.
12  * This format captures the command stream, I/O and memory layout data to
13  * enable execution of the command stream on Ethos-U hardware.
14  */
15 
16 #pragma once
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 namespace executorch {
22 namespace backends {
23 namespace arm {
24 
25 // Standard block name size
26 const uint32_t kVelaBlockNameLength = 16;
27 
28 // Generic block within the vela_bin_stream encoded by the python vela_compile
29 // step
30 typedef struct {
31   char name[kVelaBlockNameLength]; // string name, can be shorter or truncated
32   uint32_t size; // unpadded size, BinBlock size will be rounded to next_mul_16
33   char _pad[12]; // Our data often need 16 byte alignemnt
34   char data[]; // block.name specific format data
35 } VelaBinBlock;
36 
37 // A Vela input or output descriptor in the binary stream
38 typedef struct {
39   int shape[4]; // Up to 4D shape of input or output
40   int elem_size; // Element sizeof in bytes
41   int offset; // Offset in bytes within SRAM working data
42   int region; // Scratch region this belongs to
43 } VelaIO;
44 
45 // A list of VelaIOs from the binary stream
46 typedef struct {
47   int count;
48   VelaIO io[];
49 } VelaIOs;
50 
51 // Processed data used by the backend to invoke the payload
52 typedef struct {
53   const char* cmd_data;
54   size_t cmd_data_size;
55   const char* weight_data;
56   size_t weight_data_size;
57   char* scratch_data;
58   size_t scratch_data_size;
59   VelaIOs* inputs;
60   VelaIOs* outputs;
61 } VelaHandles;
62 
63 /* Takes in the preprocessed vela_bin_stream wire format and returns data
64  * needed to launch the workload on the Ethos-U and wire up input and
65  * output values.
66  */
67 bool vela_bin_read(const char* data, VelaHandles* handles, int size);
68 
69 /* Does minimal validation of a vela_bin_stream to ensure the overall
70  * structure is correct and so likely to contain valid binary data for launch
71  * on the Ethos-U.
72  */
73 bool vela_bin_validate(const char* data, int size);
74 
75 } // namespace arm
76 } // namespace backends
77 } // namespace executorch
78