1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-06-07 22:31:55 +00:00
This commit is contained in:
Newnius 2020-06-30 16:49:35 +08:00
parent fc390837ff
commit 7180d6d5e4

View File

@ -743,7 +743,7 @@ func (pool *ResourcePool) doAcquireResource(job Job) []NodeStatus {
if pool.TotalGPU == 0 { if pool.TotalGPU == 0 {
return []NodeStatus{} return []NodeStatus{}
} }
var res []NodeStatus var ress []NodeStatus
loadRatio := float64(pool.UsingGPU) / float64(pool.TotalGPU) loadRatio := float64(pool.UsingGPU) / float64(pool.TotalGPU)
/* first, choose sharable GPUs */ /* first, choose sharable GPUs */
@ -795,29 +795,30 @@ func (pool *ResourcePool) doAcquireResource(job Job) []NodeStatus {
if len(candidates) > 0 { if len(candidates) > 0 {
node := candidates[0] node := candidates[0]
res = append(res, NodeStatus{}) res := NodeStatus{}
res[0].ClientID = node.ClientID res.ClientID = node.ClientID
res[0].ClientHost = node.ClientHost res.ClientHost = node.ClientHost
res[0].NumCPU = task.NumberCPU res.NumCPU = task.NumberCPU
res[0].MemTotal = task.Memory res.MemTotal = task.Memory
res[0].Status = availables[node.ClientHost][0:task.NumberGPU] res.Status = availables[node.ClientHost][0:task.NumberGPU]
for i := range res[0].Status { for i := range res.Status {
for j := range node.Status { for j := range node.Status {
if res[0].Status[i].UUID == node.Status[j].UUID { if res.Status[i].UUID == node.Status[j].UUID {
if node.Status[j].MemoryAllocated == 0 { if node.Status[j].MemoryAllocated == 0 {
pool.UsingGPUMu.Lock() pool.UsingGPUMu.Lock()
pool.UsingGPU ++ pool.UsingGPU ++
pool.UsingGPUMu.Unlock() pool.UsingGPUMu.Unlock()
} }
node.Status[j].MemoryAllocated += task.MemoryGPU node.Status[j].MemoryAllocated += task.MemoryGPU
res[0].Status[i].MemoryTotal = task.MemoryGPU res.Status[i].MemoryTotal = task.MemoryGPU
} }
} }
} }
for _, t := range res[0].Status { for _, t := range res.Status {
pool.attach(t.UUID, job) pool.attach(t.UUID, job)
} }
ress = append(ress, res)
} }
} }
//log.Info(candidates) //log.Info(candidates)
@ -904,29 +905,30 @@ func (pool *ResourcePool) doAcquireResource(job Job) []NodeStatus {
//log.Info(candidates) //log.Info(candidates)
if len(candidates) > 0 { if len(candidates) > 0 {
node := candidates[0] node := candidates[0]
res = append(res, NodeStatus{}) res := NodeStatus{}
res[0].ClientID = node.ClientID res.ClientID = node.ClientID
res[0].ClientHost = node.ClientHost res.ClientHost = node.ClientHost
res[0].NumCPU = task.NumberCPU res.NumCPU = task.NumberCPU
res[0].MemTotal = task.Memory res.MemTotal = task.Memory
res[0].Status = availables[node.ClientHost][0:task.NumberGPU] res.Status = availables[node.ClientHost][0:task.NumberGPU]
for i := range res[0].Status { for i := range res.Status {
for j := range node.Status { for j := range node.Status {
if res[0].Status[i].UUID == node.Status[j].UUID { if res.Status[i].UUID == node.Status[j].UUID {
if node.Status[j].MemoryAllocated == 0 { if node.Status[j].MemoryAllocated == 0 {
pool.UsingGPUMu.Lock() pool.UsingGPUMu.Lock()
pool.UsingGPU ++ pool.UsingGPU ++
pool.UsingGPUMu.Unlock() pool.UsingGPUMu.Unlock()
} }
node.Status[j].MemoryAllocated += task.MemoryGPU node.Status[j].MemoryAllocated += task.MemoryGPU
res[0].Status[i].MemoryTotal = task.MemoryGPU res.Status[i].MemoryTotal = task.MemoryGPU
} }
} }
} }
for _, t := range res[0].Status { for _, t := range res.Status {
pool.attach(t.UUID, job) pool.attach(t.UUID, job)
} }
ress = append(ress, res)
} }
} }
} }
@ -937,8 +939,7 @@ func (pool *ResourcePool) doAcquireResource(job Job) []NodeStatus {
} }
/* assign */ /* assign */
var ress []NodeStatus if len(candidates) > 0 && len(ress) == 0 {
if len(candidates) > 0 && len(res) == 0 {
var nodesT []NodeStatus var nodesT []NodeStatus
for _, node := range candidates { for _, node := range candidates {
nodesT = append(nodesT, node.Copy()) nodesT = append(nodesT, node.Copy())