-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #920 from xtensor-stack/test/doc
Setup testing of documentation example
- Loading branch information
Showing
17 changed files
with
223 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Only test under some architecture, because it's just a sanity check, no full | ||
# coverage is needed. | ||
|
||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" AND NOT CMAKE_OSX_ARCHITECTURES) | ||
|
||
add_library(test_doc_any_arch OBJECT | ||
explicit_use_of_an_instruction_set_mean_aligned.cpp | ||
explicit_use_of_an_instruction_set_mean_arch_independent.cpp | ||
explicit_use_of_an_instruction_set_mean.cpp | ||
explicit_use_of_an_instruction_set_mean_tag_dispatch.cpp | ||
manipulating_abstract_batches.cpp | ||
manipulating_parametric_batches.cpp | ||
writing_vectorized_code.cpp) | ||
target_include_directories(test_doc_any_arch PRIVATE ${XSIMD_INCLUDE_DIR}) | ||
target_compile_options(test_doc_any_arch PRIVATE -mavx) | ||
|
||
add_library(test_doc_avx2 OBJECT | ||
explicit_use_of_an_instruction_set.cpp | ||
sum_avx2.cpp) | ||
target_compile_options(test_doc_avx2 PRIVATE -mavx2) | ||
target_include_directories(test_doc_avx2 PRIVATE ${XSIMD_INCLUDE_DIR}) | ||
|
||
add_library(test_doc_sse2 OBJECT | ||
sum_sse2.cpp) | ||
target_compile_options(test_doc_sse2 PRIVATE -msse2) | ||
target_include_directories(test_doc_sse2 PRIVATE ${XSIMD_INCLUDE_DIR}) | ||
|
||
add_dependencies(xtest test_doc_any_arch test_doc_avx2 test_doc_sse2) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "xsimd/xsimd.hpp" | ||
#include <iostream> | ||
|
||
namespace xs = xsimd; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
xs::batch<double, xs::avx> a = { 1.5, 2.5, 3.5, 4.5 }; | ||
xs::batch<double, xs::avx> b = { 2.5, 3.5, 4.5, 5.5 }; | ||
auto mean = (a + b) / 2; | ||
std::cout << mean << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "xsimd/xsimd.hpp" | ||
#include <cstddef> | ||
#include <vector> | ||
|
||
void mean(const std::vector<double>& a, const std::vector<double>& b, std::vector<double>& res) | ||
{ | ||
using b_type = xsimd::batch<double, xsimd::avx>; | ||
std::size_t inc = b_type::size; | ||
std::size_t size = res.size(); | ||
// size for which the vectorization is possible | ||
std::size_t vec_size = size - size % inc; | ||
for (std::size_t i = 0; i < vec_size; i += inc) | ||
{ | ||
b_type avec = b_type::load_unaligned(&a[i]); | ||
b_type bvec = b_type::load_unaligned(&b[i]); | ||
b_type rvec = (avec + bvec) / 2; | ||
rvec.store_unaligned(&res[i]); | ||
} | ||
// Remaining part that cannot be vectorize | ||
for (std::size_t i = vec_size; i < size; ++i) | ||
{ | ||
res[i] = (a[i] + b[i]) / 2; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
test/doc/explicit_use_of_an_instruction_set_mean_aligned.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "xsimd/xsimd.hpp" | ||
#include <cstddef> | ||
#include <vector> | ||
|
||
using vector_type = std::vector<double, xsimd::default_allocator<double>>; | ||
void mean(const vector_type& a, const vector_type& b, vector_type& res) | ||
{ | ||
using b_type = xsimd::batch<double>; | ||
std::size_t inc = b_type::size; | ||
std::size_t size = res.size(); | ||
// size for which the vectorization is possible | ||
std::size_t vec_size = size - size % inc; | ||
for (std::size_t i = 0; i < vec_size; i += inc) | ||
{ | ||
b_type avec = b_type::load_aligned(&a[i]); | ||
b_type bvec = b_type::load_aligned(&b[i]); | ||
b_type rvec = (avec + bvec) / 2; | ||
rvec.store_aligned(&res[i]); | ||
} | ||
// Remaining part that cannot be vectorize | ||
for (std::size_t i = vec_size; i < size; ++i) | ||
{ | ||
res[i] = (a[i] + b[i]) / 2; | ||
} | ||
} |
Oops, something went wrong.