Skip to content

Commit 3aee2a6

Browse files
melvinhefacebook-github-bot
authored andcommitted
Fixes bus error hard crashes on Apple Silicon MPS devices
Summary: Fixes hard crashes (bus errors) when using MPS device (Apple Silicon) by implementing CPU checks throughout files in csrc subdirectories to check if on same mesh on a CPU device. Note that this is the fourth and ultimate part of a larger change through multiple files & directories. Reviewed By: bottler Differential Revision: D77698176 fbshipit-source-id: 5bc9e3c5cea61afd486aed7396f390d92775ec6d
1 parent c5ea8fa commit 3aee2a6

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

pytorch3d/csrc/rasterize_meshes/rasterize_meshes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ RasterizeMeshesNaive(
138138
AT_ERROR("Not compiled with GPU support");
139139
#endif
140140
} else {
141+
CHECK_CPU(face_verts);
142+
CHECK_CPU(mesh_to_face_first_idx);
143+
CHECK_CPU(num_faces_per_mesh);
141144
return RasterizeMeshesNaiveCpu(
142145
face_verts,
143146
mesh_to_face_first_idx,
@@ -232,6 +235,11 @@ torch::Tensor RasterizeMeshesBackward(
232235
AT_ERROR("Not compiled with GPU support");
233236
#endif
234237
} else {
238+
CHECK_CPU(face_verts);
239+
CHECK_CPU(pix_to_face);
240+
CHECK_CPU(grad_zbuf);
241+
CHECK_CPU(grad_bary);
242+
CHECK_CPU(grad_dists);
235243
return RasterizeMeshesBackwardCpu(
236244
face_verts,
237245
pix_to_face,
@@ -306,6 +314,9 @@ torch::Tensor RasterizeMeshesCoarse(
306314
AT_ERROR("Not compiled with GPU support");
307315
#endif
308316
} else {
317+
CHECK_CPU(face_verts);
318+
CHECK_CPU(mesh_to_face_first_idx);
319+
CHECK_CPU(num_faces_per_mesh);
309320
return RasterizeMeshesCoarseCpu(
310321
face_verts,
311322
mesh_to_face_first_idx,
@@ -423,6 +434,8 @@ RasterizeMeshesFine(
423434
AT_ERROR("Not compiled with GPU support");
424435
#endif
425436
} else {
437+
CHECK_CPU(face_verts);
438+
CHECK_CPU(bin_faces);
426439
AT_ERROR("NOT IMPLEMENTED");
427440
}
428441
}

pytorch3d/csrc/rasterize_points/rasterize_points.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ std::tuple<torch::Tensor, torch::Tensor, torch::Tensor> RasterizePointsNaive(
9191
AT_ERROR("Not compiled with GPU support");
9292
#endif
9393
} else {
94+
CHECK_CPU(points);
95+
CHECK_CPU(cloud_to_packed_first_idx);
96+
CHECK_CPU(num_points_per_cloud);
97+
CHECK_CPU(radius);
9498
return RasterizePointsNaiveCpu(
9599
points,
96100
cloud_to_packed_first_idx,
@@ -166,6 +170,10 @@ torch::Tensor RasterizePointsCoarse(
166170
AT_ERROR("Not compiled with GPU support");
167171
#endif
168172
} else {
173+
CHECK_CPU(points);
174+
CHECK_CPU(cloud_to_packed_first_idx);
175+
CHECK_CPU(num_points_per_cloud);
176+
CHECK_CPU(radius);
169177
return RasterizePointsCoarseCpu(
170178
points,
171179
cloud_to_packed_first_idx,
@@ -232,6 +240,8 @@ std::tuple<torch::Tensor, torch::Tensor, torch::Tensor> RasterizePointsFine(
232240
AT_ERROR("Not compiled with GPU support");
233241
#endif
234242
} else {
243+
CHECK_CPU(points);
244+
CHECK_CPU(bin_points);
235245
AT_ERROR("NOT IMPLEMENTED");
236246
}
237247
}
@@ -284,6 +294,10 @@ torch::Tensor RasterizePointsBackward(
284294
AT_ERROR("Not compiled with GPU support");
285295
#endif
286296
} else {
297+
CHECK_CPU(points);
298+
CHECK_CPU(idxs);
299+
CHECK_CPU(grad_zbuf);
300+
CHECK_CPU(grad_dists);
287301
return RasterizePointsBackwardCpu(points, idxs, grad_zbuf, grad_dists);
288302
}
289303
}

pytorch3d/csrc/sample_farthest_points/sample_farthest_points.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,9 @@ at::Tensor FarthestPointSampling(
6868
AT_ERROR("Not compiled with GPU support.");
6969
#endif
7070
}
71+
CHECK_CPU(points);
72+
CHECK_CPU(lengths);
73+
CHECK_CPU(K);
74+
CHECK_CPU(start_idxs);
7175
return FarthestPointSamplingCpu(points, lengths, K, start_idxs);
7276
}

pytorch3d/csrc/sample_pdf/sample_pdf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ inline void SamplePdf(
7171
AT_ERROR("Not compiled with GPU support.");
7272
#endif
7373
}
74+
CHECK_CPU(weights);
75+
CHECK_CPU(outputs);
7476
CHECK_CONTIGUOUS(outputs);
7577
SamplePdfCpu(bins, weights, outputs, eps);
7678
}

0 commit comments

Comments
 (0)