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



##########
File path: tests/crt/aot_memory_test.cc
##########
@@ -114,22 +135,51 @@ TEST(AOTMemory, OverAllocate) {
 TEST(AOTMemory, FreeOutOfOrder) {
   static uint8_t model_memory[80];
   tvm_workspace_t tvm_runtime_workspace;
-  ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80), 
kTvmErrorNoError);
+  uint8_t* model_memory_ptr = model_memory;
+  uint32_t offset = align_memory_ptr(model_memory_ptr);
+  ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory_ptr, 
80 - offset),
+            kTvmErrorNoError);
 
   void* block_one = NULL;
   ASSERT_EQ(StackMemoryManager_Allocate_Body(&tvm_runtime_workspace, 1, 
&block_one, 1),
             kTvmErrorNoError);
-  ASSERT_EQ(block_one, &model_memory[0]);
+  ASSERT_EQ(block_one, &model_memory_ptr[0]);
 
   void* block_two = NULL;
   ASSERT_EQ(StackMemoryManager_Allocate_Body(&tvm_runtime_workspace, 1, 
&block_two, 1),
             kTvmErrorNoError);
-  ASSERT_EQ(block_two, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);
+  ASSERT_EQ(block_two, &model_memory_ptr[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);
 
   ASSERT_EQ(StackMemoryManager_Free_Body(&tvm_runtime_workspace, block_one, 1),
             kTvmErrorPlatformStackAllocBadFree);
 }
 
+/*
+ * Test for initial memory misalignment
+ */
+TEST(AOTMemory, InitialMemoryMisAlignment) {
+  static uint8_t model_memory[80];
+  tvm_workspace_t tvm_runtime_workspace;
+  uint8_t* model_memory_ptr = model_memory;
+
+  uint32_t mem_alignment = (uintptr_t)model_memory_ptr % 
TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES;
+  if (mem_alignment == 0) {

Review comment:
       I think there'e no guarantee for the outcome of the memory alignment 
based on the compiler since it is defined as `uint8_t`. So I need to make sure 
we create the scenario that we want to test.




-- 
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