Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
dd900bf2
Commit
dd900bf2
authored
Aug 19, 2022
by
Paul
Browse files
Array foreach
parent
924a0ffa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
src/targets/gpu/kernels/include/migraphx/kernels/array.hpp
src/targets/gpu/kernels/include/migraphx/kernels/array.hpp
+15
-10
No files found.
src/targets/gpu/kernels/include/migraphx/kernels/array.hpp
View file @
dd900bf2
...
@@ -37,45 +37,50 @@ namespace migraphx {
...
@@ -37,45 +37,50 @@ namespace migraphx {
template <class U> \
template <class U> \
constexpr array& operator op(const array<U, N>& x) \
constexpr array& operator op(const array<U, N>& x) \
{ \
{ \
for(index_int i = 0; i < N; i++) \
array_for_each(*this, x)([](auto& sy, auto sx) { sy op sx; }); \
d[i] op x[i]; \
return *this; \
return *this; \
} \
} \
template <class U, MIGRAPHX_REQUIRES(is_convertible<U, T>{})> \
template <class U, MIGRAPHX_REQUIRES(is_convertible<U, T>{})> \
constexpr array& operator op(const U& x) \
constexpr array& operator op(const U& x) \
{ \
{ \
for(index_int i = 0; i < N; i++) \
array_for_each(*this)([&](auto& sy) { sy op x; }); \
d[i] op x; \
return *this; \
return *this; \
} \
} \
template <class U> \
template <class U> \
friend constexpr auto operator binary_op(const array& x, const array<U, N>& y) \
friend constexpr auto operator binary_op(const array& x, const array<U, N>& y) \
{ \
{ \
array<decltype(T {} binary_op U{}), N> z{}; \
array<decltype(T {} binary_op U{}), N> z{}; \
for(index_int i = 0; i < N; i++) \
array_for_each(z, x, y)([&](auto& sz, auto sx, auto sy) { sz = sx binary_op sy; }); \
z[i] = x[i] binary_op y[i]; \
return z; \
return z; \
} \
} \
template <class U, MIGRAPHX_REQUIRES(is_convertible<U, T>{})> \
template <class U, MIGRAPHX_REQUIRES(is_convertible<U, T>{})> \
friend constexpr auto operator binary_op(const array& x, const U& y) \
friend constexpr auto operator binary_op(const array& x, const U& y) \
{ \
{ \
array<decltype(T {} binary_op U{}), N> z{}; \
array<decltype(T {} binary_op U{}), N> z{}; \
for(index_int i = 0; i < N; i++) \
array_for_each(z, x)([&](auto& sz, auto sx) { sz = sx binary_op y; }); \
z[i] = x[i] binary_op y; \
return z; \
return z; \
} \
} \
template <class U, MIGRAPHX_REQUIRES(is_convertible<U, T>{})> \
template <class U, MIGRAPHX_REQUIRES(is_convertible<U, T>{})> \
friend constexpr auto operator binary_op(const U& x, const array& y) \
friend constexpr auto operator binary_op(const U& x, const array& y) \
{ \
{ \
array<decltype(T {} binary_op U{}), N> z{}; \
array<decltype(T {} binary_op U{}), N> z{}; \
for(index_int i = 0; i < N; i++) \
array_for_each(z, y)([&](auto& sz, auto sy) { sz = x binary_op sy; }); \
z[i] = x binary_op y[i]; \
return z; \
return z; \
}
}
template
<
class
T
,
class
...
Ts
>
constexpr
auto
array_for_each
(
T
&
x
,
Ts
&
...
xs
)
{
return
[
&
](
auto
f
)
{
for
(
index_int
i
=
0
;
i
<
x
.
size
();
i
++
)
f
(
x
[
i
],
xs
[
i
]...);
};
}
template
<
class
T
,
index_int
N
>
template
<
class
T
,
index_int
N
>
struct
array
struct
array
{
{
using
value_type
=
T
;
T
d
[
N
];
T
d
[
N
];
constexpr
T
&
operator
[](
index_int
i
)
constexpr
T
&
operator
[](
index_int
i
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment