-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[onert/python] Modularize python binding code.
This commit modularizes the python binding code. - Decompose binding code into session and tensorinfo - Decompose files to session and tensorinfo ONE-DCO-1.0-Signed-off-by: ragmani <[email protected]>
- Loading branch information
Showing
6 changed files
with
175 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __ONERT_API_PYTHON_NNFW_SESSION_BINDINGS_H__ | ||
#define __ONERT_API_PYTHON_NNFW_SESSION_BINDINGS_H__ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace onert | ||
{ | ||
namespace api | ||
{ | ||
namespace python | ||
{ | ||
|
||
// Declare binding common functions | ||
void bind_nnfw_session(pybind11::module_ &m); | ||
|
||
} // namespace python | ||
} // namespace api | ||
} // namespace onert | ||
|
||
#endif // __ONERT_API_PYTHON_NNFW_SESSION_BINDINGS_H__ |
36 changes: 36 additions & 0 deletions
36
runtime/onert/api/python/include/nnfw_tensorinfo_bindings.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __ONERT_API_PYTHON_NNFW_TENSORINFO_BINDINGS_H__ | ||
#define __ONERT_API_PYTHON_NNFW_TENSORINFO_BINDINGS_H__ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace onert | ||
{ | ||
namespace api | ||
{ | ||
namespace python | ||
{ | ||
|
||
// Declare binding tensorinfo | ||
void bind_tensorinfo(pybind11::module_ &m); | ||
|
||
} // namespace python | ||
} // namespace api | ||
} // namespace onert | ||
|
||
#endif // __ONERT_API_PYTHON_NNFW_TENSORINFO_BINDINGS_H__ |
39 changes: 39 additions & 0 deletions
39
runtime/onert/api/python/src/bindings/nnfw_api_wrapper_pybind.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include "nnfw_session_bindings.h" | ||
#include "nnfw_tensorinfo_bindings.h" | ||
|
||
using namespace onert::api::python; | ||
|
||
PYBIND11_MODULE(libnnfw_api_pybind, m) | ||
{ | ||
m.doc() = "Main module that contains infer and experimental submodules"; | ||
|
||
// Bind common `NNFW_SESSION` class | ||
bind_nnfw_session(m); | ||
|
||
// Bind `NNFW_SESSION` class for inference | ||
// Currently, the `infer` session is the same as common. | ||
auto infer = m.def_submodule("infer", "Inference submodule"); | ||
infer.attr("nnfw_session") = m.attr("nnfw_session"); | ||
|
||
// Bind common `tensorinfo` class | ||
bind_tensorinfo(m); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
runtime/onert/api/python/src/bindings/nnfw_tensorinfo_bindings.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "nnfw_tensorinfo_bindings.h" | ||
|
||
#include "nnfw_api_wrapper.h" | ||
|
||
namespace onert | ||
{ | ||
namespace api | ||
{ | ||
namespace python | ||
{ | ||
|
||
namespace py = pybind11; | ||
|
||
// Bind the `tensorinfo` class | ||
void bind_tensorinfo(py::module_ &m) | ||
{ | ||
py::class_<tensorinfo>(m, "tensorinfo", "tensorinfo describes the type and shape of tensors", | ||
py::module_local()) | ||
.def(py::init<>(), "The constructor of tensorinfo") | ||
.def_readwrite("dtype", &tensorinfo::dtype, "The data type") | ||
.def_readwrite("rank", &tensorinfo::rank, "The number of dimensions (rank)") | ||
.def_property( | ||
"dims", [](const tensorinfo &ti) { return get_dims(ti); }, | ||
[](tensorinfo &ti, const py::list &dims_list) { set_dims(ti, dims_list); }, | ||
"The dimension of tensor. Maximum rank is 6 (NNFW_MAX_RANK)."); | ||
} | ||
|
||
} // namespace python | ||
} // namespace api | ||
} // namespace onert |
File renamed without changes.