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
3#include <thrust/copy.h>
4#include <thrust/count.h>
5#include <thrust/device_vector.h>
6#include <thrust/execution_policy.h>
7
8namespace graphite {
9
10// For factors, ignores the MSB
11__host__ __device__ __forceinline__ bool
12is_factor_active(const uint8_t active_val, const uint8_t level) {
13 constexpr uint8_t NOT_MSB = 0x7F; // 01111111
14 return (active_val & NOT_MSB) <= level && ((active_val & 0x80) == 0);
15}
16
17// For vertex
18__host__ __device__ __forceinline__ bool
19is_vertex_active(const uint8_t *active_state, const size_t vertex_id) {
20 return !(active_state[vertex_id] > 0);
21}
22
23// Returns the number of active constraints and fills the active_indices vector
24inline size_t
25build_active_indices(const thrust::device_vector<uint8_t> &active,
26 thrust::device_vector<size_t> &active_indices,
27 const size_t count, const uint8_t level) {
28
29 // Count active constraints
30 const size_t active_count =
31 thrust::count_if(thrust::device, active.begin(), active.end(),
32 [level] __device__(const uint8_t a) {
33 return is_factor_active(a, level);
34 });
35
36 // Resize active indices to the number of active constraints
37 active_indices.clear();
38 active_indices.resize(active_count);
39
40 // Fill active indices with the indices of active constraints
41 thrust::copy_if(thrust::device, thrust::make_counting_iterator<size_t>(0),
42 thrust::make_counting_iterator<size_t>(count), active.begin(),
43 active_indices.begin(), [level] __device__(const uint8_t a) {
44 return is_factor_active(a, level);
45 });
46 return active_count;
47}
48
49} // namespace graphite
The top-level namespace for Graphite.
Definition eigen_solver.cpp:4