milvus/pkg/util/distance/calc_distance_amd64.go
Gao 8a4c0d4a3f
enhance: compile go assembly with build constraints for different arch (#29515)
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>
2023-12-28 15:40:47 +08:00

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)))))
}
}
}