Skip to content

Commit ee38977

Browse files
Zhijian Liugithub-actions
andauthored
Rename torchsparse_cuda as torchsparse_backend (#49)
* Rename `torchsparse_cuda` as `torchsparse_backend` Co-authored-by: github-actions <[email protected]>
1 parent 26fc153 commit ee38977

File tree

11 files changed

+49
-44
lines changed

11 files changed

+49
-44
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
version=__version__,
6666
packages=find_packages(),
6767
ext_modules=[
68-
extension_type('torchsparse_cuda',
68+
extension_type('torchsparse_backend',
6969
file_lis,
7070
extra_compile_args=extra_compile_args)
7171
],

torchsparse/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
__version__ = '1.1.0'
66

7+
78
def cat(input_list, dim=1):
89
assert len(input_list) > 0
910
inputs = input_list[0]
1011
features = inputs.F
1112
coords = inputs.C
1213
cur_stride = inputs.s
13-
output_tensor = SparseTensor(torch.cat([inputs.F for inputs in input_list], 1), coords, cur_stride)
14+
output_tensor = SparseTensor(
15+
torch.cat([inputs.F for inputs in input_list], 1), coords, cur_stride)
1416
output_tensor.coord_maps = inputs.coord_maps
1517
output_tensor.kernel_maps = inputs.kernel_maps
1618
return output_tensor

torchsparse/nn/functional/conv.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import copy
22

33
import torch
4-
import torchsparse_cuda
4+
import torchsparse_backend
55
from torch.autograd import Function
66
from torchsparse import *
77
from torchsparse.nn.functional.convert_neighbor_map import *
@@ -35,9 +35,9 @@ def forward(ctx,
3535
device=features.device)
3636

3737
if 'cuda' in str(features.device):
38-
torchsparse_cuda.sparseconv_forward(features, out, kernel,
39-
neighbor_map, neighbor_offset,
40-
transpose)
38+
torchsparse_backend.sparseconv_forward(features, out, kernel,
39+
neighbor_map,
40+
neighbor_offset, transpose)
4141
else:
4242
# use the native pytorch XLA APIs for the TPU.
4343
cur_st = 0
@@ -69,10 +69,11 @@ def backward(ctx, grad_out):
6969
grad_kernel = torch.zeros(K, c_in, c_out, device=kernel.device)
7070

7171
if 'cuda' in str(features.device):
72-
torchsparse_cuda.sparseconv_backward(features, grad_features,
73-
grad_out.contiguous(), kernel,
74-
grad_kernel, neighbor_map,
75-
neighbor_offset, transpose)
72+
torchsparse_backend.sparseconv_backward(features, grad_features,
73+
grad_out.contiguous(),
74+
kernel, grad_kernel,
75+
neighbor_map,
76+
neighbor_offset, transpose)
7677
else:
7778
raise NotImplementedError
7879
return grad_features, grad_kernel, None, None, None, None

torchsparse/nn/functional/convert_neighbor_map.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import torch
2-
import torchsparse_cuda
2+
import torchsparse_backend
33
from torch.autograd import Function
44

55

@@ -8,14 +8,14 @@ class ConvertNeighborMap(Function):
88
def forward(ctx, neighbor_map):
99
idx_batch, idx_point = torch.where(neighbor_map != -1)
1010
if 'cuda' in str(neighbor_map.device):
11-
map_converted = torchsparse_cuda.convert_map_forward(
11+
map_converted = torchsparse_backend.convert_map_forward(
1212
neighbor_map.int(), idx_batch.int(), idx_point.int())
1313
elif 'cpu' in str(neighbor_map.device):
14-
map_converted = torchsparse_cuda.cpu_convert_map_forward(
14+
map_converted = torchsparse_backend.cpu_convert_map_forward(
1515
neighbor_map.int(), idx_batch.int(), idx_point.int())
1616
else:
1717
device = neighbor_map.device
18-
map_converted = torchsparse_cuda.cpu_convert_map_forward(
18+
map_converted = torchsparse_backend.cpu_convert_map_forward(
1919
neighbor_map.int().cpu(),
2020
idx_batch.int().cpu(),
2121
idx_point.int().cpu())

torchsparse/nn/functional/count.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import torchsparse_cuda
1+
import torchsparse_backend
22
from torch.autograd import Function
33

44
__all__ = ['spcount']
@@ -8,9 +8,9 @@ class CountGPU(Function):
88
@staticmethod
99
def forward(ctx, idx, num):
1010
if 'cuda' in str(idx.device):
11-
outs = torchsparse_cuda.count_forward(idx.contiguous(), num)
11+
outs = torchsparse_backend.count_forward(idx.contiguous(), num)
1212
else:
13-
outs = torchsparse_cuda.cpu_count_forward(idx.contiguous(), num)
13+
outs = torchsparse_backend.cpu_count_forward(idx.contiguous(), num)
1414
return outs
1515

1616

torchsparse/nn/functional/devox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import torch
2-
import torchsparse_cuda
2+
import torchsparse_backend
33
from torch.autograd import Function
44

55
__all__ = ['spdevoxelize', 'calc_ti_weights']
@@ -63,11 +63,11 @@ class DevoxelizationGPU(Function):
6363
@staticmethod
6464
def forward(ctx, feat, indices, weights):
6565
if 'cuda' in str(feat.device):
66-
out = torchsparse_cuda.devoxelize_forward(
66+
out = torchsparse_backend.devoxelize_forward(
6767
feat.contiguous(),
6868
indices.contiguous().int(), weights.contiguous())
6969
else:
70-
out = torchsparse_cuda.cpu_devoxelize_forward(
70+
out = torchsparse_backend.cpu_devoxelize_forward(
7171
feat.contiguous(),
7272
indices.contiguous().int(), weights.contiguous())
7373

@@ -81,10 +81,10 @@ def backward(ctx, grad_out):
8181
indices, weights, n = ctx.for_backwards
8282

8383
if 'cuda' in str(grad_out.device):
84-
grad_features = torchsparse_cuda.devoxelize_backward(
84+
grad_features = torchsparse_backend.devoxelize_backward(
8585
grad_out.contiguous(), indices, weights, n)
8686
else:
87-
grad_features = torchsparse_cuda.cpu_devoxelize_backward(
87+
grad_features = torchsparse_backend.cpu_devoxelize_backward(
8888
grad_out.contiguous(), indices, weights, n)
8989

9090
return grad_features, None, None

torchsparse/nn/functional/downsample.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import torch
2-
import torchsparse_cuda
2+
import torchsparse_backend
33
from torch.autograd import Function
44
from torchsparse.nn.functional.hash import *
55

@@ -24,16 +24,16 @@ def forward(ctx, coords, ratio):
2424
# gpu
2525
if 'cuda' in str(coords.device):
2626
uq_coords = torch.round(
27-
torchsparse_cuda.insertion_forward(coords_new.float(), inv,
28-
cnt))
27+
torchsparse_backend.insertion_forward(coords_new.float(), inv,
28+
cnt))
2929
elif 'cpu' in str(coords.device):
3030
uq_coords = torch.round(
31-
torchsparse_cuda.cpu_insertion_forward(coords_new.float(), inv,
32-
cnt))
31+
torchsparse_backend.cpu_insertion_forward(
32+
coords_new.float(), inv, cnt))
3333
else:
3434
device = coords.device
3535
uq_coords = torch.round(
36-
torchsparse_cuda.cpu_insertion_forward(
36+
torchsparse_backend.cpu_insertion_forward(
3737
coords_new.float().cpu(), inv.cpu(), cnt.cpu()))
3838
uq_coords = uq_coords.to(device)
3939
uq_coords = uq_coords.int()

torchsparse/nn/functional/hash.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import torchsparse_cuda
1+
import torchsparse_backend
22
from torch.autograd import Function
33

44
__all__ = ['sphash']
@@ -8,28 +8,28 @@ class HashGPU(Function):
88
@staticmethod
99
def forward(ctx, idx):
1010
if 'cuda' in str(idx.device):
11-
return torchsparse_cuda.hash_forward(idx.contiguous())
11+
return torchsparse_backend.hash_forward(idx.contiguous())
1212
elif 'cpu' in str(idx.device):
13-
return torchsparse_cuda.cpu_hash_forward(idx.int().contiguous())
13+
return torchsparse_backend.cpu_hash_forward(idx.int().contiguous())
1414
else:
1515
device = idx.device
16-
return torchsparse_cuda.cpu_hash_forward(
16+
return torchsparse_backend.cpu_hash_forward(
1717
idx.int().contiguous().cpu()).to(device)
1818

1919

2020
class KernelHashGPU(Function):
2121
@staticmethod
2222
def forward(ctx, idx, koffset):
2323
if 'cuda' in str(idx.device):
24-
return torchsparse_cuda.kernel_hash_forward(
24+
return torchsparse_backend.kernel_hash_forward(
2525
idx.contiguous(), koffset.contiguous())
2626
elif 'cpu' in str(idx.device):
27-
return torchsparse_cuda.cpu_kernel_hash_forward(
27+
return torchsparse_backend.cpu_kernel_hash_forward(
2828
idx.int().contiguous(),
2929
koffset.int().contiguous())
3030
else:
3131
device = idx.device
32-
return torchsparse_cuda.cpu_kernel_hash_forward(
32+
return torchsparse_backend.cpu_kernel_hash_forward(
3333
idx.int().contiguous().cpu(),
3434
koffset.int().contiguous().cpu()).to(device)
3535

torchsparse/nn/functional/query.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import torch
2-
import torchsparse_cuda
2+
import torchsparse_backend
33
from torch.autograd import Function
44

55
__all__ = ['sphashquery']
@@ -18,16 +18,16 @@ def forward(ctx, hash_query, hash_target):
1818
dtype=torch.long)
1919

2020
if 'cuda' in str(hash_query.device):
21-
out, key_buf, val_buf, key = torchsparse_cuda.query_forward(
21+
out, key_buf, val_buf, key = torchsparse_backend.query_forward(
2222
hash_query.view(-1).contiguous(), hash_target.contiguous(),
2323
idx_target)
2424
elif 'cpu' in str(hash_query.device):
25-
out = torchsparse_cuda.cpu_query_forward(
25+
out = torchsparse_backend.cpu_query_forward(
2626
hash_query.view(-1).contiguous(), hash_target.contiguous(),
2727
idx_target)
2828
else:
2929
device = hash_query.device
30-
out = torchsparse_cuda.cpu_query_forward(
30+
out = torchsparse_backend.cpu_query_forward(
3131
hash_query.view(-1).contiguous().cpu(),
3232
hash_target.contiguous().cpu(), idx_target.cpu()).to(device)
3333

torchsparse/nn/functional/voxelize.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import torchsparse_cuda
1+
import torchsparse_backend
22
from torch.autograd import Function
33
from torchsparse.nn.functional.hash import *
44

@@ -8,15 +8,16 @@
88
class VoxelizeGPU(Function):
99
@staticmethod
1010
def forward(ctx, feat, idx, cnt):
11-
out = torchsparse_cuda.insertion_forward(feat.float().contiguous(),
12-
idx.int().contiguous(), cnt)
11+
out = torchsparse_backend.insertion_forward(feat.float().contiguous(),
12+
idx.int().contiguous(),
13+
cnt)
1314
ctx.for_backwards = (idx.int().contiguous(), cnt, feat.shape[0])
1415
return out
1516

1617
@staticmethod
1718
def backward(ctx, top_grad):
1819
idx, cnt, N = ctx.for_backwards
19-
bottom_grad = torchsparse_cuda.insertion_backward(
20+
bottom_grad = torchsparse_backend.insertion_backward(
2021
top_grad.float().contiguous(), idx, cnt, N)
2122
return bottom_grad, None, None
2223

0 commit comments

Comments
 (0)