链接Cuda在C ++问题 [英] Linking Cuda in C++ issue
本文介绍了链接Cuda在C ++问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了现有的问题,但我似乎无法解决这个问题。
我有一个blur_mask.cc文件:
#include< iostream>
#include< ctime>
#include< opencv2 / highgui / highgui.hpp>
#include< opencv2 / gpu / gpu.hpp>
#include< vector_types.h>
#include< cuda.h>
#include< cuda_runtime.h>
externCvoid gpuBlurMask(unsigned char * srcData,int srcStep,uchar3 * dst,int dstStep,int width,int height,float * mask,int maskStep,int maskWidth,int maskHeight,int blockSize = 16);
using namespace std;
using namespace cv;
using namespace cv :: gpu;
void blurMask(Mat& src,Mat& dst,Mat& mask){
GpuMat gpuSrc,gpuDst,gpuMask;
gpuSrc.upload(src);
gpuDst.upload(dst);
gpuMask.upload(mask);
gpuBlurMask(gpuSrc.data,gpuSrc.step,gpuDst.ptr< uchar3>(),gpuDst.step,gpuSrc.cols,gpuSrc.rows,gpuMask.ptr< float>(),gpuMask。 step,gpuMask.cols,gpuMask.rows);
gpuDst.download(dst);
}
...
一个gpu_blur.cu文件包含
externC
void gpuBlurMask(unsigned char * srcData,int srcStep,uchar3 * dst,int dstStep,int width,int height,float * mask,int maskStep,int maskWidth,int maskHeight,int blockSize = 16){
...
当我做
nvcc -c -o gpu_blur gpu_blur.cu
我没有错误,但在编译时
g ++ -o blur_mask blur_mask.cc gpu_blur -I / usr / local / cuda / include / -lopencv_core -lopencv_highgui -lopencv_gpu
我得到以下错误:
g ++ -o blur_mask blur_mask.cc gpu_blur - I / usr / local / cuda / include / -lopencv_core -lopencv_highgui -lopencv_gpu -lcuda
gpu_blur:在函数`gpuBlurMask'中:
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(。text + 0x59):undefined引用`cudaMallocArray'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :( .text + 0xa0):未定义引用`cudaMemcpy2DToArray'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(。+ 0x139):undefined参考`cudaConfigureCall'。
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文字+ 0x16f):未定义的参考`cudaDeviceSynchronize'
gpu_blur:在功能`__cudaUnregisterBinaryUtil():
tmpxft_00000905_00000000- 3_gpu_blur.cudafe1.cpp :(。text + 0x184):未定义的引用`__cudaUnregisterFatBinary'
gpu_blur:在函数`__device_stub__Z14blurMaskKernelP6uchar3iiiPfiii(uchar3 *,int,int,int,float *,int,int,int)
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文字+ 0x1b9):未定义的参考`cudaSetupArgument'。
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文字+ 0x1dc):未定义的参考`cudaSetupArgument
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文字+到0x1FF):未定义的参考`cudaSetupArgument'。
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文字+ 0x222):未定义的参考`cudaSetupArgument
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(。text + 0x245):未定义的引用`cudaSetupArgument'
gpu_blur:tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(。text + 0x264):更多未定义的引用`cudaSetupArgument'follow
gpu_blur:在函数`__nv_cudaEntityRegisterCallback(void **)'中:
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :( .text + 0x381):未定义引用`__cudaRegisterFunction'
。tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文字+ 0x3af):未定义的参考`__cudaRegisterTexture'
gpu_blur:在功能`__sti ____ cudaRegisterAll_43_tmpxft_00000905_00000000_6_gpu_blur_cpp1_ii_srcTex():
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :(文+ 0x3c3):未定义的参考`__cudaRegisterFatBinary'
gpu_blur:在功能`cudaChannelFormatDesc cudaCreateChannelDesc< unsigned char型>():
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :( text._Z21cudaCreateChannelDescIhE21cudaChannelFormatDescv [cudaChannelFormatDesc cudaCreateChannelDesc<。 unsigned char型>()] + 0x34):未定义的参考`cudaCreateChannelDesc'
gpu_blur:在功能`cudaError cudaBindTextureToArray< unsigned char型,2,(cudaTextureReadMode)0>(质地LT; unsigned char型,2,(cudaTextureReadMode)0> ;常量和放大器;,cudaArray常量*,cudaChannelFormatDesc常量和放大器;):
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :( text._Z22cudaBindTextureToArrayIhLi2EL19cudaTextureReadMode0EE9cudaErrorRK7textureIT_XT0_EXT1_EEPK9cudaArrayRK21cudaChannelFormatDesc [cudaError cudaBindTextureToArray< unsigned char型,2,(cudaTextureReadMode)0>(质地LT; unsigned char型。 2,(cudaTextureReadMode)0>常量和放大器;,cudaArray常量*,cudaChannelFormatDesc常量和放大器;)] + 0×27):未定义的参考`cudaBindTextureToArray'
gpu_blur:在功能`cudaError cudaLaunch<焦炭>(字符*)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp :( .text._Z10cudaLaunchIcE9cudaErrorPT_ [cudaError cudaLaunch< char>(char *)] + 0x14):未定义的引用`cudaLaunch'
collect2:ld返回1退出状态$ b谢谢。解决方案 div> 您需要链接到cudart库( -L / usr / local / cuda / lib64 -lcudart
)
I've searched existing questions, but I can't seem to solve this.
I have a blur_mask.cc file with:
#include <iostream>
#include <ctime>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include <vector_types.h>
#include <cuda.h>
#include <cuda_runtime.h>
extern "C" void gpuBlurMask(unsigned char* srcData, int srcStep, uchar3* dst, int dstStep, int width, int height, float *mask, int maskStep, int maskWidth, int maskHeight, int blockSize=16);
using namespace std;
using namespace cv;
using namespace cv::gpu;
void blurMask(Mat& src, Mat& dst, Mat& mask) {
GpuMat gpuSrc, gpuDst, gpuMask;
gpuSrc.upload(src);
gpuDst.upload(dst);
gpuMask.upload(mask);
gpuBlurMask(gpuSrc.data, gpuSrc.step, gpuDst.ptr<uchar3>(), gpuDst.step, gpuSrc.cols, gpuSrc.rows, gpuMask.ptr<float>(), gpuMask.step, gpuMask.cols, gpuMask.rows);
gpuDst.download(dst);
}
...
And a gpu_blur.cu file that contains
extern "C"
void gpuBlurMask(unsigned char* srcData, int srcStep, uchar3* dst, int dstStep, int width, int height, float *mask, int maskStep, int maskWidth, int maskHeight, int blockSize=16) {
...
When I do
nvcc -c -o gpu_blur gpu_blur.cu
I get no errors, but when compiling
g++ -o blur_mask blur_mask.cc gpu_blur -I /usr/local/cuda/include/ -lopencv_core -lopencv_highgui -lopencv_gpu
I get the following errors:
g++ -o blur_mask blur_mask.cc gpu_blur -I /usr/local/cuda/include/ -lopencv_core -lopencv_highgui -lopencv_gpu -lcuda
gpu_blur: In function `gpuBlurMask':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x59): undefined reference to `cudaMallocArray'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0xa0): undefined reference to `cudaMemcpy2DToArray'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x139): undefined reference to `cudaConfigureCall'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x16f): undefined reference to `cudaDeviceSynchronize'
gpu_blur: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x184): undefined reference to `__cudaUnregisterFatBinary'
gpu_blur: In function `__device_stub__Z14blurMaskKernelP6uchar3iiiPfiii(uchar3*, int, int, int, float*, int, int, int)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x1b9): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x1dc): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x1ff): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x222): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x245): undefined reference to `cudaSetupArgument'
gpu_blur:tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x264): more undefined references to `cudaSetupArgument' follow
gpu_blur: In function `__nv_cudaEntityRegisterCallback(void**)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x381): undefined reference to `__cudaRegisterFunction'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x3af): undefined reference to `__cudaRegisterTexture'
gpu_blur: In function `__sti____cudaRegisterAll_43_tmpxft_00000905_00000000_6_gpu_blur_cpp1_ii_srcTex()':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x3c3): undefined reference to `__cudaRegisterFatBinary'
gpu_blur: In function `cudaChannelFormatDesc cudaCreateChannelDesc<unsigned char>()':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text._Z21cudaCreateChannelDescIhE21cudaChannelFormatDescv[cudaChannelFormatDesc cudaCreateChannelDesc<unsigned char>()]+0x34): undefined reference to `cudaCreateChannelDesc'
gpu_blur: In function `cudaError cudaBindTextureToArray<unsigned char, 2, (cudaTextureReadMode)0>(texture<unsigned char, 2, (cudaTextureReadMode)0> const&, cudaArray const*, cudaChannelFormatDesc const&)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text._Z22cudaBindTextureToArrayIhLi2EL19cudaTextureReadMode0EE9cudaErrorRK7textureIT_XT0_EXT1_EEPK9cudaArrayRK21cudaChannelFormatDesc[cudaError cudaBindTextureToArray<unsigned char, 2, (cudaTextureReadMode)0>(texture<unsigned char, 2, (cudaTextureReadMode)0> const&, cudaArray const*, cudaChannelFormatDesc const&)]+0x27): undefined reference to `cudaBindTextureToArray'
gpu_blur: In function `cudaError cudaLaunch<char>(char*)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch'
collect2: ld returned 1 exit status
Thank you.
解决方案 You need to link to cudart library (-L/usr/local/cuda/lib64 -lcudart
)
这篇关于链接Cuda在C ++问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文