|
|
@@ -16,6 +16,8 @@ extern "C" {
|
|
|
#include <errno.h>
|
|
|
#include <signal.h>
|
|
|
|
|
|
+#include <cuda_runtime.h>
|
|
|
+
|
|
|
#include "cudadl.h"
|
|
|
|
|
|
#include "evutils.h"
|
|
|
@@ -26,6 +28,8 @@ NTL_CLIENT
|
|
|
|
|
|
#undef VERBOSE
|
|
|
|
|
|
+static int cuda_device_id = -1;
|
|
|
+
|
|
|
typedef enum {
|
|
|
WRKCCSTATE_AWAITCMD,
|
|
|
WRKCCSTATE_RDPROBLEM,
|
|
|
@@ -89,6 +93,13 @@ bool dpcallback(void *cbdata, unsigned int *dpwords)
|
|
|
static void *worker_thread_start(void *data)
|
|
|
{
|
|
|
ZZ_p::init(wrkctrlstate.current_problem->modulus);
|
|
|
+
|
|
|
+ cudaError_t cudares = cudaSetDevice(cuda_device_id);
|
|
|
+ if (cudares != cudaSuccess) {
|
|
|
+ cerr << "Error setting CUDA device: " << cudaGetErrorString(cudares) << "\n";
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
cuda_dl(to_ZZ_p(wrkctrlstate.current_problem->base),
|
|
|
to_ZZ_p(wrkctrlstate.current_problem->target),
|
|
|
wrkctrlstate.current_problem->order,
|
|
|
@@ -290,7 +301,7 @@ static void controllerconn_event_cb(struct bufferevent *bev, short events,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int worker_main(const char *controller_host, unsigned short controller_port)
|
|
|
+int worker_main(const char *controller_host, unsigned short controller_port, int gpu_id)
|
|
|
{
|
|
|
// Initialize the prng with some randomness from the kernel
|
|
|
unsigned char randbuf[1024];
|
|
|
@@ -304,6 +315,8 @@ int worker_main(const char *controller_host, unsigned short controller_port)
|
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
|
+ cuda_device_id = gpu_id;
|
|
|
+
|
|
|
return controller_client(controller_host, controller_port,
|
|
|
controllerconn_event_cb, true);
|
|
|
}
|