Skip to content

Commit

Permalink
Add std/vir::transform with simd execution policy
Browse files Browse the repository at this point in the history
ChangeLog:

	* Makefile: Add transform.cc to ext tests.
	* testsuite/tests/transform.cc: New test.
	* vir/simd_execution.h (simd_load_and_invoke): New overloads.
	(detail::prologue): New; generalized from for_each prologue.
	(simd_transform_prologue): New.
	(simd_transform_epilogue): New.
	(vir::for_each): Replace prologue code with detail::prologue.
	(vir::transform): New.
	(std::transform): New.
	* vir/simdize.h (simd_tuple): Add memory_alignment member.
	* vir/test.cpp: Add simple vir::transform tests.
  • Loading branch information
mattkretz committed Sep 14, 2023
1 parent 6ecb156 commit 7d003aa
Show file tree
Hide file tree
Showing 5 changed files with 564 additions and 34 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $(testdirext)/Makefile: $(srcdir)/testsuite/generate_makefile.sh Makefile
@echo "Generating simd testsuite subdirs and Makefiles ..."
@mkdir -p $(testdirext)
@echo for_each.cc > $(testdirext)/testsuite_files_simd
@echo transform.cc >> $(testdirext)/testsuite_files_simd
@cd $(testdirext) && ../generate_makefile.sh --destination="." --sim="$(sim)" --testflags="-O2 $(testflags)" $(CXX) -std=gnu++2a $(CXXFLAGS) -DVIR_SIMD_TS_DROPIN

testsuite-%: testsuite/build-%/Makefile
Expand Down
70 changes: 70 additions & 0 deletions testsuite/tests/transform.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// expensive: * [1-9] * *
#include "bits/main.h"

#include <numeric>
#include <vector>

#include <vir/simd_iota.h>
#include <vir/simd_execution.h>

template <typename T>
struct Point2D
{
T x,y;
};

template <typename V>
void
test()
{
#if VIR_HAVE_SIMD_EXECUTION
constexpr int N = V::size();
using T = typename V::value_type;
std::vector<T> data0, data1;
std::vector<int> dataInt;
std::vector<Point2D<T>> data2;
data0.resize(N * 16 - 1);
data1.resize(N * 16 - 1);
dataInt.resize(N * 16 - 1);
data2.resize(N * 16 - 1);
std::iota(data0.begin(), data0.end(), T());
/* std::for_each(data2.begin(), data2.end(), [](auto& d) {
d.x = T();
d.y = T();
});*/

VERIFY(data0 != data1);

constexpr auto exec_simd = vir::execution::simd.prefer_size<N>();

T i = 0;
vir::transform(exec_simd, data0, data1, [&i](auto v) {
COMPARE(v, vir::iota_v<decltype(v)> + i);
i += v.size();
return v;
});
COMPARE(i, T(data0.size()));
COMPARE(data0, data1);

vir::transform(exec_simd.template unroll_by<2>(), data0, data1, [&i](auto v) {
return v + 1;
});
vir::transform(exec_simd, data0, data1, data2, [&i](auto v0, auto v1) {
return Point2D{v0, v1 + 2};
});

for (std::size_t i = 0; i < data2.size(); ++i)
{
COMPARE(data2[i].x, T(i));
COMPARE(data2[i].y, T(i + 3));
}

std::transform(exec_simd.prefer_aligned(), data2.begin(), data2.end(), dataInt.begin(),
[](const auto& v) {
return vir::stdx::static_simd_cast<vir::simdize<int, v.size()>>(
std::get<1>(v.as_tuple()) - std::get<0>(v.as_tuple()));
});
for (int x : dataInt)
COMPARE(x, 3);
#endif // VIR_HAVE_SIMD_EXECUTION
}
Loading

0 comments on commit 7d003aa

Please sign in to comment.