SIFT using CUDA

Hi,

I would like to use an open-source code which computes SIFT features on GPUs. This code could be accessed at link, https://github.com/Celebrandil/CudaSift

Now, I am trying to extract the SIFT feature points using the code lines below:

#include <cuda_runtime.h>
#include <stdio.h>
#include <cuda.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
extern “C” {
#include “/home/sjs/Downloads/nsight_workspace/SIFT_GPU/cudautils.h”
}
extern “C” {
#include “/home/sjs/Downloads/nsight_workspace/SIFT_GPU/cudaImage.h”
}

extern “C” {
#include “/home/sjs/Downloads/nsight_workspace/SIFT_GPU/cudaSift.h”
}

using namespace std;
using namespace cv;

//int main(int argc, const char* argv)
int main(int argc, char **argv)
{
// Read images using OpenCV
Mat limg = imread(“left.pgm”, CV_LOAD_IMAGE_GRAYSCALE);
limg.convertTo(limg,CV_32FC1);
unsigned int w = limg.cols;
unsigned int h = limg.rows;
printf("\n Left image: cols = %d \t rows = %d \n",w,h);

Mat rimg = imread("righ.pgm", CV_LOAD_IMAGE_GRAYSCALE);
rimg.convertTo(rimg, CV_32FC1);
w = rimg.cols;
h = rimg.rows;
printf("\n Right image: cols = %d \t rows = %d \n",w,h);

// Initial Cuda images and download images to device
printf("\n Initializing data...\n");

int devNum = 0;
InitCuda(devNum);
CudaImage img1, img2;
return 0;

}

Nsight Eclipse IDE is used to compile the above code. There is an error as below:

sift_gpu_v1.cpp:41: undefined reference to InitCuda(int)' sift_gpu_v1.cpp:42: undefined reference to CudaImage::CudaImage()’
sift_gpu_v1.cpp:42: undefined reference to CudaImage::CudaImage()' sift_gpu_v1.cpp:42: undefined reference to CudaImage::~CudaImage()’
sift_gpu_v1.cpp:42: undefined reference to CudaImage::~CudaImage()' sift_gpu_v1.cpp:42: undefined reference to CudaImage::~CudaImage()’
collect2: error: ld returned 1 exit status

Could anyone please suggest the cause for this error and how to resolve this.

Thanks.

The constructor and destructor for CudaImage are provided by cudaImage.cu:

https://github.com/Celebrandil/CudaSift/blob/Maxwell/cudaImage.cu

have you added that file to your project?

Thanks txbob. When i added the cudaImage.cu file 5 errros were resolved. Now there is one error remaining. I can understand that this is a linker error.

undefined reference to `InitCuda’
collect2: error: ld returned 1 exit status
make: *** [SIFT_GPU] Error 1

I have included the headers and still this error comes. Could you please suggest?

Thanks.

which file in that project provides a definition for the function InitCuda ?

“cudaSift.h” is the header file where InitCuda () is defined and it is only one line

void InitCuda(int devNum = 0);

Thanks.

That is a declaration. Not a definition.

In C and C++, there is this terminology:

function call:

float a = square(22);

declaration:

float square(float);

definition:

float square(float v){
    return v*v;
  }

Amongst all the files in that project, you need to find the definition for InitCuda()

Once you find the file that provides that definition (it is provided for in one of the files - I checked) then add that file to your project, just like you added cudaImage.cu

Thanks txbob. I realized this after replying to you and observed that there is a function defintion in file “cudaSiftH.cu”. Now, i added all the *.cu and *.h files within folder in above weblink except the file “mainSift.cpp”. Instead of this file i am trying to test the lines of code i have shared above. Now i get lot of other errors as below:

/usr/local/cuda-7.5/bin/nvcc --cudart static -L/usr/local/lib --relocatable-device-code=false -gencode arch=compute_30,code=compute_30 -gencode arch=compute_35,code=compute_35 -gencode arch=compute_50,code=compute_50 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -link -o “SIFT_GPU” ./cudaImage.o ./cudaSiftD.o ./cudaSiftH.o ./geomFuncs.o ./matching.o ./sift_gpu_v1.o -lopencv_cudabgsegm -lculibos -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_shape -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_video -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_cudaarithm -lopencv_core -lopencv_cudev -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_calib3d -lopencv_features2d -lopencv_objdetect -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_cudawarping
./cudaSiftH.o: In function ScaleDown(float*, float*, int, int, int, int)': cudaSiftD.cu:26: multiple definition of ScaleDown(float*, float*, int, int, int, int)’
./cudaSiftD.o:cudaSiftD.cu:26: first defined here
./cudaSiftH.o: In function ScaleUp(float*, float*, int, int, int, int)': cudaSiftD.cu:102: multiple definition of ScaleUp(float*, float*, int, int, int, int)’
./cudaSiftD.o:cudaSiftD.cu:102: first defined here
./cudaSiftH.o: In function ComputeOrientations(unsigned long long, SiftPoint*, int)': cudaSiftD.cu:360: multiple definition of ComputeOrientations(unsigned long long, SiftPoint*, int)’
./cudaSiftD.o:cudaSiftD.cu:360: first defined here
./cudaSiftH.o: In function ExtractSiftDescriptors(unsigned long long, SiftPoint*, int, float)': cudaSiftD.cu:128: multiple definition of ExtractSiftDescriptors(unsigned long long, SiftPoint*, int, float)’
./cudaSiftD.o:cudaSiftD.cu:128: first defined here
./cudaSiftH.o: In function RescalePositions(SiftPoint*, int, float)': cudaSiftD.cu:349: multiple definition of RescalePositions(SiftPoint*, int, float)’
./cudaSiftD.o:cudaSiftD.cu:349: first defined here
./cudaSiftH.o: In function LowPass(float*, float*, int, int, int)': cudaSiftD.cu:632: multiple definition of LowPass(float*, float*, int, int, int)’
./cudaSiftD.o:cudaSiftD.cu:632: first defined here
./cudaSiftH.o: In function LaplaceMultiMem(float*, float*, int, int, int)': cudaSiftD.cu:603: multiple definition of LaplaceMultiMem(float*, float*, int, int, int)’
./cudaSiftD.o:cudaSiftD.cu:603: first defined here
./cudaSiftH.o: In function FindPointsMulti(float*, SiftPoint*, int, int, int, int, float, float)': cudaSiftD.cu:444: multiple definition of FindPointsMulti(float*, SiftPoint*, int, int, int, int, float, float)’
./cudaSiftD.o:cudaSiftD.cu:444: first defined here
./cudaSiftH.o: In function __device_stub__Z9ScaleDownPfS_iiii(float*, float*, int, int, int, int)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:19: multiple definition of __device_stub__Z9ScaleDownPfS_iiii(float*, float*, int, int, int, int)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:19: first defined here
./cudaSiftH.o: In function __device_stub__Z7ScaleUpPfS_iiii(float*, float*, int, int, int, int)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z7ScaleUpPfS_iiii(float*, float*, int, int, int, int)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function __device_stub__Z22ExtractSiftDescriptorsyP9SiftPointif(unsigned long long, SiftPoint*, int, float)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z22ExtractSiftDescriptorsyP9SiftPointif(unsigned long long, SiftPoint*, int, float)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function __device_stub__Z25ExtractSiftDescriptorsOldyP9SiftPointif(unsigned long long, SiftPoint*, int, float)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z25ExtractSiftDescriptorsOldyP9SiftPointif(unsigned long long, SiftPoint*, int, float)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function ExtractSiftDescriptorsOld(unsigned long long, SiftPoint*, int, float)': cudaSiftD.cu:232: multiple definition of ExtractSiftDescriptorsOld(unsigned long long, SiftPoint*, int, float)’
./cudaSiftD.o:cudaSiftD.cu:232: first defined here
./cudaSiftH.o: In function __device_stub__Z16RescalePositionsP9SiftPointif(SiftPoint*, int, float)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z16RescalePositionsP9SiftPointif(SiftPoint*, int, float)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function __device_stub__Z19ComputeOrientationsyP9SiftPointi(unsigned long long, SiftPoint*, int)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z19ComputeOrientationsyP9SiftPointi(unsigned long long, SiftPoint*, int)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function __device_stub__Z15FindPointsMultiPfP9SiftPointiiiiff(float*, SiftPoint*, int, int, int, int, float, float)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z15FindPointsMultiPfP9SiftPointiiiiff(float*, SiftPoint*, int, int, int, int, float, float)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function __device_stub__Z15LaplaceMultiTexyPfiii(unsigned long long, float*, int, int, int)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z15LaplaceMultiTexyPfiii(unsigned long long, float*, int, int, int)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function LaplaceMultiTex(unsigned long long, float*, int, int, int)': cudaSiftD.cu:571: multiple definition of LaplaceMultiTex(unsigned long long, float*, int, int, int)’
./cudaSiftD.o:cudaSiftD.cu:571: first defined here
./cudaSiftH.o: In function __device_stub__Z15LaplaceMultiMemPfS_iii(float*, float*, int, int, int)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z15LaplaceMultiMemPfS_iii(float*, float*, int, int, int)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./cudaSiftH.o: In function __device_stub__Z7LowPassPfS_iii(float*, float*, int, int, int)': /tmp/tmpxft_00001179_00000000-10_cudaSiftH.compute_30.cudafe1.stub.c:1: multiple definition of __device_stub__Z7LowPassPfS_iii(float*, float*, int, int, int)’
./cudaSiftD.o:/tmp/tmpxft_00001108_00000000-10_cudaSiftD.compute_30.cudafe1.stub.c:1: first defined here
./sift_gpu_v1.o: In function main': sift_gpu_v1.cpp:44: undefined reference to InitCuda’
collect2: error: ld returned 1 exit status
make: *** [SIFT_GPU] Error 1

Could you please the mistake ?

Thanks
SIFT_GPU.zip (8.07 MB)

I have also shared the folder with all files i’m testing now so that you can try to replicate the testing if possible.

Thanks.

Hi all,

In Nsight Eclipse, There is an option to include the header files in the Project properties section.
I attempted to include path to all the five header files with .h extension.

In the linker section, i added the path to the folder where above files were located.

Now when i build the project many errors above have vanished. But the error below appears

Building file: …/geomFuncs.cpp
Invoking: NVCC Compiler
/usr/local/cuda-7.5/bin/nvcc -I/usr/local/include/opencv -I/usr/local/include/opencv2 -include /usr/local/include/opencv2/opencv.hpp -include /home/SIFT_GPU/cudaImage.h -include /home/SIFT_GPU/cudaSift.h -include /home/SIFT_GPU/cudaSiftD.h -include /home/SIFT_GPU/cudaSiftH.h -include /home/cudautils.h -include /usr/local/include/opencv2/highgui/highgui.hpp -G -g -O0 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -odir “.” -M -o “geomFuncs.d” “…/geomFuncs.cpp”
/usr/local/cuda-7.5/bin/nvcc -I/usr/local/include/opencv -I/usr/local/include/opencv2 -include /usr/local/include/opencv2/opencv.hpp -include /home/SIFT_GPU/cudaImage.h -include /home/SIFT_GPU/cudaSift.h -include /home/SIFT_GPU/cudaSiftD.h -include /home/SIFT_GPU/cudaSiftH.h -include /home/SIFT_GPU/cudautils.h -include /usr/local/include/opencv2/highgui/highgui.hpp -G -g -O0 --compile -x c++ -o “geomFuncs.o” “…/geomFuncs.cpp”

In file included from /home/SIFT_GPU/cudaSiftH.h:4:0,
from :0:
/home/SIFT_GPU/cudautils.h:15:24: error: variable or field ‘__safeCall’ declared void
inline void __safeCall(cudaError err, const char *file, const int line)
^
/home/SIFT_GPU/cudautils.h:15:24: error: ‘cudaError’ was not declared in this scope
/home/SIFT_GPU/cudautils.h:15:39: error: expected primary-expression before ‘const’
inline void __safeCall(cudaError err, const char *file, const int line)
^
/home/SIFT_GPU/cudautils.h:15:57: error: expected primary-expression before ‘const’
inline void __safeCall(cudaError err, const char *file, const int line)
^
make: *** [geomFuncs.o] Error 1

Could anyone please suggest the reason why these three errors are popping up?

Thanks.

Hi, I also download this file,but after building it with CMke,I open it with Visual studio 2010.A compile error has occured.And the message is nvcc factal :redifinition of arguement ‘gpu-architure’.My GPU is GT730, wolud you kind to give me some help on this problem.

This is a problem in one of the nvcc compile commands. It would be useful to see more of the context around the fatal error message, although since you are using Cmake, this would usually indicate a problem in your Cmakelists.txt file.

My configuration environment is :VS2010 CUDA8.0 GT730

This is Cmakelists.txt:

cmake_minimum_required(VERSION 2.6)
project(cudaSift)
set(cudaSift_VERSION_MAJOR 2)
set(cudaSift_VERSION_MINOR 0)
set(cudaSift_VERSION_PATCH 0)
set(CPACK_PACKAGE_VERSION_MAJOR “{cudaSift_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "{cudaSift_VERSION_MINOR}”)
set(CPACK_PACKAGE_VERSION_PATCH "{cudaSift_VERSION_PATCH}") set(CPACK_GENERATOR "ZIP") include(CPack) find_package(OpenCV REQUIRED) find_package(CUDA) if (NOT CUDA_FOUND) message(STATUS "CUDA not found. Project will not be built.") endif(NOT CUDA_FOUND) if (WIN32) set(EXTRA_CXX_FLAGS "/DVERBOSE /D_CRT_SECURE_NO_WARNINGS ") list(APPEND CUDA_NVCC_FLAGS "-arch=sm_35;--compiler-options;-O2;-DVERBOSE") endif() if (UNIX) if (APPLE) set(EXTRA_CXX_FLAGS "-DVERBOSE -msse2") list(APPEND CUDA_NVCC_FLAGS "-arch=sm_35;--compiler-options;-O2;-DVERBOSE") else() set(CMAKE_CXX_FLAGS "{CMAKE_CXX_FLAGS} -O2 -msse2 ")
list(APPEND CUDA_NVCC_FLAGS “-lineinfo;–compiler-options;-O2;-DVERBOSE”)
endif()
endif()
set(cuda_sources

dynamic.cu

cudaImage.cu
cudaImage.h
cudaSiftH.cu
cudaSiftH.h
matching.cu
cudaSiftD.h
cudaSift.h
cudautils.h
)
set(sources
geomFuncs.cpp
mainSift.cpp
)
include_directories(
{CMAKE_CURRENT_SOURCE_DIR} ) SET(CUDA_SEPARABLE_COMPILATION ON) cuda_add_executable(cudasift {cuda_sources} {sources} OPTIONS -arch=sm_35) set_target_properties(cudasift PROPERTIES COMPILE_FLAGS "{EXTRA_CXX_FLAGS}"
)
target_link_libraries(cudasift
/usr/local/cuda/lib64/libcudadevrt.a {OpenCV_LIBS} ) install(FILES {cuda_sources}
${sources}
cudaSiftD.cu
CMakeLists.txt
Copyright.txt
DESTINATION .
)
install(FILES data/left.pgm data/righ.pgm
DESTINATION data
)

also need:

This means enable verbose output in CMake, and post the exact compile command that generates this error message: