tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stack_allocator.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 // LINT_C_FILE
21 #ifndef TVM_RUNTIME_CRT_STACK_ALLOCATOR_H_
22 #define TVM_RUNTIME_CRT_STACK_ALLOCATOR_H_
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include "crt_config.h"
27 #include "error_codes.h"
28 
29 #define STACK_ALLOCATOR_TAG 0xabcd1234
30 #define STACK_ALLOCATOR_TAG_SIZE_BYTES 4
31 
34 #ifndef TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES
35 #define TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES 16
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct {
43  uint8_t* next_alloc; // Pointer to the next block of TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES
44  uint8_t* workspace; // Pointer to start of the workspace
45  size_t workspace_size; // Total number of bytes in the workspace
47 
56  uint8_t* g_aot_memory, size_t workspace_size);
57 
67 tvm_crt_error_t StackMemoryManager_Allocate(tvm_workspace_t* tvm_runtime_workspace, int32_t nbytes,
68  void** current_alloc);
69 
80  int32_t nbytes, void** current_alloc,
81  uint8_t do_lifo_check);
82 
90 tvm_crt_error_t StackMemoryManager_Free(tvm_workspace_t* tvm_runtime_workspace, void* ptr);
91 
101  uint8_t do_lifo_check);
102 
103 #ifdef __cplusplus
104 } // extern "C"
105 #endif
106 
107 #endif // TVM_RUNTIME_CRT_STACK_ALLOCATOR_H_
Defines integral error codes returned by the CRT.
tvm_crt_error_t
Definition: error_codes.h:50
tvm_crt_error_t StackMemoryManager_Free(tvm_workspace_t *tvm_runtime_workspace, void *ptr)
The intended user-facing function to free the tensor within the buffer. It wraps StackMemoryManager_F...
tvm_crt_error_t StackMemoryManager_Init(tvm_workspace_t *tvm_runtime_workspace, uint8_t *g_aot_memory, size_t workspace_size)
Initialize the stack-based memory manager.
tvm_crt_error_t StackMemoryManager_Allocate(tvm_workspace_t *tvm_runtime_workspace, int32_t nbytes, void **current_alloc)
The intended user-facing function to allocate within the buffer. It wraps StackMemoryManager_Allocate...
tvm_crt_error_t StackMemoryManager_Allocate_Body(tvm_workspace_t *tvm_runtime_workspace, int32_t nbytes, void **current_alloc, uint8_t do_lifo_check)
The internal function that accepts allocate inputs and an extra byte to say to enable the LIFO check ...
tvm_crt_error_t StackMemoryManager_Free_Body(tvm_workspace_t *tvm_runtime_workspace, void *ptr, uint8_t do_lifo_check)
The internal function that accepts free inputs and an extra byte to say to enable the LIFO check that...
Definition: stack_allocator.h:42
uint8_t * workspace
Definition: stack_allocator.h:44
uint8_t * next_alloc
Definition: stack_allocator.h:43
size_t workspace_size
Definition: stack_allocator.h:45