Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_backend_cpu_ll
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
Lucas Lopez
aidge_backend_cpu_ll
Commits
0d421d33
Commit
0d421d33
authored
7 months ago
by
Olivier BICHLER
Browse files
Options
Downloads
Patches
Plain Diff
Fix pad
parent
fb4f93fd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/aidge/backend/cpu/operator/PadImpl_kernels.hpp
+14
-14
14 additions, 14 deletions
include/aidge/backend/cpu/operator/PadImpl_kernels.hpp
unit_tests/operator/Test_PadImpl.cpp
+1
-1
1 addition, 1 deletion
unit_tests/operator/Test_PadImpl.cpp
with
15 additions
and
15 deletions
include/aidge/backend/cpu/operator/PadImpl_kernels.hpp
+
14
−
14
View file @
0d421d33
...
...
@@ -55,19 +55,19 @@ void PadImpl1D_cpu_forward_kernel(const std::array<DimSize_t, 2>& beginEndBorder
O
outputValue
=
static_cast
<
O
>
(
borderValue
);
if
(
borderType
==
PadBorderType
::
Constant
)
{
int
ix
=
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
1
]);
int
ix
=
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
0
]);
if
(
ix
>=
0
&&
ix
<
static_cast
<
int
>
(
dims
[
2
]))
{
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
}
else
if
(
borderType
==
PadBorderType
::
Edge
)
{
int
ix
=
std
::
max
(
0
,
std
::
min
(
static_cast
<
int
>
(
dims
[
2
])
-
1
,
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
1
])));
int
ix
=
std
::
max
(
0
,
std
::
min
(
static_cast
<
int
>
(
dims
[
2
])
-
1
,
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
0
])));
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
else
if
(
borderType
==
PadBorderType
::
Reflect
)
{
int
ix
=
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
1
]);
int
ix
=
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
0
]);
if
(
ix
<
0
)
ix
=
0
-
ix
;
...
...
@@ -77,7 +77,7 @@ void PadImpl1D_cpu_forward_kernel(const std::array<DimSize_t, 2>& beginEndBorder
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
else
if
(
borderType
==
PadBorderType
::
Wrap
)
{
int
ix
=
(
static_cast
<
int
>
(
dims
[
2
])
+
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
1
]))
%
static_cast
<
int
>
(
dims
[
2
]);
int
ix
=
(
static_cast
<
int
>
(
dims
[
2
])
+
static_cast
<
int
>
(
ox
)
-
static_cast
<
int
>
(
beginEndBorders
[
0
]))
%
static_cast
<
int
>
(
dims
[
2
]);
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
...
...
@@ -120,8 +120,8 @@ void PadImpl2D_cpu_forward_kernel(const std::array<DimSize_t, 4>& beginEndBorder
const
I
*
input
=
static_cast
<
const
I
*>
(
input_
);
O
*
output
=
static_cast
<
O
*>
(
output_
);
const
std
::
size_t
oySize
=
dims
[
2
]
+
beginEndBorders
[
0
]
+
beginEndBorders
[
1
];
const
std
::
size_t
oxSize
=
dims
[
3
]
+
beginEndBorders
[
2
]
+
beginEndBorders
[
3
];
const
std
::
size_t
oySize
=
dims
[
2
]
+
beginEndBorders
[
0
]
+
beginEndBorders
[
2
];
const
std
::
size_t
oxSize
=
dims
[
3
]
+
beginEndBorders
[
1
]
+
beginEndBorders
[
3
];
for
(
std
::
size_t
batch
=
0
;
batch
<
dims
[
0
];
++
batch
)
{
for
(
std
::
size_t
ch
=
0
;
ch
<
dims
[
1
];
++
ch
)
{
...
...
@@ -135,22 +135,22 @@ void PadImpl2D_cpu_forward_kernel(const std::array<DimSize_t, 4>& beginEndBorder
O
outputValue
=
static_cast
<
O
>
(
borderValue
);
if
(
borderType
==
PadBorderType
::
Constant
)
{
std
::
int32_t
ix
=
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
3
]);
std
::
int32_t
iy
=
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
]);
std
::
int32_t
ix
=
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
]);
std
::
int32_t
iy
=
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
0
]);
if
(
ix
>=
0
&&
ix
<
static_cast
<
std
::
int32_t
>
(
dims
[
3
])
&&
iy
>=
0
&&
iy
<
static_cast
<
std
::
int32_t
>
(
dims
[
2
]))
{
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
iy
)
*
dims
[
3
]
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
}
else
if
(
borderType
==
PadBorderType
::
Edge
)
{
std
::
int32_t
ix
=
std
::
max
(
0
,
std
::
min
(
static_cast
<
std
::
int32_t
>
(
dims
[
3
])
-
1
,
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
3
])));
std
::
int32_t
iy
=
std
::
max
(
0
,
std
::
min
(
static_cast
<
std
::
int32_t
>
(
dims
[
2
])
-
1
,
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
])));
std
::
int32_t
ix
=
std
::
max
(
0
,
std
::
min
(
static_cast
<
std
::
int32_t
>
(
dims
[
3
])
-
1
,
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
])));
std
::
int32_t
iy
=
std
::
max
(
0
,
std
::
min
(
static_cast
<
std
::
int32_t
>
(
dims
[
2
])
-
1
,
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
0
])));
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
iy
)
*
dims
[
3
]
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
else
if
(
borderType
==
PadBorderType
::
Reflect
)
{
std
::
int32_t
ix
=
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
3
]);
std
::
int32_t
iy
=
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
]);
std
::
int32_t
ix
=
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
]);
std
::
int32_t
iy
=
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
0
]);
if
(
ix
<
0
)
ix
=
0
-
ix
;
...
...
@@ -164,8 +164,8 @@ void PadImpl2D_cpu_forward_kernel(const std::array<DimSize_t, 4>& beginEndBorder
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
iy
)
*
dims
[
3
]
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
else
if
(
borderType
==
PadBorderType
::
Wrap
)
{
std
::
int32_t
ix
=
(
static_cast
<
std
::
int32_t
>
(
dims
[
3
])
+
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
3
]))
%
static_cast
<
std
::
int32_t
>
(
dims
[
3
]);
std
::
int32_t
iy
=
(
static_cast
<
std
::
int32_t
>
(
dims
[
2
])
+
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
]))
%
static_cast
<
std
::
int32_t
>
(
dims
[
2
]);
std
::
int32_t
ix
=
(
static_cast
<
std
::
int32_t
>
(
dims
[
3
])
+
static_cast
<
std
::
int32_t
>
(
ox
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
1
]))
%
static_cast
<
std
::
int32_t
>
(
dims
[
3
]);
std
::
int32_t
iy
=
(
static_cast
<
std
::
int32_t
>
(
dims
[
2
])
+
static_cast
<
std
::
int32_t
>
(
oy
)
-
static_cast
<
std
::
int32_t
>
(
beginEndBorders
[
0
]))
%
static_cast
<
std
::
int32_t
>
(
dims
[
2
]);
outputValue
=
input
[
iIndex
+
static_cast
<
std
::
size_t
>
(
iy
)
*
dims
[
3
]
+
static_cast
<
std
::
size_t
>
(
ix
)];
}
...
...
This diff is collapsed.
Click to expand it.
unit_tests/operator/Test_PadImpl.cpp
+
1
−
1
View file @
0d421d33
...
...
@@ -134,7 +134,7 @@ TEST_CASE("[cpu/operator] Pad(forward)", "[Pad][CPU]") {
SECTION
(
"Asymmetric Pad"
)
{
const
int
pv
=
0
;
// pad value
std
::
shared_ptr
<
Node
>
myPad
=
Pad
<
2
>
({
0
,
1
,
1
,
0
},
"mypad"
,
PadBorderType
::
Constant
,
static_cast
<
double
>
(
pv
));
std
::
shared_ptr
<
Node
>
myPad
=
Pad
<
2
>
({
1
,
0
,
0
,
1
},
"mypad"
,
PadBorderType
::
Constant
,
static_cast
<
double
>
(
pv
));
auto
op
=
std
::
static_pointer_cast
<
OperatorTensor
>
(
myPad
->
getOperator
());
std
::
shared_ptr
<
Tensor
>
myInput
=
std
::
make_shared
<
Tensor
>
(
Array4D
<
int
,
2
,
3
,
5
,
5
>
{
//NCHW
{
...
...
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