From cc2f2d7cd74eaa71d47759cefadf59944f59863e Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 12 Jan 2024 08:05:19 +1000 Subject: [PATCH] Remove unused thread support to enable Windows compilation --- components/equihash/src/tromp.rs | 2 - components/equihash/tromp/equi_miner.c | 41 +++----------- components/equihash/tromp/osx_barrier.h | 75 ------------------------- 3 files changed, 8 insertions(+), 110 deletions(-) delete mode 100644 components/equihash/tromp/osx_barrier.h diff --git a/components/equihash/src/tromp.rs b/components/equihash/src/tromp.rs index fac2d895f3..a0ac90eef5 100644 --- a/components/equihash/src/tromp.rs +++ b/components/equihash/src/tromp.rs @@ -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), @@ -144,7 +143,6 @@ pub fn solve_200_9( #[allow(unsafe_code)] let eq = unsafe { equi_new( - 1, blake2b::blake2b_clone, blake2b::blake2b_free, blake2b::blake2b_update, diff --git a/components/equihash/tromp/equi_miner.c b/components/equihash/tromp/equi_miner.c index eee6efa506..51ce0146eb 100644 --- a/components/equihash/tromp/equi_miner.c +++ b/components/equihash/tromp/equi_miner.c @@ -28,7 +28,6 @@ #include #include -#include #include typedef uint16_t u16; @@ -246,16 +245,13 @@ 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, @@ -263,15 +259,11 @@ typedef struct equi equi; ) { 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)); @@ -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; @@ -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)); @@ -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?! @@ -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); @@ -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); @@ -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; } diff --git a/components/equihash/tromp/osx_barrier.h b/components/equihash/tromp/osx_barrier.h deleted file mode 100644 index 659c40bf59..0000000000 --- a/components/equihash/tromp/osx_barrier.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef ZCASH_POW_TROMP_OSX_BARRIER_H -#define ZCASH_POW_TROMP_OSX_BARRIER_H - -#ifdef __APPLE__ - -#ifndef PTHREAD_BARRIER_H_ -#define PTHREAD_BARRIER_H_ - -#include -#include - -typedef int pthread_barrierattr_t; -#define PTHREAD_BARRIER_SERIAL_THREAD 1 - -typedef struct -{ - pthread_mutex_t mutex; - pthread_cond_t cond; - int count; - int tripCount; -} pthread_barrier_t; - - -int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count) -{ - if(count == 0) - { - errno = EINVAL; - return -1; - } - if(pthread_mutex_init(&barrier->mutex, 0) < 0) - { - return -1; - } - if(pthread_cond_init(&barrier->cond, 0) < 0) - { - pthread_mutex_destroy(&barrier->mutex); - return -1; - } - barrier->tripCount = count; - barrier->count = 0; - - return 0; -} - -int pthread_barrier_destroy(pthread_barrier_t *barrier) -{ - pthread_cond_destroy(&barrier->cond); - pthread_mutex_destroy(&barrier->mutex); - return 0; -} - -int pthread_barrier_wait(pthread_barrier_t *barrier) -{ - pthread_mutex_lock(&barrier->mutex); - ++(barrier->count); - if(barrier->count >= barrier->tripCount) - { - barrier->count = 0; - pthread_cond_broadcast(&barrier->cond); - pthread_mutex_unlock(&barrier->mutex); - return PTHREAD_BARRIER_SERIAL_THREAD; - } - else - { - pthread_cond_wait(&barrier->cond, &(barrier->mutex)); - pthread_mutex_unlock(&barrier->mutex); - return 0; - } -} - -#endif // PTHREAD_BARRIER_H_ -#endif // __APPLE__ - -#endif // ZCASH_POW_TROMP_OSX_BARRIER_H