diff --git a/xls/fuzzer/run_fuzz.cc b/xls/fuzzer/run_fuzz.cc index 9fdec6cee8..c637b1fcb5 100644 --- a/xls/fuzzer/run_fuzz.cc +++ b/xls/fuzzer/run_fuzz.cc @@ -212,19 +212,6 @@ absl::Status RunSample(const Sample& smp, const std::filesystem::path& run_dir, XLS_RETURN_IF_ERROR(SetTextProtoFile(testvector_path, testvector)); argv.push_back("--testvector_textproto=testvector.pbtxt"); - std::filesystem::path args_file_name = run_dir / "args.txt"; - XLS_RETURN_IF_ERROR( - SetFileContents(args_file_name, ArgsBatchToText(smp.args_batch()))); - - std::optional ir_channel_names_file_name = - std::nullopt; - if (!smp.ir_channel_names().empty()) { - ir_channel_names_file_name = run_dir / "ir_channel_names.txt"; - XLS_RETURN_IF_ERROR( - SetFileContents(*ir_channel_names_file_name, - IrChannelNamesToText(smp.ir_channel_names()))); - } - argv.push_back("\"$RUNDIR\""); std::filesystem::path run_script_path = run_dir / "run.sh"; @@ -242,9 +229,8 @@ cd "$RUNDIR" VLOG(1) << "Starting to run sample"; VLOG(2) << smp.input_text(); SampleRunner runner(run_dir); - XLS_RETURN_IF_ERROR( - runner.RunFromFiles(sample_file_name, options_file_name, args_file_name, - ir_channel_names_file_name, testvector_path)); + XLS_RETURN_IF_ERROR(runner.RunFromFiles(sample_file_name, options_file_name, + testvector_path)); fuzzer::SampleTimingProto timing = runner.timing(); diff --git a/xls/fuzzer/run_fuzz_multiprocess_test.py b/xls/fuzzer/run_fuzz_multiprocess_test.py index 20ae1c409a..3e462b831f 100644 --- a/xls/fuzzer/run_fuzz_multiprocess_test.py +++ b/xls/fuzzer/run_fuzz_multiprocess_test.py @@ -52,7 +52,7 @@ def test_two_samples(self): sample1_contents = os.listdir(os.path.join(samples_path, 'worker0-sample0')) self.assertIn('sample.x', sample1_contents) self.assertIn('sample.x.results', sample1_contents) - self.assertIn('args.txt', sample1_contents) + self.assertIn('testvector.pbtxt', sample1_contents) self.assertIn('sample.ir', sample1_contents) self.assertIn('sample.ir.results', sample1_contents) self.assertIn('sample.opt.ir', sample1_contents) @@ -62,10 +62,6 @@ def test_two_samples(self): self.assertNotIn('sample.v', sample1_contents) self.assertNotIn('sample.sv', sample1_contents) - # Args file should have three lines in it. - with open(os.path.join(samples_path, 'worker0-sample0', 'args.txt')) as f: - self.assertEqual(len(f.read().strip().splitlines()), 3) - def test_multiple_workers(self): crasher_path = self.create_tempdir().full_path samples_path = self.create_tempdir().full_path @@ -147,7 +143,7 @@ def test_codegen_and_simulate(self): sample1_contents = os.listdir(os.path.join(samples_path, 'worker0-sample0')) self.assertIn('sample.x', sample1_contents) self.assertIn('sample.x.results', sample1_contents) - self.assertIn('args.txt', sample1_contents) + self.assertIn('testvector.pbtxt', sample1_contents) self.assertIn('sample.ir', sample1_contents) self.assertIn('sample.ir.results', sample1_contents) self.assertIn('sample.opt.ir', sample1_contents) @@ -196,7 +192,7 @@ def test_codegen_and_simulate_with_proc(self): sample1_contents = os.listdir(os.path.join(samples_path, 'worker0-sample0')) self.assertIn('sample.x', sample1_contents) self.assertIn('sample.x.results', sample1_contents) - self.assertIn('args.txt', sample1_contents) + self.assertIn('testvector.pbtxt', sample1_contents) self.assertIn('sample.ir', sample1_contents) self.assertIn('sample.ir.results', sample1_contents) self.assertIn('sample.opt.ir', sample1_contents) diff --git a/xls/fuzzer/sample.h b/xls/fuzzer/sample.h index 45a245eef2..5267a4fd95 100644 --- a/xls/fuzzer/sample.h +++ b/xls/fuzzer/sample.h @@ -233,6 +233,8 @@ class Sample { // file. Crashers may be checked in as tests in `xls/fuzzer/crashers/`. std::string ToCrasher(std::string_view error_message) const; + // TODO(google/xls#1645) args batch and channel names should be sample inputs + // proto instead. Sample(std::string input_text, SampleOptions options, std::vector> args_batch, std::vector ir_channel_names = {}) diff --git a/xls/fuzzer/sample_runner.cc b/xls/fuzzer/sample_runner.cc index 3100aa9b4d..a6a173f34f 100644 --- a/xls/fuzzer/sample_runner.cc +++ b/xls/fuzzer/sample_runner.cc @@ -839,29 +839,13 @@ absl::Status SampleRunner::Run(const Sample& sample) { XLS_RETURN_IF_ERROR(sample.FillSampleInputs(&testvector)); XLS_RETURN_IF_ERROR(SetTextProtoFile(testvector_path, testvector)); - // TODO(hzeller): retire the following files and use testvector - std::filesystem::path args_path = run_dir_ / "args.txt"; - XLS_RETURN_IF_ERROR( - SetFileContents(args_path, ArgsBatchToText(sample.args_batch()))); - - std::optional ir_channel_names_path = std::nullopt; - if (!sample.ir_channel_names().empty()) { - ir_channel_names_path = run_dir_ / "ir_channel_names.txt"; - XLS_RETURN_IF_ERROR( - SetFileContents(*ir_channel_names_path, - IrChannelNamesToText(sample.ir_channel_names()))); - } - - return RunFromFiles(input_path, options_path, args_path, - ir_channel_names_path, testvector_path); + return RunFromFiles(input_path, options_path, testvector_path); } absl::Status SampleRunner::RunFromFiles( const std::filesystem::path& input_path, const std::filesystem::path& options_path, - const std::optional& args_path, // deprecated - const std::optional& ir_channel_names_path, // ditto - const std::optional& testvector_path) { + const std::filesystem::path& testvector_path) { VLOG(1) << "Running sample in directory " << run_dir_; VLOG(1) << "Reading sample files."; @@ -875,11 +859,10 @@ absl::Status SampleRunner::RunFromFiles( absl::Status status; switch (options.sample_type()) { case fuzzer::SampleType::SAMPLE_TYPE_FUNCTION: - status = RunFunction(input_path, options, std::nullopt, testvector_path); + status = RunFunction(input_path, options, testvector_path); break; case fuzzer::SampleType::SAMPLE_TYPE_PROC: - status = RunProc(input_path, options, std::nullopt, std::nullopt, - testvector_path); + status = RunProc(input_path, options, testvector_path); break; default: status = absl::InvalidArgumentError( @@ -903,23 +886,21 @@ absl::Status SampleRunner::RunFromFiles( absl::Status SampleRunner::RunFunction( const std::filesystem::path& input_path, const SampleOptions& options, - const std::optional& args_path, - const std::optional& testvector_path) { + const std::filesystem::path& testvector_path) { XLS_ASSIGN_OR_RETURN(std::string input_text, GetFileContents(input_path)); std::optional args_batch = std::nullopt; - if (args_path.has_value()) { - XLS_ASSIGN_OR_RETURN(std::string args_text, GetFileContents(*args_path)); - XLS_ASSIGN_OR_RETURN(args_batch, dslx::ParseArgsBatch(args_text)); - } else if (testvector_path.has_value()) { + { + XLS_RET_CHECK(!testvector_path.empty()); testvector::SampleInputsProto sample_inputs; - XLS_RETURN_IF_ERROR(ParseTextProtoFile(*testvector_path, &sample_inputs)); + XLS_RETURN_IF_ERROR(ParseTextProtoFile(testvector_path, &sample_inputs)); ArgsBatch extracted; XLS_RETURN_IF_ERROR(Sample::ExtractArgsBatch(/* is_proc_samples= */ false, sample_inputs, extracted)); args_batch = std::move(extracted); } + // Results from various ways of interpretation. absl::flat_hash_map> results; std::filesystem::path ir_path; @@ -954,14 +935,14 @@ absl::Status SampleRunner::RunFunction( // Unconditionally evaluate with the interpreter even if using the JIT. This // exercises the interpreter and serves as a reference. XLS_ASSIGN_OR_RETURN(results["evaluated unopt IR (interpreter)"], - EvaluateIrFunction(ir_path, *testvector_path, false, + EvaluateIrFunction(ir_path, testvector_path, false, options, run_dir_, commands_)); timing_.set_unoptimized_interpret_ir_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); if (options.use_jit()) { XLS_ASSIGN_OR_RETURN(results["evaluated unopt IR (JIT)"], - EvaluateIrFunction(ir_path, *testvector_path, true, + EvaluateIrFunction(ir_path, testvector_path, true, options, run_dir_, commands_)); timing_.set_unoptimized_jit_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); @@ -979,7 +960,7 @@ absl::Status SampleRunner::RunFunction( t.Reset(); XLS_ASSIGN_OR_RETURN( results["evaluated opt IR (JIT)"], - EvaluateIrFunction(opt_ir_path, *testvector_path, true, options, + EvaluateIrFunction(opt_ir_path, testvector_path, true, options, run_dir_, commands_)); timing_.set_optimized_jit_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); @@ -987,7 +968,7 @@ absl::Status SampleRunner::RunFunction( t.Reset(); XLS_ASSIGN_OR_RETURN( results["evaluated opt IR (interpreter)"], - EvaluateIrFunction(opt_ir_path, *testvector_path, false, options, + EvaluateIrFunction(opt_ir_path, testvector_path, false, options, run_dir_, commands_)); timing_.set_optimized_interpret_ir_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); @@ -1001,11 +982,12 @@ absl::Status SampleRunner::RunFunction( timing_.set_codegen_ns(absl::ToInt64Nanoseconds(t.GetElapsedTime())); if (options.simulate()) { + XLS_RET_CHECK(args_batch.has_value()); t.Reset(); XLS_ASSIGN_OR_RETURN( results["simulated"], SimulateFunction(verilog_path, "module_sig.textproto", - *testvector_path, options, run_dir_, commands_)); + testvector_path, options, run_dir_, commands_)); timing_.set_simulate_ns(absl::ToInt64Nanoseconds(t.GetElapsedTime())); } } @@ -1019,25 +1001,15 @@ absl::Status SampleRunner::RunFunction( absl::Status SampleRunner::RunProc( const std::filesystem::path& input_path, const SampleOptions& options, - const std::optional& args_path, - const std::optional& ir_channel_names_path, - const std::optional& testvector_path) { + const std::filesystem::path& testvector_path) { XLS_ASSIGN_OR_RETURN(std::string input_text, GetFileContents(input_path)); std::optional args_batch = std::nullopt; std::optional> ir_channel_names = std::nullopt; - if (args_path.has_value()) { - XLS_ASSIGN_OR_RETURN(std::string args_text, GetFileContents(*args_path)); - XLS_ASSIGN_OR_RETURN(args_batch, dslx::ParseArgsBatch(args_text)); - if (ir_channel_names_path.has_value()) { - XLS_ASSIGN_OR_RETURN(std::string ir_channel_names_text, - GetFileContents(*ir_channel_names_path)); - ir_channel_names = ParseIrChannelNames(ir_channel_names_text); - } - } else if (testvector_path.has_value()) { + { testvector::SampleInputsProto sample_inputs; - XLS_RETURN_IF_ERROR(ParseTextProtoFile(*testvector_path, &sample_inputs)); + XLS_RETURN_IF_ERROR(ParseTextProtoFile(testvector_path, &sample_inputs)); ArgsBatch extracted_args; std::vector extracted_channel_names; XLS_RETURN_IF_ERROR(Sample::ExtractArgsBatch(/* is_proc_samples= */ true, @@ -1047,35 +1019,6 @@ absl::Status SampleRunner::RunProc( ir_channel_names = std::move(extracted_channel_names); } - std::string ir_channel_values_file_content; - if (args_batch.has_value() && ir_channel_names.has_value()) { - absl::flat_hash_map> - all_channel_values; - for (const std::vector& channel_values : *args_batch) { - if (channel_values.size() != ir_channel_names->size()) { - return absl::InvalidArgumentError( - absl::StrFormat("Invalid number of values in args_batch sample; " - "expected: %d, got: %d", - ir_channel_names->size(), channel_values.size())); - } - for (int i = 0; i < ir_channel_names->size(); ++i) { - all_channel_values[ir_channel_names->at(i)].push_back( - channel_values[i]); - } - } - - absl::flat_hash_map> ir_channel_values; - for (const auto& [key, values] : all_channel_values) { - XLS_ASSIGN_OR_RETURN(ir_channel_values[key], - dslx::InterpValue::ConvertValuesToIr(values)); - } - ir_channel_values_file_content = ChannelValuesToString(ir_channel_values); - } - std::filesystem::path ir_channel_values_path = - run_dir_ / "channel_inputs.txt"; - XLS_RETURN_IF_ERROR( - SetFileContents(ir_channel_values_path, ir_channel_values_file_content)); - // Special case: When there no inputs for a proc, typically when there are no // channels for a proc, tick_count results to 0. Set the tick_count to a // non-zero value to execute in the eval proc main (bypasses a restriction on @@ -1125,7 +1068,7 @@ absl::Status SampleRunner::RunProc( // exercises the interpreter and serves as a reference. Stopwatch t; XLS_ASSIGN_OR_RETURN(results["evaluated unopt IR (interpreter)"], - EvaluateIrProc(ir_path, tick_count, *testvector_path, + EvaluateIrProc(ir_path, tick_count, testvector_path, false, options, run_dir_, commands_)); if (!reference.has_value()) { reference = results["evaluated unopt IR (interpreter)"]; @@ -1136,7 +1079,7 @@ absl::Status SampleRunner::RunProc( if (options.use_jit()) { t.Reset(); XLS_ASSIGN_OR_RETURN(results["evaluated unopt IR (JIT)"], - EvaluateIrProc(ir_path, tick_count, *testvector_path, + EvaluateIrProc(ir_path, tick_count, testvector_path, true, options, run_dir_, commands_)); timing_.set_unoptimized_jit_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); @@ -1155,7 +1098,7 @@ absl::Status SampleRunner::RunProc( t.Reset(); XLS_ASSIGN_OR_RETURN( results["evaluated opt IR (JIT)"], - EvaluateIrProc(*opt_ir_path, tick_count, *testvector_path, true, + EvaluateIrProc(*opt_ir_path, tick_count, testvector_path, true, options, run_dir_, commands_)); timing_.set_optimized_jit_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); @@ -1164,7 +1107,7 @@ absl::Status SampleRunner::RunProc( t.Reset(); XLS_ASSIGN_OR_RETURN( results["evaluated opt IR (interpreter)"], - EvaluateIrProc(*opt_ir_path, tick_count, *testvector_path, false, + EvaluateIrProc(*opt_ir_path, tick_count, testvector_path, false, options, run_dir_, commands_)); timing_.set_optimized_interpret_ir_ns( absl::ToInt64Nanoseconds(t.GetElapsedTime())); @@ -1186,7 +1129,7 @@ absl::Status SampleRunner::RunProc( XLS_ASSIGN_OR_RETURN( results["simulated"], SimulateProc(verilog_path, "module_sig.textproto", - *testvector_path, output_channel_counts_str, options, + testvector_path, output_channel_counts_str, options, run_dir_, commands_)); timing_.set_simulate_ns(absl::ToInt64Nanoseconds(t.GetElapsedTime())); } diff --git a/xls/fuzzer/sample_runner.h b/xls/fuzzer/sample_runner.h index 1642389c1e..b355a832ce 100644 --- a/xls/fuzzer/sample_runner.h +++ b/xls/fuzzer/sample_runner.h @@ -71,28 +71,21 @@ class SampleRunner { // Runs the provided files as a sample, writing out only outputs under the // SampleRunner's `run_dir`. - absl::Status RunFromFiles( - const std::filesystem::path& input_path, - const std::filesystem::path& options_path, - const std::optional& args_path, // deprecated - const std::optional& - ir_channel_names_path, // same - const std::optional& testvector_path); + absl::Status RunFromFiles(const std::filesystem::path& input_path, + const std::filesystem::path& options_path, + const std::filesystem::path& testvector_path); const fuzzer::SampleTimingProto& timing() const { return timing_; } private: // Runs a sample with a function as the top which is read from files. - absl::Status RunFunction( - const std::filesystem::path& input_path, const SampleOptions& options, - const std::optional& args_path, - const std::optional& testvector_path); - - absl::Status RunProc( - const std::filesystem::path& input_path, const SampleOptions& options, - const std::optional& args_path, - const std::optional& ir_channel_names_path, - const std::optional& testvector_path); + absl::Status RunFunction(const std::filesystem::path& input_path, + const SampleOptions& options, + const std::filesystem::path& testvector_path); + + absl::Status RunProc(const std::filesystem::path& input_path, + const SampleOptions& options, + const std::filesystem::path& testvector_path); const std::filesystem::path run_dir_; const Commands commands_; diff --git a/xls/fuzzer/sample_runner_main.cc b/xls/fuzzer/sample_runner_main.cc index 883ea0992d..f1a241385e 100644 --- a/xls/fuzzer/sample_runner_main.cc +++ b/xls/fuzzer/sample_runner_main.cc @@ -46,12 +46,7 @@ sample_runner_main --options_file=OPT_FILE \ ABSL_FLAG(std::string, options_file, "", "File to load sample runner options from."); ABSL_FLAG(std::string, input_file, "", "Code input file."); -ABSL_FLAG(std::optional, args_file, std::nullopt, - "Optional file containing arguments to use for interpretation and " - "simulation."); -ABSL_FLAG(std::optional, ir_channel_names_file, std::nullopt, - "Optional file containing IR names of input channels for a proc."); -ABSL_FLAG(std::optional, testvector_textproto, std::nullopt, +ABSL_FLAG(std::string, testvector_textproto, "", "A textproto file containing the function argument or proc " "channel test vectors."); @@ -77,28 +72,17 @@ std::filesystem::path MaybeCopyFile(const std::filesystem::path& file_path, } // namespace // Runs the sample in the given run directory. -static absl::Status RealMain( - const std::filesystem::path& run_dir, const std::string& options_file, - const std::string& input_file, const std::optional& args_file, - const std::optional& ir_channel_names_file, - const std::optional& testvector_file) { +static absl::Status RealMain(const std::filesystem::path& run_dir, + const std::string& options_file, + const std::string& input_file, + const std::string& testvector_file) { SampleRunner runner(run_dir); std::filesystem::path input_filename = MaybeCopyFile(input_file, run_dir); std::filesystem::path options_filename = MaybeCopyFile(options_file, run_dir); - std::optional args_filename = - args_file.has_value() - ? std::make_optional(MaybeCopyFile(*args_file, run_dir)) - : std::nullopt; - std::optional ir_channel_names_filename = - ir_channel_names_file.has_value() - ? std::make_optional(MaybeCopyFile(*ir_channel_names_file, run_dir)) - : std::nullopt; - std::optional testvector_filename = - testvector_file.has_value() - ? std::make_optional(MaybeCopyFile(*testvector_file, run_dir)) - : std::nullopt; - return runner.RunFromFiles(input_filename, options_filename, args_filename, - ir_channel_names_filename, testvector_filename); + std::filesystem::path testvector_filename = + MaybeCopyFile(testvector_file, run_dir); + return runner.RunFromFiles(input_filename, options_filename, + testvector_filename); } } // namespace xls @@ -111,6 +95,8 @@ int main(int argc, char** argv) { << "--options_file is required."; QCHECK(!absl::GetFlag(FLAGS_input_file).empty()) << "--input_file is required."; + QCHECK(!absl::GetFlag(FLAGS_testvector_textproto).empty()) + << "--testvector_textproto is required."; if (positional_arguments.size() > 1) { LOG(QFATAL) << "Usage:\n" << kUsage; @@ -139,8 +125,6 @@ int main(int argc, char** argv) { return xls::ExitStatus( xls::RealMain(run_dir, absl::GetFlag(FLAGS_options_file), absl::GetFlag(FLAGS_input_file), - absl::GetFlag(FLAGS_args_file), - absl::GetFlag(FLAGS_ir_channel_names_file), absl::GetFlag(FLAGS_testvector_textproto)), /*log_on_error=*/false); }