LSLab
map_kernels.h
Go to the documentation of this file.
1 
4 #include <cuda.h>
5 #include <cuda/std/utility>
6 
7 #pragma once
8 
9 namespace lslab {
10 namespace map_kernels {
11 
12 template<int block_size, typename map_t, typename K, typename V>
13 __global__ void put_(map_t map, cuda::std::pair<K, V>* operations, V* output, size_t size) {
14 
15  int tidx = threadIdx.x;
16  int bidx = blockIdx.x;
17 
18  K key;
19  V val;
20  if(tidx + bidx * block_size < size) {
21  key = operations[tidx + bidx * block_size].first;
22  val = operations[tidx + bidx * block_size].second;
23  }
24 
25  V res = map.put(key, val, tidx + bidx * block_size < size);
26 
27  if(tidx + bidx * block_size < size) {
28  output[tidx + bidx * block_size] = res;
29  }
30 }
31 
32 template<int block_size, typename map_t, typename K, typename V>
33 __global__ void put_(map_t map, K* operations_keys, V* operations_values, V* output, size_t size) {
34 
35  int tidx = threadIdx.x;
36  int bidx = blockIdx.x;
37 
38  K key;
39  V val;
40  if(tidx + bidx * block_size < size) {
41  key = operations_keys[tidx + bidx * block_size];
42  val = operations_values[tidx + bidx * block_size];
43  }
44 
45  V res = map.put(key, val, tidx + bidx * block_size < size);
46 
47  if(tidx + bidx * block_size < size) {
48  output[tidx + bidx * block_size] = res;
49  }
50 }
51 
52 
53 template<int block_size, typename map_t, typename K, typename V>
54 __global__ void get_(map_t map, K* operations, cuda::std::pair<bool, V>* output, size_t size) {
55 
56  int tidx = threadIdx.x;
57  int bidx = blockIdx.x;
58 
59  K key;
60  V value;
61  if(tidx + bidx * block_size < size) {
62  key = operations[tidx + bidx * block_size];
63  }
64 
65  bool res = map.get(key, value, tidx + bidx * block_size < size);
66  if(tidx + bidx * block_size < size) {
67  output[tidx + bidx * block_size] = {res, value};
68  }
69 
70 }
71 
72 template<int block_size, typename map_t, typename K, typename V>
73 __global__ void update_(map_t map, cuda::std::pair<K, V>* operations, cuda::std::pair<bool, V>* output, size_t size) {
74 
75  int tidx = threadIdx.x;
76  int bidx = blockIdx.x;
77 
78  K key;
79  V val;
80  if(tidx + bidx * block_size < size) {
81  key = operations[tidx + bidx * block_size].first;
82  val = operations[tidx + bidx * block_size].second;
83  }
84 
85  cuda::std::pair<bool, V> res = map.put(key, val, tidx + bidx * block_size < size);
86  if(tidx + bidx * block_size < size) {
87  output[tidx + bidx * block_size] = res;
88  }
89 }
90 
91 }
92 }