-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d65792
commit b760757
Showing
32 changed files
with
11,613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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_20;--compiler-options;-O2;-DVERBOSE") | ||
endif() | ||
if (UNIX) | ||
set(EXTRA_CXX_FLAGS "-DVERBOSE -msse2 -std=c++0x ") | ||
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_20;--compiler-bindir=/usr/bin/gcc-4.4;--compiler-options;-O2;-DVERBOSE") | ||
endif() | ||
|
||
set(cuda_sources | ||
cudaImage.cu | ||
cudaImage.h | ||
cudaSiftH.cu | ||
cudaSiftH.h | ||
matching.cu | ||
singular.cu | ||
cudaSiftD.h | ||
cudaSift.h | ||
cudautils.h | ||
) | ||
|
||
set(sources | ||
geomFuncs.cpp | ||
mainSift.cpp | ||
) | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
cuda_add_executable(cudasift ${cuda_sources} ${sources}) | ||
|
||
set_target_properties(cudasift PROPERTIES | ||
COMPILE_FLAGS "${EXTRA_CXX_FLAGS}" | ||
) | ||
|
||
target_link_libraries(cudasift | ||
${OpenCV_LIBS} | ||
) | ||
|
||
install(FILES | ||
${cuda_sources} | ||
${sources} | ||
cudaSiftD.cu | ||
CMakeLists.txt | ||
Copyright.txt | ||
DESTINATION . | ||
) | ||
install(FILES data/left.pgm data/righ.pgm | ||
DESTINATION data | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mainSift.cpp -> cudaSift.h -> cudaImage.h | ||
cudaImage.h | ||
|
||
cudaImage.cu -> cudaImage.h | ||
|
||
cudaSiftH.cu -> cudaImage.h | ||
cudaSift.h -> cudaImage.h | ||
cudaSiftD.h | ||
cudaSiftH.h -> cudaImage.h | ||
cudaSiftD.cu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
//********************************************************// | ||
// CUDA SIFT extractor by Marten Bjorkman aka Celebrandil // | ||
//********************************************************// | ||
|
||
#include <cstdio> | ||
|
||
#include "cudautils.h" | ||
#include "cudaImage.h" | ||
|
||
int iDivUp(int a, int b) { return (a%b != 0) ? (a/b + 1) : (a/b); } | ||
int iDivDown(int a, int b) { return a/b; } | ||
int iAlignUp(int a, int b) { return (a%b != 0) ? (a - a%b + b) : a; } | ||
int iAlignDown(int a, int b) { return a - a%b; } | ||
|
||
void CudaImage::Allocate(int w, int h, int p, bool host, float *devmem, float *hostmem) | ||
{ | ||
width = w; | ||
height = h; | ||
pitch = p; | ||
d_data = devmem; | ||
h_data = hostmem; | ||
t_data = NULL; | ||
if (devmem==NULL) { | ||
safeCall(cudaMallocPitch((void **)&d_data, (size_t*)&pitch, (size_t)(sizeof(float)*width), (size_t)height)); | ||
pitch /= sizeof(float); | ||
if (d_data==NULL) | ||
printf("Failed to allocate device data\n"); | ||
d_internalAlloc = true; | ||
} | ||
if (host && hostmem==NULL) { | ||
h_data = (float *)malloc(sizeof(float)*pitch*height); | ||
h_internalAlloc = true; | ||
} | ||
} | ||
|
||
CudaImage::CudaImage() : | ||
d_data(NULL), h_data(NULL), t_data(NULL), d_internalAlloc(false), h_internalAlloc(false) | ||
{ | ||
|
||
} | ||
|
||
CudaImage::~CudaImage() | ||
{ | ||
if (d_internalAlloc && d_data!=NULL) | ||
safeCall(cudaFree(d_data)); | ||
d_data = NULL; | ||
if (h_internalAlloc && h_data!=NULL) | ||
free(h_data); | ||
h_data = NULL; | ||
if (t_data!=NULL) | ||
safeCall(cudaFreeArray((cudaArray *)t_data)); | ||
t_data = NULL; | ||
} | ||
|
||
double CudaImage::Download() | ||
{ | ||
TimerGPU timer(0); | ||
if (d_data!=NULL && h_data!=NULL) | ||
safeCall(cudaMemcpy(d_data, h_data, sizeof(float)*pitch*height, cudaMemcpyHostToDevice)); | ||
double gpuTime = timer.read(); | ||
#ifdef VERBOSE | ||
printf("Download time = %.2f ms\n", gpuTime); | ||
#endif | ||
return gpuTime; | ||
} | ||
|
||
double CudaImage::Readback() | ||
{ | ||
TimerGPU timer(0); | ||
int p = sizeof(float)*pitch; | ||
safeCall(cudaMemcpy2D(h_data, p, d_data, p, sizeof(float)*width, height, cudaMemcpyDeviceToHost)); | ||
double gpuTime = timer.read(); | ||
#ifdef VERBOSE | ||
printf("Readback time = %.2f ms\n", gpuTime); | ||
#endif | ||
return gpuTime; | ||
} | ||
|
||
double CudaImage::InitTexture() | ||
{ | ||
TimerGPU timer(0); | ||
cudaChannelFormatDesc t_desc = cudaCreateChannelDesc<float>(); | ||
safeCall(cudaMallocArray((cudaArray **)&t_data, &t_desc, pitch, height)); | ||
if (t_data==NULL) | ||
printf("Failed to allocated texture data\n"); | ||
double gpuTime = timer.read(); | ||
#ifdef VERBOSE | ||
printf("InitTexture time = %.2f ms\n", gpuTime); | ||
#endif | ||
return gpuTime; | ||
} | ||
|
||
double CudaImage::CopyToTexture(CudaImage &dst, bool host) | ||
{ | ||
if (dst.t_data==NULL) { | ||
printf("Error CopyToTexture: No texture data\n"); | ||
return 0.0; | ||
} | ||
if ((!host || h_data==NULL) && (host || d_data==NULL)) { | ||
printf("Error CopyToTexture: No source data\n"); | ||
return 0.0; | ||
} | ||
TimerGPU timer(0); | ||
if (host) | ||
safeCall(cudaMemcpyToArray((cudaArray *)dst.t_data, 0, 0, h_data, sizeof(float)*pitch*dst.height, cudaMemcpyHostToDevice)); | ||
else | ||
safeCall(cudaMemcpyToArray((cudaArray *)dst.t_data, 0, 0, d_data, sizeof(float)*pitch*dst.height, cudaMemcpyDeviceToDevice)); | ||
safeCall(cudaThreadSynchronize()); | ||
double gpuTime = timer.read(); | ||
#ifdef VERBOSE | ||
printf("CopyToTexture time = %.2f ms\n", gpuTime); | ||
#endif | ||
return gpuTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//********************************************************// | ||
// CUDA SIFT extractor by Marten Bjorkman aka Celebrandil // | ||
//********************************************************// | ||
|
||
#ifndef CUDAIMAGE_H | ||
#define CUDAIMAGE_H | ||
|
||
class CudaImage { | ||
public: | ||
int width, height; | ||
int pitch; | ||
float *h_data; | ||
float *d_data; | ||
float *t_data; | ||
bool d_internalAlloc; | ||
bool h_internalAlloc; | ||
public: | ||
CudaImage(); | ||
~CudaImage(); | ||
void Allocate(int width, int height, int pitch, bool withHost, float *devMem = NULL, float *hostMem = NULL); | ||
double Download(); | ||
double Readback(); | ||
double InitTexture(); | ||
double CopyToTexture(CudaImage &dst, bool host); | ||
}; | ||
|
||
int iDivUp(int a, int b); | ||
int iDivDown(int a, int b); | ||
int iAlignUp(int a, int b); | ||
int iAlignDown(int a, int b); | ||
void StartTimer(unsigned int *hTimer); | ||
double StopTimer(unsigned int hTimer); | ||
|
||
#endif // CUDAIMAGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef CUDASIFT_H | ||
#define CUDASIFT_H | ||
|
||
#include "cudaImage.h" | ||
|
||
typedef struct { | ||
float xpos; | ||
float ypos; | ||
float scale; | ||
float sharpness; | ||
float edgeness; | ||
float orientation; | ||
float score; | ||
float ambiguity; | ||
int match; | ||
float match_xpos; | ||
float match_ypos; | ||
float match_error; | ||
float empty[4]; | ||
float data[128]; | ||
} SiftPoint; | ||
|
||
typedef struct { | ||
int numPts; // Number of available Sift points | ||
int maxPts; // Number of allocated Sift points | ||
SiftPoint *h_data; // Host (CPU) data | ||
SiftPoint *d_data; // Device (GPU) data | ||
} SiftData; | ||
|
||
void InitCuda(); | ||
void ExtractSift(SiftData &siftData, CudaImage &img, int numOctaves, double initBlur, float thresh, float lowestScale = 0.0f, float subsampling = 1.0f); | ||
void InitSiftData(SiftData &data, int num = 1024, bool host = false, bool dev = true); | ||
void FreeSiftData(SiftData &data); | ||
void PrintSiftData(SiftData &data); | ||
double MatchSiftData(SiftData &data1, SiftData &data2); | ||
double FindHomography(SiftData &data, float *homography, int *numMatches, int numLoops = 1000, float minScore = 0.85f, float maxAmbiguity = 0.95f, float thresh = 5.0f); | ||
|
||
#endif |
Oops, something went wrong.