Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
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
Cyril Moineau
aidge_core
Commits
e8811dbe
Commit
e8811dbe
authored
1 year ago
by
Cyril Moineau
Browse files
Options
Downloads
Patches
Plain Diff
Add SET_IMPL_MACRO macro to fix copy ctor bug.
parent
827c74fc
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/operator/Conv.hpp
+2
-2
2 additions, 2 deletions
include/aidge/operator/Conv.hpp
include/aidge/utils/Registrar.hpp
+33
-0
33 additions, 0 deletions
include/aidge/utils/Registrar.hpp
with
35 additions
and
2 deletions
include/aidge/operator/Conv.hpp
+
2
−
2
View file @
e8811dbe
...
...
@@ -23,7 +23,7 @@
#include
"aidge/operator/OperatorTensor.hpp"
#include
"aidge/operator/Producer.hpp"
#include
"aidge/utils/StaticAttributes.hpp"
#include
"aidge/utils/Registrar.hpp"
#include
"aidge/utils/Registrar.hpp"
// SET_IMPL_MACRO
#include
"aidge/utils/Types.h"
namespace
Aidge
{
...
...
@@ -174,7 +174,7 @@ std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<DimSize_t>>> co
}
void
setBackend
(
const
std
::
string
&
name
,
DeviceIdx_t
device
=
0
)
override
{
mImpl
=
Registrar
<
Conv_Op
<
DIM
>>::
create
(
name
)(
*
this
);
SET_IMPL_MACRO
(
Conv_Op
<
DIM
>
,
*
this
,
name
);
mOutputs
[
0
]
->
setBackend
(
name
,
device
);
// By default, automatically set backend for weight and bias inputs
...
...
This diff is collapsed.
Click to expand it.
include/aidge/utils/Registrar.hpp
+
33
−
0
View file @
e8811dbe
...
...
@@ -28,6 +28,9 @@ namespace Aidge {
namespace
py
=
pybind11
;
#endif
// Abstract class used to test if a class is Registrable.
class
AbstractRegistrable
{};
template
<
class
DerivedClass
,
class
Key
,
class
Func
>
// curiously rucurring template pattern
class
Registrable
{
public:
...
...
@@ -108,6 +111,36 @@ void declare_registrable(py::module& m, const std::string& class_name){
}
#endif
/*
* This macro allow to set an implementation to an operator
* This macro is mandatory for using implementation registered in python
* PyBind when calling create method will do a call to the copy ctor if
* op is not visible to the python world (if the create method return a python function)
* See this issue for more information https://github.com/pybind/pybind11/issues/4417
* Note: using a method to do this is not possible has any call to a function will call
* the cpy ctor. This is why I used a macro
* Note: I duplicated
* (op).setImpl(Registrar<T_Op>::create(backend_name)(op)); \
* This is because the py::cast need to be done in the same scope.
* I know this only empyrically not sure what happens under the hood...
*
* If someone wants to find an alternative to this Macro, you can contact me:
* cyril.moineau@cea.fr
*/
#ifdef PYBIND
#define SET_IMPL_MACRO(T_Op, op, backend_name) \
\
if
(
Py_IsInitialized
())
{
\
auto
obj
=
py
::
cast
(
&
(
op
));
\
(
op
).
setImpl
(
Registrar
<
T_Op
>::
create
(
backend_name
)(
op
));
\
}
else
{
\
(
op
).
setImpl
(
Registrar
<
T_Op
>::
create
(
backend_name
)(
op
));
\
}
#else
#define SET_IMPL_MACRO(T_Op, op, backend_name) \
(
op
).
setImpl
(
Registrar
<
T_Op
>::
create
(
backend_name
)(
op
));
#endif
}
#endif //AIDGE_CORE_UTILS_REGISTRAR_H_
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