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

Fix: fix any gpu scheduling #609

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,14 @@ func filterWorkersByResources(workers []*types.Worker, request *types.ContainerR
filteredWorkers := []*types.Worker{}
gpuRequestsMap := map[string]int{}
requiresGPU := request.RequiresGPU()
requiresAnyGPU := false

for index, gpu := range request.GpuRequest {
gpuRequestsMap[gpu] = index
if gpu == types.ANY_GPU.String() {
requiresAnyGPU = true
break
}
}

for _, worker := range workers {
Expand All @@ -309,7 +314,7 @@ func filterWorkersByResources(workers []*types.Worker, request *types.ContainerR
continue
}

if requiresGPU {
if requiresGPU && !requiresAnyGPU {
// Validate GPU resource availability
priorityModifier, validGpu := gpuRequestsMap[worker.Gpu]
if !validGpu || worker.FreeGpuCount < request.GpuCount {
Expand Down
30 changes: 30 additions & 0 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func TestSelectGPUWorker(t *testing.T) {
assert.NotNil(t, wb)

newWorker := &types.Worker{
Id: uuid.New().String(),
Status: types.WorkerStatusPending,
FreeCpu: 1000,
FreeMemory: 1000,
Expand Down Expand Up @@ -402,6 +403,12 @@ func TestSelectGPUWorker(t *testing.T) {
GpuRequest: []string{"T4"},
}

thirdRequest := &types.ContainerRequest{
Cpu: 1000,
Memory: 1000,
GpuRequest: []string{"any"},
}

// CPU request should not be able to select a GPU worker
_, err = wb.selectWorker(cpuRequest)
assert.Error(t, err)
Expand All @@ -427,6 +434,29 @@ func TestSelectGPUWorker(t *testing.T) {

_, ok = err.(*types.ErrNoSuitableWorkerFound)
assert.True(t, ok)

newWorkerAnyGpu := &types.Worker{
Id: uuid.New().String(),
Status: types.WorkerStatusPending,
FreeCpu: 1000,
FreeMemory: 1000,
Gpu: "T4",
}

err = wb.workerRepo.AddWorker(newWorkerAnyGpu)
assert.Nil(t, err)

// Select a worker for the request
worker, err = wb.selectWorker(thirdRequest)
assert.Nil(t, err)

// Check if the worker selected has the "T4" GPU
assert.Equal(t, newWorkerAnyGpu.Gpu, worker.Gpu)
assert.Equal(t, newWorkerAnyGpu.Id, worker.Id)

// Actually schedule the request
err = wb.scheduleRequest(worker, thirdRequest)
assert.Nil(t, err)
}

func TestSelectCPUWorker(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const (
GPU_A6000 GPUType = "A6000"
GPU_RTX4090 GPUType = "RTX4090"

NO_GPU GPUType = "NO_GPU"
NO_GPU GPUType = "NO_GPU"
ANY_GPU GPUType = "any"
)

func AllGPUTypes() []GPUType {
Expand Down
Loading