Skip to content

Commit

Permalink
Remove unused thread support to enable Windows compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Jan 11, 2024
1 parent e831375 commit cc2f2d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 110 deletions.
2 changes: 0 additions & 2 deletions components/equihash/src/tromp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct CEqui {
extern "C" {
#[allow(improper_ctypes)]
fn equi_new(
n_threads: u32,
blake2b_clone: extern "C" fn(state: *const State) -> *mut State,
blake2b_free: extern "C" fn(state: *mut State),
blake2b_update: extern "C" fn(state: *mut State, input: *const u8, input_len: usize),
Expand Down Expand Up @@ -144,7 +143,6 @@ pub fn solve_200_9<const N: usize>(
#[allow(unsafe_code)]
let eq = unsafe {
equi_new(
1,
blake2b::blake2b_clone,
blake2b::blake2b_free,
blake2b::blake2b_update,
Expand Down
41 changes: 8 additions & 33 deletions components/equihash/tromp/equi_miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>

typedef uint16_t u16;
Expand Down Expand Up @@ -246,32 +245,25 @@ struct equi {
bsizes *nslots; // PUT IN BUCKET STRUCT
proof *sols;
au32 nsols;
u32 nthreads;
u32 xfull;
u32 hfull;
u32 bfull;
pthread_barrier_t barry;
};
typedef struct equi equi;
void equi_clearslots(equi *eq);
equi *equi_new(
const u32 n_threads,
blake2b_clone blake2b_clone,
blake2b_free blake2b_free,
blake2b_update blake2b_update,
blake2b_finalize blake2b_finalize
) {
assert(sizeof(hashunit) == 4);
equi *eq = malloc(sizeof(equi));
eq->nthreads = n_threads;
eq->blake2b_clone = blake2b_clone;
eq->blake2b_free = blake2b_free;
eq->blake2b_update = blake2b_update;
eq->blake2b_finalize = blake2b_finalize;

const int err = pthread_barrier_init(&eq->barry, NULL, eq->nthreads);
assert(!err);

alloctrees(&eq->hta);
eq->nslots = (bsizes *)htalloc_alloc(&eq->hta, 2 * NBUCKETS, sizeof(au32));
eq->sols = (proof *)htalloc_alloc(&eq->hta, MAXSOLS, sizeof(proof));
Expand Down Expand Up @@ -412,7 +404,7 @@ typedef struct equi equi;
u32 nextbo;
};
typedef struct htlayout htlayout;

htlayout htlayout_new(equi *eq, u32 r) {
htlayout htl;
htl.hta = eq->hta;
Expand Down Expand Up @@ -528,7 +520,7 @@ typedef struct equi equi;
BLAKE2bState* state;
htlayout htl = htlayout_new(eq, 0);
const u32 hashbytes = hashsize(0);
for (u32 block = id; block < NBLOCKS; block += eq->nthreads) {
for (u32 block = id; block < NBLOCKS; block++) {
state = eq->blake2b_clone(eq->blake_ctx);
u32 leb = htole32(block);
eq->blake2b_update(state, (uchar *)&leb, sizeof(u32));
Expand Down Expand Up @@ -564,11 +556,11 @@ typedef struct equi equi;
}
}
}

void equi_digitodd(equi *eq, const u32 r, const u32 id) {
htlayout htl = htlayout_new(eq, r);
collisiondata cd;
for (u32 bucketid=id; bucketid < NBUCKETS; bucketid += eq->nthreads) {
for (u32 bucketid=id; bucketid < NBUCKETS; bucketid++) {
collisiondata_clear(&cd);
slot0 *buck = htl.hta.trees0[(r-1)/2][bucketid]; // optimize by updating previous buck?!
u32 bsize = getnslots(eq, r-1, bucketid); // optimize by putting bucketsize with block?!
Expand Down Expand Up @@ -616,11 +608,11 @@ typedef struct equi equi;
}
}
}

void equi_digiteven(equi *eq, const u32 r, const u32 id) {
htlayout htl = htlayout_new(eq, r);
collisiondata cd;
for (u32 bucketid=id; bucketid < NBUCKETS; bucketid += eq->nthreads) {
for (u32 bucketid=id; bucketid < NBUCKETS; bucketid++) {
collisiondata_clear(&cd);
slot1 *buck = htl.hta.trees1[(r-1)/2][bucketid]; // OPTIMIZE BY UPDATING PREVIOUS
u32 bsize = getnslots(eq, r-1, bucketid);
Expand Down Expand Up @@ -668,12 +660,12 @@ typedef struct equi equi;
}
}
}

void equi_digitK(equi *eq, const u32 id) {
collisiondata cd;
htlayout htl = htlayout_new(eq, WK);
u32 nc = 0;
for (u32 bucketid = id; bucketid < NBUCKETS; bucketid += eq->nthreads) {
for (u32 bucketid = id; bucketid < NBUCKETS; bucketid++) {
collisiondata_clear(&cd);
slot0 *buck = htl.hta.trees0[(WK-1)/2][bucketid];
u32 bsize = getnslots(eq, WK-1, bucketid);
Expand All @@ -700,50 +692,33 @@ nc++, candidate(eq, tree_from_bid(bucketid, s0, s1));

typedef struct {
u32 id;
pthread_t thread;
equi *eq;
} thread_ctx;

void barrier(pthread_barrier_t *barry) {
const int rc = pthread_barrier_wait(barry);
if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) {
// printf("Could not wait on barrier\n");
pthread_exit(NULL);
}
}

void *worker(void *vp) {
thread_ctx *tp = (thread_ctx *)vp;
equi *eq = tp->eq;

// if (tp->id == 0)
// printf("Digit 0\n");
barrier(&eq->barry);
equi_digit0(eq, tp->id);
barrier(&eq->barry);
if (tp->id == 0) {
equi_clearslots(eq);
showbsizes(eq, 0);
}
barrier(&eq->barry);
for (u32 r = 1; r < WK; r++) {
// if (tp->id == 0)
// printf("Digit %d", r);
barrier(&eq->barry);
r&1 ? equi_digitodd(eq, r, tp->id) : equi_digiteven(eq, r, tp->id);
barrier(&eq->barry);
if (tp->id == 0) {
// printf(" x%d b%d h%d\n", eq->xfull, eq->bfull, eq->hfull);
equi_clearslots(eq);
showbsizes(eq, r);
}
barrier(&eq->barry);
}
// if (tp->id == 0)
// printf("Digit %d\n", WK);
equi_digitK(eq, tp->id);
barrier(&eq->barry);
pthread_exit(NULL);
return 0;
}

Expand Down
75 changes: 0 additions & 75 deletions components/equihash/tromp/osx_barrier.h

This file was deleted.

0 comments on commit cc2f2d7

Please sign in to comment.