mexcuda gives unsupported GNU version error

8 views (last 30 days)
I am trying to call my custom CUDA kernel funciton (C++) from MatLab. I got an error about gcc version, and I need a help to solve it.
When I run
mexcuda -v kernel_func.cu
I got the follwing error:
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc
versions later than 8 are not supported!
138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
| ^~~~~
Error in mexcuda (line 168)
[varargout{1:nargout}] = mex(mexArguments{:});
Matlab version is R2022a (I also tried R2019b and got the same error). nvcc version is 11.7 (I also tryied nvcc version 10.1 and got the same error).
The default gcc / g++ version is 9. So, I tryied to set gcc-8 as follows.
mexcuda GCC=/usr/bin/g++-8 CPPLIB_DIR=/usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so VER=8 -v kernel_func.cu
Although it seems the configuration was modified and used gcc-8, I got the same error. The following is a part of printed configuraiton.
Compiler location: /home/kfujii2/miniconda3/envs/grid_random/bin/nvcc
CXX : /home/kfujii2/miniconda3/envs/grid_random/bin/nvcc
INCLUDE : -I"/usr/local/bin/matlab-R2022a_Linux/extern/include" -I"/usr/local/bin/matlab-R2022a_Linux/simulink/include" -I"/usr/local/bin/matlab-R2022a_Linux/toolbox/parallel/gpu/extern/include/" -I"/home/kfujii2/miniconda3/envs/grid_random/include"
LD="gcc"
LDXX="/usr/bin/g++-8"
CUDA_ROOT : /home/kfujii2/miniconda3/envs/grid_random
LIBDEVICE : /home/kfujii2/miniconda3/envs/grid_random/nvvm/libdevice
CUDA_LIBS : /usr/local/bin/matlab-R2022a_Linux/bin/glnxa64
GCC : /usr/bin/g++-8
CPPLIB_DIR : /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so
VER : 8
GCCDIR : /usr
GCC_TARGET : x86_64-linux-gnu
MATLABROOT : /usr/local/bin/matlab-R2022a_Linux
ARCH : glnxa64
To make sure, I checked nvcc version from Matlab command prompt:
>>!which nvcc
/home/kfujii2/miniconda3/envs/grid_random/bin/nvcc
>> !nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0
When I call the kernel function from C++ main function, GPU works fine. What am I missing? How can I solve this error?

Accepted Answer

Joss Knight
Joss Knight on 11 Sep 2022
R2022a uses CUDA 11.2, not 11.7. I suspect that the actual compiler that ends up being used is the version of nvcc shipped with MATLAB, because yours will be rejected as not matching MATLAB's CUDA version.
It would be useful to see the full -v output of your compilation. It should always be possible to massage things to use the right versions of things. You may find it easier just to move gcc-8 up on your path, since nvcc just uses the path to find the host compiler on linux. Otherwise we might have to add some additional flags to the compile command.
  3 Comments
Joss Knight
Joss Knight on 15 Sep 2022
MATLAB doesn't use the version of nvcc it finds on the system path, it uses the version shipped with the MATLAB installation. So it doesn't matter what !which nvcc says, it only matters what you see in the mexcuda -v output.
Codegen is completely different from mexcuda. Codegen converts your MATLAB code into C code. If you wish, it can then compile it into a MEX-function for you to run from MATLAB, and that should give you the same results as the original MATLAB code and will sometimes be faster (and sometimes a lot slower).
MEXCUDA takes C-code (or C++) that you authored and compiles it into a mex-function.
Keiko Fujii
Keiko Fujii on 15 Sep 2022
I see. To use codegen, I made a MATLAB function just to call the C-function, and codegen made a MEX file of the MATLAB function. While mexcuda makes a MEX file of the C-function. Since my goal is to call the C-function from MATLAB, I have an unnecessary extra function call by my current approach with codegen. The code from codegen doesn't seem too slow so far, but I will try mexcuda for better performance, too.
Thank you very much for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!