Skip to content

Fix missing array interface for associated_image() - #65

Merged
rapids-bot[bot] merged 1 commit into
rapidsai:branch-21.08from
gigony:fix_associated_image
Jul 27, 2021
Merged

rapids-bot[bot] merged 1 commit into
rapidsai:branch-21.08from
gigony:fix_associated_image

Conversation

@gigony

@gigony gigony commented Jul 10, 2021

Copy link
Copy Markdown
Contributor

__array_interface__ for the object returned by CuImage.associated_image() was missing so cannot be converted numpy.

This bug was introduced during the implementation of Cache and support for __cuda_array_interface__: #48 .

associated_image() API is not frequently used by users so it's fine.

We will need to add a test case for this once the artificial test image with the associated image (such as Philips TIFF) is available.

@gigony
gigony requested a review from a team as a code owner July 10, 2021 01:12
@gigony
gigony requested a review from jakirkham July 10, 2021 01:17
@gigony gigony assigned gigony and unassigned jakirkham Jul 10, 2021
@gigony gigony added bug Something isn't working non-breaking Introduces a non-breaking change labels Jul 10, 2021

@grlee77 grlee77 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks okay to me, but I have only rarely looked at pybind11 code, so it would be nice to have a test case to be 100% sure. Can you confirm that you tested the fix locally with a TIFF file?

Is there not some small public domain TIFF we could add as test data?

@gigony

gigony commented Jul 21, 2021 via email

Copy link
Copy Markdown
Contributor Author

@jakirkham jakirkham left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks Gigon! 😄

Had a question about how we handle acquiring the GIL here

Comment thread python/pybind11/cucim_py.cpp
@jakirkham

Copy link
Copy Markdown
Member

@gpucibot merge

@rapids-bot
rapids-bot Bot merged commit 9250fde into rapidsai:branch-21.08 Jul 27, 2021
@jakirkham

Copy link
Copy Markdown
Member

Thanks Gigon! 😄

@gigony

gigony commented Jul 27, 2021 •

Copy link
Copy Markdown
Contributor Author

Thanks Gigon! 😄

Had a question about how we handle acquiring the GIL here

Thanks @jakirkham !

The line 403 (https://github.com/rapidsai/cucim/pull/65/files#diff-48de51ebe61a16c8d3878cba6d31c628f024287fc2671440f9bae39ab6bcbd64R403 ) is for acquiring GIL :)

Before 20.06.00, CuImage object always had __array_interface__ attributes, and depending on the availability of the array data, it exposed correct __array_interface__ content or None/{} value. GIL could be released with the mechanism, to speed up in multi-thread use cases.

However, from 20.06.00, we introduced supporting __cuda_array_interface__. Due to how existing frameworks (CuPy, PyTorch, NumPy) worked, I should be able to remove one of those two attributes (__array_interface__ and __cuda_array_interface__) when creating CuImage object (by read_region() or associated_image()). However, there is no native C++ way to create or delete attributes dynamically (I saw you raised issues pybind/pybind11#21 but it is close now).

For this reason, it needed to acquire GIL (for using Python objects in C++).
It could affect performance when used in multi-threading environment, but I did a quick benchmark (with v0.19.0) and couldn't find a significant performance degradation.
However, we can revisit this issue when the performance issue happens.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants