Learn R Programming

OpenCL (version 0.2-10)

oclMemLimits: OpenCL Memory Management and Limits

Description

oclMemLimits manages the memory limits used internally to aid with R garbage collection and reports used buffer memory.

Usage

oclMemLimits(trigger = NULL, high = NULL)

Value

List with followng components:

trigger

active trigger limit (in bytes) or 0 if not active

high

active trigger limit (in bytes) or 0 if not active

used

number of bytes currently allocated in clBuffers on the GPU

in.zone

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

Arguments

trigger

size specification for trigger limit or NULL to not change

high

size specification for high mark limit or NULL to not change

Author

Simon Urbanek

Details

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.

See Also

gc, clBuffer

Examples

Run this code
oclMemLimits()

Run the code above in your browser using DataLab