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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
pub mod host;
pub mod manager;
pub mod output;
pub use manager::*;
type MaskMessage = (u64, u32, Vec<u64>);
type RowMessage = (u64, Vec<Vec<u32>>);
#[derive(Debug)]
pub enum Message {
CheckRequest(CheckRequest),
HostMessage(MaskMessage),
OutputMessage(RowMessage),
ResultMessage(ResultMessage),
RowResult(RowResult),
Terminate,
CpuDone,
GpuDone,
}
#[derive(Debug)]
pub struct ResultMessage {
data: Vec<u64>,
offset: usize,
size: usize,
wg_size: usize,
id: u64,
}
impl ResultMessage {
fn new(data: Vec<u64>, offset: usize, size: usize, wg_size: usize, id: u64) -> Self {
Self {
data,
offset,
size,
wg_size,
id,
}
}
fn valid_walls(&self) -> Vec<Vec<u32>> {
let mut result = vec![Vec::new(); self.wg_size];
for (j, r) in self.data.iter().enumerate() {
for b in 0..64 {
if r & (1 << b) != 0 {
let permutation = j / self.size + self.offset;
let instruction = (j % self.size) * 64 + b;
result[instruction].push(permutation as u32);
}
}
}
result
}
}
#[derive(Debug)]
pub struct CheckRequest {
rows: Vec<u32>,
bitmask: u64,
queue: u32,
}
impl CheckRequest {
pub fn new(rows: Vec<u32>, bitmask: u64, queue: u32) -> Self {
Self {
rows,
bitmask,
queue,
}
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct RowResult {
rows: Vec<u32>,
}
impl RowResult {
fn new(mut rows: Vec<u32>) -> Self {
//rows.push(0);
rows.sort();
Self { rows }
}
fn output(&self) {
/*let s = self
.rows
.iter()
.fold(String::new(), |s, d| s + &d.to_string() + " ");
println!("{}", s);*/
let i = self.rows[0];
for r in self.rows.iter() {
println!("{}\t{}", i, r);
}
}
}
|