manupa-arm commented on a change in pull request #7785: URL: https://github.com/apache/tvm/pull/7785#discussion_r622139782
########## File path: src/runtime/crt/memory/stack_allocator.c ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// LINT_C_FILE +#include <tvm/runtime/crt/stack_allocator.h> +#ifdef TVM_CRT_STACK_ALLOCATOR_ENABLE_FIFO_CHECK +#include <tvm/runtime/crt/logging.h> +#endif + +void* StackMemoryManager_Allocate(tvm_workspace_t* tvm_runtime_workspace, int32_t nbytes) { + // reserve bytes at the end of the allocation such that + // next_alloc % TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES == 0. + uint32_t offset_bytes = + (TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES - nbytes) & (TVM_RUNTIME_ALLOC_ALIGNMENT_BYTES - 1); + uint8_t* current_alloc = tvm_runtime_workspace->next_alloc; + uint8_t* next_alloc = tvm_runtime_workspace->next_alloc + nbytes + offset_bytes; + uint8_t* workspace_end = tvm_runtime_workspace->workspace + tvm_runtime_workspace->workspace_size; +#ifdef TVM_CRT_STACK_ALLOCATOR_ENABLE_FIFO_CHECK + if (next_alloc + STACK_ALLOCATOR_TAG_SIZE_BYTES > workspace_end) { + return NULL; Review comment: Need to return correct error type as expected by TVMPlatformAllocate -- 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. For queries about this service, please contact Infrastructure at: [email protected]
