oclMemLimits
manages the memory limits used internally to
aid with R garbage collection and reports used buffer memory.
oclMemLimits(trigger = NULL, high = NULL)
List with followng components:
active trigger limit (in bytes) or 0 if not active
active trigger limit (in bytes) or 0 if not active
number of bytes currently allocated in clBuffers on the GPU
logical, TRUE
if garbage collection is disabled
due to the inability to reduce usage under trigger
, i.e.,
the usage is between trigger
and high
size specification for trigger limit or NULL
to
not change
size specification for high mark limit or NULL
to
not change
Simon Urbanek
In principle the memory management is simple: as long as a reference
to a GPU object exists in R, that object is retained. As soon as R
removes the reference object, the corresponding GPU object is
released. This is sounds easy execpt for one important detail: R
only releases unused objects when a garbage collection is run (see
gc
), but R does not know about the GPU memory so it
may not decide that it is necessary if little R memory is used.
As a user, you can explicitly call gc()
to force all unused
objects to be collected, but garbage collection is expensive so it may
impact your computation. Therefore OpenCL tracks allocated memory
sizes used by clBuffer
buffers and will trigger R garbage
collection automatically if certain limits are reached.
There are two limits: trigger
limit and high
limit.
The trigger
limit is the threshold at which OpenCL will attempt
to run garbage collection. This limit is checked before any buffer
allocation. Once this limit is exceeded, OpenCL will run gc()
to attempt to free memory. Hoever, if the current operation actually
does require a lot of memory, no GPU memory may be freed. In that case
running garbage collection would be wasteful, therefore OpenCL will
disable further GC until the high
limit is reached. Beyond that
limit GC is always run.
The limit size specifications can be one of the following: a positive
integer numeric (in bytes) or a scalar string consisting of the
integer numeric and an optional unit suffix. The following suffixes
are supported: "k"
, "m"
and "g"
- corresponding
powers of 1024. Note that the reported sizes are always in bytes
represented as numerics.
gc
, clBuffer