Skip to content

Commit c9f46e2

Browse files
authored
Revert "Make _get_program_from_buffer work for bundled programs" (#14487)
Reverts #14435 `buf_len` and some other variables unused related stuff is breaking a bunch of internal builds
1 parent 42b33c0 commit c9f46e2

File tree

6 files changed

+19
-54
lines changed

6 files changed

+19
-54
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ endif()
738738

739739
if(EXECUTORCH_BUILD_PYBIND)
740740

741+
# Add codegen tools subdirectory for selective_build pybind module
742+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/codegen/tools)
743+
741744
if(NOT EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
742745
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
743746
endif()
@@ -746,9 +749,6 @@ if(EXECUTORCH_BUILD_PYBIND)
746749
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/devtools)
747750
endif()
748751

749-
# Add codegen tools subdirectory for selective_build pybind module
750-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/codegen/tools)
751-
752752
# Create bundled_module target only for pybindings when bundled_program exists
753753
# This target has hard dependencies on devtools generated headers
754754
if(TARGET bundled_program)

codegen/tools/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3-
# Copyright 2025 Arm Limited and/or its affiliates.
43
#
54
# This source code is licensed under the BSD-style license found in the
65
# LICENSE file in the root directory of this source tree.
@@ -29,10 +28,6 @@ target_compile_options(
2928
)
3029

3130
# Link against required libraries
32-
if(TARGET bundled_program)
33-
target_compile_definitions(selective_build PRIVATE -DET_BUNDLE_IO)
34-
target_link_libraries(selective_build PRIVATE bundled_program)
35-
endif()
3631
target_link_libraries(selective_build PRIVATE executorch_core program_schema)
3732

3833
# Install the module

codegen/tools/selective_build.cpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
/*
22
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
* All rights reserved.
4-
* Copyright 2025 Arm Limited and/or its affiliates.
54
*
65
* This source code is licensed under the BSD-style license found in the
76
* LICENSE file in the root directory of this source tree.
87
*/
98

10-
#include <executorch/runtime/platform/assert.h>
11-
#include <executorch/schema/program_generated.h>
129
#include <pybind11/pybind11.h>
1310
#include <pybind11/stl.h>
1411

15-
#ifdef ET_BUNDLE_IO
16-
#include <executorch/devtools/bundled_program/bundled_program.h>
17-
#include <stdexcept>
18-
#endif
12+
#include <executorch/runtime/platform/assert.h>
13+
#include <executorch/schema/program_generated.h>
1914

2015
namespace py = pybind11;
2116

@@ -191,39 +186,8 @@ get_kernel_tensor_metadatas_from_execution_plan(
191186

192187
const executorch_flatbuffer::Program* _get_program_from_buffer(
193188
const py::bytes& buffer) {
194-
// Access the Python bytes without copying and get raw pointer/size.
195-
const std::string_view sv = buffer.cast<std::string_view>();
196-
void* buf_ptr = const_cast<void*>(static_cast<const void*>(sv.data()));
197-
const size_t buf_len = sv.size();
198-
#ifdef ET_BUNDLE_IO
199-
200-
// If this is a bundled program, extract the inner ExecuTorch program bytes.
201-
if (executorch::bundled_program::is_bundled_program(buf_ptr, buf_len)) {
202-
const void* program_data = nullptr;
203-
size_t program_size = 0;
204-
205-
const auto status = executorch::bundled_program::get_program_data(
206-
buf_ptr, // serialized BundledProgram start
207-
buf_len, // total size of the BundledProgram blob
208-
&program_data, // [out] pointer to inner .pte bytes
209-
&program_size // [out] size of inner .pte bytes
210-
);
211-
212-
if (status != ::executorch::runtime::Error::Ok || program_data == nullptr ||
213-
program_size == 0) {
214-
throw std::runtime_error(
215-
"bundled_program::get_program_data() failed or returned empty data");
216-
}
217-
218-
// program_data points directly at the flatbuffer-encoded Program region.
219-
return executorch_flatbuffer::GetProgram(
220-
reinterpret_cast<const uint8_t*>(program_data));
221-
}
222-
#endif
223-
// Otherwise treat the buffer as a raw .pte (flatbuffer Program with optional
224-
// extended header).
225189
return executorch_flatbuffer::GetProgram(
226-
reinterpret_cast<const uint8_t*>(sv.data()));
190+
buffer.cast<std::string_view>().data());
227191
}
228192

229193
py::list _get_program_operators(const executorch_flatbuffer::Program* program) {

docs/source/backends-arm-ethos-u.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ You can see how this coupling between the memory mode and runtime application i
268268

269269
The arm_executor_runner supports [bundled-io](https://docs.pytorch.org/executorch/0.4/bundled-io.html) and [ETdump](https://docs.pytorch.org/executorch/stable/etdump.html) debugging tools.
270270

271-
To enable bundled-io, set `EXECUTORCH_BUILD_DEVTOOLS` when building Executorch and `DET_BUNDLE_IO` when building the executor_runner. To enable ETdump, set `EXECUTORCH_BUILD_ARM_ETDUMP` when building Executorch and `DEXECUTORCH_ENABLE_EVENT_TRACER`
271+
To enable bundled-io, set `EXECUTORCH_BUILD_DEVTOOLS` when building Executorch and `DET_BUNDLE_IO` when building the executor_runner. Currently using bundled-io requires specifying your
272+
non delegated Aten ops manually by setting `EXECUTORCH_SELECT_OPS_LIST`. To enable ETdump, set `EXECUTORCH_BUILD_ARM_ETDUMP` when building Executorch and `DEXECUTORCH_ENABLE_EVENT_TRACER`
272273
when building the executor_runner.
273274

274275

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ list(
235235
-Map=arm_executor_runner.map
236236
)
237237

238-
# Figure out which ops to include: For semihosting build, use
239-
# (user-set)SELECT_OPS_MODEL variable. For normal build, use
240-
# EXECUTORCH_SELECT_OPS_MODEL to include ops automatically. If the pte contains
241-
# no undelegated ops, use neither.
238+
# Prefer to generate kernel bindings from model file if possible, which is when
239+
# 1. Not building for semihosting 2. Not building with bundleio If that is not
240+
# the case, fallback to select_ops_list If the model file does not contain any
241+
# aten ops, a workaround is currently needed to avoid crashing.
242242
execute_process(
243243
COMMAND
244244
python "${ET_DIR_PATH}/codegen/tools/gen_oplist.py"
@@ -264,6 +264,11 @@ elseif(${FOUND_OPS_IN_FILE})
264264
message(
265265
"gen_oplist: EXECUTORCH_SELECT_OPS_MODEL=${ET_PTE_FILE_PATH} is used to auto generate ops from"
266266
)
267+
elseif(NOT ${FOUND_OPS_IN_FILE} AND ${ET_BUNDLE_IO})
268+
set(EXECUTORCH_SELECT_OPS_MODEL "")
269+
message(
270+
"gen_oplist: Building with ET_BUNDLE_IO and .bpte is not supported to auto generate ops from will use EXECUTORCH_SELECT_OPS_LIST=${EXECUTORCH_SELECT_OPS_LIST}"
271+
)
267272
else()
268273
set(EXECUTORCH_SELECT_OPS_LIST "")
269274
set(EXECUTORCH_SELECT_OPS_MODEL "")

examples/arm/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function help() {
5353
echo " --no_delegate Do not delegate the model (can't override builtin models)"
5454
echo " --no_quantize Do not quantize the model (can't override builtin models)"
5555
echo " --portable_kernels=<OPS> TO BE DEPRECATED: Alias to select_ops_list."
56-
echo " --select_ops_list=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${select_ops_list}"
57-
echo " NOTE: This is only used when building for semihosting."
56+
echo " --select_ops_list=<OPS> Comma separated list of portable (non delegated) kernels to include Default: ${select_ops_list}"
57+
echo " NOTE: This is used when select_ops_model is not possible to use, e.g. for semihosting or bundleio."
5858
echo " See https://docs.pytorch.org/executorch/stable/kernel-library-selective-build.html for more information."
5959
echo " --target=<TARGET> Target to build and run for Default: ${target}"
6060
echo " --output=<FOLDER> Target build output folder Default: ${output_folder}"

0 commit comments

Comments
 (0)