Connecting to a DeviceΒΆ

We start off by connecting to a physical device through an OCCA device object.

#include "occa.hpp"

occa::device device("mode: 'Serial'");
#include "occa_c.h"

occaDevice device = occaCreateDevice("mode: 'Serial'");
import occa
import np

device = occa.Device("mode: 'Serial'")
use occa

type(occaDevice) :: device
device = occaCreateDevice("mode: 'Serial'")

The initialization string passed to the device constructor

"mode: 'Serial'"

creates a properties object. Properties are handled as a JSON object, using shorthand notations found in JavaScript.

{
  mode: 'Serial'
}

The only property field required by OCCA when creating a device is mode. However, each mode has its own requirements such as deviceID for CUDA. In this case, we’re initializing a device that runs code serially (usually useful for debugging).

Here are examples for the all core modes supported in OCCA.

"mode: 'Serial'"
{
  mode: 'Serial'
}
"mode: 'OpenMP', threads: 4"
{
  mode: 'OpenMP',
  threads: 4
}
"mode: 'Serial', threads: 4, pinnedCores: [0, 1, 2, 3]"
{
  mode: 'Serial',
  threads: 4,
  pinnedCores: [0, 1, 2, 3]
}
"mode: 'OpenCL', deviceID: 0, platformID: 0"
{
  mode: 'OpenCL',
  deviceID: 0,
  platformID: 0
}
"mode: 'CUDA', deviceID: 0"
{
  mode: 'CUDA',
  deviceID: 0
}