diff --git a/itests/harmonytask_test.go b/itests/harmonytask_test.go index 4985b8421..8aab1f671 100644 --- a/itests/harmonytask_test.go +++ b/itests/harmonytask_test.go @@ -161,7 +161,7 @@ func TestHarmonyTasksWith2PartiesPolling(t *testing.T) { sender.GracefullyTerminate(time.Second * 5) worker.GracefullyTerminate(time.Second * 5) sort.Strings(dest) - require.Equal(t, dest, []string{"A", "B"}) + require.Equal(t, []string{"A", "B"}, dest) }) } diff --git a/lib/harmony/harmonytask/harmonytask.go b/lib/harmony/harmonytask/harmonytask.go index 5717278b6..66283d1bd 100644 --- a/lib/harmony/harmonytask/harmonytask.go +++ b/lib/harmony/harmonytask/harmonytask.go @@ -399,6 +399,9 @@ func (e *TaskEngine) resourcesInUse() resources.Resources { tmp.Cpu -= int(ct) * t.Cost.Cpu tmp.Gpu -= float64(ct) * t.Cost.Gpu tmp.Ram -= uint64(ct) * t.Cost.Ram + if len(t.Cost.GpuRam) == 0 { + continue + } for i := int32(0); i < ct; i++ { for grIdx, j := range tmp.GpuRam { if j > t.Cost.GpuRam[0] { diff --git a/lib/harmony/harmonytask/task_type_handler.go b/lib/harmony/harmonytask/task_type_handler.go index af47b498f..080769d4b 100644 --- a/lib/harmony/harmonytask/task_type_handler.go +++ b/lib/harmony/harmonytask/task_type_handler.go @@ -11,6 +11,7 @@ import ( "time" logging "github.com/ipfs/go-log/v2" + "github.com/samber/lo" "github.com/filecoin-project/lotus/lib/harmony/harmonydb" ) @@ -219,7 +220,7 @@ func (h *taskTypeHandler) AssertMachineHasCapacity() error { return errors.New("Did not accept " + h.Name + " task: out of available GPU") } for _, u := range r.GpuRam { - if u > h.Cost.GpuRam[0] { + if u > lo.Sum(h.Cost.GpuRam) { goto enoughGpuRam } } diff --git a/lib/harmony/resources/resources.go b/lib/harmony/resources/resources.go index 794e27433..09ff9c802 100644 --- a/lib/harmony/resources/resources.go +++ b/lib/harmony/resources/resources.go @@ -54,11 +54,12 @@ func Register(db *harmonydb.DB, hostnameAndPort string) (*Reg, error) { if err != nil { return nil, fmt.Errorf("could not read from harmony_machines: %w", err) } + gpuram := lo.Sum(reg.GpuRam) if len(ownerID) == 0 { err = db.QueryRow(ctx, `INSERT INTO harmony_machines (host_and_port, cpu, ram, gpu, gpuram) VALUES ($1,$2,$3,$4,$5) RETURNING id`, - hostnameAndPort, reg.Cpu, reg.Ram, reg.Gpu, lo.Sum(reg.GpuRam)).Scan(®.Resources.MachineID) + hostnameAndPort, reg.Cpu, reg.Ram, reg.Gpu, gpuram).Scan(®.Resources.MachineID) if err != nil { return nil, err } @@ -67,7 +68,7 @@ func Register(db *harmonydb.DB, hostnameAndPort string) (*Reg, error) { reg.MachineID = ownerID[0] _, err := db.Exec(ctx, `UPDATE harmony_machines SET cpu=$1, ram=$2, gpu=$3, gpuram=$4 WHERE id=$6`, - reg.Cpu, reg.Ram, reg.Gpu, lo.Sum(reg.GpuRam), reg.Resources.MachineID) + reg.Cpu, reg.Ram, reg.Gpu, gpuram, reg.Resources.MachineID) if err != nil { return nil, err }