CUDA_ERROR_OUT_OF_MEMORY = 2,
CUDA_ERROR_NOT_INITIALIZED = 3,
CUDA_ERROR_DEINITIALIZED = 4,
+ CUDA_ERROR_NO_DEVICE = 100,
CUDA_ERROR_INVALID_CONTEXT = 201,
CUDA_ERROR_INVALID_HANDLE = 400,
CUDA_ERROR_NOT_FOUND = 500,
}
/* Initialize hsa_context if it has not already been done.
- Return TRUE on success. */
+ If !PROBE: returns TRUE on success.
+ If PROBE: returns TRUE on success or if the plugin/device shall be silently
+ ignored, and otherwise emits an error and returns FALSE. */
static bool
-init_hsa_context (void)
+init_hsa_context (bool probe)
{
hsa_status_t status;
int agent_index = 0;
GOMP_PLUGIN_fatal ("%s\n", msg);
else
GCN_WARNING ("%s\n", msg);
- return false;
+ return probe ? true : false;
}
status = hsa_fns.hsa_init_fn ();
if (status != HSA_STATUS_SUCCESS)
int
GOMP_OFFLOAD_get_num_devices (unsigned int omp_requires_mask)
{
- if (!init_hsa_context ())
- return 0;
+ if (!init_hsa_context (true))
+ exit (EXIT_FAILURE);
/* Return -1 if no omp_requires_mask cannot be fulfilled but
devices were present. */
if (hsa_context.agent_count > 0
bool
GOMP_OFFLOAD_init_device (int n)
{
- if (!init_hsa_context ())
+ if (!init_hsa_context (false))
return false;
if (n >= hsa_context.agent_count)
{
CUresult r = CUDA_CALL_NOCHECK (cuInit, 0);
/* This is not an error: e.g. we may have CUDA libraries installed but
no devices available. */
- if (r != CUDA_SUCCESS)
+ if (r == CUDA_ERROR_NO_DEVICE)
{
GOMP_PLUGIN_debug (0, "Disabling nvptx offloading; cuInit: %s\n",
cuda_error (r));
return 0;
}
+ else if (r != CUDA_SUCCESS)
+ GOMP_PLUGIN_fatal ("cuInit error: %s", cuda_error (r));
}
CUDA_CALL_ASSERT (cuDeviceGetCount, &n);