diff --git a/tig-runtime/src/main.rs b/tig-runtime/src/main.rs index 248b25bf..a5bc421c 100644 --- a/tig-runtime/src/main.rs +++ b/tig-runtime/src/main.rs @@ -2,7 +2,7 @@ use anyhow::{anyhow, Result}; use clap::{arg, Command}; use libloading::Library; use serde_json::{Map, Value}; -use std::{fs, panic, path::PathBuf}; +use std::{cell::RefCell, fs, panic, path::PathBuf}; use tig_challenges::*; use tig_structs::core::{BenchmarkSettings, CPUArchitecture, OutputData}; use tig_utils::{dejsonify, jsonify}; @@ -132,6 +132,8 @@ pub fn compute_solution( let challenge = $c::Challenge::generate_instance(&seed, &track)?; + let count = RefCell::new(0); + let snapshots = RefCell::new(vec![(0, 0)]); let save_solution_fn = |solution: &$c::Solution| -> Result<()> { let fuel_consumed = (max_fuel - unsafe { **library.get::<*const u64>(b"__fuel_remaining")? }) @@ -139,6 +141,9 @@ pub fn compute_solution( let runtime_signature = unsafe { **library.get::<*const u64>(b"__runtime_signature")? }; + let mut snapshots = snapshots.borrow_mut(); + *snapshots.last_mut().unwrap() = (fuel_consumed, runtime_signature); + let solution = serde_json::to_string(&solution)?; let output_data = OutputData { @@ -146,12 +151,19 @@ pub fn compute_solution( runtime_signature, fuel_consumed, solution, + snapshots: snapshots.clone(), #[cfg(target_arch = "x86_64")] cpu_arch: CPUArchitecture::AMD64, #[cfg(target_arch = "aarch64")] cpu_arch: CPUArchitecture::ARM64, }; fs::write(&output_file, jsonify(&output_data))?; + + let mut count: usize = *count.borrow_mut(); + count += 1; + if count.is_power_of_two() { + snapshots.push((0, 0)); + } Ok(()) }; let result = solve_challenge_fn(&challenge, &save_solution_fn, hyperparameters); @@ -233,6 +245,8 @@ pub fn compute_solution( .launch(cfg)?; } + let count = RefCell::new(0); + let snapshots = RefCell::new(vec![(0, 0)]); let save_solution_fn = |solution: &$c::Solution| -> Result<()> { stream.synchronize()?; ctx.synchronize()?; @@ -268,6 +282,9 @@ pub fn compute_solution( unsafe { **library.get::<*const u64>(b"__runtime_signature")? }; let runtime_signature = gpu_runtime_signature ^ cpu_runtime_signature; + let mut snapshots = snapshots.borrow_mut(); + *snapshots.last_mut().unwrap() = (fuel_consumed, runtime_signature); + let solution = serde_json::to_string(&solution)?; let output_data = OutputData { @@ -275,12 +292,19 @@ pub fn compute_solution( runtime_signature, fuel_consumed, solution, + snapshots: snapshots.clone(), #[cfg(target_arch = "x86_64")] cpu_arch: CPUArchitecture::AMD64, #[cfg(target_arch = "aarch64")] cpu_arch: CPUArchitecture::ARM64, }; fs::write(&output_file, jsonify(&output_data))?; + + let mut count: usize = *count.borrow_mut(); + count += 1; + if count.is_power_of_two() { + snapshots.push((0, 0)); + } Ok(()) }; let result = solve_challenge_fn( diff --git a/tig-structs/src/core.rs b/tig-structs/src/core.rs index fa2d2080..940a9ab9 100644 --- a/tig-structs/src/core.rs +++ b/tig-structs/src/core.rs @@ -447,13 +447,14 @@ serializable_struct_with_getters! { nonce: u64, runtime_signature: u64, fuel_consumed: u64, + snapshots: Vec<(u64, u64)>, solution: String, cpu_arch: CPUArchitecture, } } impl OutputData { pub fn calc_solution_signature(&self) -> u64 { - u64s_from_str(&jsonify(&self.solution))[0] + u64s_from_str(&jsonify(&self.solution))[0] ^ u64s_from_str(&jsonify(&self.snapshots))[0] } }