sort_bench.py 1.25 KB
Newer Older
yan.yan's avatar
v2.1  
yan.yan committed
1
# Copyright 2021 Yan Yan
2
#
yan.yan's avatar
v2.1  
yan.yan committed
3
4
5
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
6
#
yan.yan's avatar
v2.1  
yan.yan committed
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
yan.yan's avatar
v2.1  
yan.yan committed
9
10
11
12
13
14
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15
16
import numpy as np
from cumm import tensorview as tv
yan.yan's avatar
v2.1  
yan.yan committed
17
from spconv.core_cc.csrc.sparse.all import SpconvOps
18
import pickle
yan.yan's avatar
v2.1  
yan.yan committed
19
20
import torch

21
22
from spconv.pytorch.cppcore import torch_tensor_to_tv

yan.yan's avatar
v2.1  
yan.yan committed
23
24
25
26
27

def main():
    with open("/home/yy/asd.pkl", "rb") as f:
        a_th = pickle.load(f)
    mask_argsort = torch.empty((1, a_th.shape[1]),
28
29
                               dtype=torch.int32,
                               device=a_th.device)
yan.yan's avatar
v2.1  
yan.yan committed
30
31
32
33
34
35
36
37

    a = a_th.cpu().numpy()[0]
    a_tv = torch_tensor_to_tv(a_th)
    mask_argsort_tv = torch_tensor_to_tv(mask_argsort)
    for i in range(10):
        a_tv_1 = a_tv.clone()
        SpconvOps.sort_1d_by_key(a_tv_1[0], mask_argsort_tv[0])

38

yan.yan's avatar
v2.1  
yan.yan committed
39
if __name__ == "__main__":
40
    main()