mehrdadh commented on a change in pull request #8487:
URL: https://github.com/apache/tvm/pull/8487#discussion_r673659054
##########
File path: tests/crt/aot_memory_test.cc
##########
@@ -109,27 +145,50 @@ TEST(AOTMemory, OverAllocate) {
}
/*
- * Test for out-of-order memory deallocation
+ * Test for out-of-order memory deallocation.
*/
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 = memory_align(&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 offset = memory_add_misalignment(&model_memory_ptr);
+ ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory_ptr,
80 - offset),
+ kTvmErrorNoError);
+
+ uint32_t next_alloc_offset =
+ (uintptr_t)tvm_runtime_workspace.next_alloc %
TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES;
+ uint32_t workspace_offset =
+ (uintptr_t)tvm_runtime_workspace.workspace %
TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES;
+ ASSERT_EQ(next_alloc_offset, 0);
+ ASSERT_EQ(workspace_offset, 0);
Review comment:
I think I understood what you mean. PTAL.
--
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]