Sets the computational device to use.


int mira_SetDevice(mrkernelpmr, int deviceInd);


Parameters:

  • pmr: A pointer to the runtime kernel returned by mira_Init.
  • deviceInd: Device index to get the name from, must be less than mira_GetDeviceCount.


Return value:

MIRA_OK (0) or an error code.


Description:

mira_SetDevice will set the specified device as computational device, it requires that the devices have been scanned using mira_RefreshDeviceList.


Example:

Note the MIRA_CHECK macro, which will check if the return value was MIRA_OK (0) or an error code. In case of an error code, it will jump to a label called Error.


  1. MIRA_CHECK(mira_RefreshDeviceList(pmr, 1, 0));

  2. int deviceInd = 0;
  3. MIRAACQ_CHECK(mira_SetDevice(pmr, deviceInd));
  4. printf("Device opened: %d '%s'\n", deviceInd, mira_GetDeviceName(pmr, deviceInd));

  5. Error:
  6. if (res != MIRA_OK) {
  7.     printf("Error %d: %s", mira_GetErrorCode(pmr), mira_GetErrorMsg(pmr));
  8. }


Output:

Device selected: 1 'CUDA: NVIDIA RTX A2000 12GB, 12032 MB, CUDA Compute 8.6'