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
5 changed files
with
134 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifdef __CLION_IDE__ | ||
|
||
#include <libgpu/opencl/cl/clion_defines.cl> | ||
|
||
#endif | ||
|
||
#define TS 16 | ||
__kernel void matrix_transpose(__global float *a, __global float *at, unsigned int M, unsigned int K) { | ||
const unsigned int gx = get_group_id(0) * TS; | ||
const unsigned int gy = get_group_id(1) * TS; | ||
const unsigned int lx = get_local_id(0); | ||
const unsigned int ly = get_local_id(1); | ||
|
||
__local float buf[TS][TS + 1]; | ||
|
||
if (gx + lx < M && gy + ly < K) { | ||
buf[ly][lx] = a[(gy + ly) * M + (gx + lx)]; | ||
} | ||
|
||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
if (gx + ly < M && gy + lx < K) { | ||
at[(gx + ly) * K + (gy + lx)] = buf[lx][ly]; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifdef __CLION_IDE__ | ||
#include <libgpu/opencl/cl/clion_defines.cl> | ||
#endif | ||
|
||
__kernel void prefix_sum(__global unsigned int* as, __global unsigned int* res, unsigned int k) { | ||
unsigned gid = get_global_id(0); | ||
if (gid >= k) { | ||
res[gid] = as[gid] + as[gid - k]; | ||
} else | ||
res[gid] = as[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,47 @@ | ||
__kernel void radix(__global unsigned int *as) { | ||
// TODO | ||
#ifdef __CLION_IDE__ | ||
#include <libgpu/opencl/cl/clion_defines.cl> | ||
#include <stdio.h> | ||
#endif | ||
|
||
#define BITS_PER_ITER 4 | ||
#define BITS_VALUE (1 << BITS_PER_ITER) | ||
|
||
__kernel void radix_count(__global unsigned int *as, __global unsigned int* counting, unsigned int shift) { | ||
__local unsigned int count_local[BITS_VALUE]; | ||
int group_id = get_group_id(0); | ||
int global_id = get_global_id(0); | ||
int local_id = get_local_id(0); | ||
|
||
if (local_id < BITS_VALUE) { | ||
count_local[local_id] = 0; | ||
} | ||
|
||
barrier(CLK_LOCAL_MEM_FENCE); | ||
atomic_inc(&count_local[(as[global_id] >> shift) & (BITS_VALUE - 1)]); | ||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
if (local_id < BITS_VALUE) { | ||
counting[group_id * BITS_VALUE + local_id] = count_local[local_id]; | ||
} | ||
} | ||
|
||
#define WORK_SIZE 128 | ||
__kernel void radix(__global unsigned int *as, __global unsigned int* bs, __global unsigned int* prefix_sum, __global unsigned int* cnt, unsigned int shift) { | ||
unsigned int global_id = get_global_id(0); | ||
unsigned int local_id = get_local_id(0); | ||
unsigned int group_id = get_group_id(0); | ||
unsigned int group_cnt = get_num_groups(0); | ||
|
||
__local unsigned int local_as[WORK_SIZE]; | ||
|
||
local_as[local_id] = (as[global_id] >> shift) & (BITS_VALUE - 1); | ||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
unsigned int offset = 0; | ||
unsigned int cur_value = local_as[local_id]; | ||
for (int i = 0; i < local_id; ++i) { | ||
offset += cur_value == local_as[i] ? 1 : 0; | ||
} | ||
int prev_values = prefix_sum[group_cnt * cur_value + group_id] - cnt[group_id * BITS_VALUE + cur_value]; | ||
bs[prev_values + offset] = as[global_id]; | ||
} |
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