Skip to content

Commit

Permalink
add check for gpu device and fail fast if not available
Browse files Browse the repository at this point in the history
  • Loading branch information
bodono committed Oct 27, 2021
1 parent 5be0e16 commit a0c283b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
15 changes: 13 additions & 2 deletions linsys/gpu/indirect/private.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,20 @@ ScsLinSysWork *SCS(init_lin_sys_work)(const ScsMatrix *A, const ScsMatrix *P,
cudaError_t err;
scs_int i;
csc *P_full;
ScsLinSysWork *p = (ScsLinSysWork *)scs_calloc(1, sizeof(ScsLinSysWork));
ScsGpuMatrix *Ag = (ScsGpuMatrix *)scs_calloc(1, sizeof(ScsGpuMatrix));
ScsLinSysWork *p = SCS_NULL;
ScsGpuMatrix *Ag = SCS_NULL;
ScsGpuMatrix *Pg = SCS_NULL;
int device_count;

err = cudaGetDeviceCount(&device_count);
if (err > 0) {
scs_printf("cudaError: %i (100 indicates no device)\n", (int)err);
return SCS_NULL;
}

p = (ScsLinSysWork *)scs_calloc(1, sizeof(ScsLinSysWork));
Ag = (ScsGpuMatrix *)scs_calloc(1, sizeof(ScsGpuMatrix));


p->A = A;
p->P = P;
Expand Down
20 changes: 11 additions & 9 deletions src/scs.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,6 @@ static ScsWork *init_work(const ScsData *d, const ScsCone *k,
w->cone_boundaries = SCS_NULL;
w->scal = SCS_NULL;
}
if (!(w->cone_work = SCS(init_cone)(k, w->scal, w->m))) {
scs_printf("ERROR: init_cone failure\n");
return SCS_NULL;
}
if (!(w->p =
SCS(init_lin_sys_work)(w->A, w->P, w->rho_y_vec, w->stgs->rho_x))) {
scs_printf("ERROR: init_lin_sys_work failure\n");
return SCS_NULL;
}
/* Acceleration */
w->rejected_accel_steps = 0;
w->accepted_accel_steps = 0;
Expand All @@ -869,6 +860,17 @@ static ScsWork *init_work(const ScsData *d, const ScsCone *k,
} else {
w->accel = SCS_NULL;
}
if (!(w->cone_work = SCS(init_cone)(k, w->scal, w->m))) {
scs_printf("ERROR: init_cone failure\n");
SCS(finish)(w);
return SCS_NULL;
}
if (!(w->p =
SCS(init_lin_sys_work)(w->A, w->P, w->rho_y_vec, w->stgs->rho_x))) {
scs_printf("ERROR: init_lin_sys_work failure\n");
SCS(finish)(w);
return SCS_NULL;
}
return w;
}

Expand Down

0 comments on commit a0c283b

Please sign in to comment.