Skip to content

Commit

Permalink
Brodey/s (#8)
Browse files Browse the repository at this point in the history
* fix: pointer

* chore: merge

* chore: device count

* fix

* chore: cleanup

* fix: dc bug
  • Loading branch information
brodeynewman authored Sep 16, 2024
1 parent e40d3bc commit 932a04e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Features:
- Make port configurable

Bugs:
- Server exits when the client disconnects
- Server exits when the client disconnects [done]
- Client dlsym resolution needs to switch to a hashmap or trie-based lookup table instead of linear strcmp
16 changes: 10 additions & 6 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 @@ -21,19 +21,23 @@ build() {
}

server() {
echo "building server..."
echo "building server..."

gcc -o $server_out_path $server_path -lnvidia-ml -lpthread
if [[ "$(uname)" == "Linux" ]]; then
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"
}

run() {
build

LD_PRELOAD="$libscuda_path" nvidia-smi
LD_PRELOAD="$libscuda_path" nvidia-smi --query-gpu=name --format=csv
}

# Main script logic using a switch case
Expand Down
33 changes: 28 additions & 5 deletions server.cu
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ int request_handler(int connfd)
read(connfd, &length, sizeof(unsigned int)) < 0)
return -1;
nvmlReturn_t result = nvmlDeviceGetName(device, name, length);

printf("received device name response: %s\n", name);

if (write(connfd, name, length) < 0)
return -1;
return result;
Expand Down Expand Up @@ -140,17 +143,35 @@ void *client_handler(void *arg)

int request_id;

while (read(connfd, &request_id, sizeof(int)) >= 0)
while (1)
{
if (write(connfd, &request_id, sizeof(int)) < 0)
int n = read(connfd, &request_id, sizeof(int));
if (n == 0)
{
printf("client disconnected, loop continuing. \n");
break;
}
else if (n < 0)
{
printf("error reading from client.\n");
break;
int result = request_handler(connfd);
if (write(connfd, &result, sizeof(int)) < 0)
}

if (write(connfd, &request_id, sizeof(int)) < 0) {
printf("error writing to client.\n");
break;
}

int res = request_handler(connfd);
if (write(connfd, &res, sizeof(int)) < 0) {
printf("error writing result to client.\n");
break;
}
}

close(connfd);
pthread_exit(NULL);
// dont need pthread_exit, can return when complete instead
return NULL;
}

int main()
Expand Down Expand Up @@ -204,6 +225,8 @@ int main()
continue;
}

printf("client connected, spawning thread.\n");

pthread_t thread_id;
pthread_create(&thread_id, NULL, client_handler, connfd);
}
Expand Down

0 comments on commit 932a04e

Please sign in to comment.