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
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
Axel Farrugia
aidge_export_cpp
Commits
84af7898
Commit
84af7898
authored
10 months ago
by
Cyril Moineau
Browse files
Options
Downloads
Patches
Plain Diff
Add saveOutputs function to cpp export.
parent
b12d55f1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aidge_export_cpp/static/include/network/utils.hpp
+106
-1
106 additions, 1 deletion
aidge_export_cpp/static/include/network/utils.hpp
with
106 additions
and
1 deletion
aidge_export_cpp/static/include/network/utils.hpp
+
106
−
1
View file @
84af7898
#ifndef __AIDGE_EXPORT_CPP_NETWORK_UTILS__
#define __AIDGE_EXPORT_CPP_NETWORK_UTILS__
#ifdef SAVE_OUTPUTS
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<cstdio>
// fprintf
#include
<type_traits>
// std::is_floating_point
#endif
/**
* @brief Integer clamping
* @param[in] v Value to be clamped
...
...
@@ -41,4 +48,102 @@ int min (int lhs, int rhs)
return
(
lhs
<=
rhs
)
?
lhs
:
rhs
;
}
#endif // __AIDGE_EXPORT_CPP_NETWORK_UTILS__
#ifdef SAVE_OUTPUTS
enum
class
Format
{
Default
,
NCHW
,
NHWC
,
CHWN
,
NCDHW
,
NDHWC
,
CDHWN
};
template
<
typename
Output_T
>
inline
void
saveOutputs
(
int
NB_OUTPUTS
,
int
OUTPUTS_HEIGHT
,
int
OUTPUTS_WIDTH
,
int
OUTPUT_MEM_CONT_OFFSET
,
int
OUTPUT_MEM_CONT_SIZE
,
int
OUTPUT_MEM_WRAP_OFFSET
,
int
OUTPUT_MEM_WRAP_SIZE
,
int
OUTPUT_MEM_STRIDE
,
const
Output_T
*
__restrict
outputs
,
FILE
*
pFile
,
Format
format
)
{
// default is NHCW !
if
(
format
==
Format
::
NHWC
)
{
fprintf
(
pFile
,
"("
);
for
(
int
oy
=
0
;
oy
<
OUTPUTS_HEIGHT
;
oy
++
)
{
fprintf
(
pFile
,
"("
);
for
(
int
ox
=
0
;
ox
<
OUTPUTS_WIDTH
;
ox
++
)
{
fprintf
(
pFile
,
"("
);
const
int
oPos
=
(
ox
+
OUTPUTS_WIDTH
*
oy
);
int
oOffset
=
OUTPUT_MEM_STRIDE
*
oPos
;
if
(
OUTPUT_MEM_WRAP_SIZE
>
0
&&
oOffset
>=
OUTPUT_MEM_CONT_SIZE
)
{
oOffset
+=
OUTPUT_MEM_WRAP_OFFSET
-
OUTPUT_MEM_CONT_OFFSET
-
OUTPUT_MEM_CONT_SIZE
;
}
for
(
int
output
=
0
;
output
<
NB_OUTPUTS
;
output
++
)
{
if
(
std
::
is_floating_point
<
Output_T
>::
value
)
fprintf
(
pFile
,
"%f"
,
static_cast
<
float
>
(
outputs
[
oOffset
+
output
]));
else
fprintf
(
pFile
,
"%d"
,
static_cast
<
int
>
(
outputs
[
oOffset
+
output
]));
fprintf
(
pFile
,
", "
);
}
fprintf
(
pFile
,
"),
\n
"
);
}
fprintf
(
pFile
,
"),
\n
"
);
}
fprintf
(
pFile
,
")
\n
"
);
}
else
if
(
format
==
Format
::
NCHW
||
format
==
Format
::
Default
)
{
for
(
int
output
=
0
;
output
<
NB_OUTPUTS
;
output
++
)
{
fprintf
(
pFile
,
"%d:
\n
"
,
output
);
for
(
int
oy
=
0
;
oy
<
OUTPUTS_HEIGHT
;
oy
++
)
{
for
(
int
ox
=
0
;
ox
<
OUTPUTS_WIDTH
;
ox
++
)
{
const
int
oPos
=
(
ox
+
OUTPUTS_WIDTH
*
oy
);
int
oOffset
=
OUTPUT_MEM_STRIDE
*
oPos
;
if
(
OUTPUT_MEM_WRAP_SIZE
>
0
&&
oOffset
>=
OUTPUT_MEM_CONT_SIZE
)
{
oOffset
+=
OUTPUT_MEM_WRAP_OFFSET
-
OUTPUT_MEM_CONT_OFFSET
-
OUTPUT_MEM_CONT_SIZE
;
}
if
(
std
::
is_floating_point
<
Output_T
>::
value
)
fprintf
(
pFile
,
"%f"
,
static_cast
<
float
>
(
outputs
[
oOffset
+
output
]));
else
fprintf
(
pFile
,
"%d"
,
static_cast
<
int
>
(
outputs
[
oOffset
+
output
]));
fprintf
(
pFile
,
" "
);
}
fprintf
(
pFile
,
"
\n
"
);
}
fprintf
(
pFile
,
"
\n
"
);
}
fprintf
(
pFile
,
"
\n
"
);
}
else
{
printf
(
"Warning unsupported dataformat.
\n
"
);
}
}
#endif // SAVE_OUTPUTS
#endif // __AIDGE_EXPORT_CPP_NETWORK_UTILS__
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