-
Notifications
You must be signed in to change notification settings - Fork 53
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
Showing
4 changed files
with
115 additions
and
9 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 |
---|---|---|
@@ -1,3 +1,27 @@ | ||
__kernel void bitonic(__global float *as) { | ||
// TODO | ||
enum ORDER { Lower = 0, Upper = 1}; | ||
|
||
__kernel void bitonic(__global float *as, | ||
unsigned int small_block_size, | ||
unsigned int step, | ||
unsigned int n) | ||
{ | ||
unsigned int gid = get_global_id(0); | ||
|
||
unsigned int shift = small_block_size / 2; | ||
unsigned int amount_prev_blocks = gid / shift; | ||
unsigned int ind = small_block_size * amount_prev_blocks + (gid % shift); | ||
unsigned int other_ind = ind + shift; | ||
|
||
unsigned int big_block_number = ind / step; | ||
enum ORDER order = (big_block_number & 1) ? Upper: Lower; | ||
if(other_ind < n) | ||
{ | ||
if((order == Lower && as[ind] > as[other_ind]) || | ||
(order == Upper && as[ind] < as[other_ind])) | ||
{ | ||
float tmp = as[ind]; \ | ||
as[ind] = as[other_ind]; \ | ||
as[other_ind] = tmp; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,16 @@ | ||
// TODO | ||
|
||
__kernel void reduce(__global unsigned int *as, unsigned int block_size, unsigned int n) | ||
{ | ||
unsigned int gid = get_global_id(0); | ||
unsigned int ind = gid * 2 * block_size - 1; | ||
if(ind + 2 * block_size >= n) | ||
return; | ||
as[ind + 2 * block_size] += as[ind + block_size]; | ||
} | ||
|
||
__kernel void sum(__global unsigned int *as, __global unsigned int *bs, unsigned int block_size) | ||
{ | ||
unsigned int gid = get_global_id(0); | ||
unsigned int block_ind = ((gid / block_size) * 2 + 1) * block_size; | ||
bs[block_ind + gid % block_size - 1] += as[block_ind - 1]; | ||
} |
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
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