Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
84f88fcc
Commit
84f88fcc
authored
Jun 21, 2018
by
Paul
Browse files
Refactor header files
parent
1fca08da
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
50 deletions
+69
-50
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/generate.cpp
src/generate.cpp
+17
-0
src/include/rtg/generate.hpp
src/include/rtg/generate.hpp
+23
-0
src/include/rtg/ranges.hpp
src/include/rtg/ranges.hpp
+20
-0
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+1
-12
src/onnx/read_onnx.cpp
src/onnx/read_onnx.cpp
+2
-18
test/miopen/miopen.cpp
test/miopen/miopen.cpp
+5
-20
No files found.
src/CMakeLists.txt
View file @
84f88fcc
add_library
(
rtg
add_library
(
rtg
generate.cpp
program.cpp
program.cpp
shape.cpp
shape.cpp
)
)
...
...
src/generate.cpp
0 → 100644
View file @
84f88fcc
#include <rtg/generate.hpp>
namespace
rtg
{
rtg
::
argument
generate_argument
(
rtg
::
shape
s
,
std
::
mt19937
::
result_type
seed
)
{
rtg
::
argument
result
;
s
.
visit_type
([
&
](
auto
as
)
{
using
type
=
typename
decltype
(
as
)
::
type
;
auto
v
=
generate_tensor_data
<
type
>
(
s
,
seed
);
result
=
{
s
,
[
v
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
v
.
data
());
}};
});
return
result
;
}
}
// namespace rtg
src/include/rtg/generate.hpp
0 → 100644
View file @
84f88fcc
#ifndef RTG_GUARD_RTGLIB_GENERATE_HPP
#define RTG_GUARD_RTGLIB_GENERATE_HPP
#include <rtg/argument.hpp>
#include <random>
namespace
rtg
{
template
<
class
T
>
std
::
vector
<
T
>
generate_tensor_data
(
rtg
::
shape
s
,
std
::
mt19937
::
result_type
seed
=
0
)
{
std
::
vector
<
T
>
result
(
s
.
elements
());
std
::
mt19937
engine
{
seed
};
std
::
uniform_real_distribution
<>
dist
;
std
::
generate
(
result
.
begin
(),
result
.
end
(),
[
&
]
{
return
dist
(
engine
);
});
return
result
;
}
rtg
::
argument
generate_argument
(
rtg
::
shape
s
,
std
::
mt19937
::
result_type
seed
=
0
);
}
// namespace rtg
#endif
src/include/rtg/ranges.hpp
0 → 100644
View file @
84f88fcc
#ifndef RTG_GUARD_RTGLIB_RANGES_HPP
#define RTG_GUARD_RTGLIB_RANGES_HPP
namespace
rtg
{
template
<
class
C
,
class
T
>
bool
contains
(
C
&&
c
,
T
&&
x
)
{
return
c
.
find
(
x
)
!=
c
.
end
();
}
template
<
class
Range
,
class
Iterator
>
void
copy
(
Range
&&
r
,
Iterator
it
)
{
std
::
copy
(
r
.
begin
(),
r
.
end
(),
it
);
}
}
// namespace rtg
#endif
src/onnx/onnx.cpp
View file @
84f88fcc
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <rtg/fallthrough.hpp>
#include <rtg/fallthrough.hpp>
#include <rtg/program.hpp>
#include <rtg/program.hpp>
#include <rtg/operators.hpp>
#include <rtg/operators.hpp>
#include <rtg/ranges.hpp>
namespace
rtg
{
namespace
rtg
{
...
@@ -32,18 +33,6 @@ struct unknown
...
@@ -32,18 +33,6 @@ struct unknown
}
}
};
};
template
<
class
C
,
class
T
>
bool
contains
(
C
&&
c
,
T
&&
x
)
{
return
c
.
find
(
x
)
!=
c
.
end
();
}
template
<
class
Range
,
class
Iterator
>
void
copy
(
Range
&&
r
,
Iterator
it
)
{
std
::
copy
(
r
.
begin
(),
r
.
end
(),
it
);
}
struct
onnx_parser
struct
onnx_parser
{
{
using
attribute_map
=
std
::
unordered_map
<
std
::
string
,
onnx
::
AttributeProto
>
;
using
attribute_map
=
std
::
unordered_map
<
std
::
string
,
onnx
::
AttributeProto
>
;
...
...
src/onnx/read_onnx.cpp
View file @
84f88fcc
...
@@ -2,23 +2,7 @@
...
@@ -2,23 +2,7 @@
#include <rtg/onnx.hpp>
#include <rtg/onnx.hpp>
#include <rtg/cpu/cpu_target.hpp>
#include <rtg/cpu/cpu_target.hpp>
#include <random>
#include <rtg/generate.hpp>
// 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
[])
int
main
(
int
argc
,
char
const
*
argv
[])
{
{
...
@@ -28,7 +12,7 @@ int main(int argc, char const* argv[])
...
@@ -28,7 +12,7 @@ int main(int argc, char const* argv[])
auto
prog
=
rtg
::
parse_onnx
(
file
);
auto
prog
=
rtg
::
parse_onnx
(
file
);
prog
.
compile
(
rtg
::
cpu
::
cpu_target
{});
prog
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
s
=
prog
.
get_parameter_shape
(
"Input3"
);
auto
s
=
prog
.
get_parameter_shape
(
"Input3"
);
auto
input3
=
ge
t_tensor
_argument
(
s
);
auto
input3
=
ge
nerate
_argument
(
s
);
auto
out
=
prog
.
eval
({{
"Input3"
,
input3
}});
auto
out
=
prog
.
eval
({{
"Input3"
,
input3
}});
(
void
)
out
;
(
void
)
out
;
std
::
cout
<<
prog
<<
std
::
endl
;
std
::
cout
<<
prog
<<
std
::
endl
;
...
...
test/miopen/miopen.cpp
View file @
84f88fcc
#include <rtg/program.hpp>
#include <rtg/program.hpp>
#include <rtg/operators.hpp>
#include <rtg/operators.hpp>
#include <rtg/generate.hpp>
#include <rtg/cpu/cpu_target.hpp>
#include <rtg/cpu/cpu_target.hpp>
#include <rtg/miopen/miopen_target.hpp>
#include <rtg/miopen/miopen_target.hpp>
#include <rtg/manage_ptr.hpp>
#include <rtg/manage_ptr.hpp>
#include <miopen/miopen.h>
#include <miopen/miopen.h>
#include <random>
#include "test.hpp"
#include "test.hpp"
#include "verify.hpp"
#include "verify.hpp"
...
@@ -64,24 +63,10 @@ rtg::program create_program()
...
@@ -64,24 +63,10 @@ rtg::program create_program()
return
p
;
return
p
;
}
}
std
::
vector
<
float
>
get_tensor_data
(
rtg
::
shape
s
)
// TODO: Move to header
{
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_cpu
(
rtg
::
shape
s
)
{
auto
v
=
get_tensor_data
(
s
);
return
{
s
,
[
v
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
v
.
data
());
}};
}
rtg
::
argument
get_tensor_argument_gpu
(
rtg
::
shape
s
)
rtg
::
argument
get_tensor_argument_gpu
(
rtg
::
shape
s
)
{
{
auto
v
=
get
_tensor_data
(
s
);
auto
v
=
rtg
::
generate
_tensor_data
<
float
>
(
s
);
auto
p
=
rtg
::
share
(
write
(
v
));
auto
p
=
rtg
::
share
(
write
(
v
));
return
{
s
,
[
p
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
p
.
get
());
}};
return
{
s
,
[
p
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
p
.
get
());
}};
}
}
...
@@ -90,8 +75,8 @@ std::vector<float> cpu()
...
@@ -90,8 +75,8 @@ std::vector<float> cpu()
{
{
std
::
vector
<
float
>
result
;
std
::
vector
<
float
>
result
;
auto
p
=
create_program
();
auto
p
=
create_program
();
auto
x
=
get_tensor
_argument
_cpu
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
x
=
rtg
::
generate
_argument
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
w
=
get_tensor
_argument
_cpu
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
w
=
rtg
::
generate
_argument
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
r
=
p
.
eval
({{
"x"
,
x
},
{
"w"
,
w
}});
auto
r
=
p
.
eval
({{
"x"
,
x
},
{
"w"
,
w
}});
auto
output
=
r
.
get
<
float
>
();
auto
output
=
r
.
get
<
float
>
();
...
...
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