Skip to content

Commit

Permalink
removed hard codes
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 4, 2021
1 parent 1c1d28c commit 0cf6dc0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
25 changes: 14 additions & 11 deletions gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "main.h"

int * getFreeGpuList(int *numFree) {
int * getGpuList(int *num, int unoccupied) {
int * gpuList;
unsigned int nDevices;
int i, j = 0, count = 0;
Expand All @@ -31,19 +31,22 @@ int * getFreeGpuList(int *numFree) {
goto Error;
}

result = nvmlDeviceGetMemoryInfo(dev, &mem);
if (result != 0) {
error("Failed to get GPU memory for GPU %d: %s", i, nvmlErrorString(result));
goto Error;
}
if (unoccupied) {
result = nvmlDeviceGetMemoryInfo(dev, &mem);
if (result != 0) {
error("Failed to get GPU memory for GPU %d: %s", i, nvmlErrorString(result));
goto Error;
}

if (mem.free > .1 * mem.total) {
gpuList[j] = i;
count++;
j++;
if (mem.free < .1 * mem.total)
continue;
}

gpuList[j] = i;
count++;
j++;
}
*numFree = count;
*num = count;
result = nvmlShutdown();
if (NVML_SUCCESS != result)
error("Failed to shutdown NVML: %s", nvmlErrorString(result));
Expand Down
2 changes: 1 addition & 1 deletion jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ int next_run_job() {

/* Query GPUs */
int numFree;
int *freeGpuList = getFreeGpuList(&numFree);
int *freeGpuList = getGpuList(&numFree, 1);

/* Look for a runnable task */
p = firstjob;
Expand Down
2 changes: 1 addition & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,4 @@ char *get_environment();
int tail_file(const char *fname, int last_lines);

/* gpu.c */
int *getFreeGpuList(int *numFree);
int *getGpuList(int *num, int unoccupied);
3 changes: 1 addition & 2 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ int *used_gpus;
int num_total_gpus;

static void initialize_gpus() {
/* TODO: fixed hard code */
num_total_gpus = 100;
getGpuList(&num_total_gpus, 0);
used_gpus = (int *) malloc(num_total_gpus * sizeof(int));
memset(used_gpus, 0, num_total_gpus * sizeof(int)); /* 0 is not in used, 1 is in used */
}
Expand Down
2 changes: 0 additions & 2 deletions server_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "main.h"

extern int server_socket;
int *used_gpus;
int num_total_gpus;

static char *socket_path;
static int should_check_owner = 0;
Expand Down

0 comments on commit 0cf6dc0

Please sign in to comment.