mexcuda gives unsupported GNU version error

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?

 Respuesta aceptada

Joss Knight
Joss Knight el 11 de Sept. de 2022

0 votos

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 comentarios

Joss, thank you for your reply! I set gcc-8 as my default and it worked.
> 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.
Not being rejected might be because of my computer setup. I am using a shared server. nvcc-10.1 and gcc-9 are installed as the default for all users. I installed nvcc-11.7 with anaconda and made 11.7 default for myself. Although
>> !which nvcc
showed it will be 11.7, Matlab keeps telling me gcc versions later 8 are not supported, which will be the case only for nvcc-10. So, for some reason, it seems Matlab does not use nvcc & gcc I specified. But anyway, by changing my default gcc version to 8, the error is solved.
Now I use codegen instead of mexcuda. Somehow I got my function written in C work by something like the following, but I don't understand the difference of codegen and mexcuda. Do they basically do the same?
>> cfg = coder.gpuConfig('mex');
>> cfg.PostCodeGenCommand = 'buildInfo.addLinkFlags(''-Xcompiler -fopenmp'')';
>> codegen MATLAB_FUNC -config cfg -args {MALTAB_FUNC_ARGS} kernel_func.cu
(Altough this compiles without any error and uses GPU, it seems openmp in the c code is not enabled. That is a challenge I have now.)
Joss Knight
Joss Knight el 15 de Sept. de 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 el 15 de Sept. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with GPU Coder en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 6 de Sept. de 2022

Comentada:

el 15 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by