Я пытаюсь составить следующую программу, которая является MEX файл CUDA для MATLAB, с помощью Visual Studio 2013.
Есть instructions доступны на официальном сайте MATLAB только для C++ Mex файлы, а не для CUDA mex.
Итак, я сделал следующие дополнительные изменения в настройках моего проекта, следуя официальным инструкциям в Mathworks:
1. Я создал проект с использованием проекта Visual Studio с установленной установкой CUDA 6.5.
2. Включил libs (libmx.lib, libmex.lib, libmat.lib, gpu.lib) в свойствах Linker моего проекта VS,
3. Добавлена директория include (MATLABROOT) \ toolbox \ distcomp \ gpu \ ехЬегп \ включают в себя;Компиляция CUDA Mex файлы с помощью Visual Studio 2013 IDE
Тем не менее, я получаю много нерешенных ошибок внешнего символа. Каков правильный способ сделать это, поскольку нет официальной документации для компиляции CUDA Mex с использованием VS IDE? Кто-нибудь знает, как правильно это сделать? Наверняка, мне не хватает некоторых настроек, может кто-нибудь помочь?
Моя программа (скопировано из MATLAB пример файла, mexGPUExample.cu) выглядит следующим образом:
**
/*
* Example of how to use the mxGPUArray API in a MEX file. This example shows
* how to write a MEX function that takes a gpuArray input and returns a
* gpuArray output, e.g. B=mexFunction(A).
*
* Copyright 2012 The MathWorks, Inc.
*/
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "mex.h"
#include "gpu/mxGPUArray.h"
/*
* Device code
*/
void __global__ TimesTwo(double const * const A,
double * const B,
int const N)
{
/* Calculate the global linear index, assuming a 1-d grid. */
int const i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < N) {
B[i] = 2.0 * A[i];
}
}
/*
* Host code
*/
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, mxArray const *prhs[])
{
/* Declare all variables.*/
mxGPUArray const *A;
mxGPUArray *B;
double const *d_A;
double *d_B;
int N;
char const * const errId = "parallel:gpu:mexGPUExample:InvalidInput";
char const * const errMsg = "Invalid input to MEX file.";
/* Choose a reasonably sized number of threads for the block. */
int const threadsPerBlock = 256;
int blocksPerGrid;
/* Initialize the MathWorks GPU API. */
mxInitGPU();
/* Throw an error if the input is not a GPU array. */
if ((nrhs != 1) || !(mxIsGPUArray(prhs[0]))) {
mexErrMsgIdAndTxt(errId, errMsg);
}
A = mxGPUCreateFromMxArray(prhs[0]);
/*
* Verify that A really is a double array before extracting the pointer.
*/
if (mxGPUGetClassID(A) != mxDOUBLE_CLASS) {
mexErrMsgIdAndTxt(errId, errMsg);
}
/*
* Now that we have verified the data type, extract a pointer to the input
* data on the device.
*/
d_A = (double const *)(mxGPUGetDataReadOnly(A));
/* Create a GPUArray to hold the result and get its underlying pointer. */
B = mxGPUCreateGPUArray(mxGPUGetNumberOfDimensions(A),
mxGPUGetDimensions(A),
mxGPUGetClassID(A),
mxGPUGetComplexity(A),
MX_GPU_DO_NOT_INITIALIZE);
d_B = (double *)(mxGPUGetData(B));
/*
* Call the kernel using the CUDA runtime API. We are using a 1-d grid here,
* and it would be possible for the number of elements to be too large for
* the grid. For this example we are not guarding against this possibility.
*/
N = (int)(mxGPUGetNumberOfElements(A));
blocksPerGrid = (N + threadsPerBlock - 1)/threadsPerBlock;
TimesTwo <<< blocksPerGrid, threadsPerBlock >>>(d_A, d_B, N);
/* Wrap the result up as a MATLAB gpuArray for return. */
plhs[0] = mxGPUCreateMxArrayOnGPU(B);
/*
* The mxGPUArray pointers are host-side structures that refer to device
* data. These must be destroyed before leaving the MEX function.
*/
mxGPUDestroyGPUArray(A);
mxGPUDestroyGPUArray(B);
}
Ошибки, которые я получаю, когда я пытаюсь скомпилировать свою программу:
Error 66 error LNK1120: 64 unresolved externals
Error 64 error LNK2001: unresolved external symbol _fltused
Error 62 error LNK2001: unresolved external symbol _RTC_InitBase
Error 63 error LNK2001: unresolved external symbol _RTC_Shutdown
Error 65 error LNK2001: unresolved external symbol mainCRTStartup
Error 58 error LNK2019: unresolved external symbol __imp__dsign referenced in function "bool __cdecl signbit(double)" ([email protected]@[email protected])
Error 60 error LNK2019: unresolved external symbol __imp__fdsign referenced in function "bool __cdecl signbit(float)" ([email protected]@[email protected])
Error 61 error LNK2019: unresolved external symbol __imp__hypotf referenced in function hypotf
Error 59 error LNK2019: unresolved external symbol __imp__ldsign referenced in function "bool __cdecl signbit(long double)" ([email protected]@[email protected])
Error 39 error LNK2019: unresolved external symbol __imp_acosf referenced in function "float __cdecl acos(float)" ([email protected]@[email protected])
Error 12 error LNK2019: unresolved external symbol __imp_acoshf referenced in function "float __cdecl acosh(float)" ([email protected]@[email protected])
Error 40 error LNK2019: unresolved external symbol __imp_asinf referenced in function "float __cdecl asin(float)" ([email protected]@[email protected])
Error 13 error LNK2019: unresolved external symbol __imp_asinhf referenced in function "float __cdecl asinh(float)" ([email protected]@[email protected])
Error 42 error LNK2019: unresolved external symbol __imp_atan2f referenced in function "float __cdecl atan2(float,float)" ([email protected]@[email protected])
Error 41 error LNK2019: unresolved external symbol __imp_atanf referenced in function "float __cdecl atan(float)" ([email protected]@[email protected])
Error 14 error LNK2019: unresolved external symbol __imp_atanhf referenced in function "float __cdecl atanh(float)" ([email protected]@[email protected]) D:\GitHub\arrayfire-windows-scripts\SimpleCUDAProj\CUDA_Mex\CUDA_Mex\CUDA_Times_Two.cu.obj CUDA_Mex
Error 29 error LNK2019: unresolved external symbol __imp_cbrtf referenced in function "float __cdecl cbrt(float)" ([email protected]@[email protected])
Error 55 error LNK2019: unresolved external symbol __imp_ceilf referenced in function "float __cdecl ceil(float)" ([email protected]@[email protected])
Error 36 error LNK2019: unresolved external symbol __imp_copysignf referenced in function "float __cdecl copysign(float,float)" ([email protected]@[email protected])
Error 43 error LNK2019: unresolved external symbol __imp_cosf referenced in function "float __cdecl cos(float)" ([email protected]@[email protected])
Error 46 error LNK2019: unresolved external symbol __imp_coshf referenced in function "float __cdecl cosh(float)" ([email protected]@[email protected])
Error 33 error LNK2019: unresolved external symbol __imp_erfcf referenced in function "float __cdecl erfc(float)" ([email protected]@[email protected])
Error 32 error LNK2019: unresolved external symbol __imp_erff referenced in function "float __cdecl erf(float)" ([email protected]@[email protected])
Error 8 error LNK2019: unresolved external symbol __imp_exp2f referenced in function "float __cdecl exp2(float)" ([email protected]@[email protected])
Error 49 error LNK2019: unresolved external symbol __imp_expf referenced in function "float __cdecl exp(float)" ([email protected]@[email protected])
Error 9 error LNK2019: unresolved external symbol __imp_expm1f referenced in function "float __cdecl expm1(float)" ([email protected]@[email protected])
Error 28 error LNK2019: unresolved external symbol __imp_fdimf referenced in function "float __cdecl fdim(float,float)" ([email protected]@[email protected])
Error 56 error LNK2019: unresolved external symbol __imp_floorf referenced in function "float __cdecl floor(float)" ([email protected]@[email protected])
Error 38 error LNK2019: unresolved external symbol __imp_fmaf referenced in function "float __cdecl fma(float,float,float)" ([email protected]@[email protected])
Error 7 error LNK2019: unresolved external symbol __imp_fmaxf referenced in function "float __cdecl fmax(float,float)" ([email protected]@[email protected])
Error 6 error LNK2019: unresolved external symbol __imp_fminf referenced in function "float __cdecl fmin(float,float)" ([email protected]@[email protected])
Error 57 error LNK2019: unresolved external symbol __imp_fmodf referenced in function "float __cdecl fmod(float,float)" ([email protected]@[email protected])
Error 19 error LNK2019: unresolved external symbol __imp_frexp referenced in function frexpf
Error 17 error LNK2019: unresolved external symbol __imp_ilogbf referenced in function "int __cdecl ilogb(float)" ([email protected]@[email protected])
Error 15 error LNK2019: unresolved external symbol __imp_ldexp referenced in function ldexpf
Error 34 error LNK2019: unresolved external symbol __imp_lgammaf referenced in function "float __cdecl lgamma(float)" ([email protected]@[email protected])
Error 25 error LNK2019: unresolved external symbol __imp_llrintf referenced in function "__int64 __cdecl llrint(float)" ([email protected]@[email protected])
Error 22 error LNK2019: unresolved external symbol __imp_llroundf referenced in function "__int64 __cdecl llround(float)" ([email protected]@[email protected])
Error 51 error LNK2019: unresolved external symbol __imp_log10f referenced in function "float __cdecl log10(float)" ([email protected]@[email protected])
Error 11 error LNK2019: unresolved external symbol __imp_log1pf referenced in function "float __cdecl log1p(float)" ([email protected]@[email protected])
Error 10 error LNK2019: unresolved external symbol __imp_log2f referenced in function "float __cdecl log2(float)" ([email protected]@[email protected])
Error 16 error LNK2019: unresolved external symbol __imp_logbf referenced in function "float __cdecl logb(float)" ([email protected]@[email protected])
Error 50 error LNK2019: unresolved external symbol __imp_logf referenced in function "float __cdecl log(float)" ([email protected]@[email protected])
Error 24 error LNK2019: unresolved external symbol __imp_lrintf referenced in function "long __cdecl lrint(float)" ([email protected]@[email protected])
Error 21 error LNK2019: unresolved external symbol __imp_lroundf referenced in function "long __cdecl lround(float)" ([email protected]@[email protected])
Error 52 error LNK2019: unresolved external symbol __imp_modff referenced in function "float __cdecl modf(float,float *)" ([email protected]@[email protected])
Error 26 error LNK2019: unresolved external symbol __imp_nearbyintf referenced in function "float __cdecl nearbyint(float)" ([email protected]@[email protected])
Error 37 error LNK2019: unresolved external symbol __imp_nextafterf referenced in function "float __cdecl nextafter(float,float)" ([email protected]@[email protected])
Error 53 error LNK2019: unresolved external symbol __imp_powf referenced in function "float __cdecl pow(float,float)" ([email protected]@[email protected])
Error 30 error LNK2019: unresolved external symbol __imp_remainderf referenced in function "float __cdecl remainder(float,float)" ([email protected]@[email protected])
Error 31 error LNK2019: unresolved external symbol __imp_remquof referenced in function "float __cdecl remquo(float,float,int *)" ([email protected]@[email protected])
Error 23 error LNK2019: unresolved external symbol __imp_rintf referenced in function "float __cdecl rint(float)" ([email protected]@[email protected])
Error 20 error LNK2019: unresolved external symbol __imp_roundf referenced in function "float __cdecl round(float)" ([email protected]@[email protected])
Error 18 error LNK2019: unresolved external symbol __imp_scalblnf referenced in function "float __cdecl scalbln(float,long)" ([email protected]@[email protected])
Error 44 error LNK2019: unresolved external symbol __imp_sinf referenced in function "float __cdecl sin(float)" ([email protected]@[email protected])
Error 47 error LNK2019: unresolved external symbol __imp_sinhf referenced in function "float __cdecl sinh(float)" ([email protected]@[email protected])
Error 54 error LNK2019: unresolved external symbol __imp_sqrtf referenced in function "float __cdecl sqrt(float)" ([email protected]@[email protected])
Error 45 error LNK2019: unresolved external symbol __imp_tanf referenced in function "float __cdecl tan(float)" ([email protected]@[email protected])
Error 48 error LNK2019: unresolved external symbol __imp_tanhf referenced in function "float __cdecl tanh(float)" ([email protected]@[email protected])
Error 35 error LNK2019: unresolved external symbol __imp_tgammaf referenced in function "float __cdecl tgamma(float)" ([email protected]@[email protected])
Error 27 error LNK2019: unresolved external symbol __imp_truncf referenced in function "float __cdecl trunc(float)" ([email protected]@[email protected])
Error 2 error LNK2019: unresolved external symbol atexit referenced in function "void __cdecl __nv_cudaEntityRegisterCallback(void * *)" ([email protected]@[email protected])
Error 5 error LNK2019: unresolved external symbol fabs referenced in function "double __cdecl abs(double)" ([email protected]@[email protected])
Error 3 error LNK2019: unresolved external symbol labs referenced in function "long __cdecl abs(long)" ([email protected]@[email protected])
Error 4 error LNK2019: unresolved external symbol llabs referenced in function "__int64 __cdecl abs(__int64)" ([email protected]@[email protected])
Это [статья] (HTTP://www.orangeowlsolutions.com/archives/498) может представлять интерес. –