@@ -41,31 +41,31 @@ public static SystemInfo Get()
41
41
42
42
return new SystemInfo ( platform , GetCudaMajorVersion ( ) , GetVulkanVersion ( ) ) ;
43
43
}
44
-
44
+
45
45
#region Vulkan version
46
46
private static string ? GetVulkanVersion ( )
47
47
{
48
48
// Get Vulkan Summary
49
49
string ? vulkanSummary = GetVulkanSummary ( ) ;
50
-
50
+
51
51
// If we have a Vulkan summary
52
52
if ( vulkanSummary != null )
53
53
{
54
54
// Extract Vulkan version from summary
55
55
string ? vulkanVersion = ExtractVulkanVersionFromSummary ( vulkanSummary ) ;
56
-
56
+
57
57
// If we have a Vulkan version
58
58
if ( vulkanVersion != null )
59
59
{
60
60
// Return the Vulkan version
61
61
return vulkanVersion ;
62
62
}
63
63
}
64
-
64
+
65
65
// Return null if we failed to get the Vulkan version
66
66
return null ;
67
67
}
68
-
68
+
69
69
private static string ? GetVulkanSummary ( )
70
70
{
71
71
// Note: on Linux, this requires `vulkan-tools` to be installed. (`sudo apt install vulkan-tools`)
@@ -102,19 +102,19 @@ public static SystemInfo Get()
102
102
// We have three ways of parsing the Vulkan version from the summary (output is a different between Windows and Linux)
103
103
// For now, I have decided to go with the full version number, and leave it up to the user to parse it further if needed
104
104
// I have left the other patterns in, in case we need them in the future
105
-
105
+
106
106
// Output on linux : 4206847 (1.3.255)
107
107
// Output on windows : 1.3.255
108
108
string pattern = @"apiVersion\s*=\s*([^\r\n]+)" ;
109
-
109
+
110
110
// Output on linux : 4206847
111
111
// Output on windows : 1.3.255
112
112
//string pattern = @"apiVersion\s*=\s*([\d\.]+)";
113
-
113
+
114
114
// Output on linux : 1.3.255
115
115
// Output on windows : 1.3.255
116
116
//string pattern = @"apiVersion\s*=\s*(?:\d+\s*)?(?:\(\s*)?([\d]+\.[\d]+\.[\d]+)(?:\s*\))?";
117
-
117
+
118
118
// Create a Regex object to match the pattern
119
119
Regex regex = new Regex ( pattern ) ;
120
120
@@ -158,24 +158,30 @@ private static int GetCudaMajorVersion()
158
158
}
159
159
else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
160
160
{
161
+ string ? env_version = Environment . GetEnvironmentVariable ( "CUDA_VERSION" ) ;
162
+ if ( env_version is not null )
163
+ {
164
+ return ExtractMajorVersion ( ref env_version ) ;
165
+ }
166
+
161
167
// List of default cuda paths
162
168
string [ ] defaultCudaPaths =
163
169
[
164
170
"/usr/local/bin/cuda" ,
165
171
"/usr/local/cuda" ,
166
172
] ;
167
-
173
+
168
174
// Loop through every default path to find the version
169
175
foreach ( var path in defaultCudaPaths )
170
176
{
171
177
// Attempt to get the version from the path
172
178
version = GetCudaVersionFromPath ( path ) ;
173
-
179
+
174
180
// If a CUDA version is found, break the loop
175
181
if ( ! string . IsNullOrEmpty ( version ) )
176
182
break ;
177
183
}
178
-
184
+
179
185
if ( string . IsNullOrEmpty ( version ) )
180
186
{
181
187
cudaPath = Environment . GetEnvironmentVariable ( "LD_LIBRARY_PATH" ) ;
@@ -197,6 +203,11 @@ private static int GetCudaMajorVersion()
197
203
if ( string . IsNullOrEmpty ( version ) )
198
204
return - 1 ;
199
205
206
+ return ExtractMajorVersion ( ref version ) ;
207
+ }
208
+
209
+ private static int ExtractMajorVersion ( ref string version )
210
+ {
200
211
version = version . Split ( '.' ) [ 0 ] ;
201
212
if ( int . TryParse ( version , out var majorVersion ) )
202
213
return majorVersion ;
0 commit comments