Brian2cuda testing

I am trying to run brian2 code on GPU through brian2cuda, but the tests are not yielding positive results.
I have:
brian2 2.4.2
brian2cuda 1.0a1
nvcc release 12.0, V12.0.140
build cuda 12.0.r12.0/compiler.32267302_0

Minimal code to reproduce the error:

from brian2 import *
import brian2cuda
set_device(“cuda_standalone”)
brian2cuda.example_run()

==================
Full traceback of error (if relevant)
ERROR Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at http://brian.discourse.group/, or to the issue tracker at https://github.com/brian-team/brian2/issues. Please include this file with debug information in your report: /tmp/brian_debug_pcwsspar.log You can also include a copy of the redirected std stream outputs, available at /tmp/brian_stdout_jf5pmdtl.log and /tmp/brian_stderr_hi63lyhj.log Thanks! [brian2]
Traceback (most recent call last):
File “”, line 1, in
File “/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/init.py”, line 55, in example_run
device.build(direct_call=False, directory=directory, **build_options)
File “/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/device.py”, line 1444, in build
self.generate_codeobj_source(self.writer)
File “/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/device.py”, line 724, in generate_codeobj_source
if hasattr(codeobj, ‘owner’) and hasattr(codeobj.owner, ‘_N’) and codeobj.owner._N != 0:
ReferenceError: weakly-referenced object no longer exists

PS as a new user I cannot upload the file " brian_debug_pcwsspar.log"

Hi @lparr,

I can’t reproduce your error with the brian2 and brian2cuda versions you mentioned (the error doesn’t sound like it has anything to do with your CUDA version). Are you by any chance using a Jupyter notebook? If so, can you try if running the minimal example above in it’s own Python script works as expected?

Hi @denisalevi ,

Thanks for the answer.
I probably should’ve mentioned that I am working on Ubuntu 20.04.
I am not using Jupyter since I tried everything directly on the terminal, but I have tried now with Spyder (version 4.2.5) as IDE and I got a slightly different error:


INFO       CUDA installation directory detected via location of `nvcc` binary: /home/lparrilla/anaconda3/envs/CUDA [brian2.devices.cuda_standalone]
INFO       Compiling device code for GPU 0 (NVIDIA RTX A6000) [brian2.devices.cuda_standalone]
INFO       Compiling device code for compute capability 8.6 (compiler flags: ['-arch=sm_86']) [brian2.devices.cuda_standalone]
INFO       Using the following preferences for CUDA standalone: [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.SM_multiplier = 1 [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.parallel_blocks = 1 [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.launch_bounds = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.syn_launch_bounds = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.calc_occupancy = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.extra_threshold_kernel = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.random_number_generator_type = CURAND_RNG_PSEUDO_DEFAULT [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.random_number_generator_ordering = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.push_synapse_bundles = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.threads_per_synapse_bundle = {max} [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.bundle_threads_warp_multiple = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.no_pre_references = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.no_post_references = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.default_functions_integral_convertion = <class 'numpy.float64'> [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.use_atomics = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.profile_statemonitor_copy_to_host = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.gpu_heap_size = 128 [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.detect_gpus = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.gpu_id = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.extra_compile_args_nvcc = ['-w', '-use_fast_math'] [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.compute_capability = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.detect_cuda = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.cuda_path = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.cuda_runtime_version = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.device_query_path = None [brian2.devices.cuda_standalone]
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
cc1plus: fatal error: cuda_runtime.h: No such file or directory
compilation terminated.
make: *** [makefile:23: code_objects/neurongroup_thresholder_codeobject.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [makefile:23: code_objects/neurongroup_group_variable_set_conditional_codeobject.o] Error 1
make: *** [makefile:23: code_objects/neurongroup_stateupdater_codeobject.o] Error 1
make: *** [makefile:23: network.o] Error 1
make: *** [makefile:23: synapses_classes.o] Error 1
make: *** [makefile:23: main.o] Error 1
make: *** [makefile:23: rand.o] Error 1
make: *** [makefile:23: code_objects/neurongroup_resetter_codeobject.o] Error 1
make: *** [makefile:23: run.o] Error 1
make: *** [makefile:23: objects.o] Error 1
Traceback (most recent call last):

  File "<ipython-input-4-af9ee0f286b0>", line 1, in <module>
    brian2cuda.example_run()

  File "/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/__init__.py", line 55, in example_run
    device.build(direct_call=False, directory=directory, **build_options)

  File "/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/device.py", line 1476, in build
    self.compile_source(directory, cpp_compiler, debug, clean)

  File "/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2/devices/cpp_standalone/device.py", line 990, in compile_source
    raise RuntimeError(error_message)

RuntimeError: Project compilation failed (error code: 512). Consider running with "clean=True" to force a complete rebuild.

This looks like an issue with your CUDA installation. How did you install CUDA? Can you send me the output of the following commands

which nvcc
nvidia-smi

And can you send me a summary of your conda environment?

conda list

Your nvcc binary was detected inside your conda environment folder. That is typically not where CUDA is installed (except you installed it there manually?). It could be that your CUDA path is not correctly detected due to a conda package providing an nvcc wrapper.

If that is the case, you could manually set the CUDA path via the following preference:

from brian2 import *
...
prefs.devices.cuda_standalone.cuda_backend.cuda_path = /path/to/cuda/installation

where /path/to/cuda/installation should be the output of which nvcc without the trialing nvcc (e.g. if which nvcc returns /usr/local/cuda/nvcc, then the path should be /usr/local/cuda)

Sure thing!

which nvcc
/home/usr/anaconda3/envs/CUDA/bin/nvcc
nvidia-smi
Mon Feb 27 13:43:12 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.108.03   Driver Version: 510.108.03   CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| 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 RTX A6000    Off  | 00000000:5E:00.0 Off |                  Off |
| 30%   33C    P8    24W / 300W |    265MiB / 49140MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1907      G   /usr/lib/xorg/Xorg                  4MiB |
|    0   N/A  N/A   1111498      C   .../DEEPLABCUT/bin/python3.8      257MiB |
+-----------------------------------------------------------------------------+
conda list
# packages in environment at /home/usr/anaconda3/envs/CUDA:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             4.5                       1_gnu  
alabaster                 0.7.12                   py36_0  
appdirs                   1.4.4              pyhd3eb1b0_0  
argh                      0.26.2                   py36_0  
args                      0.1.0                    pypi_0    pypi
astroid                   2.6.6            py36h06a4308_0  
async_generator           1.10             py36h28b3542_0  
atomicwrites              1.4.0                      py_0  
attrs                     21.4.0             pyhd3eb1b0_0  
autopep8                  1.5.6              pyhd3eb1b0_0  
babel                     2.9.1              pyhd3eb1b0_0  
backcall                  0.2.0              pyhd3eb1b0_0  
binutils_impl_linux-64    2.35.1               h27ae35d_9  
binutils_linux-64         2.35                h67ddf6f_30    conda-forge
black                     19.10b0                    py_0  
blas                      1.0                         mkl  
bleach                    4.1.0              pyhd3eb1b0_0  
brian2                    2.4.2            py36h51d7077_1    conda-forge
brian2cuda                1.0a1                    pypi_0    pypi
brotlipy                  0.7.0           py36h27cfd23_1003  
ca-certificates           2022.12.7            ha878542_0    conda-forge
certifi                   2020.6.20          pyhd3eb1b0_3    anaconda
cffi                      1.14.6           py36h400218f_0  
chardet                   4.0.0           py36h06a4308_1003  
charset-normalizer        2.0.4              pyhd3eb1b0_0  
click                     8.0.3              pyhd3eb1b0_0  
clint                     0.5.1                    pypi_0    pypi
cloudpickle               2.0.0              pyhd3eb1b0_0  
colorama                  0.4.4              pyhd3eb1b0_0  
coverage                  6.2                      pypi_0    pypi
cryptography              35.0.0           py36hd23ed53_0  
cuda-nvcc                 12.0.140                      0    nvidia
cudatoolkit               11.1.1               h6406543_8    conda-forge
cycler                    0.11.0             pyhd3eb1b0_0  
cython                    0.29.24          py36hc4f0c31_0    conda-forge
dbus                      1.13.18              hb2f20db_0  
decorator                 5.1.1              pyhd3eb1b0_0  
defusedxml                0.7.1              pyhd3eb1b0_0  
diff-match-patch          20200713           pyhd3eb1b0_0  
docutils                  0.17.1           py36h06a4308_1  
entrypoints               0.3                      py36_0  
expat                     2.4.4                h295c915_0  
fastcache                 1.1.0            py36h7b6447c_0  
flake8                    3.9.0              pyhd3eb1b0_0  
fontconfig                2.13.1               h6c09931_0  
freetype                  2.11.0               h70c0345_0  
future                    0.18.2                   py36_1  
gcc_impl_linux-64         7.5.0               hda68d29_13    conda-forge
gcc_linux-64              7.5.0               h47867f9_30    conda-forge
glib                      2.69.1               h4ff587b_1  
gmp                       6.2.1                h2531618_2  
gmpy2                     2.0.8            py36h10f8cd9_2  
gsl                       2.1                           2    conda-forge
gst-plugins-base          1.14.0               h8213a91_2  
gstreamer                 1.14.0               h28cd5cc_2  
gxx_impl_linux-64         7.5.0               h64c220c_13    conda-forge
gxx_linux-64              7.5.0               h555fc39_30    conda-forge
icu                       58.2                 he6710b0_3  
idna                      3.3                pyhd3eb1b0_0  
imagesize                 1.3.0              pyhd3eb1b0_0  
importlib-metadata        4.8.1            py36h06a4308_0  
importlib_metadata        4.8.1                hd3eb1b0_0  
iniconfig                 1.1.1              pyhd3eb1b0_0  
intel-openmp              2022.0.1          h06a4308_3633  
intervaltree              3.1.0              pyhd3eb1b0_0  
ipykernel                 5.3.4            py36h5ca1d4c_0  
ipython                   7.16.1           py36h5ca1d4c_0  
ipython_genutils          0.2.0              pyhd3eb1b0_1  
isort                     5.9.3              pyhd3eb1b0_0  
jedi                      0.17.2           py36h06a4308_1  
jeepney                   0.7.1              pyhd3eb1b0_0  
jinja2                    3.0.2              pyhd3eb1b0_0  
joblib                    0.13.2                   py36_0  
jpeg                      9d                   h7f8727e_0  
jsonschema                3.2.0              pyhd3eb1b0_2  
jupyter_client            7.1.2              pyhd3eb1b0_0  
jupyter_core              4.8.1            py36h06a4308_0  
jupyterlab_pygments       0.1.2                      py_0  
kernel-headers_linux-64   2.6.32              he073ed8_15    conda-forge
keyring                   23.1.0           py36h06a4308_0  
kiwisolver                1.3.1            py36h2531618_0  
lazy-object-proxy         1.6.0            py36h27cfd23_0  
lcms2                     2.12                 h3be6417_0  
ld_impl_linux-64          2.35.1               h7274673_9  
libffi                    3.3                  he6710b0_2  
libgcc-ng                 9.3.0               h5101ec6_17  
libgfortran-ng            7.5.0               ha8ba4b0_17  
libgfortran4              7.5.0               ha8ba4b0_17  
libgomp                   9.3.0               h5101ec6_17  
libpng                    1.6.37               hbc83047_0  
libsodium                 1.0.18               h7b6447c_0  
libspatialindex           1.9.3                h2531618_0  
libstdcxx-ng              9.3.0               hd4cf53a_17  
libtiff                   4.2.0                h85742a9_0  
libuuid                   1.0.3                h7f8727e_2  
libwebp-base              1.2.2                h7f8727e_0  
libxcb                    1.14                 h7b6447c_0  
libxml2                   2.9.12               h03d6c58_0  
lz4-c                     1.9.3                h295c915_1  
mamba                     0.11.2                   pypi_0    pypi
markupsafe                2.0.1            py36h27cfd23_0  
matplotlib                3.3.4            py36h06a4308_0  
matplotlib-base           3.3.4            py36h62a2d02_0  
mccabe                    0.6.1                    py36_1  
mistune                   0.8.4            py36h7b6447c_0  
mkl                       2020.2                      256  
mkl-service               2.3.0            py36he8ac12f_0  
mkl_fft                   1.3.0            py36h54f3939_0  
mkl_random                1.1.1            py36h0573a6f_0  
mne                       0.23.4                   pypi_0    pypi
more-itertools            8.12.0             pyhd3eb1b0_0  
mpc                       1.1.0                h10f8cd9_1  
mpfr                      4.0.2                hb69a4c5_1  
mpmath                    1.2.1            py36h06a4308_0  
mypy_extensions           0.4.3                    py36_0  
nbclient                  0.5.3              pyhd3eb1b0_0  
nbconvert                 6.0.7                    py36_0  
nbformat                  5.1.3              pyhd3eb1b0_0  
ncurses                   6.3                  h7f8727e_2  
nest-asyncio              1.5.1              pyhd3eb1b0_0  
numpy                     1.19.2           py36h54aff64_0  
numpy-base                1.19.2           py36hfa32c7d_0  
numpydoc                  1.1.0              pyhd3eb1b0_1  
olefile                   0.46                     py36_0  
openjpeg                  2.4.0                h3ad879b_0  
openssl                   1.1.1t               h7f8727e_0  
packaging                 21.3               pyhd3eb1b0_0  
pandas                    1.1.5            py36ha9443f7_0  
pandoc                    2.12                 h06a4308_0  
pandocfilters             1.5.0              pyhd3eb1b0_0  
parso                     0.7.0                      py_0  
pathspec                  0.7.0                      py_0  
patsy                     0.5.3              pyhd8ed1ab_0    conda-forge
pcre                      8.45                 h295c915_0  
pexpect                   4.8.0              pyhd3eb1b0_3  
pickleshare               0.7.5           pyhd3eb1b0_1003  
pillow                    8.3.1            py36h2c7a002_0  
pip                       21.2.2           py36h06a4308_0  
pluggy                    0.13.1           py36h06a4308_0  
prompt-toolkit            3.0.20             pyhd3eb1b0_0  
psutil                    5.8.0            py36h27cfd23_1  
ptyprocess                0.7.0              pyhd3eb1b0_2  
py                        1.11.0             pyhd3eb1b0_0  
pycodestyle               2.6.0              pyhd3eb1b0_0  
pycparser                 2.21               pyhd3eb1b0_0  
pydocstyle                6.1.1              pyhd3eb1b0_0  
pyflakes                  2.2.0              pyhd3eb1b0_0  
pygments                  2.11.2             pyhd3eb1b0_0  
pylint                    2.9.6            py36h06a4308_1  
pyls-black                0.4.6                hd3eb1b0_0  
pyls-spyder               0.3.2              pyhd3eb1b0_0  
pyopenssl                 22.0.0             pyhd3eb1b0_0  
pyparsing                 3.0.4              pyhd3eb1b0_0  
pyqt                      5.9.2            py36h05f1152_2  
pyrsistent                0.17.3           py36h7b6447c_0  
pysocks                   1.7.1            py36h06a4308_0  
pytest                    6.2.4            py36h06a4308_2  
python                    3.6.13               h12debd9_1  
python-dateutil           2.8.2              pyhd3eb1b0_0  
python-jsonrpc-server     0.4.0                      py_0  
python-language-server    0.36.2             pyhd3eb1b0_0  
python_abi                3.6                     2_cp36m    conda-forge
pytz                      2021.3             pyhd3eb1b0_0  
pyxdg                     0.27               pyhd3eb1b0_0  
pyyaml                    5.4.1            py36h27cfd23_1  
pyzmq                     22.2.1           py36h295c915_1  
qdarkstyle                2.8.1                      py_0  
qt                        5.9.7                h5867ecd_1  
qtawesome                 1.0.3              pyhd3eb1b0_0  
qtconsole                 5.2.2              pyhd3eb1b0_0  
qtpy                      1.11.2             pyhd3eb1b0_0  
readline                  8.1.2                h7f8727e_1  
regex                     2021.8.3         py36h7f8727e_0  
requests                  2.27.1             pyhd3eb1b0_0  
rope                      0.22.0             pyhd3eb1b0_0  
rtree                     0.9.7            py36h06a4308_1  
scikit-learn              0.24.2           py36ha9443f7_0  
scipy                     1.5.2            py36h0b6359f_0  
seaborn                   0.11.2             pyhd3eb1b0_0  
secretstorage             3.3.1            py36h06a4308_0  
setuptools                58.0.4           py36h06a4308_0  
sip                       4.19.8           py36hf484d3e_0  
six                       1.16.0             pyhd3eb1b0_1  
snowballstemmer           2.2.0              pyhd3eb1b0_0  
sortedcontainers          2.4.0              pyhd3eb1b0_0  
sphinx                    4.4.0              pyhd3eb1b0_0  
sphinxcontrib-applehelp   1.0.2              pyhd3eb1b0_0  
sphinxcontrib-devhelp     1.0.2              pyhd3eb1b0_0  
sphinxcontrib-htmlhelp    2.0.0              pyhd3eb1b0_0  
sphinxcontrib-jsmath      1.0.1              pyhd3eb1b0_0  
sphinxcontrib-qthelp      1.0.3              pyhd3eb1b0_0  
sphinxcontrib-serializinghtml 1.1.5              pyhd3eb1b0_0  
spyder                    4.2.5            py36h06a4308_0  
spyder-kernels            1.10.2           py36h06a4308_0  
sqlite                    3.37.2               hc218d9a_0  
statsmodels               0.9.0           py36h3010b51_1000    conda-forge
sympy                     1.4                      pypi_0    pypi
sysroot_linux-64          2.12                he073ed8_15    conda-forge
testpath                  0.5.0              pyhd3eb1b0_0  
textdistance              4.2.1              pyhd3eb1b0_0  
threadpoolctl             2.2.0              pyh0d69192_0  
three-merge               0.1.1              pyhd3eb1b0_0  
tk                        8.6.11               h1ccaba5_0  
toml                      0.10.2             pyhd3eb1b0_0  
tornado                   6.1              py36h27cfd23_0  
traitlets                 4.3.3            py36h06a4308_0  
typed-ast                 1.4.3            py36h7f8727e_1  
typing-extensions         3.10.0.2             hd3eb1b0_0  
typing_extensions         3.10.0.2           pyh06a4308_0  
ujson                     4.0.2            py36h2531618_0  
urllib3                   1.26.8             pyhd3eb1b0_0  
watchdog                  1.0.2            py36h06a4308_1  
wcwidth                   0.2.5              pyhd3eb1b0_0  
webencodings              0.5.1                    py36_1  
wheel                     0.37.1             pyhd3eb1b0_0  
wrapt                     1.12.1           py36h7b6447c_1  
wurlitzer                 2.1.1            py36h06a4308_0  
xz                        5.2.5                h7b6447c_0  
yaml                      0.2.5                h7b6447c_0  
yapf                      0.31.0             pyhd3eb1b0_0  
zeromq                    4.3.4                h2531618_0  
zipp                      3.6.0              pyhd3eb1b0_0  
zlib                      1.2.11               h7f8727e_4  
zstd                      1.4.9                haebb681_0

I also tried to manually set the CUDA path but I receive always the same error (i.e. weakly-referenced object)

Ah, interesting. I wasn’t aware that NVIDIA makes CUDA available via conda now. Neat. For Brian2CUDA, you need the entire CUDA tool chain (e.g. cudatoolkit from conda-forge is not enough). Until recently, conda packages didn’t include the entire CUDA tool chain because of NVIDIA EULA requirements, which is why one Brian2CUDA requirement is a full CUDA toolkit installation (else compilation fails as you see in your case). Now that NVIDIA distributes their CUDA tool chain via conda, we could support a full Brian2CUDA conda package, that is great.

Anyways, back to your error. It appears you installed cuda-nvcc, which provides the nvcc binary, but not the CUDA toolchain I mentioned above. Installing the full cuda package fixed it for me:

conda install -c nvidia cuda

After installing this, I got an error about the wrong GLIBC version being installed. So I also had to install a newer GLIBC version (and you probably will too):

conda install -c conda-forge sysroot_linux-64=2.17

This command installs GLIBC 2.17, which is required by one of the CUDA libraries we use. This all should be more streamlined if we provide a conda package for Brian2CUDA. But for now, this might solve it for you. I also tried installing only cuda-runtime instead of cuda, but it didn’t provide cuda_runtime.h.
This should fix your compilation error.

For the weakly-referenced object error, I still can’t reproduce it. Is it still happening? Can you try to run your minimal example from above outside your IDE, that means just from your terminal with

python example.py

where example.py is

from brian2 import *
import brian2cuda
set_device("cuda_standalone")
brian2cuda.example_run()

Ok so I tried your suggestions but when I try to install sysroot_linux it appears that alot of packages have conflicts, so I created a new env from conda then run:

conda install -c nvidia cuda

&

conda install -c conda-forge sysroot_linux-64=2.17

No frozen solve and anything, the installation went smooth, but when I try

python
from brian2 import *
import brian2cuda
set_device("cuda_standalone")
brian2cuda.example_run()

I have this brand new error:

INFO       CUDA installation directory detected via location of `nvcc` binary: /home/lparrilla/anaconda3/envs/CUDACUDA [brian2.devices.cuda_standalone]
INFO       Compiling device code for GPU 0 (NVIDIA RTX A6000) [brian2.devices.cuda_standalone]
INFO       Compiling device code for compute capability 8.6 (compiler flags: ['-arch=sm_86']) [brian2.devices.cuda_standalone]
INFO       Using the following preferences for CUDA standalone: [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.SM_multiplier = 1 [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.parallel_blocks = 1 [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.launch_bounds = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.syn_launch_bounds = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.calc_occupancy = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.extra_threshold_kernel = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.random_number_generator_type = CURAND_RNG_PSEUDO_DEFAULT [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.random_number_generator_ordering = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.push_synapse_bundles = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.threads_per_synapse_bundle = {max} [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.bundle_threads_warp_multiple = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.no_pre_references = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.no_post_references = False [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.default_functions_integral_convertion = <class 'numpy.float64'> [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.use_atomics = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.profile_statemonitor_copy_to_host = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.gpu_heap_size = 128 [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.detect_gpus = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.gpu_id = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.extra_compile_args_nvcc = ['-w', '-use_fast_math'] [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.compute_capability = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.detect_cuda = True [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.cuda_path = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.cuda_runtime_version = None [brian2.devices.cuda_standalone]
INFO       	devices.cuda_standalone.cuda_backend.device_query_path = None [brian2.devices.cuda_standalone]
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
/home/lparrilla/anaconda3/envs/CUDACUDA/bin/x86_64-conda-linux-gnu-c++: No such file or directory
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
nvcc fatal   : Failed to preprocess host compiler properties.
make: *** [makefile:23: code_objects/neurongroup_resetter_codeobject.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [makefile:23: code_objects/neurongroup_stateupdater_codeobject.o] Error 1
make: *** [makefile:23: code_objects/neurongroup_group_variable_set_conditional_codeobject.o] Error 1
make: *** [makefile:23: network.o] Error 1
make: *** [makefile:23: main.o] Error 1
make: *** [makefile:23: synapses_classes.o] Error 1
make: *** [makefile:23: rand.o] Error 1
make: *** [makefile:23: run.o] Error 1
make: *** [makefile:23: objects.o] Error 1
make: *** [makefile:23: code_objects/neurongroup_thresholder_codeobject.o] Error 1
ERROR      Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at <http://brian.discourse.group/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: /tmp/brian_debug__5_cdqsb.log  You can also include a copy of the redirected std stream outputs, available at /tmp/brian_stdout_iyjr4an8.log and /tmp/brian_stderr_ir_uvcxc.log Thanks! [brian2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/__init__.py", line 55, in example_run
    device.build(direct_call=False, directory=directory, **build_options)
  File "/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2cuda/device.py", line 1476, in build
    self.compile_source(directory, cpp_compiler, debug, clean)
  File "/home/lparrilla/anaconda3/envs/CUDA/lib/python3.6/site-packages/brian2/devices/cpp_standalone/device.py", line 990, in compile_source
    raise RuntimeError(error_message)
RuntimeError: Project compilation failed (error code: 512). Consider running with "clean=True" to force a complete rebuild.

Same exact error returned if sysroot_lunux is not installed

This is now getting into conda environment specifics. Generally, I want to point out that the issues you are having are not related to Brian2CUDA, but to installing CUDA. The easiest solution would be to install the CUDA toolkit not via conda, or to figure out how to correctly install it via conda. This document should generally help you with that: CUDA Installation Guide for Linux

If you want to continue with your CUDA in conda installation, I can continue guessing solutions for you:

  • Did you install Brian2 via conda in that new environment? If not, please do so (the correct version 2.4.2, so conda install -c conda-forge brian2=2.4.2). The Brian2 conda package installs a C++ compiler via conda as dependency, which should solve the error you are seeing here (it looks like the conda cuda package expects a conda C++ package which you have not installed).
  • Alternatively, you could also just install C++ via conda: conda install -c conda-forge gxx_linux-64 gcc_linux-64 (I’m not sure which of the packages you actually need, but both will likely do).

Hi @danisalevi

I resolved the issue by creating a new user on the machine, first I installed anaconda, then I create a new environment WITH spyder, otherwise I will have:

The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__glibc==2.31=0
  - feature:|@/linux-64::__glibc==2.31=0

if I try to install spyder after.

Then I proceed to install cuda toolkit (found several versions online with or without the -, this worked fine for me):

conda install -c conda-forge cudatoolkit-dev -n myenv

Then I proceeded to install brian2cuda:

python -m pip install brian2cuda

However, the main problems arising are:

  1. np.bool is deprecated, should change EVERY np.bool to np.bool_ in the installation files
  2. np.float is deprecated, should change EVERY np.float to bp.float64 in the installation files.

Finally when I run:

from brian2 import *
import brian2cuda
set_device('cuda_standalone')
brian2cuda.example_run()

everything works fine, thank you so much for your help!

Note that this is 1) mostly due to the fact that Brian2CUDA is not yet compatible with the latest version of Brian (which already fixed this issue) and 2) only occurs with numpy ≥ 1.24 (earlier versions will only raise a warning).

Hi @mstimberg ,

Thanks for pinpointing that out!
Please note that I did not install anything (except the cudatoolkit) before installing brian2cuda, so I was assuming that the installation would proceed to find all the compatible versions of different libraries, anyway the important thing is that I have it up and running!

As you say, the important thing is that it is working now, but just to explain: brian2cuda still depends on brian2 2.4.2, released at the end of 2020 (!). Back then, numpy was at version 1.19. The aliases np.bool/np.float were deprecated and started to raise warnings only in numpy 1.20, and finally turned into errors with the recent numpy 1.24 release. Long story short: we need to make brian2cuda work with the most recent brian2 version (working on it…).

@lparr Sorry for the late response, I was occupied with a conference trip

I’m glad you got it working with cudatoolkit-dev. I was aware that it ships all the CUDA Toolkit stuff, but I never tried it myself!

For the Brian2CUDA and Brian2 versions: There is already a version of Brian2CUDA that is compatible with the latest Brian2 version (2.5.1), I just haven’t released it yet. If you want to, you can install it like this:

  1. Uninstall brian2cuda if it is installed in the environment (pip uninstall brian2cuda)
  2. Manually install brian2 2.5.1 (conda install -c conda-forge brian2=2.5.1)
  3. Install the brian2cuda development version via python -m pip install --upgrade --pre -i https://test.pypi.org/simple/ brian2cuda

Brian2CUDA development is currently a bit slow because I’m on parental leave, hope to get this Brian2CUDA version released soon though.

1 Like