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