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
9164116a
Commit
9164116a
authored
Aug 18, 2018
by
Paul
Browse files
Add a pass to remove allocations on the gpu
parent
aa5e156d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
0 deletions
+74
-0
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+1
-0
src/targets/gpu/eliminate_allocation.cpp
src/targets/gpu/eliminate_allocation.cpp
+35
-0
src/targets/gpu/include/migraph/gpu/eliminate_allocation.hpp
src/targets/gpu/include/migraph/gpu/eliminate_allocation.hpp
+20
-0
src/targets/gpu/include/migraph/gpu/hip.hpp
src/targets/gpu/include/migraph/gpu/hip.hpp
+16
-0
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+2
-0
No files found.
src/targets/gpu/CMakeLists.txt
View file @
9164116a
...
...
@@ -18,6 +18,7 @@ target_link_libraries(migraph_device migraph hip::device)
target_include_directories
(
migraph_device PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/include>
)
add_library
(
migraph_gpu
eliminate_allocation.cpp
eliminate_workspace.cpp
hip.cpp
target.cpp
...
...
src/targets/gpu/eliminate_allocation.cpp
0 → 100644
View file @
9164116a
#include <migraph/gpu/eliminate_allocation.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/program.hpp>
#include <migraph/instruction.hpp>
#include <migraph/operators.hpp>
#include <migraph/iterator_for.hpp>
#include <migraph/ranges.hpp>
#include <migraph/stringutils.hpp>
namespace
migraph
{
namespace
gpu
{
void
eliminate_allocation
::
apply
(
program
&
p
)
const
{
std
::
size_t
n
=
0
;
std
::
vector
<
std
::
pair
<
instruction_ref
,
std
::
size_t
>>
allocs
;
for
(
auto
ins
:
iterator_for
(
p
))
{
if
(
ins
->
op
.
name
()
!=
"hip::allocate"
)
continue
;
allocs
.
emplace_back
(
ins
,
n
);
std
::
size_t
size
=
ins
->
get_shape
().
bytes
();
n
+=
size
+
(
size
%
4
);
}
auto
mem
=
p
.
add_parameter
(
"memory"
,
shape
{
shape
::
int8_type
,
{
n
}});
for
(
auto
&&
pp
:
allocs
)
{
auto
ins
=
pp
.
first
;
auto
s
=
ins
->
get_shape
();
auto
offset
=
pp
.
second
;
p
.
replace_instruction
(
ins
,
hip_load
{
s
,
offset
},
mem
);
}
}
}
// namespace gpu
}
// namespace migraph
src/targets/gpu/include/migraph/gpu/eliminate_allocation.hpp
0 → 100644
View file @
9164116a
#ifndef MIGRAPH_GUARD_RTGLIB_ELIMINATE_ALLOCATION_HPP
#define MIGRAPH_GUARD_RTGLIB_ELIMINATE_ALLOCATION_HPP
#include <string>
#include <migraph/instruction_ref.hpp>
namespace
migraph
{
struct
program
;
namespace
gpu
{
struct
eliminate_allocation
{
std
::
string
name
()
const
{
return
"eliminate_allocation"
;
}
void
apply
(
program
&
p
)
const
;
};
}
// namespace gpu
}
// namespace migraph
#endif
src/targets/gpu/include/migraph/gpu/hip.hpp
View file @
9164116a
...
...
@@ -28,6 +28,22 @@ struct hip_allocate
}
};
struct
hip_load
{
shape
s
;
std
::
size_t
offset
=
0
;
std
::
string
name
()
const
{
return
"hip::load"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
}.
has
(
1
);
return
s
;
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
return
{
s
,
args
[
0
].
data
()
+
offset
};
}
};
struct
hip_write
{
std
::
string
name
()
const
{
return
"hip::write"
;
}
...
...
src/targets/gpu/target.cpp
View file @
9164116a
...
...
@@ -3,6 +3,7 @@
#include <migraph/gpu/write_literals.hpp>
#include <migraph/gpu/context.hpp>
#include <migraph/gpu/eliminate_workspace.hpp>
#include <migraph/gpu/eliminate_allocation.hpp>
#include <migraph/check_context.hpp>
#include <migraph/auto_contiguous.hpp>
#include <migraph/dead_code_elimination.hpp>
...
...
@@ -27,6 +28,7 @@ std::vector<pass> target::get_passes(migraph::context& gctx) const
eliminate_contiguous
{},
dead_code_elimination
{},
write_literals
{},
eliminate_allocation
{},
check_context
<
context
>
{},
dead_code_elimination
{}
};
...
...
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