Skip to content

vertex-matching redux #217

Closed
Closed

Description

@yakra

22cf13b was left out of TravelMapping#404 because while it's easier on the CPU, it needs more RAM bandwidth. Above ~7 threads, this becomes a bottleneck, and this alternative performs worse.

This solution avoids the pointer-chasing, and allocates far less memory, all in one block.

After calling all_waypoints.graph_points, we know how many vertices there will be. This will come in handy.

  • char* vbitfield = new char[ceil(hi_priority_points.size()+lo_priority_points.size()/8)*args::numthreads];
    Organize it so as to keep all of each thread's bits contiguous.
  • Reserve this much space in the HighwayGraph::vertices vector -- or just use a C array?
    The address of each HGVertex minus the start of the array forms the basis of the index into vbitfield.
  • Default constructed. Change the existing ctor to a setup function for existing objects.
  • HighwayGraph::simplify prototype will need a const size_t offset.
  • Nix sublists; offset+w will be the index into the vertices array for in-place setup.


If this works well,

  • the concept may be adaptable to TravelerLists. Nix traveler_num.
    Err... I probably meant in_subgraph (t4 / a5d4b2d), but hey, try that too!
  • Edges are another matter. They're not stored in contiguous memory, and really kinda can't be. Getting a bitfield index = messy and/or expensive.

Activity

  1. yakra commented on Mar 24, 2022

    @yakra
    Author
  2. yakra commented on Mar 25, 2022

    @yakra
    Author
  3. yakra commented on Mar 25, 2022

    @yakra
    Author
  4. yakra commented on Mar 27, 2022

    @yakra
    OwnerAuthor
    • Similar trick (using ints, not bits) may let us get rid of HGVertex::foo_vertex_num

    Results are... hmm.
    Some thoughts upon digesting BiggaTomato's data, with lab1 & lab2's fresh in...

    Subgraph performance is slower.

    Not better because...?

    • Maybe the advantage to vbits is that the whole thing can fit in cache, with the same bytes accessed multiple times.
    • 2.88 MB per thread OTOH is a cache buster, more than lab2 has per core.
      Sure, this is still allocating less than the existing method, because no pointers from each HGVertex. But still.

    Actually worse because...?

    • Is it locality? We're already accessing elements of v...
      • v->unique_name just before first assigning numbers
      • in the case of the master graph, v.incident_*_edges
    • The amount of arithmetic to get our int refs is comparable to subgraph membership functions introduced per the OP. We have an added call to vertices.size() but lose a couple bitwise operators. That may cost more than one dereference and a quick array index.
    • _7g/_7gs: Is it dereferencing g in foo_tmg_line? What if g were passed as a reference? Shouldn't the compiler optimize this stuff away? 🤣 This does compile differently.

    There are construction/destruction gains, but...
    They fail to offset the hit to subgraphs on BiggaTomato, and only barely do so on lab1 & lab2. Most likely a loss overall, as:

    • Vertex construction can be threaded. I forget about that a lot. I'm looking at single-threaded data. :)
    • Destruction should be done in a separate thread alongside datacheck FP detection anyway.

    This leads to...

    A better solution?

    • _8/_8s: Allocate just one array per vertex: vnums= new int[3*Args::numthreads]
      • Possibly improve locality of all 3 data, while still keeping the lookup for each vertex
      • Get to keep some of the construction/destruction gains

    Sequential locality?

    _7s/_7gs/_8s: This can be applied to either solution. Will it do anything?

    • store in (c,t,s) order in array, rather than (s,c,t)
    • write subgraph edges in this order

    Seems an unclear winner fr higher-cache machines.

    • Maybe free up some cache via TravelerList elements, then come back to this.
    • Keep construction/destruction in mind
      • check10.sh -v
      • Spawn HighwayGraph::clear() to its own thread. Meh, may need to measure effects on datacheckfps?
  5. yakra commented on Apr 7, 2022

    @yakra
    OwnerAuthor

    manual "rebase"

    All changes were either implemented in the linked commits or made unnecessary by other commits in the meantime.

    • v1 store vertices in contiguous memory
      8f28a2c contiguous vertices
      cc9da66 vbits
    • v2 BUGS
      6c97b69 faster PlaceRadius vertex search
      cc9da66 subgraph vertex bit field
    • v2 bugfix for missing vertices
      cc9da66 (redone via a switch)
    • v3 bugfix for properly sized array
      cc9da66 v2 (bugfix in ec6238e)
    • v4 lists-> vectors
      cc9da66 v2
    • v5 sets-> vectors for regions & systems
      33183f2
      • rename V1 -> V0
    • v6a switch for edge matching
      cc9da66 v2
    • v6b switch writing master vertices
      8f28a2c v1
    • v6c switch writing master edges
      8f28a2c v1
    • v6d switch writing subgraph vertices
      12beccd
    • whitespace
      cc9da66 v2
    • t1 branchless nibble Drop. Less efficient.
    • t2 allocate cbycode 1x per graph; modify in place
      8f28a2c v1
    • condense switch case lines (v6b/d)
    • add comment, move const
      cc9da66 v2
    • no need to #include set_intersection.cpp
      cc9da66 v2
    • refactor listupdates.txt processing
      f0d618a
    • t3 store TravelerLists in contiguous memory
      9dcf0a5 #include in TravelerList.h
      d5d8c03 compute stats_t: std::unordered_map::operator[]
      af9d017 TMArray
    • t4 bitfield for TravelerList subgraph inclusion
      Done in 634da8b, much differently. Instead of the HGVertex-style iterate-check-add approach, |=s together loads of TMBitsets instead.
      The only similarity is the removal of TravelerList::in_subgraph.
      • (Old) Idea: cache line contention hasn't really seemed to be a problem, but still... using two bits per TravelerList should be enough to keep each thread on a separate cache line.
      • Comment: Wasting space with 2 bits per would be a Bad Thing, with the implementation via TMBitset now, existing project wide, with one as a member of every HighwaySegment.
        As of this writing our TMBitset<TravelerList*,uint32_t>s allocate 48 B. If they're magically allocated in adjacent memory that could be a 2/3 cache line overlap. But I'm not convinced this is a problem; it performs well in Linux. FreeBSD has to have something else going on. It seems to have memory bandwidth issues in a few areas; this is just siteupdate's most extreme manifestation of them. Continue to pursue solutions targeting memory locality, HGEdge alignment & size, cache hits, etc.
    • v7 family: slower than v8 family, right?
      v7 & v8 have their own issue now.
    • v8
      • Was there an improvement?
        Yes. Outperforms t2 a majority of the time on BT, lab1 & lab2.
        OTOH, on lab5, only outperforms t2 @ 8 threads.
        Be interesting to see how this scales on lab4.
      • Was v8s an improvement over v8?
        Slight lead on lab2. Other machines appear slightly slower, but may just be noise. Shouldn't do any harm.
      • Hold off until more optimizations are in place and any changes may be more easily observed.
    • New business:
      Bring in changes from e7d8dda (fcg full custom graphs branch):
      • V1: store master vertex & edge counts in HighwayGraph object; slim down graph_generation.cpp
      • V2?: GRAPH macros can be replaced with a pointer
      • V2?: ADDGRAPH macros can be replaced with more overloaded ctors (delegating ctor(s)?)
        or a new add_trio or add_group function, whatever's clever.
  6. yakra commented on Apr 20, 2022

    @yakra
    Author
  7. yakra commented on Jul 16, 2023

    @yakra
    OwnerAuthor

    Updated comments above & added links.

    Everything is either:

    • implemented (vertex bitfield & TMBitset<TravelerList*>) or
    • has its own issue (vertex_nums & traveler_num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions