Skip to content

Commit 4796455

Browse files
authored
[Bug]: broken binary search in GetSignature func (#1993)
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
1 parent d6fe21a commit 4796455

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/cache/model_gpu_profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func (pf *ModelGPUProfile) GetSignature(features ...float64) ([]int, error) {
135135
} else {
136136
ret[i] = mid
137137
found = true
138+
break
138139
}
139-
break
140140
}
141141
if !found {
142142
if value < indexes[i][left]+(indexes[i][right]-indexes[i][left])*SignatureTolerance {

pkg/cache/model_gpu_profile_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,22 @@ var _ = Describe("ModelGPUProfile", func() {
4343
Expect(err).To(BeNil())
4444
Expect(signatures).To(Equal([]int{0, 4}))
4545
})
46+
47+
It("should GetSignature find exact match in the middle of a large index", func() {
48+
signatures, err := profile.GetSignature(64, 256)
49+
Expect(err).To(BeNil())
50+
Expect(signatures).To(Equal([]int{4, 1}))
51+
})
52+
53+
It("should GetSignature find value near the end of a large index", func() {
54+
signatures, err := profile.GetSignature(256, 128)
55+
Expect(err).To(BeNil())
56+
Expect(signatures).To(Equal([]int{6, 0}))
57+
})
58+
59+
It("should GetSignature find value near the start of a large index", func() {
60+
signatures, err := profile.GetSignature(8, 128)
61+
Expect(err).To(BeNil())
62+
Expect(signatures).To(Equal([]int{1, 0}))
63+
})
4664
})

0 commit comments

Comments
 (0)