mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 20:09:57 +08:00
8a4c0d4a3f
issue #28657 follow https://pkg.go.dev/cmd/go#hdr-Build_constraints to compile go assembly with different cpu arch Signed-off-by: chasingegg <chao.gao@zilliz.com>
22 lines
440 B
Go
22 lines
440 B
Go
package distance
|
|
|
|
import (
|
|
"math"
|
|
|
|
"golang.org/x/sys/cpu"
|
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
"github.com/milvus-io/milvus/pkg/util/distance/asm"
|
|
)
|
|
|
|
func init() {
|
|
if cpu.X86.HasAVX2 {
|
|
log.Info("Hook avx for go simd distance computation")
|
|
IPImpl = asm.IP
|
|
L2Impl = asm.L2
|
|
CosineImpl = func(a []float32, b []float32) float32 {
|
|
return asm.IP(a, b) / float32(math.Sqrt(float64(asm.IP(a, a))*float64((asm.IP(b, b)))))
|
|
}
|
|
}
|
|
}
|