mirror of
https://github.com/tig-pool-nk/tig-monorepo.git
synced 2026-02-21 11:29:31 +08:00
Add verbose to tig-verifier.
This commit is contained in:
parent
d1eaab5729
commit
42cfe667e8
@ -176,23 +176,29 @@ f"""Library not found at {so_path}:
|
||||
output_file = f"{temp_dir}/{nonce}.json"
|
||||
ret2 = None
|
||||
elapsed2 = 0
|
||||
if os.path.exists(output_file):
|
||||
cmd2 = [
|
||||
args.tig_verifier_path,
|
||||
json.dumps(settings, separators=(',',':')),
|
||||
args.seed,
|
||||
str(nonce),
|
||||
f"{temp_dir}/{nonce}.json",
|
||||
|
||||
cmd2 = [
|
||||
args.tig_verifier_path,
|
||||
json.dumps(settings, separators=(',',':')),
|
||||
args.seed,
|
||||
str(nonce),
|
||||
output_file,
|
||||
]
|
||||
if ptx_path is not None:
|
||||
cmd2 += [
|
||||
"--ptx", ptx_path,
|
||||
"--gpu", str(nonce % len(VISIBLE_GPUS)),
|
||||
]
|
||||
if ptx_path is not None:
|
||||
cmd2 += [
|
||||
"--ptx", ptx_path,
|
||||
"--gpu", str(nonce % len(VISIBLE_GPUS)),
|
||||
]
|
||||
if args.verbose:
|
||||
cmd2 += ["--verbose"]
|
||||
print(f"[nonce {nonce}] {' '.join(cmd2[:1] + [f"'{cmd2[1]}'"] + cmd2[2:])}")
|
||||
ret2 = subprocess.Popen(cmd2, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, universal_newlines=True)
|
||||
for line in ret2.stdout:
|
||||
if args.verbose:
|
||||
print(f"[nonce {nonce}] {' '.join(cmd2[:1] + [f"'{cmd2[1]}'"] + cmd2[2:])}")
|
||||
ret2 = subprocess.run(cmd2, capture_output=True, text=True)
|
||||
elapsed2 = now() - start - elapsed
|
||||
print(f"[nonce {nonce}] {line.strip()}")
|
||||
ret2.wait()
|
||||
elapsed2 = now() - start - elapsed
|
||||
|
||||
if args.verbose:
|
||||
out = f"[nonce {nonce}] finished\n\ttig-runtime\n\t\telapsed: {elapsed}ms\n\t\texit code: {ret.returncode}\n\t\tstderr: "
|
||||
if ret.returncode != 0:
|
||||
|
||||
@ -28,6 +28,7 @@ fn cli() -> Command {
|
||||
)
|
||||
.arg(arg!(--ptx [PTX] "Path to a CUDA ptx file").value_parser(clap::value_parser!(PathBuf)))
|
||||
.arg(arg!(--gpu [GPU] "Which GPU device to use").value_parser(clap::value_parser!(usize)))
|
||||
.arg(arg!(--verbose "Enable verbose output").action(clap::ArgAction::SetTrue))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -40,6 +41,7 @@ fn main() {
|
||||
matches.get_one::<String>("SOLUTION").unwrap().clone(),
|
||||
matches.get_one::<PathBuf>("ptx").cloned(),
|
||||
matches.get_one::<usize>("gpu").cloned(),
|
||||
matches.get_one::<bool>("verbose").cloned().unwrap_or(false),
|
||||
) {
|
||||
eprintln!("Error: {}", e);
|
||||
std::process::exit(1);
|
||||
@ -53,9 +55,9 @@ pub fn verify_solution(
|
||||
solution_path: String,
|
||||
ptx_path: Option<PathBuf>,
|
||||
gpu_device: Option<usize>,
|
||||
verbose: bool,
|
||||
) -> Result<()> {
|
||||
let settings = load_settings(&settings);
|
||||
let solution = load_solution(&solution_path);
|
||||
let seed = settings.calc_seed(&rand_hash, nonce);
|
||||
|
||||
let mut err_msg = Option::<String>::None;
|
||||
@ -64,12 +66,21 @@ pub fn verify_solution(
|
||||
($c:ident, cpu) => {{
|
||||
let challenge =
|
||||
$c::Challenge::generate_instance(&seed, &settings.difficulty.into()).unwrap();
|
||||
if verbose {
|
||||
println!("{:?}", challenge);
|
||||
}
|
||||
|
||||
let solution = load_solution(&solution_path);
|
||||
match serde_json::from_str::<$c::Solution>(&solution) {
|
||||
Ok(solution) => match challenge.verify_solution(&solution) {
|
||||
Ok(_) => println!("Solution is valid"),
|
||||
Err(e) => err_msg = Some(format!("Invalid solution: {}", e)),
|
||||
},
|
||||
Ok(solution) => {
|
||||
if verbose {
|
||||
println!("{:?}", solution);
|
||||
}
|
||||
match challenge.verify_solution(&solution) {
|
||||
Ok(_) => println!("Solution is valid"),
|
||||
Err(e) => err_msg = Some(format!("Invalid solution: {}", e)),
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
err_msg = Some(format!(
|
||||
"Invalid solution. Cannot convert to {}::Solution",
|
||||
@ -105,8 +116,12 @@ pub fn verify_solution(
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let solution = load_solution(&solution_path);
|
||||
match serde_json::from_str::<$c::Solution>(&solution) {
|
||||
Ok(solution) => {
|
||||
if verbose {
|
||||
println!("{:?}", solution);
|
||||
}
|
||||
match challenge.verify_solution(
|
||||
&solution,
|
||||
module.clone(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user