Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose data type of CuImage object for interoperability with NumPy #246

Merged
merged 5 commits into from
Mar 31, 2022

Conversation

gigony
Copy link
Contributor

@gigony gigony commented Mar 25, 2022

  • Expose typestr property on CuImage object
  • Expose DLDataType and DLDataTypeCode under cucim.clara

Without this patch,
DLDataType and DLDataTypecode can be accessible with the below workaround.

>>> from cucim import CuImage
>>> a = CuImage("notebooks/input/image.tif")
>>> b = a.read_region((0,0), (10,10))
>>> import numpy as np
>>> np.dtype(b.__array_interface__["typestr"]) # b would expose `__cuda_array_interface__` if memory is in GPU.
dtype('uint8')

With this patch, we can convert data type to NumPy's dtype easily, and also can access cuCIM's DLDataType.

>>> from cucim import CuImage
>>> a = CuImage("notebooks/input/image.tif")
>>> b = a.read_region((0,0), (10,10))
>>> import numpy as np
>>> b.typestr
'|u1'
>>> np.dtype(b.typestr) == np.uint8
True
>>> from cucim.clara import DLDataType, DLDataTypeCode
>>> b.dtype == DLDataType(DLDataTypeCode.DLUInt, 8, 1)
True

Fixes #243

@gigony gigony added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Mar 25, 2022
@gigony gigony added this to the v21.12.01 milestone Mar 25, 2022
@gigony gigony requested review from a team as code owners March 25, 2022 01:44
@gigony gigony self-assigned this Mar 25, 2022
@gigony
Copy link
Contributor Author

gigony commented Mar 30, 2022

It seems that there is an infra issue.

Even if libnvjpeg-dev-11-6_11.6.0.55-1_arm64.deb is listed https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa/, cannot download https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa/libnvjpeg-dev-11-6_11.6.0.55-1_arm64.deb

@jakirkham
Copy link
Member

Generally this seems reasonable. Would be good to have a test. Are we thinking about other endianness?

@gigony
Copy link
Contributor Author

gigony commented Mar 31, 2022

Generally this seems reasonable. Would be good to have a test. Are we thinking about other endianness?

Since our major platform (x86-64 and aarch64 on Jetson) uses little-endian only and most TIFF files are using little-endian, supporting big-endian is lower-priority.

Will add tests later today when I am able to access my machine.

@jakirkham
Copy link
Member

@gpucibot merge

Signed-off-by: Gigon Bae <gbae@nvidia.com>
Signed-off-by: Gigon Bae <gbae@nvidia.com>
Signed-off-by: Gigon Bae <gbae@nvidia.com>
Signed-off-by: Gigon Bae <gbae@nvidia.com>
Signed-off-by: Gigon Bae <gbae@nvidia.com>
@rapids-bot rapids-bot bot merged commit 8fd6881 into rapidsai:branch-22.04 Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Expose typestr to CuImage object for converting data type of the image to numpy.dtype
2 participants