maintainer-feedback requested: [Bug 286976] x11/nvidia-driver : CUDA initialization: Unexpected error from cudaGetDeviceCount() error while trying to install Stable Diffusion on FreeBSD + nvidia driver 570.144 (even lower but not 525 and 535)

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 21 May 2025 15:29:40 UTC
Bugzilla Automation <bugzilla@FreeBSD.org> has asked freebsd-x11 (Nobody)
<x11@FreeBSD.org> for maintainer-feedback:
Bug 286976: x11/nvidia-driver :  CUDA initialization: Unexpected error from
cudaGetDeviceCount() error while trying to install Stable Diffusion on FreeBSD
+ nvidia driver 570.144 (even lower but not 525 and 535)
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=286976



--- Description ---
Hello.

I'm trying to install Stable Diffusion on FreeBSD 14.2 + nvidia driver
570.144,following this tutorial :

https://github.com/verm/freebsd-stable-diffusion

There Verm used nvidia driver 525 and FreeBSD 13 I presume,but now I'm running
FreeBSD 14.2 and the nvidia driver 570.144.

This is what I did :

# pkg install linux-miniconda-installer
# miniconda-installer
# bash
# source ${BASE_PATH}/etc/profile.d/conda.sh
# conda activate
(base) #
(base) # conda create --name pytorch python=3.10
(base) # conda activate pytorch
  # pip install torch==1.12.1+cu113 --extra-index-url
https://download.pytorch.org/whl/cu113
(pytorch) # LD_PRELOAD="/compat/dummy-uvm.so" python3 -c 'import torch;
print(torch.cuda.is_available())'
  True


but with the driver : 570.144 it does not work anymore :


(pytorch) marietto# nv-sglrun nvidia-smi

/usr/local/lib/libc6-shim/libc6.so: shim init
Wed May 21 09:41:54 2025       
+------------------------------------------------------------------------------
-----------+
| NVIDIA-SMI 570.144		    Driver Version: 570.144	   CUDA
Version: 12.8	  |
|-----------------------------------------+------------------------+-----------
-----------+
| GPU  Name		    Persistence-M | Bus-Id	    Disp.A | Volatile
Uncorr. ECC |
| Fan  Temp   Perf	    Pwr:Usage/Cap |	      Memory-Usage | GPU-Util 
Compute M. |
|					  |			   |	       
   MIG M. |
|=========================================+========================+===========
===========|
|   0  NVIDIA GeForce GTX 1060 3GB    Off |   00000000:01:00.0	On |	       
      N/A |
| 56%	39C    P8	       7W /  120W |	279MiB /   3072MiB |	  0%   
  Default |
|					  |			   |	       
      N/A |
+-----------------------------------------+------------------------+-----------
-----------+

+------------------------------------------------------------------------------
-----------+
| Processes:								       
	  |
|  GPU	 GI   CI	      PID   Type   Process name 		      
GPU Memory |
|	 ID   ID							      
Usage	   |
|==============================================================================
===========|
+------------------------------------------------------------------------------
-----------+

[marietto@marietto ~]==> source ./miniconda3//etc/profile.d/conda.sh

[marietto@marietto ~]==> conda activate
  (base) #

marietto# conda create --name pytorch python=3.10
/home/marietto/miniconda3/lib/python3.12/site-packages/archspec/cpu/detect.py:2
90:
UserWarning: [Errno 2] No such file or directory: '/proc/cpuinfo'
  warnings.warn(str(exc))
Retrieving notices: done
Channels:
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/marietto/miniconda3/envs/pytorch

  added / updated specs:
    - python=3.10


The following packages will be downloaded:

    package		       |	    build
    ---------------------------|-----------------
    python-3.10.16	       |       he870216_1	 26.9 MB
    setuptools-78.1.1	       |  py310h06a4308_0	  1.7 MB
    wheel-0.45.1	       |  py310h06a4308_0	  115 KB
    ------------------------------------------------------------
					   Total:	 28.7 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main 
  _openmp_mutex      pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu 
  bzip2 	     pkgs/main/linux-64::bzip2-1.0.8-h5eee18b_6 
  ca-certificates    pkgs/main/linux-64::ca-certificates-2025.2.25-h06a4308_0 
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.40-h12ee557_0 
  libffi	     pkgs/main/linux-64::libffi-3.4.4-h6a678d5_1 
  libgcc-ng	     pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1 
  libgomp	     pkgs/main/linux-64::libgomp-11.2.0-h1234567_1 
  libstdcxx-ng	     pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1 
  libuuid	     pkgs/main/linux-64::libuuid-1.41.5-h5eee18b_0 
  ncurses	     pkgs/main/linux-64::ncurses-6.4-h6a678d5_0 
  openssl	     pkgs/main/linux-64::openssl-3.0.16-h5eee18b_0 
  pip		     pkgs/main/noarch::pip-25.1-pyhc872135_2 
  python	     pkgs/main/linux-64::python-3.10.16-he870216_1 
  readline	     pkgs/main/linux-64::readline-8.2-h5eee18b_0 
  setuptools	     pkgs/main/linux-64::setuptools-78.1.1-py310h06a4308_0 
  sqlite	     pkgs/main/linux-64::sqlite-3.45.3-h5eee18b_0 
  tk		     pkgs/main/linux-64::tk-8.6.14-h39e8969_0 
  tzdata	     pkgs/main/noarch::tzdata-2025b-h04d1e81_0 
  wheel 	     pkgs/main/linux-64::wheel-0.45.1-py310h06a4308_0 
  xz		     pkgs/main/linux-64::xz-5.6.4-h5eee18b_1 
  zlib		     pkgs/main/linux-64::zlib-1.2.13-h5eee18b_1 


Proceed ([y]/n)? Y

Downloading and Extracting Packages:

Preparing transaction: done						       

Verifying transaction: done						       

Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate pytorch
#
# To deactivate an active environment, use
#
#     $ conda deactivate

marietto# exit
(base) [marietto@marietto ~]$ conda activate pytorch

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple,
https://download.pytorch.org/whl/cu113
Collecting torch==1.12.1+cu113
  Downloading
https://download.pytorch.org/whl/cu113/torch-1.12.1%2Bcu113-cp310-cp310-linux_x
86_64.whl
(1837.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 GB 4.5 MB/s eta 0:00:00
Collecting typing-extensions (from torch==1.12.1+cu113)
  Downloading typing_extensions-4.13.2-py3-none-any.whl.metadata (3.0 kB)
Downloading typing_extensions-4.13.2-py3-none-any.whl (45 kB)
Installing collected packages: typing-extensions, torch
   ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━ 1/2 [torch]  WARNING: The scripts
convert-caffe2-to-onnx, convert-onnx-to-caffe2 and torchrun are installed in
'/home/marietto/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this
warning, use --no-warn-script-location.
Successfully installed torch-1.12.1+cu113 typing-extensions-4.13.2

(pytorch) [marietto@marietto ~]$ export CUDA_VISIBLE_DEVICES=0,1;

(pytorch) [marietto@marietto ~]$
LD_PRELOAD="/mnt/da0p2/CG/Tools/Stable-Diffusion/dummy-uvm.so" python3 -c
'import torch; print(torch.cuda.is_available())'
/home/marietto/.local/lib/python3.10/site-packages/torch/cuda/__init__.py:83:
UserWarning: CUDA initialization: Unexpected error from cudaGetDeviceCount().
Did you run some cuda functions before calling NumCudaDevices() that might have
already set an error? Error 304: OS call failed or operation not supported on
this OS (Triggered internally at  ../c10/cuda/CUDAFunctions.cpp:109.)
  return torch._C._cuda_getDeviceCount() > 0
False