Skip to content

Commit

Permalink
Add a -v flag to generator_main() (#7193)
Browse files Browse the repository at this point in the history
This is a simple thing that just logs the path to all generated file(s) to stdout if `-v=1` is specified. It's intended for people running Generators directly from the commandline, and is intended as a more user-friendly alternative to HL_DEBUG_CODEGEN=1. No makefiles, etc specify it at present, but I anticipate using it in some tooling in the future.

Example usage:
```
$ resize_image_bilinear.generator_binary -v 1 -o /tmp -g resize_image_bilinear -n resize_image_bilinear_uint16 -f resize_image_bilinear_uint16 -e assembly,c_header,llvm_assembly,registration,static_library,stmt 'target=arm-64-android' 'input.type=uint16' 'output.type=uint16'
Generated file: /tmp/resize_image_bilinear_uint16.s
Generated file: /tmp/resize_image_bilinear_uint16.h
Generated file: /tmp/resize_image_bilinear_uint16.ll
Generated file: /tmp/resize_image_bilinear_uint16.registration.cpp
Generated file: /tmp/resize_image_bilinear_uint16.a
Generated file: /tmp/resize_image_bilinear_uint16.stmt
```
  • Loading branch information
steven-johnson authored Dec 1, 2022
1 parent 5a8c324 commit 43911f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ gengen
bugs and/or degenerate cases don't stall build systems. Defaults to 900
(=15 minutes). Specify 0 to allow ~infinite time.
-v If nonzero, log the path to all generated files to stdout.
)INLINE_CODE";

std::map<std::string, std::string> flags_info = {
Expand All @@ -683,6 +684,7 @@ gengen
{"-o", ""},
{"-p", ""},
{"-r", ""},
{"-v", "0"},
{"-t", "900"}, // 15 minutes
};

Expand Down Expand Up @@ -729,6 +731,10 @@ gengen
user_assert(d_val == "1" || d_val == "0") << "-d must be 0 or 1\n"
<< kUsage;

const auto &v_val = flags_info["-v"];
user_assert(v_val == "1" || v_val == "0") << "-v must be 0 or 1\n"
<< kUsage;

const std::vector<std::string> generator_names = generator_factory_provider.enumerate();

const auto create_generator = [&](const std::string &generator_name, const Halide::GeneratorContext &context) -> AbstractGeneratorPtr {
Expand Down Expand Up @@ -838,6 +844,8 @@ gengen
args.build_mode = (d_val == "1") ? ExecuteGeneratorArgs::Gradient : ExecuteGeneratorArgs::Default;
args.create_generator = create_generator;
// args.generator_params is already set
// If true, log the path of all output files to stdout.
args.log_outputs = (v_val == "1");

// Allow quick-n-dirty use of compiler logging via HL_DEBUG_COMPILER_LOGGER env var
const bool do_compiler_logging = args.output_types.count(OutputFileType::compiler_log) ||
Expand Down Expand Up @@ -1108,6 +1116,11 @@ void execute_generator(const ExecuteGeneratorArgs &args_in) {
gen->build_module(function_name);
};
compile_multitarget(args.function_name, output_files, args.targets, args.suffixes, module_factory, args.compiler_logger_factory);
if (args.log_outputs) {
for (const auto &o : output_files) {
std::cout << "Generated file: " << o.second << "\n";
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3934,6 +3934,9 @@ struct ExecuteGeneratorArgs {

// Compiler Logger to use, for diagnostic work. If null, don't do any logging.
CompilerLoggerFactory compiler_logger_factory = nullptr;

// If true, log the path of all output files to stdout.
bool log_outputs = false;
};

/**
Expand Down

0 comments on commit 43911f4

Please sign in to comment.