riscv64 linux kernel compilation issue - qemu

I am trying to compile the linux kernel for riscv64 using the following link -
https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html
While building linux with the command make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- defconfig
the following error shows up -
scripts/kconfig.include:35 compiler riscv64-unknown-linux-gnu-gcc not found in PATH
scripts/kconfig/Makefile:82:recipe for target 'defconfig' failed
I have included path of tool chain. Still not working. Attached the screenshot of folder structure and error.

I would suggest to provide the full prefix for your toolchain in the make command, for example:
wget https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64/tarballs/riscv64--glibc--bleeding-edge-2020.02-2.tar.bz2
mkdir -p /opt/bootlin
tar jxf riscv64--glibc--bleeding-edge-2020.02-2.tar.bz2 -C /opt/bootlin
make ARCH=riscv CROSS_COMPILE=/opt/bootlin/riscv64--glibc--bleeding-edge-2020.02-2/bin/riscv64-buildroot-linux-gnu- mrproper defconfig Image
Compilation should complete without errors - using linux 5.7.11 here:
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/confdata.o
HOSTCC scripts/kconfig/expr.o
LEX scripts/kconfig/lexer.lex.c
YACC scripts/kconfig/parser.tab.[ch]
HOSTCC scripts/kconfig/lexer.lex.o
.../...
LD vmlinux.o
MODPOST vmlinux.o
MODINFO modules.builtin.modinfo
GEN modules.builtin
LD .tmp_vmlinux.kallsyms1
KSYM .tmp_vmlinux.kallsyms1.o
LD .tmp_vmlinux.kallsyms2
KSYM .tmp_vmlinux.kallsyms2.o
LD vmlinux
SYSMAP System.map
OBJCOPY arch/riscv/boot/Image
Kernel: arch/riscv/boot/Image is ready

It is saying compiler riscv64-unknown-linux-gnu not found which means either riscv gnu toolchain is not installed on your machine or it is not found by the shell instance in which you are trying to compile linux kernel.
To check if RISC-V GNU toolchain is installed, create a simple C file and try to compile it with RISC-V gnu toolchain with following command:
riscv64-unknown-linux-gnu-gcc <filename.c> -o <binaryname>
1. If RISC-V GNU Toolchain is not installed:
Follow the instruction here to install riscv gnu toolchain. And keep in mind to compile it with make linux instead of make.
2. If RISC-V GNU Toolchain is installed or you are done installing
Add it to the $PATH variable inside .bashrc file located on home directory.
Then try compiling your kernel again.

Related

Set default host compiler for nvcc

I have just installed Debian Stretch (9) and Cuda 8 on a new GPU server. Stretch does not come with older versions of gcc, so I need to use clang as the host compiler (nvcc does not support gcc-6). I can do this invoking nvcc as:
nvcc -ccbin clang-3.8
Is there any way to acheive this system wide - e.g. in cuda config or an environment variable?
Documentation of nvcc does not list any env variable to change ccbin, only the option:
http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html
--compiler-bindir directory, -ccbin Specify the directory in which the compiler executable resides. The host compiler executable name can be also specified to ensure that the correct host compiler is selected.
Linux guide have no such info too: http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
You may try creating some nvcc wrapper script and putting it earlier in the PATH env var like:
mkdir ~/supernvcc
echo '#!/bin/sh' > ~/supernvcc/nvcc
echo `which nvcc` -ccbin clang-3.8 '$#' >> ~/supernvcc/nvcc
chmod +x ~/supernvcc/nvcc
export PATH=/home/`id -un`/supernvcc:$PATH
(repeat last line with export in every new shell before using nvcc or add it to your .bashrc or other shell init script)
PS: and nvcc is bash script too, you can just copy it and edit:
cat `which nvcc`
UPDATE: People recommend to link correct gcc version to the internal dir /usr/local/cuda/bin/ of cuda:
sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc
you can use NVCC_PREPEND_FLAGS and NVCC_APPEND_FLAGS as described in the official docs to inject -ccbin into all calls of nvcc.
For example, I have the following in my ~/.bash_profile:
export NVCC_PREPEND_FLAGS='-ccbin /home/linuxbrew/.linuxbrew/bin/g++-11'

CUDA linking error on OS X El Capitan

I've been trying to install CUDA and cuDNN for TensorFlow as instructed on the TensorFlow page. Everything works until I do the following:
$ cp -r /usr/local/cuda/samples ~/cuda-samples
$ pushd ~/cuda-samples
$ make
I then get the following error:
clang++ -rpath /Developer/NVIDIA/CUDA-7.5/lib -L/Developer/NVIDIA/CUDA-7.5/lib -framework CUDA -o clock_nvrtc clock.o -lnvrtc
ld: framework not found CUDA
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [clock_nvrtc] Error 1
make: *** [0_Simple/clock_nvrtc/Makefile.ph_build] Error 2
My question of course is what's causing the error, and how to fix it. I had previously installed CUDA 7.5, and then I installed 8.0. The whole of CUDA (and its installation) is just a black box to me; I'm just trying to get it to work with TensorFlow.
Thanks!
Add the folder containing the folder CUDA.framework to the command line as such:
-F<folder>
It looks like the linker isn't able to find the framework and you have to point it where it is
Run the following in your terminal -
xcode-select --install
Then try to run make again.
Saw the answer on an NVidia forum - https://devtalk.nvidia.com/default/topic/628298/cuda-samples-on-mac-os-x-mavericks-10-9-matrixmuldrv/
It's also documented in this Quick Start Guide - http://docs.nvidia.com/cuda/cuda-quick-start-guide/index.html#axzz4YvZYOZc0

can't find any solution for running f2py correctly on my windows 7 machine

Can someone pinpoint where I'm doing wrong, PLEASE? I'm so exhausted. I installed MinGW 4.7, python2.7.8, numpy 1.7.1 and scipy0.13.2 to an Anaconda (32bit) environment in Windows7.
Also, for user enviroment variables, I set
C_INCLUDE_PATH:
D:\Anaconda2\envs\arc103\MinGW\i686-w64-mingw32\include
Path (User variable):
C:\Program Files (x86)\Microsoft VS code\bin;D:\Anaconda2\Library\bin;D:\Anaconda2\envs\arc103\MinGW\bin
Tying the following commands in Anaconda Prompt
"f2py -c --help-fcompiler" outputs "... Fortran compilers found:
--fcompiler=gnu95 GNU Fortran 95 compiler (4.7.0) ...."
"f2py -c --help-compiler" outputs
"List of available compilers: ...", not specifically compilers found though.
Running "f2py -c fib1.f -m fib1" according to "NumPy v1.12.dev0 Manual" gives me lots of error as below:
D:\Anaconda2\envs\arc103\Scripts\gfortran.bat -Wall -Wall -shared c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-.7\fib1module.oc:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fortranobject.o c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\fib1.o -Ld:\anaconda2\envs\arc103\mingw\lib\gcc\i686-w64-mingw32\4.7.0 -LD:\Anaconda2\envs\arc103\libs -LD:\Anaconda2\envs\arc103\PCbuild -lpython27 -lgfortran -o .\fib1.pyd
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x35): undefined reference to `__imp__PyNumber_Int'
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x68): undefined reference to `__imp__PyComplex_Type'
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x79): undefined reference to `__imp__PyType_IsSubtype'
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x93): undefined reference to `__imp__PyErr_Occurred'
... (Thousands of "undefined reference to" errors I didn't put it here) ...
collect2.exe: error: ld returned 1 exit statuserror: Command "D:\Anaconda2\envs\arc103\Scripts\gfortran.bat -Wall -Wall -shared c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fortranobject.o
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\fib1.o -Ld:\anaconda2\envs\arc103\mingw\lib\gcc\i686-w64-mingw32\4.7.0 -LD:\Anaconda2\envs\arc103\libs
-LD:\Anaconda2\envs\arc103\PCbuild -lpython27 -lgfortran -o .\fib1.pyd" failed with exit status 1
Sorry for the mess. I have spent almost a few months finding out the fix, but it's too hard for me and all gone to no avail. It would be hugely appreciated if you can help me out. Thanks.
Since this is a couple month old, I am not sure if these tips will still help, but I found when building a Fortran to Python module on Win 10, that only compiling for 32bit worked, and you need to use a signature file, i.e. something along the lines of:
f2py.py -c cuncsd.pyf cuncsd.f
Instead of using the i686-w64-mingw32 toolchain I used a straight mingw32 one (to reduce the risk that I accidentally end up with anything 64bit).
I also found that you need to install a special Visual Studio for Python instance as described here:
Microsoft Visual C++ Compiler for Python 3.4
If you are using Python 2.7 this VSC version should do the trick for you, only newer version (3.5, 3.6) are left out at this time.
For reference here is my complete f2py invocation on the console that I ended up using (neither python nor f2py were on the execution PATH):
python C:\Python34\Scripts\f2py.py -c cuncsd.pyf --opt="-frecursive -fmax-stack-var-size=66560" cuncsd.f -llapack -lrefblas -ltmglib
This particular module depends on 32 bit LAPCK shared libraries that I compiled previously, and we found it even works on XP systems.
I later went back and tried to compile this for 64 bit, but eventually gave up, when I always encountered ld errors. I think going forward for Windows 10 it will be much easier to use the embedded Ubuntu to execute and extend Python.
(See How to enable Bash in Windows 10 developer preview? and Getting PyCharm to recognize python on the windows linux subsystem (bash on windows))

Error during the installation of Cython

I have installed SimpleCV 1.3 powerpack in my Windows 8.1. Then i set up the required path. And then i installed pyreadline, PIL, pip, ipython via cmd. But when i tried to run easy_install cython, i'm getting the following error,
C:\Users\Ankit>easy_install Cython
Searching for Cython
Reading http://pypi.python.org/simple/Cython/
Best match: Cython 0.22
Downloading https://pypi.python.org/packages/source/C/Cython/Cython-0.22.tar.gz#
md5=1ae25add4ef7b63ee9b4af697300d6b6
Processing Cython-0.22.tar.gz
Running Cython-0.22\setup.py -q bdist_egg --dist-dir c:\users\ankit\appdata\local
\temp\easy_install-lvjvzj\Cython-0.22\egg-dist-tmp-aeuxtq
Unable to find pgen, not compiling formal grammar.
Compiling module Cython.Plex.Scanners ...
Compiling module Cython.Plex.Actions ...
Compiling module Cython.Compiler.Lexicon ...
Compiling module Cython.Compiler.Scanning ...
Compiling module Cython.Compiler.Parsing ...
Compiling module Cython.Compiler.Visitor ...
Compiling module Cython.Compiler.FlowControl ...
Compiling module Cython.Compiler.Code ...
Compiling module Cython.Tempita._tempita ...
warning: no files found matching '*.pyx' under directory 'Cython\Debugger\Test'
warning: no files found matching '*.pxd' under directory 'Cython\Debugger\Test
warning: no files found matching '*.pxd' under directory 'Cython\Utility'
Scanners.c
C:\Python27\include\pyconfig.h(227) : fatal error C1083: Cannot open include file: 'basetsd.h': No such fil
e or directory
error: Setup script exited with error: command '"C:\Program Files (x86)\Microsof
t Visual Studio 9.0\VC\BIN\cl.exe"' failed with exit status 2
Please help me out.
I'm using a double partition system Windows8/Xubuntu14.04LTS.
I had the same issue when attempting to install Cython onto Xubuntu via pip.
So I installed Cython with below command and and everything went ok.
bashsh $ sudo apt-get install cython
This is not the best fix. But, may worth a trial if you are really
looking to port an almost complete project to Windows8.
You compile your Python main (without main):
bash $ cython --embed -o prog.c prog.py
You may decide to install Mxe (MingW) gcc on linux and do
cross compiling or, as me, to compile directly in the windows8:
bash $ gcc -Os -IC:\Python27\include -LC:\Python27\libs -o prog.exe prog.c -lpython27 -DMS_WIN64
Hope this might be of any help.

How to get the CUDA version?

Is there any quick command or script to check for the version of CUDA installed?
I found the manual of 4.0 under the installation directory but I'm not sure whether it is of the actual installed version or not.
As Jared mentions in a comment, from the command line:
nvcc --version
(or /usr/local/cuda/bin/nvcc --version) gives the CUDA compiler version (which matches the toolkit version).
From application code, you can query the runtime API version with
cudaRuntimeGetVersion()
or the driver API version with
cudaDriverGetVersion()
As Daniel points out, deviceQuery is an SDK sample app that queries the above, along with device capabilities.
As others note, you can also check the contents of the version.txt using (e.g., on Mac or Linux)
cat /usr/local/cuda/version.txt
However, if there is another version of the CUDA toolkit installed other than the one symlinked from /usr/local/cuda, this may report an inaccurate version if another version is earlier in your PATH than the above, so use with caution.
On Ubuntu Cuda V8:
$ cat /usr/local/cuda/version.txt
You can also get some insights into which CUDA versions are installed with:
$ ls -l /usr/local | grep cuda
which will give you something like this:
lrwxrwxrwx 1 root root 9 Mar 5 2020 cuda -> cuda-10.2
drwxr-xr-x 16 root root 4096 Mar 5 2020 cuda-10.2
drwxr-xr-x 16 root root 4096 Mar 5 2020 cuda-8.0.61
Given a sane PATH, the version cuda points to should be the active one (10.2 in this case).
NOTE: This only works if you are willing to assume CUDA is installed under /usr/local/cuda (which is true for the independent installer with the default location, but not true e.g. for distributions with CUDA integrated as a package). Ref: comment from #einpoklum.
[Edited answer. Thanks for everyone who corrected it]
If you run
nvidia-smi
You should find the CUDA Version highest CUDA version the installed driver supports on the top right corner of the comand's output. At least I found that output for CUDA version 10.0 e.g.,
For CUDA version:
nvcc --version
Or use,
nvidia-smi
For cuDNN version:
For Linux:
Use following to find path for cuDNN:
$ whereis cuda
cuda: /usr/local/cuda
Then use this to get version from header file,
$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
For Windows,
Use following to find path for cuDNN:
C:\>where cudnn*
C:\Program Files\cuDNN7\cuda\bin\cudnn64_7.dll
Then use this to dump version from header file,
type "%PROGRAMFILES%\cuDNN7\cuda\include\cudnn.h" | findstr CUDNN_MAJOR
If you're getting two different versions for CUDA on Windows -
Different CUDA versions shown by nvcc and NVIDIA-smi
Use the following command to check CUDA installation by Conda:
conda list cudatoolkit
And the following command to check CUDNN version installed by conda:
conda list cudnn
If you want to install/update CUDA and CUDNN through CONDA, please use the following commands:
conda install -c anaconda cudatoolkit
conda install -c anaconda cudnn
Alternatively you can use following commands to check CUDA installation:
nvidia-smi
OR
nvcc --version
If you are using tensorflow-gpu through Anaconda package (You can verify this by simply opening Python in console and check if the default python shows Anaconda, Inc. when it starts, or you can run which python and check the location), then manually installing CUDA and CUDNN will most probably not work. You will have to update through conda instead.
If you want to install CUDA, CUDNN, or tensorflow-gpu manually, you can check out the instructions here https://www.tensorflow.org/install/gpu
Other respondents have already described which commands can be used to check the CUDA version. Here, I'll describe how to turn the output of those commands into an environment variable of the form "10.2", "11.0", etc.
To recap, you can use
nvcc --version
to find out the CUDA version.
I think this should be your first port of call.
If you have multiple versions of CUDA installed, this command should print out the version for the copy which is highest on your PATH.
The output looks like this:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0
We can pass this output through sed to pick out just the MAJOR.MINOR release version number.
CUDA_VERSION=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p')
If nvcc isn't on your path, you should be able to run it by specifying the full path to the default location of nvcc instead.
/usr/local/cuda/bin/nvcc --version
The output of which is the same as above, and it can be parsed in the same way.
Alternatively, you can find the CUDA version from the version.txt file.
cat /usr/local/cuda/version.txt
The output of which
CUDA Version 10.1.243
can be parsed using sed to pick out just the MAJOR.MINOR release version number.
CUDA_VERSION=$(cat /usr/local/cuda/version.txt | sed 's/.* \([0-9]\+\.[0-9]\+\).*/\1/')
Note that sometimes the version.txt file refers to a different CUDA installation than the nvcc --version. In this scenario, the nvcc version should be the version you're actually using.
We can combine these three methods together in order to robustly get the CUDA version as follows:
if nvcc --version 2&> /dev/null; then
# Determine CUDA version using default nvcc binary
CUDA_VERSION=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p');
elif /usr/local/cuda/bin/nvcc --version 2&> /dev/null; then
# Determine CUDA version using /usr/local/cuda/bin/nvcc binary
CUDA_VERSION=$(/usr/local/cuda/bin/nvcc --version | sed -n 's/^.*release \([0-9]\+\.[0-9]\+\).*$/\1/p');
elif [ -f "/usr/local/cuda/version.txt" ]; then
# Determine CUDA version using /usr/local/cuda/version.txt file
CUDA_VERSION=$(cat /usr/local/cuda/version.txt | sed 's/.* \([0-9]\+\.[0-9]\+\).*/\1/')
else
CUDA_VERSION=""
fi
This environment variable is useful for downstream installations, such as when pip installing a copy of pytorch that was compiled for the correct CUDA version.
python -m pip install \
"torch==1.9.0+cu${CUDA_VERSION/./}" \
"torchvision==0.10.0+cu${CUDA_VERSION/./}" \
-f https://download.pytorch.org/whl/torch_stable.html
Similarly, you could install the CPU version of pytorch when CUDA is not installed.
if [ "$CUDA_VERSION" = "" ]; then
MOD="+cpu";
echo "Warning: Installing CPU-only version of pytorch"
else
MOD="+cu${CUDA_VERSION/./}";
echo "Installing pytorch with $MOD"
fi
python -m pip install \
"torch==1.9.0${MOD}" \
"torchvision==0.10.0${MOD}" \
-f https://download.pytorch.org/whl/torch_stable.html
But be careful with this because you can accidentally install a CPU-only version when you meant to have GPU support.
For example, if you run the install script on a server's login node which doesn't have GPUs and your jobs will be deployed onto nodes which do have GPUs. In this case, the login node will typically not have CUDA installed.
On Ubuntu :
Try
$ cat /usr/local/cuda/version.txt
or
$ cat /usr/local/cuda-8.0/version.txt
Sometimes the folder is named "Cuda-version".
If none of above works, try going to
$ /usr/local/
And find the correct name of your Cuda folder.
Output should be similar to:
CUDA Version 8.0.61
If you have installed CUDA SDK, you can run "deviceQuery" to see the version of CUDA
If you have PyTorch installed, you can simply run the following code in your IDE:
import torch
print(torch.version.cuda)
On Windows 10, I found nvidia-smi.exe in 'C:\Program Files\NVIDIA Corporation\NVSMI'; after cd into that folder (was not in the PATH in my case) and '.\nvidia-smi.exe' it showed
You might find CUDA-Z useful, here is a quote from their Site:
"This program was born as a parody of another Z-utilities such as CPU-Z and GPU-Z. CUDA-Z shows some basic information about CUDA-enabled GPUs and GPGPUs. It works with nVIDIA Geforce, Quadro and Tesla cards, ION chipsets."
http://cuda-z.sourceforge.net/
On the Support Tab there is the URL for the Source Code: http://sourceforge.net/p/cuda-z/code/ and the download is not actually an Installer but the Executable itself (no installation, so this is "quick").
This Utility provides lots of information and if you need to know how it was derived there is the Source to look at. There are other Utilities similar to this that you might search for.
One can get the cuda version by typing the following in the terminal:
$ nvcc -V
# below is the result
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
Alternatively, one can manually check for the version by first finding out the installation directory using:
$ whereis -b cuda
cuda: /usr/local/cuda
And then cd into that directory and check for the CUDA version.
We have three ways to check Version:
In my case below is the output:-
Way 1:-
cat /usr/local/cuda/version.txt
Output:-
CUDA Version 10.1.243
Way2:-
nvcc --version
Output:-
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
Way3:-
/usr/local/cuda/bin/nvcc --version
Output:-
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243
Way4:-
nvidia-smi
NVIDIA-SMI 450.36.06 Driver Version: 450.36.06 CUDA Version: 11.0
Outputs are not same. Don't know why it's happening.
First you should find where Cuda installed.
If it's a default installation like here the location should be:
for ubuntu:
/usr/local/cuda
in this folder you should have a file
version.txt
open this file with any text editor or run:
cat version.txt
from the folder
OR
cat /usr/local/cuda/version.txt
On Windows 11 with CUDA 11.6.1, this worked for me:
cat "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\version.json"
if nvcc --version is not working for you then use cat /usr/local/cuda/version.txt
After installing CUDA one can check the versions by: nvcc -V
I have installed both 5.0 and 5.5 so it gives
Cuda Compilation Tools,release 5.5,V5.5,0
This command works for both Windows and Ubuntu.
Apart from the ones mentioned above, your CUDA installations path (if not changed during setup) typically contains the version number
doing a which nvcc should give the path and that will give you the version
PS: This is a quick and dirty way, the above answers are more elegant and will result in the right version with considerable effort
If you are running on linux:
dpkg -l | grep cuda
If you have multiple CUDA installed, the one loaded in your system is CUDA associated with "nvcc". Therefore, "nvcc --version" shows what you want.
Open a terminal and run these commands:
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
You can get the information of CUDA Driver version, CUDA Runtime Version, and also detailed information for GPU(s). An image example of the output from my end is as below.
You can find the image here.
i get /usr/local - no such file or directory. Though nvcc -V gives
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44
Found mine after:
whereis cuda
at
cuda: /usr/lib/cuda /usr/include/cuda.h
with
nvcc --version
CUDA Version 9.1.85
Using tensorflow:
import tensorflow as tf
from tensorflow.python.platform import build_info as build
print(f"tensorflow version: {tf.__version__}")
print(f"Cuda Version: {build.build_info['cuda_version']}")
print(f"Cudnn version: {build.build_info['cudnn_version']}")
tensorflow version: 2.4.0
Cuda Version: 11.0
Cudnn version: 8
Programmatically with the CUDA Runtime API C++ wrappers (caveat: I'm the author):
auto v1 = cuda::version::maximum_supported_by_driver();
auto v2 = cuda::version::runtime();
This gives you a cuda::version_t structure, which you can compare and also print/stream e.g.:
if (v2 < cuda::version_t{ 8, 0 } ) {
std::cerr << "CUDA version " << v2 << " is insufficient." std::endl;
}
You can check the version of CUDA using
nvcc -V
or you can use
nvcc --version
or You can check the location of where the CUDA is using
whereis cuda
and then do
cat location/of/cuda/you/got/from/above/command
On my cuda-11.6.0 installation, the information can be found in /usr/local/cuda/version.json. It contains the full version number (11.6.0 instead of 11.6 as shown by nvidia-smi.
The information can be retrieved as follows:
python -c 'import json; print(json.load(open("/usr/local/cuda/version.json"))["cuda"]["version"])'
If there is a version mismatch between nvcc and nvidia-smi then different versions of cuda are used as driver and run time environemtn.
To ensure same version of CUDA drivers are used what you need to do is to get CUDA on system path.
First run whereis cuda and find the location of cuda driver.
Then go to .bashrc and modify the path variable and set the directory precedence order of search using variable 'LD_LIBRARY_PATH'.
for instance
$ whereis cuda
cuda: /usr/lib/cuda /usr/include/cuda.h /usr/local/cuda
CUDA is installed at /usr/local/cuda, now we need to to .bashrc and add the path variable as:
vim ~/.bashrc
export PATH="/usr/local/cuda/bin:${PATH}"
and after this line set the directory search path as:
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
Then save the .bashrc file. And refresh it as:
$ source ~/.bashrc
This will ensure you have nvcc -V and nvidia-smi to use the same version of drivers.