Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional ed25519_init() #10

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cuda-ecc-ed25119/ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void ED25519_DECLSPEC ed25519_free_gpu_mem();
void ED25519_DECLSPEC ed25519_set_verbose(bool val);

const char* ED25519_DECLSPEC ed25519_license();
bool ED25519_DECLSPEC ed25519_init();

#ifdef __cplusplus
}
Expand Down
44 changes: 28 additions & 16 deletions src/cuda-ecc-ed25119/verify.cu
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,33 @@ void ed25519_set_verbose(bool val) {
g_verbose = val;
}

static bool ed25519_init_locked() {
if (g_total_gpus == -1) {
cudaGetDeviceCount(&g_total_gpus);
g_total_gpus = min(8, g_total_gpus);
LOG("total_gpus: %d\n", g_total_gpus);
for (int gpu = 0; gpu < g_total_gpus; gpu++) {
for (int queue = 0; queue < MAX_QUEUE_SIZE; queue++) {
int err = pthread_mutex_init(&g_gpu_ctx[gpu][queue].mutex, NULL);
if (err != 0) {
fprintf(stderr, "pthread_mutex_init error %d gpu: %d queue: %d\n",
err, gpu, queue);
g_total_gpus = 0;
return false;
}
}
}
}
return g_total_gpus > 0;
}

bool ed25519_init() {
pthread_mutex_lock(&g_ctx_mutex);
bool success = ed25519_init_locked();
pthread_mutex_unlock(&g_ctx_mutex);
return success;
}

void ed25519_verify_many(const gpu_Elems* elems,
uint32_t num,
uint32_t message_size,
Expand Down Expand Up @@ -184,22 +211,7 @@ void ed25519_verify_many(const gpu_Elems* elems,
// Device allocate

pthread_mutex_lock(&g_ctx_mutex);
if (g_total_gpus == -1) {
cudaGetDeviceCount(&g_total_gpus);
g_total_gpus = min(8, g_total_gpus);
LOG("total_gpus: %d\n", g_total_gpus);
for (int gpu = 0; gpu < g_total_gpus; gpu++) {
for (int queue = 0; queue < MAX_QUEUE_SIZE; queue++) {
int err = pthread_mutex_init(&g_gpu_ctx[gpu][queue].mutex, NULL);
if (err != 0) {
fprintf(stderr, "pthread_mutex_init error %d gpu: %d queue: %d\n",
err, gpu, queue);
return;
}
}
}
}
if (g_total_gpus <= 0) {
if (!ed25519_init_locked()) {
pthread_mutex_unlock(&g_ctx_mutex);
LOG("No GPUs, exiting...\n");
return;
Expand Down