Graphite
Loading...
Searching...
No Matches
active.hpp
Go to the documentation of this file.
1
2#pragma once
4
5namespace graphite {
6
7namespace ops {
8
9// For flagging active vertices of a factor
10// For an active factor, the MSB of a vertex's active state is set to 1
11template <size_t I, size_t N>
12__global__ void
13flag_active_vertices_kernel(const size_t *ids, uint8_t *v_active,
14 const uint8_t *f_active, const size_t factor_count,
15 const uint8_t level) {
16 const size_t factor_id = get_thread_id();
17
18 if (factor_id >= factor_count) {
19 return;
20 }
21
22 if (is_factor_active(f_active[factor_id], level)) {
23 // TODO: Investigate if this can cause a bug - do we need to use atomicOr?
24 const auto vertex_id = ids[factor_id * N + I];
25 v_active[vertex_id] |= 0x80; // Set MSB to 1
26 }
27}
28
29template <typename F, std::size_t... Is>
30void launch_kernel_flag_active(F *f, const uint8_t level,
31 std::index_sequence<Is...>) {
32
33 auto vd = f->vertex_descriptors;
34 const uint8_t *f_active = f->device_active.data().get();
35 const size_t *device_ids = f->device_ids.data().get();
36 const size_t num_factors = f->internal_count();
37
38 (([&] {
39 uint8_t *v_active = vd[Is]->get_active_state();
40 const size_t num_threads = num_factors;
41 const auto threads_per_block = 256;
42 const auto num_blocks =
43 (num_threads + threads_per_block - 1) / threads_per_block;
44
45 flag_active_vertices_kernel<Is, F::get_num_vertices()>
46 <<<num_blocks, threads_per_block>>>(device_ids, v_active, f_active,
47 num_factors, level);
48 }()),
49 ...);
50}
51
52template <typename F> void flag_active_vertices(F *f, const uint8_t level) {
53 launch_kernel_flag_active(f, level,
54 std::make_index_sequence<F::get_num_vertices()>{});
55}
56
57} // namespace ops
58
59} // namespace graphite