Effacer les filtres
Effacer les filtres

Problems running Matlab examples of MEX + Cuda

2 vues (au cours des 30 derniers jours)
Gabriel
Gabriel le 31 Juil 2015
Commenté : Walter Roberson le 27 Oct 2016
I am trying to execute a mex file using Nvidia NVCC compiler. I created a .cu and a .h file, as follows:
addVectors.h file:
#ifndef __ADDVECTORS_H__
#define __ADDVECTORS_H__
extern void addVectors(float *A, float *B, float *C, int size);
#endif __ADDVECTORS_H__
addVectors.cu file:
#include "AddVectors.h"
#include "mex.h"
__global__ void addVectorsMask(float *A, float *B, float *C, int size)
{
int ii = blockIdx.x;
if (ii >=size)
return;
C[ii] = A[ii] + B[ii];
}
void addVectors(floar *A, float *B, float *C, int size)
{
float *devA = 0;
float *devB = 0;
float *devC = 0;
cudaMalloc((void**)&devA, sizeof(float)*size);
cudaMalloc((void**)&devB, sizeof(float)*size);
cudaMalloc((void**)&devC, sizeof(float)*size);
cudaMemcpy(devA, A, sizeof(float)*size, cudaMemcpyHostToDevice);
cudaMemcpy(devB, B, sizeof(float)*size, cudaMemcpyHostToDevice);
addVectorMask<<<size, 1>>>(devA, devB, devC, size);
cudaMemcpu(C, devC, sizeof(float)*size, cudaMemcpyDeviceToHost);
cudaFree(devA);
cudaFree(devB);
cudaFree(devC);
}
In order to configure the compilers, I followed this tutorial:
https://scivision.co/matlab-r2013a-mex-on-ubuntu-13-04-64-bit/
When I try to compile it, using the command:
system('nvcc -c AddVectors.cu')
I get the following messages:
In file included from AddVectors.cu:1:
AddVectors.h:6: warning: extra tokens at end of #endif directive
AddVectors.cu:2: fatal error: mex.h: No such file or directory
compilation terminated.
ans =
1
I tried to compile using the verbose mode (-v option) and I got this:
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/usr/local/cuda-5.5/bin
#$ _THERE_=/usr/local/cuda-5.5/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_DIR_=targets/x86_64-linux
#$ TOP=/usr/local/cuda-5.5/bin/..
#$ NVVMIR_LIBRARY_DIR=/usr/local/cuda-5.5/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/usr/local/cuda-5.5/bin/../lib:/usr/local/MATLAB/R2013a/sys/os/glnxa64:/usr/local/MATLAB/R2013a/bin/glnxa64:/usr/local/MATLAB/R2013a/extern/lib/glnxa64:/usr/local/MATLAB/R2013a/runtime/glnxa64:/usr/local/MATLAB/R2013a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/R2013a/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/R2013a/sys/java/jre/glnxa64/jre/lib/amd64::/usr/lib/nvidia-current:/opt/lib64:/opt/lib
#$ PATH=/usr/local/cuda-5.5/bin/../open64/bin:/usr/local/cuda-5.5/bin/../nvvm/bin:/usr/local/cuda-5.5/bin:/home/gabs/.matlab/bin:/home/gabs/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/bin:/opt/lib64:/opt/lib:/usr/local/cuda-5.5/bin/nvcc
#$ INCLUDES="-I/usr/local/cuda-5.5/bin/../targets/x86_64-linux/include"
#$ LIBRARIES= "-L/usr/local/cuda-5.5/bin/../targets/x86_64-linux/lib"
#$ CUDAFE_FLAGS=
#$ OPENCC_FLAGS=
#$ PTXAS_FLAGS=
#$ gcc -D__CUDA_ARCH__=100 -E -x c++ -DCUDA_FLOAT_MATH_FUNCTIONS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS -DCUDA_NO_SM_12_ATOMIC_INTRINSICS -DCUDA_NO_SM_13_DOUBLE_INTRINSICS -D__CUDACC__ -D__NVCC__ "-I/usr/local/cuda-5.5/bin/../targets/x86_64-linux/include" -include "cuda_runtime.h" -m64 -o "/tmp/tmpxft_00003248_00000000-6_AddVectors.cpp1.ii" "AddVectors.cu"
In file included from AddVectors.cu:1:
AddVectors.h:6: warning: extra tokens at end of #endif directive
AddVectors.cu:2: fatal error: mex.h: No such file or directory
compilation terminated.
I also tried the Mathworks example:
But I always get the SAME error message...!
I am using CUDA 5.5, Matlab R2013a and Ubuntu 14.04. What should I do? I looked for some answers, but none of them seem to solve my problem. Any help is appreciated.
  2 commentaires
Gabriel
Gabriel le 31 Juil 2015
Can anyone on Mathworks please help me? It seems that it is a quite recurrent question in this forum and still no answer!
Walter Roberson
Walter Roberson le 27 Oct 2016
You probably need a -I to add a different include directory, the one that contains mex.h

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 31 Juil 2015
Just reading the text of the first compiler warning, it looks like the compiler objects to the _ADDVECTORS_H_ after the #endif in addVectors.h. What happens if you replace that with this?
#endif
Also check the case of your #include; you #include "AddVectors.h" but your post calls that file addVectors.h.
  2 commentaires
Gabriel
Gabriel le 31 Juil 2015
Ok, that solved the first warning, but still, it won't compile:
AddVectors.cu:2: fatal error: mex.h: No such file or directory
compilation terminated.
ans =
1
BenImage
BenImage le 27 Oct 2016
did you ever figure this out? I'm shocked that I can't find someone clearly addressing how to resolve this "mex.h" missing error.....

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Compiler dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by