Background DevicesΒΆ

Most applications might only use one device, thus we provide a simpler API for such cases. Similar to CUDA, there is a background device that can be used to call methods that would normally require an actual device object.

For example, when allocating memory

device.malloc(10 * sizeof(int));

would turn into

occa::malloc(10 * sizeof(int));
occaDeviceMalloc(device, 10 * sizeof(int));

would turn into

occaMalloc(10 * sizeof(int));
device.malloc(10 * sizeof(int))

would turn into

occa.malloc(10 * sizeof(int))

would turn into


The default background device is set to


Methods to fetch and set the background device are

occa::setDevice("mode: 'Serial'");
occaSetDevice(occaString("mode: 'Serial'"));
occa.set_device("mode: 'Serial'")

A powerful use of the background device is the ability to easy the inclusion of OCCA in existing libraries. Changing API is not always an easy process, specially when adding a library such as OCCA that targets the most computational intensive parts of the code. Having the background device implicitly allows a device to be used inside methods without passing it as a function argument.