code wiki / _hdl_build / nx_racing.nx

nx_racing.nx source

↩ module page · 62 lines · 3020 B

1// nx_racing.nx -- the RACING role = COMPETE (operator: don't miss the novel roles; this was the one 2// missing capability). Racing RUNS the head-to-head 'tracks' -- our solution vs a competitor (gcc/clang/ 3// the field) on the same task -- and COLLECTS both results. It does NOT judge: that is the REFEREE's 4// verb (JUDGE). Folding Racing into Referee was the v1 roster error -- COMPETE and JUDGE are distinct. 5// Racing's job: set up a FAIR track (same input + same oracle for both), run both competitors, record 6// the two results, and hand them to the Referee. RACI: Racing produces RESULTS; Referee renders the 7// VERDICT; Examiner self-grades; Critic counters; Auditor audits -- five distinct evaluation verbs. 8// LAWS: struct-free, integer-only. Composes nx_role_audit (ra_distinct). license_tier: ORIGINAL 9import "nx_role_audit.nx" 10import "nx_syscalls.nx" 11 12const RC_PENDING: i64 = 0 13const RC_RAN: i64 = 1 14 15// a track is FAIR iff both competitors got the SAME input AND were measured by the SAME oracle. 16// (an unfair race -- different input or different oracle -- is not a real comparison.) 17func rc_track_fair(our_input: i64, their_input: i64, our_oracle: i64, their_oracle: i64) -> i64 { 18 if our_input != their_input { return 0 } 19 if our_oracle != their_oracle { return 0 } 20 return 1 21} 22 23// run one track: record both results (Racing RUNS + COLLECTS, never judges). returns RC_RAN. 24// out[0]=our_metric out[1]=their_metric out[2]=fair 25func rc_run_track(our_metric: i64, their_metric: i64, fair: i64, out: *i64) -> i64 { 26 out[0] = our_metric 27 out[1] = their_metric 28 out[2] = fair 29 return RC_RAN 30} 31 32// all tracks run? (the suite is complete and ready to hand to the Referee) 33func rc_all_ran(status: *i64, n: i64) -> i64 { 34 var i: i64 = 0 35 while i < n { if status[i] != RC_RAN { return 0 } i = i + 1 } 36 return 1 37} 38 39// RACI GUARD: Racing's verb (COMPETE) must be DISTINCT from the Referee's (JUDGE). Returns 1 if the 40// roles are correctly separated -- the exact v1 error (folding Racing into Referee) is caught here. 41const RC_VERB_COMPETE: i64 = 12 // Racing 42const RC_VERB_JUDGE: i64 = 5 // Referee 43func rc_separate_from_referee() -> i64 { return ra_distinct(RC_VERB_COMPETE, RC_VERB_JUDGE) } 44 45// Racing must NOT itself decide the winner -- it only reports results. (a guard so the capability can't 46// quietly become a judge.) returns 1 if `judged_by` is the Referee, 0 if Racing tried to self-judge. 47func rc_hands_to_referee(judged_by_verb: i64) -> i64 { 48 if judged_by_verb == RC_VERB_JUDGE { return 1 } 49 return 0 50} 51 52// suite-level COMPETE summary: how many tracks our side won outright (their_metric beaten on a 53// lower-is-better metric, e.g. cycles/bytes). Racing REPORTS the tally; the Referee ratifies the verdict. 54func rc_tracks_we_lead(our: *i64, their: *i64, fair: *i64, n: i64) -> i64 { 55 var wins: i64 = 0 56 var i: i64 = 0 57 while i < n { 58 if fair[i] == 1 { if our[i] < their[i] { wins = wins + 1 } } 59 i = i + 1 60 } 61 return wins 62}