summaryrefslogtreecommitdiff
path: root/src/solvers/gpu/mod.rs
blob: f9ab711389e7fbda9535fcac0ff89010294f0427 (plain)
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
pub mod host;
pub mod manager;
pub mod output;

pub use manager::*;

type MaskMessage = (u64, Vec<u64>);
type RowMessage = (u64, Vec<Vec<u32>>);

pub enum Message {
    CheckRequest(CheckRequest),
    HostMessage(MaskMessage),
    OutputMessage(RowMessage),
    Terminate,
}

pub struct ResultMessage {
    data: Vec<u64>,
    offset: usize,
    size: usize,
}

impl ResultMessage {
    fn new(data: Vec<u64>, offset: usize, size: usize) -> Self {
        Self { data, offset, size }
    }
    fn valid_walls(&self, wg_size: usize) -> &[Vec<u32>] {
        let mut result = vec![Vec::new(); 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.as_ref()
    }
}

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,
        }
    }
}