From 2a3e6c601a1bbae8bf81dde9c0cc03c4156d320b Mon Sep 17 00:00:00 2001 From: Hesam Salehipour Date: Fri, 30 Aug 2024 12:40:32 -0400 Subject: [PATCH] Fixing the syntax error in Warp when bc list is empty. When empty, perf is really bad, otherwise normal. --- examples/cfd/flow_past_sphere_3d.py | 2 +- xlb/operator/stepper/nse_stepper.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/cfd/flow_past_sphere_3d.py b/examples/cfd/flow_past_sphere_3d.py index ff39b1a..7d07e05 100644 --- a/examples/cfd/flow_past_sphere_3d.py +++ b/examples/cfd/flow_past_sphere_3d.py @@ -128,7 +128,7 @@ def post_process(self, i): fields = {"u_magnitude": u_magnitude, "u_x": u[0], "u_y": u[1], "u_z": u[2], "rho": rho[0]} - save_fields_vtk(fields, timestep=i) + # save_fields_vtk(fields, timestep=i) save_image(fields["u_magnitude"][:, self.grid_shape[1] // 2, :], timestep=i) diff --git a/xlb/operator/stepper/nse_stepper.py b/xlb/operator/stepper/nse_stepper.py index ad9831f..ba3e294 100644 --- a/xlb/operator/stepper/nse_stepper.py +++ b/xlb/operator/stepper/nse_stepper.py @@ -14,6 +14,7 @@ from xlb.operator.macroscopic import Macroscopic from xlb.operator.stepper import Stepper from xlb.operator.boundary_condition.boundary_condition import ImplementationStep +from xlb.operator.boundary_condition import DoNothingBC as DummyBC class IncompressibleNavierStokesStepper(Stepper): @@ -378,9 +379,16 @@ def warp_implementation(self, f_0, f_1, boundary_map, missing_mask, timestep): setattr(bc_struct, "id_" + bc_name, bc_to_id[bc_name]) active_bc_list.append("id_" + bc_name) - # Setting the Struct attributes and active BC classes based on the BC class names - bc_fallback = self.boundary_conditions[0] - # TODO: what if self.boundary_conditions is an empty list e.g. when we have periodic BC all around! + # Check if boundary_conditions is an empty list (e.g. all periodic and no BC) + # TODO: There is a huge issue here with perf. when boundary_conditions list + # is empty and is initialized with a dummy BC. If it is not empty, no perf + # loss ocurrs. The following code at least prevents syntax error for periodic examples. + if self.boundary_conditions: + bc_dummy = self.boundary_conditions[0] + else: + bc_dummy = DummyBC() + + # Setting the Struct attributes for inactive BC classes for var in vars(bc_struct): if var not in active_bc_list and not var.startswith("_"): # set unassigned boundaries to the maximum integer in uint8 @@ -388,7 +396,7 @@ def warp_implementation(self, f_0, f_1, boundary_map, missing_mask, timestep): # Assing a fall-back BC for inactive BCs. This is just to ensure Warp codegen does not # produce error when a particular BC is not used in an example. - setattr(self, var.replace("id_", ""), bc_fallback) + setattr(self, var.replace("id_", ""), bc_dummy) # Launch the warp kernel wp.launch(