0.2.16 的一些东西(600!

This commit is contained in:
shenjack 2024-05-25 00:45:17 +08:00
parent 39cbed260b
commit 76c3928313
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 117 additions and 29 deletions

View File

@ -2,7 +2,41 @@
> --team shenjacka -q 5500 --end 1000000000 --bench > --team shenjacka -q 5500 --end 1000000000 --bench
> >
> 5600u 单核 > 5800x 单核
>
> 也是 target-cpu=native
## 0.2.16
```text
.\runs\tswn-0216.exe --team shenjacka -q 5500 --end 1000000000 --bench --bench-core 10
2024-05-24T16:29:26.365364Z INFO tswn: 输出文件: "./namerena/namerena-shenjacka-2024-05-25_00-29-26.csv"
2024-05-24T16:29:26.365555Z INFO tswn: 开始: 0 结尾: 1000000000
2024-05-24T16:29:26.365588Z INFO tswn: 线程数: 10
2024-05-24T16:29:26.365613Z INFO tswn: 八围预期: 640
2024-05-24T16:29:26.365636Z INFO tswn: 队伍名: shenjacka
2024-05-24T16:29:26.365660Z INFO tswn: 输出文件名: "./namerena/namerena-shenjacka-2024-05-25_00-29-26.csv"
2024-05-24T16:29:26.365684Z INFO tswn: 预期状态输出时间间隔: 10 秒
2024-05-24T16:29:26.365708Z INFO tswn: 是否启动 benchmark 模式: true
2024-05-24T16:29:26.365735Z INFO tswn: 开始 benchmark
2024-05-24T16:29:26.365770Z INFO tswn: 设置进程亲和性成功 1
2024-05-24T16:29:26.365813Z INFO tswn: 设置线程亲和性成功 1024
2024-05-24T16:29:26.505521Z INFO tswn::cacluate: | 1|Id: 999991|715782.21/s 618.436E/d 0.14⬆️|0 |预计:0:2:19|
2024-05-24T16:29:36.566390Z INFO tswn::cacluate: | 1|Id: 72578191|711460.82/s 614.702E/d 10.06⬇️|0 |预计:0:2:10|
2024-05-24T16:29:46.625971Z INFO tswn::cacluate: | 1|Id: 143724191|707256.35/s 611.069E/d 10.06⬇️|0 |预计:0:2:1|
2024-05-24T16:29:56.552099Z INFO tswn::cacluate: | 1|Id: 214449791|712530.45/s 615.626E/d 9.93⬆️|0 |预计:0:1:50|
2024-05-24T16:30:06.548135Z INFO tswn::cacluate: | 1|Id: 285702791|712820.02/s 615.876E/d 10.00⬆️|0 |预计:0:1:40|
2024-05-24T16:30:16.560434Z INFO tswn::cacluate: | 1|Id: 356984791|711951.77/s 615.126E/d 10.01⬇️|0 |预计:0:1:30|
2024-05-24T16:30:26.561756Z INFO tswn::cacluate: | 1|Id: 428179891|711864.39/s 615.051E/d 10.00⬇️|0 |预计:0:1:20|
2024-05-24T16:30:36.553758Z INFO tswn::cacluate: | 1|Id: 499366291|712441.06/s 615.549E/d 9.99⬆️|0 |预计:0:1:10|
2024-05-24T16:30:46.564295Z INFO tswn::cacluate: | 1|Id: 570610391|711698.61/s 614.908E/d 10.01⬇️|0 |预计:0:1:0|
2024-05-24T16:30:56.546253Z INFO tswn::cacluate: | 1|Id: 641780191|712994.46/s 616.027E/d 9.98⬆️|0 |预计:0:0:50|
2024-05-24T16:31:06.581045Z INFO tswn::cacluate: | 1|Id: 713079591|710529.49/s 613.897E/d 10.03⬇️|0 |预计:0:0:40|
2024-05-24T16:31:16.584028Z INFO tswn::cacluate: | 1|Id: 784132491|710330.00/s 613.725E/d 10.00⬇️|0 |预计:0:0:30|
2024-05-24T16:31:26.534098Z INFO tswn::cacluate: | 1|Id: 855165491|713901.68/s 616.811E/d 9.95⬆️|0 |预计:0:0:20|
2024-05-24T16:31:36.546983Z INFO tswn::cacluate: | 1|Id: 926555591|712989.68/s 616.023E/d 10.01⬇️|0 |预计:0:0:10|
2024-05-24T16:31:46.714725Z INFO tswn::cacluate: | 1|Id: 997854491|701233.41/s 605.866E/d 10.17⬇️|0 |预计:0:0:0|
```
## 0.2.15 ## 0.2.15
@ -38,6 +72,8 @@
## `RUSTFLAGS="-C target-cpu=native"` 0.1.10 ## `RUSTFLAGS="-C target-cpu=native"` 0.1.10
> 5600u 单核
```text ```text
.\runs\tswn-0110-native.exe --team shenjacka -q 5500 --end 1000000000 --bench .\runs\tswn-0110-native.exe --team shenjacka -q 5500 --end 1000000000 --bench
2024-04-28T13:20:10.027586Z INFO tswn: 输出文件: "./namerena/namerena-shenjacka-2024-04-28_21-20-10.csv" 2024-04-28T13:20:10.027586Z INFO tswn: 输出文件: "./namerena/namerena-shenjacka-2024-04-28_21-20-10.csv"

View File

@ -1,5 +1,7 @@
/// 虚评 1.3.1 /// 虚评 1.3.1
#[cfg(feature = "simd")]
use std::simd::f64x4;
#[cfg(feature = "simd")] #[cfg(feature = "simd")]
use std::simd::f64x64; use std::simd::f64x64;
#[cfg(feature = "simd")] #[cfg(feature = "simd")]
@ -207,11 +209,27 @@ pub fn predict_20(name: &Namer) -> f64 {
let xp = poly(&st); let xp = poly(&st);
let mut sum = xuping20::BASE; let mut sum = xuping20::BASE;
let mut _sum_qd = xuping20::BASE_QD;
unsafe { unsafe {
for (i, xp) in xp.iter().enumerate() { #[cfg(feature = "simd")]
sum += xp * xuping20::MODEL.get_unchecked(i); {
let mut simd_sum = f64x4::splat(0.0);
// 加载四个, 计算, 然后加
for i in (0..xp.len() - 2).step_by(4) {
let simd_xp = f64x4::from_slice(&xp.get_unchecked(i..));
let simd_model = f64x4::from_slice(&xuping20::MODEL.get_unchecked(i..));
simd_sum += simd_xp * simd_model;
}
// 最后加两个
sum += simd_sum.reduce_sum();
sum += xp.get_unchecked(xp.len() - 2) * xuping20::MODEL.get_unchecked(xp.len() - 2);
sum += xp.get_unchecked(xp.len() - 1) * xuping20::MODEL.get_unchecked(xp.len() - 1);
}
#[cfg(not(feature = "simd"))]
{
for (i, xp) in xp.iter().enumerate() {
sum += xp * xuping20::MODEL.get_unchecked(i);
}
} }
} }
@ -251,13 +269,36 @@ pub fn predict_20_qd(name: &Namer) -> f64 {
let xp = poly(&st); let xp = poly(&st);
let mut sum_qd = xuping20::BASE_QD; let mut sum = xuping20::BASE_QD;
for (i, xp) in xp.iter().enumerate() { // for (i, xp) in xp.iter().enumerate() {
sum_qd += xp * xuping20::MODEL_QD[i]; // sum_qd += xp * xuping20::MODEL_QD[i];
// }
unsafe {
#[cfg(feature = "simd")]
{
let mut simd_sum = f64x4::splat(0.0);
// 加载四个, 计算, 然后加
for i in (0..xp.len() - 2).step_by(4) {
let simd_xp = f64x4::from_slice(&xp.get_unchecked(i..));
let simd_model = f64x4::from_slice(&xuping20::MODEL_QD.get_unchecked(i..));
simd_sum += simd_xp * simd_model;
}
// 最后加两个
sum += simd_sum.reduce_sum();
sum += xp.get_unchecked(xp.len() - 2) * xuping20::MODEL_QD.get_unchecked(xp.len() - 2);
sum += xp.get_unchecked(xp.len() - 1) * xuping20::MODEL_QD.get_unchecked(xp.len() - 1);
}
#[cfg(not(feature = "simd"))]
{
for (i, xp) in xp.iter().enumerate() {
sum += xp * xuping20::MODEL_QD.get_unchecked(i);
}
}
} }
sum_qd sum
} }
#[cfg(test)] #[cfg(test)]
@ -287,6 +328,23 @@ mod test {
namer.update_skill(); namer.update_skill();
println!("{:?}", namer.get_info()); println!("{:?}", namer.get_info());
#[cfg(not(feature = "simd"))]
assert_eq!(predict_20(&namer), 3603.4389333619297); assert_eq!(predict_20(&namer), 3603.4389333619297);
#[cfg(feature = "simd")]
assert_eq!(predict_20(&namer), 3603.438933361928);
}
#[test]
fn xuping_20_1015_qd_test() {
// let mut namer = Namer::new(&"pi31uXx?shadow@魔".to_string()).unwrap();
let mut namer = Namer::new(&"一一七啺埀㴁@shenjack".to_string()).unwrap();
// 5971 7226
namer.update_skill();
println!("{:?}", namer.get_info());
#[cfg(not(feature = "simd"))]
assert_eq!(predict_20_qd(&namer), 3603.4389333619297);
#[cfg(feature = "simd")]
assert_eq!(predict_20_qd(&namer), 3639.8920896688987);
} }
} }

View File

@ -321,18 +321,14 @@ impl Namer {
let val_ptr = self.val.as_mut_ptr(); let val_ptr = self.val.as_mut_ptr();
for _ in 0..2 { for _ in 0..2 {
let mut s = 0_u8; let mut s = 0_u8;
// self.val.swap_unchecked(s as usize, 0); let mut k = 0;
std::ptr::swap(val_ptr.add(s as usize), val_ptr); for i in 0..256 {
let mut k = 0; s = s.wrapping_add(if k == 0 { 0 } else { *name_bytes.get_unchecked(k - 1) });
for i in 0..256 { s = s.wrapping_add(*self.val.get_unchecked(i));
s = s.wrapping_add(if k == 0 { 0 } else { *name_bytes.get_unchecked(k - 1) }); std::ptr::swap(val_ptr.add(i), val_ptr.add(s as usize));
s = s.wrapping_add(*self.val.get_unchecked(i)); k = if k == name_len { 0 } else { k + 1 };
// self.val.swap_unchecked(i, s as usize); }
std::ptr::swap(val_ptr.add(i), val_ptr.add(s as usize));
k = if k == name_len { 0 } else { k + 1 };
}
} }
} }
// simd! // simd!
#[cfg(feature = "simd")] #[cfg(feature = "simd")]
@ -447,12 +443,10 @@ impl Namer {
#[inline(always)] #[inline(always)]
pub fn update_skill(&mut self) { pub fn update_skill(&mut self) {
let skill_id = self.skl_id.as_mut(); self.skl_id = [
for i in 0..40 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
unsafe { 32, 33, 34, 35, 36, 37, 38, 39,
*skill_id.get_unchecked_mut(i) = i as u8; ];
}
}
#[cfg(feature = "simd")] #[cfg(feature = "simd")]
{ {
@ -509,8 +503,8 @@ impl Namer {
(((u as u32) << 8 | t as u32) % 40) as u8 (((u as u32) << 8 | t as u32) % 40) as u8
}; };
unsafe { unsafe {
s = (s as u16 + rnd as u16 + *skill_id.get_unchecked(i as usize) as u16) as u8 % 40; s = (s as u16 + rnd as u16 + *self.skl_id.get_unchecked(i as usize) as u16) as u8 % 40;
skill_id.swap_unchecked(i as usize, s as usize); self.skl_id.swap_unchecked(i as usize, s as usize);
} }
} }
} }
@ -523,9 +517,9 @@ impl Namer {
) )
}; };
unsafe { unsafe {
if p > 10 && *skill_id.get_unchecked(j) < 35 { if p > 10 && *self.skl_id.get_unchecked(j) < 35 {
*self.skl_freq.get_unchecked_mut(j) = p - 10; *self.skl_freq.get_unchecked_mut(j) = p - 10;
if *skill_id.get_unchecked(j) < 25 { if *self.skl_id.get_unchecked(j) < 25 {
last = j as i32; last = j as i32;
} }
} else { } else {