Commit 426a5e2e authored by Gaurav Kukreja's avatar Gaurav Kukreja

Merge branch 'master' of https://github.com/gkernel/cuda_lab

parents 0030c87d 3844b5e2
......@@ -68,7 +68,7 @@ __global__ void compute_P(float *image, float *Px, float *Py, int w, int h, int
float G2 = 0;
for (int c = 0; c < nc; c++) {
int i = x + w*y + w*h*c;
int i = x + (size_t)w*y + (size_t)w*h*c;
float ux = ((x < w-1) ? (image[i + 1] - image[i]) : 0);
float uy = ((y < h-1) ? (image[i + w] - image[i]) : 0);
sh_u[b + B*c + B*nc*0] = ux;
......@@ -78,7 +78,7 @@ __global__ void compute_P(float *image, float *Px, float *Py, int w, int h, int
float g = huber(sqrtf(G2), epsilon);
for (int c = 0; c < nc; c++) {
int i = x + w*y + w*h*c;
int i = x + (size_t)w*y + (size_t)w*h*c;
Px[i] = g * sh_u[b + B*c + B*nc*0];
Py[i] = g * sh_u[b + B*c + B*nc*1];
}
......@@ -91,9 +91,9 @@ __global__ void divergence_and_update(float *image, float *Px, float *Py, int w,
int y = threadIdx.y + blockDim.y * blockIdx.y;
if (x < w && y < h) {
for (int c = 0; c < nc; c++) {
int i = x + w*y + w*h*c;
float dx_u1 = Px[i] - ((x > 0) ? Px[i - 1] : 0);
float dy_u2 = Py[i] - ((y > 0) ? Py[i - w] : 0);
int i = x + (size_t)w*y + (size_t)w*h*c;
float dx_u1 = ((x+1 < w) ? Px[i] : 0) - ((x > 0) ? Px[i - 1] : 0);
float dy_u2 = ((y+1 < h) ? Py[i] : 0) - ((y > 0) ? Py[i - w] : 0);
image[i] += tau * (dx_u1 + dy_u2);
}
}
......
......@@ -34,6 +34,14 @@ using namespace std;
#define USING_GPU
int min_pixels( int a, int b) {
if ( a < b ) {
return a;
} else {
return b;
}
}
__host__ __device__ float absolute_value ( float2 z ) {
return sqrtf((z.x * z.x) + (z.y * z.y));
}
......@@ -51,11 +59,18 @@ __global__ void callKernel(float* imgOut, int width, int height, float2 center,
int iy = blockIdx.y * blockDim.y + threadIdx.y; // WIDTH
int ix = blockIdx.x * blockDim.x + threadIdx.x; // HEIGHT
int idx = iy * width + ix;
if(ix >= width || iy >= height) return;
int size;
if ( width < height ) {
size = width;
} else {
size = height;
}
float2 c, z;
c.x = ((float)ix / width) * (2.0f * radius) + center.x - radius;
c.y = ((float)iy / height) * (2.0f * radius) + center.y - radius;
c.x = ((float)(ix - ((width - size)/2.0f)) / size) * (2.0f * radius) + center.x - radius;
c.y = ((float)(iy - ((height - size)/2.0f)) / size) * (2.0f * radius) + center.y - radius;
z = c;
int n = 0;
while( (absolute_value(z) < 2.0f) && (n < iterations))
......@@ -91,11 +106,13 @@ int main(int argc, char **argv)
getParam("height", height, argc, argv);
cout << "height = " << height<< endl;
float2 center = {-0.5f, 0.0f};
// float2 center = {-0.5f, 0.0f};
float2 center = {-0.773f, 0.1175f};
// getParam("center", center, argc, argv);
// cout << "center = " << center.x << ", " << center.y << endl;
float radius = 1.5f;
// float radius = 1.5f;
float radius = 0.005f;
getParam("radius", radius, argc, argv);
cout << "radius = " << radius << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment