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
0ce9810a
Commit
0ce9810a
authored
Aug 14, 2018
by
wsttiger
Browse files
Added CPU to resnet18
parent
73b2dfe6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
29 deletions
+51
-29
src/onnx/CMakeLists.txt
src/onnx/CMakeLists.txt
+1
-1
src/onnx/resnet18.cpp
src/onnx/resnet18.cpp
+50
-28
No files found.
src/onnx/CMakeLists.txt
View file @
0ce9810a
...
@@ -22,7 +22,7 @@ target_link_libraries(mnist migraph_cpu migraph_onnx)
...
@@ -22,7 +22,7 @@ target_link_libraries(mnist migraph_cpu migraph_onnx)
add_executable
(
resnet18 resnet18.cpp
)
add_executable
(
resnet18 resnet18.cpp
)
rocm_clang_tidy_check
(
resnet18
)
rocm_clang_tidy_check
(
resnet18
)
target_link_libraries
(
resnet18 migraph_gpu migraph_onnx
)
target_link_libraries
(
resnet18
migraph_cpu
migraph_gpu migraph_onnx
)
if
(
MIGRAPH_ENABLE_GPU
)
if
(
MIGRAPH_ENABLE_GPU
)
add_executable
(
verify_onnx verify_onnx.cpp
)
add_executable
(
verify_onnx verify_onnx.cpp
)
...
...
src/onnx/resnet18.cpp
View file @
0ce9810a
...
@@ -6,30 +6,33 @@
...
@@ -6,30 +6,33 @@
#include <migraph/onnx.hpp>
#include <migraph/onnx.hpp>
#include <migraph/cpu/cpu_target.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/target.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/gpu/hip.hpp>
#include <migraph/generate.hpp>
#include <migraph/generate.hpp>
auto
read_cifar10_images
(
std
::
string
full_path
)
{
auto
read_cifar10_images
(
std
::
string
full_path
)
{
std
::
ifstream
file
(
full_path
,
std
::
ios
::
binary
);
std
::
ifstream
file
(
full_path
,
std
::
ios
::
binary
);
const
size_t
nimages
=
10
;
const
size_t
nimages
=
10
;
const
size_t
nbytes_per_image
=
3072
;
const
size_t
nbytes_per_image
=
3072
;
std
::
vector
<
int8_t
>
raw_data
(
nimages
*
(
nbytes_per_image
+
1
));
std
::
vector
<
int8_t
>
raw_data
(
nimages
*
(
nbytes_per_image
+
1
));
std
::
vector
<
int8_t
>
labels
(
nimages
);
std
::
vector
<
int8_t
>
labels
(
nimages
);
std
::
vector
<
float
>
data
(
nimages
*
nbytes_per_image
);
std
::
vector
<
float
>
data
(
nimages
*
nbytes_per_image
);
if
(
file
.
is_open
())
if
(
file
.
is_open
())
{
{
file
.
read
(
reinterpret_cast
<
char
*>
(
raw_data
.
data
()),
(
nbytes_per_image
+
1
)
*
nimages
*
sizeof
(
int8_t
));
file
.
read
(
reinterpret_cast
<
char
*>
(
raw_data
.
data
()),
(
nbytes_per_image
+
1
)
*
nimages
*
sizeof
(
int8_t
));
int8_t
*
pimage
=
raw_data
.
data
();
int8_t
*
pimage
=
raw_data
.
data
();
for
(
size_t
i
=
0
;
i
<
nimages
;
i
++
,
pimage
+=
nbytes_per_image
)
for
(
size_t
i
=
0
;
i
<
nimages
;
i
++
,
pimage
+=
nbytes_per_image
)
{
{
labels
[
i
]
=
*
pimage
++
;
labels
[
i
]
=
*
pimage
++
;
for
(
size_t
j
=
0
;
j
<
nbytes_per_image
;
j
++
)
for
(
size_t
j
=
0
;
j
<
nbytes_per_image
;
j
++
)
{
{
float
v
=
*
(
pimage
+
j
)
/
255.0
f
;
float
v
=
*
(
pimage
+
j
)
/
255.0
f
;
data
[
i
*
nbytes_per_image
+
j
]
=
v
;
data
[
i
*
nbytes_per_image
+
j
]
=
v
;
}
}
}
}
return
std
::
make_pair
(
labels
,
data
);
return
std
::
make_pair
(
labels
,
data
);
...
@@ -58,19 +61,43 @@ int main(int argc, char const* argv[])
...
@@ -58,19 +61,43 @@ int main(int argc, char const* argv[])
auto
imageset
=
read_cifar10_images
(
datafile
);
auto
imageset
=
read_cifar10_images
(
datafile
);
// GPU target
// // GPU target
prog
.
compile
(
migraph
::
gpu
::
target
{});
// prog.compile(migraph::gpu::target{});
migraph
::
program
::
parameter_map
m
;
// migraph::program::parameter_map m;
// auto s = migraph::shape{migraph::shape::float_type, {1, 3, 32, 32}};
// m["output"] =
// migraph::gpu::to_gpu(migraph::generate_argument(prog.get_parameter_shape("output")));
// 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 << std::endl;
// }
// // CPU target
// prog.compile(migraph::cpu::cpu_target{});
// auto s = migraph::shape{migraph::shape::float_type, {1, 3, 32, 32}};
// auto input3 = migraph::generate_argument(s, 12345);
// auto result = prog.eval({{"0", input3}});
prog
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
auto
s
=
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
32
,
32
}};
m
[
"output"
]
=
migraph
::
gpu
::
to_gpu
(
migraph
::
generate_argument
(
prog
.
get_parameter_shape
(
"output"
)));
auto
labels
=
imageset
.
first
;
auto
labels
=
imageset
.
first
;
auto
input
=
imageset
.
second
;
auto
input
=
imageset
.
second
;
auto
ptr
=
input
.
data
();
auto
ptr
=
input
.
data
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
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
]});
std
::
cout
<<
"label: "
<<
(
uint32_t
)
labels
[
i
]
<<
" ----> "
;
auto
result
=
migraph
::
gpu
::
from_gpu
(
prog
.
eval
(
m
));
auto
input3
=
migraph
::
argument
{
s
,
&
ptr
[
3072
*
i
]};
auto
result
=
prog
.
eval
({{
"0"
,
input3
}});
std
::
vector
<
float
>
logits
;
std
::
vector
<
float
>
logits
;
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
logits
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
std
::
vector
<
float
>
probs
=
softmax
(
logits
);
...
@@ -79,9 +106,4 @@ int main(int argc, char const* argv[])
...
@@ -79,9 +106,4 @@ int main(int argc, char const* argv[])
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 input3 = migraph::generate_argument(s, 12345);
// auto result = prog.eval({{"0", input3}});
}
}
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