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
de62b8ac
Commit
de62b8ac
authored
Jun 05, 2019
by
Paul
Browse files
Formatting
parent
c20d0fc2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
42 deletions
+34
-42
src/driver/argument_parser.hpp
src/driver/argument_parser.hpp
+17
-22
src/driver/command.hpp
src/driver/command.hpp
+5
-7
src/driver/main.cpp
src/driver/main.cpp
+8
-10
src/include/migraphx/requires.hpp
src/include/migraphx/requires.hpp
+4
-3
No files found.
src/driver/argument_parser.hpp
View file @
de62b8ac
...
@@ -55,21 +55,21 @@ struct argument_parser
...
@@ -55,21 +55,21 @@ struct argument_parser
{
{
std
::
vector
<
std
::
string
>
flags
;
std
::
vector
<
std
::
string
>
flags
;
std
::
function
<
bool
(
argument_parser
&
,
const
std
::
vector
<
std
::
string
>&
)
>
action
{};
std
::
function
<
bool
(
argument_parser
&
,
const
std
::
vector
<
std
::
string
>&
)
>
action
{};
std
::
string
type
=
""
;
std
::
string
type
=
""
;
std
::
string
help
=
""
;
std
::
string
help
=
""
;
std
::
string
metavar
=
""
;
std
::
string
metavar
=
""
;
unsigned
nargs
=
1
;
unsigned
nargs
=
1
;
};
};
template
<
class
T
,
class
...
Fs
>
template
<
class
T
,
class
...
Fs
>
void
add
(
T
&
x
,
std
::
vector
<
std
::
string
>
flags
,
Fs
...
fs
)
void
add
(
T
&
x
,
std
::
vector
<
std
::
string
>
flags
,
Fs
...
fs
)
{
{
arguments
.
push_back
({
flags
,
[
&
](
auto
&&
,
const
std
::
vector
<
std
::
string
>&
params
)
{
arguments
.
push_back
({
flags
,
[
&
](
auto
&&
,
const
std
::
vector
<
std
::
string
>&
params
)
{
if
(
params
.
empty
())
if
(
params
.
empty
())
throw
std
::
runtime_error
(
"Flag with no value."
);
throw
std
::
runtime_error
(
"Flag with no value."
);
x
=
value_parser
<
T
>::
apply
(
params
.
back
());
x
=
value_parser
<
T
>::
apply
(
params
.
back
());
return
false
;
return
false
;
}});
}});
argument
&
arg
=
arguments
.
back
();
argument
&
arg
=
arguments
.
back
();
arg
.
type
=
migraphx
::
get_type_name
<
T
>
();
arg
.
type
=
migraphx
::
get_type_name
<
T
>
();
...
@@ -89,9 +89,7 @@ struct argument_parser
...
@@ -89,9 +89,7 @@ struct argument_parser
static
auto
nargs
(
unsigned
n
=
1
)
static
auto
nargs
(
unsigned
n
=
1
)
{
{
return
[
=
](
auto
&&
,
auto
&
arg
)
{
return
[
=
](
auto
&&
,
auto
&
arg
)
{
arg
.
nargs
=
n
;
};
arg
.
nargs
=
n
;
};
}
}
template
<
class
F
>
template
<
class
F
>
...
@@ -109,7 +107,7 @@ struct argument_parser
...
@@ -109,7 +107,7 @@ struct argument_parser
static
auto
do_action
(
F
f
)
static
auto
do_action
(
F
f
)
{
{
return
[
=
](
auto
&
,
auto
&
arg
)
{
return
[
=
](
auto
&
,
auto
&
arg
)
{
arg
.
nargs
=
0
;
arg
.
nargs
=
0
;
arg
.
action
=
[
&
,
f
](
auto
&
self
,
const
std
::
vector
<
std
::
string
>&
)
{
arg
.
action
=
[
&
,
f
](
auto
&
self
,
const
std
::
vector
<
std
::
string
>&
)
{
f
(
self
);
f
(
self
);
return
true
;
return
true
;
...
@@ -135,7 +133,7 @@ struct argument_parser
...
@@ -135,7 +133,7 @@ struct argument_parser
{
{
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
string
prefix
=
" "
;
std
::
string
prefix
=
" "
;
if
(
arg
.
flags
.
empty
())
if
(
arg
.
flags
.
empty
())
{
{
std
::
cout
<<
prefix
;
std
::
cout
<<
prefix
;
std
::
cout
<<
arg
.
metavar
;
std
::
cout
<<
arg
.
metavar
;
...
@@ -185,16 +183,14 @@ struct argument_parser
...
@@ -185,16 +183,14 @@ struct argument_parser
std
::
unordered_map
<
std
::
string
,
unsigned
>
keywords
;
std
::
unordered_map
<
std
::
string
,
unsigned
>
keywords
;
for
(
auto
&&
arg
:
arguments
)
for
(
auto
&&
arg
:
arguments
)
{
{
for
(
auto
&&
flag
:
arg
.
flags
)
for
(
auto
&&
flag
:
arg
.
flags
)
keywords
[
flag
]
=
arg
.
nargs
+
1
;
keywords
[
flag
]
=
arg
.
nargs
+
1
;
}
}
auto
arg_map
=
generic_parse
(
args
,
[
&
](
std
::
string
x
)
{
auto
arg_map
=
generic_parse
(
args
,
[
&
](
std
::
string
x
)
{
return
keywords
[
x
];
});
return
keywords
[
x
];
});
for
(
auto
&&
arg
:
arguments
)
for
(
auto
&&
arg
:
arguments
)
{
{
auto
flags
=
arg
.
flags
;
auto
flags
=
arg
.
flags
;
if
(
flags
.
empty
())
if
(
flags
.
empty
())
flags
=
{
""
};
flags
=
{
""
};
for
(
auto
&&
flag
:
arg
.
flags
)
for
(
auto
&&
flag
:
arg
.
flags
)
{
{
...
@@ -223,18 +219,17 @@ struct argument_parser
...
@@ -223,18 +219,17 @@ struct argument_parser
{
{
flag
=
x
;
flag
=
x
;
result
[
flag
];
// Ensure the flag exists
result
[
flag
];
// Ensure the flag exists
if
(
k
==
1
)
if
(
k
==
1
)
flag
=
""
;
flag
=
""
;
else
if
(
k
==
2
)
else
if
(
k
==
2
)
clear
=
true
;
clear
=
true
;
else
else
clear
=
false
;
clear
=
false
;
}
}
else
else
{
{
result
[
flag
].
push_back
(
x
);
result
[
flag
].
push_back
(
x
);
if
(
clear
)
if
(
clear
)
flag
=
""
;
flag
=
""
;
clear
=
false
;
clear
=
false
;
}
}
...
...
src/driver/command.hpp
View file @
de62b8ac
...
@@ -26,15 +26,15 @@ std::string command_name()
...
@@ -26,15 +26,15 @@ std::string command_name()
return
name
.
substr
(
name
.
rfind
(
"::"
)
+
2
);
return
name
.
substr
(
name
.
rfind
(
"::"
)
+
2
);
}
}
template
<
class
T
>
template
<
class
T
>
void
run_command
(
std
::
vector
<
std
::
string
>
args
,
bool
add_help
=
false
)
void
run_command
(
std
::
vector
<
std
::
string
>
args
,
bool
add_help
=
false
)
{
{
T
x
;
T
x
;
argument_parser
ap
;
argument_parser
ap
;
if
(
add_help
)
if
(
add_help
)
ap
.
add
(
nullptr
,
{
"-h"
,
"--help"
},
ap
.
help
(
"Show help"
),
ap
.
show_help
());
ap
.
add
(
nullptr
,
{
"-h"
,
"--help"
},
ap
.
help
(
"Show help"
),
ap
.
show_help
());
x
.
parse
(
ap
);
x
.
parse
(
ap
);
if
(
ap
.
parse
(
args
))
if
(
ap
.
parse
(
args
))
return
;
return
;
x
.
run
();
x
.
run
();
}
}
...
@@ -43,9 +43,7 @@ template <class T>
...
@@ -43,9 +43,7 @@ template <class T>
int
auto_register_command
()
int
auto_register_command
()
{
{
auto
&
m
=
get_commands
();
auto
&
m
=
get_commands
();
m
[
command_name
<
T
>
()]
=
[](
std
::
vector
<
std
::
string
>
args
)
{
m
[
command_name
<
T
>
()]
=
[](
std
::
vector
<
std
::
string
>
args
)
{
run_command
<
T
>
(
args
,
true
);
};
run_command
<
T
>
(
args
,
true
);
};
return
0
;
return
0
;
}
}
...
...
src/driver/main.cpp
View file @
de62b8ac
...
@@ -21,22 +21,23 @@ struct loader
...
@@ -21,22 +21,23 @@ struct loader
ap
.
add
(
type
,
{
"--onnx"
},
ap
.
help
(
"Load as onnx"
),
ap
.
set_value
(
"onnx"
));
ap
.
add
(
type
,
{
"--onnx"
},
ap
.
help
(
"Load as onnx"
),
ap
.
set_value
(
"onnx"
));
ap
.
add
(
type
,
{
"--tf"
},
ap
.
help
(
"Load as tensorflow"
),
ap
.
set_value
(
"tf"
));
ap
.
add
(
type
,
{
"--tf"
},
ap
.
help
(
"Load as tensorflow"
),
ap
.
set_value
(
"tf"
));
ap
.
add
(
is_nhwc
,
{
"--nhwc"
},
ap
.
help
(
"Treat tensorflow format as nhwc"
),
ap
.
set_value
(
true
));
ap
.
add
(
is_nhwc
,
{
"--nhwc"
},
ap
.
help
(
"Treat tensorflow format as nhwc"
),
ap
.
set_value
(
true
));
ap
.
add
(
is_nhwc
,
{
"--nchw"
},
ap
.
help
(
"Treat tensorflow format as nchw"
),
ap
.
set_value
(
false
));
ap
.
add
(
is_nhwc
,
{
"--nchw"
},
ap
.
help
(
"Treat tensorflow format as nchw"
),
ap
.
set_value
(
false
));
}
}
program
load
()
program
load
()
{
{
program
p
;
program
p
;
if
(
type
.
empty
())
if
(
type
.
empty
())
{
{
if
(
ends_with
(
file
,
".onnx"
))
if
(
ends_with
(
file
,
".onnx"
))
type
=
"onnx"
;
type
=
"onnx"
;
else
else
type
=
"tf"
;
type
=
"tf"
;
}
}
if
(
type
==
"onnx"
)
if
(
type
==
"onnx"
)
p
=
parse_onnx
(
file
);
p
=
parse_onnx
(
file
);
else
if
(
type
==
"tf"
)
else
if
(
type
==
"tf"
)
p
=
parse_tf
(
file
,
is_nhwc
);
p
=
parse_tf
(
file
,
is_nhwc
);
return
p
;
return
p
;
}
}
...
@@ -45,10 +46,7 @@ struct loader
...
@@ -45,10 +46,7 @@ struct loader
struct
read
:
command
<
read
>
struct
read
:
command
<
read
>
{
{
loader
l
;
loader
l
;
void
parse
(
argument_parser
&
ap
)
void
parse
(
argument_parser
&
ap
)
{
l
.
parse
(
ap
);
}
{
l
.
parse
(
ap
);
}
void
run
()
void
run
()
{
{
...
...
src/include/migraphx/requires.hpp
View file @
de62b8ac
...
@@ -23,9 +23,10 @@ using bool_c = std::integral_constant<bool, B>;
...
@@ -23,9 +23,10 @@ using bool_c = std::integral_constant<bool, B>;
#ifdef CPPCHECK
#ifdef CPPCHECK
#define MIGRAPHX_REQUIRES(...) class = void
#define MIGRAPHX_REQUIRES(...) class = void
#else
#else
#define MIGRAPHX_REQUIRES(...) \
#define MIGRAPHX_REQUIRES(...) \
bool MIGRAPHX_REQUIRES_VAR()=true, \
bool MIGRAPHX_REQUIRES_VAR() = true, \
typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() && (migraphx::and_<__VA_ARGS__>{})), int>::type = 0
typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() && (migraphx::and_<__VA_ARGS__>{})), \
int>::type = 0
#endif
#endif
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace MIGRAPHX_INLINE_NS
...
...
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