Skip to content

Add python function operator - DALI-571#732

Merged
JanuszL merged 19 commits intoNVIDIA:masterfrom
banasraf:add_python_function_operator
Apr 30, 2019
Merged

Add python function operator - DALI-571#732
JanuszL merged 19 commits intoNVIDIA:masterfrom
banasraf:add_python_function_operator

Conversation

@banasraf
Copy link
Collaborator

@banasraf banasraf commented Apr 2, 2019

Added python operator, a test and a jupyter notebook.

Rafał Banaś added 2 commits April 2, 2019 17:35
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
const auto &input = ws->Input<CPUBackend>(idx);
auto &output = ws->Output<CPUBackend>(idx);
py::gil_scoped_acquire guard{};
py::array output_array = python_function(tensorToNumpyArray(input));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can provide instead of one NumpyArray a list of based on the number of inputs provided to the operator?

const auto &input = ws->Input<CPUBackend>(idx);
auto &output = ws->Output<CPUBackend>(idx);
py::gil_scoped_acquire guard{};
py::array output_array = python_function(tensorToNumpyArray(input));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe we could accept list on NumpyArrays to get multiple outputs from the operator?

const auto &input = ws->Input<CPUBackend>(idx);
auto &output = ws->Output<CPUBackend>(idx);
py::gil_scoped_acquire guard{};
py::array output_array = python_function(tensorToNumpyArray(input));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the lifetime of this output_array? Maybe we can share its memory with the tensor and took over the ownership instead of copying it?

p->SetOutputNames(outputs);
})
.def("RunCPU", &Pipeline::RunCPU)
.def("RunCPU", &Pipeline::RunCPU, py::call_guard<py::gil_scoped_release>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just wondering what is this extra argument doing. Any performance implications (since this affects any pipeline's RunCPU)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What it does is releasing the python global interpreter lock. Since a normal pipeline execution does not touch any python's resources it is safe to do it while not holding the GIL. Speaking about performance, actually it could even help because it unlocks the interpreter for other python threads. Of course in case of a python operator, GIL must be reacquired before executing.

Rafał Banaś added 2 commits April 4, 2019 13:47
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
@banasraf banasraf force-pushed the add_python_function_operator branch from 712b2bc to 49eae64 Compare April 8, 2019 08:50
Rafał Banaś added 2 commits April 8, 2019 13:28
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [705291]: BUILD STARTED

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [705327]: BUILD STARTED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [705327]: BUILD PASSED

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706273]: BUILD STARTED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706273]: BUILD FAILED

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706487]: BUILD FAILED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706491]: BUILD FAILED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706494]: BUILD STARTED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706494]: BUILD PASSED

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706568]: BUILD STARTED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI MESSAGE: [706568]: BUILD PASSED

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
@klecki
Copy link
Contributor

klecki commented Apr 17, 2019

CI MESSAGE: [707545]: BUILD STARTED

@klecki
Copy link
Contributor

klecki commented Apr 17, 2019

CI MESSAGE: [707545]: BUILD PASSED

@banasraf banasraf requested a review from szalpal April 18, 2019 09:08
Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
@JanuszL JanuszL merged commit 398ced8 into NVIDIA:master Apr 30, 2019
kychennv pushed a commit to kychennv/DALI that referenced this pull request May 14, 2019
* Add python function operator.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add custom python operator example.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add custom python operator example.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix style

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix style.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix test to follow nosetest convention

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add test to the test script

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix docker build.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move python operator to external plugin

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add proper documentation for the operator

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move plugin loading to backend.py

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix example notebook

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move plugin loading to the operator constructor.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move plugin loading to backend initialization.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move the operator to pipeline/operators

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix registring python wrapper ops

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Typo fix

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Signed-off-by: kychennv <kychen@nvidia.com>
haoxintong pushed a commit to haoxintong/DALI that referenced this pull request Jul 16, 2019
* Add python function operator.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add custom python operator example.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add custom python operator example.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix style

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix style.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix test to follow nosetest convention

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add test to the test script

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix docker build.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move python operator to external plugin

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Add proper documentation for the operator

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move plugin loading to backend.py

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix example notebook

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move plugin loading to the operator constructor.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move plugin loading to backend initialization.

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Move the operator to pipeline/operators

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Fix registring python wrapper ops

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>

* Typo fix

Signed-off-by: Rafał Banaś <Banas.Rafal97@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants