Play with CUDA
Need to program on CUDA, so try to compile some examples first.
Installation
I already have CUDA installed on my system, so this section is just a list of commands that might be useful when installation.
Lookup Linux Centos release version:
$cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)Look up Unix system information:
$uname -a
Linux tehp1308 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/LinuxList PCI devices, search for Nvidia devices only, case insensitively:
$lspci | grep -i nvidia
2d:00.0 VGA compatible controller: NVIDIA Corporation Device 2204 (rev a1)
2d:00.1 Audio device: NVIDIA Corporation Device 1aef (rev a1)gcc compiler support:
$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)Upgrade gcc version temporaryly
$sudo yum -y install centos-release-scl
$sudo yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
$sudo scl enable devtoolset-8 csh
$which gcc
/opt/rh/devtoolset-8/root/usr/bin/gcc
$gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.if let it be permanent
$echo "source /opt/rh/devtoolset-8/enable" >>/etc/profileAfter installation:
test nvcc version:
$nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Tue_Sep_15_19:10:02_PDT_2020
Cuda compilation tools, release 11.1, V11.1.74
Build cuda_11.1.TC455_06.29069683_0Compile the examples
try to compile one of the samples
$cd NVIDIA-Sample
$make
...
$cd bin/x86_64/linux/release/ # where the compiled files storedcompilation error: cannot find -lglut
compilation with get failed at some samples and the error message shows:
/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/ld: cannot find -lglut
collect2: error: ld returned 1 exit status
check libglut:
$ls /usr/lib64 |grep glut
libkwinglutils.so.1
libkwinglutils.so.1.0.0it turns out there is no libglut exist, install by yum
$sudo yum install freeglut
...
$ls /usr/lib64 | grep glut
libglut.so.3
libglut.so.3.10.0
libkwinglutils.so.1
libkwinglutils.so.1.0.0try compile, the same error exit, gcc does not manage to find the lib, according to solve the problem of “cannot find -lglut”, link this file as libglut.so.
sudo ln -s /usr/lib64/libglut.so.3 /usr/lib64/libglut.socompile success!
Play with examples
$./vectorAddDrv # a small case
Vector Addition (Driver API)
> Using CUDA Device [0]: GeForce RTX 3090
> findModulePath found file at <./vectorAdd_kernel64.ptx>
> initCUDA loading module: <./vectorAdd_kernel64.ptx>
> PTX JIT log:
Result = PASS
$./deviceQuery
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce RTX 3090"
CUDA Driver Version / Runtime Version 11.2 / 11.1
CUDA Capability Major/Minor version number: 8.6
Total amount of global memory: 24259 MBytes (25437339648 bytes)
(82) Multiprocessors, (128) CUDA Cores/MP: 10496 CUDA Cores
GPU Max Clock rate: 1695 MHz (1.70 GHz)
Memory Clock rate: 9751 Mhz
Memory Bus Width: 384-bit
L2 Cache Size: 6291456 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total shared memory per multiprocessor: 102400 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 1536
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Managed Memory: Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 45 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.2, CUDA Runtime Version = 11.1, NumDevs = 1
Result = PASS