Skip to content

Commit 6e18b02

Browse files
VecBitSet now deployed in StarComplexity
1 parent 5061cb5 commit 6e18b02

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

models/starComplexity.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "starComplexity.h"
2+
#include "vecBitSet.cd"
23
#include "starComplexity.cd"
34
#include "netcomplexity.h"
45
#include "pythonBuffer.h"

models/starComplexity.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ constexpr unsigned maxNodes=22, maxStars=2*maxNodes-1;
55

66
#include "netcomplexity.h"
77

8-
#ifdef SYCL_LANGUAGE_VERSION
9-
8+
#include "vecBitSet.h"
109

1110

1211

1312
class linkRep
1413
{
1514
public:
15+
#ifdef SYCL_LANGUAGE_VERSION
16+
using Impl=VecBitSet<unsigned,4>;
17+
#else
1618
using Impl=/*long long*/ unsigned;
19+
#endif
1720
private:
1821
constexpr static unsigned size=maxNodes*(maxNodes-1)/(16*sizeof(Impl))+1;
1922
Impl data[linkRep::size];
@@ -58,7 +61,7 @@ class linkRep
5861
for (unsigned i=0; i<size; ++i)
5962
{
6063
if (data[i]<x.data[i]) return true;
61-
if (data[i]>x.data[i]) return false;
64+
if (x.data[i]<data[i]) return false;
6265
}
6366
return false;
6467
}

models/vecBitSet.h

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ V swizzleFrom(const V& x) {
1616
} else if constexpr (NumItems<V::size()) { // fill in remainder of permutation
1717
return swizzleFrom<V,0,V::size()-NumItems,NumItems,N...>(x);
1818
} else {
19-
return x.template swizzle<N...>();
19+
return V(x.template swizzle<N...>());
2020
}
2121
}
2222

@@ -44,7 +44,7 @@ class VecBitSet: public sycl::vec<T,N>
4444
swizzleAsg<VecBitSet,T,0,n>(r,0);
4545
return r;
4646
}
47-
return sycl::vec<T,N>(0);
47+
return VecBitSet(0);
4848
}
4949

5050
// shift vector by n positions using a swizzle
@@ -54,7 +54,7 @@ class VecBitSet: public sycl::vec<T,N>
5454
swizzleAsg<VecBitSet,T,N-n,N>(r,0);
5555
return r;
5656
}
57-
return sycl::vec<T,N>(0);
57+
return VecBitSet(0);
5858
}
5959

6060
// returns result of bitshifting to the left
@@ -63,21 +63,28 @@ class VecBitSet: public sycl::vec<T,N>
6363
VecBitSet bitShiftLeft(sycl::vec<T,N> r, const sycl::vec<T,N>& l, unsigned remainder) const {
6464
r>>=(8*sizeof(T)-remainder);
6565
r|=l<<remainder;
66-
return r;
66+
return VecBitSet(r);
6767
}
6868

6969
#ifdef CLASSDESC_ACCESS
7070
CLASSDESC_ACCESS(VecBitSet);
7171
#endif
7272
public:
73+
using Vec=sycl::vec<T,N>;
7374
VecBitSet()=default;
7475
template <class U>
75-
VecBitSet(const U& x): sycl::vec<T,N>(x) {}
76-
template <class U>
77-
VecBitSet& operator=(const U& x) {sycl::vec<T,N>::operator=(x); return *this;}
76+
explicit VecBitSet(const U& x): sycl::vec<T,N>(x) {}
77+
VecBitSet& operator=(T x) {sycl::vec<T,N>::operator=(x); return *this;}
78+
VecBitSet& operator=(const Vec& x) {sycl::vec<T,N>::operator=(x); return *this;}
79+
operator bool() const {
80+
for (unsigned i=0; i<N; ++i)
81+
if ((*this)[i]) return true;
82+
return false;
83+
}
84+
7885
// only need to fix up bit shift operations
79-
VecBitSet operator<<(unsigned n) const {
80-
auto d=div(int(n),8*sizeof(T));
86+
VecBitSet operator<<(int n) const {
87+
auto d=div(n,8*sizeof(T));
8188
switch (d.quot) {
8289
case 0: return bitShiftLeft(shiftLeft<1>(), *this, d.rem);
8390
case 1: return bitShiftLeft(shiftLeft<2>(), shiftLeft<1>(), d.rem);
@@ -94,12 +101,12 @@ class VecBitSet: public sycl::vec<T,N>
94101
case 12: return bitShiftLeft(shiftLeft<13>(), shiftLeft<12>(), d.rem);
95102
case 13: return bitShiftLeft(shiftLeft<14>(), shiftLeft<13>(), d.rem);
96103
case 14: return bitShiftLeft(shiftLeft<15>(), shiftLeft<14>(), d.rem);
97-
case 15: return shiftLeft<15>() >> (8*sizeof(T)-d.rem);
98-
default: return sycl::vec<T,N>(0); // SYCL defines a maximum of 16 elements in a vec.
104+
case 15: return shiftLeft<15>() >> int(8*sizeof(T)-d.rem);
105+
default: return VecBitSet(0); // SYCL defines a maximum of 16 elements in a vec.
99106
}
100107
}
101-
VecBitSet operator>>(unsigned n) const {
102-
auto d=div(int(n),8*sizeof(T));
108+
VecBitSet operator>>(int n) const {
109+
auto d=div(n,8*sizeof(T));
103110
d.rem=(8*sizeof(T)-d.rem)%(8*sizeof(T)); // shift the other way
104111
switch (d.quot) {
105112
case 0: return bitShiftLeft(*this, shiftRight<1>(), d.rem);
@@ -117,13 +124,53 @@ class VecBitSet: public sycl::vec<T,N>
117124
case 12: return bitShiftLeft(shiftRight<12>(), shiftRight<13>(), d.rem);
118125
case 13: return bitShiftLeft(shiftRight<13>(), shiftRight<14>(), d.rem);
119126
case 14: return bitShiftLeft(shiftRight<14>(), shiftRight<15>(), d.rem);
120-
case 15: return shiftRight<15>() >> (8*sizeof(T)-d.rem);
121-
default: return sycl::vec<T,N>(0); // SYCL defines a maximum of 16 elements in a vec.
127+
case 15: return shiftRight<15>() >> d.rem;
128+
default: return VecBitSet(0); // SYCL defines a maximum of 16 elements in a vec.
122129
}
123130
}
131+
132+
int operator<=>(const VecBitSet& x) const {
133+
for (unsigned i=0; i<N; ++i)
134+
{
135+
if ((*this)[i]<x[i]) return -1;
136+
if (x[i]<(*this)[i]) return 1;
137+
}
138+
return 0;
139+
}
124140
};
125141

142+
#define CLASSDESC_json_pack___VecBitSet_T_N_
143+
#define CLASSDESC_json_unpack___VecBitSet_T_N_
144+
#define CLASSDESC_RESTProcess___VecBitSet_T_N_
126145

146+
#include "json_pack_base.h"
147+
namespace classdesc_access
148+
{
149+
template <class T, unsigned N> struct access_json_pack<VecBitSet<T,N>> {
150+
template <class _CD_ARG_TYPE>
151+
void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg)
152+
{
153+
std::vector<T> tmp;
154+
for (unsigned i=0; i<arg.size(); ++i)
155+
tmp.push_back(arg[i]);
156+
targ<<tmp;
157+
}
158+
};
159+
160+
template <class T, unsigned N> struct access_json_unpack<VecBitSet<T,N>> {
161+
template <class _CD_ARG_TYPE>
162+
void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg)
163+
{
164+
std::vector<T> tmp;
165+
targ>>tmp;
166+
for (unsigned i=0; i<arg.size() && i<tmp.size(); ++i)
167+
arg[i]=tmp[i];
168+
}
169+
};
170+
171+
template <class T, unsigned N> struct access_RESTProcess<VecBitSet<T,N>>:
172+
public classdesc::NullDescriptor<classdesc::RESTProcess_t> {};
173+
}
127174

128175
#endif
129176
#endif

0 commit comments

Comments
 (0)