Skip to content

Commit f5fd66d

Browse files
authored
Add AVX detection support (#132)
This PR adds the AVX detection utilties.
1 parent 43233c2 commit f5fd66d

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

include/svs/lib/avx_detection.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#ifdef __x86_64__
20+
#include "svs/third-party/eve.h"
21+
#endif
22+
23+
#include <dlfcn.h>
24+
25+
namespace svs::detail {
26+
27+
inline bool is_avx2_supported() {
28+
#ifdef __x86_64__
29+
return eve::is_supported(eve::avx2);
30+
#else
31+
return false;
32+
#endif
33+
}
34+
35+
inline bool is_avx512_supported() {
36+
#ifdef __x86_64__
37+
return eve::is_supported(eve::avx512);
38+
#else
39+
return false;
40+
#endif
41+
}
42+
43+
} // namespace svs::detail

include/svs/third-party/eve.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include "eve/detection.hpp"
1920
#include "eve/module/core.hpp"
2021
#include "eve/wide.hpp"
2122

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ set(TEST_SOURCES
9191
${TEST_DIR}/svs/lib/version.cpp
9292
${TEST_DIR}/svs/lib/uuid.cpp
9393
${TEST_DIR}/svs/lib/concurrency/readwrite_protected.cpp
94+
${TEST_DIR}/svs/lib/avx_detection.cpp
9495
# Third Party
9596
${TEST_DIR}/svs/third-party/fmt.cpp
9697
${TEST_DIR}/svs/third-party/toml.cpp

tests/svs/lib/avx_detection.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// header under test
18+
#include "svs/lib/avx_detection.h"
19+
20+
// catch2
21+
#include "catch2/catch_test_macros.hpp"
22+
#include <iostream>
23+
24+
CATCH_TEST_CASE("AVX detection", "[lib][lib-avx-detection]") {
25+
std::cout << "Checking AVX availability...\n";
26+
std::cout << "AVX 2: " << std::boolalpha << svs::detail::is_avx2_supported() << "\n";
27+
std::cout << "AVX 512: " << std::boolalpha << svs::detail::is_avx512_supported()
28+
<< "\n";
29+
}

0 commit comments

Comments
 (0)