File tree Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change
1
+ import ctypes
2
+ import os
3
+ import sys
4
+ from warnings import warn
5
+
1
6
import torch
2
7
3
8
from ._internally_replaced_utils import _get_extension_path
@@ -62,4 +67,22 @@ def _check_cuda_version():
62
67
return _version
63
68
64
69
70
+ def _load_library (lib_name ):
71
+ lib_path = _get_extension_path (lib_name )
72
+ # On Windows Python-3.8+ has `os.add_dll_directory` call,
73
+ # which is called from _get_extension_path to configure dll search path
74
+ # Condition below adds a workaround for older versions by
75
+ # explicitly calling `LoadLibraryExW` with the following flags:
76
+ # - LOAD_LIBRARY_SEARCH_DEFAULT_DIRS (0x1000)
77
+ # - LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR (0x100)
78
+ if os .name == "nt" and sys .version_info < (3 , 8 ):
79
+ _kernel32 = ctypes .WinDLL ("kernel32.dll" , use_last_error = True )
80
+ if hasattr (_kernel32 , "LoadLibraryExW" ):
81
+ _kernel32 .LoadLibraryExW (lib_path , None , 0x00001100 )
82
+ else :
83
+ warn ("LoadLibraryExW is missing in kernel32.dll" )
84
+
85
+ torch .ops .load_library (lib_path )
86
+
87
+
65
88
_check_cuda_version ()
Original file line number Diff line number Diff line change 8
8
import numpy as np
9
9
import torch
10
10
11
- from .._internally_replaced_utils import _get_extension_path
11
+ from ..extension import _load_library
12
12
13
13
14
14
try :
15
- lib_path = _get_extension_path ('video_reader' )
16
- torch .ops .load_library (lib_path )
15
+ _load_library ("video_reader" )
17
16
_HAS_VIDEO_OPT = True
18
17
except (ImportError , OSError ):
19
18
_HAS_VIDEO_OPT = False
Original file line number Diff line number Diff line change 1
1
import torch
2
2
from enum import Enum
3
+ from warnings import warn
3
4
4
- from .._internally_replaced_utils import _get_extension_path
5
+ from ..extension import _load_library
5
6
6
7
7
8
try :
8
- lib_path = _get_extension_path ('image' )
9
- torch .ops .load_library (lib_path )
10
- except (ImportError , OSError ):
11
- pass
9
+ _load_library ("image" )
10
+ except (ImportError , OSError ) as e :
11
+ warn (f"Failed to load image Python extension: { e } " )
12
12
13
13
14
14
class ImageReadMode (Enum ):
You can’t perform that action at this time.
0 commit comments