SETUP void set_threads( int count )
KERNEL void coarse_active( const unsigned char* codes, const long long* n, const long long* c,
                           unsigned char* out )
KERNEL void code_counts( const unsigned char* codes, const long long* n, long long* counts )
KERNEL void select_cells( long long count, const unsigned char* codes,
                          const unsigned char* active, long long* uncut, unsigned char* inside,
                          long long* cut, long long* sizes )
KERNEL void pore_runs( const unsigned char* bits, const long long* n, const long long* first,
                       const long long* count, long long* out )
KERNEL long long node_values( const levelset* ls, const long long* first, const long long* count,
                              double* out, char* scratch )
KERNEL long long classify( const levelset* ls, const voxel_grid* g, unsigned char* codes,
                           char* scratch )
KERNEL long long correction_step( const levelset* ls, const long long* first,
                                  const long long* count, double damping, short* correction_out,
                                  char* scratch )
KERNEL long long label_slabs( const levelset* ls, const long long* first, const long long* count,
                              const int* held_faces, const long long* edges, long long slab_begin,
                              long long slab_end, unsigned* numbers, unsigned char* held,
                              long long* counts, char* scratch )
KERNEL void join_slabs( long long slab_begin, long long slab_end, long long plane,
                        const unsigned* numbers, const unsigned char* held,
                        const long long* offsets, unsigned* top, unsigned* labels,
                        unsigned char* touching )
KERNEL long long mark_removed( const levelset* ls, const long long* first, const long long* count,
                               const int* held_faces, const long long* edges, long long slab_begin,
                               long long slab_end, const unsigned* labels,
                               const unsigned char* touching,
                               const long long* offsets, unsigned char* removed,
                               long long* counts, char* scratch )
KERNEL long long moments( const levelset* ls, const voxel_grid* g, long long count,
                          const long long* cells, float* out, char* scratch )
KERNEL long long surface( const levelset* ls, const long long* first, const long long* count,
                          const double* box, long long z_begin, long long z_end,
                          long long* rows, float* out, char* scratch )
KERNEL long long merge_points( long long count, const float* points, long long* ids, float* out,
                               char* scratch )
SETUP void law_tangent( const linear_operator* o, double* tangent )
SETUP long long cell_matrices( const linear_operator* o, long long count,
                                const long long* candidates, const float* inverse_diagonal,
                                const unsigned char* free_dofs, double* matrices, char* scratch )
SETUP long long diagonal( const linear_operator* o, long long count, const long long* candidates,
                           double* y, char* scratch )
SETUP void coarse_codes( const linear_operator* o, const long long* c, unsigned char* codes )
SETUP long long coarse_weights( const linear_operator* o, long long count,
                                 const long long* coarse, const long long* c, int mc,
                                 const double* fine_bounds, const double* coarse_bounds,
                                 const double* fine_points, const double* coarse_points,
                                 double margin, float* out, char* scratch )
SETUP void mix_weights( const linear_operator* o, const float* body, float* out )
SETUP void coarse_constrained( const linear_operator* o, const transfer_map* p,
                                unsigned char* flags )
SETUP long long NAME( energies )( const linear_operator* o, int count, const float* x,
                                   long long stride, const real* gradients, double* out,
                                   char* scratch )
SOLVE void apply_level( const linear_operator* o, const real* b, real* x, real* y, real scale,
                         real keep, int* done, int blocks, int epoch, real* kept )
KERNEL long long PRECISE( apply )( const linear_operator* o, const real* b, real* x, real* y,
                                   real scale, real keep, char* scratch )
SOLVE void precondition_level( const linear_operator* o, const preconditioner* b, const real* r,
                                real factor, real keep, real* out, int* done, int blocks,
                                int epoch )
SETUP long long cell_modes( const linear_operator* o, long long count,
                             const long long* candidates, const float* inverse_diagonal,
                             const unsigned char* free_dofs, double lower, double upper,
                             int* counts, short* vectors, float* gamma, long long* sizes,
                             char* scratch )
SETUP long long weight_stiff( const linear_operator* o, long long count, const long long* cells,
                               const long long* starts, short* modes, float* gamma,
                               char* scratch )
SETUP void gather_modes( long long count, const long long* cells, const int* counts,
                          const short* vectors, const float* gamma, long long first,
                          long long* mode_cells, long long* starts, short* modes, float* gammas )
KERNEL void invert( long long count, const double* in, float* out )
KERNEL void update( long long count, double step, const real* p, const real* q, real* u, real* r )
KERNEL long long dot( long long count, const real* a, const real* b, double* out, char* scratch )
KERNEL long long node_map( const unsigned char* codes, const long long* n, int p, long long* map,
                           char* scratch )
KERNEL long long interpolation( int nf, int p, const double* fine_bounds,
                                const double* fine_points, int nc, int q,
                                const double* coarse_bounds, const double* coarse_points,
                                int* starts, int* columns, float* values )
KERNEL void linear_field( const lattice* g, int fields, const double* xs, const double* ys,
                          const double* zs, const double* gradient, const double* centre,
                          const int* groups, const double* offsets, real* out )
KERNEL void field_points( const lattice* g, int fields, const double* xs, const double* ys,
                          const double* zs, const double* nodes, long long count,
                          const double* points, const long long* cells, const real* in,
                          double* values, double* gradients )
KERNEL long long face_dofs( const lattice* g, int fields, const int* faces, int count,
                            const int* held, long long* out )
KERNEL long long cell_parts( const unsigned char* codes, const long long* n, int faces,
                             int* parts, char* scratch )
KERNEL long long part_joints( const long long* n, const int* parts, long long* planes,
                              long long* vertices, int* pairs )
KERNEL long long rigid_pins( const lattice* g, const unsigned char* codes, const int* parts,
                             int count, const double* spacing, long long* nodes,
                             long long* corners, int* faces, char* scratch )
KERNEL void node_pattern( const transfer_map* m, long long nodes, const long long* positions,
                          int* columns, double* values )
KERNEL void stencil_pattern( const lattice* g, long long nodes, const long long* positions,
                             const long long* starts, int* counts, int* columns, int* masks )
KERNEL void gather_columns( long long nodes, int fields, const long long* positions,
                            const long long* starts, const int* masks, int colour, int field,
                            const double* y, float* blocks )
KERNEL void pattern_product( long long nodes, int fields, const long long* a_starts,
                             const int* a_columns, const float* a_blocks,
                             const long long* p_starts, const int* p_columns,
                             const double* p_blocks, double* product )
KERNEL void galerkin( long long coarse_nodes, int fields, const long long* positions,
                      const long long* starts, const int* masks, const long long* r_starts,
                      const int* r_columns, const float* r_values, const long long* a_starts,
                      const int* a_columns, const float* a_blocks, const long long* p_starts,
                      const int* p_columns, const float* p_values, float* blocks )
KERNEL void minimize_energy( long long nodes, int fields, const long long* starts,
                             const int* columns, const double* fine_xyz,
                             const double* coarse_xyz, const unsigned char* fine_free,
                             const unsigned char* coarse_free, const double* diagonal,
                             double omega, const double* product, double* blocks )
KERNEL void block_apply( long long nodes, const long long* starts, const int* columns,
                         const float* values, int fields, int diagonal, const real* x, real* y )
KERNEL void apply_stencil( const linear_operator* o, const real* b, real* x, real* y, real scale,
                           real keep, int* done, int blocks, int epoch, real* kept )
KERNEL void precondition_stencil( const linear_operator* o, const preconditioner* b,
                                  const real* r, real factor, real keep, real* out, int* done,
                                  int blocks, int epoch )
KERNEL long long cycle( const level* levels, int count, int first, const real* rhs, real* out,
                        const real* q, double* dots, char* scratch )
KERNEL long long direction( const level* levels, int count, const real* z, double beta, real* p,
                            real* q, double* pq, char* scratch )
KERNEL long long lanczos( const level* l, int steps, double* scalars, int* count, char* scratch )
