toolboxes appear to be improperly installed, matlab unable to locate basic functionalities from the parallel processing toolbox even though I see them in my directory

7 次查看(过去 30 天)
I'm ultimately trying to compile GPU / C-MEX files with my version of Matlab (R2024B), and have all the necessary functionalities installed including necessary matlab toolboxes, notably the parallel processing toolbox.
Please see the very simple test of code that I am trying to compile below:
// simple_gpu_test.c
// Very basic MEX file to test GPU compilation
#include "mex.h"
// Check if we can at least include basic GPU headers
#ifdef MX_HAS_INTERLEAVED_COMPLEX
#include "gpu/mxGPUArray.h"
#endif
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
if (nrhs != 1) {
mexErrMsgTxt("One input required");
}
// Just check if input is a GPU array and return info
bool isGPU = mxIsGPUArray(prhs[0]);
plhs[0] = mxCreateLogicalScalar(isGPU);
if (isGPU) {
mexPrintf("Input is a GPU array\n");
} else {
mexPrintf("Input is a CPU array\n");
}
}
When I tried to compile this basic test, matlab responded with the following error:
>> mex simple_gpu_test.c
Building with 'Microsoft Visual C++ 2022 (C)'.
Error using mex
simple_gpu_test.c
C:\MATLAB DIRECTORY\TOOLBOX RECOURCES\GPU mex compile tutorial\simple_gpu_test.c(7): fatal error
C1083: Cannot open include file: 'gpu/mxGPUArray.h': No such file or directory
>>
I asked a LLM (Claude) about this problem, and Claude implied that the header for the "mxGPUArray.h" file should be 'C:\Program Files\MATLAB\R2024b\extern\include\gpu\mxGPUArray.h', however there was no "gpu" subfolder located in 'C:\Program Files\MATLAB\R2024b\extern\include'. However, I did find the 'mxGPUArray.h' file in a similar subfolder 'C:\Program Files\MATLAB\R2024b\toolbox\parallel\gpu\extern\include\gpu', inside the toolbox's subfolder from I guess how matlab installed the toolbox.
Claude suggested to copy 'C:\Program Files\MATLAB\R2024b\toolbox\parallel\gpu\extern\include\gpu' into 'C:\Program Files\MATLAB\R2024b\extern\include', and when I did that that error message was gone from the compile, but another one was introduced:
>> mex simple_gpu_test.c
Building with 'Microsoft Visual C++ 2022 (C)'.
Error using mex
Creating library simple_gpu_test.lib and object simple_gpu_test.exp
simple_gpu_test.obj : error LNK2019: unresolved external symbol mxIsGPUArray referenced in function mexFunction
simple_gpu_test.mexw64 : fatal error LNK1120: 1 unresolved externals
>>
I think these issues may be a bit beyond me selecting a few files to copy over and over again, so I'm wondering if all these issues stem from matlab doing an improper installation of the parallel processing toolbox from the beginning. The thing is that the toolbox actually works, which I verified with the below checks:
% Check if the toolbox is available and licensed
license('test', 'Distrib_Computing_Toolbox') % Should return 1 if licensed
% Check toolbox version (should work if installed)
ver('parallel')
% Test basic parallel functionality
parpool('local', 2); % This should work if PCT is functional
delete(gcp('nocreate')); % Clean up
which when I performed, I do have an enabled license, and the other two checks work as well.
So the installation appears to have been correctly done for the most part, but maybe not completely. It doesn't seem that I can solve it with a reinstallation of the toolbox, since matlab appears to refuse to install toolboxes when I try to (e.g., when I try to install the parallel processing toolbox that has identifier "DM"):
>> matlab.addons.enableAddon("DM")
Error using enableAddonWithNameOrIdentifierAndVersion (line 96)
Enable/Disable not supported for MathWorks products, MathWorks toolboxes, or support packages.
Error in
matlab.addons.enableAddon (line 44)
enableAddonWithNameOrIdentifierAndVersion(NameOrIdentifier);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Also when I try to see my current installed toolboxes it shows that they are all "disabled", even if they apparently aren't (e.g. in the case with the parallel processing toolbox that was able to do the basic functionalities above):
>> matlab.addons.installedAddons
ans =
13×4 table
Name Version Enabled Identifier
_________________________________________________________ ________ _______ _______________________
"MATLAB Coder" "24.2" false "ME"
"GPU Coder" "24.2" false "GC"
"MATLAB Compiler" "24.2" false "CO"
"New Desktop for MATLAB Tech Preview" "24.2.0" false "ML_JAVASCRIPT_DESKTOP"
"Parallel Computing Toolbox" "24.2" false "DM"
"Image Processing Toolbox" "24.2" false "IP"
"MATLAB Compiler SDK" "24.2" false "MJ"
"MATLAB Support for MinGW-w64 C/C++/Fortran Compiler" "24.2.0" false "ML_MINGW"
"Deep Learning Toolbox" "24.2" false "NN"
"Statistics and Machine Learning Toolbox" "24.2" false "ST"
"Computer Vision Toolbox" "24.2" false "VP"
So in summary, with these observations:
  1. matlab says my toolboxes are not enabled even though I can perform some basic functions from them, and not do some other basic functions,
  2. matlab appears to have several files not in the right locations to do basic GPU compilation tests, even though those files exist in the toolboxes subfolders
I believe that there may have been a faulty installation for some or all of the toolboxes I installed.
I wonder ways of solving this issue, for instance, is there a way for me to simply manually install the toolbox, by copying and pasting folders/files to the directories they need to go to?

回答(1 个)

Joss Knight
Joss Knight 2025-5-28
编辑:Joss Knight 2025-5-28
Hi Benjamin! To compile a mex function which can receive or return gpuArray objects, you need to use the mexcuda command. This will ensure that mex includes all the right directory paths and libraries so you can use the mxGPU APIs.
Hope this helps.
Joss
  2 个评论
Benjamin Gabrielson
Thanks Joss, I solved the problem with your note and with the help of Claude. essentially all the files needed for compilation were in slightly different directories that may not have been unpacked as expected from installing the parallel processing toolbox. Claude wrote an alternative matlab file that I could use to compile my cuda mex files. This included the mexcuda command. Thank you!
Joss Knight
Joss Knight 2025-5-30
Okay...this sounds unlikely (that the installer unpacked files into the wrong directories, assuming you are using a legitimate MATLAB installer). You needed mexcuda because it accesses the correct options file which will put the locations of the mxGPUArray header files and CUDA header files on the include path and the mxgpu library and all the cuda libraries on the library path and ensure those libraries are linked at link time. Because writing CUDA mex files is a bit of a niche use of mex, AI chatbots are quite likely to give misinformation when they attempt to cobble together their knowledge of mex, cuda and compilers.
Still, I'm glad you were unblocked.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with GPU Coder 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by