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
eea003a5
Commit
eea003a5
authored
Jul 02, 2018
by
Paul
Browse files
s/rtg/migraph
parent
5f1ea74f
Changes
62
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
167 additions
and
193 deletions
+167
-193
src/include/migraph/operation.hpp
src/include/migraph/operation.hpp
+8
-8
src/include/migraph/operators.hpp
src/include/migraph/operators.hpp
+32
-32
src/include/migraph/program.hpp
src/include/migraph/program.hpp
+9
-9
src/include/migraph/ranges.hpp
src/include/migraph/ranges.hpp
+4
-4
src/include/migraph/raw_data.hpp
src/include/migraph/raw_data.hpp
+12
-12
src/include/migraph/requires.hpp
src/include/migraph/requires.hpp
+6
-6
src/include/migraph/shape.hpp
src/include/migraph/shape.hpp
+16
-16
src/include/migraph/shape_for_each.hpp
src/include/migraph/shape_for_each.hpp
+6
-6
src/include/migraph/streamutils.hpp
src/include/migraph/streamutils.hpp
+4
-4
src/include/migraph/stringutils.hpp
src/include/migraph/stringutils.hpp
+4
-4
src/include/migraph/target.hpp
src/include/migraph/target.hpp
+5
-5
src/include/migraph/tensor_view.hpp
src/include/migraph/tensor_view.hpp
+11
-11
src/include/rtg/fallthrough.hpp
src/include/rtg/fallthrough.hpp
+0
-14
src/include/rtg/onnx.hpp
src/include/rtg/onnx.hpp
+0
-12
src/onnx/CMakeLists.txt
src/onnx/CMakeLists.txt
+7
-7
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+10
-10
src/onnx/read_onnx.cpp
src/onnx/read_onnx.cpp
+2
-2
src/onnx/verify_onnx.cpp
src/onnx/verify_onnx.cpp
+17
-17
src/program.cpp
src/program.cpp
+6
-6
src/shape.cpp
src/shape.cpp
+8
-8
No files found.
src/include/
rtg
/operation.hpp
→
src/include/
migraph
/operation.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_OPERAND_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_OPERAND_HPP
#define
RTG_GUARD_RTG
LIB_OPERAND_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_OPERAND_HPP
#include <string>
#include <string>
#include <functional>
#include <functional>
#include <memory>
#include <memory>
#include <type_traits>
#include <type_traits>
#include <utility>
#include <utility>
#include <
rtg
/shape.hpp>
#include <
migraph
/shape.hpp>
#include <
rtg
/argument.hpp>
#include <
migraph
/argument.hpp>
#include <
rtg
/context.hpp>
#include <
migraph
/context.hpp>
namespace
rtg
{
namespace
migraph
{
namespace
operation_stream
{
namespace
operation_stream
{
...
@@ -174,7 +174,7 @@ struct operation
...
@@ -174,7 +174,7 @@ struct operation
std
::
ostream
&
operator_shift_left
(
std
::
ostream
&
os
)
const
override
std
::
ostream
&
operator_shift_left
(
std
::
ostream
&
os
)
const
override
{
{
using
rtg
::
operation_stream
::
operator
<<
;
using
migraph
::
operation_stream
::
operator
<<
;
return
os
<<
private_detail_te_value
;
return
os
<<
private_detail_te_value
;
}
}
...
@@ -243,6 +243,6 @@ inline const ValueType& any_cast(const operation& x)
...
@@ -243,6 +243,6 @@ inline const ValueType& any_cast(const operation& x)
return
*
y
;
return
*
y
;
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/operators.hpp
→
src/include/
migraph
/operators.hpp
View file @
eea003a5
#ifndef
RTG
_GUARD_OPERATORS_HPP
#ifndef
MIGRAPH
_GUARD_OPERATORS_HPP
#define
RTG
_GUARD_OPERATORS_HPP
#define
MIGRAPH
_GUARD_OPERATORS_HPP
#include <array>
#include <array>
#include <
rtg
/operation.hpp>
#include <
migraph
/operation.hpp>
#include <
rtg
/stringutils.hpp>
#include <
migraph
/stringutils.hpp>
#include <
rtg
/streamutils.hpp>
#include <
migraph
/streamutils.hpp>
#include <cmath>
#include <cmath>
namespace
rtg
{
namespace
migraph
{
struct
check_shapes
struct
check_shapes
{
{
...
@@ -33,7 +33,7 @@ struct check_shapes
...
@@ -33,7 +33,7 @@ struct check_shapes
{
{
assert
(
shapes
!=
nullptr
);
assert
(
shapes
!=
nullptr
);
if
(
shapes
->
size
()
!=
n
)
if
(
shapes
->
size
()
!=
n
)
RTG
_THROW
(
prefix
()
+
"Wrong number of arguments: expected "
+
std
::
to_string
(
n
)
+
MIGRAPH
_THROW
(
prefix
()
+
"Wrong number of arguments: expected "
+
std
::
to_string
(
n
)
+
" but given "
+
std
::
to_string
(
shapes
->
size
()));
" but given "
+
std
::
to_string
(
shapes
->
size
()));
return
*
this
;
return
*
this
;
}
}
...
@@ -44,7 +44,7 @@ struct check_shapes
...
@@ -44,7 +44,7 @@ struct check_shapes
if
(
!
shapes
->
empty
())
if
(
!
shapes
->
empty
())
{
{
if
(
shapes
->
front
().
lens
().
size
()
!=
n
)
if
(
shapes
->
front
().
lens
().
size
()
!=
n
)
RTG
_THROW
(
prefix
()
+
"Only "
+
std
::
to_string
(
n
)
+
"d supported"
);
MIGRAPH
_THROW
(
prefix
()
+
"Only "
+
std
::
to_string
(
n
)
+
"d supported"
);
}
}
return
*
this
;
return
*
this
;
}
}
...
@@ -52,28 +52,28 @@ struct check_shapes
...
@@ -52,28 +52,28 @@ struct check_shapes
const
check_shapes
&
same_shape
()
const
const
check_shapes
&
same_shape
()
const
{
{
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
;
}))
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
;
}))
RTG
_THROW
(
prefix
()
+
"Shapes do not match"
);
MIGRAPH
_THROW
(
prefix
()
+
"Shapes do not match"
);
return
*
this
;
return
*
this
;
}
}
const
check_shapes
&
same_type
()
const
const
check_shapes
&
same_type
()
const
{
{
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
.
type
();
}))
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
.
type
();
}))
RTG
_THROW
(
prefix
()
+
"Types do not match"
);
MIGRAPH
_THROW
(
prefix
()
+
"Types do not match"
);
return
*
this
;
return
*
this
;
}
}
const
check_shapes
&
same_dims
()
const
const
check_shapes
&
same_dims
()
const
{
{
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
.
lens
();
}))
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
.
lens
();
}))
RTG
_THROW
(
prefix
()
+
"Dimensions do not match"
);
MIGRAPH
_THROW
(
prefix
()
+
"Dimensions do not match"
);
return
*
this
;
return
*
this
;
}
}
const
check_shapes
&
same_ndims
()
const
const
check_shapes
&
same_ndims
()
const
{
{
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
.
lens
().
size
();
}))
if
(
!
this
->
same
([](
const
shape
&
s
)
{
return
s
.
lens
().
size
();
}))
RTG
_THROW
(
prefix
()
+
"Dimensions do not match"
);
MIGRAPH
_THROW
(
prefix
()
+
"Dimensions do not match"
);
return
*
this
;
return
*
this
;
}
}
...
@@ -97,7 +97,7 @@ struct check_shapes
...
@@ -97,7 +97,7 @@ struct check_shapes
struct
not_computable
struct
not_computable
{
{
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
};
};
struct
convolution
struct
convolution
...
@@ -163,11 +163,11 @@ struct convolution
...
@@ -163,11 +163,11 @@ struct convolution
}
}
else
else
{
{
RTG
_THROW
(
"Invalid padding mode"
);
MIGRAPH
_THROW
(
"Invalid padding mode"
);
}
}
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
convolution
&
op
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
convolution
&
op
)
{
{
...
@@ -214,7 +214,7 @@ struct pooling
...
@@ -214,7 +214,7 @@ struct pooling
}};
}};
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
pooling
&
op
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
pooling
&
op
)
{
{
...
@@ -237,7 +237,7 @@ struct activation
...
@@ -237,7 +237,7 @@ struct activation
return
inputs
.
front
();
return
inputs
.
front
();
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
activation
&
op
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
activation
&
op
)
{
{
os
<<
op
.
name
()
<<
":"
<<
op
.
mode
;
os
<<
op
.
name
()
<<
":"
<<
op
.
mode
;
...
@@ -258,13 +258,13 @@ struct transpose
...
@@ -258,13 +258,13 @@ struct transpose
auto
t
=
input
.
type
();
auto
t
=
input
.
type
();
if
(
dims
.
size
()
!=
input_lens
.
size
())
if
(
dims
.
size
()
!=
input_lens
.
size
())
{
{
RTG
_THROW
(
"Permutation has wrong number of axes"
);
MIGRAPH
_THROW
(
"Permutation has wrong number of axes"
);
}
}
std
::
vector
<
int64_t
>
axes
(
dims
.
size
());
std
::
vector
<
int64_t
>
axes
(
dims
.
size
());
std
::
iota
(
axes
.
begin
(),
axes
.
end
(),
0
);
std
::
iota
(
axes
.
begin
(),
axes
.
end
(),
0
);
if
(
!
std
::
is_permutation
(
axes
.
begin
(),
axes
.
end
(),
dims
.
begin
()))
if
(
!
std
::
is_permutation
(
axes
.
begin
(),
axes
.
end
(),
dims
.
begin
()))
{
{
RTG
_THROW
(
"Invalid permutation"
);
MIGRAPH
_THROW
(
"Invalid permutation"
);
}
}
std
::
vector
<
size_t
>
output_lens
(
input_lens
.
size
());
std
::
vector
<
size_t
>
output_lens
(
input_lens
.
size
());
std
::
vector
<
size_t
>
output_strides
(
input_lens
.
size
());
std
::
vector
<
size_t
>
output_strides
(
input_lens
.
size
());
...
@@ -275,7 +275,7 @@ struct transpose
...
@@ -275,7 +275,7 @@ struct transpose
}
}
return
{
t
,
output_lens
,
output_strides
};
return
{
t
,
output_lens
,
output_strides
};
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
};
};
struct
contiguous
struct
contiguous
...
@@ -288,11 +288,11 @@ struct contiguous
...
@@ -288,11 +288,11 @@ struct contiguous
auto
t
=
inputs
.
at
(
0
).
type
();
auto
t
=
inputs
.
at
(
0
).
type
();
if
(
lens
.
size
()
<
2
)
if
(
lens
.
size
()
<
2
)
{
{
RTG
_THROW
(
"Number of dimensions should exceed 1"
);
MIGRAPH
_THROW
(
"Number of dimensions should exceed 1"
);
}
}
return
{
t
,
lens
};
return
{
t
,
lens
};
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
};
};
struct
reshape
struct
reshape
...
@@ -316,11 +316,11 @@ struct reshape
...
@@ -316,11 +316,11 @@ struct reshape
}
}
shape
s
{
inputs
.
front
().
type
(),
rdims
};
shape
s
{
inputs
.
front
().
type
(),
rdims
};
if
(
s
.
elements
()
!=
inputs
.
front
().
elements
())
if
(
s
.
elements
()
!=
inputs
.
front
().
elements
())
RTG
_THROW
(
"Wrong number of elements for reshape"
);
MIGRAPH
_THROW
(
"Wrong number of elements for reshape"
);
return
s
;
return
s
;
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
reshape
&
op
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
reshape
&
op
)
{
{
...
@@ -342,11 +342,11 @@ struct gemm
...
@@ -342,11 +342,11 @@ struct gemm
auto
t
=
a
.
type
();
auto
t
=
a
.
type
();
if
(
a
.
lens
()[
1
]
!=
b
.
lens
()[
0
])
if
(
a
.
lens
()[
1
]
!=
b
.
lens
()[
0
])
RTG
_THROW
(
"Inner dimensions do not match"
);
MIGRAPH
_THROW
(
"Inner dimensions do not match"
);
return
{
t
,
{
a
.
lens
()[
0
],
b
.
lens
()[
1
]}};
return
{
t
,
{
a
.
lens
()[
0
],
b
.
lens
()[
1
]}};
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
gemm
&
op
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
gemm
&
op
)
{
{
...
@@ -363,7 +363,7 @@ struct unary
...
@@ -363,7 +363,7 @@ struct unary
check_shapes
{
inputs
}.
has
(
1
);
check_shapes
{
inputs
}.
has
(
1
);
return
inputs
.
at
(
0
);
return
inputs
.
at
(
0
);
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
};
};
struct
identity
:
unary
struct
identity
:
unary
...
@@ -451,14 +451,14 @@ struct broadcast
...
@@ -451,14 +451,14 @@ struct broadcast
result
.
lens
().
cbegin
(),
result
.
lens
().
cend
(),
[
&
](
auto
x
)
{
return
x
==
1
;
}))
result
.
lens
().
cbegin
(),
result
.
lens
().
cend
(),
[
&
](
auto
x
)
{
return
x
==
1
;
}))
{
{
if
(
axis
!=
0
)
if
(
axis
!=
0
)
RTG
_THROW
(
"when broadcasting tensor of size 1, axis should be 0"
);
MIGRAPH
_THROW
(
"when broadcasting tensor of size 1, axis should be 0"
);
return
{
t
,
result
.
lens
(),
std
::
move
(
bcast_strides
)};
return
{
t
,
result
.
lens
(),
std
::
move
(
bcast_strides
)};
}
}
else
else
{
{
assert
(
result
.
lens
().
size
()
-
axis
>=
input
.
lens
().
size
());
assert
(
result
.
lens
().
size
()
-
axis
>=
input
.
lens
().
size
());
if
(
!
std
::
equal
(
input
.
lens
().
begin
(),
input
.
lens
().
end
(),
result
.
lens
().
begin
()
+
axis
))
if
(
!
std
::
equal
(
input
.
lens
().
begin
(),
input
.
lens
().
end
(),
result
.
lens
().
begin
()
+
axis
))
RTG
_THROW
(
"when broadcasting success sizes must match"
);
MIGRAPH
_THROW
(
"when broadcasting success sizes must match"
);
std
::
copy
(
input
.
strides
().
begin
(),
input
.
strides
().
end
(),
bcast_strides
.
begin
()
+
axis
);
std
::
copy
(
input
.
strides
().
begin
(),
input
.
strides
().
end
(),
bcast_strides
.
begin
()
+
axis
);
return
{
t
,
result
.
lens
(),
std
::
move
(
bcast_strides
)};
return
{
t
,
result
.
lens
(),
std
::
move
(
bcast_strides
)};
}
}
...
@@ -477,7 +477,7 @@ struct binary
...
@@ -477,7 +477,7 @@ struct binary
check_shapes
{
inputs
}.
has
(
2
).
same_type
().
same_dims
();
check_shapes
{
inputs
}.
has
(
2
).
same_type
().
same_dims
();
return
inputs
.
at
(
0
);
return
inputs
.
at
(
0
);
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
};
};
struct
add
:
binary
struct
add
:
binary
...
@@ -521,11 +521,11 @@ struct check_context
...
@@ -521,11 +521,11 @@ struct check_context
{
{
T
*
x
=
any_cast
<
T
>
(
&
ctx
);
T
*
x
=
any_cast
<
T
>
(
&
ctx
);
if
(
x
==
nullptr
)
if
(
x
==
nullptr
)
RTG
_THROW
(
std
::
string
(
"Unexpected context type: "
)
+
ctx
.
type_id
().
name
());
MIGRAPH
_THROW
(
std
::
string
(
"Unexpected context type: "
)
+
ctx
.
type_id
().
name
());
return
{};
return
{};
}
}
};
};
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/program.hpp
→
src/include/
migraph
/program.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_PROGRAM_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_PROGRAM_HPP
#define
RTG_GUARD_RTG
LIB_PROGRAM_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_PROGRAM_HPP
#include <list>
#include <list>
#include <unordered_map>
#include <unordered_map>
#include <
rtg
/operation.hpp>
#include <
migraph
/operation.hpp>
#include <
rtg
/literal.hpp>
#include <
migraph
/literal.hpp>
#include <
rtg
/builtin.hpp>
#include <
migraph
/builtin.hpp>
#include <
rtg
/instruction_ref.hpp>
#include <
migraph
/instruction_ref.hpp>
#include <
rtg
/target.hpp>
#include <
migraph
/target.hpp>
#include <algorithm>
#include <algorithm>
#include <iostream>
#include <iostream>
namespace
rtg
{
namespace
migraph
{
struct
program_impl
;
struct
program_impl
;
...
@@ -83,6 +83,6 @@ struct program
...
@@ -83,6 +83,6 @@ struct program
std
::
unique_ptr
<
program_impl
>
impl
;
std
::
unique_ptr
<
program_impl
>
impl
;
};
};
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/ranges.hpp
→
src/include/
migraph
/ranges.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_RANGES_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_RANGES_HPP
#define
RTG_GUARD_RTG
LIB_RANGES_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_RANGES_HPP
namespace
rtg
{
namespace
migraph
{
template
<
class
C
,
class
T
>
template
<
class
C
,
class
T
>
bool
contains
(
C
&&
c
,
T
&&
x
)
bool
contains
(
C
&&
c
,
T
&&
x
)
...
@@ -15,6 +15,6 @@ void copy(Range&& r, Iterator it)
...
@@ -15,6 +15,6 @@ void copy(Range&& r, Iterator it)
std
::
copy
(
r
.
begin
(),
r
.
end
(),
it
);
std
::
copy
(
r
.
begin
(),
r
.
end
(),
it
);
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/raw_data.hpp
→
src/include/
migraph
/raw_data.hpp
View file @
eea003a5
#ifndef
RTG
_GUARD_RAW_DATA_HPP
#ifndef
MIGRAPH
_GUARD_RAW_DATA_HPP
#define
RTG
_GUARD_RAW_DATA_HPP
#define
MIGRAPH
_GUARD_RAW_DATA_HPP
#include <
rtg
/tensor_view.hpp>
#include <
migraph
/tensor_view.hpp>
#include <
rtg
/requires.hpp>
#include <
migraph
/requires.hpp>
namespace
rtg
{
namespace
migraph
{
struct
raw_data_base
struct
raw_data_base
{
{
...
@@ -102,7 +102,7 @@ struct raw_data : raw_data_base
...
@@ -102,7 +102,7 @@ struct raw_data : raw_data_base
bool
matches
()
const
bool
matches
()
const
{
{
return
is_data_ptr
<
T
>
{}
||
return
is_data_ptr
<
T
>
{}
||
self
->
get_shape
().
type
()
==
rtg
::
shape
::
get_type
<
get_data_type
<
T
>>
{};
self
->
get_shape
().
type
()
==
migraph
::
shape
::
get_type
<
get_data_type
<
T
>>
{};
}
}
template
<
class
T
>
template
<
class
T
>
...
@@ -123,15 +123,15 @@ struct raw_data : raw_data_base
...
@@ -123,15 +123,15 @@ struct raw_data : raw_data_base
{
{
auto
&&
s
=
static_cast
<
const
Derived
&>
(
*
this
).
get_shape
();
auto
&&
s
=
static_cast
<
const
Derived
&>
(
*
this
).
get_shape
();
auto
&&
buffer
=
static_cast
<
const
Derived
&>
(
*
this
).
data
();
auto
&&
buffer
=
static_cast
<
const
Derived
&>
(
*
this
).
data
();
if
(
s
.
type
()
!=
rtg
::
shape
::
get_type
<
T
>
{})
if
(
s
.
type
()
!=
migraph
::
shape
::
get_type
<
T
>
{})
RTG
_THROW
(
"Incorrect data type for raw data"
);
MIGRAPH
_THROW
(
"Incorrect data type for raw data"
);
return
make_view
(
s
,
reinterpret_cast
<
T
*>
(
buffer
));
return
make_view
(
s
,
reinterpret_cast
<
T
*>
(
buffer
));
}
}
};
};
template
<
class
T
,
template
<
class
T
,
class
U
,
class
U
,
RTG
_REQUIRES
(
std
::
is_base_of
<
raw_data_base
,
T
>{}
&&
std
::
is_base_of
<
raw_data_base
,
U
>
{})
>
MIGRAPH
_REQUIRES
(
std
::
is_base_of
<
raw_data_base
,
T
>{}
&&
std
::
is_base_of
<
raw_data_base
,
U
>
{})
>
bool
operator
==
(
const
T
&
x
,
const
U
&
y
)
bool
operator
==
(
const
T
&
x
,
const
U
&
y
)
{
{
auto
&&
xshape
=
x
.
get_shape
();
auto
&&
xshape
=
x
.
get_shape
();
...
@@ -153,7 +153,7 @@ bool operator==(const T& x, const U& y)
...
@@ -153,7 +153,7 @@ bool operator==(const T& x, const U& y)
template
<
class
T
,
template
<
class
T
,
class
U
,
class
U
,
RTG
_REQUIRES
(
std
::
is_base_of
<
raw_data_base
,
T
>{}
&&
std
::
is_base_of
<
raw_data_base
,
U
>
{})
>
MIGRAPH
_REQUIRES
(
std
::
is_base_of
<
raw_data_base
,
T
>{}
&&
std
::
is_base_of
<
raw_data_base
,
U
>
{})
>
bool
operator
!=
(
const
T
&
x
,
const
U
&
y
)
bool
operator
!=
(
const
T
&
x
,
const
U
&
y
)
{
{
return
!
(
x
==
y
);
return
!
(
x
==
y
);
...
@@ -184,13 +184,13 @@ auto visit_all(T&& x, Ts&&... xs)
...
@@ -184,13 +184,13 @@ auto visit_all(T&& x, Ts&&... xs)
auto
&&
s
=
x
.
get_shape
();
auto
&&
s
=
x
.
get_shape
();
std
::
initializer_list
<
shape
::
type_t
>
types
=
{
xs
.
get_shape
().
type
()...};
std
::
initializer_list
<
shape
::
type_t
>
types
=
{
xs
.
get_shape
().
type
()...};
if
(
!
std
::
all_of
(
types
.
begin
(),
types
.
end
(),
[
&
](
shape
::
type_t
t
)
{
return
t
==
s
.
type
();
}))
if
(
!
std
::
all_of
(
types
.
begin
(),
types
.
end
(),
[
&
](
shape
::
type_t
t
)
{
return
t
==
s
.
type
();
}))
RTG
_THROW
(
"Types must be the same"
);
MIGRAPH
_THROW
(
"Types must be the same"
);
return
[
&
](
auto
v
)
{
return
[
&
](
auto
v
)
{
// Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70100
// Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70100
detail
::
visit_all_impl
(
s
,
v
,
x
,
xs
...);
detail
::
visit_all_impl
(
s
,
v
,
x
,
xs
...);
};
};
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/requires.hpp
→
src/include/
migraph
/requires.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_REQUIRES_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_REQUIRES_HPP
#define
RTG_GUARD_RTG
LIB_REQUIRES_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_REQUIRES_HPP
#include <type_traits>
#include <type_traits>
namespace
rtg
{
namespace
migraph
{
template
<
bool
...
Bs
>
template
<
bool
...
Bs
>
struct
and_
:
std
::
is_same
<
and_
<
Bs
...
>
,
and_
<
(
Bs
||
true
)...
>>
// NOLINT
struct
and_
:
std
::
is_same
<
and_
<
Bs
...
>
,
and_
<
(
Bs
||
true
)...
>>
// NOLINT
...
@@ -14,13 +14,13 @@ template <bool B>
...
@@ -14,13 +14,13 @@ template <bool B>
using
bool_c
=
std
::
integral_constant
<
bool
,
B
>
;
using
bool_c
=
std
::
integral_constant
<
bool
,
B
>
;
#ifdef CPPCHECK
#ifdef CPPCHECK
#define
RTG
_REQUIRES(...) class = void
#define
MIGRAPH
_REQUIRES(...) class = void
#else
#else
#define
RTG
_REQUIRES(...) \
#define
MIGRAPH
_REQUIRES(...) \
bool PrivateRequires##__LINE__ = true, \
bool PrivateRequires##__LINE__ = true, \
class = typename std::enable_if<and_<__VA_ARGS__, PrivateRequires##__LINE__>{}>::type
class = typename std::enable_if<and_<__VA_ARGS__, PrivateRequires##__LINE__>{}>::type
#endif
#endif
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/shape.hpp
→
src/include/
migraph
/shape.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_SHAPE_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_SHAPE_HPP
#define
RTG_GUARD_RTG
LIB_SHAPE_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_SHAPE_HPP
#include <vector>
#include <vector>
#include <cassert>
#include <cassert>
#include <ostream>
#include <ostream>
#include <numeric>
#include <numeric>
#include <
rtg
/errors.hpp>
#include <
migraph
/errors.hpp>
namespace
rtg
{
namespace
migraph
{
struct
shape
struct
shape
{
{
// Add new types here
// Add new types here
// clang-format off
// clang-format off
#define
RTG
_SHAPE_VISIT_TYPES(m) \
#define
MIGRAPH
_SHAPE_VISIT_TYPES(m) \
m(float_type, float) \
m(float_type, float) \
m(double_type, double) \
m(double_type, double) \
m(uint8_type, uint8_t) \
m(uint8_type, uint8_t) \
...
@@ -28,22 +28,22 @@ struct shape
...
@@ -28,22 +28,22 @@ struct shape
m(uint64_type, uint64_t)
m(uint64_type, uint64_t)
// clang-format on
// clang-format on
#define
RTG
_SHAPE_ENUM_TYPES(x, t) x,
#define
MIGRAPH
_SHAPE_ENUM_TYPES(x, t) x,
enum
type_t
enum
type_t
{
{
RTG
_SHAPE_VISIT_TYPES
(
RTG
_SHAPE_ENUM_TYPES
)
MIGRAPH
_SHAPE_VISIT_TYPES
(
MIGRAPH
_SHAPE_ENUM_TYPES
)
};
};
#undef
RTG
_SHAPE_ENUM_TYPES
#undef
MIGRAPH
_SHAPE_ENUM_TYPES
template
<
class
T
,
class
=
void
>
template
<
class
T
,
class
=
void
>
struct
get_type
;
struct
get_type
;
#define
RTG
_SHAPE_GET_TYPE(x, t) \
#define
MIGRAPH
_SHAPE_GET_TYPE(x, t) \
template <class T> \
template <class T> \
struct get_type<t, T> : std::integral_constant<type_t, x> \
struct get_type<t, T> : std::integral_constant<type_t, x> \
{ \
{ \
};
};
RTG
_SHAPE_VISIT_TYPES
(
RTG
_SHAPE_GET_TYPE
)
MIGRAPH
_SHAPE_VISIT_TYPES
(
MIGRAPH
_SHAPE_GET_TYPE
)
#undef
RTG
_SHAPE_GET_TYPE
#undef
MIGRAPH
_SHAPE_GET_TYPE
shape
();
shape
();
shape
(
type_t
t
);
shape
(
type_t
t
);
...
@@ -122,12 +122,12 @@ struct shape
...
@@ -122,12 +122,12 @@ struct shape
{
{
switch
(
this
->
m_type
)
switch
(
this
->
m_type
)
{
{
#define
RTG
_SHAPE_VISITOR_CASE(x, t) \
#define
MIGRAPH
_SHAPE_VISITOR_CASE(x, t) \
case x: v(as<t>()); return;
case x: v(as<t>()); return;
RTG
_SHAPE_VISIT_TYPES
(
RTG
_SHAPE_VISITOR_CASE
)
MIGRAPH
_SHAPE_VISIT_TYPES
(
MIGRAPH
_SHAPE_VISITOR_CASE
)
#undef
RTG
_SHAPE_VISITOR_CASE
#undef
MIGRAPH
_SHAPE_VISITOR_CASE
}
}
RTG
_THROW
(
"Unknown type"
);
MIGRAPH
_THROW
(
"Unknown type"
);
}
}
private:
private:
...
@@ -141,6 +141,6 @@ struct shape
...
@@ -141,6 +141,6 @@ struct shape
std
::
string
type_string
()
const
;
std
::
string
type_string
()
const
;
};
};
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/shape_for_each.hpp
→
src/include/
migraph
/shape_for_each.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_SHAPE_FOR_EACH_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_SHAPE_FOR_EACH_HPP
#define
RTG_GUARD_RTG
LIB_SHAPE_FOR_EACH_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_SHAPE_FOR_EACH_HPP
#include <
rtg
/shape.hpp>
#include <
migraph
/shape.hpp>
#include <algorithm>
#include <algorithm>
namespace
rtg
{
namespace
migraph
{
template
<
class
F
>
template
<
class
F
>
void
shape_for_each
(
const
rtg
::
shape
&
s
,
F
f
)
void
shape_for_each
(
const
migraph
::
shape
&
s
,
F
f
)
{
{
// Ensure calls to f use const ref to vector
// Ensure calls to f use const ref to vector
auto
call
=
[
&
f
](
const
std
::
vector
<
std
::
size_t
>&
i
)
{
f
(
i
);
};
auto
call
=
[
&
f
](
const
std
::
vector
<
std
::
size_t
>&
i
)
{
f
(
i
);
};
...
@@ -26,6 +26,6 @@ void shape_for_each(const rtg::shape& s, F f)
...
@@ -26,6 +26,6 @@ void shape_for_each(const rtg::shape& s, F f)
}
}
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/streamutils.hpp
→
src/include/
migraph
/streamutils.hpp
View file @
eea003a5
#ifndef
RTG
_GUARD_STREAMUTILS_HPP
#ifndef
MIGRAPH
_GUARD_STREAMUTILS_HPP
#define
RTG
_GUARD_STREAMUTILS_HPP
#define
MIGRAPH
_GUARD_STREAMUTILS_HPP
#include <ostream>
#include <ostream>
#include <algorithm>
#include <algorithm>
namespace
rtg
{
namespace
migraph
{
template
<
class
T
>
template
<
class
T
>
struct
stream_range_container
struct
stream_range_container
...
@@ -31,6 +31,6 @@ inline stream_range_container<Range> stream_range(const Range& r)
...
@@ -31,6 +31,6 @@ inline stream_range_container<Range> stream_range(const Range& r)
return
{
r
};
return
{
r
};
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/stringutils.hpp
→
src/include/
migraph
/stringutils.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_STRINGUTILS_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_STRINGUTILS_HPP
#define
RTG_GUARD_RTG
LIB_STRINGUTILS_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_STRINGUTILS_HPP
#include <algorithm>
#include <algorithm>
#include <numeric>
#include <numeric>
#include <string>
#include <string>
#include <sstream>
#include <sstream>
namespace
rtg
{
namespace
migraph
{
inline
std
::
string
inline
std
::
string
replace_string
(
std
::
string
subject
,
const
std
::
string
&
search
,
const
std
::
string
&
replace
)
replace_string
(
std
::
string
subject
,
const
std
::
string
&
search
,
const
std
::
string
&
replace
)
...
@@ -77,6 +77,6 @@ inline std::string to_string(const Range& r)
...
@@ -77,6 +77,6 @@ inline std::string to_string(const Range& r)
return
ss
.
str
();
return
ss
.
str
();
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/target.hpp
→
src/include/
migraph
/target.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_TARGET_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_TARGET_HPP
#define
RTG_GUARD_RTG
LIB_TARGET_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_TARGET_HPP
#include <string>
#include <string>
#include <functional>
#include <functional>
#include <memory>
#include <memory>
#include <type_traits>
#include <type_traits>
#include <utility>
#include <utility>
#include <
rtg
/context.hpp>
#include <
migraph
/context.hpp>
namespace
rtg
{
namespace
migraph
{
struct
program
;
struct
program
;
...
@@ -210,6 +210,6 @@ inline const ValueType& any_cast(const target& x)
...
@@ -210,6 +210,6 @@ inline const ValueType& any_cast(const target& x)
return
*
y
;
return
*
y
;
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/
rtg
/tensor_view.hpp
→
src/include/
migraph
/tensor_view.hpp
View file @
eea003a5
#ifndef
RTG
_GUARD_TENSOR_VIEW_HPP
#ifndef
MIGRAPH
_GUARD_TENSOR_VIEW_HPP
#define
RTG
_GUARD_TENSOR_VIEW_HPP
#define
MIGRAPH
_GUARD_TENSOR_VIEW_HPP
#include <
rtg
/shape.hpp>
#include <
migraph
/shape.hpp>
#include <
rtg
/float_equal.hpp>
#include <
migraph
/float_equal.hpp>
#include <
rtg
/requires.hpp>
#include <
migraph
/requires.hpp>
#include <iostream>
#include <iostream>
namespace
rtg
{
namespace
migraph
{
template
<
class
T
>
template
<
class
T
>
struct
tensor_view
struct
tensor_view
...
@@ -26,25 +26,25 @@ struct tensor_view
...
@@ -26,25 +26,25 @@ struct tensor_view
const
T
*
data
()
const
{
return
this
->
m_data
;
}
const
T
*
data
()
const
{
return
this
->
m_data
;
}
template
<
class
...
Ts
,
RTG
_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
template
<
class
...
Ts
,
MIGRAPH
_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
const
T
&
operator
()(
Ts
...
xs
)
const
const
T
&
operator
()(
Ts
...
xs
)
const
{
{
return
m_data
[
m_shape
.
index
({
static_cast
<
std
::
size_t
>
(
xs
)...})];
return
m_data
[
m_shape
.
index
({
static_cast
<
std
::
size_t
>
(
xs
)...})];
}
}
template
<
class
...
Ts
,
RTG
_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
template
<
class
...
Ts
,
MIGRAPH
_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
T
&
operator
()(
Ts
...
xs
)
T
&
operator
()(
Ts
...
xs
)
{
{
return
m_data
[
m_shape
.
index
({
static_cast
<
std
::
size_t
>
(
xs
)...})];
return
m_data
[
m_shape
.
index
({
static_cast
<
std
::
size_t
>
(
xs
)...})];
}
}
template
<
class
Iterator
,
RTG
_REQUIRES
(
not
std
::
is_integral
<
Iterator
>{})
>
template
<
class
Iterator
,
MIGRAPH
_REQUIRES
(
not
std
::
is_integral
<
Iterator
>{})
>
const
T
&
operator
()(
Iterator
start
,
Iterator
last
)
const
const
T
&
operator
()(
Iterator
start
,
Iterator
last
)
const
{
{
return
m_data
[
m_shape
.
index
(
start
,
last
)];
return
m_data
[
m_shape
.
index
(
start
,
last
)];
}
}
template
<
class
Iterator
,
RTG
_REQUIRES
(
not
std
::
is_integral
<
Iterator
>{})
>
template
<
class
Iterator
,
MIGRAPH
_REQUIRES
(
not
std
::
is_integral
<
Iterator
>{})
>
T
&
operator
()(
Iterator
start
,
Iterator
last
)
T
&
operator
()(
Iterator
start
,
Iterator
last
)
{
{
return
m_data
[
m_shape
.
index
(
start
,
last
)];
return
m_data
[
m_shape
.
index
(
start
,
last
)];
...
@@ -162,6 +162,6 @@ tensor_view<T> make_view(shape s, T* data)
...
@@ -162,6 +162,6 @@ tensor_view<T> make_view(shape s, T* data)
return
{
s
,
data
};
return
{
s
,
data
};
}
}
}
// namespace
rtg
}
// namespace
migraph
#endif
#endif
src/include/rtg/fallthrough.hpp
deleted
100644 → 0
View file @
5f1ea74f
#ifndef RTG_GUARD_FALLTHROUGH_HPP
#define RTG_GUARD_FALLTHROUGH_HPP
namespace
rtg
{
#ifdef __clang__
#define RTG_FALLTHROUGH [[clang::fallthrough]]
#else
#define RTG_FALLTHROUGH
#endif
}
// namespace rtg
#endif
src/include/rtg/onnx.hpp
deleted
100644 → 0
View file @
5f1ea74f
#ifndef GUARD_RTGLIB_ONNX_HPP
#define GUARD_RTGLIB_ONNX_HPP
#include <rtg/program.hpp>
namespace
rtg
{
program
parse_onnx
(
const
std
::
string
&
name
);
}
// namespace rtg
#endif
src/onnx/CMakeLists.txt
View file @
eea003a5
...
@@ -7,17 +7,17 @@ target_compile_options(onnx-proto PRIVATE -w)
...
@@ -7,17 +7,17 @@ target_compile_options(onnx-proto PRIVATE -w)
target_link_libraries
(
onnx-proto PRIVATE
${
PROTOBUF_LIBRARY
}
)
target_link_libraries
(
onnx-proto PRIVATE
${
PROTOBUF_LIBRARY
}
)
set_target_properties
(
onnx-proto PROPERTIES POSITION_INDEPENDENT_CODE On
)
set_target_properties
(
onnx-proto PROPERTIES POSITION_INDEPENDENT_CODE On
)
add_library
(
rtg
_onnx onnx.cpp
)
add_library
(
migraph
_onnx onnx.cpp
)
rocm_clang_tidy_check
(
rtg
_onnx
)
rocm_clang_tidy_check
(
migraph
_onnx
)
target_link_libraries
(
rtg
_onnx PRIVATE onnx-proto
)
target_link_libraries
(
migraph
_onnx PRIVATE onnx-proto
)
target_link_libraries
(
rtg
_onnx PUBLIC
rtg
)
target_link_libraries
(
migraph
_onnx PUBLIC
migraph
)
add_executable
(
read_onnx read_onnx.cpp
)
add_executable
(
read_onnx read_onnx.cpp
)
rocm_clang_tidy_check
(
read_onnx
)
rocm_clang_tidy_check
(
read_onnx
)
target_link_libraries
(
read_onnx
rtg
_onnx
)
target_link_libraries
(
read_onnx
migraph
_onnx
)
if
(
RTG
_ENABLE_MIOPEN
)
if
(
MIGRAPH
_ENABLE_MIOPEN
)
add_executable
(
verify_onnx verify_onnx.cpp
)
add_executable
(
verify_onnx verify_onnx.cpp
)
rocm_clang_tidy_check
(
verify_onnx
)
rocm_clang_tidy_check
(
verify_onnx
)
target_link_libraries
(
verify_onnx
rtg_onnx rtg_cpu rtg
_miopen
)
target_link_libraries
(
verify_onnx
migraph_onnx migraph_cpu migraph
_miopen
)
endif
()
endif
()
src/onnx/onnx.cpp
View file @
eea003a5
...
@@ -7,12 +7,12 @@
...
@@ -7,12 +7,12 @@
#include <functional>
#include <functional>
#include <array>
#include <array>
#include <
rtg
/fallthrough.hpp>
#include <
migraph
/fallthrough.hpp>
#include <
rtg
/program.hpp>
#include <
migraph
/program.hpp>
#include <
rtg
/operators.hpp>
#include <
migraph
/operators.hpp>
#include <
rtg
/ranges.hpp>
#include <
migraph
/ranges.hpp>
namespace
rtg
{
namespace
migraph
{
struct
unknown
struct
unknown
{
{
...
@@ -25,7 +25,7 @@ struct unknown
...
@@ -25,7 +25,7 @@ struct unknown
else
else
return
input
.
front
();
return
input
.
front
();
}
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
unknown
&
x
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
unknown
&
x
)
{
{
os
<<
x
.
name
();
os
<<
x
.
name
();
...
@@ -162,7 +162,7 @@ struct onnx_parser
...
@@ -162,7 +162,7 @@ struct onnx_parser
void
parse_node
(
std
::
string
name
)
void
parse_node
(
std
::
string
name
)
{
{
if
(
name
.
empty
())
if
(
name
.
empty
())
RTG
_THROW
(
"Onnx node must have a name"
);
MIGRAPH
_THROW
(
"Onnx node must have a name"
);
if
(
instructions
.
count
(
name
)
==
0
)
if
(
instructions
.
count
(
name
)
==
0
)
{
{
auto
&&
node
=
nodes
.
at
(
name
);
auto
&&
node
=
nodes
.
at
(
name
);
...
@@ -239,7 +239,7 @@ struct onnx_parser
...
@@ -239,7 +239,7 @@ struct onnx_parser
case
onnx
::
AttributeProto
::
TENSORS
:
return
{};
case
onnx
::
AttributeProto
::
TENSORS
:
return
{};
case
onnx
::
AttributeProto
::
GRAPHS
:
return
{};
case
onnx
::
AttributeProto
::
GRAPHS
:
return
{};
}
}
RTG
_THROW
(
"Invalid attribute type"
);
MIGRAPH
_THROW
(
"Invalid attribute type"
);
}
}
static
literal
parse_tensor
(
const
onnx
::
TensorProto
&
t
)
static
literal
parse_tensor
(
const
onnx
::
TensorProto
&
t
)
...
@@ -273,7 +273,7 @@ struct onnx_parser
...
@@ -273,7 +273,7 @@ struct onnx_parser
case
onnx
::
TensorProto
::
COMPLEX64
:
throw
std
::
runtime_error
(
""
);
case
onnx
::
TensorProto
::
COMPLEX64
:
throw
std
::
runtime_error
(
""
);
case
onnx
::
TensorProto
::
COMPLEX128
:
throw
std
::
runtime_error
(
""
);
case
onnx
::
TensorProto
::
COMPLEX128
:
throw
std
::
runtime_error
(
""
);
}
}
RTG
_THROW
(
"Invalid tensor type"
);
MIGRAPH
_THROW
(
"Invalid tensor type"
);
}
}
static
shape
parse_type
(
const
onnx
::
TypeProto
&
t
)
static
shape
parse_type
(
const
onnx
::
TypeProto
&
t
)
...
@@ -336,4 +336,4 @@ program parse_onnx(const std::string& name)
...
@@ -336,4 +336,4 @@ program parse_onnx(const std::string& name)
return
std
::
move
(
parser
.
prog
);
return
std
::
move
(
parser
.
prog
);
}
}
}
// namespace
rtg
}
// namespace
migraph
src/onnx/read_onnx.cpp
View file @
eea003a5
#include <
rtg
/onnx.hpp>
#include <
migraph
/onnx.hpp>
int
main
(
int
argc
,
char
const
*
argv
[])
int
main
(
int
argc
,
char
const
*
argv
[])
{
{
if
(
argc
>
1
)
if
(
argc
>
1
)
{
{
std
::
string
file
=
argv
[
1
];
std
::
string
file
=
argv
[
1
];
auto
prog
=
rtg
::
parse_onnx
(
file
);
auto
prog
=
migraph
::
parse_onnx
(
file
);
std
::
cout
<<
prog
<<
std
::
endl
;
std
::
cout
<<
prog
<<
std
::
endl
;
}
}
}
}
src/onnx/verify_onnx.cpp
View file @
eea003a5
#include <
rtg
/onnx.hpp>
#include <
migraph
/onnx.hpp>
#include <
rtg
/cpu/cpu_target.hpp>
#include <
migraph
/cpu/cpu_target.hpp>
#include <
rtg
/miopen/miopen_target.hpp>
#include <
migraph
/miopen/miopen_target.hpp>
#include <
rtg
/miopen/hip.hpp>
#include <
migraph
/miopen/hip.hpp>
#include <
rtg
/generate.hpp>
#include <
migraph
/generate.hpp>
#include <miopen/miopen.h>
#include <miopen/miopen.h>
#include <
rtg
/miopen/miopen.hpp>
#include <
migraph
/miopen/miopen.hpp>
rtg
::
argument
run_cpu
(
std
::
string
file
)
migraph
::
argument
run_cpu
(
std
::
string
file
)
{
{
auto
p
=
rtg
::
parse_onnx
(
file
);
auto
p
=
migraph
::
parse_onnx
(
file
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
s
=
p
.
get_parameter_shape
(
"Input3"
);
auto
s
=
p
.
get_parameter_shape
(
"Input3"
);
auto
input3
=
rtg
::
generate_argument
(
s
);
auto
input3
=
migraph
::
generate_argument
(
s
);
auto
out
=
p
.
eval
({{
"Input3"
,
input3
}});
auto
out
=
p
.
eval
({{
"Input3"
,
input3
}});
std
::
cout
<<
p
<<
std
::
endl
;
std
::
cout
<<
p
<<
std
::
endl
;
return
out
;
return
out
;
}
}
rtg
::
argument
run_gpu
(
std
::
string
file
)
migraph
::
argument
run_gpu
(
std
::
string
file
)
{
{
auto
p
=
rtg
::
parse_onnx
(
file
);
auto
p
=
migraph
::
parse_onnx
(
file
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
s
=
p
.
get_parameter_shape
(
"Input3"
);
auto
s
=
p
.
get_parameter_shape
(
"Input3"
);
auto
input3
=
rtg
::
miopen
::
to_gpu
(
rtg
::
generate_argument
(
s
));
auto
input3
=
migraph
::
miopen
::
to_gpu
(
migraph
::
generate_argument
(
s
));
auto
output
=
rtg
::
miopen
::
to_gpu
(
rtg
::
generate_argument
(
p
.
get_parameter_shape
(
"output"
)));
auto
output
=
migraph
::
miopen
::
to_gpu
(
migraph
::
generate_argument
(
p
.
get_parameter_shape
(
"output"
)));
auto
handle
=
rtg
::
miopen
::
make_obj
<
rtg
::
miopen
::
miopen_handle
>
(
&
miopenCreate
);
auto
handle
=
migraph
::
miopen
::
make_obj
<
migraph
::
miopen
::
miopen_handle
>
(
&
miopenCreate
);
auto
out
=
p
.
eval
({{
"Input3"
,
input3
},
{
"output"
,
output
}});
auto
out
=
p
.
eval
({{
"Input3"
,
input3
},
{
"output"
,
output
}});
std
::
cout
<<
p
<<
std
::
endl
;
std
::
cout
<<
p
<<
std
::
endl
;
return
rtg
::
miopen
::
from_gpu
(
out
);
return
migraph
::
miopen
::
from_gpu
(
out
);
}
}
int
main
(
int
argc
,
char
const
*
argv
[])
int
main
(
int
argc
,
char
const
*
argv
[])
...
...
src/program.cpp
View file @
eea003a5
#include <
rtg
/program.hpp>
#include <
migraph
/program.hpp>
#include <
rtg
/stringutils.hpp>
#include <
migraph
/stringutils.hpp>
#include <
rtg
/instruction.hpp>
#include <
migraph
/instruction.hpp>
#include <iostream>
#include <iostream>
#include <algorithm>
#include <algorithm>
namespace
rtg
{
namespace
migraph
{
struct
program_impl
struct
program_impl
{
{
...
@@ -113,7 +113,7 @@ void program::compile(const target& t)
...
@@ -113,7 +113,7 @@ void program::compile(const target& t)
this
->
impl
->
ctx
=
t
.
get_context
();
this
->
impl
->
ctx
=
t
.
get_context
();
t
.
apply
(
*
this
);
t
.
apply
(
*
this
);
if
(
this
->
validate
()
==
impl
->
instructions
.
end
())
if
(
this
->
validate
()
==
impl
->
instructions
.
end
())
RTG
_THROW
(
"Invalid program from compilation"
);
MIGRAPH
_THROW
(
"Invalid program from compilation"
);
}
}
argument
program
::
eval
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
argument
program
::
eval
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
...
@@ -196,4 +196,4 @@ std::ostream& operator<<(std::ostream& os, const program& p)
...
@@ -196,4 +196,4 @@ std::ostream& operator<<(std::ostream& os, const program& p)
return
os
;
return
os
;
}
}
}
// namespace
rtg
}
// namespace
migraph
src/shape.cpp
View file @
eea003a5
#include <
rtg
/shape.hpp>
#include <
migraph
/shape.hpp>
#include <
rtg
/stringutils.hpp>
#include <
migraph
/stringutils.hpp>
#include <numeric>
#include <numeric>
#include <algorithm>
#include <algorithm>
#include <functional>
#include <functional>
#include <iostream>
#include <iostream>
namespace
rtg
{
namespace
migraph
{
shape
::
shape
()
:
m_type
(
float_type
),
m_packed
(
false
)
{}
shape
::
shape
()
:
m_type
(
float_type
),
m_packed
(
false
)
{}
...
@@ -109,12 +109,12 @@ std::string shape::type_string() const
...
@@ -109,12 +109,12 @@ std::string shape::type_string() const
{
{
switch
(
this
->
m_type
)
switch
(
this
->
m_type
)
{
{
#define
RTG
_SHAPE_TYPE_STRING_CASE(x, t) \
#define
MIGRAPH
_SHAPE_TYPE_STRING_CASE(x, t) \
case x: return #x;
case x: return #x;
RTG
_SHAPE_VISIT_TYPES
(
RTG
_SHAPE_TYPE_STRING_CASE
)
MIGRAPH
_SHAPE_VISIT_TYPES
(
MIGRAPH
_SHAPE_TYPE_STRING_CASE
)
#undef
RTG
_SHAPE_TYPE_STRING_CASE
#undef
MIGRAPH
_SHAPE_TYPE_STRING_CASE
}
}
RTG
_THROW
(
"Invalid type"
);
MIGRAPH
_THROW
(
"Invalid type"
);
}
}
bool
operator
==
(
const
shape
&
x
,
const
shape
&
y
)
bool
operator
==
(
const
shape
&
x
,
const
shape
&
y
)
...
@@ -131,4 +131,4 @@ std::ostream& operator<<(std::ostream& os, const shape& x)
...
@@ -131,4 +131,4 @@ std::ostream& operator<<(std::ostream& os, const shape& x)
return
os
;
return
os
;
}
}
}
// namespace
rtg
}
// namespace
migraph
Prev
1
2
3
4
Next
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