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
aeb9f78c
Unverified
Commit
aeb9f78c
authored
Aug 04, 2023
by
Lakhinder Walia
Committed by
GitHub
Aug 04, 2023
Browse files
Bug in driver argument parser. Fix Levenshtein_distance. (#2020)
parent
e46a6a52
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
src/driver/argument_parser.hpp
src/driver/argument_parser.hpp
+14
-3
src/driver/main.cpp
src/driver/main.cpp
+2
-1
src/include/migraphx/algorithm.hpp
src/include/migraphx/algorithm.hpp
+37
-0
No files found.
src/driver/argument_parser.hpp
View file @
aeb9f78c
...
...
@@ -342,7 +342,19 @@ struct argument_parser
if
(
params
.
empty
())
throw
std
::
runtime_error
(
"No argument passed."
);
if
(
not
fs
::
exists
(
params
.
back
()))
throw
std
::
runtime_error
(
"Path does not exists: "
+
params
.
back
());
throw
std
::
runtime_error
(
"Path does not exist: "
+
params
.
back
());
});
}
MIGRAPHX_DRIVER_STATIC
auto
matches
(
const
std
::
unordered_set
<
std
::
string
>&
names
)
{
return
validate
([
=
](
auto
&
,
auto
&
,
auto
&
params
)
{
for
(
const
auto
&
p
:
params
)
{
if
(
names
.
count
(
p
)
==
0
)
throw
std
::
runtime_error
(
"Invalid argument: "
+
p
+
". Valid arguments are {"
+
to_string_range
(
names
)
+
"}"
);
}
});
}
...
...
@@ -570,8 +582,7 @@ struct argument_parser
continue
;
if
(
flag
[
0
]
!=
'-'
)
continue
;
auto
d
=
levenshtein_distance
(
flag
.
begin
(),
flag
.
end
(),
input
.
begin
(),
input
.
end
());
std
::
ptrdiff_t
d
=
levenshtein_distance
(
flag
,
input
);
if
(
d
<
result
.
distance
)
result
=
result_t
{
&
arg
,
flag
,
input
,
d
};
}
...
...
src/driver/main.cpp
View file @
aeb9f78c
...
...
@@ -82,6 +82,7 @@ struct loader
{
"--model"
},
ap
.
help
(
"Load model"
),
ap
.
type
(
"resnet50|inceptionv3|alexnet"
),
ap
.
matches
({
"resnet50"
,
"inceptionv3"
,
"alexnet"
}),
ap
.
group
(
"input"
));
ap
(
file_type
,
{
"--onnx"
},
ap
.
help
(
"Load as onnx"
),
ap
.
set_value
(
"onnx"
));
ap
(
file_type
,
{
"--tf"
},
ap
.
help
(
"Load as tensorflow"
),
ap
.
set_value
(
"tf"
));
...
...
@@ -769,7 +770,7 @@ struct main_command
{
std
::
cout
<<
"'"
<<
color
::
fg_yellow
<<
wrong_commands
.
front
()
<<
color
::
reset
<<
"' is not a valid command."
<<
std
::
endl
;
std
::
cout
<<
get_command_help
(
"Available commands:"
)
<<
std
::
endl
;
std
::
cout
<<
get_command_help
(
"Available commands:"
);
}
else
{
...
...
src/include/migraphx/algorithm.hpp
View file @
aeb9f78c
...
...
@@ -90,6 +90,43 @@ levenshtein_distance(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterat
return
std
::
ptrdiff_t
{
1
}
+
std
::
min
({
x1
,
x2
,
x3
});
}
inline
size_t
levenshtein_distance
(
const
std
::
string
&
s1
,
const
std
::
string
&
s2
)
{
const
size_t
l1
=
s1
.
length
();
const
size_t
l2
=
s2
.
length
();
if
(
l1
<
l2
)
levenshtein_distance
(
s2
,
s1
);
std
::
vector
<
size_t
>
d
(
l2
+
1
);
for
(
size_t
j
=
1
;
j
<=
l2
;
j
++
)
d
[
j
]
=
j
;
for
(
size_t
i
=
1
;
i
<=
l1
;
i
++
)
{
size_t
prev_cost
=
d
[
0
];
d
[
0
]
=
i
;
for
(
size_t
j
=
1
;
j
<=
l2
;
j
++
)
{
if
(
s1
[
i
-
1
]
==
s2
[
j
-
1
])
{
d
[
j
]
=
prev_cost
;
}
else
{
size_t
cost_insert_or_delete
=
std
::
min
(
d
[
j
-
1
],
d
[
j
]);
size_t
cost_substitute
=
prev_cost
;
prev_cost
=
d
[
j
];
d
[
j
]
=
std
::
min
(
cost_substitute
,
cost_insert_or_delete
)
+
1
;
}
}
}
return
d
[
l2
];
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
...
...
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