Maybe trigger a garbage collection.
(vl-gc) → nil
In the logic vl-gc just returns nil. On CCL, its raw
Lisp definition, it may (or may not) trigger a garbage collection. On other
Lisps, it just does nothing.
Throughout VL, we call vl-gc at "good" places to do garbage
collection. We typically call it right after computations that allocate a lot
of "temporary" memory—memory that will be garbage once the computation
has finished. A GC at this time may be cheaper than a GC later, when we just
happen to run out of memory, because GC costs are basically proportional to the
number of live objects.
Running vl-gc only sometimes triggers a GC. Why? We sometimes use VL
to process large designs (hundreds of thousands of lines of Verilog), and
sometimes use it on much smaller designs. Depending on the kind of input, we
probably want to use different GC strategies:
- When we process large designs, each transformation naturally allocates more
memory. Some transforms might allocate hundreds of megabytes or gigabytes of
memory. In this case, we would like to GC more frequently in order to keep our
memory usage down.
- When we deal with small designs, nothing is very expensive. We probably
have ample memory to process the whole design without any garbage collection.
In this case, we would like to avoid GC altogether to maximize
vl-gc is meant to work well with either scenario. Basically, after
triggering a GC, vl-gc records how much memory are allocated. This gives
us a rough baseline of how much memory the rest of the program is using. Then,
each time vl-gc is called, it compares the current memory usage to this
baseline. A GC is only triggered if the new memory usage exceeds the baseline
by some threshold (e.g., 1 GB).
Here's how this works under either scenario.
- When we process a large design, our transforms are consuming memory quite
quickly, so the vl-gc calls throughout our program end up causing many
GCs. These GCs occur at good places (the places where we called vl-gc,
and keep our memory usage down, as desired.
- When we process a small design, our transforms don't use much memory so
when we call vl-gc, we haven't exceeded the threshold. So, we don't waste
our time collecting this insignificant garbage, as desired.
Definitions and Theorems
(defun vl-gc nil
(declare (xargs :guard t))
(let ((__function__ 'vl-gc))
(declare (ignorable __function__))
(raise "Under-the-hood definition not installed?")))
- Instruct vl-gc to trigger a garbage collection when the
current memory usage exceeds the baseline by some amount.
- Resets the baseline for vl-gc to however much memory is