Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Operators use work vectors #1673

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/cuda-gen/ceed-cuda-gen-operator-build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,11 @@ extern "C" int CeedOperatorBuildKernel_Cuda_gen(CeedOperator op) {
CeedElemRestriction rstr_i;

if (is_ordered[i]) continue;
CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i));
field_rstr_in_buffer[i] = i;
is_ordered[i] = true;
input_field_order[curr_index] = i;
curr_index++;
CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i));
if (vec_i == CEED_VECTOR_NONE) continue; // CEED_EVAL_WEIGHT
CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr_i));
for (CeedInt j = i + 1; j < num_input_fields; j++) {
Expand Down
19 changes: 16 additions & 3 deletions backends/cuda-ref/ceed-cuda-ref-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ static int CeedBasisApplyCore_Cuda(CeedBasis basis, bool apply_add, const CeedIn

// Clear v for transpose operation
if (is_transpose && !apply_add) {
CeedInt num_comp, q_comp, num_nodes, num_qpts;
CeedSize length;

CeedCallBackend(CeedVectorGetLength(v, &length));
CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp));
CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts));
length = (CeedSize)num_elem * (CeedSize)num_comp * (t_mode == CEED_TRANSPOSE ? (CeedSize)num_nodes : ((CeedSize)num_qpts * (CeedSize)q_comp));
CeedCallCuda(ceed, cudaMemset(d_v, 0, length * sizeof(CeedScalar)));
}
CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
Expand Down Expand Up @@ -206,9 +211,14 @@ static int CeedBasisApplyAtPointsCore_Cuda(CeedBasis basis, bool apply_add, cons

// Clear v for transpose operation
if (is_transpose && !apply_add) {
CeedInt num_comp, q_comp, num_nodes;
CeedSize length;

CeedCallBackend(CeedVectorGetLength(v, &length));
CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp));
CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
length =
(CeedSize)num_elem * (CeedSize)num_comp * (t_mode == CEED_TRANSPOSE ? (CeedSize)num_nodes : ((CeedSize)max_num_points * (CeedSize)q_comp));
CeedCallCuda(ceed, cudaMemset(d_v, 0, length * sizeof(CeedScalar)));
}

Expand Down Expand Up @@ -283,9 +293,12 @@ static int CeedBasisApplyNonTensorCore_Cuda(CeedBasis basis, bool apply_add, con

// Clear v for transpose operation
if (is_transpose && !apply_add) {
CeedInt num_comp, q_comp;
CeedSize length;

CeedCallBackend(CeedVectorGetLength(v, &length));
CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp));
length = (CeedSize)num_elem * (CeedSize)num_comp * (t_mode == CEED_TRANSPOSE ? (CeedSize)num_nodes : ((CeedSize)num_qpts * (CeedSize)q_comp));
CeedCallCuda(ceed, cudaMemset(d_v, 0, length * sizeof(CeedScalar)));
}

Expand Down
852 changes: 469 additions & 383 deletions backends/cuda-ref/ceed-cuda-ref-operator.c

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions backends/cuda-ref/ceed-cuda-ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ typedef struct {
} CeedOperatorAssemble_Cuda;

typedef struct {
bool *skip_rstr_in, *skip_rstr_out, *apply_add_basis_out, has_shared_e_vecs;
bool *skip_rstr_in, *skip_rstr_out, *apply_add_basis_out;
uint64_t *input_states; // State tracking for passive inputs
CeedVector *e_vecs; // E-vectors, inputs followed by outputs
CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator
CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator
CeedVector *e_vecs_in, *e_vecs_out;
CeedVector *q_vecs_in, *q_vecs_out;
CeedInt num_inputs, num_outputs;
CeedInt num_active_in, num_active_out;
CeedInt *input_field_order, *output_field_order;
CeedSize max_active_e_vec_len;
CeedInt max_num_points;
CeedInt *num_points;
CeedVector *qf_active_in, point_coords_elem;
Expand Down
7 changes: 6 additions & 1 deletion backends/cuda-shared/ceed-cuda-shared-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,14 @@ static int CeedBasisApplyAtPointsCore_Cuda_shared(CeedBasis basis, bool apply_ad

// Clear v for transpose operation
if (is_transpose && !apply_add) {
CeedInt num_comp, q_comp, num_nodes;
CeedSize length;

CeedCallBackend(CeedVectorGetLength(v, &length));
CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp));
CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
length =
(CeedSize)num_elem * (CeedSize)num_comp * (t_mode == CEED_TRANSPOSE ? (CeedSize)num_nodes : ((CeedSize)max_num_points * (CeedSize)q_comp));
CeedCallCuda(ceed, cudaMemset(d_v, 0, length * sizeof(CeedScalar)));
}

Expand Down
2 changes: 1 addition & 1 deletion backends/hip-gen/ceed-hip-gen-operator-build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,11 @@ extern "C" int CeedOperatorBuildKernel_Hip_gen(CeedOperator op) {
CeedElemRestriction rstr_i;

if (is_ordered[i]) continue;
CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i));
field_rstr_in_buffer[i] = i;
is_ordered[i] = true;
input_field_order[curr_index] = i;
curr_index++;
CeedCallBackend(CeedOperatorFieldGetVector(op_input_fields[i], &vec_i));
if (vec_i == CEED_VECTOR_NONE) continue; // CEED_EVAL_WEIGHT
CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr_i));
for (CeedInt j = i + 1; j < num_input_fields; j++) {
Expand Down
14 changes: 12 additions & 2 deletions backends/hip-ref/ceed-hip-ref-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ static int CeedBasisApplyCore_Hip(CeedBasis basis, bool apply_add, const CeedInt

// Clear v for transpose operation
if (is_transpose && !apply_add) {
CeedInt num_comp, q_comp, num_nodes, num_qpts;
CeedSize length;

CeedCallBackend(CeedVectorGetLength(v, &length));
CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp));
CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts));
length = (CeedSize)num_elem * (CeedSize)num_comp * (t_mode == CEED_TRANSPOSE ? (CeedSize)num_nodes : ((CeedSize)num_qpts * (CeedSize)q_comp));
CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar)));
}
CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d));
Expand Down Expand Up @@ -204,9 +209,14 @@ static int CeedBasisApplyAtPointsCore_Hip(CeedBasis basis, bool apply_add, const

// Clear v for transpose operation
if (is_transpose && !apply_add) {
CeedInt num_comp, q_comp, num_nodes;
CeedSize length;

CeedCallBackend(CeedVectorGetLength(v, &length));
CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp));
CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp));
CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes));
length =
(CeedSize)num_elem * (CeedSize)num_comp * (t_mode == CEED_TRANSPOSE ? (CeedSize)num_nodes : ((CeedSize)max_num_points * (CeedSize)q_comp));
CeedCallHip(ceed, hipMemset(d_v, 0, length * sizeof(CeedScalar)));
}

Expand Down
Loading