From 200f8b1770c83b755918573dda578be1b2d9dddd Mon Sep 17 00:00:00 2001 From: quanghanh Date: Fri, 21 Jul 2023 09:59:38 +0000 Subject: [PATCH] feat: build vlfeat on arm64 --- Makefile | 7 +++++++ docsrc/install-shell.html | 5 +++++ make/dll.mak | 6 ++++++ make/matlab.mak | 4 ++++ vl/host.c | 8 ++++++-- vl/host.h | 14 ++++++++++++++ vl/kmeans.c | 2 +- 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9f0655a2..f0ac3b9e 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,7 @@ Linux_i386_ARCH := glnx86 Linux_i686_ARCH := glnx86 Linux_unknown_ARCH := glnx86 Linux_x86_64_ARCH := glnxa64 +Linux_aarch64_ARCH := armv8 UNAME := $(shell uname -sm) ARCH ?= $($(shell echo "$(UNAME)" | tr \ _)_ARCH) @@ -232,6 +233,12 @@ STD_CFLAGS += -m$(march) -D_GNU_SOURCE -fno-stack-protector STD_LDFLAGS += -m$(march) -Wl,--rpath,\$$ORIGIN/ -Wl,--as-needed endif +# Linux ARM64 +# Linux +ifeq "$(ARCH)" "$(filter $(ARCH),armv8)" +DISABLE_SSE2:=yes +endif + # Convert back DISALBE_*="no" flags to be empty ifeq "$(DISABLE_SSE2)" "no" override DISABLE_SSE2:= diff --git a/docsrc/install-shell.html b/docsrc/install-shell.html index c7695c77..409a403b 100644 --- a/docsrc/install-shell.html +++ b/docsrc/install-shell.html @@ -69,6 +69,11 @@ glnxa64 VLFEATROOT/bin/glnxa64/sift + +Linux ARM64 +armv8 +VLFEATROOT/bin/armv8/sift + diff --git a/make/dll.mak b/make/dll.mak index 22c30396..2ea561fe 100644 --- a/make/dll.mak +++ b/make/dll.mak @@ -76,6 +76,12 @@ DLL_SUFFIX := so DLL_LDFLAGS += -m64 endif +# Linux-arm64 +ifeq ($(ARCH),armv8) +DLL_SUFFIX := so +DLL_LDFLAGS += -march=armv8-a +endif + # -------------------------------------------------------------------- # Build # -------------------------------------------------------------------- diff --git a/make/matlab.mak b/make/matlab.mak index 4dde699e..086a3f84 100644 --- a/make/matlab.mak +++ b/make/matlab.mak @@ -59,6 +59,10 @@ ifeq ($(ARCH),glnxa64) MEX_SUFFIX := mexa64 endif +ifeq ($(ARCH),armv8) +MEX_SUFFIX := mexa64 +endif + MEX_BINDIR := toolbox/mex/$(MEX_SUFFIX) # generate the mex-dir target diff --git a/vl/host.c b/vl/host.c index ef97cdca..92efc62b 100644 --- a/vl/host.c +++ b/vl/host.c @@ -403,7 +403,9 @@ it supports POSIX threads. #undef HAS_CPUID #endif -#if defined(HAS_CPUID) & defined(VL_COMPILER_MSC) +#if defined(HAS_CPUID) + +#if defined(VL_COMPILER_MSC) #include VL_INLINE void _vl_cpuid (vl_int32* info, int function) @@ -412,7 +414,7 @@ _vl_cpuid (vl_int32* info, int function) } #endif -#if defined(HAS_CPUID) & defined(VL_COMPILER_GNUC) +#if defined(VL_COMPILER_GNUC) VL_INLINE void _vl_cpuid (vl_int32* info, int function) { @@ -488,6 +490,8 @@ _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self) return string ; } +#endif // defined(HAS_CPUID) + /** ------------------------------------------------------------------ ** @brief Human readable static library configuration ** @return a new string with the static configuration. diff --git a/vl/host.h b/vl/host.h index 293fe1f5..73ddba6d 100644 --- a/vl/host.h +++ b/vl/host.h @@ -266,6 +266,17 @@ defined(__DOXYGEN__) defined(__DOXYGEN__) #define VL_ARCH_IA64 #endif + +#if defined(_M_ARM64) || \ + defined(__aarch64__) || \ + defined(__ARM64_ARCH_8__) || \ + defined(__ARM_ARCH_8A__) || \ + defined(__arm64__) || \ + defined(__arm64) || \ + defined(__arm64__) +#define VL_ARCH_ARM64 +#endif + /** @} */ /** @name Identifying the host data model @@ -299,6 +310,7 @@ defined(__DOXYGEN__) defined(VL_ARCH_IX86) || \ defined(VL_ARCH_IA64) || \ defined(VL_ARCH_X64) || \ + defined(VL_ARCH_ARM64) || \ defined(__DOXYGEN__) #define VL_ARCH_LITTLE_ENDIAN #endif @@ -553,6 +565,7 @@ VL_INLINE void vl_swap_host_big_endianness_2 (void *dst, void* src) ; /** ------------------------------------------------------------------ ** @name Obtaining host info at run time ** @{ */ +#if defined(VL_ARCH_IX86) || defined(VL_ARCH_IA64) || defined(VL_ARCH_X64) typedef struct _VlX86CpuInfo { @@ -572,6 +585,7 @@ typedef struct _VlX86CpuInfo void _vl_x86cpu_info_init (VlX86CpuInfo *self) ; char * _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self) ; +#endif /** @} */ /** ------------------------------------------------------------------ diff --git a/vl/kmeans.c b/vl/kmeans.c index c250ca89..b7c93088 100644 --- a/vl/kmeans.c +++ b/vl/kmeans.c @@ -669,7 +669,7 @@ VL_XCAT(_vl_kmeans_quantize_, SFX) #endif #ifdef _OPENMP -#pragma omp parallel default(none) \ +#pragma omp parallel \ shared(self, distances, assignments, numData, distFn, data) \ num_threads(vl_get_max_threads()) #endif