experimental#

EXPERIMENTAL PUBLIC; may change in any minor release. dyng::experimental::count_local_patterns<op_t> counts a new hypergraph pattern, given as an Op, with triad_count’s wedge engine, and keeps the counts exact under hyperedge batches (ADR ADR 0058: experimental::count_local_patterns: one driver, one engine, and the Op concept). The tutorial is Count a new hypergraph pattern (an Op).

Two headers: <dyng/experimental/local_patterns.hpp> compiles with a host compiler (the shapes, the rows an Op reads and the set helpers, the stats, access_rows()); <dyng/experimental/local_patterns.cuh> needs nvcc (count_local_patterns, its result and the kernels compiled for an Op), the one kind of public header that does (PLAN Section 4.1). The experimental tier is tracked by the API check, which reports its changes without failing on them; the changes are listed in the changelog.

enum class dyng::experimental::shape : std::uint8_t#

What an Op counts over: the triangles of the line graph, its edges (adjacent pairs of hyperedges), or the hyperedges themselves (ESCHER-GPU’s countTriangles, countPairs and countKeys).

Values:

enumerator triangles#

begin_wedge(rows, a, b), then triangle(rows, c, bins) per triangle {a, b, c}

enumerator pairs#

pair(rows, a, b, bins) per pair of hyperedges that share a vertex

enumerator keys#

key(rows, a, bins) per hyperedge

using dyng::experimental::member_code = std::int32_t#

An opaque member code: the codes of a hyperedge’s members are distinct and ascending in the vertex ids, so two rows can be merged and compared code by code, and hyperedge_rows::decode() gives the vertex id of a code. Nothing else is meant by its value.

constexpr int dyng::experimental::max_pattern_bins = 1024#

The largest num_bins of an Op: its bins live in the block’s shared memory on the GPU (8 bytes each: 8 KiB at most), and on the stack of every host thread.

constexpr std::size_t dyng::experimental::max_op_size = 4096#

The largest size of an Op, in bytes: the Op’s value is a parameter of every counting kernel and every GPU thread and host worker holds a copy of it, so it is small per-worker state, not a table (the kernel-parameter space of CUDA is 32,764 bytes).

std::string_view dyng::experimental::to_string(shape s) noexcept#

The lower-case name of a shape (“triangles”, “pairs”, “keys”).

Parameters:

s – [in] The shape.

Returns:

A static string naming s.

inline int dyng::experimental::intersect_size(member_span a, member_span b) noexcept#

|A ∩ B|: the number of members two hyperedges share (one merge of their codes).

Parameters:
  • a – [in] The members of one hyperedge.

  • b – [in] The members of another.

Returns:

The size of the intersection.

inline venn_counts dyng::experimental::venn3(member_span a, member_span b, member_span c) noexcept#

The pairwise and the triple intersections of three hyperedges in one merge of their codes (the regions of their Venn diagram follow: only a = |A| - ab - ca + abc, …).

Parameters:
  • a – [in] The members of the first hyperedge.

  • b – [in] The members of the second.

  • c – [in] The members of the third.

Returns:

|A ∩ B|, |B ∩ C|, |C ∩ A| and |A ∩ B ∩ C|.

inline bool dyng::experimental::intersects3(member_span a, member_span b, member_span c) noexcept#

Whether three hyperedges share a member.

Parameters:
  • a – [in] The members of the first hyperedge.

  • b – [in] The members of the second.

  • c – [in] The members of the third.

Returns:

true if some vertex is in all three.

template<typename vertex_t, typename weight_t>
row_access dyng::experimental::access_rows(const hypergraph<vertex_t, weight_t> &h)#

The rows the engine reads of h’s current state (the hyperedges’ members by id).

Nothing is copied or built (under line_graph_policy::automatic the line graph exists only once an algorithm asked for it: has_line_graph() says).

Template Parameters:
  • vertex_t – Vertex id type (int32_t).

  • weight_t – Hyperedge weight type (unweighted or int32_t).

Parameters:

h – [in] The hypergraph.

Throws:

invalid_argument_error – if h was poisoned by a failed apply().

Returns:

Its rows, valid until the next apply() or update() of h.

DYNG_DETAIL_LP_CONCAT2(a, b)#

Paste two tokens (a helper of DYNG_EXPERIMENTAL_CHECK_HOST_CALLBACKS).

DYNG_DETAIL_LP_CONCAT(a, b)#

Paste two tokens after expanding them (a helper of DYNG_EXPERIMENTAL_CHECK_HOST_CALLBACKS).

DYNG_EXPERIMENTAL_CHECK_HOST_CALLBACKS(op_type)#

Make nvcc check that the callbacks of the Op op_type can be called on the host: use it once per Op, at namespace scope of a .cu file, after the Op’s definition.

nvcc does not report a __device__

-only callback that the library calls from its host function template (the sequential and openmp backends then end the process with exit status 1 and no message: see “Host and device callbacks” at count_local_patterns). This macro defines a host function that is never called and calls the Op’s callbacks from it, outside any template, where nvcc reports “calling a __device__ function … from a __host__ function is not

allowed”. It also checks the Op concept (count_local_patterns<op_type>::valid). It adds no code that runs.

struct my_op { ... };
DYNG_EXPERIMENTAL_CHECK_HOST_CALLBACKS(my_op);

Parameters:
  • op_type – The Op (a type name).

DYNG_HD#

Marks a callback of an Op (and any function it calls) that runs on the host and the device: __host__ __device__ under nvcc, nothing for a host compiler.

DYNG_HD_INLINE#

A small function of the engine and its set helpers, inlined on the host and the device.

DYNG_LOCAL_PATTERNS_TYPES_MESSAGE#

The message of count_local_patterns’ and access_rows()’s static_assert for an unsupported hypergraph type.

template<class op_t>
class local_patterns_result#

The counts of an Op kept up to date by count_local_patterns<op_t>::update() (opaque, move-only; the counterpart of triad_count::result).

counts()[k] is the count of bin k, num_bins() = op_t::num_bins values, a host array on every backend. The Op value given to compute() is kept (op()): every update counts with it.

Thread safety. As triad_count::result: accessors may run concurrently with each other, not with an update of the result.

Template Parameters:

op_t – The Op.

Public Types

using op_type = op_t#

the Op

Public Functions

local_patterns_result(local_patterns_result &&other) noexcept = default#

Move constructor.

Parameters:

other – [inout] The result to move from; it may only be assigned to or destroyed after.

local_patterns_result &operator=(local_patterns_result &&other) noexcept = default#

Move assignment.

Parameters:

other – [inout] The result to move from; it may only be assigned to or destroyed after.

Returns:

*this.

local_patterns_result(const local_patterns_result&) = delete#

use clone()

local_patterns_result &operator=(const local_patterns_result&) = delete#

use clone()

~local_patterns_result() = default#

releases the counts

inline int num_bins() const#

The number of bins.

Throws:
Returns:

op_t::num_bins.

inline array_view<const std::uint64_t> counts() const#

The counts.

Throws:
Returns:

num_bins() counts (host memory), valid until the next update of the result.

inline std::uint64_t count(int bin) const#

The count of one bin.

Parameters:

bin – [in] The bin, in [0, num_bins()).

Throws:
Returns:

Its count.

inline std::uint64_t total() const#

The sum of the bins.

Throws:
Returns:

The total.

inline op_t op() const#

The Op the result counts with (the value given to compute()).

Throws:
Returns:

A copy of it.

inline std::uint64_t graph_version() const noexcept#

The hypergraph version this result matches.

Returns:

The version after the last compute() / update() of this result (0 if moved from).

inline memory_space space() const noexcept#

The memory space of the counts.

Returns:

memory_space::host (on every backend).

inline local_patterns_result clone(const resources &res) const#

A deep copy for the resources res.

Synchronization:

Blocks until the work has completed (synchronous). The copy is complete on return (host memory on every backend).

Parameters:

res – [in] Execution resources of the copy (any available backend).

Throws:
Returns:

The copy.

template<class op_t>
struct count_local_patterns#

Count a hypergraph pattern given as an Op, and keep the counts exact under hyperedge batches: experimental::count_local_patterns<op_t>::compute() and update() (PLAN Appendix B: ESCHER-GPU’s countTriangles<Op>).

The Op concept (each requirement has its own static_assert message):

  • static constexpr int num_bins, in [1, max_pattern_bins] (the bins live in a block’s shared memory);

  • static constexpr dyng::experimental::shape shape: what the engine enumerates;

  • the callbacks of the shape, each DYNG_HD (they run on the GPU and on the host) and each taking the rows handle (const hyperedge_rows&) and 0-based hyperedge ids:

    • shape::triangles: void begin_wedge(const hyperedge_rows& rows, int a, int b) (once per wedge (a, b) of the line graph) and template <class bins_t> void triangle(const hyperedge_rows& rows, int c, bins_t& bins) (once per triangle {a, b, c} closing it);

    • shape::pairs: template <class bins_t> void pair(const hyperedge_rows& rows, int a, int b, bins_t& bins) (once per pair of hyperedges that share a vertex);

    • shape::keys: template <class bins_t> void key(const hyperedge_rows& rows, int a, bins_t& bins) (once per live hyperedge); and template <class bins_t> void flush(bins_t& bins), called once at the end of a worker’s run, which adds what the Op kept in its own members;

  • trivially copyable and default-constructible: the Op value given to compute() (op_t{} by default) is the initial state of every worker (a GPU thread, a host source), which may call the callbacks any number of times before flush();

  • at most max_op_size (4,096) bytes: the value is a parameter of every counting kernel and every GPU thread holds a copy of it (registers or local memory), so the Op is small per-worker state, not a table.

Host and device callbacks. nvcc reports a host-only callback at the engine’s call, but not a __device__-only one: the library calls the host callbacks from a function template, where nvcc compiles such a call to a stub, and the sequential and openmp backends then end the process with exit status 1 and no message (the cuda backend works). Write each callback DYNG_HD, and put DYNG_EXPERIMENTAL_CHECK_HOST_CALLBACKS(op_t) after the Op at namespace scope: it calls the callbacks from a non-template host function, where nvcc does report a __device__-only one.

The ids of a call come in no particular order. A full count (compute()) happens to pass a < b to pair() and begin_wedge() and a < b < c for a triangle, but a frontier phase of update() passes a changed hyperedge as a and its neighbours in any order (b < a, c < a). The count must therefore be symmetric in a and b (pairs) and in a, b and c (triangles). An Op that counts rows.size(a) > rows.size(b) agrees with a brute force over every pair i < j under compute() and is silently wrong after update()

; test every Op with “baseline + deltas ==

recount” under updates, never against

compute() alone.

The bins handle has add(int bin, std::uint64_t value) (a bin outside [0, num_bins) is refused and reported) and overflow() (report a count of the Op’s own past 2^64 - 1). Every count is an unsigned 64-bit sum; a count of a pattern must not depend on which worker or in which order it is counted (the engine’s guarantee of exact, deterministic counts rests on it).

The Op never sees the frontier, the sign of a phase or the ownership rule: the engine counts each triangle (pair, hyperedge) through the changed hyperedges once, at its smallest changed member (ownership::min_member), subtracts the ones through the deleted hyperedges on the hypergraph before the batch and adds the ones through the inserted hyperedges on the hypergraph after it. The Op never holds a view or a pointer of its own into the hypergraph, so the subtraction cannot read the new state (invariant I1 by construction).

Data of the user’s own (vertex labels, a vertex set): the engine passes only the rows and the ids, so such data goes in through a pointer member the caller sets. It must point to device memory on cuda and to host memory on sequential and openmp, and stay valid and unchanged for the result’s whole lifetime (the result keeps the Op value for every update()). Only an Op without pointers runs on every backend unchanged.

The rows: a member code (member_code) is opaque and ascending in the vertex ids; hyperedge_rows::decode() gives the vertex id. intersect_size(), venn3() and intersects3() merge the codes directly (no decode pass on the hot path).

Requirements: the shapes triangles and pairs read the line graph and the vertex-to-hyperedge rows (hypergraph_properties::line_graph other than none, store_v2h); keys reads neither. Every Op is refused on a hypergraph with 2,147,483,647 vertices (the set helpers end a row at INT_MAX; the vertex ids up to 2^31 - 3 are supported).

Types: hypergraph<int32_t, unweighted or int32_t> (the weights are ignored).

Template Parameters:

op_t – The Op.

Public Types

using result = local_patterns_result<op_t>#

the counts of the Op

using stats = local_patterns_stats#

the counters of an update

Public Static Functions

template<typename vertex_t, typename weight_t>
static inline result compute(const resources &res, const hypergraph<vertex_t, weight_t> &h, const op_t &op)#

Count the Op’s pattern on h (the full count, the oracle of update()).

Synchronization:

Blocks until the work has completed (synchronous). The counts are complete on return.

Backends:

sequential, openmp, cuda (the wedge engine of triad_count)

Determinism:

Exact values: identical counts on every backend and thread count (for an Op whose counts do not depend on the order of its calls).

Exception safety:

Strong: h is not modified (its line graph may be built under automatic).

Paper:

The engine of ESCHER (IPDPS 2026) and ESCHER+ (TKDE 2026): dyng::citation("triad_count").

Template Parameters:
  • vertex_t – Vertex id type (int32_t).

  • weight_t – Hyperedge weight type (unweighted or int32_t; ignored).

Parameters:
  • res – [in] Execution resources (cuda, sequential or openmp).

  • h – [in] The hypergraph (under line_graph_policy::automatic its line graph is built here, once, for the shapes triangles and pairs).

  • op – [in] The Op’s initial value (kept by the result for every update; the overload without it uses op_t{}).

Throws:
  • invalid_argument_error – if the shape needs the line graph or the vertex-to-hyperedge rows and h keeps none, h has 2,147,483,647 vertices, h belongs to another backend than res, or h was poisoned; or an Op named a bin outside [0, num_bins).

  • not_supported_error – if the backend of res is not available, the header and the library differ, or h has hypergraph_storage::slack_csr (0.4: escher storage only).

  • capacity_error – if a count exceeds 2^64 - 1.

  • out_of_memory_error – if host or device memory cannot be allocated.

  • cuda_error – if the CUDA runtime reports an error.

Returns:

The counts, matching h.version().

template<typename vertex_t, typename weight_t>
static inline result compute(const resources &res, const hypergraph<vertex_t, weight_t> &h)#

compute() with the value-initialized Op, op_t{}.

Synchronization:

Blocks until the work has completed (synchronous). The counts are complete on return.

Backends:

sequential, openmp, cuda

Determinism:

As compute(res, h, op).

Exception safety:

Strong.

Paper:

The engine of ESCHER (IPDPS 2026) and ESCHER+ (TKDE 2026).

Template Parameters:
  • vertex_t – Vertex id type (int32_t).

  • weight_t – Hyperedge weight type (unweighted or int32_t; ignored).

Parameters:
  • res – [in] Execution resources.

  • h – [in] The hypergraph.

Throws:
Returns:

The counts, matching h.version().

template<typename vertex_t, typename weight_t>
static inline stats update(const resources &res, hypergraph<vertex_t, weight_t> &h, const hyperedge_batch_view<vertex_t, weight_t> &batch, result &r)#

Apply a batch of hyperedge changes to h and update the counts r (count(-) on the hypergraph before the batch, the commit, count(+) after it).

Postcondition: r equals compute(res, h, r.op()) exactly.

Synchronization:

Blocks until the work has completed (synchronous). The hypergraph and the counts are updated on return.

Backends:

sequential, openmp, cuda

Determinism:

Exact values: identical counts and counters on every backend and thread count.

Exception safety:

As triad_count::update(): strong before the commit, basic after it (the result is poisoned).

Paper:

The engine of ESCHER (IPDPS 2026) and ESCHER+ (TKDE 2026).

Template Parameters:
  • vertex_t – Vertex id type (int32_t).

  • weight_t – Hyperedge weight type (unweighted or int32_t; ignored).

Parameters:
  • res – [in] Execution resources.

  • h – [inout] The hypergraph; the batch is applied to it and its version increases.

  • batch – [in] Hyperedge deletions (by id) and insertions.

  • r – [inout] Result of compute() or of a previous update() on h.

Throws:
  • stale_result_error – if r.graph_version() != h.version(), r was computed on another hypergraph, or r was left unusable by a failed update.

  • invalid_argument_error – if a batch member is invalid, h belongs to another backend than res or was poisoned (nothing is changed); or an Op named a bin outside [0, num_bins) (after the commit: r is left unusable).

  • not_supported_error – if the backend of res is not available, the batch has incidence edits, or h has hypergraph_storage::slack_csr (0.4: escher storage only; nothing is changed).

  • internal_error – if a bin would become negative (an Op whose counts depend on the order of its calls, or a library bug; r is left unusable).

  • capacity_error – if a count exceeds 2^64 - 1 or the change of a bin is outside the signed 64-bit range (r is left unusable), or the storage cannot hold the batch.

  • out_of_memory_error – if memory cannot be allocated.

  • cuda_error – if the CUDA runtime reports an error.

Returns:

Counters of this update (deterministic).

Public Static Attributes

static constexpr bool valid = detail::local_patterns::check_op<op_t>()#

Whether op_t is an Op (otherwise a static_assert of the Op concept has fired).

class member_span#

The members of one hyperedge: its member codes, ascending (a contiguous, read-only span in the memory the engine runs in; never stored beyond the callback).

Public Functions

constexpr member_span() noexcept = default#

An empty span.

inline constexpr member_span(const member_code *first, int count) noexcept#

The span of count codes from first.

Parameters:
  • first – [in] The first code.

  • count – [in] The number of codes.

inline constexpr const member_code *begin() const noexcept#

The first code.

Returns:

A pointer to it.

inline constexpr const member_code *end() const noexcept#

Past the last code.

Returns:

begin() + size().

inline constexpr int size() const noexcept#

The number of members.

Returns:

The span’s length (the hyperedge’s size).

inline constexpr bool empty() const noexcept#

Whether the span is empty (a dead hyperedge id).

Returns:

size() == 0.

inline constexpr member_code operator[](int i) const noexcept#

The code of member i.

Parameters:

i – [in] The position, in [0, size()).

Returns:

The code.

class hyperedge_rows#

The rows handle the engine passes to an Op’s callbacks: the members of every hyperedge by its 0-based id, as member spans (no decode pass: the codes are the store’s own).

Trivially copyable and cheap to pass by value; it points into the memory of the engine’s backend (device memory on cuda), so it is valid only inside a callback, or for the life of the row_access it came from.

Public Functions

constexpr hyperedge_rows() noexcept = default#

A handle of no rows (row() must not be called on it).

inline member_span row(int id) const noexcept#

The members of hyperedge id.

Parameters:

id – [in] A hyperedge id the engine passed (a callback’s argument).

Returns:

Its member codes, ascending.

inline int size(int id) const noexcept#

The number of members of hyperedge id.

Parameters:

id – [in] A hyperedge id the engine passed.

Returns:

row(id).size().

Public Static Functions

static inline constexpr std::int32_t decode(member_code code) noexcept#

The vertex id of a member code.

Parameters:

code – [in] A code of a member_span of these rows.

Returns:

The member’s vertex id, in [0, num_vertices()).

struct venn_counts#

The sizes of the regions of three member sets that the classification of a triad reads (venn3()).

Public Members

int ab = 0#

|A ∩ B|

int bc = 0#

|B ∩ C|

int ca = 0#

|C ∩ A|

int abc = 0#

|A ∩ B ∩ C|

class row_access#

The rows the engine reads of one hypergraph state, as access_rows() returns them: the hyperedges’ members by id (the handle the callbacks get) and the state’s id bound.

It points into the hypergraph’s storage (device memory on cuda: space() and device() say where) and is valid until the next apply() or update() of the hypergraph; reading it does not copy anything.

Public Functions

constexpr row_access() noexcept = default#

No rows.

inline hyperedge_rows hyperedges() const noexcept#

The members of every hyperedge by id: hyperedges().row(id) for every id in [0, id_bound()); a dead id has an empty row.

Returns:

The rows handle (as an Op’s callbacks receive it).

inline std::int64_t id_bound() const noexcept#

The hyperedge id bound of the state (hypergraph::hyperedge_id_bound()).

Returns:

One more than the largest id that may be live.

inline bool has_line_graph() const noexcept#

Whether the state keeps its line graph (what the triangles and pairs shapes read).

Returns:

true if the line graph is maintained.

inline memory_space space() const noexcept#

Where the rows are.

Returns:

memory_space::device for a hypergraph of the cuda backend, memory_space::host otherwise.

inline int device() const noexcept#

The CUDA device of device rows.

Returns:

The device ordinal, or -1 for host rows.

struct local_patterns_stats : public dyng::update_stats#

Counters of one count_local_patterns update (fields are only ever appended).

Every counter is deterministic (identical on every backend, thread count and run). The inherited fields mean what they mean for triad_count::stats: affected is the number of bins whose count changed, iterations is 0, frontier_visits is deleted_frontier + inserted_frontier, fallback_used is false, converged is true, and engine_used is engine::fused on cuda and engine::operators on the host backends.

Public Members

hyper_apply_summary batch#

What applying the batch did to the hypergraph (the inserted ids among it).

std::int64_t deleted_frontier = 0#

The hyperedges of the subtract phase: the live ids the batch deleted (distinct).

std::int64_t inserted_frontier = 0#

The hyperedges of the add phase: the hyperedges the batch inserted.

std::uint64_t removed = 0#

The subtract phase’s count, summed over the bins (what the deleted hyperedges took away).

std::uint64_t added = 0#

The add phase’s count, summed over the bins (what the inserted hyperedges brought).

std::vector<std::int64_t> delta#

The change of every bin: the counts after the update minus the counts before it (num_bins values).