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
73ca4689
"...composable_kernel.git" did not exist on "c366de553ede7ccb931ad32b03db5dd1b8655201"
Commit
73ca4689
authored
Oct 19, 2018
by
wsttiger
Browse files
Merge branch 'concat' of
https://github.com/ROCmSoftwarePlatform/RTGLib
into concat
parents
4443608d
c5697826
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
19 deletions
+48
-19
src/targets/gpu/hip.cpp
src/targets/gpu/hip.cpp
+8
-2
src/targets/gpu/include/migraph/gpu/hip.hpp
src/targets/gpu/include/migraph/gpu/hip.hpp
+11
-11
src/targets/gpu/write_literals.cpp
src/targets/gpu/write_literals.cpp
+18
-4
test/gpu/literal.cpp
test/gpu/literal.cpp
+11
-2
No files found.
src/targets/gpu/hip.cpp
View file @
73ca4689
...
@@ -90,9 +90,15 @@ argument from_gpu(argument arg)
...
@@ -90,9 +90,15 @@ argument from_gpu(argument arg)
void
gpu_sync
()
{
hipDeviceSynchronize
();
}
void
gpu_sync
()
{
hipDeviceSynchronize
();
}
void
copy_to_gpu
(
char
*
dst
,
const
char
*
src
,
std
::
size_t
size
)
void
copy_to_gpu
(
argument
src
,
argument
dst
)
{
{
hipMemcpy
(
dst
,
src
,
size
,
hipMemcpyHostToDevice
);
std
::
size_t
src_size
=
src
.
get_shape
().
bytes
();
std
::
size_t
dst_size
=
dst
.
get_shape
().
bytes
();
if
(
src_size
>
dst_size
)
MIGRAPH_THROW
(
"Not enough memory available in destination to do copy"
);
auto
status
=
hipMemcpy
(
dst
.
data
(),
src
.
data
(),
src_size
,
hipMemcpyHostToDevice
);
if
(
status
!=
hipSuccess
)
MIGRAPH_THROW
(
"Copy to gpu failed: "
+
hip_error
(
status
));
}
}
}
// namespace gpu
}
// namespace gpu
}
// namespace migraph
}
// namespace migraph
src/targets/gpu/include/migraph/gpu/hip.hpp
View file @
73ca4689
...
@@ -15,7 +15,7 @@ migraph::argument from_gpu(migraph::argument arg);
...
@@ -15,7 +15,7 @@ migraph::argument from_gpu(migraph::argument arg);
void
gpu_sync
();
void
gpu_sync
();
void
copy_to_gpu
(
char
*
dst
,
const
char
*
src
,
std
::
size_t
size
);
void
copy_to_gpu
(
argument
src
,
argument
dst
);
struct
hip_allocate
struct
hip_allocate
{
{
...
@@ -67,19 +67,19 @@ struct hip_write
...
@@ -67,19 +67,19 @@ struct hip_write
}
}
};
};
struct
hip_
mem
cpy
struct
hip_c
o
py
{
{
std
::
string
name
()
const
{
return
"hip_memcpy"
;
}
std
::
string
name
()
const
{
return
"hip_copy"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
return
inputs
.
at
(
1
);
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
argument
compute
(
context
&
,
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
{
char
*
dst
=
args
.
at
(
0
).
data
()
+
offset
;
check_shapes
{
inputs
}.
has
(
2
);
const
char
*
src
=
args
.
at
(
1
).
data
();
return
inputs
.
at
(
1
);
std
::
size_t
size
=
args
.
at
(
1
).
get_shape
().
bytes
();
}
copy_to_gpu
(
dst
,
src
,
size
);
argument
compute
(
context
&
,
const
shape
&
,
std
::
vector
<
argument
>
args
)
const
return
{
std
::
move
(
output_shape
),
dst
};
{
copy_to_gpu
(
args
[
0
],
args
[
1
]);
return
args
[
1
];
}
}
std
::
size_t
offset
=
0
;
};
};
}
// namespace gpu
}
// namespace gpu
}
// namespace migraph
}
// namespace migraph
...
...
src/targets/gpu/write_literals.cpp
View file @
73ca4689
...
@@ -2,11 +2,14 @@
...
@@ -2,11 +2,14 @@
#include <migraph/iterator_for.hpp>
#include <migraph/iterator_for.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/instruction.hpp>
#include <migraph/instruction.hpp>
#include <migraph/env.hpp>
namespace
migraph
{
namespace
migraph
{
namespace
gpu
{
namespace
gpu
{
MIGRAPH_DECLARE_ENV_VAR
(
MIGRAPH_COPY_LITERALS
)
struct
hip_load_literal
struct
hip_load_literal
{
{
shape
s
;
shape
s
;
...
@@ -30,10 +33,21 @@ void write_literals::apply(program& p) const
...
@@ -30,10 +33,21 @@ void write_literals::apply(program& p) const
{
{
if
(
ins
->
name
()
==
"@literal"
)
if
(
ins
->
name
()
==
"@literal"
)
{
{
argument
a
=
to_gpu
(
ins
->
get_literal
().
get_argument
());
if
(
enabled
(
MIGRAPH_COPY_LITERALS
{}))
std
::
size_t
n
=
ctx
->
literals
.
size
();
{
ctx
->
literals
.
push_back
(
a
);
literal
l
=
ins
->
get_literal
();
p
.
replace_instruction
(
ins
,
hip_load_literal
{
a
.
get_shape
(),
n
});
auto
pre
=
p
.
add_literal
(
l
);
auto
s
=
p
.
add_outline
(
l
.
get_shape
());
auto
alloc
=
p
.
insert_instruction
(
std
::
next
(
pre
),
hip_allocate
{},
s
);
p
.
replace_instruction
(
ins
,
hip_copy
{},
pre
,
alloc
);
}
else
{
argument
a
=
to_gpu
(
ins
->
get_literal
().
get_argument
());
std
::
size_t
n
=
ctx
->
literals
.
size
();
ctx
->
literals
.
push_back
(
a
);
p
.
replace_instruction
(
ins
,
hip_load_literal
{
a
.
get_shape
(),
n
});
}
}
}
}
}
}
}
...
...
test/gpu/literal.cpp
View file @
73ca4689
#include <test.hpp>
#include <test.hpp>
#include <basic_ops.hpp>
#include <basic_ops.hpp>
#include <migraph/program.hpp>
#include <migraph/program.hpp>
#include <migraph/instruction.hpp>
#include <migraph/generate.hpp>
#include <migraph/generate.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/gpu/hip.hpp>
...
@@ -11,8 +12,16 @@ void gpu_literal_test()
...
@@ -11,8 +12,16 @@ void gpu_literal_test()
auto
lit
=
generate_literal
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
lit
=
generate_literal
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
p
.
add_literal
(
lit
);
p
.
add_literal
(
lit
);
p
.
compile
(
migraph
::
gpu
::
target
{});
p
.
compile
(
migraph
::
gpu
::
target
{});
auto
result
=
p
.
eval
({});
auto
scratch
=
p
.
get_parameter
(
"scratch"
);
EXPECT
(
lit
==
migraph
::
gpu
::
from_gpu
(
result
));
if
(
scratch
==
p
.
end
())
{
auto
result
=
p
.
eval
({});
EXPECT
(
lit
==
migraph
::
gpu
::
from_gpu
(
result
));
}
else
{
EXPECT
(
scratch
->
get_shape
().
bytes
()
==
lit
.
get_shape
().
bytes
());
}
}
}
int
main
()
{
gpu_literal_test
();
}
int
main
()
{
gpu_literal_test
();
}
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