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
0fb084b3
Commit
0fb084b3
authored
Jun 29, 2022
by
Paul
Browse files
Format
parent
78be5944
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
51 deletions
+49
-51
src/targets/gpu/kernels/include/migraphx/kernels/array.hpp
src/targets/gpu/kernels/include/migraphx/kernels/array.hpp
+1
-1
src/targets/gpu/kernels/include/migraphx/kernels/shape.hpp
src/targets/gpu/kernels/include/migraphx/kernels/shape.hpp
+48
-50
No files found.
src/targets/gpu/kernels/include/migraphx/kernels/array.hpp
View file @
0fb084b3
...
...
@@ -209,7 +209,7 @@ struct integral_const_array : array<T, sizeof...(Xs)>
MIGRAPHX_DEVICE_CONSTEXPR
integral_const_array
()
:
base_array
({
Xs
...})
{}
};
template
<
class
F
>
template
<
class
F
>
constexpr
auto
return_const_array
(
F
f
)
{
constexpr
const
auto
a
=
f
();
...
...
src/targets/gpu/kernels/include/migraphx/kernels/shape.hpp
View file @
0fb084b3
...
...
@@ -102,64 +102,62 @@ struct shape
{
if
constexpr
(
shape
{}.
standard
())
MIGRAPHX_ASSERT
(
i
==
compute_index
(
i
));
return
i
;
}
else
{
return
compute_index
(
i
);
}
}
constexpr
index_int
compute_index
(
index_int
i
)
const
{
constexpr
auto
sstrides
=
compute_standard_strides
();
constexpr
auto
rank
=
Lens
{}.
size
();
index_int
result
=
0
;
repeat
(
rank
,
[
&
](
auto
j
)
{
constexpr
auto
k
=
rank
-
j
-
1
;
constexpr
auto
stride
=
Strides
{}[
k
];
constexpr
auto
len
=
Lens
{}[
k
];
if
constexpr
(
stride
!=
0
)
{
constexpr
auto
s
=
sstrides
[
k
];
constexpr
auto
slen
=
s
*
len
;
auto
idx
=
(
i
%
slen
)
/
s
;
result
+=
stride
*
idx
;
}
});
return
result
;
return
i
;
}
else
{
return
compute_index
(
i
);
}
}
/// Convert single index into a multi-index
constexpr
index_array
multi
(
index_int
idx
)
const
{
index_array
result
;
index_int
tidx
=
idx
;
for
(
diff_int
is
=
result
.
size
()
-
1
;
is
>
0
;
is
--
)
constexpr
index_int
compute_index
(
index_int
i
)
const
{
constexpr
auto
sstrides
=
compute_standard_strides
();
constexpr
auto
rank
=
Lens
{}.
size
();
index_int
result
=
0
;
repeat
(
rank
,
[
&
](
auto
j
)
{
constexpr
auto
k
=
rank
-
j
-
1
;
constexpr
auto
stride
=
Strides
{}[
k
];
constexpr
auto
len
=
Lens
{}[
k
];
if
constexpr
(
stride
!=
0
)
{
result
[
is
]
=
tidx
%
lens
[
is
];
tidx
=
tidx
/
lens
[
is
];
constexpr
auto
s
=
sstrides
[
k
];
constexpr
auto
slen
=
s
*
len
;
auto
idx
=
(
i
%
slen
)
/
s
;
result
+=
stride
*
idx
;
}
result
[
0
]
=
tidx
;
return
result
;
}
/// Convert multi-index into a single index
constexpr
index_int
single
(
index_array
idx
)
const
});
return
result
;
}
/// Convert single index into a multi-index
constexpr
index_array
multi
(
index_int
idx
)
const
{
index_array
result
;
index_int
tidx
=
idx
;
for
(
diff_int
is
=
result
.
size
()
-
1
;
is
>
0
;
is
--
)
{
if
(
idx
.
empty
())
return
0
;
return
inner_product
(
lens
.
begin
()
+
1
,
lens
.
end
(),
idx
.
begin
(),
idx
.
back
());
result
[
is
]
=
tidx
%
lens
[
is
];
tidx
=
tidx
/
lens
[
is
];
}
result
[
0
]
=
tidx
;
return
result
;
}
/// Convert multi-index into a single index
constexpr
index_int
single
(
index_array
idx
)
const
{
if
(
idx
.
empty
())
return
0
;
return
inner_product
(
lens
.
begin
()
+
1
,
lens
.
end
(),
idx
.
begin
(),
idx
.
back
());
}
constexpr
shape
get_shape
()
const
{
return
*
this
;
}
constexpr
shape
get_shape
()
const
{
return
*
this
;
}
template
<
class
Stream
>
friend
constexpr
const
Stream
&
operator
<<
(
const
Stream
&
ss
,
const
shape
&
s
)
{
ss
<<
"{"
<<
s
.
lens
<<
"}, {"
<<
s
.
strides
<<
"}"
;
return
ss
;
}
};
template
<
class
Stream
>
friend
constexpr
const
Stream
&
operator
<<
(
const
Stream
&
ss
,
const
shape
&
s
)
{
ss
<<
"{"
<<
s
.
lens
<<
"}, {"
<<
s
.
strides
<<
"}"
;
return
ss
;
}
};
// namespace migraphx
template
<
class
Lens
,
class
Strides
>
constexpr
shape
<
Lens
,
Strides
>
make_shape
(
Lens
lens
,
Strides
strides
)
...
...
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