Skip to content

Commit

Permalink
add task06 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenySvirin committed Dec 13, 2024
1 parent 024d0d3 commit fe22472
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
build
cmake-build*
.vs
CMakeLists.txt.user
25 changes: 23 additions & 2 deletions src/cl/bitonic.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
__kernel void bitonic()
__kernel void bitonic(__global int *const as,
uint const top_block_size,
uint const cur_block_size)
{

uint const gid = get_global_id(0);

uint const top_block_id = gid / (top_block_size / 2);
uint const cur_step = cur_block_size / 2;
uint const cur_block_id = gid / cur_step;

bool const is_order_increase = top_block_id % 2 == 0;
uint const idx1 = gid + (cur_block_id * cur_step);
uint const idx2 = idx1 + cur_step;

int const left_value = as[idx1];
int const right_value = as[idx2];
bool const is_lesser = left_value < right_value;

if ((is_order_increase && !is_lesser) || (!is_order_increase && is_lesser))
{
as[idx1] = right_value;
as[idx2] = left_value;
}
}

11 changes: 9 additions & 2 deletions src/main_bitonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

const int benchmarkingIters = 10;
const int benchmarkingItersCPU = 1;
// обязательно степень двойки, или докидывать нулей в массив тогда
const unsigned int n = 32 * 1024 * 1024;

template<typename T>
Expand Down Expand Up @@ -59,7 +60,7 @@ int main(int argc, char **argv) {
const std::vector<int> cpu_sorted = computeCPU(as);

// remove me
return 0;


gpu::gpu_mem_32i as_gpu;
as_gpu.resizeN(n);
Expand All @@ -74,6 +75,12 @@ int main(int argc, char **argv) {
t.restart();// Запускаем секундомер после прогрузки данных, чтобы замерять время работы кернела, а не трансфер данных

/*TODO*/
for (uint top_block_size = 1; top_block_size <= n; top_block_size *= 2) {
for (uint cur_block_size = top_block_size; 1 < cur_block_size; cur_block_size /= 2) {
bitonic.exec(gpu::WorkSize(64, n / 2), as_gpu, top_block_size, cur_block_size);
as_gpu.readN(as.data(), n);
}
}

t.nextLap();
}
Expand All @@ -90,4 +97,4 @@ int main(int argc, char **argv) {
}

return 0;
}
}

0 comments on commit fe22472

Please sign in to comment.