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
df561381
Commit
df561381
authored
Mar 06, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/gkernel/cuda_lab
parents
87170c69
62affe03
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
30 deletions
+32
-30
main.cu
miklos/ex11/main.cu
+32
-30
No files found.
miklos/ex11/main.cu
View file @
df561381
...
...
@@ -53,19 +53,20 @@ __global__ void gradient(float *image, float *vx, float *vy, int w, int h, int n
{
int x = threadIdx.x + blockDim.x * blockIdx.x;
int y = threadIdx.y + blockDim.y * blockIdx.y;
int c = threadIdx.z + blockDim.z * blockIdx.z;
if (x < w && y < h && c < nc) {
int i = x + w*y + w*h*c;
if (x == w-1)
vx[i] = 0;
else
vx[i] = image[i + 1] - image[i];
if (y == h-1)
vy[i] = 0;
else
vy[i] = image[i + w] - image[i];
if (x < w && y < h) {
for (int c = 0; c < nc; c++) {
int i = x + w*y + w*h*c;
if (x == w-1)
vx[i] = 0;
else
vx[i] = image[i + 1] - image[i];
if (y == h-1)
vy[i] = 0;
else
vy[i] = image[i + w] - image[i];
}
}
}
...
...
@@ -98,12 +99,13 @@ __global__ void divergence(float *u1, float *u2, float *div, int w, int h, int n
{
int x = threadIdx.x + blockDim.x * blockIdx.x;
int y = threadIdx.y + blockDim.y * blockIdx.y;
int c = threadIdx.z + blockDim.z * blockIdx.z;
if (x < w && y < h && c < nc) {
int i = x + w*y + w*h*c;
float dx_u1 = u1[i] - ((x > 0) ? u1[i - 1] : 0);
float dy_u2 = u2[i] - ((y > 0) ? u2[i - w] : 0);
div[i] = dx_u1 + dy_u2;
if (x < w && y < h) {
for (int c = 0; c < nc; c++) {
int i = x + w*y + w*h*c;
float dx_u1 = u1[i] - ((x > 0) ? u1[i - 1] : 0);
float dy_u2 = u2[i] - ((y > 0) ? u2[i - w] : 0);
div[i] = dx_u1 + dy_u2;
}
}
}
...
...
@@ -111,10 +113,11 @@ __global__ void update(float *image, float *dir, int w, int h, int nc, float tau
{
int x = threadIdx.x + blockDim.x * blockIdx.x;
int y = threadIdx.y + blockDim.y * blockIdx.y;
int c = threadIdx.z + blockDim.z * blockIdx.z;
if (x < w && y < h && c < nc) {
int i = x + w*y + w*h*c;
image[i] += tau * dir[i];
if (x < w && y < h) {
for (int c = 0; c < nc; c++) {
int i = x + w*y + w*h*c;
image[i] += tau * dir[i];
}
}
}
...
...
@@ -256,9 +259,8 @@ int main(int argc, char **argv)
// So we will convert as necessary, using interleaved "cv::Mat" for loading/saving/displaying, and layered "float*" for CUDA computations
convert_mat_to_layered (imgIn, mIn);
dim3 dim(w, h, nc);
dim3 block2d(32, 16);
dim3 block3d(16, 8, 3);
dim3 block(32, 16);
dim3 grid = make_grid(dim3(w, h, 1), block);
Timer timer; timer.start();
float *d_image, *d_vx, *d_vy, *d_div;
...
...
@@ -269,10 +271,10 @@ int main(int argc, char **argv)
cudaMemcpy(d_image, imgIn, imageBytes, cudaMemcpyHostToDevice);
for (int n = 0; n < N; n++) {
gradient<<<
make_grid(dim, block3d), block3d
>>>(d_image, d_vx, d_vy, w, h, nc);
compute_P<<<
make_grid(dim, block2d), block2d
>>>(d_vx, d_vy, w, h, nc, epsilon);
divergence<<<
make_grid(dim, block3d), block3d
>>>(d_vx, d_vy, d_div, w, h, nc);
update<<<
make_grid(dim, block3d), block3d
>>>(d_image, d_div, w, h, nc, tau);
gradient<<<
grid, block
>>>(d_image, d_vx, d_vy, w, h, nc);
compute_P<<<
grid, block
>>>(d_vx, d_vy, w, h, nc, epsilon);
divergence<<<
grid, block
>>>(d_vx, d_vy, d_div, w, h, nc);
update<<<
grid, block
>>>(d_image, d_div, w, h, nc, tau);
}
cudaMemcpy(imgOut, d_image, imageBytes, cudaMemcpyDeviceToHost);
...
...
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