Upload folder using huggingface_hub
Browse files- neural_engine/src/main.rs +25 -2
neural_engine/src/main.rs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
use std::collections::{HashMap, HashSet};
|
| 2 |
use std::io::{self, BufRead};
|
| 3 |
use std::sync::{Arc, Mutex};
|
| 4 |
-
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
|
|
|
| 5 |
use dashmap::DashMap;
|
| 6 |
use shakmaty::{Chess, Move, Position, Setup, CastlingMode};
|
| 7 |
use shakmaty::zobrist::{Zobrist64, ZobristHash};
|
|
@@ -237,6 +239,7 @@ fn alpha_beta(
|
|
| 237 |
stop_flag: &AtomicBool,
|
| 238 |
is_null: bool,
|
| 239 |
) -> f32 {
|
|
|
|
| 240 |
if stop_flag.load(Ordering::Relaxed) { return 0.0; }
|
| 241 |
|
| 242 |
if let Some(tb) = tablebases {
|
|
@@ -438,6 +441,8 @@ fn main() {
|
|
| 438 |
}
|
| 439 |
|
| 440 |
tt.clear();
|
|
|
|
|
|
|
| 441 |
let stop_flag = Arc::new(AtomicBool::new(false));
|
| 442 |
let mut handles = Vec::new();
|
| 443 |
|
|
@@ -452,7 +457,7 @@ fn main() {
|
|
| 452 |
root_cache = Some(compute_root_kv_cache(&mut sess, &history_moves, &vocab));
|
| 453 |
}
|
| 454 |
|
| 455 |
-
for
|
| 456 |
let t_board = board.clone();
|
| 457 |
let mut t_history = history_moves.clone();
|
| 458 |
let t_vocab = Arc::clone(&vocab);
|
|
@@ -518,6 +523,24 @@ fn main() {
|
|
| 518 |
);
|
| 519 |
}
|
| 520 |
prev_score = score;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
}
|
| 522 |
});
|
| 523 |
handles.push(handle);
|
|
|
|
| 1 |
use std::collections::{HashMap, HashSet};
|
| 2 |
use std::io::{self, BufRead};
|
| 3 |
use std::sync::{Arc, Mutex};
|
| 4 |
+
use std::sync::atomic::{AtomicU64, AtomicBool, Ordering};
|
| 5 |
+
|
| 6 |
+
static NODES_SEARCHED: AtomicU64 = AtomicU64::new(0);
|
| 7 |
use dashmap::DashMap;
|
| 8 |
use shakmaty::{Chess, Move, Position, Setup, CastlingMode};
|
| 9 |
use shakmaty::zobrist::{Zobrist64, ZobristHash};
|
|
|
|
| 239 |
stop_flag: &AtomicBool,
|
| 240 |
is_null: bool,
|
| 241 |
) -> f32 {
|
| 242 |
+
NODES_SEARCHED.fetch_add(1, Ordering::Relaxed);
|
| 243 |
if stop_flag.load(Ordering::Relaxed) { return 0.0; }
|
| 244 |
|
| 245 |
if let Some(tb) = tablebases {
|
|
|
|
| 441 |
}
|
| 442 |
|
| 443 |
tt.clear();
|
| 444 |
+
NODES_SEARCHED.store(0, Ordering::Relaxed);
|
| 445 |
+
let start_time = std::time::Instant::now();
|
| 446 |
let stop_flag = Arc::new(AtomicBool::new(false));
|
| 447 |
let mut handles = Vec::new();
|
| 448 |
|
|
|
|
| 457 |
root_cache = Some(compute_root_kv_cache(&mut sess, &history_moves, &vocab));
|
| 458 |
}
|
| 459 |
|
| 460 |
+
for thread_id in 0..num_threads {
|
| 461 |
let t_board = board.clone();
|
| 462 |
let mut t_history = history_moves.clone();
|
| 463 |
let t_vocab = Arc::clone(&vocab);
|
|
|
|
| 523 |
);
|
| 524 |
}
|
| 525 |
prev_score = score;
|
| 526 |
+
|
| 527 |
+
let is_main_thread = thread_id == 0;
|
| 528 |
+
if is_main_thread && !t_stop_flag.load(Ordering::Relaxed) {
|
| 529 |
+
let elapsed = start_time.elapsed().as_secs_f64();
|
| 530 |
+
let n = NODES_SEARCHED.load(Ordering::Relaxed);
|
| 531 |
+
let nps = if elapsed > 0.0 { (n as f64 / elapsed) as u64 } else { 0 };
|
| 532 |
+
let cp = (prev_score * 100.0) as i32;
|
| 533 |
+
|
| 534 |
+
let mut pv = String::new();
|
| 535 |
+
if let Some(entry) = t_tt.get(&global_root_hash) {
|
| 536 |
+
if let Some(m) = &entry.best_move {
|
| 537 |
+
pv = m.to_string();
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
println!("info depth {} score cp {} nodes {} nps {} time {} pv {}",
|
| 542 |
+
depth, cp, n, nps, (elapsed * 1000.0) as u64, pv);
|
| 543 |
+
}
|
| 544 |
}
|
| 545 |
});
|
| 546 |
handles.push(handle);
|