Skip to content

Commit

Permalink
memcheck - minor clarify on QF impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Sep 20, 2024
1 parent c63ecbc commit 31020a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions backends/memcheck/ceed-memcheck-qfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector *U, CeedVector *V) {
Ceed ceed;
void *ctx_data = NULL;
int input_block_ids[CEED_FIELD_MAX], output_block_ids[CEED_FIELD_MAX];
CeedInt num_in, num_out;
CeedQFunctionUser f = NULL;
CeedQFunctionField *output_fields;
Expand All @@ -29,12 +30,21 @@ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector *
CeedCallBackend(CeedQFunctionGetContextData(qf, CEED_MEM_HOST, &ctx_data));
CeedCallBackend(CeedQFunctionGetUserFunction(qf, &f));
CeedCallBackend(CeedQFunctionGetNumArgs(qf, &num_in, &num_out));
int mem_block_ids[num_out];

// Get input/output arrays
// Get input arrays
for (CeedInt i = 0; i < num_in; i++) {
CeedSize len;
char name[32] = "";

CeedCallBackend(CeedVectorGetArrayRead(U[i], CEED_MEM_HOST, &impl->inputs[i]));

CeedCallBackend(CeedVectorGetLength(U[i], &len));

snprintf(name, 32, "QFunction input %" CeedInt_FMT, i);
input_block_ids[i] = VALGRIND_CREATE_BLOCK(impl->inputs[i], len, name);
}

// Get output arrays
for (CeedInt i = 0; i < num_out; i++) {
CeedSize len;
char name[32] = "";
Expand All @@ -44,8 +54,8 @@ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector *
CeedCallBackend(CeedVectorGetLength(V[i], &len));
VALGRIND_MAKE_MEM_UNDEFINED(impl->outputs[i], len);

snprintf(name, 32, "'QFunction output %" CeedInt_FMT "'", i);
mem_block_ids[i] = VALGRIND_CREATE_BLOCK(impl->outputs[i], len, name);
snprintf(name, 32, "QFunction output %" CeedInt_FMT, i);
output_block_ids[i] = VALGRIND_CREATE_BLOCK(impl->outputs[i], len, name);
}

// Call user function
Expand All @@ -54,8 +64,10 @@ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector *
// Restore input arrays
for (CeedInt i = 0; i < num_in; i++) {
CeedCallBackend(CeedVectorRestoreArrayRead(U[i], &impl->inputs[i]));
VALGRIND_DISCARD(input_block_ids[i]);
}
// Check for unset output values

// Check for unset output values and restore arrays
{
const char *kernel_name, *kernel_path;

Expand All @@ -73,7 +85,7 @@ static int CeedQFunctionApply_Memcheck(CeedQFunction qf, CeedInt Q, CeedVector *
kernel_name);
}
CeedCallBackend(CeedVectorRestoreArray(V[i], &impl->outputs[i]));
VALGRIND_DISCARD(mem_block_ids[i]);
VALGRIND_DISCARD(output_block_ids[i]);
}
}
CeedCallBackend(CeedQFunctionRestoreContextData(qf, &ctx_data));
Expand Down
2 changes: 1 addition & 1 deletion backends/memcheck/ceed-memcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ typedef struct {
} CeedElemRestriction_Memcheck;

typedef struct {
bool setup_done;
const CeedScalar **inputs;
CeedScalar **outputs;
bool setup_done;
} CeedQFunction_Memcheck;

typedef struct {
Expand Down

0 comments on commit 31020a9

Please sign in to comment.