keep source preparation parallel for linear targets

This commit is contained in:
Samuel Cui
2026-08-22 12:27:13 +08:00
parent 202c9d3041
commit 2122425105
2 changed files with 47 additions and 4 deletions
-4
View File
@@ -64,10 +64,6 @@ func (o *option) check() error {
o.fromDevice.check()
o.toDevice.check()
if o.fromDevice.linear || o.toDevice.linear {
o.fromDevice.threads = 1
o.toDevice.threads = 1
}
if o.logger == nil {
o.logger = logrus.StandardLogger()
}
+47
View File
@@ -51,3 +51,50 @@ func TestComparePath(t *testing.T) {
}
}
}
func TestLinearDeviceOnlySerializesItsOwnStage(t *testing.T) {
// Cover each directional linear constraint independently.
tests := []struct {
name string
options []Option
wantFromThreads int
wantToThreads int
}{
{
name: "linear target",
options: []Option{
SetToDevice(LinearDevice(true)),
},
wantFromThreads: 8,
wantToThreads: 1,
},
{
name: "linear source",
options: []Option{
SetFromDevice(LinearDevice(true)),
},
wantFromThreads: 1,
wantToThreads: 8,
},
}
// Keep the unconstrained side parallel while serializing only the linear stage.
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
option := newOption()
for _, apply := range test.options {
option = apply(option)
}
if err := option.check(); err != nil {
t.Fatal(err)
}
if option.fromDevice.threads != test.wantFromThreads {
t.Fatalf("source threads = %d, want %d", option.fromDevice.threads, test.wantFromThreads)
}
if option.toDevice.threads != test.wantToThreads {
t.Fatalf("target threads = %d, want %d", option.toDevice.threads, test.wantToThreads)
}
})
}
}