Skip to content

Conversation

@cwsmith
Copy link
Contributor

@cwsmith cwsmith commented Feb 19, 2025

This PR adds support for the Cabana backend for field creation through the high level/user API.

Todo:

  • run clang formatting
  • describe what the recursive baseType struct does for defining ValArray
  • remove numComp switch in createCoordinateField(...) and just use DataType[1][3] in the cab controller
  • add FIXME for oversized cabana datatypes for numComps == 1|2 in createCoordinateField(...)

@cwsmith cwsmith marked this pull request as ready for review February 20, 2025 13:34
@cwsmith
Copy link
Contributor Author

cwsmith commented Feb 20, 2025

@Joshua-Kloepfer Thanks for addressing the items. Can you describe how the recursive baseType struct for defining ValArray works?

Copy link
Contributor Author

@cwsmith cwsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A few comments are below.

@cwsmith
Copy link
Contributor Author

cwsmith commented Feb 26, 2025

@Joshua-Kloepfer Please address the few comments above when you get a chance. Thanks for adding the the baseType struct description.

@cwsmith
Copy link
Contributor Author

cwsmith commented Mar 19, 2025

@Joshua-Kloepfer Would you please take a look at the failing CI tests and try to fix those?

using Ctrlr = Controller<MemorySpace, ExecutionSpace, DataType ***>;
const int numComp = meshInfo.dim;
Ctrlr kk_ctrl({/*field 0*/ 1, numComp, meshInfo.numVtx});
// FIXME Oversized cabana datatypes when numComp = 1|2

Check notice

Code scanning / CodeQL

FIXME comment Note

FIXME comment: Oversized cabana datatypes when numComp = 1|2

Copilot Autofix

AI 10 months ago

To fix the problem, we need to ensure that the Cabana datatypes are appropriately sized when numComp is 1 or 2. This involves modifying the type used for the Ctrlr alias and the way the controller is instantiated. Specifically, we should use a different datatype for the controller when numComp is 1 or 2 to avoid oversized allocations.

  1. Modify the Ctrlr alias to use a different datatype when numComp is 1 or 2.
  2. Update the createController lambda function to handle these cases correctly.
  3. Ensure that the changes are only applied when MESHFIELDS_ENABLE_CABANA is defined.
Suggested changeset 1
src/MeshField_ShapeField.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/MeshField_ShapeField.hpp b/src/MeshField_ShapeField.hpp
--- a/src/MeshField_ShapeField.hpp
+++ b/src/MeshField_ShapeField.hpp
@@ -277,3 +277,3 @@
   const int numComp = meshInfo.dim;
-// FIXME Oversized cabana datatypes when numComp = 1|2
+
 #ifdef MESHFIELDS_ENABLE_CABANA
@@ -283,3 +283,6 @@
           MeshField::CabanaController<ExecutionSpace, MemorySpace, DataType>>,
-      Controller<ExecutionSpace, MemorySpace, DataType[1][3]>,
+      std::conditional_t<
+          (numComp == 1 || numComp == 2),
+          Controller<ExecutionSpace, MemorySpace, DataType[1][3]>,
+          Controller<ExecutionSpace, MemorySpace, DataType ***>>,
       Controller<MemorySpace, ExecutionSpace, DataType ***>>;
@@ -292,3 +295,7 @@
     } else {
-      return Ctrlr({/*field 0*/ numVtx, 1, numComp});
+      if (numComp == 1 || numComp == 2) {
+        return Ctrlr({/*field 0*/ numVtx, 1, 3});
+      } else {
+        return Ctrlr({/*field 0*/ numVtx, 1, numComp});
+      }
     }
EOF
@@ -277,3 +277,3 @@
const int numComp = meshInfo.dim;
// FIXME Oversized cabana datatypes when numComp = 1|2

#ifdef MESHFIELDS_ENABLE_CABANA
@@ -283,3 +283,6 @@
MeshField::CabanaController<ExecutionSpace, MemorySpace, DataType>>,
Controller<ExecutionSpace, MemorySpace, DataType[1][3]>,
std::conditional_t<
(numComp == 1 || numComp == 2),
Controller<ExecutionSpace, MemorySpace, DataType[1][3]>,
Controller<ExecutionSpace, MemorySpace, DataType ***>>,
Controller<MemorySpace, ExecutionSpace, DataType ***>>;
@@ -292,3 +295,7 @@
} else {
return Ctrlr({/*field 0*/ numVtx, 1, numComp});
if (numComp == 1 || numComp == 2) {
return Ctrlr({/*field 0*/ numVtx, 1, 3});
} else {
return Ctrlr({/*field 0*/ numVtx, 1, numComp});
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
@Joshua-Kloepfer
Copy link
Collaborator

@cwsmith The CI tests were failing because the Cabana Controller is referenced even when MESHFIELDS_ENABLE_CABANA is undefined. Previously, if undefined, it would not include the Cabana Controller but would still have code using it. I surrounded code using the Cabana Controller in the shape field and omegah element tests with the same preprocessor directive and all the CI tests pass now.

Copy link
Contributor Author

@cwsmith cwsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thank you. A few comments are below.

@cwsmith cwsmith merged commit 12c06ac into main Mar 30, 2025
6 checks passed
@cwsmith cwsmith deleted the jk/cabBackend branch March 30, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants