mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 20:02:49 +08:00
Summary: Fix default setting of `max_faces_per_bin` and update mesh rasterization benchmark tests. The previous setting of `max_faces_per_bin` was wrong and for larger mesh sizes and batch sizes it was causing a significant slow down due to an unecessarily large intermediate tensor being created. Reviewed By: gkioxari Differential Revision: D22301819 fbshipit-source-id: d5e817f5b917fb5633c9c6a8634b6c8ff65e3508
88 lines
2.3 KiB
Python
88 lines
2.3 KiB
Python
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
|
|
|
|
|
from itertools import product
|
|
|
|
import torch
|
|
from fvcore.common.benchmark import benchmark
|
|
from test_rasterize_meshes import TestRasterizeMeshes
|
|
|
|
|
|
# ico levels:
|
|
# 0: (12 verts, 20 faces)
|
|
# 1: (42 verts, 80 faces)
|
|
# 3: (642 verts, 1280 faces)
|
|
# 4: (2562 verts, 5120 faces)
|
|
# 5: (10242 verts, 20480 faces)
|
|
# 6: (40962 verts, 81920 faces)
|
|
|
|
|
|
def bm_rasterize_meshes() -> None:
|
|
kwargs_list = [
|
|
{
|
|
"num_meshes": 1,
|
|
"ico_level": 0,
|
|
"image_size": 10, # very slow with large image size
|
|
"blur_radius": 0.0,
|
|
"faces_per_pixel": 3,
|
|
}
|
|
]
|
|
benchmark(
|
|
TestRasterizeMeshes.rasterize_meshes_python_with_init,
|
|
"RASTERIZE_MESHES",
|
|
kwargs_list,
|
|
warmup_iters=1,
|
|
)
|
|
|
|
kwargs_list = []
|
|
num_meshes = [1]
|
|
ico_level = [1]
|
|
image_size = [64, 128]
|
|
blur = [1e-6]
|
|
faces_per_pixel = [3, 50]
|
|
test_cases = product(num_meshes, ico_level, image_size, blur, faces_per_pixel)
|
|
for case in test_cases:
|
|
n, ic, im, b, f = case
|
|
kwargs_list.append(
|
|
{
|
|
"num_meshes": n,
|
|
"ico_level": ic,
|
|
"image_size": im,
|
|
"blur_radius": b,
|
|
"faces_per_pixel": f,
|
|
}
|
|
)
|
|
benchmark(
|
|
TestRasterizeMeshes.rasterize_meshes_cpu_with_init,
|
|
"RASTERIZE_MESHES",
|
|
kwargs_list,
|
|
warmup_iters=1,
|
|
)
|
|
|
|
if torch.cuda.is_available():
|
|
kwargs_list = []
|
|
num_meshes = [8, 16]
|
|
ico_level = [4, 5, 6]
|
|
image_size = [64, 128, 512]
|
|
blur = [1e-6]
|
|
faces_per_pixel = [50]
|
|
test_cases = product(num_meshes, ico_level, image_size, blur, faces_per_pixel)
|
|
|
|
for case in test_cases:
|
|
n, ic, im, b, f = case
|
|
kwargs_list.append(
|
|
{
|
|
"num_meshes": n,
|
|
"ico_level": ic,
|
|
"image_size": im,
|
|
"blur_radius": b,
|
|
"faces_per_pixel": f,
|
|
}
|
|
)
|
|
benchmark(
|
|
TestRasterizeMeshes.rasterize_meshes_cuda_with_init,
|
|
"RASTERIZE_MESHES_CUDA",
|
|
kwargs_list,
|
|
warmup_iters=1,
|
|
)
|