Skip to content

Remove torch:: references from devtools/example_runner #5495

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

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 28 additions & 17 deletions examples/devtools/example_runner/example_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@ DEFINE_int32(
262144, // 256 KB
"Size of the debug buffer in bytes to allocate for intermediate outputs and program outputs logging.");

using namespace torch::executor;
using executorch::etdump::ETDumpGen;
using executorch::etdump::ETDumpResult;
using executorch::extension::BufferDataLoader;
using executorch::runtime::Error;
using executorch::runtime::EValue;
using executorch::runtime::EventTracerDebugLogLevel;
using executorch::runtime::HierarchicalAllocator;
using executorch::runtime::MemoryAllocator;
using executorch::runtime::MemoryManager;
using executorch::runtime::Method;
using executorch::runtime::MethodMeta;
using executorch::runtime::Program;
using executorch::runtime::Result;
using executorch::runtime::Span;

std::vector<uint8_t> load_file_or_die(const char* path) {
std::ifstream file(path, std::ios::binary | std::ios::ate);
Expand All @@ -90,7 +103,7 @@ std::vector<uint8_t> load_file_or_die(const char* path) {
}

int main(int argc, char** argv) {
runtime_init();
executorch::runtime::runtime_init();

gflags::ParseCommandLineFlags(&argc, &argv, true);
if (argc != 1) {
Expand All @@ -109,19 +122,18 @@ int main(int argc, char** argv) {
// Find the offset to the embedded Program.
const void* program_data;
size_t program_data_len;
Error status = torch::executor::bundled_program::GetProgramData(
Error status = executorch::bundled_program::get_program_data(
reinterpret_cast<void*>(file_data.data()),
file_data.size(),
&program_data,
&program_data_len);
ET_CHECK_MSG(
status == Error::Ok,
"GetProgramData() failed on file '%s': 0x%x",
"get_program_data() failed on file '%s': 0x%x",
bundled_program_path,
(unsigned int)status);

auto buffer_data_loader =
util::BufferDataLoader(program_data, program_data_len);
auto buffer_data_loader = BufferDataLoader(program_data, program_data_len);

// Parse the program file. This is immutable, and can also be reused
// between multiple execution invocations across multiple threads.
Expand Down Expand Up @@ -202,7 +214,7 @@ int main(int argc, char** argv) {
// the method can mutate the memory-planned buffers, so the method should only
// be used by a single thread at at time, but it can be reused.
//
torch::executor::ETDumpGen etdump_gen = torch::executor::ETDumpGen();
ETDumpGen etdump_gen;
Result<Method> method =
program->load_method(method_name, &memory_manager, &etdump_gen);
ET_CHECK_MSG(
Expand All @@ -225,7 +237,7 @@ int main(int argc, char** argv) {
EventTracerDebugLogLevel::kProgramOutputs);
}
// Use the inputs embedded in the bundled program.
status = torch::executor::bundled_program::LoadBundledInput(
status = executorch::bundled_program::load_bundled_input(
*method, file_data.data(), FLAGS_testset_idx);
ET_CHECK_MSG(
status == Error::Ok,
Expand Down Expand Up @@ -262,7 +274,7 @@ int main(int argc, char** argv) {

// Dump the etdump data containing profiling/debugging data to the specified
// file.
etdump_result result = etdump_gen.get_etdump_data();
ETDumpResult result = etdump_gen.get_etdump_data();
if (result.buf != nullptr && result.size > 0) {
FILE* f = fopen(FLAGS_etdump_path.c_str(), "w+");
fwrite((uint8_t*)result.buf, 1, result.size, f);
Expand All @@ -272,14 +284,13 @@ int main(int argc, char** argv) {

if (FLAGS_output_verification) {
// Verify the outputs.
status =
torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput(
*method,
file_data.data(),
FLAGS_testset_idx,
1e-3, // rtol
1e-5 // atol
);
status = executorch::bundled_program::verify_method_outputs(
*method,
file_data.data(),
FLAGS_testset_idx,
1e-3, // rtol
1e-5 // atol
);
ET_CHECK_MSG(
status == Error::Ok,
"Bundle verification failed with status 0x%" PRIx32,
Expand Down
Loading