Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 139975b

Browse files
mvinesgarious
authored andcommitted
Add optional ed25519_init() (#10)
This function permits ed25519_verify_many() users to ensure the GPU is initialized correctly and if not take action rather than having the failure suppressed. ed25519_verify_many() retains its previous behavior of implicit initialization if ed25519_init() is not explicitly called.
1 parent bfb0cc7 commit 139975b

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/cuda-ecc-ed25119/ed25519.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void ED25519_DECLSPEC ed25519_free_gpu_mem();
6060
void ED25519_DECLSPEC ed25519_set_verbose(bool val);
6161

6262
const char* ED25519_DECLSPEC ed25519_license();
63+
bool ED25519_DECLSPEC ed25519_init();
6364

6465
#ifdef __cplusplus
6566
}

src/cuda-ecc-ed25119/verify.cu

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,33 @@ void ed25519_set_verbose(bool val) {
146146
g_verbose = val;
147147
}
148148

149+
static bool ed25519_init_locked() {
150+
if (g_total_gpus == -1) {
151+
cudaGetDeviceCount(&g_total_gpus);
152+
g_total_gpus = min(8, g_total_gpus);
153+
LOG("total_gpus: %d\n", g_total_gpus);
154+
for (int gpu = 0; gpu < g_total_gpus; gpu++) {
155+
for (int queue = 0; queue < MAX_QUEUE_SIZE; queue++) {
156+
int err = pthread_mutex_init(&g_gpu_ctx[gpu][queue].mutex, NULL);
157+
if (err != 0) {
158+
fprintf(stderr, "pthread_mutex_init error %d gpu: %d queue: %d\n",
159+
err, gpu, queue);
160+
g_total_gpus = 0;
161+
return false;
162+
}
163+
}
164+
}
165+
}
166+
return g_total_gpus > 0;
167+
}
168+
169+
bool ed25519_init() {
170+
pthread_mutex_lock(&g_ctx_mutex);
171+
bool success = ed25519_init_locked();
172+
pthread_mutex_unlock(&g_ctx_mutex);
173+
return success;
174+
}
175+
149176
void ed25519_verify_many(const gpu_Elems* elems,
150177
uint32_t num,
151178
uint32_t message_size,
@@ -184,22 +211,7 @@ void ed25519_verify_many(const gpu_Elems* elems,
184211
// Device allocate
185212

186213
pthread_mutex_lock(&g_ctx_mutex);
187-
if (g_total_gpus == -1) {
188-
cudaGetDeviceCount(&g_total_gpus);
189-
g_total_gpus = min(8, g_total_gpus);
190-
LOG("total_gpus: %d\n", g_total_gpus);
191-
for (int gpu = 0; gpu < g_total_gpus; gpu++) {
192-
for (int queue = 0; queue < MAX_QUEUE_SIZE; queue++) {
193-
int err = pthread_mutex_init(&g_gpu_ctx[gpu][queue].mutex, NULL);
194-
if (err != 0) {
195-
fprintf(stderr, "pthread_mutex_init error %d gpu: %d queue: %d\n",
196-
err, gpu, queue);
197-
return;
198-
}
199-
}
200-
}
201-
}
202-
if (g_total_gpus <= 0) {
214+
if (!ed25519_init_locked()) {
203215
pthread_mutex_unlock(&g_ctx_mutex);
204216
LOG("No GPUs, exiting...\n");
205217
return;

0 commit comments

Comments
 (0)