Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_export_cpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
aidge_export_cpp
Commits
033e1e85
Commit
033e1e85
authored
4 weeks ago
by
Maxence Naud
Committed by
Maxence Naud
4 weeks ago
Browse files
Options
Downloads
Patches
Plain Diff
[upd] benchmark file to last export updates
parent
dc6653a0
No related branches found
No related tags found
2 merge requests
!71
0.4.0
,
!62
[upd] benchmark file to last export updates
Pipeline
#79017
passed
4 weeks ago
Stage: static_analysis
Stage: build
Stage: test
Stage: coverage
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aidge_export_cpp/benchmark.py
+49
-51
49 additions, 51 deletions
aidge_export_cpp/benchmark.py
with
49 additions
and
51 deletions
aidge_export_cpp/benchmark.py
+
49
−
51
View file @
033e1e85
...
...
@@ -15,31 +15,42 @@ def measure_inference_time(model: aidge_core.GraphView, input_data: list[str, np
model
.
set_backend
(
"
cpu
"
)
# create input Tensor list for the GraphView
ordered_inputs
:
list
[
aidge_core
.
Tensor
]
=
[]
ordered_inputs
:
list
[
aidge_core
.
Tensor
]
=
[
aidge_core
.
Tensor
(
i
[
1
])
for
i
in
input_data
]
# [tmp fix] manual transpositin of data for input of export BEFORE converting to Tensor
for
i
in
input_data
:
nb_dims
=
len
(
i
[
1
].
shape
)
if
nb_dims
==
3
:
ordered_inputs
.
append
(
aidge_core
.
Tensor
(
i
[
1
].
transpose
(
0
,
2
,
1
).
reshape
(
i
[
1
].
shape
).
copy
()))
if
nb_dims
==
4
:
ordered_inputs
.
append
(
aidge_core
.
Tensor
(
np
.
transpose
(
i
[
1
],
axes
=
(
0
,
2
,
3
,
1
)).
reshape
(
i
[
1
].
shape
).
copy
()))
else
:
ordered_inputs
.
append
(
aidge_core
.
Tensor
(
i
[
1
]))
#
for i in input_data:
#
nb_dims = len(i[1].shape)
#
if nb_dims == 3:
#
ordered_inputs.append(aidge_core.Tensor(i[1].transpose(0,2,1).reshape(i[1].shape).copy()))
#
if nb_dims == 4:
#
ordered_inputs.append(aidge_core.Tensor(np.transpose(i[1], axes=(0,2,3,1)).reshape(i[1].shape).copy()))
#
else:
#
ordered_inputs.append(aidge_core.Tensor(i[1]))
# set inputs for the export
for
i
,
inp
in
enumerate
(
model
.
get_ordered_inputs
()):
op
=
inp
[
0
].
get_operator
()
op
.
set_input
(
i
,
ordered_inputs
[
i
])
ordered_inputs
[
i
].
set_data_format
(
aidge_core
.
dformat
.
nchw
)
op
.
associate_input
(
i
,
ordered_inputs
[
i
])
scheduler
=
aidge_core
.
SequentialScheduler
(
model
)
scheduler
.
generate_scheduling
()
for
i
in
range
(
len
(
ordered_inputs
)):
ordered_inputs
[
i
].
set_data_format
(
aidge_core
.
dformat
.
nhwc
)
model
.
set_dataformat
(
aidge_core
.
dformat
.
nhwc
)
model
.
set_backend
(
aidge_export_cpp
.
ExportLibCpp
.
_name
)
aidge_core
.
adapt_to_backend
(
model
)
aidge_core
.
adapt_fc_params_format
(
model
)
model
.
forward_dims
([
t
.
dims
()
for
t
in
ordered_inputs
])
scheduler
=
aidge_core
.
SequentialScheduler
(
model
)
scheduler
.
reset_scheduling
(
)
scheduler
.
generate_scheduling
()
# for ordered_input in ordered_inputs:
# ordered_input.set_backend("cpu")
operator_type
:
str
=
model
.
get_ordered_outputs
()[
0
][
0
].
get_operator
().
type
()
print
(
"
├─Generating export...
"
,
end
=
""
,
flush
=
True
)
folder_name
:
str
=
f
"
{
operator_type
.
lower
()
}
_test_export_cpp
"
with
open
(
'
/dev/null
'
,
'
w
'
)
as
f
,
contextlib
.
redirect_stdout
(
f
):
aidge_core
.
export_utils
.
scheduler_export
(
...
...
@@ -50,12 +61,10 @@ def measure_inference_time(model: aidge_core.GraphView, input_data: list[str, np
memory_manager_args
=
{
"
wrapping
"
:
False
}
)
aidge_core
.
export_utils
.
generate_main_inference_time_cpp
(
folder_name
,
model
,
nb_iterations
,
nb_warmup
)
print
(
"
ok
"
)
print
(
"
├─Compiling...
"
,
end
=
""
,
flush
=
True
)
with
open
(
'
/dev/null
'
,
'
w
'
)
as
f
,
contextlib
.
redirect_stdout
(
f
):
run
([
'
make
'
],
cwd
=
folder_name
,
stdout
=
f
)
print
(
"
ok
"
)
timings_str
=
run
(
f
'
./
{
folder_name
}
/bin/run_export
'
,
capture_output
=
True
,
text
=
True
)
folder_path
=
os
.
path
.
abspath
(
folder_name
)
...
...
@@ -70,30 +79,31 @@ def compute_output(model: aidge_core.GraphView, input_data: list[str, np.ndarray
model
.
set_backend
(
"
cpu
"
)
# create input Tensor list for the GraphView
ordered_inputs
:
list
[
aidge_core
.
Tensor
]
=
[]
# [tmp fix] manual transpositin of data for input of export BEFORE converting to Tensor
for
i
in
input_data
:
nb_dims
=
len
(
i
[
1
].
shape
)
if
nb_dims
==
3
:
ordered_inputs
.
append
(
aidge_core
.
Tensor
(
i
[
1
].
transpose
(
0
,
2
,
1
).
reshape
(
i
[
1
].
shape
).
copy
()))
if
nb_dims
==
4
:
ordered_inputs
.
append
(
aidge_core
.
Tensor
(
np
.
transpose
(
i
[
1
],
axes
=
(
0
,
2
,
3
,
1
)).
reshape
(
i
[
1
].
shape
).
copy
()))
else
:
ordered_inputs
.
append
(
aidge_core
.
Tensor
(
i
[
1
]))
ordered_inputs
:
list
[
aidge_core
.
Tensor
]
=
[
aidge_core
.
Tensor
(
i
[
1
])
for
i
in
input_data
]
# set inputs for the export
for
i
,
inp
in
enumerate
(
model
.
get_ordered_inputs
()):
op
=
inp
[
0
].
get_operator
()
op
.
set_input
(
i
,
ordered_inputs
[
i
])
model
.
forward_dims
([
t
.
dims
()
for
t
in
ordered_inputs
])
ordered_inputs
[
i
].
set_data_format
(
aidge_core
.
dformat
.
nchw
)
op
.
associate_input
(
i
,
ordered_inputs
[
i
])
scheduler
=
aidge_core
.
SequentialScheduler
(
model
)
scheduler
.
generate_scheduling
()
for
i
in
range
(
len
(
ordered_inputs
)):
ordered_inputs
[
i
].
set_data_format
(
aidge_core
.
dformat
.
nhwc
)
model
.
set_dataformat
(
aidge_core
.
dformat
.
nhwc
)
model
.
set_backend
(
aidge_export_cpp
.
ExportLibCpp
.
_name
)
aidge_core
.
adapt_to_backend
(
model
)
aidge_core
.
adapt_fc_params_format
(
model
)
model
.
forward_dims
([
t
.
dims
()
for
t
in
ordered_inputs
])
scheduler
.
reset_scheduling
()
scheduler
.
generate_scheduling
()
operator_type
:
str
=
model
.
get_ordered_outputs
()[
0
][
0
].
get_operator
().
type
()
print
(
"
│ Generating export...
"
,
end
=
""
,
flush
=
True
)
folder_name
:
str
=
f
"
{
operator_type
.
lower
()
}
_test_export_cpp
"
with
open
(
'
/dev/null
'
,
'
w
'
)
as
f
,
contextlib
.
redirect_stdout
(
f
):
aidge_core
.
export_utils
.
scheduler_export
(
...
...
@@ -104,12 +114,10 @@ def compute_output(model: aidge_core.GraphView, input_data: list[str, np.ndarray
memory_manager_args
=
{
"
wrapping
"
:
False
}
)
aidge_core
.
export_utils
.
generate_main_display_output_cpp
(
folder_name
,
model
)
print
(
"
ok
"
)
print
(
"
│ Compiling...
"
,
end
=
""
,
flush
=
True
)
with
open
(
'
/dev/null
'
,
'
w
'
)
as
f
,
contextlib
.
redirect_stdout
(
f
):
run
([
'
make
'
],
cwd
=
folder_name
,
stdout
=
f
)
print
(
"
ok
"
)
output_str
:
str
=
run
(
f
'
./
{
folder_name
}
/bin/run_export
'
,
capture_output
=
True
,
text
=
True
)
folder_path
=
os
.
path
.
abspath
(
folder_name
)
if
os
.
path
.
exists
(
folder_path
):
...
...
@@ -117,22 +125,12 @@ def compute_output(model: aidge_core.GraphView, input_data: list[str, np.ndarray
outputs_str
:
list
[
str
]
=
output_str
.
stdout
.
strip
().
split
(
'
\n
'
)
outputs
=
[
np
.
array
([
float
(
val
)
for
val
in
single_output_str
.
split
(
'
'
)
if
val
.
strip
()])
for
i
,
single_output_str
in
enumerate
(
outputs_str
)]
for
i
,
pair
in
enumerate
(
model
.
get_ordered_outputs
()):
dims
=
pair
[
0
].
get_operator
().
get_output
(
pair
[
1
]).
dims
()
nb_dims
=
len
(
dims
)
dims_permutted
=
dims
if
nb_dims
==
3
:
dims_permutted
=
[
dims
[
0
],
dims
[
2
],
dims
[
1
]]
if
nb_dims
==
4
:
dims_permutted
=
[
dims
[
0
],
dims
[
2
],
dims
[
3
],
dims
[
1
]]
if
np
.
prod
(
dims
)
!=
outputs
[
i
].
size
:
aidge_core
.
Log
.
fatal
(
"
Incompatible export output size ({}) with required shape {}
"
,
outputs
[
i
].
size
,
dims
)
outputs
[
i
]
=
outputs
[
i
].
reshape
(
dims_permutted
)
if
nb_dims
==
3
:
outputs
[
i
]
=
outputs
[
i
].
transpose
(
0
,
2
,
1
)
if
nb_dims
==
4
:
outputs
[
i
]
=
outputs
[
i
].
transpose
(
0
,
3
,
1
,
2
)
return
outputs
output_tensors
=
[]
outputs_dims
=
[
pair
[
0
].
get_operator
().
get_output
(
pair
[
1
]).
dims
()
for
pair
in
model
.
get_ordered_outputs
()]
for
out_idx
,
arr
in
enumerate
(
outputs
):
t
=
aidge_core
.
Tensor
(
arr
.
reshape
(
outputs_dims
[
out_idx
]))
t
.
set_data_format
(
aidge_core
.
dformat
.
nhwc
)
t
.
set_data_format
(
aidge_core
.
dformat
.
nchw
)
output_tensors
.
append
(
np
.
array
(
t
))
return
output_tensors
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment