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
e93f4102
Commit
e93f4102
authored
Jun 24, 2018
by
Paul
Browse files
Remove hip_free operator
parent
a7a08134
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
45 deletions
+34
-45
src/targets/miopen/hip.cpp
src/targets/miopen/hip.cpp
+32
-2
src/targets/miopen/include/rtg/miopen/hip.hpp
src/targets/miopen/include/rtg/miopen/hip.hpp
+2
-42
src/targets/miopen/miopen_target.cpp
src/targets/miopen/miopen_target.cpp
+0
-1
No files found.
src/targets/miopen/hip.cpp
View file @
e93f4102
#include <rtg/miopen/hip.hpp>
#include <rtg/manage_ptr.hpp>
#include <miopen/miopen.h>
#include <vector>
namespace
rtg
{
namespace
miopen
{
hip_ptr
gpu_allocate
(
std
::
size_t
sz
)
using
hip_ptr
=
RTG_MANAGE_PTR
(
void
,
hipFree
);
hip_ptr
allocate_gpu
(
std
::
size_t
sz
)
{
void
*
result
;
// TODO: Check status
...
...
@@ -12,14 +19,37 @@ hip_ptr gpu_allocate(std::size_t sz)
return
hip_ptr
{
result
};
}
template
<
class
T
>
hip_ptr
write_to_gpu
(
const
T
&
x
)
{
using
type
=
typename
T
::
value_type
;
auto
size
=
x
.
size
()
*
sizeof
(
type
);
return
write_to_gpu
(
x
.
data
(),
size
);
}
template
<
class
T
>
std
::
vector
<
T
>
read_from_gpu
(
const
void
*
x
,
std
::
size_t
sz
)
{
std
::
vector
<
T
>
result
(
sz
);
// TODO: Check status
hipMemcpy
(
result
.
data
(),
x
,
sz
*
sizeof
(
T
),
hipMemcpyDeviceToHost
);
return
result
;
}
hip_ptr
write_to_gpu
(
const
void
*
x
,
std
::
size_t
sz
)
{
auto
result
=
gpu_
allocate
(
sz
);
auto
result
=
allocate
_gpu
(
sz
);
// TODO: Check status
hipMemcpy
(
result
.
get
(),
x
,
sz
,
hipMemcpyHostToDevice
);
return
result
;
}
rtg
::
argument
allocate_gpu
(
rtg
::
shape
s
)
{
auto
p
=
share
(
allocate_gpu
(
s
.
bytes
()));
return
{
s
,
[
p
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
p
.
get
());
}};
}
rtg
::
argument
to_gpu
(
rtg
::
argument
arg
)
{
auto
p
=
share
(
write_to_gpu
(
arg
.
data
(),
arg
.
get_shape
().
bytes
()));
...
...
src/targets/miopen/include/rtg/miopen/hip.hpp
View file @
e93f4102
...
...
@@ -11,33 +11,12 @@
namespace
rtg
{
namespace
miopen
{
using
hip_ptr
=
RTG_MANAGE_PTR
(
void
,
hipFree
);
hip_ptr
gpu_allocate
(
std
::
size_t
sz
);
hip_ptr
write_to_gpu
(
const
void
*
x
,
std
::
size_t
sz
);
rtg
::
argument
allocate_gpu
(
rtg
::
shape
s
);
rtg
::
argument
to_gpu
(
rtg
::
argument
arg
);
rtg
::
argument
from_gpu
(
rtg
::
argument
arg
);
template
<
class
T
>
hip_ptr
write_to_gpu
(
const
T
&
x
)
{
using
type
=
typename
T
::
value_type
;
auto
size
=
x
.
size
()
*
sizeof
(
type
);
return
write_to_gpu
(
x
.
data
(),
size
);
}
template
<
class
T
>
std
::
vector
<
T
>
read_from_gpu
(
const
void
*
x
,
std
::
size_t
sz
)
{
std
::
vector
<
T
>
result
(
sz
);
// TODO: Check status
hipMemcpy
(
result
.
data
(),
x
,
sz
*
sizeof
(
T
),
hipMemcpyDeviceToHost
);
return
result
;
}
struct
hip_allocate
{
std
::
string
name
()
const
{
return
"hip::allocate"
;
}
...
...
@@ -48,26 +27,7 @@ struct hip_allocate
}
argument
compute
(
shape
output_shape
,
std
::
vector
<
argument
>
)
const
{
char
*
data
=
nullptr
;
// TODO: Check return status
hipMalloc
(
&
data
,
output_shape
.
bytes
());
return
{
output_shape
,
data
};
}
};
struct
hip_free
{
std
::
string
name
()
const
{
return
"hip::free"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
}.
has
(
1
);
return
{};
}
argument
compute
(
shape
,
std
::
vector
<
argument
>
args
)
const
{
// TODO: Check return status
hipFree
(
args
.
front
().
data
());
return
{};
return
allocate_gpu
(
output_shape
);
}
};
...
...
src/targets/miopen/miopen_target.cpp
View file @
e93f4102
...
...
@@ -118,7 +118,6 @@ struct miopen_apply
{
auto
is
=
prog
->
add_outline
(
s
);
auto
result
=
prog
->
insert_instruction
(
ins
,
hip_allocate
{},
is
);
prog
->
insert_instruction
(
++
ins
,
hip_free
{},
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