Repository navigation
Define alias detection for every GPU array through a location hook - #811
Merged
Merged
Conversation
Back-ends each defined `Base.dataids` and `Base.mightalias`, with diverging handling of empty arrays (the new aliasing testsuite fails on CUDA, AMDGPU, oneAPI and OpenCL) and with Base's SubArray check converting GPU arrays to pointers, which takes stream ownership on CUDA and throws for OpenCL buffers without an address. GPUArrays now defines both for `AbstractGPUArray`, plus `Base._parentsmatch`, from a new `GPUArrays.memory_location` hook: the coordinate of an array's allocation and its byte offset. Bare arrays are compared by byte range, wrapped ones by allocation, empty arrays alias nothing on every Julia version, and isbits-union arrays and types without the hook stay at allocation granularity. JLArrays implements the hook instead of its own `mightalias`.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Back-ends each defined their own
Base.dataidsandBase.mightalias, and they diverge. Thealiasingtestsuite added in 12.0.3 fails on CUDA, AMDGPU, oneAPI and OpenCL, because an empty contiguous view is reported as aliasing the array around it. Base's check for twoSubArrays also converts GPU parents to pointers. That takes stream ownership on CUDA and throws for OpenCL buffers without a device address.This PR defines alias detection once, for every
AbstractGPUArray, on top of a new hook:baseidentifies the allocation (normally its address; a handle works for memory without one) andoffsetis the byte offset of the first element.Base.mightalias: empty arrays alias nothing on every Julia version, including 1.10, which has noisemptycheck. Two arrays with a location alias when their byte ranges overlap. Isbits-union element types, whose selector bytes lie outside that range, and types without the hook are compared bydataids.Base.dataids: the sharedDataRef, the allocation's base and the array's start address, or()for empty arrays. Base compares these whenever an array is wrapped (e.g. in aSubArray), so wrapped arrays are compared by allocation, which is conservative.Base._parentsmatch: two parents are the same memory if they have the same location, element size and size. GPU arrays are no longer converted to pointers. When parents don't match, Base falls back todataids, which is always sound.JLArrays implements the hook in place of its byte-range
mightaliasfrom #803. The behaviour for JLArrays is the same, except that isbits-union arrays are now compared by allocation. The docstring documents the contract, including what the hook cannot express: memory reachable at two addresses, and memory wrapped from a pointer into the middle of an allocation when it is compared through a wrapper.The design was reviewed by two other agents (Codex and Claude). It was checked on Julia 1.10, 1.11, 1.12 and 1.13: the
aliasingtestsuite forJLArrayandArray, JLArraybroadcasting, CPU probes of the wrapper, union and mixed GPU/CPU paths, and no new method ambiguities.This is a minor release: GPUArrays 12.1.0, and JLArrays 0.4.2, which requires it. Once this is merged, the back-ends replace their
dataids/mightaliasmethods with the one-line hook (see NEWS.md).