Skip to content

Commit 914dedb

Browse files
committed
Document device allocation limits and failure behavior
Explain the per-work-item heap's size, alignment, lifetime, and cumulative usage in loops. Make clear that exhaustion exits the work-item without a host exception and can leave kernel output incomplete. Avoid promising that the device compiler eliminates the storage or its performance cost. Keep the existing scalar-indexing and Diagonal error overrides: their printed diagnostics remain useful even with an allocator, since ordinary device exceptions still do not report their reason to the host.
1 parent 441c8ed commit 914dedb

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

docs/src/kernels.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,23 @@ and correspond to the standard OpenCL built-in functions. Note that the indices
6262
are 1-based, so they can be used to index Julia arrays directly. See
6363
[Device Intrinsics](device.md) for the full list.
6464

65+
66+
## Dynamic Memory Allocation
67+
68+
Kernels can allocate Julia objects, such as a `Ref` passed to a `@noinline` function or a
69+
boxed value in an `Any` field. Allocations that survive optimization use a 1 KiB heap
70+
private to each work-item. Each allocation is rounded up to 16 bytes, and memory is only
71+
reclaimed when the work-item exits. Allocated objects must not be shared with other
72+
work-items or retained across kernel launches.
73+
74+
When the heap is exhausted, the work-item prints an error and exits without completing
75+
its work. This does not raise a host-side exception, and kernel output may be incomplete:
76+
77+
```
78+
ERROR: Out of dynamic GPU memory (trying to allocate 4 bytes)
79+
```
80+
81+
Kernels without remaining allocations do not reserve an arena. The device compiler may
82+
optimize away some heap storage, but allocations can increase private-memory use and
83+
reduce performance. Avoid repeated allocations in loops: even short-lived objects consume
84+
heap space until the work-item exits.

src/device/quirks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ end
3838
@print_and_throw "sincos(x) is only defined for finite x."
3939

4040
# diagonal.jl
41-
# XXX: remove when we have malloc
41+
# Base's version throws an ArgumentError; this one prints the reason
4242
import LinearAlgebra
4343
@device_override function Base.setindex!(D::LinearAlgebra.Diagonal, v, i::Int, j::Int)
4444
@boundscheck checkbounds(D, i, j)
@@ -51,7 +51,7 @@ import LinearAlgebra
5151
end
5252

5353
# number.jl
54-
# XXX: remove when we have malloc
54+
# Base's version throws a BoundsError; this one prints the reason
5555
@device_override @inline function Base.getindex(x::Number, I::Integer...)
5656
@boundscheck all(isone, I) ||
5757
@print_and_throw "Out-of-bounds access of scalar value"

0 commit comments

Comments
 (0)