Skip to content

Commit

Permalink
[BE] Delete torch._dl extension (pytorch#84361)
Browse files Browse the repository at this point in the history
And lots of complexity around the availability of RTLD_GLOBAL flags in `os` module
As this flag is always present since Python-3.3, see https://docs.python.org/3/library/os.html#os.RTLD_GLOBAL

Fixes pytorch#84351

Pull Request resolved: pytorch#84361
Approved by: https://github.com/kit1980
  • Loading branch information
malfet authored and pytorchmergebot committed Aug 31, 2022
1 parent cfb9d0d commit 4b8ae04
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 48 deletions.
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,6 @@ def make_relative_rpath_args(path):
extensions.append(C)
extensions.append(C_flatbuffer)

if not IS_WINDOWS:
DL = Extension("torch._dl",
sources=["torch/csrc/dl.c"],
language='c')
extensions.append(DL)

# These extensions are built by cmake and copied manually in build_extensions()
# inside the build_ext implementation
if cmake_cache_vars['BUILD_CAFFE2']:
Expand Down
11 changes: 1 addition & 10 deletions torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,11 @@ def _load_global_deps():
# you load consistently use the same libstdc++, or you may have
# mysterious segfaults.
#
import os as _dl_flags
if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_LAZY'):
try:
# next try if DLFCN exists
import DLFCN as _dl_flags # type: ignore[import, no-redef]
except ImportError:
# as a last attempt, use compile-time constants
import torch._dl as _dl_flags # type: ignore[import, no-redef]
old_flags = sys.getdlopenflags()
sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)
sys.setdlopenflags(os.RTLD_GLOBAL | os.RTLD_LAZY)
from torch._C import * # noqa: F403
sys.setdlopenflags(old_flags)
del old_flags
del _dl_flags

else:
# Easy way. You want this most of the time, because it will prevent
Expand Down
32 changes: 0 additions & 32 deletions torch/csrc/dl.c

This file was deleted.

0 comments on commit 4b8ae04

Please sign in to comment.