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
cfbafecb
Commit
cfbafecb
authored
Jun 20, 2018
by
Scott Thornton
Browse files
Merge branch 'lenet-test' of
https://github.com/ROCmSoftwarePlatform/RTGLib
into lenet-test
parents
92051ab8
7359bd4d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
5 deletions
+38
-5
src/onnx/CMakeLists.txt
src/onnx/CMakeLists.txt
+1
-1
src/onnx/read_onnx.cpp
src/onnx/read_onnx.cpp
+33
-4
src/targets/cpu/cpu_target.cpp
src/targets/cpu/cpu_target.cpp
+4
-0
No files found.
src/onnx/CMakeLists.txt
View file @
cfbafecb
...
...
@@ -8,4 +8,4 @@ target_link_libraries(onnx-proto PRIVATE ${PROTOBUF_LIBRARY})
add_executable
(
read_onnx read_onnx.cpp
)
rocm_clang_tidy_check
(
read_onnx
)
target_link_libraries
(
read_onnx onnx-proto rtg
)
target_link_libraries
(
read_onnx onnx-proto rtg
rtg_cpu
)
src/onnx/read_onnx.cpp
View file @
cfbafecb
...
...
@@ -12,6 +12,9 @@
#include <rtg/program.hpp>
#include <rtg/operators.hpp>
#include <rtg/cpu/cpu_target.hpp>
#include <random>
struct
unknown
{
std
::
string
op
;
...
...
@@ -227,6 +230,13 @@ struct onnx_parser
return
result
;
}
template
<
class
T
>
static
rtg
::
literal
from_repeated
(
rtg
::
shape
::
type_t
t
,
const
T
&
r
)
{
std
::
size_t
size
=
r
.
size
();
return
rtg
::
literal
{{
t
,
{
size
}},
r
.
begin
(),
r
.
end
()};
}
static
rtg
::
literal
parse_value
(
const
onnx
::
AttributeProto
&
attr
)
{
switch
(
attr
.
type
())
...
...
@@ -238,10 +248,8 @@ struct onnx_parser
case
onnx
::
AttributeProto
::
TENSOR
:
return
parse_tensor
(
attr
.
t
());
case
onnx
::
AttributeProto
::
GRAPH
:
return
{};
case
onnx
::
AttributeProto
::
FLOATS
:
return
rtg
::
literal
{
rtg
::
shape
::
float_type
,
attr
.
floats
().
begin
(),
attr
.
floats
().
end
()};
case
onnx
::
AttributeProto
::
INTS
:
return
rtg
::
literal
{
rtg
::
shape
::
int32_type
,
attr
.
ints
().
begin
(),
attr
.
ints
().
end
()};
;
return
from_repeated
(
rtg
::
shape
::
float_type
,
attr
.
floats
());
case
onnx
::
AttributeProto
::
INTS
:
return
from_repeated
(
rtg
::
shape
::
int64_type
,
attr
.
ints
());
case
onnx
::
AttributeProto
::
STRINGS
:
return
{};
case
onnx
::
AttributeProto
::
TENSORS
:
return
{};
case
onnx
::
AttributeProto
::
GRAPHS
:
return
{};
...
...
@@ -329,6 +337,22 @@ struct onnx_parser
}
};
// TODO: Move this to a seperate header
std
::
vector
<
float
>
get_tensor_data
(
rtg
::
shape
s
)
{
std
::
vector
<
float
>
result
(
s
.
elements
());
std
::
mt19937
engine
{
0
};
std
::
uniform_real_distribution
<>
dist
;
std
::
generate
(
result
.
begin
(),
result
.
end
(),
[
&
]
{
return
dist
(
engine
);
});
return
result
;
}
rtg
::
argument
get_tensor_argument
(
rtg
::
shape
s
)
{
auto
v
=
get_tensor_data
(
s
);
return
{
s
,
[
v
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
v
.
data
());
}};
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
if
(
argc
>
1
)
...
...
@@ -339,6 +363,11 @@ int main(int argc, char const* argv[])
try
{
parser
.
parse_from
(
input
);
parser
.
prog
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
s
=
parser
.
prog
.
get_parameter_shape
(
"Input3"
);
auto
input3
=
get_tensor_argument
(
s
);
auto
out
=
parser
.
prog
.
eval
({{
"Input3"
,
input3
}});
(
void
)
out
;
}
catch
(...)
{
...
...
src/targets/cpu/cpu_target.cpp
View file @
cfbafecb
...
...
@@ -586,6 +586,10 @@ struct cpu_apply
{
apply_activation
(
it
);
}
else
if
(
it
->
op
.
name
()
==
"pooling"
)
{
apply_pooling
(
it
);
}
else
if
(
apply_map
.
count
(
it
->
op
.
name
())
>
0
)
{
apply_map
.
at
(
it
->
op
.
name
())(
it
);
...
...
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