Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
b171e9ad
Commit
b171e9ad
authored
Jun 23, 2019
by
Paul
Browse files
Refactor pad
parent
1599d553
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
22 deletions
+15
-22
src/targets/gpu/device/include/migraphx/gpu/device/tensor_view.hpp
...ts/gpu/device/include/migraphx/gpu/device/tensor_view.hpp
+1
-0
src/targets/gpu/device/pad.cpp
src/targets/gpu/device/pad.cpp
+14
-22
No files found.
src/targets/gpu/device/include/migraphx/gpu/device/tensor_view.hpp
View file @
b171e9ad
...
@@ -13,6 +13,7 @@ template <class T, std::size_t N>
...
@@ -13,6 +13,7 @@ template <class T, std::size_t N>
struct
hip_tensor_view
struct
hip_tensor_view
{
{
using
value_type
=
T
;
using
value_type
=
T
;
using
hip_index
=
typename
hip_shape
<
N
>::
hip_index
;
__device__
__host__
hip_tensor_view
()
=
default
;
__device__
__host__
hip_tensor_view
()
=
default
;
__host__
hip_tensor_view
(
tensor_view
<
T
>
x
)
:
d
(
x
.
data
()),
s
(
x
.
get_shape
())
{}
__host__
hip_tensor_view
(
tensor_view
<
T
>
x
)
:
d
(
x
.
data
()),
s
(
x
.
get_shape
())
{}
__host__
hip_tensor_view
(
T
*
x
,
const
shape
&
ss
)
:
d
(
x
),
s
(
ss
)
{}
__host__
hip_tensor_view
(
T
*
x
,
const
shape
&
ss
)
:
d
(
x
),
s
(
ss
)
{}
...
...
src/targets/gpu/device/pad.cpp
View file @
b171e9ad
...
@@ -15,33 +15,25 @@ argument
...
@@ -15,33 +15,25 @@ argument
pad
(
hipStream_t
stream
,
argument
result
,
argument
arg1
,
float
value
,
std
::
vector
<
std
::
int64_t
>
pads
)
pad
(
hipStream_t
stream
,
argument
result
,
argument
arg1
,
float
value
,
std
::
vector
<
std
::
int64_t
>
pads
)
{
{
std
::
size_t
nelements
=
arg1
.
get_shape
().
elements
();
std
::
size_t
nelements
=
arg1
.
get_shape
().
elements
();
visit_all
(
result
)([
&
](
auto
output
)
{
hip_visit_all
(
result
,
arg1
)([
&
](
auto
output
,
auto
input
)
{
auto
*
outptr
=
device_cast
(
output
.
data
());
using
type
=
typename
decltype
(
output
)
::
value_type
;
using
type
=
typename
decltype
(
output
)
::
value_type
;
device_type
<
type
>
device_val
=
value
;
using
hip_index
=
typename
decltype
(
output
)
::
hip_index
;
type
device_val
=
value
;
if
(
float_equal
(
value
,
std
::
numeric_limits
<
float
>::
lowest
()))
if
(
float_equal
(
value
,
std
::
numeric_limits
<
float
>::
lowest
()))
{
{
device_val
=
device_cast
(
std
::
numeric_limits
<
type
>::
lowest
());
device_val
=
device_cast
(
std
::
numeric_limits
<
type
>::
lowest
());
}
}
gs_launch
(
stream
,
result
.
get_shape
().
elements
())([
=
](
auto
i
)
{
outptr
[
i
]
=
device_val
;
});
gs_launch
(
stream
,
result
.
get_shape
().
elements
())([
=
](
auto
i
)
{
output
.
data
()[
i
]
=
device_val
;
});
});
visit_all
(
result
,
arg1
)([
&
](
auto
output
,
auto
input
)
{
hip_index
offsets
;
visit_tensor_size
(
result
.
get_shape
().
lens
().
size
(),
[
&
](
auto
ndim
)
{
std
::
copy
(
pads
.
begin
(),
pads
.
begin
()
+
offsets
.
size
(),
offsets
.
begin
());
std
::
size_t
offsets
[
ndim
];
std
::
copy
(
pads
.
begin
(),
pads
.
begin
()
+
ndim
,
offsets
);
auto
*
outptr
=
output
.
data
();
const
auto
*
inptr
=
input
.
data
();
hip_tensor_descriptor
<
ndim
>
desc_input
(
input
.
get_shape
());
hip_tensor_descriptor
<
ndim
>
desc_output
(
output
.
get_shape
());
gs_launch
(
stream
,
nelements
)([
=
](
auto
i
)
{
gs_launch
(
stream
,
nelements
)([
=
](
auto
i
)
{
auto
idx
=
desc_
input
.
multi
(
i
);
auto
idx
=
input
.
get_shape
()
.
multi
(
i
);
for
(
std
::
size_t
j
=
0
;
j
<
ndim
;
j
++
)
for
(
std
::
size_t
j
=
0
;
j
<
offsets
.
size
()
;
j
++
)
{
{
idx
[
j
]
+=
offsets
[
j
];
idx
[
j
]
+=
offsets
[
j
];
}
}
outptr
[
desc_output
.
linear
(
idx
)]
=
inptr
[
i
];
output
[
idx
]
=
input
.
data
()[
i
];
});
});
});
});
});
return
result
;
return
result
;
...
...
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