Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
6ae81129
Commit
6ae81129
authored
Aug 23, 2018
by
wsttiger
Browse files
Moved resnet18 to cifar10 executable
parent
c5d75240
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
4 deletions
+118
-4
src/onnx/CMakeLists.txt
src/onnx/CMakeLists.txt
+3
-3
src/onnx/cifar10.cpp
src/onnx/cifar10.cpp
+115
-0
src/program.cpp
src/program.cpp
+0
-1
No files found.
src/onnx/CMakeLists.txt
View file @
6ae81129
...
...
@@ -21,9 +21,9 @@ add_executable(mnist mnist.cpp)
rocm_clang_tidy_check
(
mnist
)
target_link_libraries
(
mnist migraph_cpu migraph_gpu migraph_onnx
)
add_executable
(
resnet18 resnet18
.cpp
)
rocm_clang_tidy_check
(
resnet18
)
target_link_libraries
(
resnet18
migraph_cpu migraph_gpu migraph_onnx
)
add_executable
(
cifar10 cifar10
.cpp
)
rocm_clang_tidy_check
(
cifar10
)
target_link_libraries
(
cifar10
migraph_cpu migraph_gpu migraph_onnx
)
if
(
MIGRAPH_ENABLE_GPU
)
add_executable
(
verify_onnx verify_onnx.cpp
)
...
...
src/onnx/
resnet18
.cpp
→
src/onnx/
cifar10
.cpp
View file @
6ae81129
...
...
@@ -11,9 +11,8 @@
#include <migraph/gpu/hip.hpp>
#include <migraph/generate.hpp>
auto
read_cifar10_images
(
std
::
string
full_path
)
auto
read_cifar10_images
(
const
std
::
string
&
full_path
)
{
std
::
ifstream
file
(
full_path
,
std
::
ios
::
binary
);
const
size_t
nimages
=
10
;
...
...
@@ -55,55 +54,62 @@ std::vector<float> softmax(std::vector<float> p)
int
main
(
int
argc
,
char
const
*
argv
[])
{
std
::
string
file
=
argv
[
1
];
std
::
string
datafile
=
argv
[
2
];
if
(
argc
<
4
)
{
throw
std
::
runtime_error
(
"Usage: cifar10 [gpu | cpu] <onnx file> <cifar10 data file>"
);
}
std
::
string
gpu_cpu
=
argv
[
1
];
std
::
string
file
=
argv
[
2
];
std
::
string
datafile
=
argv
[
3
];
auto
prog
=
migraph
::
parse_onnx
(
file
);
std
::
cout
<<
prog
<<
std
::
endl
;
auto
imageset
=
read_cifar10_images
(
datafile
);
// // GPU target
// prog.compile(migraph::gpu::target{});
// migraph::program::parameter_map m;
// auto s = migraph::shape{migraph::shape::float_type, {1, 3, 32, 32}};
// for(auto&& x : prog.get_parameter_shapes())
// {
// m[x.first] = migraph::gpu::to_gpu(migraph::generate_argument(x.second));
// }
// auto labels = imageset.first;
// auto input = imageset.second;
// auto ptr = input.data();
// for(int i = 0; i < 10; i++)
// {
// std::cout << "label: " << (uint32_t)labels[i] << " ----> ";
// m["0"] = migraph::gpu::to_gpu(migraph::argument{s, &ptr[3072 * i]});
// auto result = migraph::gpu::from_gpu(prog.eval(m));
// std::vector<float> logits;
// result.visit([&](auto output) { logits.assign(output.begin(), output.end()); });
// std::vector<float> probs = softmax(logits);
// for(auto x : logits)
// //std::cout << x << " ";
// //std::cout << x << std::endl;
// printf("%10.5e ", x);
// std::cout << std::endl;
// std::cout << std::endl;
// }
// // CPU target
prog
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
auto
labels
=
imageset
.
first
;
auto
input
=
imageset
.
second
;
auto
ptr
=
input
.
data
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
if
(
gpu_cpu
==
"gpu"
)
{
std
::
cout
<<
"label: "
<<
(
uint32_t
)
labels
[
i
]
<<
" ----> "
;
auto
input3
=
migraph
::
argument
{
s
,
&
ptr
[
3072
*
i
]};
auto
result
=
prog
.
eval
({{
"0"
,
input3
}});
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
for
(
auto
x
:
logits
)
printf
(
"%10.5e "
,
x
);
std
::
cout
<<
std
::
endl
;
// GPU target
prog
.
compile
(
migraph
::
gpu
::
target
{});
migraph
::
program
::
parameter_map
m
;
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
for
(
auto
&&
x
:
prog
.
get_parameter_shapes
())
{
m
[
x
.
first
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
x
.
second
));
}
auto
labels
=
imageset
.
first
;
auto
input
=
imageset
.
second
;
auto
ptr
=
input
.
data
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
std
::
cout
<<
"label: "
<<
static_cast
<
uint32_t
>
(
labels
[
i
])
<<
" ----> "
;
m
[
"0"
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
argument
{
s
,
&
ptr
[
3072
*
i
]});
auto
result
=
migraph
::
gpu
::
from_gpu
(
prog
.
eval
(
m
));
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
for
(
auto
x
:
probs
)
std
::
cout
<<
x
<<
" "
;
std
::
cout
<<
std
::
endl
<<
std
::
endl
;
}
}
else
{
// CPU target
prog
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
auto
labels
=
imageset
.
first
;
auto
input
=
imageset
.
second
;
auto
ptr
=
input
.
data
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
std
::
cout
<<
"label: "
<<
static_cast
<
uint32_t
>
(
labels
[
i
])
<<
" ----> "
;
auto
input3
=
migraph
::
argument
{
s
,
&
ptr
[
3072
*
i
]};
auto
result
=
prog
.
eval
({{
"0"
,
input3
}});
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
for
(
auto
x
:
probs
)
std
::
cout
<<
x
<<
" "
;
std
::
cout
<<
std
::
endl
;
}
}
}
src/program.cpp
View file @
6ae81129
...
...
@@ -292,7 +292,6 @@ argument generic_eval(const program& p,
}
else
if
(
ins
->
op
.
name
()
==
"@param"
)
{
std
::
cout
<<
ins
->
op
.
name
()
<<
std
::
endl
;
results
.
emplace
(
ins
,
trace
(
ins
,
[
&
]
{
return
params
.
at
(
any_cast
<
builtin
::
param
>
(
ins
->
op
).
parameter
);
}));
...
...
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