Grid 0.7.0
Lattice_where.h
Go to the documentation of this file.
1 /*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/lattice/Lattice_where.h
6
7 Copyright (C) 2015
8
9Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
10Author: Peter Boyle <paboyle@ph.ed.ac.uk>
11Author: Peter Boyle <peterboyle@Peters-MacBook-Pro-2.local>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
27 See the full license in the file "LICENSE" in the top level distribution directory
28 *************************************************************************************/
29 /* END LEGAL */
30#ifndef GRID_LATTICE_WHERE_H
31#define GRID_LATTICE_WHERE_H
32namespace Grid {
33// Must implement the predicate gating the
34// Must be able to reduce the predicate down to a single vInteger per site.
35// Must be able to require the type be iScalar x iScalar x ....
36// give a GetVtype method in iScalar
37// and blow away the tensor structures.
38//
39template<class vobj,class iobj>
40inline void whereWolf(Lattice<vobj> &ret,const Lattice<iobj> &predicate,Lattice<vobj> &iftrue,Lattice<vobj> &iffalse)
41{
42 conformable(iftrue,iffalse);
43 conformable(iftrue,predicate);
44 conformable(iftrue,ret);
45
46 GridBase *grid=iftrue.Grid();
47
48 typedef typename vobj::scalar_object scalar_object;
49 typedef typename vobj::scalar_type scalar_type;
50 typedef typename vobj::vector_type vector_type;
51 typedef typename iobj::vector_type mask_type;
52
53 const int Nsimd = grid->Nsimd();
54
55 autoView(iftrue_v,iftrue,CpuRead);
56 autoView(iffalse_v,iffalse,CpuRead);
57 autoView(predicate_v,predicate,CpuRead);
58 autoView(ret_v,ret,CpuWrite);
59 Integer NN= grid->oSites();
60 thread_for(ss,NN,{
61 Integer mask;
62 scalar_object trueval;
63 scalar_object falseval;
64 for(int l=0;l<Nsimd;l++){
65 trueval =extractLane(l,iftrue_v[ss]);
66 falseval=extractLane(l,iffalse_v[ss]);
67 mask =extractLane(l,predicate_v[ss]);
68 if (mask) falseval=trueval;
69 insertLane(l,ret_v[ss],falseval);
70 }
71 });
72}
73
74template<class vobj,class iobj>
75inline Lattice<vobj> whereWolf(const Lattice<iobj> &predicate,Lattice<vobj> &iftrue,Lattice<vobj> &iffalse)
76{
77 conformable(iftrue,iffalse);
78 conformable(iftrue,predicate);
79
80 Lattice<vobj> ret(iftrue.Grid());
81
82 whereWolf(ret,predicate,iftrue,iffalse);
83
84 return ret;
85}
86}
87#endif
void conformable(const Lattice< obj1 > &lhs, const Lattice< obj2 > &rhs)
#define autoView(l_v, l, mode)
@ CpuRead
@ CpuWrite
uint32_t Integer
Definition Simd.h:58
accelerator_inline void insertLane(int lane, vobj &__restrict__ vec, const typename vobj::scalar_object &__restrict__ extracted)
accelerator_inline vobj::scalar_object extractLane(int lane, const vobj &__restrict__ vec)
#define thread_for(i, num,...)
Definition Threads.h:60
int oSites(void) const
int Nsimd(void) const
GridBase * Grid(void) const
void whereWolf(Lattice< vobj > &ret, const Lattice< iobj > &predicate, Lattice< vobj > &iftrue, Lattice< vobj > &iffalse)