spla
Loading...
Searching...
No Matches
auto_common_func.hpp
Go to the documentation of this file.
1
2// Copyright (c) 2021 - 2023 SparseLinearAlgebra
3// Autogenerated file, do not modify
5
6#pragma once
7
8static const char source_common_func[] = R"(
9
10
11// memory bank conflict-free address and local buffer size
12#ifdef LM_NUM_MEM_BANKS
13 #define LM_ADDR(address) (address + ((address) / LM_NUM_MEM_BANKS))
14 #define LM_SIZE(size) (size + (size) / LM_NUM_MEM_BANKS)
15#endif
16
17#define SWAP_KEYS(x, y) \
18 uint tmp1 = x; \
19 x = y; \
20 y = tmp1;
21
22#define SWAP_VALUES(x, y) \
23 TYPE tmp2 = x; \
24 x = y; \
25 y = tmp2;
26
27// nearest power of two number greater equals n
28uint ceil_to_pow2(uint n) {
29 uint r = 1;
30 while (r < n) r *= 2;
31 return r;
32}
33
34// find first element in a sorted array such x <= element
35uint lower_bound(const uint x,
36 uint first,
37 uint size,
38 __global const uint* array) {
39 while (size > 0) {
40 int step = size / 2;
41
42 if (array[first + step] < x) {
43 first = first + step + 1;
44 size -= step + 1;
45 } else {
46 size = step;
47 }
48 }
49 return first;
50}
51
52// find first element in a sorted array such x <= element
53uint lower_bound_local(const uint x,
54 uint first,
55 uint size,
56 __local const uint* array) {
57 while (size > 0) {
58 int step = size / 2;
59
60 if (array[first + step] < x) {
61 first = first + step + 1;
62 size -= step + 1;
63 } else {
64 size = step;
65 }
66 }
67 return first;
68}
69)";