Removing iree-run-trace/iree-benchmark-trace tools.
diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index 833919c..97b31a6 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel
@@ -41,26 +41,6 @@ ) iree_runtime_cc_binary( - name = "iree-benchmark-trace", - srcs = ["iree-benchmark-trace-main.c"], - deps = [ - "//runtime/src/iree/base", - "//runtime/src/iree/base/internal:atomic_slist", - "//runtime/src/iree/base/internal:file_io", - "//runtime/src/iree/base/internal:flags", - "//runtime/src/iree/base/internal:path", - "//runtime/src/iree/hal", - "//runtime/src/iree/testing:benchmark", - "//runtime/src/iree/tooling:device_util", - "//runtime/src/iree/tooling:trace_replay", - "//runtime/src/iree/tooling:vm_util", - "//runtime/src/iree/tooling:yaml_util", - "//runtime/src/iree/vm", - "@com_github_yaml_libyaml//:yaml", - ], -) - -iree_runtime_cc_binary( name = "iree-check-module", testonly = True, srcs = ["iree-check-module-main.cc"], @@ -224,23 +204,6 @@ ) iree_runtime_cc_binary( - name = "iree-run-trace", - srcs = ["iree-run-trace-main.c"], - deps = [ - "//runtime/src/iree/base", - "//runtime/src/iree/base/internal:flags", - "//runtime/src/iree/base/internal:path", - "//runtime/src/iree/hal", - "//runtime/src/iree/tooling:device_util", - "//runtime/src/iree/tooling:trace_replay", - "//runtime/src/iree/tooling:vm_util", - "//runtime/src/iree/tooling:yaml_util", - "//runtime/src/iree/vm", - "@com_github_yaml_libyaml//:yaml", - ], -) - -iree_runtime_cc_binary( name = "iree-e2e-matmul-test", srcs = ["iree-e2e-matmul-test.c"], deps = [
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index ed3453e..02cd782 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt
@@ -76,30 +76,7 @@ iree::tooling::device_util iree::tooling::vm_util iree::vm - INSTALL_COMPONENT IREETools-Runtime -) - -iree_cc_binary( - NAME - iree-benchmark-trace - SRCS - "iree-benchmark-trace-main.c" - DEPS - iree::base - iree::base::internal::atomic_slist - iree::base::internal::file_io - iree::base::internal::flags - iree::base::internal::path - iree::hal - iree::modules::hal - iree::testing::benchmark - iree::tooling::device_util - iree::tooling::trace_replay - iree::tooling::vm_util - iree::tooling::yaml_util - iree::vm - yaml - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) iree_cc_binary( @@ -136,7 +113,7 @@ iree::io::parameter_index iree::io::scope_map iree::tooling::parameter_util - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) iree_cc_binary( @@ -148,7 +125,7 @@ iree::base iree::base::internal::cpu iree::schemas::cpu_data - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) iree_cc_binary( @@ -165,7 +142,7 @@ iree::io::parameter_index iree::io::scope_map iree::io::stream - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) iree_cc_binary( @@ -180,7 +157,7 @@ iree::base::internal::flatcc::parsing iree::schemas::instruments iree::schemas::instruments::dispatch_def_c_fbs - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) iree_cc_binary( @@ -197,7 +174,7 @@ iree::base::internal::flatcc::parsing iree::schemas::bytecode_module_def_c_fbs iree::vm::bytecode::module - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) iree_cc_binary( @@ -212,7 +189,7 @@ iree::io::parameter_index iree::io::scope_map iree::tooling::parameter_util - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) # Only enable fatelf tool when we're compiling it in. @@ -230,7 +207,7 @@ iree::base::internal::file_io iree::base::internal::path iree::hal::local::elf::elf_module - INSTALL_COMPONENT IREETools-Runtime + INSTALL_COMPONENT IREETools-Runtime ) endif() # IREE_HAL_EXECUTABLE_*_EMBEDDED_ELF @@ -251,26 +228,6 @@ iree_cc_binary( NAME - iree-run-trace - SRCS - "iree-run-trace-main.c" - DEPS - iree::base - iree::base::internal::flags - iree::base::internal::path - iree::hal - iree::modules::hal - iree::tooling::device_util - iree::tooling::trace_replay - iree::tooling::vm_util - iree::tooling::yaml_util - iree::vm - yaml - INSTALL_COMPONENT IREETools-Runtime -) - -iree_cc_binary( - NAME iree-e2e-matmul-test SRCS "iree-e2e-matmul-test.c"
diff --git a/tools/iree-benchmark-trace-main.c b/tools/iree-benchmark-trace-main.c deleted file mode 100644 index 5920714..0000000 --- a/tools/iree-benchmark-trace-main.c +++ /dev/null
@@ -1,310 +0,0 @@ -// Copyright 2021 The IREE Authors -// -// Licensed under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -// DISCLAIMER: this is leaky under error conditions as it's a benchmark tool and -// not a correctness test. - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "iree/base/api.h" -#include "iree/base/internal/file_io.h" -#include "iree/base/internal/flags.h" -#include "iree/base/internal/path.h" -#include "iree/hal/api.h" -#include "iree/testing/benchmark.h" -#include "iree/tooling/device_util.h" -#include "iree/tooling/trace_replay.h" -#include "iree/tooling/vm_util.h" -#include "iree/tooling/yaml_util.h" -#include "iree/vm/api.h" - -IREE_FLAG(bool, capture_stdin, false, - "Captures stdin up to EOF on startup to use during trace execution."); - -IREE_FLAG(bool, print_statistics, false, - "Prints runtime statistics to stderr on exit."); - -IREE_FLAG(bool, reuse_devices, true, - "Only creates a HAL device once and reuses it for all iterations."); -IREE_FLAG(bool, reuse_modules, true, - "Only loads modules once and reuses them for all iterations."); - -IREE_FLAG_LIST( - string, input, - "An input (a) value or (b) buffer of the format:\n" - " (a) scalar value\n" - " value\n" - " e.g.: --input=\"3.14\"\n" - " (b) buffer:\n" - " [shape]xtype=[value]\n" - " e.g.: --input=\"2x2xi32=1 2 3 4\"\n" - "Optionally, brackets may be used to separate the element values:\n" - " 2x2xi32=[[1 2][3 4]]\n" - "Raw binary files can be read to provide buffer contents:\n" - " 2x2xi32=@some/file.bin\n" - "\n" - "Numpy npy files from numpy.save can be read to provide 1+ values:\n" - " @some.npy\n" - "\n" - "Each occurrence of the flag indicates an input in the order they were\n" - "specified on the command line."); - -// Global state shared across all benchmarks and iterations. -// Immutable and thread-safe (so much as anything contained within is). -typedef struct iree_replay_benchmark_globals_t { - // Shared VM instance. Unowned; callers must retain for the valid lifetime of - // the registration. - iree_vm_instance_t* instance; - // Entire contents of stdin as read on startup. - // This allows repeated benchmark calls to consume stdin. - // Only captured if --capture_stdin is passed. - iree_const_byte_span_t stdin_contents; -} iree_replay_benchmark_globals_t; - -// A benchmark registration for each file to run. -typedef struct iree_replay_benchmark_registration_t { - iree_benchmark_def_t benchmark_def; // Must be first. - // Used for relative file path lookup when referencing files in the trace. - iree_string_view_t root_path; - // Trace file path. - iree_string_view_t file_path; - // Global state shared across all benchmarks and iterations. - const iree_replay_benchmark_globals_t* globals; -} iree_replay_benchmark_registration_t; - -IREE_TRACE(static const char* IREE_REPLAY_ACTIVE_PLOT_ID = "Timing Active"); - -static iree_status_t iree_replay_benchmark_call_before( - void* user_data, iree_trace_replay_t* replay, yaml_document_t* document, - yaml_node_t* event_node, iree_vm_function_t function, - iree_vm_list_t* input_list) { - iree_benchmark_state_t* benchmark_state = (iree_benchmark_state_t*)user_data; - IREE_TRACE_PLOT_VALUE_I64(IREE_REPLAY_ACTIVE_PLOT_ID, 1); - iree_benchmark_resume_timing(benchmark_state); - return iree_ok_status(); -} - -static iree_status_t iree_replay_benchmark_call_after( - void* user_data, iree_trace_replay_t* replay, yaml_document_t* document, - yaml_node_t* event_node, iree_vm_function_t function, - iree_vm_list_t* output_list) { - iree_benchmark_state_t* benchmark_state = (iree_benchmark_state_t*)user_data; - iree_benchmark_pause_timing(benchmark_state); - IREE_TRACE_PLOT_VALUE_I64(IREE_REPLAY_ACTIVE_PLOT_ID, 0); - return iree_ok_status(); -} - -static iree_status_t iree_replay_benchmark_run_documents( - iree_trace_replay_t* replay, FILE* file, - iree_benchmark_state_t* benchmark_state) { - // One-pass parsing through the file. - yaml_parser_t parser; - if (!yaml_parser_initialize(&parser)) { - return iree_make_status(IREE_STATUS_INTERNAL, - "yaml_parser_initialize failed"); - } - yaml_parser_set_input_file(&parser, file); - - bool have_parsed_inputs = false; - iree_status_t status = iree_ok_status(); - for (bool document_eof = false; !document_eof;) { - // Parse the subdocument event. - IREE_TRACE_ZONE_BEGIN_NAMED(z_load, "yaml_parser_load"); - yaml_document_t document; - bool did_load = yaml_parser_load(&parser, &document); - IREE_TRACE_ZONE_END(z_load); - if (!did_load) { - status = iree_status_from_yaml_parser_error(&parser); - break; - } - - // Execute the event or handle EOF (empty document). - yaml_node_t* event_node = yaml_document_get_root_node(&document); - if (event_node) { - status = iree_trace_replay_event(replay, &document, event_node); - } else { - document_eof = true; - } - - // Reclaim subdocument resources before moving on to the next. - IREE_TRACE_ZONE_BEGIN_NAMED(z_delete, "yaml_document_delete"); - yaml_document_delete(&document); - IREE_TRACE_ZONE_END(z_delete); - - // If the event created a device and we haven't yet performed our input - // loading we can do that now before processing subsequent events. - if (iree_status_is_ok(status) && !have_parsed_inputs && replay->device) { - status = iree_tooling_parse_into_variant_list( - replay->device, iree_hal_device_allocator(replay->device), - FLAG_input_list().values, FLAG_input_list().count, - replay->host_allocator, replay->inputs); - have_parsed_inputs = true; - } - - if (!iree_status_is_ok(status)) break; - } - - yaml_parser_delete(&parser); - - return status; -} - -// Benchmark function that runs a trace file. -static iree_status_t iree_replay_benchmark_run_file( - const iree_benchmark_def_t* benchmark_def, - iree_benchmark_state_t* benchmark_state) { - const iree_replay_benchmark_registration_t* registration = - (const iree_replay_benchmark_registration_t*)benchmark_def->user_data; - const iree_replay_benchmark_globals_t* globals = registration->globals; - - iree_trace_replay_flags_t replay_flags = IREE_TRACE_REPLAY_FLAG_NONE; - if (FLAG_print_statistics) { - replay_flags |= IREE_TRACE_REPLAY_FLAG_PRINT_STATISTICS; - } - if (FLAG_reuse_devices) { - replay_flags |= IREE_TRACE_REPLAY_FLAG_REUSE_DEVICES; - } - if (FLAG_reuse_modules) { - replay_flags |= IREE_TRACE_REPLAY_FLAG_REUSE_MODULES; - } - - // Setup replay state used for this benchmark. - iree_trace_replay_t replay; - IREE_RETURN_IF_ERROR(iree_trace_replay_initialize( - registration->root_path, globals->instance, replay_flags, - IREE_VM_CONTEXT_FLAG_NONE, iree_hal_available_driver_registry(), - iree_allocator_system(), &replay)); - replay.stdin_contents = globals->stdin_contents; - - // Hook into all calls processed during the trace so we can time them. - replay.call_hooks.user_data = benchmark_state; - replay.call_hooks.before = iree_replay_benchmark_call_before; - replay.call_hooks.after = iree_replay_benchmark_call_after; - - // Query device overrides, if any. When omitted the devices from the trace - // file will be used. - iree_trace_replay_set_hal_devices_override(&replay, - iree_hal_device_flag_list()); - - // Open trace YAML file from the given file_path. - FILE* file = fopen(registration->file_path.data, "rb"); - if (!file) { - return iree_make_status( - iree_status_code_from_errno(errno), "failed to open trace file '%.*s'", - (int)registration->file_path.size, registration->file_path.data); - } - - // Call the functions within the trace in order. - while (iree_benchmark_keep_running(benchmark_state, - /*batch_count=*/1)) { - // Pause timing that was started automatically. We'll resume/pause around - // each call. - // TODO(benvanik): see if we can tell benchmark to start paused? - iree_benchmark_pause_timing(benchmark_state); - - // Clear replay state. - iree_trace_replay_reset(&replay); - - // Run all events in the document from start to end. - IREE_RETURN_IF_ERROR( - iree_replay_benchmark_run_documents(&replay, file, benchmark_state)); - - // Reset file back to the start. - fseek(file, 0, SEEK_SET); - - // Resume before looping because keep_running requires it. - iree_benchmark_resume_timing(benchmark_state); - } - - iree_trace_replay_deinitialize(&replay); - return iree_ok_status(); -} - -// Registers benchmarks for each trace file. -static void iree_replay_benchmark_register_trace_files( - int file_count, char** file_paths, - const iree_replay_benchmark_globals_t* globals) { - static iree_replay_benchmark_registration_t* registrations = NULL; - if (!registrations) free(registrations); - registrations = (iree_replay_benchmark_registration_t*)malloc( - file_count * sizeof(iree_replay_benchmark_registration_t)); - - for (int i = 0; i < file_count; ++i) { - iree_string_view_t file_path = iree_make_cstring_view(file_paths[i]); - registrations[i].root_path = iree_file_path_dirname(file_path); - registrations[i].file_path = file_path; - registrations[i].globals = globals; - registrations[i].benchmark_def = (iree_benchmark_def_t){ - .flags = IREE_BENCHMARK_FLAG_MEASURE_PROCESS_CPU_TIME | - IREE_BENCHMARK_FLAG_USE_REAL_TIME, - .time_unit = IREE_BENCHMARK_UNIT_MILLISECOND, - .minimum_duration_ns = 0, - .iteration_count = 0, - .run = iree_replay_benchmark_run_file, - .user_data = ®istrations[i], - }; - iree_benchmark_register(iree_file_path_stem(file_path), - ®istrations[i].benchmark_def); - } -} - -int main(int argc, char** argv) { - IREE_TRACE_APP_ENTER(); - - iree_allocator_t host_allocator = iree_allocator_system(); - - // Pass through flags to benchmark (allowing --help to fall through). - iree_flags_set_usage( - "iree-benchmark-trace", - "Benchmarks a YAML trace file. See iree-run-trace for general usage."); - iree_flags_parse_checked(IREE_FLAGS_PARSE_MODE_UNDEFINED_OK | - IREE_FLAGS_PARSE_MODE_CONTINUE_AFTER_HELP, - &argc, &argv); - iree_benchmark_initialize(&argc, argv); - if (argc <= 1) { - fprintf(stderr, - "no trace files provided; pass one or more yaml file paths"); - IREE_TRACE_APP_EXIT(EXIT_FAILURE); - return EXIT_FAILURE; - } - - // Used when tracing to display benchmark state. - IREE_TRACE_SET_PLOT_TYPE(IREE_REPLAY_ACTIVE_PLOT_ID, - IREE_TRACING_PLOT_TYPE_NUMBER, - /*step=*/true, /*fill=*/true, /*color=*/0); - - // Setup shared instance used for each benchmark. - iree_vm_instance_t* instance = NULL; - IREE_CHECK_OK(iree_vm_instance_create(IREE_VM_TYPE_CAPACITY_DEFAULT, - host_allocator, &instance)); - - // Parse all of stdin right away. The traces we run may source things from it - // and because we're running in a benchmark loop it'll quickly drain. To - // ensure every iteration of every benchmark gets the same input we retain it. - iree_file_contents_t* stdin_contents = NULL; - if (FLAG_capture_stdin) { - fprintf(stderr, "Capturing stdin contents at startup...\n"); - IREE_CHECK_OK(iree_stdin_read_contents(host_allocator, &stdin_contents)); - fprintf(stderr, "Captured %" PRIhsz " bytes of stdin content\n", - stdin_contents->const_buffer.data_length); - } - - // Register a benchmark per file provided and run them. - iree_replay_benchmark_globals_t globals = { - .instance = instance, - .stdin_contents = stdin_contents ? stdin_contents->const_buffer - : iree_const_byte_span_empty(), - }; - iree_replay_benchmark_register_trace_files(argc - 1, argv + 1, &globals); - iree_benchmark_run_specified(); - - iree_file_contents_free(stdin_contents); - iree_vm_instance_release(instance); - IREE_TRACE_APP_EXIT(EXIT_SUCCESS); - return EXIT_SUCCESS; -}
diff --git a/tools/iree-run-trace-main.c b/tools/iree-run-trace-main.c deleted file mode 100644 index 4bca457..0000000 --- a/tools/iree-run-trace-main.c +++ /dev/null
@@ -1,396 +0,0 @@ -// Copyright 2021 The IREE Authors -// -// Licensed under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "iree/base/api.h" -#include "iree/base/internal/flags.h" -#include "iree/base/internal/path.h" -#include "iree/hal/api.h" -#include "iree/tooling/device_util.h" -#include "iree/tooling/trace_replay.h" -#include "iree/tooling/vm_util.h" -#include "iree/tooling/yaml_util.h" -#include "iree/vm/api.h" - -IREE_FLAG(bool, trace_execution, false, "Traces VM execution to stderr."); - -IREE_FLAG(bool, print_statistics, false, - "Prints runtime statistics to stderr on exit."); - -IREE_FLAG(bool, print_calls, false, "Prints all I/O for each call to stdout."); -IREE_FLAG(bool, print_call_inputs, false, - "Prints all inputs for each call before they are made to stdout."); -IREE_FLAG(bool, print_call_outputs, false, - "Prints all outputs for each call after they are made to stdout."); - -IREE_FLAG_LIST( - string, input, - "An input (a) value or (b) buffer of the format:\n" - " (a) scalar value\n" - " value\n" - " e.g.: --input=\"3.14\"\n" - " (b) buffer:\n" - " [shape]xtype=[value]\n" - " e.g.: --input=\"2x2xi32=1 2 3 4\"\n" - "Optionally, brackets may be used to separate the element values:\n" - " 2x2xi32=[[1 2][3 4]]\n" - "Raw binary files can be read to provide buffer contents:\n" - " 2x2xi32=@some/file.bin\n" - "\n" - "Numpy npy files from numpy.save can be read to provide 1+ values:\n" - " @some.npy\n" - "\n" - "Each occurrence of the flag indicates an input in the order they were\n" - "specified on the command line."); - -IREE_FLAG_LIST( - string, output, - "Specifies how to handle an output from the invocation:\n" - " `` (empty): ignore output\n" - " e.g.: --output=\n" - " `-`: print textual form to stdout\n" - " e.g.: --output=-\n" - " `@file.npy`: create/overwrite a numpy npy file and write buffer view\n" - " e.g.: --output=@file.npy\n" - " `+file.npy`: create/append a numpy npy file and write buffer view\n" - " e.g.: --output=+file.npy\n" - "\n" - "Numpy npy files can be read in Python using numpy.load, for example an\n" - "invocation producing two outputs can be concatenated as:\n" - " --output=@file.npy --output=+file.npy\n" - "And then loaded in Python by reading from the same file:\n" - " with open('file.npy', 'rb') as f:\n" - " print(numpy.load(f))\n" - " print(numpy.load(f))\n" - "\n" - "Each occurrence of the flag indicates an output in the order they were\n" - "specified on the command line."); - -IREE_FLAG_LIST(string, expected_output, - "An expected function output following the same format as " - "--input. When present the results of the " - "invocation will be compared against these values and the " - "tool will return non-zero if any differ. If the value of a " - "particular output is not of interest provide `(ignored)`."); - -IREE_FLAG(int32_t, output_max_element_count, 1024, - "Prints up to the maximum number of elements of output tensors, " - "eliding the remainder."); - -static iree_status_t iree_trace_replay_call_before(void* user_data, - iree_trace_replay_t* replay, - yaml_document_t* document, - yaml_node_t* event_node, - iree_vm_function_t function, - iree_vm_list_t* input_list) { - if (FLAG_print_calls || FLAG_print_call_inputs) { - iree_string_view_t function_name = iree_vm_function_name(&function); - fprintf(stdout, "--- CALL[%.*s] ---\n", (int)function_name.size, - function_name.data); - IREE_RETURN_IF_ERROR(iree_tooling_variant_list_fprint( - IREE_SV("arg"), input_list, - (iree_host_size_t)FLAG_output_max_element_count, stdout)); - } - return iree_ok_status(); -} - -static iree_status_t iree_trace_replay_call_after(void* user_data, - iree_trace_replay_t* replay, - yaml_document_t* document, - yaml_node_t* event_node, - iree_vm_function_t function, - iree_vm_list_t* output_list) { - if (FLAG_print_calls || FLAG_print_call_outputs) { - if (!FLAG_print_calls && !FLAG_print_call_inputs) { - iree_string_view_t function_name = iree_vm_function_name(&function); - fprintf(stdout, "--- CALL[%.*s] ---\n", (int)function_name.size, - function_name.data); - } - IREE_RETURN_IF_ERROR(iree_tooling_variant_list_fprint( - IREE_SV("result"), output_list, - (iree_host_size_t)FLAG_output_max_element_count, stdout)); - } - return iree_ok_status(); -} - -// Runs the trace in |file| using |root_path| as the base for any path lookups -// required for external files referenced in |file|. -static iree_status_t iree_run_trace_file(iree_string_view_t root_path, - FILE* file, - iree_vm_instance_t* instance) { - iree_trace_replay_flags_t replay_flags = IREE_TRACE_REPLAY_FLAG_NONE; - if (FLAG_print_statistics) { - replay_flags |= IREE_TRACE_REPLAY_FLAG_PRINT_STATISTICS; - } - - iree_vm_context_flags_t context_flags = IREE_VM_CONTEXT_FLAG_NONE; - if (FLAG_trace_execution) { - context_flags |= IREE_VM_CONTEXT_FLAG_TRACE_EXECUTION; - } - - iree_trace_replay_t replay; - IREE_RETURN_IF_ERROR(iree_trace_replay_initialize( - root_path, instance, replay_flags, context_flags, - iree_hal_available_driver_registry(), iree_allocator_system(), &replay)); - - // Hook into all calls processed during the trace. - replay.call_hooks.user_data = NULL; - replay.call_hooks.before = iree_trace_replay_call_before; - replay.call_hooks.after = iree_trace_replay_call_after; - - // Query device overrides, if any. When omitted the devices from the trace - // file will be used. - iree_trace_replay_set_hal_devices_override(&replay, - iree_hal_device_flag_list()); - - yaml_parser_t parser; - if (!yaml_parser_initialize(&parser)) { - iree_trace_replay_deinitialize(&replay); - return iree_make_status(IREE_STATUS_INTERNAL, - "yaml_parser_initialize failed"); - } - yaml_parser_set_input_file(&parser, file); - - bool have_parsed_inputs = false; - iree_status_t status = iree_ok_status(); - for (bool document_eof = false; !document_eof;) { - // Parse the subdocument event. - yaml_document_t document; - if (!yaml_parser_load(&parser, &document)) { - status = iree_status_from_yaml_parser_error(&parser); - break; - } - - // Execute the event or handle EOF (empty document). - yaml_node_t* event_node = yaml_document_get_root_node(&document); - if (event_node) { - status = iree_trace_replay_event(&replay, &document, event_node); - } else { - document_eof = true; - } - - // Reclaim subdocument resources before moving on to the next. - yaml_document_delete(&document); - if (!iree_status_is_ok(status)) break; - - // If the event created a device and we haven't yet performed our input - // loading we can do that now before processing subsequent events. - if (!have_parsed_inputs && replay.device) { - status = iree_tooling_parse_into_variant_list( - replay.device, iree_hal_device_allocator(replay.device), - FLAG_input_list().values, FLAG_input_list().count, - replay.host_allocator, replay.inputs); - have_parsed_inputs = true; - } - if (!iree_status_is_ok(status)) break; - } - - yaml_parser_delete(&parser); - - // Transfer outputs to the host so they can be processed. - if (iree_status_is_ok(status) && replay.device != NULL) { - iree_hal_buffer_params_t target_params = { - .usage = IREE_HAL_BUFFER_USAGE_TRANSFER | IREE_HAL_BUFFER_USAGE_MAPPING, - .access = IREE_HAL_MEMORY_ACCESS_ALL, - .type = IREE_HAL_MEMORY_TYPE_HOST_LOCAL | - IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE, - .queue_affinity = IREE_HAL_QUEUE_AFFINITY_ANY, - .min_alignment = 0, - }; - status = iree_tooling_transfer_variant_list( - replay.device, replay.outputs, iree_hal_device_allocator(replay.device), - target_params, /*wait_fence=*/NULL, /*signal_fence=*/NULL); - } - - // Optionally process outputs from the replay session. - if (iree_status_is_ok(status)) { - if (FLAG_output_list().count == 0) { - IREE_RETURN_IF_ERROR( - iree_tooling_variant_list_fprint( - IREE_SV("output"), replay.outputs, - (iree_host_size_t)FLAG_output_max_element_count, stdout), - "printing results"); - } else { - IREE_RETURN_IF_ERROR( - iree_tooling_output_variant_list( - replay.outputs, FLAG_output_list().values, - FLAG_output_list().count, - (iree_host_size_t)FLAG_output_max_element_count, stdout), - "outputting results"); - } - } - - iree_trace_replay_deinitialize(&replay); - return status; -} - -// Runs each of the given traces files sequentially in isolated contexts. -static iree_status_t iree_run_trace_files(int file_count, char** file_paths, - iree_vm_instance_t* instance) { - for (int i = 0; i < file_count; ++i) { - iree_string_view_t file_path = iree_make_cstring_view(file_paths[i]); - iree_string_view_t root_path = iree_file_path_dirname(file_path); - FILE* file = fopen(file_paths[i], "rb"); - if (!file) { - return iree_make_status(iree_status_code_from_errno(errno), - "failed to open trace file '%.*s'", - (int)file_path.size, file_path.data); - } - iree_status_t status = iree_run_trace_file(root_path, file, instance); - fclose(file); - IREE_RETURN_IF_ERROR(status, "replaying trace file '%.*s'", - (int)file_path.size, file_path.data); - } - return iree_ok_status(); -} - -int main(int argc, char** argv) { - IREE_TRACE_APP_ENTER(); - - iree_flags_set_usage( - "iree-run-trace", - "Executes a YAML trace file containing a sequence of context operations\n" - "and calls represented as subdocuments.\n" - "\n" - "Example loading a bytecode module and calling a function:\n" - "\n" - "```yaml\n" - "type: context_load\n" - "---\n" - "type: module_load\n" - "module:\n" - " type: buildin\n" - " name: hal\n" - "---\n" - "type: module_load\n" - "module:\n" - " type: bytecode\n" - " path: ../build/some_module.vmfb\n" - " mmap: true\n" - "---\n" - "type: call\n" - "function: module.mul\n" - "args:\n" - "- !input.take 0\n" - "- !input.take 1\n" - "results:\n" - "- !output.push\n" - "- !output.push\n" - "```\n" - "\n" - "This can be invoked like iree-run-module specifying inputs/outputs:\n" - " iree-run-trace trace.yml \\\n" - " --device=local-sync \\\n" - " --input=4xf32=0,1,2,3,4 \\\n" - " --input=@input1.npy \\\n" - " --output=@outputs.npy \\\n" - " --output=+outputs.npy\n" - "\n" - "In addition to `--input=`/`--output=` flag access a user-defined\n" - "blackboard exists for preserving temporary values used within the\n" - "trace. Blackboard slots are defined by ordinal and they can be used\n" - "in any context and input/output can be, `!blackboard.get` instead of\n" - "`!input.get` and `!blackboard.set` instead of `!output.set`.\n" - "\n" - "--- Events ---\n" - "\n" - "`type: context_load`\n" - "Loads an empty VM context with no modules registered.\n" - "\n" - "`type: module_load`\n" - "Loads a module into the current context. Modules may either be\n" - "`builtin` (compiled into the binary) or dynamically-loaded `bytecode`.\n" - "\n" - "`type: blackboard_clear`\n" - "Clears the contents of the blackboard and resets it to 0 elements.\n" - "\n" - "`type: assign`\n" - "Assigns sources from a `from` sequence to targets in a `to` sequence.\n" - "Equivalent to an identity function call and can be used to move\n" - "between inputs, outputs, and the blackboard.\n" - "\n" - "`type: numpy_load`\n" - "Loads one or more ndarrays from a .npy value. Each array has a target\n" - "where the array will be retained such as `!blackboard.set 2`.\n" - "\n" - "`type: numpy_save\n" - "Saves one or more ndarrays to a .npy value. Each array has a source\n" - "where the array will be taken from such as `!blackboard.get 2`.\n" - "\n" - "`type: call`\n" - "Invokes a function in the context by fully-qualified `function` name.\n" - "Uses arguments from an `args` sequence and produces results into a\n" - "`results` sequence.\n" - "\n" - "--- Sources ---\n" - "\n" - "`type: null`\n" - "A null ref value.\n" - "\n" - "`!hal.buffer_view 4xf32=0,1,2,3`\n" - "A constant iree_hal_buffer_view_t/!hal.buffer_view value using the\n" - "same formatting as iree-run-module's `--input=` flag.\n" - "\n" - "`!hal.buffer 4xf32=0,1,2,3`\n" - "An initialized iree_hal_buffer_t/!hal.buffer without the wrapping view\n" - "metadata.\n" - "\n" - "`!input.get ORDINAL` / `!input.take ORDINAL`\n" - "Returns a reference to `--input=` flag at ORDINAL. Note that a single\n" - "npy file may expand to multiple inputs. The `take` variant transfers\n" - "ownership and clears the slot in the list and is recommended to avoid\n" - "keeping unneeded inputs around for the duration of the trace.\n" - "\n" - "`!output.get ORDINAL` / `!output.take ORDINAL`\n" - "Returns a reference to the `--output=` flag at ORDINAL. These are\n" - "initially empty until assigned by the trace.\n" - "\n" - "`!blackboard.get ORDINAL` / `!blackboard.take ORDINAL`\n" - "Returns a reference to the blackboard slot ORDINAL. The blackboard is\n" - "initially empty and slots must be assigned in order to define them.\n" - "The `take` variant transfers ownership and clears the slot in the\n" - "blackboard and is recommended to avoid keeping large resources live\n" - "in the blackboard longer than they need to be.\n" - "\n" - "--- Targets ---\n" - "\n" - "`!output.set ORDINAL` / `!output.push`\n" - "Sets the `--output=` flag result value at ORDINAL or pushes it to the\n" - "back of the output list. Outputs can either be dumped to files or by\n" - "default printed to stdout.\n" - "\n" - "`!blackboard.set ORDINAL` / `blackboard.push`\n" - "Sets the value of the blackboard slot ORDINAL or pushes it to the back\n" - "of the blackboard list. Blackboard values will be retained until they\n" - "are consumed via `!blackboard.take` or the blackboard is cleared.\n" - "\n"); - iree_flags_parse_checked(IREE_FLAGS_PARSE_MODE_DEFAULT, &argc, &argv); - if (argc <= 1) { - fprintf(stderr, - "no trace files provided; pass one or more yaml file paths"); - IREE_TRACE_APP_EXIT(EXIT_FAILURE); - return EXIT_FAILURE; - } - - iree_vm_instance_t* instance = NULL; - iree_status_t status = iree_vm_instance_create( - IREE_VM_TYPE_CAPACITY_DEFAULT, iree_allocator_system(), &instance); - if (iree_status_is_ok(status)) { - status = iree_run_trace_files(argc - 1, argv + 1, instance); - } - iree_vm_instance_release(instance); - int exit_code = EXIT_SUCCESS; - if (!iree_status_is_ok(status)) { - iree_status_fprint(stderr, status); - iree_status_free(status); - exit_code = EXIT_FAILURE; - } - IREE_TRACE_APP_EXIT(exit_code); - return exit_code; -}
diff --git a/tools/test/BUILD.bazel b/tools/test/BUILD.bazel index c9602f1..14e39d8 100644 --- a/tools/test/BUILD.bazel +++ b/tools/test/BUILD.bazel
@@ -32,7 +32,6 @@ "iree-run-module-inputs.mlir", "iree-run-module-outputs.mlir", "iree-run-module.mlir", - "iree-run-trace.mlir", "multiple_args.mlir", "multiple_exported_functions.mlir", "null_values.mlir", @@ -49,7 +48,6 @@ cfg = "//tools:lit.cfg.py", data = [ "echo_npy.py", - "iree-run-trace.yml", "parameters_a.safetensors", "parameters_b.safetensors", ], @@ -59,13 +57,11 @@ ], tools = [ "//tools:iree-benchmark-module", - "//tools:iree-benchmark-trace", "//tools:iree-compile", "//tools:iree-dump-parameters", "//tools:iree-opt", "//tools:iree-run-mlir", "//tools:iree-run-module", - "//tools:iree-run-trace", "@llvm-project//lld", "@llvm-project//llvm:FileCheck", "@llvm-project//llvm:not",
diff --git a/tools/test/CMakeLists.txt b/tools/test/CMakeLists.txt index 6270174..dcacb08 100644 --- a/tools/test/CMakeLists.txt +++ b/tools/test/CMakeLists.txt
@@ -28,7 +28,6 @@ "iree-run-module-inputs.mlir" "iree-run-module-outputs.mlir" "iree-run-module.mlir" - "iree-run-trace.mlir" "multiple_args.mlir" "multiple_exported_functions.mlir" "null_values.mlir" @@ -40,17 +39,14 @@ ${IREE_LLD_TARGET} FileCheck iree-benchmark-module - iree-benchmark-trace iree-compile iree-dump-parameters iree-opt iree-run-mlir iree-run-module - iree-run-trace not DATA echo_npy.py - iree-run-trace.yml parameters_a.safetensors parameters_b.safetensors LABELS
diff --git a/tools/test/iree-run-trace.mlir b/tools/test/iree-run-trace.mlir deleted file mode 100644 index 030136f..0000000 --- a/tools/test/iree-run-trace.mlir +++ /dev/null
@@ -1,33 +0,0 @@ -// Tests iree-run-trace usage by running two calls of @mul and passing the -// result between them. The outputs of both calls are produced as outputs from -// the trace and both are written to a .npy file for processing. Inputs can -// also come from an .npy file. See iree-run-module usage for more information -// on the `--input=` and `--output=` flags. - -// RUN: (iree-compile --iree-hal-target-backends=vmvx %s | \ -// RUN: iree-run-trace %S/iree-run-trace.yml \ -// RUN: --device=local-sync \ -// RUN: --input=4xf32=4,4,4,4 \ -// RUN: --output=@%t \ -// RUN: --output=+%t) && \ -// RUN: "%PYTHON" %S/echo_npy.py %t | \ -// RUN: FileCheck %s --check-prefix=RUN-TRACE -// RUN-TRACE{LITERAL}: [ 0. 4. 8. 12.] -// RUN-TRACE-NEXT{LITERAL}: [ 0. 12. 24. 36.] - -// Tests iree-run-benchmark usage by running the same sequence as above but with -// benchmarking enabled. The tools are mostly interchangable except benchmarking -// doesn't yield any output values or feature I/O printing. All traces that can -// run with iree-run-trace *should* run with iree-benchmark-trace. -// RUN: (iree-compile --iree-hal-target-backends=vmvx %s | \ -// RUN: iree-benchmark-trace %S/iree-run-trace.yml \ -// RUN: --capture_stdin=true \ -// RUN: --device=local-sync \ -// RUN: --input=4xf32=4,4,4,4) | \ -// RUN: FileCheck %s --check-prefix=BENCHMARK-TRACE -// BENCHMARK-TRACE{LITERAL}: BM_iree-run-trace/process_time/real_time - -func.func @mul(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32> { - %0 = arith.mulf %arg0, %arg1 : tensor<4xf32> - return %0 : tensor<4xf32> -}
diff --git a/tools/test/iree-run-trace.yml b/tools/test/iree-run-trace.yml deleted file mode 100644 index ea71303..0000000 --- a/tools/test/iree-run-trace.yml +++ /dev/null
@@ -1,82 +0,0 @@ -# Copyright 2023 The IREE Authors -# -# Licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Tests loading and executing a bytecode module and issuing a few calls showing -# how to take input, produce output, and support temporary values within the -# trace session. See iree-run-trace.mlir for how to compile the module and -# invoke the iree-run-trace tool. - -# Prepare the VM context for use; effectively a reset. -# API: iree_vm_context_create -type: context_load - ---- - -# Load the builtin HAL module used to execute the program. -# API: iree_hal_module_create -type: module_load -module: - type: builtin - name: hal - ---- - -# Load the compiled bytecode module. -# API: iree_vm_bytecode_module_create -type: module_load -module: - type: bytecode - name: module - # The test pulls the .vmfb from stdin but you can also reference relative or - # absolute file paths: - # path: ../iree-tmp/iree-run-trace.vmfb - # NOTE: if using iree-benchmark-trace then --capture_stdin must be passed to - # capture the full contents of stdin for reuse in benchmark iterations. - path: <stdin> - ---- - -# Call #0 of @mul. -# API: iree_vm_invoke -type: call -function: module.mul -args: -# arg[0]: the first `--input=` buffer. !input.get would retain the input for -# other calls to use but otherwise prefer taking ownership. -- !input.take 0 -# arg[1]: constant value defined inline. -- !hal.buffer_view 4xf32=0,1,2,3 -results: -# result[0]: store in blackboard slot 4 for later use. -- !blackboard.set 4 - ---- - -# Assigns one or more source values to a set of target values. -# Effectively: outputs.push(retain(blackboard[4])) -type: assign -from: -# from[0]: retain blackboard slot 4, leaving it for later use. -- !blackboard.get 4 -to: -# to[0]: push on to the trace output list. --output= can save off the results -# and otherwise they are printed to stdout. -- !output.push - ---- - -# Call #1 of @mul. -# API: iree_vm_invoke -type: call -function: module.mul -args: -# arg[0]: take the previously-stored value in blackboard slot 4. -- !blackboard.take 4 -# arg[1]: another constant. -- !hal.buffer_view 4xf32=3,3,3,3 -results: -# result[0]: push on to the trace output list. -- !output.push