File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -100,4 +100,19 @@ def _init_extension():
100
100
pass
101
101
102
102
103
+ def _check_cuda_version ():
104
+ version = torch .ops .torchaudio .cuda_version ()
105
+ if version != - 1 and torch .version .cuda is not None :
106
+ version_str = str (version )
107
+ ta_version = f"{ version_str [:- 3 ]} .{ version_str [- 2 ]} "
108
+ t_version = torch .version .cuda
109
+ if ta_version != t_version :
110
+ raise RuntimeError (
111
+ "Detected that PyTorch and TorchAudio were compiled with different CUDA versions. "
112
+ f"PyTorch has CUDA version { t_version } whereas TorchAudio has CUDA version { ta_version } . "
113
+ "Please install the TorchAudio version that matches your PyTorch version."
114
+ )
115
+
116
+
103
117
_init_extension ()
118
+ _check_cuda_version ()
Original file line number Diff line number Diff line change 1
1
#include < torch/script.h>
2
2
3
+ #ifdef USE_CUDA
4
+ #include < cuda.h>
5
+ #endif
6
+
3
7
namespace torchaudio {
4
8
5
9
namespace {
@@ -30,12 +34,21 @@ bool is_ffmpeg_available() {
30
34
#endif
31
35
}
32
36
37
+ int64_t cuda_version () {
38
+ #ifdef USE_CUDA
39
+ return CUDA_VERSION;
40
+ #else
41
+ return -1 ;
42
+ #endif
43
+ }
44
+
33
45
} // namespace
34
46
35
47
TORCH_LIBRARY_FRAGMENT (torchaudio, m) {
36
48
m.def (" torchaudio::is_sox_available" , &is_sox_available);
37
49
m.def (" torchaudio::is_kaldi_available" , &is_kaldi_available);
38
50
m.def (" torchaudio::is_ffmpeg_available" , &is_ffmpeg_available);
51
+ m.def (" torchaudio::cuda_version" , &cuda_version);
39
52
}
40
53
41
54
} // namespace torchaudio
You can’t perform that action at this time.
0 commit comments