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
e85e0fa1
Commit
e85e0fa1
authored
Jul 11, 2018
by
wsttiger
Browse files
Initial checkin for adding contiguous operator using HIP
parent
8addb9d5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
src/targets/miopen/hip.cpp
src/targets/miopen/hip.cpp
+46
-0
No files found.
src/targets/miopen/hip.cpp
View file @
e85e0fa1
...
...
@@ -11,6 +11,30 @@ namespace miopen {
using
hip_ptr
=
MIGRAPH_MANAGE_PTR
(
void
,
hipFree
);
template
<
int
NDIM
>
struct
HIPTensorDescriptor
{
size_t
lens
[
NDIM
];
size_t
strides
[
NDIM
];
};
template
<
typename
T
,
int
NDIM
>
__global__
void
contiguous_gpu
(
const
T
*
A
,
HIPTensorDescriptor
<
NDIM
>
td_a
,
T
*
At
,
HIPTensorDescriptor
<
NDIM
>
td_at
,
size_t
nelements
)
{
for
(
size_t
i
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
i
<
nelements
;
i
+=
blockDim
.
x
*
gridDim
.
x
)
{
size_t
s
[
NDIM
];
multiindex
<
NDIM
>
(
td_at
.
strides
,
i
,
s
);
size_t
lidx
=
0
;
for
(
size_t
j
=
0
;
j
<
NDIM
;
j
++
)
lidx
+=
s
[
j
]
*
td_a
.
strides
[
j
];
At
[
i
]
=
A
[
lidx
];
}
}
hip_ptr
allocate_gpu
(
std
::
size_t
sz
)
{
void
*
result
;
...
...
@@ -67,6 +91,28 @@ migraph::argument from_gpu(migraph::argument arg)
return
result
;
}
migraph
::
argument
hip_contiguous
(
migraph
::
argument
arg
,
migraph
::
shape
output_shape
)
{
migraph
::
argument
result
{
output_shape
};
visit_all
(
result
,
arg
)([
&
](
auto
output
,
auto
input
)
{
HIPTensorDescriptor
td_a
,
td_at
;
auto
s
=
arg
.
get_shape
();
for
(
int
i
=
0
;
i
<
output_shape
.
lens
().
size
();
i
++
)
{
td_a
.
strides
[
i
]
=
s
.
strides
().
at
(
i
);
td_at
.
strides
[
i
]
=
output_shape
.
strides
().
at
(
i
);
}
dim3
nblocks
(
512
);
dim3
nthreads
(
512
);
hipLaunchKernelGGL
((
contiguous_gpu
<
int
,
4
>
),
nblocks
,
nthreads
,
0
,
0
,
input
.
data
(),
td_a
,
output
.
data
(),
td_at
,
s
.
elements
());
});
return
result
;
}
}
// namespace miopen
}
// namespace migraph
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