Skip to content

fundal_registry ​

FUNDAL, allocation registry module: device and size of every structured allocation.

Host-side open-addressing hash table (linear probing, backward-shift deletion, doubling at load 0.5) keyed by the base address of the buffer; key 0 marks an empty slot (a successful allocation never returns a null address). The registry owns the live-allocation totals and mirrors them into the fundal_env counters (dev_allocs_live, dev_bytes_live). A second structure, the base addresses sorted in ascending order, finds the allocation containing an address (a section of a buffer) by binary search: O(log n) lookup, O(n) insertion and removal. Updates are serialized by an OpenMP critical section: thread-safe only when the library is compiled with OpenMP.

Source: src/lib/fundal_registry.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
FUNDAL_REGISTRY_OFFinteger(kind=I4P)parameterRegistry checks disabled: today's behaviour, no warnings.
FUNDAL_REGISTRY_WARNinteger(kind=I4P)parameterMisuse is reported on stderr, behaviour unchanged (default).
FUNDAL_REGISTRY_ERRORinteger(kind=I4P)parameterMisuse is an error (error code or error stop).
LABEL_LENinteger(kind=I4P)parameterLength of allocation labels.
INITIAL_CAPACITYinteger(kind=I8P)parameterInitial number of slots (power of 2).
tabletype(registry_entry)allocatable, saveHash table, slots 0:capacity-1.
sortedinteger(kind=c_intptr_t)allocatable, saveBase addresses in ascending order, sorted(1:used).
usedinteger(kind=I8P)saveNumber of occupied slots.
policy_integer(kind=I4P)saveRegistry policy, -1 = not yet resolved.

Derived Types ​

registry_entry ​

Registered allocation.

Components ​

NameTypeAttributesDescription
addrinteger(kind=c_intptr_t)Base address of the buffer (0 = empty slot).
bytesinteger(kind=I8P)Size of the buffer [bytes].
dev_idinteger(kind=I4P)Device where the buffer lives.
labelcharacter(len=LABEL_LEN)Optional user label.

Subroutines ​

registry_insert ​

Register an allocation. If the address is already registered (its buffer was released outside FUNDAL and the address reused), the old entry is replaced and replaced is set to true.

fortran
subroutine registry_insert(addr, bytes, dev_id, label, replaced)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inBase address.
bytesinteger(kind=I8P)inSize [bytes].
dev_idinteger(kind=I4P)inDevice.
labelcharacter(len=*)inoptionalLabel.
replacedlogicaloutoptionalAddress was already registered.

Call graph

registry_remove ​

Unregister an allocation, returning its entry.

fortran
subroutine registry_remove(addr, found, entry)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inBase address.
foundlogicaloutAddress was registered.
entrytype(registry_entry)outoptionalRemoved entry.

Call graph

registry_lookup ​

Look an allocation up.

fortran
subroutine registry_lookup(addr, found, entry)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inBase address.
foundlogicaloutAddress is registered.
entrytype(registry_entry)outoptionalEntry.

Call graph

registry_lookup_range ​

Look up the allocation containing the range [addr, addr+bytes): the whole buffer (exact hash lookup) or a part of it (binary search of the sorted base addresses). A range that starts inside an allocation but ends beyond it is not found and sets overflow.

fortran
subroutine registry_lookup_range(addr, bytes, found, entry, overflow)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inStart address of the range.
bytesinteger(kind=I8P)inSize of the range [bytes].
foundlogicaloutThe range lies inside a registered allocation.
entrytype(registry_entry)outoptionalEntry of the containing allocation.
overflowlogicaloutoptionalThe range starts inside an allocation but ends beyond it.

Call graph

registry_stats ​

Return the number and the bytes of live allocations, optionally only those on one device.

fortran
subroutine registry_stats(allocs, bytes, dev_id)

Arguments

NameTypeIntentAttributesDescription
allocsinteger(kind=I8P)outoptionalNumber of live allocations.
bytesinteger(kind=I8P)outoptionalBytes of live allocations.
dev_idinteger(kind=I4P)inoptionalCount only allocations on this device.

Call graph

registry_report ​

Write the live allocations (address, bytes, device, label), one per line in ascending address order, followed by a summary line.

fortran
subroutine registry_report(unit)

Arguments

NameTypeIntentAttributesDescription
unitinteger(kind=I4P)inoptionalOutput unit (default standard output).

Call graph

registry_clear ​

Forget every allocation (without freeing any memory) and reset the totals. Meant for tests.

fortran
subroutine registry_clear()

dev_set_registry_policy ​

Set the registry policy: 'off', 'warn' or 'error' (case insensitive). It overrides FUNDAL_REGISTRY.

fortran
subroutine dev_set_registry_policy(policy, ierr)

Arguments

NameTypeIntentAttributesDescription
policycharacter(len=*)inPolicy name.
ierrinteger(kind=I4P)outoptionalError status: 1 if the name is not valid (policy unchanged).

Call graph

registry_misuse ​

Report a misuse according to the policy: error stop with policy error, warning on stderr with policy warn (followed by the action taken, the caller then proceeds), nothing with policy off.

fortran
subroutine registry_misuse(msg, action)

Arguments

NameTypeIntentAttributesDescription
msgcharacter(len=*)inDescription of the misuse.
actioncharacter(len=*)inWhat is done anyway under policy warn.

Call graph

set_policy ​

Set the policy from its name, leaving it unchanged if the name is not valid.

fortran
subroutine set_policy(name, valid)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inPolicy name.
validlogicaloutoptionalValid name.

Call graph

totals_update ​

Update the live totals (mirrored in fundal_env).

fortran
subroutine totals_update(dn, db)

Arguments

NameTypeIntentAttributesDescription
dninteger(kind=I8P)inAllocations increment.
dbinteger(kind=I8P)inBytes increment.

Call graph

sorted_insert ​

Insert a new base address in the sorted list (called before used is incremented).

fortran
subroutine sorted_insert(addr)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inAddress.

Call graph

sorted_remove ​

Remove a base address from the sorted list (called before used is decremented).

fortran
subroutine sorted_remove(addr)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inAddress.

Call graph

table_init ​

Allocate an empty table.

fortran
subroutine table_init(capacity)

Arguments

NameTypeIntentAttributesDescription
capacityinteger(kind=I8P)inNumber of slots (power of 2).

Call graph

table_find ​

Find the slot of an address, or the empty slot where it would be inserted.

fortran
subroutine table_find(addr, slot, found)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inAddress.
slotinteger(kind=I8P)outSlot.
foundlogicaloutAddress present.

Call graph

table_delete ​

Empty a slot with backward-shift deletion, so that no tombstones are needed: entries of the following cluster that may move closer to their home slot are shifted into the hole.

fortran
subroutine table_delete(slot)

Arguments

NameTypeIntentAttributesDescription
slotinteger(kind=I8P)inSlot to empty.

Call graph

table_resize ​

Rehash every entry into a table of the given capacity.

fortran
subroutine table_resize(capacity)

Arguments

NameTypeIntentAttributesDescription
capacityinteger(kind=I8P)inNew number of slots (power of 2).

Call graph

Functions ​

registry_address ​

Return the address held by a C pointer as an integer key.

Returns: integer(kind=c_intptr_t)

fortran
function registry_address(cptr) result(addr)

Arguments

NameTypeIntentAttributesDescription
cptrtype(c_ptr)inC pointer.

Call graph

registry_policy ​

Return the registry policy; on first use it is read from the environment variable FUNDAL_REGISTRY (off, warn or error; default warn) unless already set by dev_set_registry_policy.

Returns: integer(kind=I4P)

fortran
function registry_policy() result(policy)

Call graph

home_slot ​

Return the home slot of an address: shift-xor mixing (no multiplication, so no integer overflow) of the address, whose low bits are zero for aligned device buffers, reduced modulo the power-of-2 capacity.

Attributes: pure

Returns: integer(kind=I8P)

fortran
function home_slot(addr, capacity) result(slot)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inAddress.
capacityinteger(kind=I8P)inNumber of slots (power of 2).

Call graph

sorted_position ​

Return the position of the first sorted base address >= addr (used + 1 if none), by binary search.

Attributes: pure

Returns: integer(kind=I8P)

fortran
function sorted_position(addr) result(pos)

Arguments

NameTypeIntentAttributesDescription
addrinteger(kind=c_intptr_t)inAddress.

Call graph