@@ -321,7 +321,7 @@ absl::StatusOr<std::vector<dslx::InterpValue>> ParseValues(std::string_view s) {
321
321
// Evaluate the IR file with a function as its top and return the result Values.
322
322
absl::StatusOr<std::vector<dslx::InterpValue>> EvaluateIrFunction (
323
323
const std::filesystem::path& ir_path,
324
- const std::filesystem::path& args_path , bool use_jit,
324
+ const std::filesystem::path& testvector_path , bool use_jit,
325
325
const SampleOptions& options, const std::filesystem::path& run_dir,
326
326
const SampleRunner::Commands& commands) {
327
327
std::optional<SampleRunner::Commands::Callable> command =
@@ -332,15 +332,16 @@ absl::StatusOr<std::vector<dslx::InterpValue>> EvaluateIrFunction(
332
332
333
333
XLS_ASSIGN_OR_RETURN (
334
334
std::string results_text,
335
- RunCommand (absl::StrFormat (" Evaluating IR file (%s): %s" ,
336
- (use_jit ? " JIT" : " interpreter" ), ir_path),
337
- *command,
338
- {
339
- absl::StrCat (" --input_file=" , args_path.string ()),
340
- absl::StrFormat (" --%suse_llvm_jit" , use_jit ? " " : " no" ),
341
- ir_path,
342
- },
343
- run_dir, options));
335
+ RunCommand (
336
+ absl::StrFormat (" Evaluating IR file (%s): %s" ,
337
+ (use_jit ? " JIT" : " interpreter" ), ir_path),
338
+ *command,
339
+ {
340
+ absl::StrCat (" --testvector_textproto=" , testvector_path.string ()),
341
+ absl::StrFormat (" --%suse_llvm_jit" , use_jit ? " " : " no" ),
342
+ ir_path,
343
+ },
344
+ run_dir, options));
344
345
XLS_RETURN_IF_ERROR (SetFileContents (
345
346
absl::StrCat (ir_path.string (), " .results" ), results_text));
346
347
return ParseValues (results_text);
@@ -397,7 +398,7 @@ absl::StatusOr<std::filesystem::path> OptimizeIr(
397
398
absl::StatusOr<std::vector<dslx::InterpValue>> SimulateFunction (
398
399
const std::filesystem::path& verilog_path,
399
400
const std::filesystem::path& module_sig_path,
400
- const std::filesystem::path& args_path , const SampleOptions& options,
401
+ const std::filesystem::path& testvector_path , const SampleOptions& options,
401
402
const std::filesystem::path& run_dir,
402
403
const SampleRunner::Commands& commands) {
403
404
std::optional<SampleRunner::Commands::Callable> command =
@@ -408,7 +409,7 @@ absl::StatusOr<std::vector<dslx::InterpValue>> SimulateFunction(
408
409
409
410
std::vector<std::string> simulator_args = {
410
411
absl::StrCat (" --signature_file=" , module_sig_path.string ()),
411
- absl::StrCat (" --args_file =" , args_path .string ()),
412
+ absl::StrCat (" --testvector_textproto =" , testvector_path .string ()),
412
413
};
413
414
XLS_RETURN_IF_ERROR (CheckSimulator (options.simulator ()));
414
415
if (!options.simulator ().empty ()) {
@@ -706,8 +707,8 @@ absl::StatusOr<std::filesystem::path> DslxToIrProc(
706
707
707
708
absl::StatusOr<absl::flat_hash_map<std::string, std::vector<Value>>>
708
709
EvaluateIrProc (const std::filesystem::path& ir_path, int64_t tick_count,
709
- const std::filesystem::path& ir_channel_values_path ,
710
- bool use_jit, const SampleOptions& options,
710
+ const std::filesystem::path& testvector_proto_path, bool use_jit ,
711
+ const SampleOptions& options,
711
712
const std::filesystem::path& run_dir,
712
713
const SampleRunner::Commands& commands) {
713
714
std::optional<SampleRunner::Commands::Callable> command =
@@ -721,8 +722,7 @@ EvaluateIrProc(const std::filesystem::path& ir_path, int64_t tick_count,
721
722
absl::StrFormat (" Evaluating IR file (%s): %s" , evaluation_type, ir_path);
722
723
std::string_view backend_type = use_jit ? " serial_jit" : " ir_interpreter" ;
723
724
std::vector<std::string> args = {
724
- absl::StrCat (" --inputs_for_all_channels=" ,
725
- ir_channel_values_path.string ()),
725
+ absl::StrCat (" --testvector_textproto=" , testvector_proto_path.string ()),
726
726
absl::StrCat (" --ticks=" , tick_count),
727
727
absl::StrCat (" --backend=" , backend_type),
728
728
ir_path,
@@ -780,7 +780,7 @@ std::string GetOutputChannelToString(
780
780
absl::StatusOr<absl::flat_hash_map<std::string, std::vector<Value>>>
781
781
SimulateProc (const std::filesystem::path& verilog_path,
782
782
const std::filesystem::path& module_sig_path,
783
- const std::filesystem::path& ir_channel_values_path ,
783
+ const std::filesystem::path& testvector_path ,
784
784
std::string_view output_channel_counts,
785
785
const SampleOptions& options, const std::filesystem::path& run_dir,
786
786
const SampleRunner::Commands& commands) {
@@ -792,7 +792,7 @@ SimulateProc(const std::filesystem::path& verilog_path,
792
792
793
793
std::vector<std::string> simulator_args = {
794
794
absl::StrCat (" --signature_file=" , module_sig_path.string ()),
795
- absl::StrCat (" --channel_values_file =" , ir_channel_values_path .string ()),
795
+ absl::StrCat (" --testvector_textproto =" , testvector_path .string ()),
796
796
absl::StrCat (" --output_channel_counts=" , output_channel_counts),
797
797
};
798
798
if (!options.simulator ().empty ()) {
@@ -853,14 +853,15 @@ absl::Status SampleRunner::Run(const Sample& sample) {
853
853
}
854
854
855
855
return RunFromFiles (input_path, options_path, args_path,
856
- ir_channel_names_path);
856
+ ir_channel_names_path, testvector_path );
857
857
}
858
858
859
859
absl::Status SampleRunner::RunFromFiles (
860
860
const std::filesystem::path& input_path,
861
861
const std::filesystem::path& options_path,
862
- const std::optional<std::filesystem::path>& args_path,
863
- const std::optional<std::filesystem::path>& ir_channel_names_path) {
862
+ const std::optional<std::filesystem::path>& args_path, // deprecated
863
+ const std::optional<std::filesystem::path>& ir_channel_names_path, // ditto
864
+ const std::optional<std::filesystem::path>& testvector_path) {
864
865
VLOG (1 ) << " Running sample in directory " << run_dir_;
865
866
VLOG (1 ) << " Reading sample files." ;
866
867
@@ -874,10 +875,11 @@ absl::Status SampleRunner::RunFromFiles(
874
875
absl::Status status;
875
876
switch (options.sample_type ()) {
876
877
case fuzzer::SampleType::SAMPLE_TYPE_FUNCTION:
877
- status = RunFunction (input_path, options, args_path );
878
+ status = RunFunction (input_path, options, std::nullopt, testvector_path );
878
879
break ;
879
880
case fuzzer::SampleType::SAMPLE_TYPE_PROC:
880
- status = RunProc (input_path, options, args_path, ir_channel_names_path);
881
+ status = RunProc (input_path, options, std::nullopt, std::nullopt,
882
+ testvector_path);
881
883
break ;
882
884
default :
883
885
status = absl::InvalidArgumentError (
@@ -901,13 +903,21 @@ absl::Status SampleRunner::RunFromFiles(
901
903
902
904
absl::Status SampleRunner::RunFunction (
903
905
const std::filesystem::path& input_path, const SampleOptions& options,
904
- const std::optional<std::filesystem::path>& args_path) {
906
+ const std::optional<std::filesystem::path>& args_path,
907
+ const std::optional<std::filesystem::path>& testvector_path) {
905
908
XLS_ASSIGN_OR_RETURN (std::string input_text, GetFileContents (input_path));
906
909
907
910
std::optional<ArgsBatch> args_batch = std::nullopt;
908
911
if (args_path.has_value ()) {
909
912
XLS_ASSIGN_OR_RETURN (std::string args_text, GetFileContents (*args_path));
910
913
XLS_ASSIGN_OR_RETURN (args_batch, dslx::ParseArgsBatch (args_text));
914
+ } else if (testvector_path.has_value ()) {
915
+ testvector::SampleInputsProto sample_inputs;
916
+ XLS_RETURN_IF_ERROR (ParseTextProtoFile (*testvector_path, &sample_inputs));
917
+ ArgsBatch extracted;
918
+ XLS_RETURN_IF_ERROR (Sample::ExtractArgsBatch (/* is_proc_samples= */ false ,
919
+ sample_inputs, extracted));
920
+ args_batch = std::move (extracted);
911
921
}
912
922
913
923
absl::flat_hash_map<std::string, std::vector<dslx::InterpValue>> results;
@@ -938,20 +948,20 @@ absl::Status SampleRunner::RunFunction(
938
948
XLS_RETURN_IF_ERROR (SetFileContents (ir_path, input_text));
939
949
}
940
950
941
- if (args_path .has_value ()) {
951
+ if (args_batch .has_value ()) {
942
952
Stopwatch t;
943
953
944
954
// Unconditionally evaluate with the interpreter even if using the JIT. This
945
955
// exercises the interpreter and serves as a reference.
946
956
XLS_ASSIGN_OR_RETURN (results[" evaluated unopt IR (interpreter)" ],
947
- EvaluateIrFunction (ir_path, *args_path , false , options ,
948
- run_dir_, commands_));
957
+ EvaluateIrFunction (ir_path, *testvector_path , false ,
958
+ options, run_dir_, commands_));
949
959
timing_.set_unoptimized_interpret_ir_ns (
950
960
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
951
961
952
962
if (options.use_jit ()) {
953
963
XLS_ASSIGN_OR_RETURN (results[" evaluated unopt IR (JIT)" ],
954
- EvaluateIrFunction (ir_path, *args_path , true ,
964
+ EvaluateIrFunction (ir_path, *testvector_path , true ,
955
965
options, run_dir_, commands_));
956
966
timing_.set_unoptimized_jit_ns (
957
967
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
@@ -964,19 +974,21 @@ absl::Status SampleRunner::RunFunction(
964
974
OptimizeIr (ir_path, options, run_dir_, commands_));
965
975
timing_.set_optimize_ns (absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
966
976
967
- if (args_path .has_value ()) {
977
+ if (args_batch .has_value ()) {
968
978
if (options.use_jit ()) {
969
979
t.Reset ();
970
- XLS_ASSIGN_OR_RETURN (results[" evaluated opt IR (JIT)" ],
971
- EvaluateIrFunction (opt_ir_path, *args_path, true ,
972
- options, run_dir_, commands_));
980
+ XLS_ASSIGN_OR_RETURN (
981
+ results[" evaluated opt IR (JIT)" ],
982
+ EvaluateIrFunction (opt_ir_path, *testvector_path, true , options,
983
+ run_dir_, commands_));
973
984
timing_.set_optimized_jit_ns (
974
985
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
975
986
}
976
987
t.Reset ();
977
- XLS_ASSIGN_OR_RETURN (results[" evaluated opt IR (interpreter)" ],
978
- EvaluateIrFunction (opt_ir_path, *args_path, false ,
979
- options, run_dir_, commands_));
988
+ XLS_ASSIGN_OR_RETURN (
989
+ results[" evaluated opt IR (interpreter)" ],
990
+ EvaluateIrFunction (opt_ir_path, *testvector_path, false , options,
991
+ run_dir_, commands_));
980
992
timing_.set_optimized_interpret_ir_ns (
981
993
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
982
994
}
@@ -989,12 +1001,11 @@ absl::Status SampleRunner::RunFunction(
989
1001
timing_.set_codegen_ns (absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
990
1002
991
1003
if (options.simulate ()) {
992
- XLS_RET_CHECK (args_path.has_value ());
993
1004
t.Reset ();
994
1005
XLS_ASSIGN_OR_RETURN (
995
1006
results[" simulated" ],
996
- SimulateFunction (verilog_path, " module_sig.textproto" , *args_path,
997
- options, run_dir_, commands_));
1007
+ SimulateFunction (verilog_path, " module_sig.textproto" ,
1008
+ *testvector_path, options, run_dir_, commands_));
998
1009
timing_.set_simulate_ns (absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
999
1010
}
1000
1011
}
@@ -1009,20 +1020,31 @@ absl::Status SampleRunner::RunFunction(
1009
1020
absl::Status SampleRunner::RunProc (
1010
1021
const std::filesystem::path& input_path, const SampleOptions& options,
1011
1022
const std::optional<std::filesystem::path>& args_path,
1012
- const std::optional<std::filesystem::path>& ir_channel_names_path) {
1023
+ const std::optional<std::filesystem::path>& ir_channel_names_path,
1024
+ const std::optional<std::filesystem::path>& testvector_path) {
1013
1025
XLS_ASSIGN_OR_RETURN (std::string input_text, GetFileContents (input_path));
1014
1026
1015
1027
std::optional<ArgsBatch> args_batch = std::nullopt;
1028
+ std::optional<std::vector<std::string>> ir_channel_names = std::nullopt;
1029
+
1016
1030
if (args_path.has_value ()) {
1017
1031
XLS_ASSIGN_OR_RETURN (std::string args_text, GetFileContents (*args_path));
1018
1032
XLS_ASSIGN_OR_RETURN (args_batch, dslx::ParseArgsBatch (args_text));
1019
- }
1020
-
1021
- std::optional<std::vector<std::string>> ir_channel_names = std::nullopt;
1022
- if (ir_channel_names_path.has_value ()) {
1023
- XLS_ASSIGN_OR_RETURN (std::string ir_channel_names_text,
1024
- GetFileContents (*ir_channel_names_path));
1025
- ir_channel_names = ParseIrChannelNames (ir_channel_names_text);
1033
+ if (ir_channel_names_path.has_value ()) {
1034
+ XLS_ASSIGN_OR_RETURN (std::string ir_channel_names_text,
1035
+ GetFileContents (*ir_channel_names_path));
1036
+ ir_channel_names = ParseIrChannelNames (ir_channel_names_text);
1037
+ }
1038
+ } else if (testvector_path.has_value ()) {
1039
+ testvector::SampleInputsProto sample_inputs;
1040
+ XLS_RETURN_IF_ERROR (ParseTextProtoFile (*testvector_path, &sample_inputs));
1041
+ ArgsBatch extracted_args;
1042
+ std::vector<std::string> extracted_channel_names;
1043
+ XLS_RETURN_IF_ERROR (Sample::ExtractArgsBatch (/* is_proc_samples= */ true ,
1044
+ sample_inputs, extracted_args,
1045
+ &extracted_channel_names));
1046
+ args_batch = std::move (extracted_args);
1047
+ ir_channel_names = std::move (extracted_channel_names);
1026
1048
}
1027
1049
1028
1050
std::string ir_channel_values_file_content;
@@ -1102,10 +1124,9 @@ absl::Status SampleRunner::RunProc(
1102
1124
// Unconditionally evaluate with the interpreter even if using the JIT. This
1103
1125
// exercises the interpreter and serves as a reference.
1104
1126
Stopwatch t;
1105
- XLS_ASSIGN_OR_RETURN (
1106
- results[" evaluated unopt IR (interpreter)" ],
1107
- EvaluateIrProc (ir_path, tick_count, ir_channel_values_path, false ,
1108
- options, run_dir_, commands_));
1127
+ XLS_ASSIGN_OR_RETURN (results[" evaluated unopt IR (interpreter)" ],
1128
+ EvaluateIrProc (ir_path, tick_count, *testvector_path,
1129
+ false , options, run_dir_, commands_));
1109
1130
if (!reference.has_value ()) {
1110
1131
reference = results[" evaluated unopt IR (interpreter)" ];
1111
1132
}
@@ -1114,10 +1135,9 @@ absl::Status SampleRunner::RunProc(
1114
1135
1115
1136
if (options.use_jit ()) {
1116
1137
t.Reset ();
1117
- XLS_ASSIGN_OR_RETURN (
1118
- results[" evaluated unopt IR (JIT)" ],
1119
- EvaluateIrProc (ir_path, tick_count, ir_channel_values_path, true ,
1120
- options, run_dir_, commands_));
1138
+ XLS_ASSIGN_OR_RETURN (results[" evaluated unopt IR (JIT)" ],
1139
+ EvaluateIrProc (ir_path, tick_count, *testvector_path,
1140
+ true , options, run_dir_, commands_));
1121
1141
timing_.set_unoptimized_jit_ns (
1122
1142
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
1123
1143
}
@@ -1135,17 +1155,17 @@ absl::Status SampleRunner::RunProc(
1135
1155
t.Reset ();
1136
1156
XLS_ASSIGN_OR_RETURN (
1137
1157
results[" evaluated opt IR (JIT)" ],
1138
- EvaluateIrProc (*opt_ir_path, tick_count, ir_channel_values_path ,
1139
- true , options, run_dir_, commands_));
1158
+ EvaluateIrProc (*opt_ir_path, tick_count, *testvector_path, true ,
1159
+ options, run_dir_, commands_));
1140
1160
timing_.set_optimized_jit_ns (
1141
1161
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
1142
1162
}
1143
1163
1144
1164
t.Reset ();
1145
1165
XLS_ASSIGN_OR_RETURN (
1146
1166
results[" evaluated opt IR (interpreter)" ],
1147
- EvaluateIrProc (*opt_ir_path, tick_count, ir_channel_values_path ,
1148
- false , options, run_dir_, commands_));
1167
+ EvaluateIrProc (*opt_ir_path, tick_count, *testvector_path, false ,
1168
+ options, run_dir_, commands_));
1149
1169
timing_.set_optimized_interpret_ir_ns (
1150
1170
absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
1151
1171
@@ -1166,8 +1186,8 @@ absl::Status SampleRunner::RunProc(
1166
1186
XLS_ASSIGN_OR_RETURN (
1167
1187
results[" simulated" ],
1168
1188
SimulateProc (verilog_path, " module_sig.textproto" ,
1169
- ir_channel_values_path , output_channel_counts_str,
1170
- options, run_dir_, commands_));
1189
+ *testvector_path , output_channel_counts_str, options ,
1190
+ run_dir_, commands_));
1171
1191
timing_.set_simulate_ns (absl::ToInt64Nanoseconds (t.GetElapsedTime ()));
1172
1192
}
1173
1193
}
0 commit comments