1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-12-21 21:24:30 +00:00

Introduce accelerator friendly expression template rewrite.

Must obtain and access lattice indexing through a view object that is safe
to copy construct in copy to GPU (without copying the lattice).
This commit is contained in:
paboyle
2018-03-04 16:03:19 +00:00
parent dad7862f91
commit 0e6197fbed
16 changed files with 470 additions and 513 deletions

View File

@@ -38,12 +38,13 @@ NAMESPACE_BEGIN(Grid);
// Trace
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class vobj>
inline auto trace(const Lattice<vobj> &lhs)
-> Lattice<decltype(trace(lhs[0]))>
inline auto trace(const Lattice<vobj> &lhs) -> Lattice<decltype(trace(vobj()))>
{
Lattice<decltype(trace(lhs[0]))> ret(lhs.Grid());
accelerator_loop( ss, lhs, {
ret[ss] = trace(lhs[ss]);
Lattice<decltype(trace(vobj()))> ret(lhs.Grid());
auto ret_v = ret.View();
auto lhs_v = lhs.View();
accelerator_loop( ss, lhs_v, {
ret_v[ss] = trace(lhs_v[ss]);
});
return ret;
};
@@ -52,11 +53,13 @@ inline auto trace(const Lattice<vobj> &lhs)
// Trace Index level dependent operation
////////////////////////////////////////////////////////////////////////////////////////////////////
template<int Index,class vobj>
inline auto TraceIndex(const Lattice<vobj> &lhs) -> Lattice<decltype(traceIndex<Index>(lhs[0]))>
inline auto TraceIndex(const Lattice<vobj> &lhs) -> Lattice<decltype(traceIndex<Index>(vobj()))>
{
Lattice<decltype(traceIndex<Index>(lhs[0]))> ret(lhs.Grid());
accelerator_loop( ss, lhs, {
ret[ss] = traceIndex<Index>(lhs[ss]);
Lattice<decltype(traceIndex<Index>(vobj()))> ret(lhs.Grid());
auto ret_v = ret.View();
auto lhs_v = lhs.View();
accelerator_loop( ss, lhs_v, {
ret_v[ss] = traceIndex<Index>(lhs_v[ss]);
});
return ret;
};