traveller59 / spconv

Spatial Sparse Convolution Library
Apache License 2.0
1.89k stars 366 forks source link

import spconv.pytorch will slow down torch.multiprocessing.Pool().apply_async() #699

Open dwbzxc opened 6 months ago

dwbzxc commented 6 months ago

Hi, when I try using spconv-cu116(2.3.6) and torch.multiprocessing.Pool().apply_async() in 1.13 Pytorch version together, I find that the time for executing multiprocess mission is much longer after importing spconv (4.728647470474243 seconds before importing spconv, 11.85951018333435 after importing spconv, while the singleprocess takes 6.01546311378479 seconds to run the codes below with a NVIDIA GeForce 4090 GPU). Do you have any ideas how to solve this problem? Thanks!

import spconv.pytorch as spconv
import time
import torch.multiprocessing as mp

def multipreocess_func(x, y):
    time.sleep(1.5)
    return x, y, x + y

if __name__ == '__main__':
    torch.multiprocessing.set_start_method('spawn')
    with mp.Pool(processes=4) as pool:
        pytorch_device = torch.device('cuda:0')
        num = torch.ones(1)

        a = time.time()
        res = [pool.apply_async(multipreocess_func, (num, i)) for i in range(4)]
        for i, x in enumerate(res):
            pam_x = x.get()[0]
            pam_y = x.get()[1]
            pam_xy = x.get()[2]
            print(f"{pam_x},{pam_y},{pam_xy}")
        b = time.time()

        c = time.time()
        for i in range(4):
            res = multipreocess_func(num, i)
            pam_x = res[0]
            pam_y = res[1]
            pam_xy = res[2]
            print(f"{pam_x},{pam_y},{pam_xy}")
        d = time.time()
        print(f"multiprocess time:{b - a}, singleprocess time:{d - c}")