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
d2549384
"benchmark/git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "ddf39d3fcee2ed42284bfb90c3ea37b302090dad"
Commit
d2549384
authored
Feb 01, 2019
by
Khalique
Browse files
manual merge
parents
67048d04
ab6cd9d3
Changes
303
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
717 additions
and
297 deletions
+717
-297
src/include/migraphx/shape.hpp
src/include/migraphx/shape.hpp
+20
-20
src/include/migraphx/shape_for_each.hpp
src/include/migraphx/shape_for_each.hpp
+9
-9
src/include/migraphx/simplify_algebra.hpp
src/include/migraphx/simplify_algebra.hpp
+24
-0
src/include/migraphx/simplify_reshapes.hpp
src/include/migraphx/simplify_reshapes.hpp
+25
-0
src/include/migraphx/streamutils.hpp
src/include/migraphx/streamutils.hpp
+8
-8
src/include/migraphx/stringutils.hpp
src/include/migraphx/stringutils.hpp
+7
-7
src/include/migraphx/target.hpp
src/include/migraphx/target.hpp
+15
-9
src/include/migraphx/tensor_view.hpp
src/include/migraphx/tensor_view.hpp
+15
-15
src/include/migraphx/time.hpp
src/include/migraphx/time.hpp
+7
-7
src/include/migraphx/tracer.hpp
src/include/migraphx/tracer.hpp
+8
-8
src/include/migraphx/type_name.hpp
src/include/migraphx/type_name.hpp
+9
-9
src/include/migraphx/type_traits.hpp
src/include/migraphx/type_traits.hpp
+36
-0
src/include/migraphx/verify.hpp
src/include/migraphx/verify.hpp
+8
-8
src/include/migraphx/verify_args.hpp
src/include/migraphx/verify_args.hpp
+9
-9
src/instruction.cpp
src/instruction.cpp
+45
-16
src/onnx/CMakeLists.txt
src/onnx/CMakeLists.txt
+12
-12
src/onnx/cifar10.cpp
src/onnx/cifar10.cpp
+15
-15
src/onnx/mnist.cpp
src/onnx/mnist.cpp
+18
-13
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+416
-121
src/onnx/perf_onnx.cpp
src/onnx/perf_onnx.cpp
+11
-11
No files found.
src/include/migraph/shape.hpp
→
src/include/migraph
x
/shape.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_SHAPE_HPP
#ifndef MIGRAPH
X
_GUARD_MIGRAPHLIB_SHAPE_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_SHAPE_HPP
#define MIGRAPH
X
_GUARD_MIGRAPHLIB_SHAPE_HPP
#include <vector>
#include <vector>
#include <cassert>
#include <cassert>
...
@@ -7,12 +7,12 @@
...
@@ -7,12 +7,12 @@
#include <numeric>
#include <numeric>
#include <memory>
#include <memory>
#include <migraph/errors.hpp>
#include <migraph
x
/errors.hpp>
#include <migraph/half.hpp>
#include <migraph
x
/half.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
struct
shape_impl
;
struct
shape_impl
;
...
@@ -21,7 +21,7 @@ struct shape
...
@@ -21,7 +21,7 @@ struct shape
// Add new types here
// Add new types here
// clang-format off
// clang-format off
#define MIGRAPH_SHAPE_VISIT_TYPES(m) \
#define MIGRAPH
X
_SHAPE_VISIT_TYPES(m) \
m(half_type, half) \
m(half_type, half) \
m(float_type, float) \
m(float_type, float) \
m(double_type, double) \
m(double_type, double) \
...
@@ -35,22 +35,22 @@ struct shape
...
@@ -35,22 +35,22 @@ struct shape
m(uint64_type, uint64_t)
m(uint64_type, uint64_t)
// clang-format on
// clang-format on
#define MIGRAPH_SHAPE_ENUM_TYPES(x, t) x,
#define MIGRAPH
X
_SHAPE_
GENERATE_
ENUM_TYPES(x, t) x,
enum
type_t
enum
type_t
{
{
MIGRAPH_SHAPE_VISIT_TYPES
(
MIGRAPH_SHAPE_ENUM_TYPES
)
MIGRAPH
X
_SHAPE_VISIT_TYPES
(
MIGRAPH
X
_SHAPE_
GENERATE_
ENUM_TYPES
)
};
};
#undef MIGRAPH_SHAPE_ENUM_TYPES
#undef MIGRAPH
X
_SHAPE_
GENERATE_
ENUM_TYPES
template
<
class
T
,
class
=
void
>
template
<
class
T
,
class
=
void
>
struct
get_type
;
struct
get_type
;
#define MIGRAPH_SHAPE_GET_TYPE(x, t)
\
#define MIGRAPH
X
_SHAPE_
GENERATE_
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> \
{ \
{ \
};
};
MIGRAPH_SHAPE_VISIT_TYPES
(
MIGRAPH_SHAPE_GET_TYPE
)
MIGRAPH
X
_SHAPE_VISIT_TYPES
(
MIGRAPH
X
_SHAPE_
GENERATE_
GET_TYPE
)
#undef MIGRAPH_SHAPE_GET_TYPE
#undef MIGRAPH
X
_SHAPE_
GENERATE_
GET_TYPE
template
<
class
T
>
template
<
class
T
>
struct
get_type
<
const
T
>
:
get_type
<
T
>
struct
get_type
<
const
T
>
:
get_type
<
T
>
...
@@ -148,12 +148,12 @@ struct shape
...
@@ -148,12 +148,12 @@ struct shape
{
{
switch
(
this
->
type
())
switch
(
this
->
type
())
{
{
#define MIGRAPH_SHAPE_VISITOR_CASE(x, t) \
#define MIGRAPH
X
_SHAPE_
GENERATE_
VISITOR_CASE(x, t) \
case x: v(as<t>()); return;
case x: v(as<t>()); return;
MIGRAPH_SHAPE_VISIT_TYPES
(
MIGRAPH_SHAPE_VISITOR_CASE
)
MIGRAPH
X
_SHAPE_VISIT_TYPES
(
MIGRAPH
X
_SHAPE_
GENERATE_
VISITOR_CASE
)
#undef MIGRAPH_SHAPE_VISITOR_CASE
#undef MIGRAPH
X
_SHAPE_
GENERATE_
VISITOR_CASE
}
}
MIGRAPH_THROW
(
"Unknown type"
);
MIGRAPH
X
_THROW
(
"Unknown type"
);
}
}
private:
private:
...
@@ -163,7 +163,7 @@ struct shape
...
@@ -163,7 +163,7 @@ struct shape
std
::
string
type_string
()
const
;
std
::
string
type_string
()
const
;
};
};
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/shape_for_each.hpp
→
src/include/migraph
x
/shape_for_each.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_SHAPE_FOR_EACH_HPP
#ifndef MIGRAPH
X
_GUARD_MIGRAPHLIB_SHAPE_FOR_EACH_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_SHAPE_FOR_EACH_HPP
#define MIGRAPH
X
_GUARD_MIGRAPHLIB_SHAPE_FOR_EACH_HPP
#include <migraph/shape.hpp>
#include <migraph
x
/shape.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
#include <algorithm>
#include <algorithm>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
template
<
class
F
>
template
<
class
F
>
void
shape_for_each
(
const
migraph
::
shape
&
s
,
F
f
)
void
shape_for_each
(
const
migraph
x
::
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
);
};
...
@@ -28,7 +28,7 @@ void shape_for_each(const migraph::shape& s, F f)
...
@@ -28,7 +28,7 @@ void shape_for_each(const migraph::shape& s, F f)
}
}
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/simplify_algebra.hpp
→
src/include/migraph
x
/simplify_algebra.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_RTGLIB_SIMPLIFY_ALGEBRA_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_SIMPLIFY_ALGEBRA_HPP
#define MIGRAPH_GUARD_RTGLIB_SIMPLIFY_ALGEBRA_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_SIMPLIFY_ALGEBRA_HPP
#include <string>
#include <string>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
struct
program
;
struct
program
;
...
@@ -18,7 +18,7 @@ struct simplify_algebra
...
@@ -18,7 +18,7 @@ struct simplify_algebra
void
apply
(
program
&
p
)
const
;
void
apply
(
program
&
p
)
const
;
};
};
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/simplify_reshapes.hpp
→
src/include/migraph
x
/simplify_reshapes.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_RTGLIB_SIMPLIFY_RESHAPES_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_SIMPLIFY_RESHAPES_HPP
#define MIGRAPH_GUARD_RTGLIB_SIMPLIFY_RESHAPES_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_SIMPLIFY_RESHAPES_HPP
#include <string>
#include <string>
#include <migraph/instruction_ref.hpp>
#include <migraph
x
/instruction_ref.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
struct
program
;
struct
program
;
...
@@ -19,7 +19,7 @@ struct simplify_reshapes
...
@@ -19,7 +19,7 @@ struct simplify_reshapes
void
apply
(
program
&
p
)
const
;
void
apply
(
program
&
p
)
const
;
};
};
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/streamutils.hpp
→
src/include/migraph
x
/streamutils.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_STREAMUTILS_HPP
#ifndef MIGRAPH
X
_GUARD_STREAMUTILS_HPP
#define MIGRAPH_GUARD_STREAMUTILS_HPP
#define MIGRAPH
X
_GUARD_STREAMUTILS_HPP
#include <ostream>
#include <ostream>
#include <algorithm>
#include <algorithm>
#include <migraph/rank.hpp>
#include <migraph
x
/rank.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
template
<
class
T
>
template
<
class
T
>
struct
stream_range_container
struct
stream_range_container
...
@@ -56,7 +56,7 @@ void stream_write_value(std::ostream& os, const T& x)
...
@@ -56,7 +56,7 @@ void stream_write_value(std::ostream& os, const T& x)
detail
::
stream_write_value_impl
(
rank
<
1
>
{},
os
,
x
);
detail
::
stream_write_value_impl
(
rank
<
1
>
{},
os
,
x
);
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/stringutils.hpp
→
src/include/migraph
x
/stringutils.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_STRINGUTILS_HPP
#ifndef MIGRAPH
X
_GUARD_MIGRAPHLIB_STRINGUTILS_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_STRINGUTILS_HPP
#define MIGRAPH
X
_GUARD_MIGRAPHLIB_STRINGUTILS_HPP
#include <algorithm>
#include <algorithm>
#include <numeric>
#include <numeric>
#include <string>
#include <string>
#include <sstream>
#include <sstream>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
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
)
...
@@ -87,7 +87,7 @@ inline std::string to_string(const T& x)
...
@@ -87,7 +87,7 @@ inline std::string to_string(const T& x)
return
ss
.
str
();
return
ss
.
str
();
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/target.hpp
→
src/include/migraph
x
/target.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_TARGET_HPP
#ifndef MIGRAPH
X
_GUARD_MIGRAPHLIB_TARGET_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_TARGET_HPP
#define MIGRAPH
X
_GUARD_MIGRAPHLIB_TARGET_HPP
#include <cassert>
#include <cassert>
#include <string>
#include <string>
...
@@ -8,12 +8,12 @@
...
@@ -8,12 +8,12 @@
#include <type_traits>
#include <type_traits>
#include <utility>
#include <utility>
#include <vector>
#include <vector>
#include <migraph/context.hpp>
#include <migraph
x
/context.hpp>
#include <migraph/pass.hpp>
#include <migraph
x
/pass.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
#ifdef DOXYGEN
#ifdef DOXYGEN
...
@@ -127,6 +127,12 @@ struct target
...
@@ -127,6 +127,12 @@ struct target
return
(
*
this
).
private_detail_te_get_handle
().
get_context
();
return
(
*
this
).
private_detail_te_get_handle
().
get_context
();
}
}
friend
bool
is_shared
(
const
target
&
private_detail_x
,
const
target
&
private_detail_y
)
{
return
private_detail_x
.
private_detail_te_handle_mem_var
==
private_detail_y
.
private_detail_te_handle_mem_var
;
}
private:
private:
struct
private_detail_te_handle_base_type
struct
private_detail_te_handle_base_type
{
{
...
@@ -244,7 +250,7 @@ inline const ValueType& any_cast(const target& x)
...
@@ -244,7 +250,7 @@ inline const ValueType& any_cast(const target& x)
#endif
#endif
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/tensor_view.hpp
→
src/include/migraph
x
/tensor_view.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_TENSOR_VIEW_HPP
#ifndef MIGRAPH
X
_GUARD_TENSOR_VIEW_HPP
#define MIGRAPH_GUARD_TENSOR_VIEW_HPP
#define MIGRAPH
X
_GUARD_TENSOR_VIEW_HPP
#include <migraph/shape.hpp>
#include <migraph
x
/shape.hpp>
#include <migraph/float_equal.hpp>
#include <migraph
x
/float_equal.hpp>
#include <migraph/requires.hpp>
#include <migraph
x
/requires.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
#include <iostream>
#include <iostream>
#include <utility>
#include <utility>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
template
<
class
T
>
template
<
class
T
>
struct
tensor_view
struct
tensor_view
...
@@ -29,7 +29,7 @@ struct tensor_view
...
@@ -29,7 +29,7 @@ struct tensor_view
const
T
*
data
()
const
{
return
this
->
m_data
;
}
const
T
*
data
()
const
{
return
this
->
m_data
;
}
template
<
class
...
Ts
,
MIGRAPH_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
template
<
class
...
Ts
,
MIGRAPH
X
_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
const
T
&
operator
()(
Ts
...
xs
)
const
const
T
&
operator
()(
Ts
...
xs
)
const
{
{
assert
(
std
::
vector
<
std
::
size_t
>
{
static_cast
<
std
::
size_t
>
(
xs
)...}
<
m_shape
.
lens
());
assert
(
std
::
vector
<
std
::
size_t
>
{
static_cast
<
std
::
size_t
>
(
xs
)...}
<
m_shape
.
lens
());
...
@@ -37,7 +37,7 @@ struct tensor_view
...
@@ -37,7 +37,7 @@ struct tensor_view
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
,
MIGRAPH_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
template
<
class
...
Ts
,
MIGRAPH
X
_REQUIRES
(
std
::
is_integral
<
Ts
>{}...)
>
T
&
operator
()(
Ts
...
xs
)
T
&
operator
()(
Ts
...
xs
)
{
{
assert
(
std
::
vector
<
std
::
size_t
>
{
static_cast
<
std
::
size_t
>
(
xs
)...}
<
m_shape
.
lens
());
assert
(
std
::
vector
<
std
::
size_t
>
{
static_cast
<
std
::
size_t
>
(
xs
)...}
<
m_shape
.
lens
());
...
@@ -45,13 +45,13 @@ struct tensor_view
...
@@ -45,13 +45,13 @@ struct tensor_view
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
,
MIGRAPH_REQUIRES
(
not
std
::
is_integral
<
Iterator
>{})
>
template
<
class
Iterator
,
MIGRAPH
X
_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
,
MIGRAPH_REQUIRES
(
not
std
::
is_integral
<
Iterator
>{})
>
template
<
class
Iterator
,
MIGRAPH
X
_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
)];
...
@@ -164,12 +164,12 @@ bool operator!=(const tensor_view<T>& x, const tensor_view<U>& y)
...
@@ -164,12 +164,12 @@ bool operator!=(const tensor_view<T>& x, const tensor_view<U>& y)
}
}
template
<
class
T
>
template
<
class
T
>
tensor_view
<
T
>
make_view
(
shape
s
,
T
*
data
)
tensor_view
<
T
>
make_view
(
const
shape
&
s
,
T
*
data
)
{
{
return
{
s
,
data
};
return
{
s
,
data
};
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/time.hpp
→
src/include/migraph
x
/time.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_RTGLIB_TIME_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_TIME_HPP
#define MIGRAPH_GUARD_RTGLIB_TIME_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_TIME_HPP
#include <chrono>
#include <chrono>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
template
<
class
Duration
,
class
F
>
template
<
class
Duration
,
class
F
>
auto
time
(
F
f
)
auto
time
(
F
f
)
...
@@ -16,7 +16,7 @@ auto time(F f)
...
@@ -16,7 +16,7 @@ auto time(F f)
return
std
::
chrono
::
duration_cast
<
Duration
>
(
finish
-
start
).
count
();
return
std
::
chrono
::
duration_cast
<
Duration
>
(
finish
-
start
).
count
();
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/tracer.hpp
→
src/include/migraph
x
/tracer.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_RTGLIB_TRACER_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_TRACER_HPP
#define MIGRAPH_GUARD_RTGLIB_TRACER_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_TRACER_HPP
#include <ostream>
#include <ostream>
#include <migraph/functional.hpp>
#include <migraph
x
/functional.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
struct
tracer
struct
tracer
{
{
...
@@ -30,7 +30,7 @@ struct tracer
...
@@ -30,7 +30,7 @@ struct tracer
std
::
ostream
*
os
=
nullptr
;
std
::
ostream
*
os
=
nullptr
;
};
};
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/type_name.hpp
→
src/include/migraph
x
/type_name.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_RTGLIB_TYPE_NAME_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_TYPE_NAME_HPP
#define MIGRAPH_GUARD_RTGLIB_TYPE_NAME_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_TYPE_NAME_HPP
#include <string>
#include <string>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
template
<
class
PrivateMigraphTypeNameProbe
>
template
<
class
PrivateMigraphTypeNameProbe
>
const
std
::
string
&
get_type_name
()
const
std
::
string
&
get_type_name
()
...
@@ -18,7 +18,7 @@ const std::string& get_type_name()
...
@@ -18,7 +18,7 @@ const std::string& get_type_name()
name
=
typeid
(
PrivateMigraphTypeNameProbe
).
name
();
name
=
typeid
(
PrivateMigraphTypeNameProbe
).
name
();
name
=
name
.
substr
(
7
);
name
=
name
.
substr
(
7
);
#else
#else
const
char
parameter_name
[]
=
"PrivateMigraphTypeNameProbe ="
;
const
char
parameter_name
[]
=
"PrivateMigraphTypeNameProbe ="
;
// NOLINT
name
=
__PRETTY_FUNCTION__
;
name
=
__PRETTY_FUNCTION__
;
...
@@ -38,10 +38,10 @@ const std::string& get_type_name()
...
@@ -38,10 +38,10 @@ const std::string& get_type_name()
template
<
class
T
>
template
<
class
T
>
const
std
::
string
&
get_type_name
(
const
T
&
)
const
std
::
string
&
get_type_name
(
const
T
&
)
{
{
return
migraph
::
get_type_name
<
T
>
();
return
migraph
x
::
get_type_name
<
T
>
();
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/type_traits.hpp
→
src/include/migraph
x
/type_traits.hpp
View file @
d2549384
...
@@ -5,32 +5,32 @@
...
@@ -5,32 +5,32 @@
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
==============================================================================*/
#ifndef MIGRAPH_GUARD_RTGLIB_TYPE_TRAITS_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_TYPE_TRAITS_HPP
#define MIGRAPH_GUARD_RTGLIB_TYPE_TRAITS_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_TYPE_TRAITS_HPP
#include <type_traits>
#include <type_traits>
#include <migraph/half.hpp>
#include <migraph
x
/half.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
#define MIGRAPH_DETAIL_EXTEND_TRAIT_FOR(trait, T) \
#define MIGRAPH
X
_DETAIL_EXTEND_TRAIT_FOR(trait, T) \
template <class X> \
template <class X>
\
struct trait : std::trait<X> \
struct trait : std::trait<X>
\
{ \
{
\
}; \
};
\
\
\
template <> \
template <>
\
struct trait<T> : std::true_type \
struct trait<T> : std::true_type
\
{ \
{
\
};
};
MIGRAPH_DETAIL_EXTEND_TRAIT_FOR
(
is_floating_point
,
half
)
MIGRAPH
X
_DETAIL_EXTEND_TRAIT_FOR
(
is_floating_point
,
half
)
MIGRAPH_DETAIL_EXTEND_TRAIT_FOR
(
is_signed
,
half
)
MIGRAPH
X
_DETAIL_EXTEND_TRAIT_FOR
(
is_signed
,
half
)
MIGRAPH_DETAIL_EXTEND_TRAIT_FOR
(
is_arithmetic
,
half
)
MIGRAPH
X
_DETAIL_EXTEND_TRAIT_FOR
(
is_arithmetic
,
half
)
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/verify.hpp
→
src/include/migraph
x
/verify.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_VERIFY_HPP
#ifndef MIGRAPH
X
_GUARD_VERIFY_HPP
#define MIGRAPH_GUARD_VERIFY_HPP
#define MIGRAPH
X
_GUARD_VERIFY_HPP
#include <algorithm>
#include <algorithm>
#include <cmath>
#include <cmath>
...
@@ -7,11 +7,11 @@
...
@@ -7,11 +7,11 @@
#include <iostream>
#include <iostream>
#include <numeric>
#include <numeric>
#include <migraph/float_equal.hpp>
#include <migraph
x
/float_equal.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
// Compute the value of a range
// Compute the value of a range
template
<
class
R
>
template
<
class
R
>
...
@@ -173,6 +173,6 @@ bool verify_range(R1&& r1, R2&& r2, double tolerance = 80, double* out_error = n
...
@@ -173,6 +173,6 @@ bool verify_range(R1&& r1, R2&& r2, double tolerance = 80, double* out_error = n
return
error
<=
threshold
;
return
error
<=
threshold
;
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/include/migraph/verify_args.hpp
→
src/include/migraph
x
/verify_args.hpp
View file @
d2549384
#ifndef MIGRAPH_GUARD_RTGLIB_VERIFY_ARGS_HPP
#ifndef MIGRAPH
X
_GUARD_RTGLIB_VERIFY_ARGS_HPP
#define MIGRAPH_GUARD_RTGLIB_VERIFY_ARGS_HPP
#define MIGRAPH
X
_GUARD_RTGLIB_VERIFY_ARGS_HPP
#include <migraph/verify.hpp>
#include <migraph
x
/verify.hpp>
#include <migraph/argument.hpp>
#include <migraph
x
/argument.hpp>
#include <migraph/config.hpp>
#include <migraph
x
/config.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
inline
bool
verify_args
(
const
std
::
string
&
name
,
inline
bool
verify_args
(
const
std
::
string
&
name
,
const
argument
&
cpu_arg
,
const
argument
&
cpu_arg
,
...
@@ -84,7 +84,7 @@ inline bool verify_args(const std::string& name,
...
@@ -84,7 +84,7 @@ inline bool verify_args(const std::string& name,
return
passed
;
return
passed
;
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
#endif
#endif
src/instruction.cpp
View file @
d2549384
#include <migraph/instruction.hpp>
#include <migraph
x
/instruction.hpp>
#include <migraph/builtin.hpp>
#include <migraph
x
/builtin.hpp>
#include <migraph/erase.hpp>
#include <migraph
x
/erase.hpp>
namespace
migraph
{
namespace
migraph
x
{
inline
namespace
MIGRAPH_INLINE_NS
{
inline
namespace
MIGRAPH
X
_INLINE_NS
{
instruction
::
instruction
(
operation
o
,
shape
r
,
std
::
vector
<
instruction_ref
>
args
)
instruction
::
instruction
(
operation
o
,
shape
r
,
std
::
vector
<
instruction_ref
>
args
)
:
op
(
std
::
move
(
o
)),
result
(
std
::
move
(
r
)),
arguments
(
std
::
move
(
args
))
:
op
(
std
::
move
(
o
)),
result
(
std
::
move
(
r
)),
arguments
(
std
::
move
(
args
))
...
@@ -70,7 +70,7 @@ bool instruction::valid() const
...
@@ -70,7 +70,7 @@ bool instruction::valid() const
{
{
computed
=
compute_shape
(
op
,
arguments
);
computed
=
compute_shape
(
op
,
arguments
);
}
}
catch
(
migraph
::
exception
&
)
catch
(
migraph
x
::
exception
&
)
{
{
return
false
;
return
false
;
}
}
...
@@ -162,26 +162,55 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
...
@@ -162,26 +162,55 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
old
->
remove_output
(
*
this
);
old
->
remove_output
(
*
this
);
}
}
std
::
vector
<
shape
>
compute_shapes
(
const
std
::
vector
<
instruction_ref
>&
args
)
argument
instruction
::
eval
()
const
{
{
std
::
vector
<
shape
>
shapes
(
args
.
size
());
if
(
op
.
name
()
==
"@literal"
)
std
::
transform
(
{
args
.
begin
(),
args
.
end
(),
shapes
.
begin
(),
[](
instruction_ref
i
)
{
return
i
->
get_shape
();
});
return
this
->
get_literal
().
get_argument
();
return
shapes
;
}
if
(
is_context_free
(
op
))
{
std
::
vector
<
argument
>
args
;
for
(
auto
&&
arg
:
this
->
inputs
())
{
argument
a
=
arg
->
eval
();
if
(
a
.
empty
())
return
{};
args
.
push_back
(
a
);
}
return
op
.
compute
(
result
,
args
);
}
return
{};
}
}
instruction_ref
instruction
::
get_output_alias
(
instruction_ref
ins
)
void
instruction
::
finalize
(
context
&
ctx
)
{
{
auto
i
=
ins
->
get_operator
().
output_alias
(
compute_shapes
(
ins
->
inputs
()));
if
(
has_finalize
(
this
->
op
))
this
->
op
.
finalize
(
ctx
,
this
->
get_shape
(),
to_shapes
(
this
->
inputs
()));
}
instruction_ref
instruction
::
get_output_alias
(
instruction_ref
ins
,
bool
shallow
)
{
auto
i
=
ins
->
get_operator
().
output_alias
(
to_shapes
(
ins
->
inputs
()));
if
(
i
<
0
)
if
(
i
<
0
)
return
ins
;
return
ins
;
if
(
shallow
)
return
ins
->
inputs
().
at
(
i
);
return
get_output_alias
(
ins
->
inputs
().
at
(
i
));
return
get_output_alias
(
ins
->
inputs
().
at
(
i
));
}
}
std
::
vector
<
shape
>
to_shapes
(
const
std
::
vector
<
instruction_ref
>&
args
)
{
std
::
vector
<
shape
>
shapes
(
args
.
size
());
std
::
transform
(
args
.
begin
(),
args
.
end
(),
shapes
.
begin
(),
[](
instruction_ref
i
)
{
return
i
->
get_shape
();
});
return
shapes
;
}
shape
compute_shape
(
const
operation
&
op
,
const
std
::
vector
<
instruction_ref
>&
args
)
shape
compute_shape
(
const
operation
&
op
,
const
std
::
vector
<
instruction_ref
>&
args
)
{
{
return
op
.
compute_shape
(
compute
_shapes
(
args
));
return
op
.
compute_shape
(
to
_shapes
(
args
));
}
}
}
// namespace MIGRAPH_INLINE_NS
}
// namespace MIGRAPH
X
_INLINE_NS
}
// namespace migraph
}
// namespace migraph
x
src/onnx/CMakeLists.txt
View file @
d2549384
...
@@ -7,35 +7,35 @@ target_compile_options(onnx-proto PRIVATE -w)
...
@@ -7,35 +7,35 @@ 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
(
migraph_onnx onnx.cpp
)
add_library
(
migraph
x
_onnx onnx.cpp
)
set_target_properties
(
migraph_onnx PROPERTIES EXPORT_NAME onnx
)
set_target_properties
(
migraph
x
_onnx PROPERTIES EXPORT_NAME onnx
)
rocm_clang_tidy_check
(
migraph_onnx
)
rocm_clang_tidy_check
(
migraph
x
_onnx
)
target_link_libraries
(
migraph_onnx PRIVATE onnx-proto
)
target_link_libraries
(
migraph
x
_onnx PRIVATE onnx-proto
)
target_link_libraries
(
migraph_onnx PUBLIC migraph
)
target_link_libraries
(
migraph
x
_onnx PUBLIC migraph
x
)
rocm_install_targets
(
rocm_install_targets
(
TARGETS migraph_onnx
TARGETS migraph
x
_onnx
)
)
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 migraph_onnx
)
target_link_libraries
(
read_onnx migraph
x
_onnx
)
if
(
MIGRAPH_ENABLE_GPU
)
if
(
MIGRAPH
X
_ENABLE_GPU
)
add_executable
(
mnist mnist.cpp
)
add_executable
(
mnist mnist.cpp
)
rocm_clang_tidy_check
(
mnist
)
rocm_clang_tidy_check
(
mnist
)
target_link_libraries
(
mnist migraph_cpu migraph_gpu migraph_onnx
)
target_link_libraries
(
mnist migraph
x
_cpu migraph
x
_gpu migraph
x
_onnx
)
add_executable
(
cifar10 cifar10.cpp
)
add_executable
(
cifar10 cifar10.cpp
)
rocm_clang_tidy_check
(
cifar10
)
rocm_clang_tidy_check
(
cifar10
)
target_link_libraries
(
cifar10 migraph_cpu migraph_gpu migraph_onnx
)
target_link_libraries
(
cifar10 migraph
x
_cpu migraph
x
_gpu migraph
x
_onnx
)
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 migraph_onnx migraph_cpu migraph_gpu
)
target_link_libraries
(
verify_onnx migraph
x
_onnx migraph
x
_cpu migraph
x
_gpu
)
add_executable
(
perf_onnx perf_onnx.cpp
)
add_executable
(
perf_onnx perf_onnx.cpp
)
rocm_clang_tidy_check
(
perf_onnx
)
rocm_clang_tidy_check
(
perf_onnx
)
target_link_libraries
(
perf_onnx migraph_onnx migraph_cpu migraph_gpu
)
target_link_libraries
(
perf_onnx migraph
x
_onnx migraph
x
_cpu migraph
x
_gpu
)
endif
()
endif
()
src/onnx/cifar10.cpp
View file @
d2549384
...
@@ -4,12 +4,12 @@
...
@@ -4,12 +4,12 @@
#include <numeric>
#include <numeric>
#include <stdexcept>
#include <stdexcept>
#include <migraph/onnx.hpp>
#include <migraph
x
/onnx.hpp>
#include <migraph/cpu/target.hpp>
#include <migraph
x
/cpu/target.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph
x
/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph
x
/gpu/hip.hpp>
#include <migraph/generate.hpp>
#include <migraph
x
/generate.hpp>
#include "softmax.hpp"
#include "softmax.hpp"
...
@@ -53,19 +53,19 @@ int main(int argc, char const* argv[])
...
@@ -53,19 +53,19 @@ int main(int argc, char const* argv[])
std
::
string
gpu_cpu
=
argv
[
1
];
std
::
string
gpu_cpu
=
argv
[
1
];
std
::
string
file
=
argv
[
2
];
std
::
string
file
=
argv
[
2
];
std
::
string
datafile
=
argv
[
3
];
std
::
string
datafile
=
argv
[
3
];
auto
prog
=
migraph
::
parse_onnx
(
file
);
auto
prog
=
migraph
x
::
parse_onnx
(
file
);
std
::
cout
<<
prog
<<
std
::
endl
;
std
::
cout
<<
prog
<<
std
::
endl
;
auto
imageset
=
read_cifar10_images
(
datafile
);
auto
imageset
=
read_cifar10_images
(
datafile
);
if
(
gpu_cpu
==
"gpu"
)
if
(
gpu_cpu
==
"gpu"
)
{
{
// GPU target
// GPU target
prog
.
compile
(
migraph
::
gpu
::
target
{});
prog
.
compile
(
migraph
x
::
gpu
::
target
{});
migraph
::
program
::
parameter_map
m
;
migraph
x
::
program
::
parameter_map
m
;
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
auto
s
=
migraph
x
::
shape
{
migraph
x
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
for
(
auto
&&
x
:
prog
.
get_parameter_shapes
())
for
(
auto
&&
x
:
prog
.
get_parameter_shapes
())
{
{
m
[
x
.
first
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
x
.
second
));
m
[
x
.
first
]
=
migraph
x
::
gpu
::
to_gpu
(
migraph
x
::
generate_argument
(
x
.
second
));
}
}
auto
labels
=
imageset
.
first
;
auto
labels
=
imageset
.
first
;
auto
input
=
imageset
.
second
;
auto
input
=
imageset
.
second
;
...
@@ -73,8 +73,8 @@ int main(int argc, char const* argv[])
...
@@ -73,8 +73,8 @@ int main(int argc, char const* argv[])
for
(
int
i
=
0
;
i
<
10
;
i
++
)
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
{
std
::
cout
<<
"label: "
<<
static_cast
<
uint32_t
>
(
labels
[
i
])
<<
" ----> "
;
std
::
cout
<<
"label: "
<<
static_cast
<
uint32_t
>
(
labels
[
i
])
<<
" ----> "
;
m
[
"0"
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
argument
{
s
,
&
ptr
[
3072
*
i
]});
m
[
"0"
]
=
migraph
x
::
gpu
::
to_gpu
(
migraph
x
::
argument
{
s
,
&
ptr
[
3072
*
i
]});
auto
result
=
migraph
::
gpu
::
from_gpu
(
prog
.
eval
(
m
));
auto
result
=
migraph
x
::
gpu
::
from_gpu
(
prog
.
eval
(
m
));
std
::
vector
<
float
>
logits
;
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
<
float
>
(
logits
);
std
::
vector
<
float
>
probs
=
softmax
<
float
>
(
logits
);
...
@@ -86,15 +86,15 @@ int main(int argc, char const* argv[])
...
@@ -86,15 +86,15 @@ int main(int argc, char const* argv[])
else
else
{
{
// CPU target
// CPU target
prog
.
compile
(
migraph
::
cpu
::
target
{});
prog
.
compile
(
migraph
x
::
cpu
::
target
{});
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
auto
s
=
migraph
x
::
shape
{
migraph
x
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
auto
labels
=
imageset
.
first
;
auto
labels
=
imageset
.
first
;
auto
input
=
imageset
.
second
;
auto
input
=
imageset
.
second
;
auto
ptr
=
input
.
data
();
auto
ptr
=
input
.
data
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
{
std
::
cout
<<
"label: "
<<
static_cast
<
uint32_t
>
(
labels
[
i
])
<<
" ----> "
;
std
::
cout
<<
"label: "
<<
static_cast
<
uint32_t
>
(
labels
[
i
])
<<
" ----> "
;
auto
input3
=
migraph
::
argument
{
s
,
&
ptr
[
3072
*
i
]};
auto
input3
=
migraph
x
::
argument
{
s
,
&
ptr
[
3072
*
i
]};
auto
result
=
prog
.
eval
({{
"0"
,
input3
}});
auto
result
=
prog
.
eval
({{
"0"
,
input3
}});
std
::
vector
<
float
>
logits
;
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
src/onnx/mnist.cpp
View file @
d2549384
...
@@ -4,17 +4,20 @@
...
@@ -4,17 +4,20 @@
#include <numeric>
#include <numeric>
#include <stdexcept>
#include <stdexcept>
#include <migraph/onnx.hpp>
#include <migraph
x
/onnx.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph
x
/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph
x
/gpu/hip.hpp>
#include <migraph/generate.hpp>
#include <migraph
x
/generate.hpp>
#include "softmax.hpp"
#include "softmax.hpp"
auto
reverse_int
(
unsigned
int
i
)
auto
reverse_int
(
unsigned
int
i
)
{
{
unsigned
char
c1
,
c2
,
c3
,
c4
;
unsigned
char
c1
;
unsigned
char
c2
;
unsigned
char
c3
;
unsigned
char
c4
;
c1
=
i
&
255u
;
c1
=
i
&
255u
;
c2
=
(
i
>>
8u
)
&
255u
;
c2
=
(
i
>>
8u
)
&
255u
;
c3
=
(
i
>>
16u
)
&
255u
;
c3
=
(
i
>>
16u
)
&
255u
;
...
@@ -32,7 +35,9 @@ read_mnist_images(const std::string& full_path, int& number_of_images, int& imag
...
@@ -32,7 +35,9 @@ read_mnist_images(const std::string& full_path, int& number_of_images, int& imag
if
(
file
.
is_open
())
if
(
file
.
is_open
())
{
{
int
magic_number
=
0
,
n_rows
=
0
,
n_cols
=
0
;
int
magic_number
=
0
;
int
n_rows
=
0
;
int
n_cols
=
0
;
file
.
read
(
reinterpret_cast
<
char
*>
(
&
magic_number
),
sizeof
(
magic_number
));
file
.
read
(
reinterpret_cast
<
char
*>
(
&
magic_number
),
sizeof
(
magic_number
));
magic_number
=
reverse_int
(
magic_number
);
magic_number
=
reverse_int
(
magic_number
);
...
@@ -113,20 +118,20 @@ int main(int argc, char const* argv[])
...
@@ -113,20 +118,20 @@ int main(int argc, char const* argv[])
std
::
vector
<
int32_t
>
labels
=
read_mnist_labels
(
labelfile
,
nlabels
);
std
::
vector
<
int32_t
>
labels
=
read_mnist_labels
(
labelfile
,
nlabels
);
std
::
string
file
=
argv
[
1
];
std
::
string
file
=
argv
[
1
];
auto
prog
=
migraph
::
parse_onnx
(
file
);
auto
prog
=
migraph
x
::
parse_onnx
(
file
);
std
::
cout
<<
prog
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
prog
<<
std
::
endl
<<
std
::
endl
;
prog
.
compile
(
migraph
::
gpu
::
target
{});
prog
.
compile
(
migraph
x
::
gpu
::
target
{});
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
1
,
28
,
28
}};
auto
s
=
migraph
x
::
shape
{
migraph
x
::
shape
::
float_type
,
{
1
,
1
,
28
,
28
}};
std
::
cout
<<
s
<<
std
::
endl
;
std
::
cout
<<
s
<<
std
::
endl
;
auto
ptr
=
input
.
data
();
auto
ptr
=
input
.
data
();
migraph
::
program
::
parameter_map
m
;
migraph
x
::
program
::
parameter_map
m
;
m
[
"output"
]
=
m
[
"output"
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
prog
.
get_parameter_shape
(
"output"
)));
migraph
x
::
gpu
::
to_gpu
(
migraph
x
::
generate_argument
(
prog
.
get_parameter_shape
(
"output"
)));
for
(
int
i
=
0
;
i
<
20
;
i
++
)
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
{
std
::
cout
<<
"label: "
<<
labels
[
i
]
<<
" ----> "
;
std
::
cout
<<
"label: "
<<
labels
[
i
]
<<
" ----> "
;
m
[
"0"
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
argument
{
s
,
&
ptr
[
784
*
i
]});
m
[
"0"
]
=
migraph
x
::
gpu
::
to_gpu
(
migraph
x
::
argument
{
s
,
&
ptr
[
784
*
i
]});
auto
result
=
migraph
::
gpu
::
from_gpu
(
prog
.
eval
(
m
));
auto
result
=
migraph
x
::
gpu
::
from_gpu
(
prog
.
eval
(
m
));
std
::
vector
<
float
>
logits
;
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
...
...
src/onnx/onnx.cpp
View file @
d2549384
This diff is collapsed.
Click to expand it.
src/onnx/perf_onnx.cpp
View file @
d2549384
#include <migraph/onnx.hpp>
#include <migraph
x
/onnx.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph
x
/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph
x
/gpu/hip.hpp>
#include <migraph/generate.hpp>
#include <migraph
x
/generate.hpp>
#include <migraph/verify.hpp>
#include <migraph
x
/verify.hpp>
migraph
::
program
::
parameter_map
create_param_map
(
const
migraph
::
program
&
p
,
bool
gpu
=
true
)
migraph
x
::
program
::
parameter_map
create_param_map
(
const
migraph
x
::
program
&
p
,
bool
gpu
=
true
)
{
{
migraph
::
program
::
parameter_map
m
;
migraph
x
::
program
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
{
if
(
gpu
)
if
(
gpu
)
m
[
x
.
first
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
x
.
second
));
m
[
x
.
first
]
=
migraph
x
::
gpu
::
to_gpu
(
migraph
x
::
generate_argument
(
x
.
second
));
else
else
m
[
x
.
first
]
=
migraph
::
generate_argument
(
x
.
second
);
m
[
x
.
first
]
=
migraph
x
::
generate_argument
(
x
.
second
);
}
}
return
m
;
return
m
;
}
}
...
@@ -25,9 +25,9 @@ int main(int argc, char const* argv[])
...
@@ -25,9 +25,9 @@ int main(int argc, char const* argv[])
{
{
std
::
string
file
=
argv
[
1
];
std
::
string
file
=
argv
[
1
];
std
::
size_t
n
=
argc
>
2
?
std
::
stoul
(
argv
[
2
])
:
50
;
std
::
size_t
n
=
argc
>
2
?
std
::
stoul
(
argv
[
2
])
:
50
;
auto
p
=
migraph
::
parse_onnx
(
file
);
auto
p
=
migraph
x
::
parse_onnx
(
file
);
std
::
cout
<<
"Compiling ... "
<<
std
::
endl
;
std
::
cout
<<
"Compiling ... "
<<
std
::
endl
;
p
.
compile
(
migraph
::
gpu
::
target
{});
p
.
compile
(
migraph
x
::
gpu
::
target
{});
std
::
cout
<<
"Allocating params ... "
<<
std
::
endl
;
std
::
cout
<<
"Allocating params ... "
<<
std
::
endl
;
auto
m
=
create_param_map
(
p
);
auto
m
=
create_param_map
(
p
);
std
::
cout
<<
"Running performance report ... "
<<
std
::
endl
;
std
::
cout
<<
"Running performance report ... "
<<
std
::
endl
;
...
...
Prev
1
2
3
4
5
6
7
8
9
…
16
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