forked from vatican1/GPGPUTasks2023
-
Notifications
You must be signed in to change notification settings - Fork 0
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
2 changed files
with
35 additions
and
4 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 +1,29 @@ | ||
#ifdef __CLION_IDE__ | ||
|
||
#include <libgpu/opencl/cl/clion_defines.cl> | ||
|
||
#endif | ||
|
||
__kernel void merge(__global float* a, __global float* b, unsigned int n, unsigned int k) { | ||
int gid = get_global_id(0); | ||
|
||
int batch_id = gid / k; | ||
int local_id = gid - batch_id * k; | ||
|
||
bool is_left = batch_id % 2 == 0; | ||
int other_batch_id = is_left ? batch_id + 1 : batch_id - 1; | ||
int other_batch_bound = other_batch_id * k; | ||
int left_bound = is_left ? batch_id * k : (batch_id - 1) * k; | ||
|
||
int start = other_batch_bound; | ||
int end = other_batch_bound + k; | ||
while (start < end) { | ||
int mid = (start + end) / 2; | ||
if (a[gid] < a[mid] || (is_left && a[gid] == a[mid])) | ||
end = mid; | ||
else | ||
start = mid + 1; | ||
} | ||
|
||
b[left_bound + local_id + end - other_batch_bound] = a[gid]; | ||
} |
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