5 template <
int N>
class extent;
10 template <
int N>
class extent;
16 template <
int...>
struct __indices {};
18 template <
int _Sp,
class _IntTuple,
int _Ep>
19 struct __make_indices_imp;
21 template <
int _Sp,
int ..._Indices,
int _Ep>
22 struct __make_indices_imp<_Sp, __indices<_Indices...>, _Ep> {
23 typedef typename __make_indices_imp<_Sp+1, __indices<_Indices..., _Sp>, _Ep>::type type;
26 template <
int _Ep,
int ..._Indices>
27 struct __make_indices_imp<_Ep, __indices<_Indices...>, _Ep> {
28 typedef __indices<_Indices...> type;
31 template <
int _Ep,
int _Sp = 0>
32 struct __make_indices {
33 static_assert(_Sp <= _Ep,
"__make_indices input error");
34 typedef typename __make_indices_imp<_Sp, __indices<>, _Ep>::type type;
42 explicit __index_leaf(
int __t) restrict(amp,cpu) : __idx(__t) {}
44 __index_leaf& operator=(
const int __t) restrict(amp,cpu) {
48 __index_leaf& operator+=(
const int __t) restrict(amp,cpu) {
52 __index_leaf& operator-=(
const int __t) restrict(amp,cpu) {
56 __index_leaf& operator*=(
const int __t) restrict(amp,cpu) {
60 __index_leaf& operator/=(
const int __t) restrict(amp,cpu) {
64 __index_leaf& operator%=(
const int __t) restrict(amp,cpu) {
68 int&
get() restrict(amp,cpu) {
return __idx; }
69 const int&
get()
const restrict(amp,cpu) {
return __idx; }
72 template <
class _Indx>
struct index_impl;
75 struct index_impl<__indices<N...> > :
public __index_leaf<N>... {
76 index_impl() restrict(amp,cpu) : __index_leaf<N>(0)... {}
78 template<
class ..._Up>
79 explicit index_impl(_Up... __u) restrict(amp,cpu)
80 : __index_leaf<N>(__u)... {}
82 index_impl(
const index_impl& other) restrict(amp,cpu)
83 : index_impl(static_cast<const __index_leaf<N>&>(other).get()...) {}
85 index_impl(
int component) restrict(amp,cpu)
86 : __index_leaf<N>(component)... {}
87 index_impl(
int components[]) restrict(amp,cpu)
88 : __index_leaf<N>(components[N])... {}
89 index_impl(
const int components[]) restrict(amp,cpu)
90 : __index_leaf<N>(components[N])... {}
92 template<
class ..._Tp>
93 inline void __swallow(_Tp...) restrict(amp,cpu) {}
95 int operator[] (
unsigned int c)
const restrict(amp,cpu) {
96 return static_cast<const __index_leaf<0>&
>(*((__index_leaf<0> *)
this + c)).
get();
98 int& operator[] (
unsigned int c) restrict(amp,cpu) {
99 return static_cast<__index_leaf<0>&
>(*((__index_leaf<0> *)
this + c)).
get();
101 index_impl& operator=(
const index_impl& __t) restrict(amp,cpu) {
102 __swallow(__index_leaf<N>::operator=(
static_cast<const __index_leaf<N>&
>(__t).
get())...);
105 index_impl& operator+=(
const index_impl& __t) restrict(amp,cpu) {
106 __swallow(__index_leaf<N>::operator+=(
static_cast<const __index_leaf<N>&
>(__t).
get())...);
109 index_impl& operator-=(
const index_impl& __t) restrict(amp,cpu) {
110 __swallow(__index_leaf<N>::operator-=(
static_cast<const __index_leaf<N>&
>(__t).
get())...);
113 index_impl& operator*=(
const index_impl& __t) restrict(amp,cpu) {
114 __swallow(__index_leaf<N>::operator*=(
static_cast<const __index_leaf<N>&
>(__t).
get())...);
117 index_impl& operator/=(
const index_impl& __t) restrict(amp,cpu) {
118 __swallow(__index_leaf<N>::operator/=(
static_cast<const __index_leaf<N>&
>(__t).
get())...);
121 index_impl& operator%=(
const index_impl& __t) restrict(amp,cpu) {
122 __swallow(__index_leaf<N>::operator%=(
static_cast<const __index_leaf<N>&
>(__t).
get())...);
125 index_impl& operator+=(
const int __t) restrict(amp,cpu) {
126 __swallow(__index_leaf<N>::operator+=(__t)...);
129 index_impl& operator-=(
const int __t) restrict(amp,cpu) {
130 __swallow(__index_leaf<N>::operator-=(__t)...);
133 index_impl& operator*=(
const int __t) restrict(amp,cpu) {
134 __swallow(__index_leaf<N>::operator*=(__t)...);
137 index_impl& operator/=(
const int __t) restrict(amp,cpu) {
138 __swallow(__index_leaf<N>::operator/=(__t)...);
141 index_impl& operator%=(
const int __t) restrict(amp,cpu) {
142 __swallow(__index_leaf<N>::operator%=(__t)...);
147 template <
int N,
typename _Tp>
150 static inline void set(_Tp& now) restrict(amp,cpu) {
151 now[N - 1] = amp_get_global_id(_Tp::rank - N);
152 index_helper<N - 1, _Tp>::set(now);
154 static inline bool equal(
const _Tp& _lhs,
const _Tp& _rhs) restrict(amp,cpu) {
155 return (_lhs[N - 1] == _rhs[N - 1]) &&
156 (index_helper<N - 1, _Tp>::equal(_lhs, _rhs));
158 static inline int count_size(
const _Tp& now) restrict(amp,cpu) {
159 return now[N - 1] * index_helper<N - 1, _Tp>::count_size(now);
163 template<
typename _Tp>
164 struct index_helper<1, _Tp>
166 static inline void set(_Tp& now) restrict(amp,cpu) {
167 now[0] = amp_get_global_id(_Tp::rank - 1);
169 static inline bool equal(
const _Tp& _lhs,
const _Tp& _rhs) restrict(amp,cpu) {
170 return (_lhs[0] == _rhs[0]);
172 static inline int count_size(
const _Tp& now) restrict(amp,cpu) {
177 template <
int N,
typename _Tp1,
typename _Tp2>
180 static bool inline contains(
const _Tp1& idx,
const _Tp2& ext) restrict(amp,cpu) {
181 return idx[N - 1] >= 0 && idx[N - 1] < ext[N - 1] &&
182 amp_helper<N - 1, _Tp1, _Tp2>::contains(idx, ext);
185 static bool inline contains(
const _Tp1& idx,
const _Tp2& ext,
const _Tp2& ext2) restrict(amp,cpu) {
186 return idx[N - 1] >= 0 && ext[N - 1] > 0 && (idx[N - 1] + ext[N - 1]) <= ext2[N - 1] &&
187 amp_helper<N - 1, _Tp1, _Tp2>::contains(idx, ext,ext2);
190 static int inline flatten(
const _Tp1& idx,
const _Tp2& ext) restrict(amp,cpu) {
191 return idx[N - 1] + ext[N - 1] * amp_helper<N - 1, _Tp1, _Tp2>::flatten(idx, ext);
193 static void inline minus(
const _Tp1& idx, _Tp2& ext) restrict(amp,cpu) {
194 ext.base_ -= idx.base_;
198 template <
typename _Tp1,
typename _Tp2>
199 struct amp_helper<1, _Tp1, _Tp2>
201 static bool inline contains(
const _Tp1& idx,
const _Tp2& ext) restrict(amp,cpu) {
202 return idx[0] >= 0 && idx[0] < ext[0];
205 static bool inline contains(
const _Tp1& idx,
const _Tp2& ext,
const _Tp2& ext2) restrict(amp,cpu) {
206 return idx[0] >= 0 && ext[0] > 0 && (idx[0] + ext[0]) <= ext2[0] ;
209 static int inline flatten(
const _Tp1& idx,
const _Tp2& ext) restrict(amp,cpu) {
212 static void inline minus(
const _Tp1& idx, _Tp2& ext) restrict(amp,cpu) {
213 ext.base_ -= idx.base_;
231 static const int rank = N;
242 index() restrict(amp,cpu) : base_() {
243 static_assert( N>0,
"rank should bigger than 0 ");
254 : base_(other.base_) {}
265 explicit index(
int i0) restrict(amp,cpu)
268 template <
typename ..._Tp>
269 explicit index(_Tp ... __t) restrict(amp,cpu)
271 static_assert(
sizeof...(_Tp) <= 3,
"Explicit constructor with rank greater than 3 is not allowed");
272 static_assert(
sizeof...(_Tp) == N,
"rank should be consistency");
285 explicit index(
const int components[]) restrict(amp,cpu)
286 : base_(components) {}
297 explicit index(
int components[]) restrict(amp,cpu)
298 : base_(components) {}
308 base_.operator=(other.base_);
319 int operator[] (
unsigned int c)
const restrict(amp,cpu) {
322 int& operator[] (
unsigned int c) restrict(amp,cpu) {
340 bool operator== (
const index& other)
const restrict(amp,cpu) {
341 return index_helper<N, index<N> >::equal(*
this, other);
343 bool operator!= (
const index& other)
const restrict(amp,cpu) {
344 return !(*
this == other);
358 base_.operator+=(rhs.base_);
362 base_.operator-=(rhs.base_);
368 base_.operator*=(__r.base_);
373 base_.operator/=(__r.base_);
378 base_.operator%=(__r.base_);
393 base_.operator+=(value);
397 base_.operator-=(value);
401 base_.operator*=(value);
405 base_.operator/=(value);
409 base_.operator%=(value);
445 typedef index_impl<typename __make_indices<N>::type> base;
449 template <
int K,
typename Q>
friend struct index_helper;
450 template <
int K,
typename Q1,
typename Q2>
friend struct amp_helper;
453 __attribute__((annotate(
"__cxxamp_opencl_index")))
454 void __cxxamp_opencl_index() restrict(amp,cpu)
455 #if __KALMAR_ACCELERATOR__ == 1 457 index_helper<N, index<N>>::set(*
this);
459 #elif __KALMAR_ACCELERATOR__ == 2 || __KALMAR_CPU__ == 2 index & operator++()
For a given operator , produces the same effect as (*this) = (*this) 1;.
Definition: kalmar_index.h:423
index(int components[])
Constructs an index<N> with the coordinate values provided the array of int component values...
Definition: kalmar_index.h:297
index & operator--()
For a given operator , produces the same effect as (*this) = (*this) 1;.
Definition: kalmar_index.h:432
extent< N > operator/(const extent< N > &ext, int value)
Binary arithmetic operations that produce a new extent<N> that is the result of performing the corres...
Definition: amp.h:4651
index & operator*=(int value)
For a given operator , produces the same effect as (*this) = (*this) value; The return value is "*th...
Definition: kalmar_index.h:400
index & operator/=(int value)
For a given operator , produces the same effect as (*this) = (*this) value; The return value is "*th...
Definition: kalmar_index.h:404
Represents a unique position in N-dimensional space.
Definition: hc.hpp:58
C++ AMP namespace.
Definition: amp.h:25
extent< N > operator+(const extent< N > &lhs, const extent< N > &rhs)
Adds (or subtracts) two objects of extent<N> to form a new extent.
Definition: amp.h:4584
index & operator=(const index &other)
Assigns the component values of "other" to this index<N> object.
Definition: kalmar_index.h:307
namespace for internal classes of Kalmar compiler / runtime
Definition: hc.hpp:42
index & operator%=(int value)
For a given operator , produces the same effect as (*this) = (*this) value; The return value is "*th...
Definition: kalmar_index.h:408
int value_type
The element type of index<N>.
Definition: kalmar_index.h:236
index operator++(int)
For a given operator , produces the same effect as (*this) = (*this) 1;.
Definition: kalmar_index.h:427
index & operator%=(const index &__r)
For a given operator , produces the same effect as (*this) = (*this) rhs; The return value is "*this...
Definition: kalmar_index.h:377
extent< N > operator*(const extent< N > &ext, int value)
Binary arithmetic operations that produce a new extent<N> that is the result of performing the corres...
Definition: amp.h:4639
extent< N > operator-(const extent< N > &lhs, const extent< N > &rhs)
Adds (or subtracts) two objects of extent<N> to form a new extent.
Definition: amp.h:4590
index(_Tp...__t)
Constructs an index<N> with the coordinate values provided by .
Definition: kalmar_index.h:269
index & operator*=(const index &__r)
For a given operator , produces the same effect as (*this) = (*this) rhs; The return value is "*this...
Definition: kalmar_index.h:367
Represents a unique position in N-dimensional space.
Definition: amp.h:31
index & operator+=(const index &rhs)
For a given operator , produces the same effect as (*this) = (*this) rhs; The return value is "*this...
Definition: kalmar_index.h:357
Represents a unique position in N-dimensional space.
Definition: kalmar_index.h:226
index & operator-=(const index &rhs)
For a given operator , produces the same effect as (*this) = (*this) rhs; The return value is "*this...
Definition: kalmar_index.h:361
extent< N > operator%(const extent< N > &ext, int value)
Binary arithmetic operations that produce a new extent<N> that is the result of performing the corres...
Definition: amp.h:4663
index(const index &other)
Copy constructor.
Definition: kalmar_index.h:253
index & operator+=(int value)
For a given operator , produces the same effect as (*this) = (*this) value; The return value is "*th...
Definition: kalmar_index.h:392
index(int i0)
Constructs an index<N> with the coordinate values provided by .
Definition: kalmar_index.h:265
index()
Default constructor.
Definition: kalmar_index.h:242
index operator--(int)
For a given operator , produces the same effect as (*this) = (*this) 1;.
Definition: kalmar_index.h:436
index & operator/=(const index &__r)
For a given operator , produces the same effect as (*this) = (*this) rhs; The return value is "*this...
Definition: kalmar_index.h:372
Heterogeneous C++ (HC) namespace.
Definition: grid_launch.h:10
index(const int components[])
Constructs an index<N> with the coordinate values provided the array of int component values...
Definition: kalmar_index.h:285
index & operator-=(int value)
For a given operator , produces the same effect as (*this) = (*this) value; The return value is "*th...
Definition: kalmar_index.h:396