Skip to content

Commit ed3f974

Browse files
committed
Fix support of Apple Metal.
1 parent d201735 commit ed3f974

File tree

7 files changed

+47
-50
lines changed

7 files changed

+47
-50
lines changed

genesis/engine/entities/rigid_entity/rigid_entity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,9 @@ def _init_jac_and_IK(self):
560560
else:
561561
q_limit_lower.append(joint.dofs_limit[:, 0])
562562
q_limit_upper.append(joint.dofs_limit[:, 1])
563-
self.q_limit = np.array([np.concatenate(q_limit_lower), np.concatenate(q_limit_upper)])
563+
self.q_limit = np.stack(
564+
(np.concatenate(q_limit_lower), np.concatenate(q_limit_upper)), axis=0, dtype=gs.np_float
565+
)
564566

565567
# for storing intermediate results
566568
self._IK_n_tgts = self._solver._options.IK_max_targets
@@ -1287,7 +1289,6 @@ def _kernel_inverse_kinematics(
12871289
rot_mask = ti.Vector([rot_mask_[0], rot_mask_[1], rot_mask_[2]], dt=gs.ti_float)
12881290
n_error_dims = 6 * n_links
12891291

1290-
ti.loop_config(serialize=self._solver._para_level < gs.PARA_LEVEL.ALL)
12911292
for i_b in envs_idx:
12921293
# save original qpos
12931294
for i_q in range(self.n_qs):
@@ -1579,7 +1580,6 @@ def _kernel_forward_kinematics(
15791580
links_idx: ti.types.ndarray(),
15801581
envs_idx: ti.types.ndarray(),
15811582
):
1582-
15831583
ti.loop_config(serialize=self._solver._para_level < gs.PARA_LEVEL.ALL)
15841584
for i_q_, i_b_ in ti.ndrange(qs_idx.shape[0], envs_idx.shape[0]):
15851585
# save original qpos
@@ -2195,7 +2195,7 @@ def _get_idx(self, idx_local, idx_local_max, idx_global_start=0, *, unsafe=False
21952195
(idx_local.stop if idx_local.stop is not None else idx_local_max) + idx_global_start,
21962196
idx_local.step or 1,
21972197
)
2198-
elif isinstance(idx_local, int):
2198+
elif isinstance(idx_local, (int, np.integer)):
21992199
idx_global = idx_local + idx_global_start
22002200
elif isinstance(idx_local, (list, tuple)):
22012201
try:

genesis/engine/solvers/fem_solver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _init_surface_info(self):
295295
surface_vertices_mapping = np.full(self.n_vertices, -1, dtype=np.int32)
296296
surface_vertices_mapping[surface_vertices_np] = np.arange(len(surface_vertices_np))
297297
mass = igl.massmatrix(pos_np, surface_vertices_mapping[surface_triangles_np])
298-
surface_vert_mass_np = mass.diagonal()
298+
surface_vert_mass_np = mass.diagonal().astype(gs.np_float, copy=False)
299299
self.surface_vert_mass = ti.field(
300300
dtype=gs.ti_float,
301301
shape=(len(surface_vertices_np),),

genesis/engine/solvers/rigid/rigid_solver_decomp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,7 +4563,7 @@ def _sanitize_1D_io_variables(
45634563
inputs_idx.stop if inputs_idx.stop is not None else input_size,
45644564
inputs_idx.step or 1,
45654565
)
4566-
elif isinstance(inputs_idx, int):
4566+
elif isinstance(inputs_idx, (int, np.integer)):
45674567
inputs_idx = [inputs_idx]
45684568

45694569
is_preallocated = tensor is not None
@@ -4648,7 +4648,7 @@ def _sanitize_2D_io_variables(
46484648
inputs_idx.stop if inputs_idx.stop is not None else input_size,
46494649
inputs_idx.step or 1,
46504650
)
4651-
elif isinstance(inputs_idx, int):
4651+
elif isinstance(inputs_idx, (int, np.integer)):
46524652
inputs_idx = [inputs_idx]
46534653

46544654
is_preallocated = tensor is not None

genesis/engine/states/entities.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, entity, s_global):
1212
self.s_global = s_global
1313

1414
args = {
15-
"dtype": float,
15+
"dtype": gs.tc_float,
1616
"requires_grad": self.entity.scene.requires_grad,
1717
"scene": self.entity.scene,
1818
}
@@ -48,7 +48,7 @@ def __init__(self, entity, s_global):
4848
self._s_global = s_global
4949
base_shape = (self.entity.sim._B, self._entity.n_particles)
5050
args = {
51-
"dtype": float,
51+
"dtype": gs.tc_float,
5252
"requires_grad": self._entity.scene.requires_grad,
5353
"scene": self._entity.scene,
5454
}
@@ -115,7 +115,7 @@ def __init__(self, entity, s_global):
115115
self._s_global = s_global
116116
base_shape = (self.entity.sim._B, self._entity.n_particles)
117117
args = {
118-
"dtype": float,
118+
"dtype": gs.tc_float,
119119
"requires_grad": False,
120120
"scene": self._entity.scene,
121121
}
@@ -151,7 +151,7 @@ def __init__(self, entity, s_global):
151151
base_shape = (self.entity.sim._B, self._entity.n_vertices, 3)
152152

153153
args = {
154-
"dtype": float,
154+
"dtype": gs.tc_float,
155155
"requires_grad": False,
156156
"scene": self.entity.scene,
157157
}

genesis/engine/states/solvers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class RigidSolverState:
5151
def __init__(self, scene):
5252
self.scene = scene
5353
args = {
54-
"dtype": float,
54+
"dtype": gs.tc_float,
5555
"requires_grad": scene.requires_grad,
5656
"scene": self.scene,
5757
}
@@ -84,7 +84,7 @@ class AvatarSolverState:
8484
def __init__(self, scene):
8585
self.scene = scene
8686
args = {
87-
"dtype": float,
87+
"dtype": gs.tc_float,
8888
"requires_grad": scene.requires_grad,
8989
"scene": self.scene,
9090
}
@@ -137,7 +137,7 @@ class MPMSolverState(RBC):
137137
def __init__(self, scene):
138138
self._scene = scene
139139
args = {
140-
"dtype": float,
140+
"dtype": gs.tc_float,
141141
"requires_grad": scene.requires_grad,
142142
"scene": self._scene,
143143
}
@@ -146,7 +146,7 @@ def __init__(self, scene):
146146
self._C = gs.zeros((scene.sim._B, scene.sim.mpm_solver.n_particles, 3, 3), **args)
147147
self._F = gs.zeros((scene.sim._B, scene.sim.mpm_solver.n_particles, 3, 3), **args)
148148
self._Jp = gs.zeros((scene.sim._B, scene.sim.mpm_solver.n_particles), **args)
149-
args["dtype"] = bool
149+
args["dtype"] = gs.tc_bool
150150
args["requires_grad"] = False
151151
self._active = gs.zeros((scene.sim._B, scene.sim.mpm_solver.n_particles), **args)
152152

@@ -197,13 +197,13 @@ class SPHSolverState:
197197
def __init__(self, scene):
198198
self._scene = scene
199199
args = {
200-
"dtype": float,
200+
"dtype": gs.tc_float,
201201
"requires_grad": scene.requires_grad,
202202
"scene": self._scene,
203203
}
204204
self._pos = gs.zeros((scene.sim._B, scene.sim.sph_solver.n_particles, 3), **args)
205205
self._vel = gs.zeros((self._scene.sim._B, scene.sim.sph_solver.n_particles, 3), **args)
206-
args["dtype"] = bool
206+
args["dtype"] = gs.tc_bool
207207
args["requires_grad"] = False
208208
self._active = gs.zeros((self._scene.sim._B, scene.sim.sph_solver.n_particles), **args)
209209

@@ -232,13 +232,13 @@ class PBDSolverState:
232232
def __init__(self, scene):
233233
self._scene = scene
234234
args = {
235-
"dtype": float,
235+
"dtype": flgs.tc_floatoat,
236236
"requires_grad": scene.requires_grad,
237237
"scene": self._scene,
238238
}
239239
self._pos = gs.zeros((scene.sim._B, scene.sim.pbd_solver.n_particles, 3), **args)
240240
self._vel = gs.zeros((self._scene.sim._B, scene.sim.pbd_solver.n_particles, 3), **args)
241-
args["dtype"] = bool
241+
args["dtype"] = gs.tc_bool
242242
args["requires_grad"] = False
243243
self._free = gs.zeros((self._scene.sim._B, scene.sim.pbd_solver.n_particles), **args)
244244

@@ -269,7 +269,7 @@ def __init__(self, scene):
269269
}
270270
self._pos = gs.zeros((scene.sim._B, scene.sim.fem_solver.n_vertices, 3), **args)
271271
self._vel = gs.zeros((scene.sim._B, scene.sim.fem_solver.n_vertices, 3), **args)
272-
args["dtype"] = bool
272+
args["dtype"] = gs.tc_bool
273273
args["requires_grad"] = False
274274
self._active = gs.zeros((scene.sim._B, scene.sim.fem_solver.n_elements), **args)
275275

genesis/utils/misc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def ti_field_to_torch(
467467
if mask is None or isinstance(mask, slice):
468468
# Slices are always valid by default. Nothing to check.
469469
is_out_of_bounds = False
470-
elif isinstance(mask, int):
470+
elif isinstance(mask, (int, np.integer)):
471471
# Do not allow negative indexing for consistency with Taichi
472472
is_out_of_bounds = not (0 <= mask < _field_shape[i])
473473
elif isinstance(mask, torch.Tensor):
@@ -487,12 +487,12 @@ def ti_field_to_torch(
487487
# Must convert masks to torch if not slice or int since torch will do it anyway.
488488
# Note that being contiguous is not required and does not affect performance.
489489
must_allocate = False
490-
is_row_mask_tensor = not (row_mask is None or isinstance(row_mask, (slice, int)))
490+
is_row_mask_tensor = not (row_mask is None or isinstance(row_mask, (slice, int, np.integer)))
491491
if is_row_mask_tensor:
492492
_row_mask = torch.as_tensor(row_mask, dtype=gs.tc_int, device=gs.device)
493493
must_allocate = _row_mask is not row_mask
494494
row_mask = _row_mask
495-
is_col_mask_tensor = not (col_mask is None or isinstance(col_mask, (slice, int)))
495+
is_col_mask_tensor = not (col_mask is None or isinstance(col_mask, (slice, int, np.integer)))
496496
if is_col_mask_tensor:
497497
_col_mask = torch.as_tensor(col_mask, dtype=gs.tc_int, device=gs.device)
498498
must_allocate = _col_mask is not col_mask
@@ -532,8 +532,8 @@ def ti_field_to_torch(
532532
# Extract slice if necessary.
533533
# Note that unsqueeze is MUCH faster than indexing with `[row_mask]` to keep batch dimensions,
534534
# because this required allocating GPU data.
535-
is_single_col = (is_col_mask_tensor and col_mask.ndim == 0) or isinstance(col_mask, int)
536-
is_single_row = (is_row_mask_tensor and row_mask.ndim == 0) or isinstance(row_mask, int)
535+
is_single_col = (is_col_mask_tensor and col_mask.ndim == 0) or isinstance(col_mask, (int, np.integer))
536+
is_single_row = (is_row_mask_tensor and row_mask.ndim == 0) or isinstance(row_mask, (int, np.integer))
537537
try:
538538
if is_col_mask_tensor and is_row_mask_tensor:
539539
if not is_single_col and not is_single_row:

0 commit comments

Comments
 (0)