Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cuda_lab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
cuda_lab
Commits
1ae438e8
Commit
1ae438e8
authored
Mar 25, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/gkernel/cuda_lab
parents
55399ce1
81d3d305
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
585 additions
and
0 deletions
+585
-0
Makefile
miklos/project_primal_dual/Makefile
+3
-0
aux.cu
miklos/project_primal_dual/aux.cu
+146
-0
aux.h
miklos/project_primal_dual/aux.h
+109
-0
main.cu
miklos/project_primal_dual/main.cu
+327
-0
No files found.
miklos/project_primal_dual/Makefile
0 → 100644
View file @
1ae438e8
main
:
main.cu aux.cu aux.h Makefile
nvcc
-o
main main.cu aux.cu
--ptxas-options
=
-v
--use_fast_math
--compiler-options
-Wall
-lopencv_highgui
-lopencv_core
miklos/project_primal_dual/aux.cu
0 → 100644
View file @
1ae438e8
// ###
// ###
// ### Practical Course: GPU Programming in Computer Vision
// ###
// ###
// ### Technical University Munich, Computer Vision Group
// ### Winter Semester 2013/2014, March 3 - April 4
// ###
// ###
// ### Evgeny Strekalovskiy, Maria Klodt, Jan Stuehmer, Mohamed Souiai
// ###
// ###
// ###
// ### THIS FILE IS SUPPOSED TO REMAIN UNCHANGED
// ###
// ###
#include "aux.h"
#include <cstdlib>
#include <iostream>
using std::stringstream;
using std::cerr;
using std::cout;
using std::endl;
using std::string;
// parameter processing: template specialization for T=bool
template<>
bool getParam<bool>(std::string param, bool &var, int argc, char **argv)
{
const char *c_param = param.c_str();
for(int i=argc-1; i>=1; i--)
{
if (argv[i][0]!='-') continue;
if (strcmp(argv[i]+1, c_param)==0)
{
if (!(i+1<argc) || argv[i+1][0]=='-') { var = true; return true; }
std::stringstream ss;
ss << argv[i+1];
ss >> var;
return (bool)ss;
}
}
return false;
}
// opencv helpers
void convert_layered_to_interleaved(float *aOut, const float *aIn, int w, int h, int nc)
{
if (nc==1) { memcpy(aOut, aIn, w*h*sizeof(float)); return; }
size_t nOmega = (size_t)w*h;
for (int y=0; y<h; y++)
{
for (int x=0; x<w; x++)
{
for (int c=0; c<nc; c++)
{
aOut[(nc-1-c) + nc*(x + (size_t)w*y)] = aIn[x + (size_t)w*y + nOmega*c];
}
}
}
}
void convert_layered_to_mat(cv::Mat &mOut, const float *aIn)
{
convert_layered_to_interleaved((float*)mOut.data, aIn, mOut.cols, mOut.rows, mOut.channels());
}
void convert_interleaved_to_layered(float *aOut, const float *aIn, int w, int h, int nc)
{
if (nc==1) { memcpy(aOut, aIn, w*h*sizeof(float)); return; }
size_t nOmega = (size_t)w*h;
for (int y=0; y<h; y++)
{
for (int x=0; x<w; x++)
{
for (int c=0; c<nc; c++)
{
aOut[x + (size_t)w*y + nOmega*c] = aIn[(nc-1-c) + nc*(x + (size_t)w*y)];
}
}
}
}
void convert_mat_to_layered(float *aOut, const cv::Mat &mIn)
{
convert_interleaved_to_layered(aOut, (float*)mIn.data, mIn.cols, mIn.rows, mIn.channels());
}
void showImage(string title, const cv::Mat &mat, int x, int y)
{
const char *wTitle = title.c_str();
cv::namedWindow(wTitle, CV_WINDOW_AUTOSIZE);
cvMoveWindow(wTitle, x, y);
cv::imshow(wTitle, mat);
}
// adding Gaussian noise
float noise(float sigma)
{
float x1 = (float)rand()/RAND_MAX;
float x2 = (float)rand()/RAND_MAX;
return sigma * sqrtf(-2*log(std::max(x1,0.000001f)))*cosf(2*M_PI*x2);
}
void addNoise(cv::Mat &m, float sigma)
{
float *data = (float*)m.data;
int w = m.cols;
int h = m.rows;
int nc = m.channels();
size_t n = (size_t)w*h*nc;
for(size_t i=0; i<n; i++)
{
data[i] += noise(sigma);
}
}
// cuda error checking
string prev_file = "";
int prev_line = 0;
void cuda_check(string file, int line)
{
cudaError_t e = cudaGetLastError();
if (e != cudaSuccess)
{
cout << endl << file << ", line " << line << ": " << cudaGetErrorString(e) << " (" << e << ")" << endl;
if (prev_line>0) cout << "Previous CUDA call:" << endl << prev_file << ", line " << prev_line << endl;
exit(1);
}
prev_file = file;
prev_line = line;
}
miklos/project_primal_dual/aux.h
0 → 100644
View file @
1ae438e8
// ###
// ###
// ### Practical Course: GPU Programming in Computer Vision
// ###
// ###
// ### Technical University Munich, Computer Vision Group
// ### Winter Semester 2013/2014, March 3 - April 4
// ###
// ###
// ### Evgeny Strekalovskiy, Maria Klodt, Jan Stuehmer, Mohamed Souiai
// ###
// ###
// ###
// ### THIS FILE IS SUPPOSED TO REMAIN UNCHANGED
// ###
// ###
#ifndef AUX_H
#define AUX_H
#include <cuda_runtime.h>
#include <ctime>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include <sstream>
// parameter processing
template
<
typename
T
>
bool
getParam
(
std
::
string
param
,
T
&
var
,
int
argc
,
char
**
argv
)
{
const
char
*
c_param
=
param
.
c_str
();
for
(
int
i
=
argc
-
1
;
i
>=
1
;
i
--
)
{
if
(
argv
[
i
][
0
]
!=
'-'
)
continue
;
if
(
strcmp
(
argv
[
i
]
+
1
,
c_param
)
==
0
)
{
if
(
!
(
i
+
1
<
argc
))
continue
;
std
::
stringstream
ss
;
ss
<<
argv
[
i
+
1
];
ss
>>
var
;
return
(
bool
)
ss
;
}
}
return
false
;
}
// opencv helpers
void
convert_mat_to_layered
(
float
*
aOut
,
const
cv
::
Mat
&
mIn
);
void
convert_layered_to_mat
(
cv
::
Mat
&
mOut
,
const
float
*
aIn
);
void
showImage
(
std
::
string
title
,
const
cv
::
Mat
&
mat
,
int
x
,
int
y
);
// adding Gaussian noise
void
addNoise
(
cv
::
Mat
&
m
,
float
sigma
);
// measuring time
class
Timer
{
public
:
Timer
()
:
tStart
(
0
),
running
(
false
),
sec
(
0
.
f
)
{
}
void
start
()
{
tStart
=
clock
();
running
=
true
;
}
void
end
()
{
if
(
!
running
)
{
sec
=
0
;
return
;
}
cudaDeviceSynchronize
();
clock_t
tEnd
=
clock
();
sec
=
(
float
)(
tEnd
-
tStart
)
/
CLOCKS_PER_SEC
;
running
=
false
;
}
float
get
()
{
if
(
running
)
end
();
return
sec
;
}
private
:
clock_t
tStart
;
bool
running
;
float
sec
;
};
// cuda error checking
#define CUDA_CHECK cuda_check(__FILE__,__LINE__)
void
cuda_check
(
std
::
string
file
,
int
line
);
#endif // AUX_H
miklos/project_primal_dual/main.cu
0 → 100644
View file @
1ae438e8
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment