Skip to content

Commit

Permalink
Check all tdp return values
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstratford committed Oct 4, 2024
1 parent 9255199 commit 90dda90
Show file tree
Hide file tree
Showing 50 changed files with 570 additions and 554 deletions.
34 changes: 20 additions & 14 deletions src/advection.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ __host__ int advflux_create(pe_t * pe, cs_t * cs, lees_edw_t * le, int nf,

/* Allocate target copy of structure (or alias) */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
obj->target = obj;
Expand Down Expand Up @@ -260,24 +260,30 @@ __host__ int advflux_free(advflux_t * obj) {

assert(obj);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice > 0) {
if (obj->le == NULL) {
tdpMemcpy(&tmp, &obj->target->fx, sizeof(double *), tdpMemcpyDeviceToHost);
tdpFree(tmp);
tdpAssert( tdpMemcpy(&tmp, &obj->target->fx, sizeof(double *),
tdpMemcpyDeviceToHost) );
tdpAssert( tdpFree(tmp) );
}
else {
tdpMemcpy(&tmp, &obj->target->fe, sizeof(double *), tdpMemcpyDeviceToHost);
tdpFree(tmp);
tdpMemcpy(&tmp, &obj->target->fw, sizeof(double *), tdpMemcpyDeviceToHost);
tdpFree(tmp);
tdpAssert( tdpMemcpy(&tmp, &obj->target->fe, sizeof(double *),
tdpMemcpyDeviceToHost) );
tdpAssert( tdpFree(tmp) );
tdpAssert( tdpMemcpy(&tmp, &obj->target->fw, sizeof(double *),
tdpMemcpyDeviceToHost) );
tdpAssert( tdpFree(tmp) );
}
tdpMemcpy(&tmp, &obj->target->fy, sizeof(double *), tdpMemcpyDeviceToHost);
tdpFree(tmp);
tdpMemcpy(&tmp, &obj->target->fz, sizeof(double *), tdpMemcpyDeviceToHost);
tdpFree(tmp);
tdpFree(obj->target);

tdpAssert( tdpMemcpy(&tmp, &obj->target->fy, sizeof(double *),
tdpMemcpyDeviceToHost) );
tdpAssert( tdpFree(tmp) );
tdpAssert( tdpMemcpy(&tmp, &obj->target->fz, sizeof(double *),
tdpMemcpyDeviceToHost) );
tdpAssert( tdpFree(tmp) );
tdpAssert( tdpFree(obj->target) );
}

if (obj->le == NULL) {
Expand Down Expand Up @@ -373,7 +379,7 @@ __host__ int advflux_memcpy(advflux_t * adv, tdpMemcpyKind flag) {

assert(adv);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
/* Ensure we alias */
Expand Down
4 changes: 2 additions & 2 deletions src/blue_phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ __host__ int fe_lc_create(pe_t * pe, cs_t * cs, lees_edw_t * le,

/* Allocate device memory, or alias */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
fe->target = fe;
Expand Down Expand Up @@ -167,7 +167,7 @@ __host__ int fe_lc_free(fe_lc_t * fe) {

assert(fe);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice > 0) tdpAssert(tdpFree(fe->target));

Expand Down
4 changes: 2 additions & 2 deletions src/blue_phase_beris_edwards.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ __host__ int beris_edw_create(pe_t * pe, cs_t * cs, lees_edw_t * le,

/* Allocate a target copy, or alias */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
obj->target = obj;
Expand Down Expand Up @@ -190,7 +190,7 @@ __host__ int beris_edw_free(beris_edw_t * be) {

assert(be);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice > 0) {
double * htmp;
Expand Down
26 changes: 13 additions & 13 deletions src/brazovskii.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,27 @@ __host__ int fe_brazovskii_create(pe_t * pe, cs_t * cs, field_t * phi,

/* Allocate device memory, or alias */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
obj->target = obj;
}
else {
fe_brazovskii_param_t * tmp;
fe_vt_t * vt;
tdpMalloc((void **) &obj->target, sizeof(fe_brazovskii_t));
tdpMemset(obj->target, 0, sizeof(fe_brazovskii_t));
tdpAssert( tdpMalloc((void **) &obj->target, sizeof(fe_brazovskii_t)) );
tdpAssert( tdpMemset(obj->target, 0, sizeof(fe_brazovskii_t)) );
tdpGetSymbolAddress((void **) &tmp, tdpSymbol(const_param));
tdpMemcpy(&obj->target->param, &tmp, sizeof(fe_brazovskii_t *),
tdpMemcpyHostToDevice);
tdpAssert( tdpMemcpy(&obj->target->param, &tmp, sizeof(fe_brazovskii_t *),
tdpMemcpyHostToDevice) );
tdpGetSymbolAddress((void **) &vt, tdpSymbol(fe_braz_dvt));
tdpMemcpy(&obj->target->super.func, &vt, sizeof(fe_vt_t *),
tdpMemcpyHostToDevice);
tdpAssert( tdpMemcpy(&obj->target->super.func, &vt, sizeof(fe_vt_t *),
tdpMemcpyHostToDevice) );

tdpMemcpy(&obj->target->phi, &phi->target, sizeof(field_t *),
tdpMemcpyHostToDevice);
tdpMemcpy(&obj->target->dphi, &dphi->target, sizeof(field_grad_t *),
tdpMemcpyHostToDevice);
tdpAssert( tdpMemcpy(&obj->target->phi, &phi->target, sizeof(field_t *),
tdpMemcpyHostToDevice) );
tdpAssert( tdpMemcpy(&obj->target->dphi, &dphi->target,
sizeof(field_grad_t *), tdpMemcpyHostToDevice) );
}

*p = obj;
Expand All @@ -165,8 +165,8 @@ __host__ int fe_brazovskii_free(fe_brazovskii_t * fe) {

assert(fe);

tdpGetDeviceCount(&ndevice);
if (ndevice > 0) tdpFree(fe->target);
tdpAssert( tdpGetDeviceCount(&ndevice) );
if (ndevice > 0) tdpAssert( tdpFree(fe->target) );

free(fe->param);
free(fe);
Expand Down
4 changes: 2 additions & 2 deletions src/cahn_hilliard.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ __host__ int ch_create(pe_t * pe, cs_t * cs, ch_info_t info, ch_t ** ch) {
advflux_cs_create(pe, cs, info.nfield, &obj->flux);
assert(obj->flux);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
obj->target = obj;
Expand Down Expand Up @@ -109,7 +109,7 @@ __host__ int ch_free(ch_t * ch) {
{
int ndevice = 0;

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );
if (ndevice > 0) tdpAssert(tdpFree(ch->target));
}

Expand Down
2 changes: 1 addition & 1 deletion src/cahn_hilliard_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ __host__ int cahn_stats_reduce(phi_ch_t * pch, field_t * phi,
MPI_Reduce(&local.max, &stats->max, 1, MPI_DOUBLE, MPI_MAX, root, comm);
MPI_Reduce(&local.vol, &stats->vol, 1, MPI_DOUBLE, MPI_SUM, root, comm);

tdpFree(stats_d);
tdpAssert( tdpFree(stats_d) );

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/colloids.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ __host__ int colloids_info_create(pe_t * pe, cs_t * cs, int ncell[3],
obj->rho0 = RHO_DEFAULT;
obj->drmax = DRMAX_DEFAULT;

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
obj->target = obj;
Expand Down Expand Up @@ -184,7 +184,7 @@ __host__ int colloids_memcpy(colloids_info_t * info, int flag) {
assert(info);
assert(info->map_new);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
/* Bare pointer equality causes HIPCC to choke, hence explicit (()) */
Expand Down Expand Up @@ -284,7 +284,7 @@ __host__ int colloids_info_map_init(colloids_info_t * info) {

/* Allocate data space on target */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice > 0) {
void * tmp;
Expand Down
12 changes: 6 additions & 6 deletions src/coords.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Edinburgh Soft Matter and Statistical Physics and
* Edinburgh Parallel Computing Centre
*
* (c) 2010-2022 The University of Edinburgh
* (c) 2010-2024 The University of Edinburgh
*
* Contributing authors:
* Kevin Stratford ([email protected])
Expand Down Expand Up @@ -216,18 +216,18 @@ __host__ int cs_init(cs_t * cs) {

/* Device side */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
cs->target = cs;
}
else {
cs_param_t * tmp;
tdpMalloc((void **) &cs->target, sizeof(cs_t));
tdpMemset(cs->target, 0, sizeof(cs_t));
tdpAssert( tdpMalloc((void **) &cs->target, sizeof(cs_t)) );
tdpAssert( tdpMemset(cs->target, 0, sizeof(cs_t)) );
tdpGetSymbolAddress((void **) &tmp, tdpSymbol(const_param));
tdpMemcpy(&cs->target->param, (const void *) &tmp, sizeof(cs_param_t *),
tdpMemcpyHostToDevice);
tdpAssert( tdpMemcpy(&cs->target->param, (const void *) &tmp,
sizeof(cs_param_t *), tdpMemcpyHostToDevice) );
cs_commit(cs);
}

Expand Down
2 changes: 1 addition & 1 deletion src/distribution_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int lb_run_time_prev(pe_t * pe, cs_t * cs, rt_t * rt, lb_t ** lb) {
* not as to disrupt the regression tests. */
{
int ndevice = 0;
tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );
if (ndevice > 0) options.halo = LB_HALO_TARGET;
}

Expand Down
8 changes: 4 additions & 4 deletions src/fe_electro.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Edinburgh Soft Matter and Statistical Physics Group and
* Edinburgh Parallel Computing Centre
*
* (c) 2013-2023 The University of Edinburgh
* (c) 2013-2024 The University of Edinburgh
*
* Contributing authors:
* Oliver Henrich ([email protected])
Expand Down Expand Up @@ -120,7 +120,7 @@ __host__ int fe_electro_create(pe_t * pe, psi_t * psi, fe_electro_t ** pobj) {
fe->super.func = &fe_electro_hvt;
fe->super.id = FE_ELECTRO;

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
fe->target = fe;
Expand All @@ -131,7 +131,7 @@ __host__ int fe_electro_create(pe_t * pe, psi_t * psi, fe_electro_t ** pobj) {
fe_vt_t * vt = NULL;

tdpAssert(tdpMalloc((void **) &fe->target, sizeof(fe_electro_t)));
tdpMemset(fe->target, 0, sizeof(fe_electro_t));
tdpAssert( tdpMemset(fe->target, 0, sizeof(fe_electro_t)) );

tdpGetSymbolAddress((void **) &vt, tdpSymbol(fe_electro_dvt));
tdpAssert(tdpMemcpy(&fe->target->super.func, &vt, sizeof(fe_vt_t *),
Expand All @@ -155,7 +155,7 @@ __host__ int fe_electro_free(fe_electro_t * fe) {

assert(fe);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );
if (ndevice > 0) tdpAssert(tdpFree(fe->target));

if (fe->mu_ref) free(fe->mu_ref);
Expand Down
12 changes: 6 additions & 6 deletions src/fe_electro_symmetric.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Edinburgh Soft Matter and Statistical Physics Group and
* Edinburgh Parallel Computing Centre
*
* (c) 2013-2018 The University of Edinburgh
* (c) 2013-2024 The University of Edinburgh
*
* Contributing authors:
* Kevin Stratford ([email protected])
Expand Down Expand Up @@ -138,7 +138,7 @@ __host__ int fe_es_create(pe_t * pe, cs_t * cs, fe_symm_t * symm,
psi_nk(psi, &fe->param->nk);
fe_es_epsilon_set(fe, psi->epsilon, psi->epsilon2);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
fe->target = fe;
Expand All @@ -147,10 +147,10 @@ __host__ int fe_es_create(pe_t * pe, cs_t * cs, fe_symm_t * symm,
fe_vt_t * vt;
fe_es_param_t * tmp;

tdpMalloc((void **) &fe->target, sizeof(fe_es_t));
tdpAssert( tdpMalloc((void **) &fe->target, sizeof(fe_es_t)) );
tdpGetSymbolAddress((void **) &tmp, tdpSymbol(const_param));
tdpMemcpy(&fe->target->param, tmp, sizeof(fe_es_param_t *),
tdpMemcpyHostToDevice);
tdpAssert( tdpMemcpy(&fe->target->param, tmp, sizeof(fe_es_param_t *),
tdpMemcpyHostToDevice) );
tdpGetSymbolAddress((void **) &vt, tdpSymbol(fe_es_dvt));
}

Expand All @@ -169,7 +169,7 @@ __host__ int fe_es_free(fe_es_t * fe) {

assert(fe);

if (fe->target != fe) tdpFree(fe->target);
if (fe->target != fe) tdpAssert( tdpFree(fe->target) );

free(fe->param);
free(fe);
Expand Down
8 changes: 4 additions & 4 deletions src/fe_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Edinburgh Soft Matter and Statistical Physics Group
* and Edinburgh Parallel Computing Centre
*
* (c) 2022 The University of Edinburgh
* (c) 2022-2024 The University of Edinburgh
*
* Contributing authors:
* Kevin Stratford ([email protected])
Expand Down Expand Up @@ -79,7 +79,7 @@ __host__ int fe_null_create(pe_t * pe, fe_null_t ** p) {

/* Allocate target memory, or alias */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
fe->target = fe;
Expand Down Expand Up @@ -112,9 +112,9 @@ __host__ int fe_null_free(fe_null_t * fe) {

assert(fe);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice > 0) tdpFree(fe->target);
if (ndevice > 0) tdpAssert( tdpFree(fe->target) );
free(fe);

return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/fe_ternary.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Edinburgh Soft Matter and Statistical Physics Group
* and Edinburgh Parallel Computing Centre
*
* (c) 2019-2021 The University of Edinburgh
* (c) 2019-2024 The University of Edinburgh
*
* Contributing authors:
* Shan Chen ([email protected])
Expand Down Expand Up @@ -111,7 +111,7 @@ int fe_ternary_create(pe_t * pe, cs_t * cs, field_t * phi,

/* Allocate target memory, or alias */

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );

if (ndevice == 0) {
obj->target = obj;
Expand Down Expand Up @@ -163,7 +163,7 @@ __host__ int fe_ternary_free(fe_ternary_t * fe) {

assert(fe);

tdpGetDeviceCount(&ndevice);
tdpAssert( tdpGetDeviceCount(&ndevice) );
if (ndevice > 0) tdpAssert(tdpFree(fe->target));

free(fe->param);
Expand Down
Loading

0 comments on commit 90dda90

Please sign in to comment.