Skip to content

Commit

Permalink
chore: device count
Browse files Browse the repository at this point in the history
  • Loading branch information
brodeynewman committed Sep 13, 2024
1 parent 2196d27 commit 2a1dd0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

#define RPC_nvmlDeviceGetName 3

#define RPC_nvmlDeviceGetCount_v2 4

#endif
20 changes: 14 additions & 6 deletions client.cu
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ nvmlReturn_t nvmlInit_v2()
return send_rpc_message(RPC_nvmlInit_v2);
}

nvmlReturn_t nvmlDeviceGetCountHandler_v2()
{
open_rpc_client();
return send_rpc_message(RPC_nvmlDeviceGetCount_v2);
}

nvmlReturn_t nvmlShutdown()
{
open_rpc_client();
Expand All @@ -163,12 +169,14 @@ void *dlsym(void *handle, const char *name) __THROW

if (!strcmp(name, "nvmlInitWithFlags"))
return (void *)nvmlInitWithFlags;
// if (!strcmp(name, "nvmlInit_v2"))
// return (void *)nvmlInit_v2;
// if (!strcmp(name, "nvmlShutdown"))
// return (void *)nvmlShutdown;
// if (!strcmp(name, "nvmlDeviceGetName"))
// return (void *)nvmlDeviceGetName;
if (!strcmp(name, "nvmlInit_v2"))
return (void *)nvmlInit_v2;
if (!strcmp(name, "nvmlShutdown"))
return (void *)nvmlShutdown;
if (!strcmp(name, "nvmlDeviceGetName"))
return (void *)nvmlDeviceGetName;
if (!strcmp(name, "nvmlDeviceGetCount_v2"))
return (void *)nvmlDeviceGetCountHandler_v2;

static void *(*real_dlsym)(void *, const char *) = NULL;
if (real_dlsym == NULL)
Expand Down
8 changes: 4 additions & 4 deletions local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
libscuda_path="$(pwd)/libscuda.so"
client_path="$(pwd)/client.cu"
server_path="$(pwd)/server.cu"
server_out_path="$(pwd)/server"
server_out_path="$(pwd)/server.so"

build() {
echo "building client..."

if [[ "$(uname)" == "Linux" ]]; then
nvcc -shared -Xcompiler -fPIC -o $libscuda_path $client_path -lcudart
nvcc -Xcompiler -fPIC -shared -o $libscuda_path $client_path
else
echo "No compiler options set for os "$(uname)""
fi
Expand All @@ -24,12 +24,12 @@ server() {
echo "building server..."

if [[ "$(uname)" == "Linux" ]]; then
nvcc -shared -Xcompiler -fPIC -o $server_out_path $server_path -lcudart
nvcc -o $server_out_path $server_path -lnvidia-ml
else
echo "No compiler options set for os "$(uname)""
fi

echo "starting server..."
echo "starting server... $server_out_path"

"$server_out_path"
}
Expand Down
16 changes: 15 additions & 1 deletion server.cu
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,22 @@ void *client_handler(void *arg)
printf("Sending nvmlInitWithFlags response %d %d\n", request_id, result);
if (write(connfd, &result, sizeof(nvmlReturn_t)) < 0)
goto exit;
break;
}
case RPC_nvmlDeviceGetCount_v2:
{
unsigned int dcount;
if (read(connfd, &dcount, sizeof(unsigned int)) < 0)
goto exit;
printf("Received device count request %d %d\n", request_id, dcount);
nvmlReturn_t result = nvmlDeviceGetCount_v2(&dcount);

if (result == NVML_SUCCESS) {
printf("Number of devices: %u\n", dcount);
}

if (write(connfd, &result, sizeof(nvmlReturn_t)) < 0)
goto exit;
}
}
}

Expand Down

0 comments on commit 2a1dd0f

Please sign in to comment.