Skip to content

Commit 7577ddf

Browse files
authored
Merge pull request #1772 from CEED/jeremy/gen-field-names
gen - use field names for clarity
2 parents 549c5e6 + 826538b commit 7577ddf

File tree

2 files changed

+100
-34
lines changed

2 files changed

+100
-34
lines changed

backends/cuda-gen/ceed-cuda-gen-operator-build.cpp

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static int CeedOperatorBuildKernelData_Cuda_gen(Ceed ceed, CeedInt num_input_fie
135135
static int CeedOperatorBuildKernelFieldData_Cuda_gen(std::ostringstream &code, CeedOperator_Cuda_gen *data, CeedInt i, CeedOperatorField op_field,
136136
CeedQFunctionField qf_field, FieldReuse_Cuda field_reuse, CeedInt Q_1d, bool is_input,
137137
bool is_tensor, bool is_at_points, bool use_3d_slices) {
138+
const char *field_name;
138139
std::string var_suffix = (is_input ? "_in_" : "_out_") + std::to_string(i);
139140
std::string P_name = (is_tensor ? "P_1d" : "P") + var_suffix, Q_name = is_tensor ? "Q_1d" : "Q";
140141
std::string option_name = (is_input ? "inputs" : "outputs");
@@ -147,7 +148,8 @@ static int CeedOperatorBuildKernelFieldData_Cuda_gen(std::ostringstream &code, C
147148
// Field reuse info
148149
bool use_previous_field = field_reuse.index != -1;
149150

150-
code << " // -- " << (is_input ? "Input" : "Output") << " field " << i << "\n";
151+
CeedCallBackend(CeedOperatorFieldGetName(op_field, &field_name));
152+
code << " // -- " << (is_input ? "Input" : "Output") << " field " << i << ": " << field_name << "\n";
151153

152154
// Get field data
153155
CeedCallBackend(CeedOperatorFieldGetElemRestriction(op_field, &elem_rstr));
@@ -600,9 +602,11 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
600602
// Setup output arrays
601603
code << "\n // -- Output field setup\n";
602604
for (CeedInt i = 0; i < num_output_fields; i++) {
605+
const char *field_name;
603606
std::string var_suffix = "_out_" + std::to_string(i);
604607

605-
code << " // ---- Output field " << i << "\n";
608+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
609+
code << " // ---- Output field " << i << ": " << field_name << "\n";
606610
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
607611
switch (eval_mode) {
608612
case CEED_EVAL_NONE:
@@ -664,9 +668,11 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
664668

665669
code << " // -- Input fields\n";
666670
for (CeedInt i = 0; i < num_input_fields; i++) {
671+
const char *field_name;
667672
std::string var_suffix = "_in_" + std::to_string(i);
668673

669-
code << " // ---- Input field " << i << "\n";
674+
CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
675+
code << " // ---- Input field " << i << ": " << field_name << "\n";
670676
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
671677
// Basis action
672678
code << " // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
@@ -699,9 +705,11 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
699705
}
700706
code << "\n // -- Output fields\n";
701707
for (CeedInt i = 0; i < num_output_fields; i++) {
708+
const char *field_name;
702709
std::string var_suffix = "_out_" + std::to_string(i);
703710

704-
code << " // ---- Output field " << i << "\n";
711+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
712+
code << " // ---- Output field " << i << ": " << field_name << "\n";
705713
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
706714
// Basis action
707715
switch (eval_mode) {
@@ -731,9 +739,11 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
731739
code << " for (CeedInt q = 0; q < " << Q_name << "; q++) {\n";
732740
code << " // -- Input fields\n";
733741
for (CeedInt i = 0; i < num_input_fields; i++) {
742+
const char *field_name;
734743
std::string var_suffix = "_in_" + std::to_string(i);
735744

736-
code << " // ---- Input field " << i << "\n";
745+
CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
746+
code << " // ---- Input field " << i << ": " << field_name << "\n";
737747
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
738748
// Basis action
739749
code << " // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
@@ -800,9 +810,11 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
800810
}
801811
code << "\n // -- Output fields\n";
802812
for (CeedInt i = 0; i < num_output_fields; i++) {
813+
const char *field_name;
803814
std::string var_suffix = "_out_" + std::to_string(i);
804815

805-
code << " // ---- Output field " << i << "\n";
816+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
817+
code << " // ---- Output field " << i << ": " << field_name << "\n";
806818
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
807819
// Basis action
808820
switch (eval_mode) {
@@ -829,12 +841,18 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
829841
code << " {\n";
830842
code << " // -- Input fields\n";
831843
for (CeedInt i = 0; i < num_input_fields; i++) {
832-
code << " // ---- Input field " << i << "\n";
844+
const char *field_name;
845+
846+
CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
847+
code << " // ---- Input field " << i << ": " << field_name << "\n";
833848
code << " CeedScalar *r_s_in_" << i << " = r_q_in_" << i << ";\n";
834849
}
835850
code << " // -- Output fields\n";
836851
for (CeedInt i = 0; i < num_output_fields; i++) {
837-
code << " // ---- Output field " << i << "\n";
852+
const char *field_name;
853+
854+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
855+
code << " // ---- Output field " << i << ": " << field_name << "\n";
838856
code << " CeedScalar *r_s_out_" << i << " = r_q_out_" << i << ";\n";
839857
}
840858
}
@@ -844,13 +862,19 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
844862
code << " // ---- Inputs\n";
845863
code << " CeedScalar *inputs[" << CeedIntMax(num_input_fields, 1) << "];\n";
846864
for (CeedInt i = 0; i < num_input_fields; i++) {
847-
code << " // ------ Input field " << i << "\n";
865+
const char *field_name;
866+
867+
CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[i], &field_name));
868+
code << " // ------ Input field " << i << ": " << field_name << "\n";
848869
code << " inputs[" << i << "] = r_s_in_" << i << ";\n";
849870
}
850871
code << " // ---- Outputs\n";
851872
code << " CeedScalar *outputs[" << CeedIntMax(num_output_fields, 1) << "];\n";
852873
for (CeedInt i = 0; i < num_output_fields; i++) {
853-
code << " // ------ Output field " << i << "\n";
874+
const char *field_name;
875+
876+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
877+
code << " // ------ Output field " << i << ": " << field_name << "\n";
854878
code << " outputs[" << i << "] = r_s_out_" << i << ";\n";
855879
}
856880

@@ -868,10 +892,12 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
868892
// Map back to coefficients
869893
code << "\n // -- Output fields\n";
870894
for (CeedInt i = 0; i < num_output_fields; i++) {
895+
const char *field_name;
871896
std::string var_suffix = "_out_" + std::to_string(i);
872897
std::string P_name = "P_1d" + var_suffix;
873898

874-
code << " // ---- Output field " << i << "\n";
899+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
900+
code << " // ---- Output field " << i << ": " << field_name << "\n";
875901
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
876902
// Basis action
877903
code << " // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
@@ -916,10 +942,12 @@ static int CeedOperatorBuildKernelQFunction_Cuda_gen(std::ostringstream &code, C
916942
// Copy or apply transpose grad, if needed
917943
code << "\n // -- Output fields\n";
918944
for (CeedInt i = 0; i < num_output_fields; i++) {
945+
const char *field_name;
919946
std::string var_suffix = "_out_" + std::to_string(i);
920947
std::string P_name = "P_1d" + var_suffix;
921948

922-
code << " // ---- Output field " << i << "\n";
949+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
950+
code << " // ---- Output field " << i << ": " << field_name << "\n";
923951
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
924952
// Basis action
925953
code << " // EvalMode: " << CeedEvalModes[eval_mode] << "\n";
@@ -1154,11 +1182,11 @@ extern "C" int CeedOperatorBuildKernel_Cuda_gen(CeedOperator op, bool *is_good_b
11541182

11551183
CeedCallBackend(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
11561184
if (eval_mode != CEED_EVAL_WEIGHT) { // Skip CEED_EVAL_WEIGHT
1157-
code << " const CeedScalar *d_in_" << i << " = fields.inputs[" << i << "];\n";
1185+
code << " const CeedScalar *__restrict__ d_in_" << i << " = fields.inputs[" << i << "];\n";
11581186
}
11591187
}
11601188
for (CeedInt i = 0; i < num_output_fields; i++) {
1161-
code << " CeedScalar *d_out_" << i << " = fields.outputs[" << i << "];\n";
1189+
code << " CeedScalar *__restrict__ d_out_" << i << " = fields.outputs[" << i << "];\n";
11621190
}
11631191

11641192
code << " const CeedInt dim = " << dim << ";\n";
@@ -1367,9 +1395,11 @@ extern "C" int CeedOperatorBuildKernel_Cuda_gen(CeedOperator op, bool *is_good_b
13671395
// -- Input restriction and basis
13681396
code << "\n // -- Input field restrictions and basis actions\n";
13691397
for (CeedInt i = 0; i < num_input_fields; i++) {
1370-
CeedInt f = input_field_order[i];
1398+
const char *field_name;
1399+
const CeedInt f = input_field_order[i];
13711400

1372-
code << " // ---- Input field " << f << "\n";
1401+
CeedCallBackend(CeedOperatorFieldGetName(op_input_fields[f], &field_name));
1402+
code << " // ---- Input field " << f << ": " << field_name << "\n";
13731403

13741404
// ---- Restriction
13751405
CeedCallBackend(CeedOperatorBuildKernelRestriction_Cuda_gen(code, data, f, dim, field_rstr_in_buffer, op_input_fields[f], qf_input_fields[f],
@@ -1388,7 +1418,10 @@ extern "C" int CeedOperatorBuildKernel_Cuda_gen(CeedOperator op, bool *is_good_b
13881418
// -- Output basis and restriction
13891419
code << "\n // -- Output field basis action and restrictions\n";
13901420
for (CeedInt i = 0; i < num_output_fields; i++) {
1391-
code << " // ---- Output field " << i << "\n";
1421+
const char *field_name;
1422+
1423+
CeedCallBackend(CeedOperatorFieldGetName(op_output_fields[i], &field_name));
1424+
code << " // ---- Output field " << i << ": " << field_name << "\n";
13921425

13931426
// ---- Basis action
13941427
CeedCallBackend(CeedOperatorBuildKernelBasis_Cuda_gen(code, data, i, dim, op_output_fields[i], qf_output_fields[i], Q_1d, false, is_tensor,

0 commit comments

Comments
 (0)