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
74c98abd
Commit
74c98abd
authored
Nov 30, 2023
by
Paul
Browse files
Short circuit some of the runs
parent
332dc42e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
28 deletions
+68
-28
src/onnx/parse_gather_elements.cpp
src/onnx/parse_gather_elements.cpp
+1
-1
src/program.cpp
src/program.cpp
+1
-4
src/reduce_dims.cpp
src/reduce_dims.cpp
+1
-1
src/rewrite_rnn.cpp
src/rewrite_rnn.cpp
+1
-1
src/simplify_reshapes.cpp
src/simplify_reshapes.cpp
+1
-1
src/targets/gpu/device/include/migraphx/gpu/device/multi_index.hpp
...ts/gpu/device/include/migraphx/gpu/device/multi_index.hpp
+1
-0
src/targets/gpu/loop.cpp
src/targets/gpu/loop.cpp
+1
-2
tools/cppcheck/migraphx.py
tools/cppcheck/migraphx.py
+61
-18
No files found.
src/onnx/parse_gather_elements.cpp
View file @
74c98abd
...
...
@@ -58,7 +58,7 @@ struct parse_gather_elements : op_parser<parse_gather_elements>
MIGRAPHX_THROW
(
"PARSE_GATHER_ELEMENTS: input data and index must have the same rank!"
);
}
int
n_rank
=
static_cast
<
int
>
(
data_s
.
lens
().
size
()
)
;
int
n_rank
=
data_s
.
lens
().
size
();
int
tuned_axis
=
tune_axis
(
n_rank
,
axis
,
opd
.
op_name
);
auto
axis_stride
=
data_s
.
strides
()[
tuned_axis
];
...
...
src/program.cpp
View file @
74c98abd
...
...
@@ -507,10 +507,7 @@ std::vector<argument> generic_eval(const module* mod,
}));
}
assert
(
results
.
find
(
ins
)
!=
results
.
end
());
if
(
not
ins
->
get_shape
().
any_of_dynamic
())
{
assert
(
results
.
at
(
ins
).
get_shape
()
==
ins
->
get_shape
());
}
assert
(
ins
->
get_shape
().
any_of_dynamic
()
or
results
.
at
(
ins
).
get_shape
()
==
ins
->
get_shape
());
}
return
{
results
.
at
(
std
::
prev
(
mod
->
end
()))};
}
...
...
src/reduce_dims.cpp
View file @
74c98abd
...
...
@@ -76,7 +76,7 @@ void reduce_dim1(std::vector<shape>& shapes)
std
::
size_t
reduce_dim_all
(
std
::
vector
<
shape
>&
shapes
,
std
::
size_t
n
)
{
while
(
reduce_dim
(
shapes
,
n
)
and
n
<
shapes
.
size
())
{}
while
(
reduce_dim
(
shapes
,
n
)
and
n
<
shapes
.
size
())
{
(
void
)
n
;
}
return
n
+
1
;
}
void
reduce_dim_all
(
std
::
vector
<
shape
>&
shapes
)
...
...
src/rewrite_rnn.cpp
View file @
74c98abd
...
...
@@ -273,7 +273,7 @@ std::vector<instruction_ref> rewrite_rnn::vanilla_rnn_cell(bool is_forward,
instruction_ref
bb
{};
if
(
bias
!=
m
.
end
())
{
long
hs
=
static_cast
<
long
>
(
r
->
get_shape
().
lens
()[
2
]
)
;
long
hs
=
r
->
get_shape
().
lens
()[
2
];
auto
sbias
=
m
.
insert_instruction
(
ins
,
make_op
(
"squeeze"
,
{{
"axes"
,
{
0
}}}),
bias
);
auto
wb
=
m
.
insert_instruction
(
ins
,
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
hs
}}}),
sbias
);
...
...
src/simplify_reshapes.cpp
View file @
74c98abd
...
...
@@ -322,7 +322,7 @@ struct find_concat_transpose
}
// axis could be a negative value
int64_t
n_dim
=
static_cast
<
int64_t
>
(
s
.
lens
().
size
()
)
;
int64_t
n_dim
=
s
.
lens
().
size
();
op
.
axis
=
tune_axis
(
n_dim
,
op
.
axis
,
op
.
name
());
auto
ipermutation
=
invert_permutation
(
permutation
);
...
...
src/targets/gpu/device/include/migraphx/gpu/device/multi_index.hpp
View file @
74c98abd
...
...
@@ -110,6 +110,7 @@ inline auto mi_nlocal(const hip_shape<N>& s, index_int local)
//
// assert(std::any_of(nlocal_multi.begin(), nlocal_multi.end(), [](auto x){return x>0;}));
// cppcheck-suppress migraphx-RedundantLocalVariable
return
nlocal_multi
;
}
...
...
src/targets/gpu/loop.cpp
View file @
74c98abd
...
...
@@ -83,8 +83,7 @@ struct gpu_loop
auto
loc
=
name
.
find
(
out_prefix
);
if
(
loc
!=
std
::
string
::
npos
)
{
int
index
=
std
::
stoi
(
name
.
substr
(
loc
+
out_prefix
.
size
()));
return
index
;
return
std
::
stoi
(
name
.
substr
(
loc
+
out_prefix
.
size
()));
}
return
-
1
;
...
...
tools/cppcheck/migraphx.py
View file @
74c98abd
...
...
@@ -37,10 +37,23 @@ def getVariableDecl(var):
end
=
end
.
next
return
var
.
typeStartToken
.
forward
(
end
)
def
isFunctionCall
(
token
):
if
not
token
:
return
False
if
not
token
.
isName
:
return
False
if
not
token
.
next
:
return
False
if
not
token
.
next
.
str
==
'('
:
return
False
return
True
@
cppcheck
.
checker
def
AvoidBranchingStatementAsLastInLoop
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
not
token
.
str
in
[
'for'
,
'while'
]:
continue
end
=
match
(
token
,
"for|while (*) {*}"
).
end
if
not
end
:
continue
...
...
@@ -67,6 +80,8 @@ def AvoidBranchingStatementAsLastInLoop(cfg, data):
@
cppcheck
.
checker
def
ConditionalAssert
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'if'
:
continue
if
not
match
(
token
,
"if (*) { assert (*) ; }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
...
...
@@ -76,6 +91,8 @@ def ConditionalAssert(cfg, data):
@
cppcheck
.
checker
def
EmptyCatchStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'catch'
:
continue
if
not
match
(
token
,
"catch (*) { }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"An empty catch statement."
)
...
...
@@ -84,7 +101,9 @@ def EmptyCatchStatement(cfg, data):
@
cppcheck
.
checker
def
EmptyDoWhileStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
not
match
(
token
,
"do { } while ("
):
if
token
.
str
!=
'do'
:
continue
if
not
simpleMatch
(
token
,
"do { } while ("
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty do-while."
)
...
...
@@ -92,7 +111,9 @@ def EmptyDoWhileStatement(cfg, data):
@
cppcheck
.
checker
def
EmptyElseBlock
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
not
match
(
token
,
"else { }"
):
if
token
.
str
!=
'else'
:
continue
if
not
simpleMatch
(
token
,
"else { }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty else statement can be safely removed."
)
...
...
@@ -101,6 +122,8 @@ def EmptyElseBlock(cfg, data):
@
cppcheck
.
checker
def
EmptyForStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'for'
:
continue
if
not
match
(
token
,
"for (*) { }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty for statement."
)
...
...
@@ -109,6 +132,8 @@ def EmptyForStatement(cfg, data):
@
cppcheck
.
checker
def
EmptyIfStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'if'
:
continue
if
not
match
(
token
,
"if (*) { }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty if statement."
)
...
...
@@ -117,6 +142,8 @@ def EmptyIfStatement(cfg, data):
@
cppcheck
.
checker
def
EmptySwitchStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'switch'
:
continue
if
not
match
(
token
,
"switch (*) { }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty switch statement."
)
...
...
@@ -125,6 +152,8 @@ def EmptySwitchStatement(cfg, data):
@
cppcheck
.
checker
def
EmptyWhileStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'while'
:
continue
if
not
match
(
token
,
"while (*) { }"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Empty while statement."
)
...
...
@@ -133,6 +162,8 @@ def EmptyWhileStatement(cfg, data):
@
cppcheck
.
checker
def
ForLoopShouldBeWhileLoop
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'for'
:
continue
if
not
match
(
token
,
"for ( ; !!;"
):
continue
# Skip empty for loops
...
...
@@ -148,7 +179,7 @@ def ForLoopShouldBeWhileLoop(cfg, data):
@
cppcheck
.
checker
def
GotoStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
not
match
(
token
,
"
goto
"
)
:
if
token
.
str
!=
'
goto
'
:
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Goto considered harmful."
)
...
...
@@ -169,6 +200,8 @@ def GotoStatement(cfg, data):
@
cppcheck
.
checker
def
LambdaAttribute
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
']'
:
continue
if
not
match
(
token
,
"] __device__|__host__ {|{}}"
):
continue
cppcheck
.
reportError
(
...
...
@@ -179,10 +212,10 @@ def LambdaAttribute(cfg, data):
@
cppcheck
.
checker
def
MultipleUnaryOperator
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
not
match
(
token
,
"+|-|~|!"
):
continue
if
not
token
.
isUnaryOp
(
token
.
str
):
continue
if
not
token
.
str
in
[
'+'
,
'-'
,
'~'
,
'!'
]:
continue
if
not
match
(
token
.
astOperand1
,
"+|-|~|!"
):
continue
if
not
token
.
astOperand1
.
isUnaryOp
(
token
.
astOperand1
.
str
):
...
...
@@ -194,6 +227,8 @@ def MultipleUnaryOperator(cfg, data):
@
cppcheck
.
checker
def
MutableVariable
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'mutable'
:
continue
if
not
match
(
token
,
"mutable %var%"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
...
...
@@ -220,20 +255,19 @@ def RedundantCast(cfg, data):
continue
if
m
.
decl
.
varId
!=
m
.
assign
.
varId
:
continue
if
not
m
atch
(
token
.
previous
,
"auto"
):
if
not
simpleM
atch
(
token
.
previous
,
"auto"
):
if
not
isTokensEqual
(
getVariableDecl
(
m
.
decl
.
variable
),
getInnerLink
(
m
.
cast
),
skip
=
'const|volatile|&|&&|*'
):
continue
if
not
match
(
token
,
"%var%@decl ; %var%@assign = static_cast <*>@cast (*) ;"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Static cast is redundant."
)
@
cppcheck
.
checker
def
RedundantConditionalOperator
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'?'
:
continue
if
not
match
(
token
,
"? true|false : true|false"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
...
...
@@ -243,6 +277,8 @@ def RedundantConditionalOperator(cfg, data):
@
cppcheck
.
checker
def
RedundantIfStatement
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'if'
:
continue
if
not
match
(
token
,
"if (*) { return true|false ; } else { return true|false ; }"
):
...
...
@@ -286,6 +322,8 @@ def RedundantLocalVariable(cfg, data):
@
cppcheck
.
checker
def
UnnecessaryEmptyCondition
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'if'
:
continue
m
=
match
(
token
,
"if (*)@if_cond { for (*)@for_cond {*} }"
)
if
not
m
:
continue
...
...
@@ -310,18 +348,18 @@ def UnnecessaryEmptyCondition(cfg, data):
@
cppcheck
.
checker
def
UseDeviceLaunch
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
not
m
atch
(
token
,
"hipLaunchKernelGGL ("
):
if
not
simpleM
atch
(
token
,
"hipLaunchKernelGGL ("
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Use device::launch instead."
)
@
cppcheck
.
checker
def
UseManagePointer
(
cfg
,
data
):
functions
=
{
"fclose"
,
"free"
,
"hipFree"
,
"hipHostFree"
,
"hipFreeArray"
,
"hipMemFree"
,
"hipStreamDestroy"
,
"hipEventDestroy"
,
"hipArrayDestroy"
,
"hipCtxDestroy"
,
"hipDestroyTextureObject"
,
"hipDestroySurfaceObject"
,
"miirDestroyHandle"
}
for
token
in
cfg
.
tokenlist
:
if
not
match
(
token
,
"fclose|free|hipFree|hipHostFree|hipFreeArray|hipMemFree|hipStreamDestroy|hipEventDestroy|hipArrayDestroy|hipCtxDestroy|hipDestroyTextureObject|hipDestroySurfaceObject|miirDestroyHandle ("
):
if
not
isFunctionCall
(
token
):
continue
if
not
token
.
str
in
functions
:
continue
cppcheck
.
reportError
(
token
,
"style"
,
"Use manage pointer for resource management."
)
...
...
@@ -330,6 +368,8 @@ def UseManagePointer(cfg, data):
@
cppcheck
.
checker
def
UseSmartPointer
(
cfg
,
data
):
for
token
in
cfg
.
tokenlist
:
if
token
.
str
!=
'new'
:
continue
if
not
match
(
token
,
"new %name%"
):
continue
cppcheck
.
reportError
(
token
,
"style"
,
...
...
@@ -338,13 +378,16 @@ def UseSmartPointer(cfg, data):
@
cppcheck
.
checker
def
useStlAlgorithms
(
cfg
,
data
):
copy_functions
=
{
"memcpy"
,
"strcpy"
,
"strncpy"
,
"strcat"
,
"strncat"
}
for
token
in
cfg
.
tokenlist
:
if
match
(
token
,
"memcpy|strcpy|strncpy|strcat|strncat ("
):
if
not
isFunctionCall
(
token
):
continue
if
token
.
str
in
copy_functions
:
cppcheck
.
reportError
(
token
,
"style"
,
"Use std::copy instead."
)
elif
match
(
token
,
"
memset
("
)
:
elif
token
.
str
==
'
memset
'
:
cppcheck
.
reportError
(
token
,
"style"
,
"Use std::fill instead."
)
elif
match
(
token
,
"
memcmp
("
)
:
elif
token
.
str
==
'
memcmp
'
:
cppcheck
.
reportError
(
token
,
"style"
,
"Use std::equal_range instead."
)
elif
match
(
token
,
"
memchr
("
)
:
elif
token
.
str
==
'
memchr
'
:
cppcheck
.
reportError
(
token
,
"style"
,
"Use std::find instead."
)
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