Skip to content

Commit c9434cf

Browse files
authored
[Windows] fix sequences for Windows (#2359)
1 parent f920405 commit c9434cf

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

speedtests/sequences.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ bool Next(const TRange& range, TValue& value)
172172
template <class TValue, TValue... values>
173173
struct BoostSequence
174174
{
175-
using ValueType = TValue;
175+
using value_type = TValue;
176176
using const_iterator = const TValue*;
177177
constexpr const_iterator begin() const { return arr.begin(); }
178178
constexpr const_iterator end() const { return arr.end(); }
@@ -188,7 +188,7 @@ struct span_impl;
188188
template <class Start, class T, T... Ns>
189189
struct span_impl<Start, std::integer_sequence<T, Ns...>>
190190
{
191-
using ValueType = T;
191+
using value_type = T;
192192
using const_iterator = const T*;
193193
T data[sizeof...(Ns)] = {(Ns + Start{})...};
194194

src/include/miopen/sequences.hpp

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To be a sequence class must follow the concept:
4646
4747
class Sequence
4848
{
49-
using ValueType = <unspecified>;
49+
using value_type = <unspecified>;
5050
5151
Sequence();
5252
@@ -61,11 +61,10 @@ class Sequence
6161
constexpr <unspecified> find(TValue value) const;
6262
}
6363
64-
ValueType may have any constraints depending on specific sequences but it also must have operator==.
65-
It is forbidden to use any of existing sequences with several equal values. It will lead to hangs.
66-
Each of existing sequences which can produce such scenario has assert which will fail with a reason
67-
of failure stated.
68-
Example: sequence 1-2-1 will be looped as:
64+
'value_type' may have any constraints depending on specific sequences but it also must have
65+
operator==. It is forbidden to use any of existing sequences with several equal values. It will lead
66+
to hangs. Each of existing sequences which can produce such scenario has assert which will fail with
67+
a reason of failure stated. Example: sequence 1-2-1 will be looped as:
6968
7069
1-2-1 -> 1-2-1 -> 1-2-1 -> 1-2-1
7170
| | | |
@@ -185,19 +184,27 @@ auto GenericFind(const TRange& range, const TValue& value)
185184
template <class TValue, TValue... values>
186185
struct Sequence
187186
{
188-
using const_iterator = const TValue*;
189-
using ValueType = TValue;
187+
using sequence_type = std::array<TValue, sizeof...(values)>;
188+
using value_type = typename sequence_type::value_type;
189+
using iterator = typename sequence_type::iterator;
190+
using const_iterator = typename sequence_type::const_iterator;
191+
using reference = typename sequence_type::reference;
192+
using const_reference = typename sequence_type::const_reference;
193+
using difference_type = typename sequence_type::difference_type;
190194

191195
Sequence() { assert(ValidateValues() && "Values must be unique"); }
192196

193197
constexpr const_iterator begin() const { return data.begin(); }
194198
constexpr const_iterator end() const { return data.end(); }
195-
constexpr const_iterator find(const TValue& value) const { return data.data() + find_(value); }
199+
constexpr const_iterator find(const_reference value) const
200+
{
201+
return std::next(data.begin(), find_(value));
202+
}
196203

197204
private:
198205
static constexpr std::array<int, sizeof...(values)> data = {{values...}};
199206

200-
static constexpr int ValuesCount() { return sizeof...(values); }
207+
static constexpr difference_type ValuesCount() { return sizeof...(values); }
201208

202209
static constexpr bool ValidateValues()
203210
{
@@ -209,31 +216,31 @@ struct Sequence
209216
return true;
210217
}
211218

212-
template <int icur, TValue cur, TValue... rest>
219+
template <difference_type icur, TValue cur, TValue... rest>
213220
struct Find
214221
{
215-
int operator()(const TValue& value) const
222+
constexpr difference_type operator()(const TValue& value) const
216223
{
217224
if(value == cur)
218225
return icur;
219226
return rest_(value);
220227
}
221228

222-
Find<icur + 1, rest...> rest_ = {};
229+
Find<icur + 1, rest...> rest_{};
223230
};
224231

225-
template <int icur, TValue cur>
232+
template <difference_type icur, TValue cur>
226233
struct Find<icur, cur>
227234
{
228-
int operator()(const TValue& value) const
235+
constexpr difference_type operator()(const TValue& value) const
229236
{
230237
if(value == cur)
231238
return icur;
232239
return icur + 1;
233240
}
234241
};
235242

236-
Find<0, values...> find_ = {};
243+
Find<0, values...> find_{};
237244
};
238245

239246
template <class TValue>
@@ -280,7 +287,7 @@ template <class TValue, TValue low, TValue high>
280287
struct Span
281288
{
282289
using const_iterator = SpanIterator<int, high>;
283-
using ValueType = TValue;
290+
using value_type = TValue;
284291

285292
constexpr const_iterator begin() const { return {low}; }
286293
constexpr const_iterator end() const { return {}; }
@@ -326,7 +333,7 @@ template <class TValue, TValue low, TValue high>
326333
struct TwoPowersSpan
327334
{
328335
using const_iterator = TwoPowersSpanIterator<int, high>;
329-
using ValueType = TValue;
336+
using value_type = TValue;
330337

331338
constexpr const_iterator begin() const { return {low}; }
332339
constexpr const_iterator end() const { return {high + 1}; }
@@ -349,12 +356,12 @@ struct TwoPowersSpan
349356
};
350357

351358
template <class TFirst, class... TRest>
352-
struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
359+
struct JoinIterator : public SequenceIteratorBase<typename TFirst::value_type>
353360
{
354-
using ValueType = typename TFirst::ValueType;
361+
using value_type = typename TFirst::value_type;
355362

356-
JoinIterator() : SequenceIteratorBase<ValueType>(0) {}
357-
JoinIterator(ValueType value_) : SequenceIteratorBase<ValueType>(value_), finished(false) {}
363+
JoinIterator() : SequenceIteratorBase<value_type>(0) {}
364+
JoinIterator(value_type value_) : SequenceIteratorBase<value_type>(value_), finished(false) {}
358365

359366
JoinIterator& operator++()
360367
{
@@ -389,7 +396,7 @@ struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
389396
template <class TCur, class TNext, class... TRest_>
390397
struct Next<TCur, TNext, TRest_...>
391398
{
392-
bool operator()(ValueType& value)
399+
bool operator()(value_type& value)
393400
{
394401
auto it = GenericFind(cur, value);
395402

@@ -415,7 +422,7 @@ struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
415422
template <class TSeq>
416423
struct Next<TSeq>
417424
{
418-
bool operator()(ValueType& value)
425+
bool operator()(value_type& value)
419426
{
420427
auto it = GenericFind(seq, value);
421428

@@ -436,20 +443,20 @@ struct JoinIterator : public SequenceIteratorBase<typename TFirst::ValueType>
436443
template <class TFirst, class... TRest>
437444
struct Join
438445
{
439-
using ValueType = typename TFirst::ValueType;
446+
using value_type = typename TFirst::value_type;
440447
using const_iterator = JoinIterator<TFirst, TRest...>;
441448

442449
Join() { assert(Validate() && "Values must be unique"); }
443450

444451
constexpr const_iterator begin() const { return {*first.begin()}; }
445452
constexpr const_iterator end() const { return {}; }
446-
constexpr const_iterator find(ValueType value) const { return find_(value); }
453+
constexpr const_iterator find(value_type value) const { return find_(value); }
447454

448455
private:
449456
template <class TCur, class... TRest_>
450457
struct Find
451458
{
452-
const_iterator operator()(ValueType value) const
459+
const_iterator operator()(value_type value) const
453460
{
454461
auto it = cur(value);
455462
return it ? it : rest(value);
@@ -463,7 +470,7 @@ struct Join
463470
template <class TSeq>
464471
struct Find<TSeq>
465472
{
466-
const_iterator operator()(ValueType value) const
473+
const_iterator operator()(value_type value) const
467474
{
468475
auto it = GenericFind(seq, value);
469476

@@ -480,7 +487,7 @@ struct Join
480487
bool Validate() const
481488
{
482489
auto cur = begin();
483-
std::vector<ValueType> values(1, *cur);
490+
std::vector<value_type> values(1, *cur);
484491

485492
while(++cur != end())
486493
{
@@ -497,11 +504,11 @@ struct Join
497504
Find<TFirst, TRest...> find_ = {};
498505
};
499506

500-
template <class TInner, typename TInner::ValueType mul>
507+
template <class TInner, typename TInner::value_type mul>
501508
struct MultipliedIterator
502509
{
503510
using InnerIterator = typename TInner::const_iterator;
504-
using ValueType = typename TInner::ValueType;
511+
using value_type = typename TInner::value_type;
505512

506513
MultipliedIterator(InnerIterator inner_) : inner(inner_) {}
507514

@@ -518,7 +525,7 @@ struct MultipliedIterator
518525
return copy;
519526
}
520527

521-
ValueType operator*() const { return mul * *inner; }
528+
value_type operator*() const { return mul * *inner; }
522529
bool operator==(const MultipliedIterator& other) const { return inner == other.inner; }
523530
bool operator!=(const MultipliedIterator& other) const { return !(*this == other); }
524531

@@ -527,15 +534,15 @@ struct MultipliedIterator
527534
};
528535

529536
/// A sequence containing values of another sequence multiplied by a constant.
530-
template <class TInner, typename TInner::ValueType mul>
537+
template <class TInner, typename TInner::value_type mul>
531538
struct Multiplied
532539
{
533-
using ValueType = typename TInner::ValueType;
540+
using value_type = typename TInner::value_type;
534541
using const_iterator = MultipliedIterator<TInner, mul>;
535542

536543
constexpr const_iterator begin() const { return {inner.begin()}; }
537544
constexpr const_iterator end() const { return {inner.end()}; }
538-
constexpr const_iterator find(ValueType value) const
545+
constexpr const_iterator find(value_type value) const
539546
{
540547
return {GenericFind(inner, value / mul)};
541548
}
@@ -614,7 +621,7 @@ bool SeqNextImpl(rank<1>, const Sequence<TValue, first, values...>&, TValue& val
614621
}
615622

616623
template <class TSequence>
617-
bool SeqNextImpl(rank<0>, const TSequence& seq, typename TSequence::ValueType& value)
624+
bool SeqNextImpl(rank<0>, const TSequence& seq, typename TSequence::value_type& value)
618625
{
619626
auto it = GenericFind(seq, value);
620627

@@ -630,7 +637,7 @@ bool SeqNextImpl(rank<0>, const TSequence& seq, typename TSequence::ValueType& v
630637
}
631638

632639
template <class TSequence>
633-
bool SeqNext(const TSequence& seq, typename TSequence::ValueType& value)
640+
bool SeqNext(const TSequence& seq, typename TSequence::value_type& value)
634641
{
635642
return SeqNextImpl(rank<16>{}, seq, value);
636643
}

0 commit comments

Comments
 (0)