mehrdadh commented on a change in pull request #8487:
URL: https://github.com/apache/tvm/pull/8487#discussion_r672444156



##########
File path: src/runtime/crt/memory/stack_allocator.c
##########
@@ -79,8 +79,13 @@ tvm_crt_error_t StackMemoryManager_Free(tvm_workspace_t* 
tvm_runtime_workspace,
 
 tvm_crt_error_t StackMemoryManager_Init(tvm_workspace_t* tvm_runtime_workspace,
                                         uint8_t* g_aot_memory, size_t 
workspace_size) {
-  tvm_runtime_workspace->next_alloc = g_aot_memory;
-  tvm_runtime_workspace->workspace = g_aot_memory;
-  tvm_runtime_workspace->workspace_size = workspace_size;
+  // Calculate g_aot_memory misalignment and offset
+  uint32_t extra = (uintptr_t)g_aot_memory % TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES;

Review comment:
       done.

##########
File path: tests/crt/aot_memory_test.cc
##########
@@ -24,33 +24,48 @@
 
 // Check with LIFO checks enabled for stack allocator
 #define TVM_CRT_STACK_ALLOCATOR_ENABLE_LIFO_CHECK
+
+/*
+ * Align memory pointer
+ */
+uint32_t align_memory_ptr(uint8_t* memory_ptr) {
+  uint32_t extra = (uintptr_t)memory_ptr % TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES;
+  uint32_t offset =
+      (TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES - extra) & 
(TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES - 1);
+  memory_ptr += offset;
+  return offset;
+}
+
 /*
  * Tests allocations are properly aligned when allocated
  */
 TEST(AOTMemory, Allocate) {
   static uint8_t model_memory[96];
   tvm_workspace_t tvm_runtime_workspace;
+  uint8_t* model_memory_ptr = model_memory;

Review comment:
       `memory_add_misalignment` and `memory_align` functions required to 
return the offset size so we can adjust the size.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to