Skip to content

Commit 87a7564

Browse files
Merge pull request #48 from hzxie/master
Format all code with clang-format and black.
2 parents eb64e4c + e7ce101 commit 87a7564

File tree

13 files changed

+68
-108
lines changed

13 files changed

+68
-108
lines changed

cuda/src/ball_query.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ void query_ball_point_kernel_dense_wrapper(int b, int n, int m, float radius, in
66
const float* new_xyz, const float* xyz, int64_t* idx,
77
float* dist_out);
88

9-
void query_ball_point_kernel_partial_wrapper(int64_t batch_size, int size_x, int size_y, float radius,
10-
int nsample, const float* x, const float* y,
11-
const int64_t* batch_x, const int64_t* batch_y,
12-
int64_t* idx_out, float* dist_out);
9+
void query_ball_point_kernel_partial_wrapper(int64_t batch_size, int size_x, int size_y,
10+
float radius, int nsample, const float* x,
11+
const float* y, const int64_t* batch_x,
12+
const int64_t* batch_y, int64_t* idx_out,
13+
float* dist_out);
1314

1415
std::pair<at::Tensor, at::Tensor> ball_query_dense(at::Tensor new_xyz, at::Tensor xyz,
1516
const float radius, const int nsample)
@@ -71,10 +72,10 @@ std::pair<at::Tensor, at::Tensor> ball_query_partial_dense(at::Tensor x, at::Ten
7172
batch_y = degree(batch_y, batch_size);
7273
batch_y = at::cat({at::zeros(1, batch_y.options()), batch_y.cumsum(0)}, 0);
7374

74-
query_ball_point_kernel_partial_wrapper(batch_size, x.size(0), y.size(0), radius, nsample,
75-
x.DATA_PTR<float>(), y.DATA_PTR<float>(),
76-
batch_x.DATA_PTR<int64_t>(), batch_y.DATA_PTR<int64_t>(),
77-
idx.DATA_PTR<int64_t>(), dist.DATA_PTR<float>());
75+
query_ball_point_kernel_partial_wrapper(
76+
batch_size, x.size(0), y.size(0), radius, nsample, x.DATA_PTR<float>(), y.DATA_PTR<float>(),
77+
batch_x.DATA_PTR<int64_t>(), batch_y.DATA_PTR<int64_t>(), idx.DATA_PTR<int64_t>(),
78+
dist.DATA_PTR<float>());
7879

7980
return std::make_pair(idx, dist);
8081
}

cuda/src/ball_query_gpu.cu

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__global__ void query_ball_point_kernel_dense(int b, int n, int m, float radius, int nsample,
1010
const float* __restrict__ new_xyz,
1111
const float* __restrict__ xyz,
12-
int64_t* __restrict__ idx_out,
12+
int64_t* __restrict__ idx_out,
1313
float* __restrict__ dist_out)
1414
{
1515
int batch_index = blockIdx.x;
@@ -51,10 +51,13 @@ __global__ void query_ball_point_kernel_dense(int b, int n, int m, float radius,
5151
}
5252
}
5353

54-
__global__ void query_ball_point_kernel_partial_dense(
55-
int size_x, int size_y, float radius, int nsample, const float* __restrict__ x,
56-
const float* __restrict__ y, const int64_t* __restrict__ batch_x, const int64_t* __restrict__ batch_y,
57-
int64_t* __restrict__ idx_out, float* __restrict__ dist_out)
54+
__global__ void query_ball_point_kernel_partial_dense(int size_x, int size_y, float radius,
55+
int nsample, const float* __restrict__ x,
56+
const float* __restrict__ y,
57+
const int64_t* __restrict__ batch_x,
58+
const int64_t* __restrict__ batch_y,
59+
int64_t* __restrict__ idx_out,
60+
float* __restrict__ dist_out)
5861
{
5962
// taken from
6063
// https://github.com/rusty1s/pytorch_cluster/blob/master/cuda/radius_kernel.cu
@@ -67,7 +70,7 @@ __global__ void query_ball_point_kernel_partial_dense(
6770
const ptrdiff_t end_idx_y = batch_y[batch_idx + 1];
6871
float radius2 = radius * radius;
6972

70-
for (ptrdiff_t n_y = start_idx_y + threadIdx.x; n_y < end_idx_y; n_y += blockDim.x)
73+
for (ptrdiff_t n_y = start_idx_y + threadIdx.x; n_y < end_idx_y; n_y += blockDim.x)
7174
{
7275
int64_t count = 0;
7376
for (ptrdiff_t n_x = start_idx_x; n_x < end_idx_x; n_x++)
@@ -92,19 +95,21 @@ __global__ void query_ball_point_kernel_partial_dense(
9295
}
9396

9497
void query_ball_point_kernel_dense_wrapper(int b, int n, int m, float radius, int nsample,
95-
const float* new_xyz, const float* xyz, int64_t* idx,float* dist_out)
98+
const float* new_xyz, const float* xyz, int64_t* idx,
99+
float* dist_out)
96100
{
97101
cudaStream_t stream = at::cuda::getCurrentCUDAStream();
98102
query_ball_point_kernel_dense<<<b, opt_n_threads(m), 0, stream>>>(b, n, m, radius, nsample,
99-
new_xyz, xyz, idx,dist_out);
103+
new_xyz, xyz, idx, dist_out);
100104

101105
CUDA_CHECK_ERRORS();
102106
}
103107

104-
void query_ball_point_kernel_partial_wrapper(int64_t batch_size, int size_x, int size_y, float radius,
105-
int nsample, const float* x, const float* y,
106-
const int64_t* batch_x, const int64_t* batch_y,
107-
int64_t* idx_out, float* dist_out)
108+
void query_ball_point_kernel_partial_wrapper(int64_t batch_size, int size_x, int size_y,
109+
float radius, int nsample, const float* x,
110+
const float* y, const int64_t* batch_x,
111+
const int64_t* batch_y, int64_t* idx_out,
112+
float* dist_out)
108113
{
109114
query_ball_point_kernel_partial_dense<<<batch_size, TOTAL_THREADS_SPARSE>>>(
110115
size_x, size_y, radius, nsample, x, y, batch_x, batch_y, idx_out, dist_out);

cuda/src/metrics.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#include "utils.h"
44

55
void instance_iou_kernel_wrapper(int64_t total_gt_instances, int64_t max_gt_instances,
6-
const int64_t* nInstance, int nProposal, const int64_t* proposals_idx,
7-
const int64_t* proposals_offset, const int64_t* instance_labels,
6+
const int64_t* nInstance, int nProposal,
7+
const int64_t* proposals_idx, const int64_t* proposals_offset,
8+
const int64_t* instance_labels,
89
const int64_t* offset_num_gt_instances, const int64_t* batch,
910
const int64_t* instance_pointnum, float* proposals_iou);
1011

@@ -41,9 +42,10 @@ at::Tensor instance_iou_cuda(at::Tensor instance_idx, at::Tensor instance_offset
4142
at::cat({at::zeros(1, num_gt_instances.options()), num_gt_instances.cumsum(0)}, 0);
4243
instance_iou_kernel_wrapper(
4344
total_gt_instances[0], max_gt_instances[0], num_gt_instances.DATA_PTR<int64_t>(),
44-
num_proposed_instances, instance_idx.DATA_PTR<int64_t>(), instance_offsets.DATA_PTR<int64_t>(),
45-
gt_instances.DATA_PTR<int64_t>(), offset_num_gt_instances.DATA_PTR<int64_t>(),
46-
batch.DATA_PTR<int64_t>(), gt_instance_sizes.DATA_PTR<int64_t>(), output.DATA_PTR<float>());
45+
num_proposed_instances, instance_idx.DATA_PTR<int64_t>(),
46+
instance_offsets.DATA_PTR<int64_t>(), gt_instances.DATA_PTR<int64_t>(),
47+
offset_num_gt_instances.DATA_PTR<int64_t>(), batch.DATA_PTR<int64_t>(),
48+
gt_instance_sizes.DATA_PTR<int64_t>(), output.DATA_PTR<float>());
4749

4850
return output;
4951
}

cuda/src/metrics_gpu.cu

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
__global__ void instance_iou_cuda_kernel(
1010
int64_t total_gt_instances, const int64_t* __restrict__ nInstance, int nProposal,
1111
const int64_t* __restrict__ proposals_idx, const int64_t* __restrict__ proposals_offset,
12-
const int64_t* __restrict__ instance_labels, const int64_t* __restrict__ offset_num_gt_instances,
13-
const int64_t* __restrict__ batch, const int64_t* __restrict__ instance_pointnum,
14-
float* proposals_iou)
12+
const int64_t* __restrict__ instance_labels,
13+
const int64_t* __restrict__ offset_num_gt_instances, const int64_t* __restrict__ batch,
14+
const int64_t* __restrict__ instance_pointnum, float* proposals_iou)
1515
{
1616
for (int proposal_id = blockIdx.x; proposal_id < nProposal; proposal_id += gridDim.x)
1717
{
@@ -48,8 +48,9 @@ __global__ void instance_iou_cuda_kernel(
4848
// input: instance_pointnum (total_nInst), int
4949
// output: proposals_iou (nProposal, total_nInst), float
5050
void instance_iou_kernel_wrapper(int64_t total_gt_instances, int64_t max_gt_instances,
51-
const int64_t* nInstance, int nProposal, const int64_t* proposals_idx,
52-
const int64_t* proposals_offset, const int64_t* instance_labels,
51+
const int64_t* nInstance, int nProposal,
52+
const int64_t* proposals_idx, const int64_t* proposals_offset,
53+
const int64_t* instance_labels,
5354
const int64_t* offset_num_gt_instances, const int64_t* batch,
5455
const int64_t* instance_pointnum, float* proposals_iou)
5556
{

setup.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def get_ext_modules():
2828
extra_compile_args += ["-DVERSION_GE_1_3"]
2929

3030
ext_src_root = "cuda"
31-
ext_sources = glob.glob("{}/src/*.cpp".format(ext_src_root)) + glob.glob(
32-
"{}/src/*.cu".format(ext_src_root)
33-
)
31+
ext_sources = glob.glob("{}/src/*.cpp".format(ext_src_root)) + glob.glob("{}/src/*.cu".format(ext_src_root))
3432

3533
ext_modules = []
3634
if CUDA_HOME:
@@ -39,10 +37,7 @@ def get_ext_modules():
3937
name="torch_points_kernels.points_cuda",
4038
sources=ext_sources,
4139
include_dirs=["{}/include".format(ext_src_root)],
42-
extra_compile_args={
43-
"cxx": extra_compile_args,
44-
"nvcc": extra_compile_args,
45-
},
40+
extra_compile_args={"cxx": extra_compile_args, "nvcc": extra_compile_args,},
4641
)
4742
)
4843

@@ -86,8 +81,5 @@ def get_cmdclass():
8681
cmdclass=get_cmdclass(),
8782
long_description=long_description,
8883
long_description_content_type="text/markdown",
89-
classifiers=[
90-
"Programming Language :: Python :: 3",
91-
"License :: OSI Approved :: MIT License",
92-
],
84+
classifiers=["Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License",],
9385
)

test/speed_radius.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def test_speed(self):
2323
R = 1
2424
samples = 50
2525

26-
idx, dist = ball_query(R, samples, a, b, mode="PARTIAL_DENSE", batch_x=batch_a, batch_y=batch_b, sort=True)
27-
idx1, dist = ball_query(R, samples, a, b, mode="PARTIAL_DENSE", batch_x=batch_a, batch_y=batch_b, sort=True)
26+
idx, dist = ball_query(R, samples, a, b, mode="PARTIAL_DENSE", batch_x=batch_a, batch_y=batch_b, sort=True,)
27+
idx1, dist = ball_query(R, samples, a, b, mode="PARTIAL_DENSE", batch_x=batch_a, batch_y=batch_b, sort=True,)
2828
print(time.time() - start)
2929
torch.testing.assert_allclose(idx1, idx)
3030

@@ -40,5 +40,6 @@ def test_speed(self):
4040
# if p >= 0 and p < len(batch_a):
4141
# assert p in idx3_sk[i]
4242

43+
4344
if __name__ == "__main__":
44-
unittest.main()
45+
unittest.main()

test/test_chamfer_dist.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,14 @@ def test_chamfer_dist_grad(self):
2626

2727
@run_if_cuda
2828
def test_chamfer_dist(self):
29-
xyz1 = torch.from_numpy(np.array([[
30-
[0, 0, 0],
31-
[1, 1, 1],
32-
[2, 0, 1]
33-
]])).float()
29+
xyz1 = torch.from_numpy(np.array([[[0, 0, 0], [1, 1, 1], [2, 0, 1]]])).float()
3430
xyz2 = torch.from_numpy(np.array([[[1, 0, 0], [1, 2, 1]]])).float()
3531
dist = chamfer_dist(xyz1.cuda(), xyz2.cuda())
3632
self.assertAlmostEqual(dist.item(), 2.333333, places=5)
3733

3834
@run_if_cuda
3935
def test_chamfer_dist_ignore_zeros(self):
40-
xyz1 = torch.from_numpy(np.array([[
41-
[0, 0, 0],
42-
[1, 1, 1],
43-
[2, 0, 1]
44-
]])).float()
36+
xyz1 = torch.from_numpy(np.array([[[0, 0, 0], [1, 1, 1], [2, 0, 1]]])).float()
4537
xyz2 = torch.from_numpy(np.array([[[1, 0, 0], [1, 2, 1]]])).float()
4638
dist = chamfer_dist(xyz1.cuda(), xyz2.cuda(), True)
4739
self.assertAlmostEqual(dist.item(), 3.0, places=5)

test/test_cluster.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@
1212
class TestGrow(unittest.TestCase):
1313
def setUp(self):
1414
self.pos = torch.tensor(
15-
[
16-
[0, 0, 0],
17-
[1, 0, 0],
18-
[2, 0, 0],
19-
[10, 0, 0],
20-
[0, 0, 0],
21-
[1, 0, 0],
22-
[2, 0, 0],
23-
[10, 0, 0],
24-
]
15+
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [10, 0, 0], [0, 0, 0], [1, 0, 0], [2, 0, 0], [10, 0, 0],]
2516
)
2617
self.batch = torch.tensor([0, 0, 0, 0, 1, 1, 1, 1])
2718
self.labels = torch.tensor([0, 0, 1, 1, 0, 1, 1, 10])
@@ -34,9 +25,7 @@ def test_simple(self):
3425
self.assertEqual(clusters, [[0, 1, 2], [4, 5, 6]])
3526

3627
def test_region_grow(self):
37-
cluster_idx = region_grow(
38-
self.pos, self.labels, self.batch, radius=2, min_cluster_size=1
39-
)
28+
cluster_idx = region_grow(self.pos, self.labels, self.batch, radius=2, min_cluster_size=1)
4029
self.assertEqual(len(cluster_idx), 6)
4130
torch.testing.assert_allclose(cluster_idx[0], torch.tensor([0, 1]))
4231
torch.testing.assert_allclose(cluster_idx[1], torch.tensor([4]))

test/test_grouping.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def test_simple(self):
3737
npt.assert_array_equal(expected, cpu_output)
3838

3939
if torch.cuda.is_available():
40-
npt.assert_array_equal(grouping_operation(features.cuda(), idx.cuda()).detach().cpu().numpy(), expected)
40+
npt.assert_array_equal(
41+
grouping_operation(features.cuda(), idx.cuda()).detach().cpu().numpy(), expected,
42+
)
4143

4244

4345
if __name__ == "__main__":

test/test_metrics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def test_simple(self, cuda=False):
2424
proposed_instances = [c.cuda() for c in proposed_instances]
2525
gt_instances = gt_instances.cuda()
2626
ious = instance_iou(proposed_instances, gt_instances)
27-
torch.testing.assert_allclose(ious.cpu(), torch.tensor([[1, 0, 0], [0, 2 / 3.0, 0], [0, 1.0 / 4.0, 1.0 / 2.0]]))
27+
torch.testing.assert_allclose(
28+
ious.cpu(), torch.tensor([[1, 0, 0], [0, 2 / 3.0, 0], [0, 1.0 / 4.0, 1.0 / 2.0]]),
29+
)
2830

2931
def test_batch(self, cuda=False):
3032
gt_instances = torch.tensor([1, 2, 1, 2, 2, 3, 0])

0 commit comments

Comments
 (0)