subtitlemaker 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ """SubtitleMaker: generate subtitles from media files with Faster-Whisper."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """Allow `python -m subtitlemaker`."""
2
+
3
+ from .cli import main
4
+
5
+ raise SystemExit(main())
subtitlemaker/_cuda.py ADDED
@@ -0,0 +1,91 @@
1
+ """CUDA library setup for CTranslate2.
2
+
3
+ CTranslate2 needs the CUDA 12 runtime libraries (cuBLAS and cuDNN 9). They
4
+ can come from the system, or from the pip packages installed by the
5
+ `subtitlemaker[cuda]` extra. The dynamic loader only searches
6
+ LD_LIBRARY_PATH as it was when the process started, so instead of
7
+ re-executing the interpreter we load the pip copies ourselves, early, with
8
+ global visibility. CTranslate2 later asks for them by name and the loader
9
+ hands back the copies already in memory.
10
+ """
11
+
12
+ import ctypes
13
+ import logging
14
+ import sys
15
+ from pathlib import Path
16
+
17
+ log = logging.getLogger(__name__)
18
+
19
+ # Load order matters: cuBLAS needs cuBLASLt, cuDNN's front library goes first.
20
+ _PACKAGES = (
21
+ ("nvidia.cublas", ("libcublasLt.so.12", "libcublas.so.12")),
22
+ ("nvidia.cudnn", ("libcudnn.so.9",)),
23
+ )
24
+
25
+ _loaded = None
26
+
27
+
28
+ def _package_lib_dir(package):
29
+ """Directory holding the shared libraries of an nvidia-* pip package."""
30
+
31
+ try:
32
+ module = __import__(package + ".lib", fromlist=["lib"])
33
+
34
+ except ImportError:
35
+ return None
36
+
37
+ paths = list(getattr(module, "__path__", []))
38
+
39
+ return Path(paths[0]) if paths else None
40
+
41
+
42
+ def preload_cuda_libs():
43
+ """
44
+ Load cuBLAS and cuDNN from the pip nvidia-* packages, if installed.
45
+
46
+ Returns True if the libraries are available this way, False if not
47
+ (not on Linux, or the `[cuda]` extra is not installed). Safe to call
48
+ repeatedly; it never raises for missing packages. A False result does
49
+ not mean CUDA is unusable, system libraries may still be found.
50
+ """
51
+
52
+ global _loaded
53
+
54
+ if _loaded is not None:
55
+ return _loaded
56
+
57
+ if not sys.platform.startswith("linux"):
58
+ _loaded = False
59
+ return _loaded
60
+
61
+ found_any = False
62
+
63
+ for package, libraries in _PACKAGES:
64
+
65
+ directory = _package_lib_dir(package)
66
+
67
+ if directory is None:
68
+ log.debug("%s is not installed", package)
69
+ continue
70
+
71
+ for library in libraries:
72
+
73
+ path = directory / library
74
+
75
+ if not path.exists():
76
+ log.debug("%s not found", path)
77
+ continue
78
+
79
+ try:
80
+ ctypes.CDLL(str(path), mode=ctypes.RTLD_GLOBAL)
81
+
82
+ except OSError as e:
83
+ log.debug("couldn't load %s: %s", path, e)
84
+ continue
85
+
86
+ log.debug("preloaded %s", path)
87
+ found_any = True
88
+
89
+ _loaded = found_any
90
+
91
+ return _loaded