Skip to content

Remove ET_ALLOCATE_LIST_OR_RETURN_ERROR from all core code for MSVC windows #6502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 47 additions & 22 deletions runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ class BackendDelegate final {
CompileSpec** out_spec) {
auto number_of_compile_specs = compile_specs_in_program->size();

CompileSpec* compile_specs_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
backend_init_context.get_runtime_allocator(),
CompileSpec,
number_of_compile_specs);
CompileSpec* compile_specs_list =
backend_init_context.get_runtime_allocator()->allocateList<CompileSpec>(
number_of_compile_specs);
if (compile_specs_list == nullptr) {
return Error::MemoryAllocationFailed;
}

// Initialize the spec list for each method spec
for (size_t j = 0; j < number_of_compile_specs; j++) {
Expand Down Expand Up @@ -226,8 +228,10 @@ Result<InstructionArgs> gen_instruction_arguments(
EValue* values,
size_t num_args,
const int32_t* arg_idxs) {
EValue** arg_list =
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, EValue*, num_args);
EValue** arg_list = method_allocator->allocateList<EValue*>(num_args);
if (arg_list == nullptr) {
return Error::MemoryAllocationFailed;
}
for (size_t i = 0; i < num_args; ++i) {
int32_t arg_idx = arg_idxs[i];
ET_CHECK_OR_RETURN_ERROR(
Expand Down Expand Up @@ -287,8 +291,10 @@ Error Method::parse_values() {
ET_CHECK_OR_RETURN_ERROR(
flatbuffer_values != nullptr, InvalidProgram, "Missing values");
size_t n_value = flatbuffer_values->size();
values_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
memory_manager_->method_allocator(), EValue, n_value);
values_ = memory_manager_->method_allocator()->allocateList<EValue>(n_value);
if (values_ == nullptr) {
return Error::MemoryAllocationFailed;
}

// n_value_ counts the number of successfully-initialized values for ~Method()
// to clean up, and is incremented at the bottom of the loop. This makes it
Expand Down Expand Up @@ -510,17 +516,23 @@ Error Method::resolve_operator(

// resolve tensor meta
auto method_allocator = memory_manager_->method_allocator();
TensorMeta* meta =
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, TensorMeta, n_args);
TensorMeta* meta = method_allocator->allocateList<TensorMeta>(n_args);
if (meta == nullptr) {
return Error::MemoryAllocationFailed;
}

size_t count = 0;
for (size_t i = 0; i < n_args; i++) {
EValue* eval = args[i];
// handle tensor list as well
if (eval->isTensor()) {
auto tensor = eval->toTensor();
meta[count].dtype_ = tensor.scalar_type();
exec_aten::DimOrderType* dim_order_ptr = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
method_allocator, exec_aten::DimOrderType, tensor.dim());
exec_aten::DimOrderType* dim_order_ptr =
method_allocator->allocateList<exec_aten::DimOrderType>(tensor.dim());
if (dim_order_ptr == nullptr) {
return Error::MemoryAllocationFailed;
}
size_t size = tensor.dim();
err = get_dim_order(tensor, dim_order_ptr, size);
ET_CHECK_OR_RETURN_ERROR(
Expand Down Expand Up @@ -554,8 +566,11 @@ Result<Method> Method::load(
MemoryAllocator* temp_allocator = memory_manager->temp_allocator();
if (temp_allocator == nullptr) {
PlatformMemoryAllocator* platform_allocator =
ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(
memory_manager->method_allocator(), PlatformMemoryAllocator);
memory_manager->method_allocator()
->allocateInstance<PlatformMemoryAllocator>();
if (platform_allocator == nullptr) {
return Error::MemoryAllocationFailed;
}
new (platform_allocator) PlatformMemoryAllocator();
temp_allocator = platform_allocator;
}
Expand Down Expand Up @@ -599,8 +614,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
ET_CHECK_OR_RETURN_ERROR(
delegates != nullptr, InvalidProgram, "Missing delegates field");
size_t n_delegate = delegates->size();
delegates_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
method_allocator, BackendDelegate, n_delegate);
delegates_ = method_allocator->allocateList<BackendDelegate>(n_delegate);
if (delegates_ == nullptr) {
return Error::MemoryAllocationFailed;
}

// n_delegate_ counts the number of successfully-initialized delegates for
// ~Method() to clean up, and is incremented at the bottom of the loop. This
Expand Down Expand Up @@ -628,8 +645,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
ET_CHECK_OR_RETURN_ERROR(
chains != nullptr && chains->size() > 0, InvalidProgram, "No chains");
n_chains_ = chains->size();
chains_ =
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, Chain, n_chains_);
chains_ = method_allocator->allocateList<Chain>(n_chains_);
if (chains_ == nullptr) {
return Error::MemoryAllocationFailed;
}

// Try resolving all operators before failing, to make it easier to debug
// multiple problems at once.
Expand All @@ -644,10 +663,16 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
"Missing instructions in chain %zu",
i);
auto num_instructions = s_instructions->size();
auto chain_instruction_kernels = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
method_allocator, OpFunction, num_instructions);
auto chain_instruction_arg_lists = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
method_allocator, InstructionArgs, num_instructions);
auto chain_instruction_kernels =
method_allocator->allocateList<OpFunction>(num_instructions);
if (chain_instruction_kernels == nullptr) {
return Error::MemoryAllocationFailed;
}
auto chain_instruction_arg_lists =
method_allocator->allocateList<InstructionArgs>(num_instructions);
if (chain_instruction_arg_lists == nullptr) {
return Error::MemoryAllocationFailed;
}

// Set up the argument lists ahead of time and store pointers to them to
// use when the instructions are called
Expand Down
17 changes: 11 additions & 6 deletions runtime/executor/tensor_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ parseListOptionalType(
const flatbuffers::Vector<int32_t>* value_indices,
EValue* values_,
MemoryManager* memory_manager) {
auto* evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
memory_manager->method_allocator(), EValue*, value_indices->size());

auto* optional_tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
memory_manager->method_allocator(),
executorch::aten::optional<T>,
auto* evalp_list = memory_manager->method_allocator()->allocateList<EValue*>(
value_indices->size());
if (evalp_list == nullptr) {
return Error::MemoryAllocationFailed;
}

auto* optional_tensor_list =
memory_manager->method_allocator()
->allocateList<executorch::aten::optional<T>>(value_indices->size());
if (optional_tensor_list == nullptr) {
return Error::MemoryAllocationFailed;
}

size_t output_idx = 0;
// For each index look up the corresponding EValue (which has been
Expand Down
15 changes: 10 additions & 5 deletions runtime/executor/tensor_parser_exec_aten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ ET_NODISCARD Result<BoxedEvalueList<exec_aten::Tensor>> parseTensorList(
MemoryManager* memory_manager) {
EXECUTORCH_SCOPE_PROF("TensorParser::parseTensorList");

auto* tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
memory_manager->method_allocator(),
exec_aten::Tensor,
auto* tensor_list =
memory_manager->method_allocator()->allocateList<exec_aten::Tensor>(
tensor_indices->size());
if (tensor_list == nullptr) {
return Error::MemoryAllocationFailed;
}
auto* evalp_list = memory_manager->method_allocator()->allocateList<EValue*>(
tensor_indices->size());
auto* evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
memory_manager->method_allocator(), EValue*, tensor_indices->size());
if (evalp_list == nullptr) {
return Error::MemoryAllocationFailed;
}

// For each tensor index look up the corresponding Tensor (which has been
// already allocated) and stick it in the list.
Expand Down
Loading