Skip to content

Commit 9922034

Browse files
authored
Fix NVIDIA#962: Don't perform unnecessary version checks (NVIDIA#969)
* Fix NVIDIA#962: Don't perform unnecessary version checks * Fix code having no version checks on Linux * Restore things removed from cybind
1 parent e06b299 commit 9922034

5 files changed

Lines changed: 79 additions & 89 deletions

File tree

cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ cdef int get_cuda_version():
4343
raise NotSupportedError(f'CUDA driver is not found ({err_msg.decode()})')
4444
cuDriverGetVersion = dlsym(handle, "cuDriverGetVersion")
4545
if cuDriverGetVersion == NULL:
46-
raise RuntimeError('something went wrong')
46+
raise RuntimeError('Did not find cuDriverGetVersion symbol in libcuda.so.1')
4747
err = (<int (*)(int*) noexcept nogil>cuDriverGetVersion)(&driver_ver)
4848
if err != 0:
49-
raise RuntimeError('something went wrong')
49+
raise RuntimeError(f'cuDriverGetVersion returned error code {err}')
5050

5151
return driver_ver
5252

@@ -103,7 +103,7 @@ cdef void* __cuFileSetParameterPosixPoolSlabArray = NULL
103103
cdef void* __cuFileGetParameterPosixPoolSlabArray = NULL
104104

105105

106-
cdef void* load_library(const int driver_ver) except* with gil:
106+
cdef void* load_library() except* with gil:
107107
cdef uintptr_t handle = load_nvidia_dynamic_lib("cufile")._handle_uint
108108
return <void*>handle
109109

@@ -116,308 +116,306 @@ cdef int _check_or_init_cufile() except -1 nogil:
116116
cdef void* handle = NULL
117117

118118
with gil, __symbol_lock:
119-
driver_ver = get_cuda_version()
120-
121119
# Load function
122120
global __cuFileHandleRegister
123121
__cuFileHandleRegister = dlsym(RTLD_DEFAULT, 'cuFileHandleRegister')
124122
if __cuFileHandleRegister == NULL:
125123
if handle == NULL:
126-
handle = load_library(driver_ver)
124+
handle = load_library()
127125
__cuFileHandleRegister = dlsym(handle, 'cuFileHandleRegister')
128126

129127
global __cuFileHandleDeregister
130128
__cuFileHandleDeregister = dlsym(RTLD_DEFAULT, 'cuFileHandleDeregister')
131129
if __cuFileHandleDeregister == NULL:
132130
if handle == NULL:
133-
handle = load_library(driver_ver)
131+
handle = load_library()
134132
__cuFileHandleDeregister = dlsym(handle, 'cuFileHandleDeregister')
135133

136134
global __cuFileBufRegister
137135
__cuFileBufRegister = dlsym(RTLD_DEFAULT, 'cuFileBufRegister')
138136
if __cuFileBufRegister == NULL:
139137
if handle == NULL:
140-
handle = load_library(driver_ver)
138+
handle = load_library()
141139
__cuFileBufRegister = dlsym(handle, 'cuFileBufRegister')
142140

143141
global __cuFileBufDeregister
144142
__cuFileBufDeregister = dlsym(RTLD_DEFAULT, 'cuFileBufDeregister')
145143
if __cuFileBufDeregister == NULL:
146144
if handle == NULL:
147-
handle = load_library(driver_ver)
145+
handle = load_library()
148146
__cuFileBufDeregister = dlsym(handle, 'cuFileBufDeregister')
149147

150148
global __cuFileRead
151149
__cuFileRead = dlsym(RTLD_DEFAULT, 'cuFileRead')
152150
if __cuFileRead == NULL:
153151
if handle == NULL:
154-
handle = load_library(driver_ver)
152+
handle = load_library()
155153
__cuFileRead = dlsym(handle, 'cuFileRead')
156154

157155
global __cuFileWrite
158156
__cuFileWrite = dlsym(RTLD_DEFAULT, 'cuFileWrite')
159157
if __cuFileWrite == NULL:
160158
if handle == NULL:
161-
handle = load_library(driver_ver)
159+
handle = load_library()
162160
__cuFileWrite = dlsym(handle, 'cuFileWrite')
163161

164162
global __cuFileDriverOpen
165163
__cuFileDriverOpen = dlsym(RTLD_DEFAULT, 'cuFileDriverOpen')
166164
if __cuFileDriverOpen == NULL:
167165
if handle == NULL:
168-
handle = load_library(driver_ver)
166+
handle = load_library()
169167
__cuFileDriverOpen = dlsym(handle, 'cuFileDriverOpen')
170168

171169
global __cuFileDriverClose_v2
172170
__cuFileDriverClose_v2 = dlsym(RTLD_DEFAULT, 'cuFileDriverClose_v2')
173171
if __cuFileDriverClose_v2 == NULL:
174172
if handle == NULL:
175-
handle = load_library(driver_ver)
173+
handle = load_library()
176174
__cuFileDriverClose_v2 = dlsym(handle, 'cuFileDriverClose_v2')
177175

178176
global __cuFileUseCount
179177
__cuFileUseCount = dlsym(RTLD_DEFAULT, 'cuFileUseCount')
180178
if __cuFileUseCount == NULL:
181179
if handle == NULL:
182-
handle = load_library(driver_ver)
180+
handle = load_library()
183181
__cuFileUseCount = dlsym(handle, 'cuFileUseCount')
184182

185183
global __cuFileDriverGetProperties
186184
__cuFileDriverGetProperties = dlsym(RTLD_DEFAULT, 'cuFileDriverGetProperties')
187185
if __cuFileDriverGetProperties == NULL:
188186
if handle == NULL:
189-
handle = load_library(driver_ver)
187+
handle = load_library()
190188
__cuFileDriverGetProperties = dlsym(handle, 'cuFileDriverGetProperties')
191189

192190
global __cuFileDriverSetPollMode
193191
__cuFileDriverSetPollMode = dlsym(RTLD_DEFAULT, 'cuFileDriverSetPollMode')
194192
if __cuFileDriverSetPollMode == NULL:
195193
if handle == NULL:
196-
handle = load_library(driver_ver)
194+
handle = load_library()
197195
__cuFileDriverSetPollMode = dlsym(handle, 'cuFileDriverSetPollMode')
198196

199197
global __cuFileDriverSetMaxDirectIOSize
200198
__cuFileDriverSetMaxDirectIOSize = dlsym(RTLD_DEFAULT, 'cuFileDriverSetMaxDirectIOSize')
201199
if __cuFileDriverSetMaxDirectIOSize == NULL:
202200
if handle == NULL:
203-
handle = load_library(driver_ver)
201+
handle = load_library()
204202
__cuFileDriverSetMaxDirectIOSize = dlsym(handle, 'cuFileDriverSetMaxDirectIOSize')
205203

206204
global __cuFileDriverSetMaxCacheSize
207205
__cuFileDriverSetMaxCacheSize = dlsym(RTLD_DEFAULT, 'cuFileDriverSetMaxCacheSize')
208206
if __cuFileDriverSetMaxCacheSize == NULL:
209207
if handle == NULL:
210-
handle = load_library(driver_ver)
208+
handle = load_library()
211209
__cuFileDriverSetMaxCacheSize = dlsym(handle, 'cuFileDriverSetMaxCacheSize')
212210

213211
global __cuFileDriverSetMaxPinnedMemSize
214212
__cuFileDriverSetMaxPinnedMemSize = dlsym(RTLD_DEFAULT, 'cuFileDriverSetMaxPinnedMemSize')
215213
if __cuFileDriverSetMaxPinnedMemSize == NULL:
216214
if handle == NULL:
217-
handle = load_library(driver_ver)
215+
handle = load_library()
218216
__cuFileDriverSetMaxPinnedMemSize = dlsym(handle, 'cuFileDriverSetMaxPinnedMemSize')
219217

220218
global __cuFileBatchIOSetUp
221219
__cuFileBatchIOSetUp = dlsym(RTLD_DEFAULT, 'cuFileBatchIOSetUp')
222220
if __cuFileBatchIOSetUp == NULL:
223221
if handle == NULL:
224-
handle = load_library(driver_ver)
222+
handle = load_library()
225223
__cuFileBatchIOSetUp = dlsym(handle, 'cuFileBatchIOSetUp')
226224

227225
global __cuFileBatchIOSubmit
228226
__cuFileBatchIOSubmit = dlsym(RTLD_DEFAULT, 'cuFileBatchIOSubmit')
229227
if __cuFileBatchIOSubmit == NULL:
230228
if handle == NULL:
231-
handle = load_library(driver_ver)
229+
handle = load_library()
232230
__cuFileBatchIOSubmit = dlsym(handle, 'cuFileBatchIOSubmit')
233231

234232
global __cuFileBatchIOGetStatus
235233
__cuFileBatchIOGetStatus = dlsym(RTLD_DEFAULT, 'cuFileBatchIOGetStatus')
236234
if __cuFileBatchIOGetStatus == NULL:
237235
if handle == NULL:
238-
handle = load_library(driver_ver)
236+
handle = load_library()
239237
__cuFileBatchIOGetStatus = dlsym(handle, 'cuFileBatchIOGetStatus')
240238

241239
global __cuFileBatchIOCancel
242240
__cuFileBatchIOCancel = dlsym(RTLD_DEFAULT, 'cuFileBatchIOCancel')
243241
if __cuFileBatchIOCancel == NULL:
244242
if handle == NULL:
245-
handle = load_library(driver_ver)
243+
handle = load_library()
246244
__cuFileBatchIOCancel = dlsym(handle, 'cuFileBatchIOCancel')
247245

248246
global __cuFileBatchIODestroy
249247
__cuFileBatchIODestroy = dlsym(RTLD_DEFAULT, 'cuFileBatchIODestroy')
250248
if __cuFileBatchIODestroy == NULL:
251249
if handle == NULL:
252-
handle = load_library(driver_ver)
250+
handle = load_library()
253251
__cuFileBatchIODestroy = dlsym(handle, 'cuFileBatchIODestroy')
254252

255253
global __cuFileReadAsync
256254
__cuFileReadAsync = dlsym(RTLD_DEFAULT, 'cuFileReadAsync')
257255
if __cuFileReadAsync == NULL:
258256
if handle == NULL:
259-
handle = load_library(driver_ver)
257+
handle = load_library()
260258
__cuFileReadAsync = dlsym(handle, 'cuFileReadAsync')
261259

262260
global __cuFileWriteAsync
263261
__cuFileWriteAsync = dlsym(RTLD_DEFAULT, 'cuFileWriteAsync')
264262
if __cuFileWriteAsync == NULL:
265263
if handle == NULL:
266-
handle = load_library(driver_ver)
264+
handle = load_library()
267265
__cuFileWriteAsync = dlsym(handle, 'cuFileWriteAsync')
268266

269267
global __cuFileStreamRegister
270268
__cuFileStreamRegister = dlsym(RTLD_DEFAULT, 'cuFileStreamRegister')
271269
if __cuFileStreamRegister == NULL:
272270
if handle == NULL:
273-
handle = load_library(driver_ver)
271+
handle = load_library()
274272
__cuFileStreamRegister = dlsym(handle, 'cuFileStreamRegister')
275273

276274
global __cuFileStreamDeregister
277275
__cuFileStreamDeregister = dlsym(RTLD_DEFAULT, 'cuFileStreamDeregister')
278276
if __cuFileStreamDeregister == NULL:
279277
if handle == NULL:
280-
handle = load_library(driver_ver)
278+
handle = load_library()
281279
__cuFileStreamDeregister = dlsym(handle, 'cuFileStreamDeregister')
282280

283281
global __cuFileGetVersion
284282
__cuFileGetVersion = dlsym(RTLD_DEFAULT, 'cuFileGetVersion')
285283
if __cuFileGetVersion == NULL:
286284
if handle == NULL:
287-
handle = load_library(driver_ver)
285+
handle = load_library()
288286
__cuFileGetVersion = dlsym(handle, 'cuFileGetVersion')
289287

290288
global __cuFileGetParameterSizeT
291289
__cuFileGetParameterSizeT = dlsym(RTLD_DEFAULT, 'cuFileGetParameterSizeT')
292290
if __cuFileGetParameterSizeT == NULL:
293291
if handle == NULL:
294-
handle = load_library(driver_ver)
292+
handle = load_library()
295293
__cuFileGetParameterSizeT = dlsym(handle, 'cuFileGetParameterSizeT')
296294

297295
global __cuFileGetParameterBool
298296
__cuFileGetParameterBool = dlsym(RTLD_DEFAULT, 'cuFileGetParameterBool')
299297
if __cuFileGetParameterBool == NULL:
300298
if handle == NULL:
301-
handle = load_library(driver_ver)
299+
handle = load_library()
302300
__cuFileGetParameterBool = dlsym(handle, 'cuFileGetParameterBool')
303301

304302
global __cuFileGetParameterString
305303
__cuFileGetParameterString = dlsym(RTLD_DEFAULT, 'cuFileGetParameterString')
306304
if __cuFileGetParameterString == NULL:
307305
if handle == NULL:
308-
handle = load_library(driver_ver)
306+
handle = load_library()
309307
__cuFileGetParameterString = dlsym(handle, 'cuFileGetParameterString')
310308

311309
global __cuFileSetParameterSizeT
312310
__cuFileSetParameterSizeT = dlsym(RTLD_DEFAULT, 'cuFileSetParameterSizeT')
313311
if __cuFileSetParameterSizeT == NULL:
314312
if handle == NULL:
315-
handle = load_library(driver_ver)
313+
handle = load_library()
316314
__cuFileSetParameterSizeT = dlsym(handle, 'cuFileSetParameterSizeT')
317315

318316
global __cuFileSetParameterBool
319317
__cuFileSetParameterBool = dlsym(RTLD_DEFAULT, 'cuFileSetParameterBool')
320318
if __cuFileSetParameterBool == NULL:
321319
if handle == NULL:
322-
handle = load_library(driver_ver)
320+
handle = load_library()
323321
__cuFileSetParameterBool = dlsym(handle, 'cuFileSetParameterBool')
324322

325323
global __cuFileSetParameterString
326324
__cuFileSetParameterString = dlsym(RTLD_DEFAULT, 'cuFileSetParameterString')
327325
if __cuFileSetParameterString == NULL:
328326
if handle == NULL:
329-
handle = load_library(driver_ver)
327+
handle = load_library()
330328
__cuFileSetParameterString = dlsym(handle, 'cuFileSetParameterString')
331329

332330
global __cuFileDriverClose
333331
__cuFileDriverClose = dlsym(RTLD_DEFAULT, 'cuFileDriverClose')
334332
if __cuFileDriverClose == NULL:
335333
if handle == NULL:
336-
handle = load_library(driver_ver)
334+
handle = load_library()
337335
__cuFileDriverClose = dlsym(handle, 'cuFileDriverClose')
338336

339337
global __cuFileGetParameterMinMaxValue
340338
__cuFileGetParameterMinMaxValue = dlsym(RTLD_DEFAULT, 'cuFileGetParameterMinMaxValue')
341339
if __cuFileGetParameterMinMaxValue == NULL:
342340
if handle == NULL:
343-
handle = load_library(driver_ver)
341+
handle = load_library()
344342
__cuFileGetParameterMinMaxValue = dlsym(handle, 'cuFileGetParameterMinMaxValue')
345343

346344
global __cuFileSetStatsLevel
347345
__cuFileSetStatsLevel = dlsym(RTLD_DEFAULT, 'cuFileSetStatsLevel')
348346
if __cuFileSetStatsLevel == NULL:
349347
if handle == NULL:
350-
handle = load_library(driver_ver)
348+
handle = load_library()
351349
__cuFileSetStatsLevel = dlsym(handle, 'cuFileSetStatsLevel')
352350

353351
global __cuFileGetStatsLevel
354352
__cuFileGetStatsLevel = dlsym(RTLD_DEFAULT, 'cuFileGetStatsLevel')
355353
if __cuFileGetStatsLevel == NULL:
356354
if handle == NULL:
357-
handle = load_library(driver_ver)
355+
handle = load_library()
358356
__cuFileGetStatsLevel = dlsym(handle, 'cuFileGetStatsLevel')
359357

360358
global __cuFileStatsStart
361359
__cuFileStatsStart = dlsym(RTLD_DEFAULT, 'cuFileStatsStart')
362360
if __cuFileStatsStart == NULL:
363361
if handle == NULL:
364-
handle = load_library(driver_ver)
362+
handle = load_library()
365363
__cuFileStatsStart = dlsym(handle, 'cuFileStatsStart')
366364

367365
global __cuFileStatsStop
368366
__cuFileStatsStop = dlsym(RTLD_DEFAULT, 'cuFileStatsStop')
369367
if __cuFileStatsStop == NULL:
370368
if handle == NULL:
371-
handle = load_library(driver_ver)
369+
handle = load_library()
372370
__cuFileStatsStop = dlsym(handle, 'cuFileStatsStop')
373371

374372
global __cuFileStatsReset
375373
__cuFileStatsReset = dlsym(RTLD_DEFAULT, 'cuFileStatsReset')
376374
if __cuFileStatsReset == NULL:
377375
if handle == NULL:
378-
handle = load_library(driver_ver)
376+
handle = load_library()
379377
__cuFileStatsReset = dlsym(handle, 'cuFileStatsReset')
380378

381379
global __cuFileGetStatsL1
382380
__cuFileGetStatsL1 = dlsym(RTLD_DEFAULT, 'cuFileGetStatsL1')
383381
if __cuFileGetStatsL1 == NULL:
384382
if handle == NULL:
385-
handle = load_library(driver_ver)
383+
handle = load_library()
386384
__cuFileGetStatsL1 = dlsym(handle, 'cuFileGetStatsL1')
387385

388386
global __cuFileGetStatsL2
389387
__cuFileGetStatsL2 = dlsym(RTLD_DEFAULT, 'cuFileGetStatsL2')
390388
if __cuFileGetStatsL2 == NULL:
391389
if handle == NULL:
392-
handle = load_library(driver_ver)
390+
handle = load_library()
393391
__cuFileGetStatsL2 = dlsym(handle, 'cuFileGetStatsL2')
394392

395393
global __cuFileGetStatsL3
396394
__cuFileGetStatsL3 = dlsym(RTLD_DEFAULT, 'cuFileGetStatsL3')
397395
if __cuFileGetStatsL3 == NULL:
398396
if handle == NULL:
399-
handle = load_library(driver_ver)
397+
handle = load_library()
400398
__cuFileGetStatsL3 = dlsym(handle, 'cuFileGetStatsL3')
401399

402400
global __cuFileGetBARSizeInKB
403401
__cuFileGetBARSizeInKB = dlsym(RTLD_DEFAULT, 'cuFileGetBARSizeInKB')
404402
if __cuFileGetBARSizeInKB == NULL:
405403
if handle == NULL:
406-
handle = load_library(driver_ver)
404+
handle = load_library()
407405
__cuFileGetBARSizeInKB = dlsym(handle, 'cuFileGetBARSizeInKB')
408406

409407
global __cuFileSetParameterPosixPoolSlabArray
410408
__cuFileSetParameterPosixPoolSlabArray = dlsym(RTLD_DEFAULT, 'cuFileSetParameterPosixPoolSlabArray')
411409
if __cuFileSetParameterPosixPoolSlabArray == NULL:
412410
if handle == NULL:
413-
handle = load_library(driver_ver)
411+
handle = load_library()
414412
__cuFileSetParameterPosixPoolSlabArray = dlsym(handle, 'cuFileSetParameterPosixPoolSlabArray')
415413

416414
global __cuFileGetParameterPosixPoolSlabArray
417415
__cuFileGetParameterPosixPoolSlabArray = dlsym(RTLD_DEFAULT, 'cuFileGetParameterPosixPoolSlabArray')
418416
if __cuFileGetParameterPosixPoolSlabArray == NULL:
419417
if handle == NULL:
420-
handle = load_library(driver_ver)
418+
handle = load_library()
421419
__cuFileGetParameterPosixPoolSlabArray = dlsym(handle, 'cuFileGetParameterPosixPoolSlabArray')
422420

423421
__py_cufile_init = True

0 commit comments

Comments
 (0)