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
e637b5aa
"...text-generation-inference-dcu.git" did not exist on "366dfe8247b1978f9a1cd4aee5fcf91bde836372"
Commit
e637b5aa
authored
Aug 29, 2018
by
Paul
Browse files
Add an option to verify each instruction
parent
d2778c9e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
12 deletions
+75
-12
src/onnx/verify_onnx.cpp
src/onnx/verify_onnx.cpp
+72
-10
src/program.cpp
src/program.cpp
+1
-0
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+2
-2
No files found.
src/onnx/verify_onnx.cpp
View file @
e637b5aa
...
@@ -6,10 +6,18 @@
...
@@ -6,10 +6,18 @@
#include <migraph/gpu/hip.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/generate.hpp>
#include <migraph/generate.hpp>
#include <migraph/verify_args.hpp>
#include <migraph/verify_args.hpp>
#include <migraph/instruction.hpp>
migraph
::
argument
run_cpu
(
const
std
::
string
&
file
)
template
<
class
T
>
auto
get_hash
(
const
T
&
x
)
{
{
auto
p
=
migraph
::
parse_onnx
(
file
);
return
std
::
hash
<
T
>
{}(
x
);
}
template
<
class
F
>
migraph
::
argument
run_cpu
(
F
f
)
{
auto
p
=
f
();
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
migraph
::
program
::
parameter_map
m
;
migraph
::
program
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
...
@@ -21,31 +29,85 @@ migraph::argument run_cpu(const std::string& file)
...
@@ -21,31 +29,85 @@ migraph::argument run_cpu(const std::string& file)
return
out
;
return
out
;
}
}
migraph
::
argument
run_gpu
(
const
std
::
string
&
file
)
template
<
class
F
>
migraph
::
argument
run_gpu
(
F
f
)
{
{
auto
p
=
migraph
::
parse_onnx
(
file
);
auto
p
=
f
(
);
p
.
compile
(
migraph
::
gpu
::
target
{});
p
.
compile
(
migraph
::
gpu
::
target
{});
migraph
::
program
::
parameter_map
m
;
migraph
::
program
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
{
m
[
x
.
first
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
x
.
second
));
m
[
x
.
first
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
x
.
second
,
get_hash
(
x
.
first
)
));
}
}
auto
out
=
migraph
::
gpu
::
from_gpu
(
p
.
eval
(
m
));
auto
out
=
migraph
::
gpu
::
from_gpu
(
p
.
eval
(
m
));
std
::
cout
<<
p
<<
std
::
endl
;
std
::
cout
<<
p
<<
std
::
endl
;
return
migraph
::
gpu
::
from_gpu
(
out
);
return
migraph
::
gpu
::
from_gpu
(
out
);
}
}
template
<
class
F
>
void
verify_program
(
const
std
::
string
&
name
,
F
f
,
double
tolerance
=
100
)
{
auto
x
=
run_cpu
(
f
);
auto
y
=
run_gpu
(
f
);
migraph
::
verify_args
(
name
,
x
,
y
,
tolerance
);
}
void
verify_instructions
(
const
migraph
::
program
&
prog
,
double
tolerance
=
100
)
{
for
(
auto
&&
ins
:
prog
)
{
if
(
ins
.
op
.
name
().
front
()
==
'@'
)
continue
;
if
(
ins
.
op
.
name
()
==
"broadcast"
)
continue
;
if
(
ins
.
op
.
name
()
==
"transpose"
)
continue
;
if
(
ins
.
op
.
name
()
==
"reshape"
)
continue
;
auto
create_program
=
[
&
]
{
migraph
::
program
p
;
std
::
vector
<
migraph
::
instruction_ref
>
inputs
;
for
(
auto
&&
arg
:
ins
.
arguments
)
{
if
(
arg
->
op
.
name
()
==
"@literal"
)
inputs
.
push_back
(
p
.
add_literal
(
arg
->
lit
));
else
inputs
.
push_back
(
p
.
add_parameter
(
std
::
to_string
(
inputs
.
size
()),
arg
->
get_shape
()));
}
p
.
add_instruction
(
ins
.
op
,
inputs
);
return
p
;
};
try
{
std
::
cout
<<
"Verify: "
<<
ins
.
op
.
name
()
<<
std
::
endl
;
std
::
cout
<<
create_program
()
<<
std
::
endl
;
verify_program
(
ins
.
op
.
name
(),
create_program
,
tolerance
);
}
catch
(...)
{
std
::
cout
<<
"Instruction "
<<
ins
.
op
.
name
()
<<
" threw an exception."
<<
std
::
endl
;
throw
;
}
}
}
int
main
(
int
argc
,
char
const
*
argv
[])
int
main
(
int
argc
,
char
const
*
argv
[])
{
{
if
(
argc
>
1
)
std
::
vector
<
std
::
string
>
args
(
argv
+
1
,
argv
+
argc
);
if
(
not
args
.
empty
())
{
{
std
::
string
file
=
arg
v
[
1
]
;
std
::
string
file
=
arg
s
.
front
()
;
auto
p
=
migraph
::
parse_onnx
(
file
);
auto
p
=
migraph
::
parse_onnx
(
file
);
std
::
cout
<<
p
<<
std
::
endl
;
std
::
cout
<<
p
<<
std
::
endl
;
auto
x
=
run_cpu
(
file
);
if
(
std
::
any_of
(
args
.
begin
(),
args
.
end
(),
[](
const
auto
&
s
)
{
return
s
==
"-i"
;
}))
auto
y
=
run_gpu
(
file
);
{
migraph
::
verify_args
(
file
,
x
,
y
,
100
);
verify_instructions
(
p
);
}
else
{
verify_program
(
file
,
[
&
]
{
return
migraph
::
parse_onnx
(
file
);
});
}
}
}
}
}
src/program.cpp
View file @
e637b5aa
...
@@ -179,6 +179,7 @@ instruction_ref program::add_outline(const shape& s)
...
@@ -179,6 +179,7 @@ instruction_ref program::add_outline(const shape& s)
instruction_ref
program
::
add_parameter
(
std
::
string
name
,
shape
s
)
instruction_ref
program
::
add_parameter
(
std
::
string
name
,
shape
s
)
{
{
assert
(
get_parameter_shape
(
name
)
==
shape
{});
impl
->
instructions
.
push_front
({
builtin
::
param
{
std
::
move
(
name
)},
std
::
move
(
s
),
{}});
impl
->
instructions
.
push_front
({
builtin
::
param
{
std
::
move
(
name
)},
std
::
move
(
s
),
{}});
return
impl
->
instructions
.
begin
();
return
impl
->
instructions
.
begin
();
}
}
...
...
src/targets/gpu/lowering.cpp
View file @
e637b5aa
...
@@ -220,7 +220,7 @@ struct miopen_add
...
@@ -220,7 +220,7 @@ struct miopen_add
struct
miopen_gemm
struct
miopen_gemm
{
{
gemm
op
;
gemm
op
;
std
::
string
name
()
const
{
return
"gpu::
convolution
"
;
}
std
::
string
name
()
const
{
return
"gpu::
gemm
"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
{
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
...
@@ -355,7 +355,7 @@ struct miopen_apply
...
@@ -355,7 +355,7 @@ struct miopen_apply
instruction_ref
insert_allocation
(
instruction_ref
ins
,
const
shape
&
s
,
std
::
string
tag
=
""
)
instruction_ref
insert_allocation
(
instruction_ref
ins
,
const
shape
&
s
,
std
::
string
tag
=
""
)
{
{
if
(
ins
==
--
prog
->
end
())
if
(
ins
==
--
prog
->
end
()
and
not
tag
.
empty
()
)
{
{
return
prog
->
add_parameter
(
"output"
,
s
);
return
prog
->
add_parameter
(
"output"
,
s
);
}
}
...
...
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