dmlc--dgl
901e0c24d6
* test * profile * opt * Some fix * upd * upd * Add multigpu training support for graphsage unsupervised * Add share neg * Fix * Add profile * turn on eval * upd * Fix * performance opt Co-authored-by: Ubuntu <ubuntu@ip-172-31-12-103.ec2.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-14-53.ec2.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-19-29.ec2.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-2-50.ec2.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-52-181.ec2.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-87-240.ec2.internal>
38 行
1.2 KiB
Python
38 行
1.2 KiB
Python
#### Miscellaneous functions
|
|
|
|
# According to https://github.com/pytorch/pytorch/issues/17199, this decorator
|
|
# is necessary to make fork() and openmp work together.
|
|
#
|
|
# TODO: confirm if this is necessary for MXNet and Tensorflow. If so, we need
|
|
# to standardize worker process creation since our operators are implemented with
|
|
# OpenMP.
|
|
|
|
import torch.multiprocessing as mp
|
|
from _thread import start_new_thread
|
|
from functools import wraps
|
|
import traceback
|
|
|
|
def thread_wrapped_func(func):
|
|
"""
|
|
Wraps a process entry point to make it work with OpenMP.
|
|
"""
|
|
@wraps(func)
|
|
def decorated_function(*args, **kwargs):
|
|
queue = mp.Queue()
|
|
def _queue_result():
|
|
exception, trace, res = None, None, None
|
|
try:
|
|
res = func(*args, **kwargs)
|
|
except Exception as e:
|
|
exception = e
|
|
trace = traceback.format_exc()
|
|
queue.put((res, exception, trace))
|
|
|
|
start_new_thread(_queue_result, ())
|
|
result, exception, trace = queue.get()
|
|
if exception is None:
|
|
return result
|
|
else:
|
|
assert isinstance(exception, Exception)
|
|
raise exception.__class__(trace)
|
|
return decorated_function |