Skip to content

CUDA: Use relaxed strides checking to compute contiguity - #6830

Merged
stuartarchibald merged 6 commits into
numba:masterfrom
gmarkall:grm-issue-6824
Mar 17, 2021
Merged

stuartarchibald merged 6 commits into
numba:masterfrom
gmarkall:grm-issue-6824

Conversation

@gmarkall

Copy link
Copy Markdown
Member

Since NumPy 1.8, a relaxed strides check has been available for computing the contiguity of arrays (and the relaxed check is the default starting from 1.12). The relaxed check permits additional conditions for arrays to be considered contiguous:

  • All 0-size arrays are considered contiguous, even if they are multidimensional.
  • Strides for an axis are ignored if its shape is 1 when checking contiguity.

Examples of shapes and strides that would now be considered contiguous:

  • Shape: (1, 10), Strides: (800, 80): because the first axis has size 1.
  • Shape: (1, 0, 2), Strides (64, 16, 8): because the second axis has size 0.

This PR makes relaxed strides checking the default when computing the C- and F-contiguity of device arrays, and enables more use cases. For example, from the reproducer in Issue #6824:

import dask.array as da
import numpy as np
from numba import guvectorize

x = da.arange(10000, dtype=np.float64).reshape(100, 100).rechunk((1, 10))
f = np.ascontiguousarray(x.blocks[0, 0])

f is an array that is only contiguous under relaxed strides checking, and prior to this commit could not be transferred to a device array.

Since this may expose latent bugs (the switch in NumPy exposed some issues between versions 1.10.0 and 1.10.2, for example), a config variable, NPY_RELAXED_STRIDES_CHECKING is provided to restore the old, strict checking. This is provided on a temporary basis in case any bugs need to be worked out, and will be removed in 0.55 in the current deprecation schedule.

Fixes #6824.
Fixes #4943.
Fixes #2766.

Since NumPy 1.8, a relaxed strides check has been available for
computing the contiguity of arrays (and the relaxed check is the default
starting from 1.12). The relaxed check permits additional conditions for
arrays to be considered contiguous:

- All 0-size arrays are considered contiguous, even if they are
  multidimensional.
- Strides for an axis are ignored if its shape is 1 when checking
  contiguity.

Examples of shapes and strides that would now be considered contiguous:

- Shape: (1, 10), Strides: (800, 80): because the first axis has size 1.
- Shape: (1, 0, 2), Strides (64, 16, 8): because the second axis has
  size 0.

This commit makes relaxed strides checking the default when computing
the C- and F-contiguity of device arrays, and enables more use cases.
For example, from the reproducer in Issue numba#6824:

```python
import dask.array as da
import numpy as np
from numba import guvectorize

x = da.arange(10000, dtype=np.float64).reshape(100, 100).rechunk((1, 10))
f = np.ascontiguousarray(x.blocks[0, 0])
```

`f` is an array that is only contiguous under relaxed strides checking,
and prior to this commit could not be transferred to a device array.

Since this may expose latent bugs (the switch in NumPy exposed some
issues between versions 1.10.0 and 1.10.2, for example), a config
variable, `NPY_RELAXED_STRIDES_CHECKING` is provided to restore the old,
strict checking. This is provided on a temporary basis in case any bugs
need to be worked out, and will be removed in 0.55 in the current
deprecation schedule.

Fixes numba#6824.
Fixes numba#4943.
Fixes numba#2766.

@stuartarchibald stuartarchibald 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.

Thanks for the patch and for working on a fix for this issue. In general it seems good, just a few minor comments/queries to look at. Thanks again!

Comment thread docs/source/reference/envvars.rst Outdated
Comment thread docs/source/reference/envvars.rst Outdated
Comment thread docs/source/reference/envvars.rst Outdated
Comment thread docs/source/reference/deprecation.rst Outdated
Comment thread numba/misc/dummyarray.py
Comment thread numba/misc/dummyarray.py
Comment thread numba/cuda/tests/cudadrv/test_cuda_ndarray.py
Comment thread numba/cuda/tests/cudadrv/test_cuda_ndarray.py
Comment thread numba/misc/dummyarray.py
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Mar 17, 2021
@gmarkall

Copy link
Copy Markdown
Member Author

@stuartarchibald Many thanks for the review - comments addressed / responded to!

@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Mar 17, 2021
Comment thread docs/source/reference/envvars.rst Outdated
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Mar 17, 2021
@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Mar 17, 2021

@stuartarchibald stuartarchibald 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.

Thanks for the fixes.

@stuartarchibald stuartarchibald added 4 - Waiting on CI Review etc done, waiting for CI to finish Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Mar 17, 2021
@stuartarchibald

Copy link
Copy Markdown
Contributor

Buildfarm ID: numba_smoketest_cuda_yaml_29.

@stuartarchibald

Copy link
Copy Markdown
Contributor

Buildfarm ID: numba_smoketest_cuda_yaml_29.

Passed.

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed and removed 4 - Waiting on CI Review etc done, waiting for CI to finish Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm labels Mar 17, 2021
@stuartarchibald
stuartarchibald merged commit e1de1a1 into numba:master Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed CUDA CUDA related issue/PR

Projects

None yet

2 participants