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
91523467
Commit
91523467
authored
Jun 21, 2022
by
Paul
Browse files
Format
parent
c4bba3cf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
30 deletions
+33
-30
src/driver/argument_parser.hpp
src/driver/argument_parser.hpp
+14
-17
src/driver/command.hpp
src/driver/command.hpp
+7
-2
src/driver/main.cpp
src/driver/main.cpp
+12
-11
No files found.
src/driver/argument_parser.hpp
View file @
91523467
...
...
@@ -257,11 +257,11 @@ struct argument_parser
});
}
template
<
class
F
>
template
<
class
F
>
argument
*
find_argument
(
F
f
)
{
auto
it
=
std
::
find_if
(
arguments
.
begin
(),
arguments
.
end
(),
f
);
if
(
it
==
arguments
.
end
())
if
(
it
==
arguments
.
end
())
return
nullptr
;
return
std
::
addressof
(
*
it
);
}
...
...
@@ -269,14 +269,15 @@ struct argument_parser
MIGRAPHX_DRIVER_STATIC
auto
show_help
(
const
std
::
string
&
msg
=
""
)
{
return
do_action
([
=
](
auto
&
self
)
{
argument
*
input_argument
=
self
.
find_argument
([](
const
auto
&
arg
)
{
return
arg
.
flags
.
empty
();
});
argument
*
input_argument
=
self
.
find_argument
([](
const
auto
&
arg
)
{
return
arg
.
flags
.
empty
();
});
std
::
cout
<<
color
::
fg_yellow
<<
"USAGE:"
<<
color
::
reset
<<
std
::
endl
;
std
::
cout
<<
" "
<<
self
.
exe_name
<<
" <options> "
;
if
(
input_argument
)
if
(
input_argument
)
std
::
cout
<<
input_argument
->
metavar
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
if
(
self
.
find_argument
([](
const
auto
&
arg
)
{
return
arg
.
nargs
==
0
;
}))
if
(
self
.
find_argument
([](
const
auto
&
arg
)
{
return
arg
.
nargs
==
0
;
}))
{
std
::
cout
<<
color
::
fg_yellow
<<
"FLAGS:"
<<
color
::
reset
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
...
...
@@ -310,7 +311,7 @@ struct argument_parser
}
std
::
cout
<<
std
::
endl
;
}
if
(
self
.
find_argument
([](
const
auto
&
arg
)
{
return
arg
.
nargs
!=
0
;
}))
if
(
self
.
find_argument
([](
const
auto
&
arg
)
{
return
arg
.
nargs
!=
0
;
}))
{
std
::
cout
<<
color
::
fg_yellow
<<
"OPTIONS:"
<<
color
::
reset
<<
std
::
endl
;
for
(
auto
&&
arg
:
self
.
arguments
)
...
...
@@ -376,7 +377,8 @@ struct argument_parser
};
}
bool
run_action
(
const
argument
&
arg
,
const
std
::
string
&
flag
,
const
std
::
vector
<
std
::
string
>&
inputs
)
bool
run_action
(
const
argument
&
arg
,
const
std
::
string
&
flag
,
const
std
::
vector
<
std
::
string
>&
inputs
)
{
std
::
string
msg
=
""
;
try
...
...
@@ -406,10 +408,11 @@ struct argument_parser
std
::
cout
<<
" "
<<
exe_name
<<
" "
;
show_usage
();
std
::
cout
<<
std
::
endl
;
if
(
find_argument
([](
const
auto
&
a
)
{
return
contains
(
a
.
flags
,
"--help"
);
}))
if
(
find_argument
([](
const
auto
&
a
)
{
return
contains
(
a
.
flags
,
"--help"
);
}))
{
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"For more information try '"
<<
color
::
fg_green
<<
"--help"
<<
color
::
reset
<<
"'"
<<
std
::
endl
;
std
::
cout
<<
"For more information try '"
<<
color
::
fg_green
<<
"--help"
<<
color
::
reset
<<
"'"
<<
std
::
endl
;
}
return
true
;
}
...
...
@@ -441,15 +444,9 @@ struct argument_parser
return
false
;
}
void
set_exe_name
(
const
std
::
string
&
s
)
{
exe_name
=
s
;
}
void
set_exe_name
(
const
std
::
string
&
s
)
{
exe_name
=
s
;
}
const
std
::
string
&
get_exe_name
()
const
{
return
exe_name
;
}
const
std
::
string
&
get_exe_name
()
const
{
return
exe_name
;
}
using
string_map
=
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
;
template
<
class
IsKeyword
>
...
...
src/driver/command.hpp
View file @
91523467
...
...
@@ -18,7 +18,10 @@ inline namespace MIGRAPHX_INLINE_NS {
inline
auto
&
get_commands
()
{
// NOLINTNEXTLINE
static
std
::
unordered_map
<
std
::
string
,
std
::
function
<
void
(
const
std
::
string
&
exe_name
,
std
::
vector
<
std
::
string
>
args
)
>>
m
;
static
std
::
unordered_map
<
std
::
string
,
std
::
function
<
void
(
const
std
::
string
&
exe_name
,
std
::
vector
<
std
::
string
>
args
)
>>
m
;
return
m
;
}
...
...
@@ -59,7 +62,9 @@ template <class T>
int
auto_register_command
()
{
auto
&
m
=
get_commands
();
m
[
command_name
<
T
>
()]
=
[](
const
std
::
string
&
exe_name
,
std
::
vector
<
std
::
string
>
args
)
{
run_command
<
T
>
(
exe_name
,
args
,
true
);
};
m
[
command_name
<
T
>
()]
=
[](
const
std
::
string
&
exe_name
,
std
::
vector
<
std
::
string
>
args
)
{
run_command
<
T
>
(
exe_name
,
args
,
true
);
};
return
0
;
}
...
...
src/driver/main.cpp
View file @
91523467
...
...
@@ -552,24 +552,25 @@ struct onnx : command<onnx>
struct
main_command
{
static
std
::
string
get_command_help
(
const
std
::
string
&
title
=
colorize
(
color
::
fg_yellow
,
"COMMANDS:"
))
static
std
::
string
get_command_help
(
const
std
::
string
&
title
=
colorize
(
color
::
fg_yellow
,
"COMMANDS:"
))
{
std
::
string
result
=
title
+
"
\n
"
;
std
::
vector
<
std
::
string
>
commands
(
get_commands
().
size
());
std
::
transform
(
get_commands
().
begin
(),
get_commands
().
end
(),
commands
.
begin
(),
[](
const
auto
&
p
)
{
return
colorize
(
color
::
fg_green
,
p
.
first
);
});
std
::
transform
(
get_commands
().
begin
(),
get_commands
().
end
(),
commands
.
begin
(),
[](
const
auto
&
p
)
{
return
colorize
(
color
::
fg_green
,
p
.
first
);
});
std
::
sort
(
commands
.
begin
(),
commands
.
end
());
return
std
::
accumulate
(
commands
.
begin
(),
commands
.
end
(),
result
,
[](
auto
r
,
auto
&&
s
)
{
return
r
+
" "
+
s
+
"
\n
"
;
});
return
std
::
accumulate
(
commands
.
begin
(),
commands
.
end
(),
result
,
[](
auto
r
,
auto
&&
s
)
{
return
r
+
" "
+
s
+
"
\n
"
;
});
}
void
parse
(
argument_parser
&
ap
)
{
std
::
string
version_str
=
"MIGraphX Version: "
+
std
::
to_string
(
MIGRAPHX_VERSION_MAJOR
)
+
"."
+
std
::
to_string
(
MIGRAPHX_VERSION_MINOR
);
ap
(
unused
,
{},
ap
.
metavar
(
"<command>"
),
ap
.
set_value
(
true
));
ap
(
unused
,
{},
ap
.
metavar
(
"<command>"
),
ap
.
set_value
(
true
));
ap
(
nullptr
,
{
"-h"
,
"--help"
},
ap
.
help
(
"Show help"
),
ap
.
show_help
(
get_command_help
()));
ap
(
nullptr
,
{
"-v"
,
"--version"
},
...
...
@@ -583,9 +584,9 @@ struct main_command
bool
unused
=
false
;
void
run
()
{
{
std
::
cout
<<
color
::
fg_red
<<
color
::
bold
<<
"error: "
<<
color
::
reset
;
std
::
cout
<<
get_command_help
(
"missing command:"
)
<<
std
::
endl
;
std
::
cout
<<
get_command_help
(
"missing command:"
)
<<
std
::
endl
;
}
};
...
...
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