kvikio: kvikio still segfaults on program termination
Hi everyone,
I’m getting a segfault when my python script terminates. This only happens when kvikio is used.
Reproducer
mamba env create -f img2tensor_kvikio.yaml && mamba clean -afy
// img2tensor_kvikio.yaml
name: img2tensor
channels:
- pytorch
- nvidia
- rapidsai
- conda-forge
dependencies:
- notebook
- tifffile
- python=3.11
- pytorch
- pytorch-cuda=12.4
- kvikio
bug.py
import kvikio
file_name = 'file0.txt'
fd = kvikio.CuFile(file_name, "w")
fd.close()
I’m running in a kubernetes environment. We use the open kernel driver 535.183.01
I assumed this #462 has fixed the issue but it seems there is more to it.
You can find the concretized environment here: exported_img2tensor_kvikio.txt
It uses kvikio 24.10 which should include the previously mentioned PR.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 31 (21 by maintainers)
Below is a minimally reproducible C++ example for the segfault. It emulates KvikIO’s dynamic loading, which seems to be correlated to the issue observed.
Concretely, KvikIO dynamically loads the cuFile shared library at runtime, and therefore the information on the cuFile library is not passed to the linker at link time. Apparently, the segfault somehow occurs with this setup (
run_bad.sh).If the information on the cuFile library is passed to the linker, the segfault would then be gone (
run_good.sh). This, however, defies our purpose of using dynamic loading.biu.cpp
Single source file to reproduce the segfault.
my_cufile.json
A copy of
/etc/cufile.json, except thatcufile_statsis assigned a positive value.Run this script to compile
biu.cppand observe the segfault. Note thatCUFILE_ENV_PATH_JSONis set tomy_cufile.json.run_bad.sh
Sample output:
Run this script to compile biu.cpp. The segfault ceases to exist once the cuFile library is linked to the program.
run_good.sh
Sample output:
We want to support setups that doesn’t have cuFile/gds installed. cuFile supports ARM64 as of CUDA toolkit v12.3+ so we might be able to use regular dynamic or static linking in the future but for now, we need to support systems without cuFile.
This has been fixed in CUDA-13.0 which would be available pretty soon.
I continued playing around with the environment to ensure the issue was not related to my setup. Just a few minutes ago I found out that the segmentation fault on termination does not occur when I set
"cufile_stats": 0in the cufile.json. Any value in cufile_stats above 0 causes the segfault. But as mentioned during execution everything works fine. The READ-WRITE SIZE histogram is written to cufile.log and all. Only on termination, the segfault happens. I could observe this both inside and outside of a docker container.Do you still think that this is related to
cufileDriverClose()?Lawrence mentioned doing a debug build. So wanted to share that resource
If the segfault happens somewhere in KvikIO, it may help. If it happens in cuFile, we likely don’t learn much
Could you please slim the environment further like so and retry?
Asking as there are mismatching CUDA versions in the reproducing environment. Plus some extra bits that appear unused in the example. So would like to simplify further to avoid other potential issues