Skip to content

Commit

Permalink
fix arm compile error (antgroup#240)
Browse files Browse the repository at this point in the history
- add arm test on ci

Signed-off-by: LHT129 <[email protected]>
  • Loading branch information
LHT129 authored Dec 24, 2024
1 parent 2adb25d commit 2698dcb
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 95 deletions.
45 changes: 45 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ workflows:
branches:
ignore:
- main
- pull-request-check-aarch64:
filters:
branches:
ignore:
- main
main-branch-workflow:
jobs:
- main-branch-check:
filters:
branches:
only:
- main
- main-branch-check-aarch64:
filters:
branches:
only:
- main

jobs:
pull-request-check:
Expand All @@ -33,12 +43,46 @@ jobs:
- ./build
- run: make test_parallel

pull-request-check-aarch64:
docker:
- image: ubuntu:22.04
resource_class: arm.medium
steps:
- checkout
- run: bash scripts/deps/install_deps_ubuntu.sh
- restore_cache:
keys:
- fork-cache-arm-{{ checksum "CMakeLists.txt" }}-{{ checksum ".circleci/fresh_ci_cache.commit" }}
- run: make debug
- save_cache:
key: fork-cache-arm-{{ checksum "CMakeLists.txt" }}-{{ checksum ".circleci/fresh_ci_cache.commit" }}
paths:
- ./build
- run: make test_parallel

main-branch-check:
docker:
- image: vsaglib/vsag:ubuntu
resource_class: medium+
steps:
- checkout
- restore_cache:
keys:
- main-ccache-arm-{{ checksum "CMakeLists.txt" }}-{{ checksum ".circleci/fresh_ci_cache.commit" }}
- run: make debug
- save_cache:
key: main-ccache-arm-{{ checksum "CMakeLists.txt" }}-{{ checksum ".circleci/fresh_ci_cache.commit" }}
paths:
- ./build
- run: make test_parallel

main-branch-check-aarch64:
docker:
- image: ubuntu:22.04
resource_class: arm.medium
steps:
- checkout
- run: bash scripts/deps/install_deps_ubuntu.sh
- restore_cache:
keys:
- main-ccache-{{ checksum "CMakeLists.txt" }}-{{ checksum ".circleci/fresh_ci_cache.commit" }}
Expand All @@ -48,3 +92,4 @@ jobs:
paths:
- ./build
- run: make test_parallel

12 changes: 11 additions & 1 deletion scripts/deps/install_deps_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
sudo apt install -y gfortran python3-dev libomp-15-dev lcov intel-mkl
arch=$(uname -m)

if [[ "$arch" == "x86_64" ]]; then
echo "Executing apt install for x86_64"
apt update && apt install -y gfortran python3-dev libomp-15-dev lcov intel-mkl gcc make cmake g++
elif [[ "$arch" == "aarch64" ]]; then
echo "Executing apt install for aarch64"
apt update && apt install -y gfortran python3-dev libomp-15-dev gcc make cmake g++ lcov
else
echo "Unknown architecture: $arch"
fi
1 change: 1 addition & 0 deletions src/simd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set (SIMD_SRCS
sse.cpp
avx.cpp
avx512.cpp
normalize.cpp
)
if (DIST_CONTAINS_SSE)
set (SIMD_SRCS ${SIMD_SRCS} sse.cpp)
Expand Down
5 changes: 5 additions & 0 deletions src/simd/avx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if defined(ENABLE_AVX)
#include <immintrin.h>
#endif

#include <cmath>
#include <cstdint>
Expand All @@ -30,6 +32,7 @@ namespace vsag {
#define PORTABLE_ALIGN32 __attribute__((aligned(32)))
#define PORTABLE_ALIGN64 __attribute__((aligned(64)))

#if defined(ENABLE_AVX)
float
L2SqrSIMD16ExtAVX(const void* pVect1v, const void* pVect2v, const void* qty_ptr) {
float* pVect1 = (float*)pVect1v;
Expand Down Expand Up @@ -163,6 +166,8 @@ PQDistanceAVXFloat256(const void* single_dim_centers, float single_dim_val, void
}
}

#endif

namespace avx2 {

#if defined(ENABLE_AVX2)
Expand Down
20 changes: 12 additions & 8 deletions src/simd/avx512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if defined(ENABLE_AVX512)
#include <immintrin.h>
#endif

#include <cmath>

Expand All @@ -30,6 +31,7 @@ namespace vsag {
#define PORTABLE_ALIGN32 __attribute__((aligned(32)))
#define PORTABLE_ALIGN64 __attribute__((aligned(64)))

#if defined(ENABLE_AVX512)
float
L2SqrSIMD16ExtAVX512(const void* pVect1v, const void* pVect2v, const void* qty_ptr) {
float* pVect1 = (float*)pVect1v;
Expand Down Expand Up @@ -202,6 +204,8 @@ INT8InnerProduct512ResidualsAVX512Distance(const void* pVect1v,
return -INT8InnerProduct512ResidualsAVX512(pVect1v, pVect2v, qty_ptr);
}

#endif

namespace avx512 {
float
FP32ComputeIP(const float* query, const float* codes, uint64_t dim) {
Expand All @@ -221,7 +225,7 @@ FP32ComputeIP(const float* query, const float* codes, uint64_t dim) {
ip += avx2::FP32ComputeIP(query + n * 16, codes + n * 16, dim - n * 16);
return ip;
#else
return vsag::Generic::FP32ComputeIP(query, codes, dim);
return vsag::generic::FP32ComputeIP(query, codes, dim);
#endif
}

Expand All @@ -244,7 +248,7 @@ FP32ComputeL2Sqr(const float* query, const float* codes, uint64_t dim) {
l2 += avx2::FP32ComputeL2Sqr(query + n * 16, codes + n * 16, dim - n * 16);
return l2;
#else
return vsag::Generic::FP32ComputeL2Sqr(query, codes, dim);
return vsag::generic::FP32ComputeL2Sqr(query, codes, dim);
#endif
}

Expand Down Expand Up @@ -282,7 +286,7 @@ SQ8ComputeIP(const float* query,
finalResult += avx2::SQ8ComputeIP(query + i, codes + i, lowerBound + i, diff + i, dim - i);
return finalResult;
#else
return Generic::SQ8ComputeIP(query, codes, lowerBound, diff, dim);
return generic::SQ8ComputeIP(query, codes, lowerBound, diff, dim);
#endif
}

Expand Down Expand Up @@ -320,7 +324,7 @@ SQ8ComputeL2Sqr(const float* query,
result += avx2::SQ8ComputeL2Sqr(query + i, codes + i, lowerBound + i, diff + i, dim - i);
return result;
#else
return Generic::SQ8ComputeL2Sqr(query, codes, lowerBound, diff, dim);
return generic::SQ8ComputeL2Sqr(query, codes, lowerBound, diff, dim);
#endif
}

Expand Down Expand Up @@ -357,7 +361,7 @@ SQ8ComputeCodesIP(const uint8_t* codes1,
result += avx2::SQ8ComputeCodesIP(codes1 + i, codes2 + i, lowerBound + i, diff + i, dim - i);
return result;
#else
return Generic::SQ8ComputeCodesIP(codes1, codes2, lowerBound, diff, dim);
return generic::SQ8ComputeCodesIP(codes1, codes2, lowerBound, diff, dim);
#endif
}

Expand Down Expand Up @@ -390,7 +394,7 @@ SQ8ComputeCodesL2Sqr(const uint8_t* codes1,
result += avx2::SQ8ComputeCodesL2Sqr(codes1 + i, codes2 + i, lowerBound + i, diff + i, dim - i);
return result;
#else
return Generic::SQ8ComputeL2Sqr(query, codes, lowerBound, diff, dim);
return generic::SQ8ComputeCodesL2Sqr(codes1, codes2, lowerBound, diff, dim);
#endif
}

Expand Down Expand Up @@ -494,7 +498,7 @@ SQ8UniformComputeCodesIP(const uint8_t* codes1, const uint8_t* codes2, uint64_t
result += static_cast<int32_t>(avx2::SQ8UniformComputeCodesIP(codes1 + d, codes2 + d, dim - d));
return static_cast<float>(result);
#else
return avx2::S8UniformComputeCodesIP(codes1, codes2, dim);
return avx2::SQ8UniformComputeCodesIP(codes1, codes2, dim);
#endif
}

Expand Down
12 changes: 0 additions & 12 deletions src/simd/fp32_simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@

using namespace vsag;

#ifndef ENABLE_SSE
namespace sse = generic;
#endif

#ifndef ENABLE_AVX2
namespace avx2 = sse;
#endif

#ifndef ENABLE_AVX512
namespace avx512 = avx2;
#endif

#define TEST_ACCURACY(Func) \
{ \
float gt, sse, avx2, avx512; \
Expand Down
12 changes: 0 additions & 12 deletions src/simd/normalize_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@

using namespace vsag;

#ifndef ENABLE_SSE
namespace sse = generic;
#endif

#ifndef ENABLE_AVX2
namespace avx2 = sse;
#endif

#ifndef ENABLE_AVX512
namespace avx512 = avx2;
#endif

TEST_CASE("Normalize SIMD Compute", "[simd]") {
auto dims = fixtures::get_common_used_dims();
int64_t count = 100;
Expand Down
13 changes: 0 additions & 13 deletions src/simd/sq4_simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@

#include <catch2/catch_test_macros.hpp>

#include "../logger.h"
#include "catch2/benchmark/catch_benchmark.hpp"
#include "fixtures.h"

using namespace vsag;

#ifndef ENABLE_SSE
namespace sse = generic;
#endif

#ifndef ENABLE_AVX2
namespace avx2 = sse;
#endif

#ifndef ENABLE_AVX512
namespace avx512 = avx2;
#endif

#define TEST_ACCURACY(Func) \
{ \
auto gt = generic::Func(codes1.data() + i * code_size, \
Expand Down
12 changes: 0 additions & 12 deletions src/simd/sq4_uniform_simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@

using namespace vsag;

#ifndef ENABLE_SSE
namespace sse = generic;
#endif

#ifndef ENABLE_AVX2
namespace avx2 = sse;
#endif

#ifndef ENABLE_AVX512
namespace avx512 = avx2;
#endif

#define TEST_ACCURACY(Func) \
{ \
auto gt = \
Expand Down
2 changes: 0 additions & 2 deletions src/simd/sq8_simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ SQ8ComputeCodesL2Sqr(const uint8_t* codes1,
uint64_t dim);
} // namespace generic

#if defined(ENABLE_SSE)
namespace sse {
float
SQ8ComputeIP(const float* query,
Expand All @@ -72,7 +71,6 @@ SQ8ComputeCodesL2Sqr(const uint8_t* codes1,
const float* diff,
uint64_t dim);
} // namespace sse
#endif

namespace avx2 {
float
Expand Down
14 changes: 1 addition & 13 deletions src/simd/sq8_simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "simd/sq8_simd.h"
#include "sq8_simd.h"

#include "catch2/benchmark/catch_benchmark.hpp"
#include "catch2/catch_test_macros.hpp"
Expand All @@ -22,18 +22,6 @@

using namespace vsag;

#ifndef ENABLE_SSE
namespace sse = generic;
#endif

#ifndef ENABLE_AVX2
namespace avx2 = sse;
#endif

#ifndef ENABLE_AVX512
namespace avx512 = avx2;
#endif

#define TEST_ACCURACY(Func) \
{ \
auto gt = generic::Func( \
Expand Down
12 changes: 0 additions & 12 deletions src/simd/sq8_uniform_simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@

using namespace vsag;

#ifndef ENABLE_SSE
namespace sse = generic;
#endif

#ifndef ENABLE_AVX2
namespace avx2 = sse;
#endif

#ifndef ENABLE_AVX512
namespace avx512 = avx2;
#endif

#define TEST_ACCURACY(Func) \
{ \
auto gt = \
Expand Down
Loading

0 comments on commit 2698dcb

Please sign in to comment.