mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-19 22:00:35 +08:00
Linter, deprecated type()
Summary: Run linter after recent changes. Fix long comment in knn.h which clang-format has reflowed badly. Add crude test that code doesn't call deprecated `.type()` or `.data()`. Reviewed By: nikhilaravi Differential Revision: D20692935 fbshipit-source-id: 28ce0308adae79a870cb41a810b7cf8744f41ab8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3061c5b663
commit
37c5c8e0b6
@@ -1,7 +1,6 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
|
||||
from itertools import product
|
||||
|
||||
import torch
|
||||
from fvcore.common.benchmark import benchmark
|
||||
|
||||
@@ -30,21 +29,13 @@ def benchmark_knn_cuda_versions() -> None:
|
||||
continue
|
||||
if version == 3 and K > 4:
|
||||
continue
|
||||
knn_kwargs.append({'N': N, 'D': D, 'P': P, 'K': K, 'v': version})
|
||||
knn_kwargs.append({"N": N, "D": D, "P": P, "K": K, "v": version})
|
||||
for N, P, D in product(Ns, Ps, Ds):
|
||||
nn_kwargs.append({'N': N, 'D': D, 'P': P})
|
||||
nn_kwargs.append({"N": N, "D": D, "P": P})
|
||||
benchmark(
|
||||
knn_cuda_with_init,
|
||||
'KNN_CUDA_VERSIONS',
|
||||
knn_kwargs,
|
||||
warmup_iters=1,
|
||||
)
|
||||
benchmark(
|
||||
nn_cuda_with_init,
|
||||
'NN_CUDA',
|
||||
nn_kwargs,
|
||||
warmup_iters=1,
|
||||
knn_cuda_with_init, "KNN_CUDA_VERSIONS", knn_kwargs, warmup_iters=1
|
||||
)
|
||||
benchmark(nn_cuda_with_init, "NN_CUDA", nn_kwargs, warmup_iters=1)
|
||||
|
||||
|
||||
def benchmark_knn_cuda_vs_naive() -> None:
|
||||
@@ -55,21 +46,16 @@ def benchmark_knn_cuda_vs_naive() -> None:
|
||||
Ks = [1, 2, 4, 8, 16]
|
||||
knn_kwargs, naive_kwargs = [], []
|
||||
for N, P, D, K in product(Ns, Ps, Ds, Ks):
|
||||
knn_kwargs.append({'N': N, 'D': D, 'P': P, 'K': K})
|
||||
knn_kwargs.append({"N": N, "D": D, "P": P, "K": K})
|
||||
if P <= 4096:
|
||||
naive_kwargs.append({'N': N, 'D': D, 'P': P, 'K': K})
|
||||
naive_kwargs.append({"N": N, "D": D, "P": P, "K": K})
|
||||
benchmark(
|
||||
knn_python_cuda_with_init,
|
||||
'KNN_CUDA_PYTHON',
|
||||
"KNN_CUDA_PYTHON",
|
||||
naive_kwargs,
|
||||
warmup_iters=1,
|
||||
)
|
||||
benchmark(
|
||||
knn_cuda_with_init,
|
||||
'KNN_CUDA',
|
||||
knn_kwargs,
|
||||
warmup_iters=1,
|
||||
)
|
||||
benchmark(knn_cuda_with_init, "KNN_CUDA", knn_kwargs, warmup_iters=1)
|
||||
|
||||
|
||||
def benchmark_knn_cpu() -> None:
|
||||
@@ -79,31 +65,18 @@ def benchmark_knn_cpu() -> None:
|
||||
Ks = [1, 2, 4]
|
||||
knn_kwargs, nn_kwargs = [], []
|
||||
for N, P, D, K in product(Ns, Ps, Ds, Ks):
|
||||
knn_kwargs.append({'N': N, 'D': D, 'P': P, 'K': K})
|
||||
knn_kwargs.append({"N": N, "D": D, "P": P, "K": K})
|
||||
for N, P, D in product(Ns, Ps, Ds):
|
||||
nn_kwargs.append({'N': N, 'D': D, 'P': P})
|
||||
nn_kwargs.append({"N": N, "D": D, "P": P})
|
||||
benchmark(
|
||||
knn_python_cpu_with_init,
|
||||
'KNN_CPU_PYTHON',
|
||||
knn_kwargs,
|
||||
warmup_iters=1,
|
||||
)
|
||||
benchmark(
|
||||
knn_cpu_with_init,
|
||||
'KNN_CPU_CPP',
|
||||
knn_kwargs,
|
||||
warmup_iters=1,
|
||||
)
|
||||
benchmark(
|
||||
nn_cpu_with_init,
|
||||
'NN_CPU_CPP',
|
||||
nn_kwargs,
|
||||
warmup_iters=1,
|
||||
knn_python_cpu_with_init, "KNN_CPU_PYTHON", knn_kwargs, warmup_iters=1
|
||||
)
|
||||
benchmark(knn_cpu_with_init, "KNN_CPU_CPP", knn_kwargs, warmup_iters=1)
|
||||
benchmark(nn_cpu_with_init, "NN_CPU_CPP", nn_kwargs, warmup_iters=1)
|
||||
|
||||
|
||||
def knn_cuda_with_init(N, D, P, K, v=-1):
|
||||
device = torch.device('cuda:0')
|
||||
device = torch.device("cuda:0")
|
||||
x = torch.randn(N, P, D, device=device)
|
||||
y = torch.randn(N, P, D, device=device)
|
||||
torch.cuda.synchronize()
|
||||
@@ -116,7 +89,7 @@ def knn_cuda_with_init(N, D, P, K, v=-1):
|
||||
|
||||
|
||||
def knn_cpu_with_init(N, D, P, K):
|
||||
device = torch.device('cpu')
|
||||
device = torch.device("cpu")
|
||||
x = torch.randn(N, P, D, device=device)
|
||||
y = torch.randn(N, P, D, device=device)
|
||||
|
||||
@@ -127,7 +100,7 @@ def knn_cpu_with_init(N, D, P, K):
|
||||
|
||||
|
||||
def knn_python_cuda_with_init(N, D, P, K):
|
||||
device = torch.device('cuda')
|
||||
device = torch.device("cuda")
|
||||
x = torch.randn(N, P, D, device=device)
|
||||
y = torch.randn(N, P, D, device=device)
|
||||
torch.cuda.synchronize()
|
||||
@@ -140,7 +113,7 @@ def knn_python_cuda_with_init(N, D, P, K):
|
||||
|
||||
|
||||
def knn_python_cpu_with_init(N, D, P, K):
|
||||
device = torch.device('cpu')
|
||||
device = torch.device("cpu")
|
||||
x = torch.randn(N, P, D, device=device)
|
||||
y = torch.randn(N, P, D, device=device)
|
||||
|
||||
@@ -151,7 +124,7 @@ def knn_python_cpu_with_init(N, D, P, K):
|
||||
|
||||
|
||||
def nn_cuda_with_init(N, D, P):
|
||||
device = torch.device('cuda')
|
||||
device = torch.device("cuda")
|
||||
x = torch.randn(N, P, D, device=device)
|
||||
y = torch.randn(N, P, D, device=device)
|
||||
torch.cuda.synchronize()
|
||||
@@ -164,7 +137,7 @@ def nn_cuda_with_init(N, D, P):
|
||||
|
||||
|
||||
def nn_cpu_with_init(N, D, P):
|
||||
device = torch.device('cpu')
|
||||
device = torch.device("cpu")
|
||||
x = torch.randn(N, P, D, device=device)
|
||||
y = torch.randn(N, P, D, device=device)
|
||||
|
||||
|
||||
@@ -22,6 +22,27 @@ class TestBuild(unittest.TestCase):
|
||||
for k, v in counter.items():
|
||||
self.assertEqual(v, 1, f"Too many files with stem {k}.")
|
||||
|
||||
def test_deprecated_usage(self):
|
||||
# Check certain expressions do not occur in the csrc code
|
||||
test_dir = Path(__file__).resolve().parent
|
||||
source_dir = test_dir.parent / "pytorch3d" / "csrc"
|
||||
|
||||
files = sorted(source_dir.glob("**/*.*"))
|
||||
self.assertGreater(len(files), 4)
|
||||
|
||||
patterns = [".type()", ".data()"]
|
||||
|
||||
for file in files:
|
||||
with open(file) as f:
|
||||
text = f.read()
|
||||
for pattern in patterns:
|
||||
found = pattern in text
|
||||
msg = (
|
||||
f"{pattern} found in {file.name}"
|
||||
+ ", this has been deprecated."
|
||||
)
|
||||
self.assertFalse(found, msg)
|
||||
|
||||
def test_copyright(self):
|
||||
test_dir = Path(__file__).resolve().parent
|
||||
root_dir = test_dir.parent
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestKNN(unittest.TestCase):
|
||||
|
||||
def test_knn_vs_python_cpu(self):
|
||||
""" Test CPU output vs PyTorch implementation """
|
||||
device = torch.device('cpu')
|
||||
device = torch.device("cpu")
|
||||
Ns = [1, 4]
|
||||
Ds = [2, 3]
|
||||
P1s = [1, 10, 101]
|
||||
@@ -45,7 +45,7 @@ class TestKNN(unittest.TestCase):
|
||||
|
||||
def test_knn_vs_python_cuda(self):
|
||||
""" Test CUDA output vs PyTorch implementation """
|
||||
device = torch.device('cuda')
|
||||
device = torch.device("cuda")
|
||||
Ns = [1, 4]
|
||||
Ds = [2, 3, 8]
|
||||
P1s = [1, 8, 64, 128, 1001]
|
||||
|
||||
Reference in New Issue
Block a user