MCPcopy Create free account
hub / github.com/MegEngine/MegCC / alloc_tensor_opt

Function alloc_tensor_opt

runtime/src/vm/common.h:11–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "vm.h"
10
11static inline TinyNNStatus alloc_tensor_opt(Tensor* tensor, const RuntimeOpt* opt) {
12 if (tensor->is_dynamic) {
13 size_t length_in_byte = tensor_length_in_byte(tensor);
14 if (!tensor->ptr || tensor->size < length_in_byte) {
15 if (tensor->ptr)
16 opt->device->free(tensor->ptr);
17 tensor->ptr = opt->device->malloc(length_in_byte);
18 tensor->size = length_in_byte;
19 tensor->offset = 0;
20 }
21 } else {
22 LOG_DEBUG("tensor is static, no memory allocated.\n");
23 }
24 return TinyNN_SUCCESS;
25}
26
27static inline DeviceModel* get_active_device_model(VM* vm) {
28 return vm->model->device_models[vm->model->active_device_model_idx];

Callers 2

execute_single_oprFunction · 0.85
alloc_tensorFunction · 0.85

Calls 3

tensor_length_in_byteFunction · 0.85
mallocMethod · 0.80
freeMethod · 0.45

Tested by

no test coverage detected