mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 18:38:44 +08:00
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>
This commit is contained in:
parent
5474bce9d2
commit
8a4c0d4a3f
@ -1,4 +1,4 @@
|
||||
// Code generated by command: go run ip.go -out ip.s -stubs ip_stub.go. DO NOT EDIT.
|
||||
// Code generated by command: go run ip.go -out ip_amd64.s -stubs ip_stub_amd64.go. DO NOT EDIT.
|
||||
|
||||
#include "textflag.h"
|
||||
|
@ -1,6 +0,0 @@
|
||||
// Code generated by command: go run ip.go -out ip.s -stubs ip_stub.go. DO NOT EDIT.
|
||||
|
||||
package asm
|
||||
|
||||
// inner product between x and y
|
||||
func IP(x []float32, y []float32) float32
|
6
pkg/util/distance/asm/ip_stub_amd64.go
Normal file
6
pkg/util/distance/asm/ip_stub_amd64.go
Normal file
@ -0,0 +1,6 @@
|
||||
// Code generated by command: go run ip.go -out ip_amd64.s -stubs ip_stub_amd64.go. DO NOT EDIT.
|
||||
|
||||
package asm
|
||||
|
||||
// inner product between x and y
|
||||
func IP(x []float32, y []float32) float32
|
@ -1,4 +1,4 @@
|
||||
// Code generated by command: go run l2.go -out l2.s -stubs l2_stub.go. DO NOT EDIT.
|
||||
// Code generated by command: go run l2.go -out l2_amd64.s -stubs l2_stub_amd64.go. DO NOT EDIT.
|
||||
|
||||
#include "textflag.h"
|
||||
|
@ -1,6 +0,0 @@
|
||||
// Code generated by command: go run l2.go -out l2.s -stubs l2_stub.go. DO NOT EDIT.
|
||||
|
||||
package asm
|
||||
|
||||
// squared l2 between x and y
|
||||
func L2(x []float32, y []float32) float32
|
6
pkg/util/distance/asm/l2_stub_amd64.go
Normal file
6
pkg/util/distance/asm/l2_stub_amd64.go
Normal file
@ -0,0 +1,6 @@
|
||||
// Code generated by command: go run l2.go -out l2_amd64.s -stubs l2_stub_amd64.go. DO NOT EDIT.
|
||||
|
||||
package asm
|
||||
|
||||
// squared l2 between x and y
|
||||
func L2(x []float32, y []float32) float32
|
@ -6,10 +6,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"golang.org/x/sys/cpu"
|
||||
|
||||
"github.com/milvus-io/milvus/pkg/log"
|
||||
"github.com/milvus-io/milvus/pkg/util/distance/asm"
|
||||
)
|
||||
|
||||
/**
|
||||
@ -58,27 +54,11 @@ func CosineImplPure(a []float32, b []float32) float32 {
|
||||
}
|
||||
|
||||
var (
|
||||
L2Impl func(a []float32, b []float32) float32
|
||||
IPImpl func(a []float32, b []float32) float32
|
||||
CosineImpl func(a []float32, b []float32) float32
|
||||
L2Impl func(a []float32, b []float32) float32 = IPImplPure
|
||||
IPImpl func(a []float32, b []float32) float32 = L2ImplPure
|
||||
CosineImpl func(a []float32, b []float32) float32 = CosineImplPure
|
||||
)
|
||||
|
||||
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)))))
|
||||
}
|
||||
} else {
|
||||
log.Info("Use pure go distance computation")
|
||||
IPImpl = IPImplPure
|
||||
L2Impl = L2ImplPure
|
||||
CosineImpl = CosineImplPure
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateMetricType returns metric text or error
|
||||
func ValidateMetricType(metric string) (string, error) {
|
||||
if metric == "" {
|
||||
|
21
pkg/util/distance/calc_distance_amd64.go
Normal file
21
pkg/util/distance/calc_distance_amd64.go
Normal file
@ -0,0 +1,21 @@
|
||||
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)))))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user