What This Visualizes This simulator models a simplified training input pipeline as three stages: Data loading into a CPU-side prefetch queue (often pinned host memory). Host-to-device transfer into a GPU-side VRAM backlog queue. GPU compute consuming queued batches. Each stage has a throughput and each queue has a capacity. The key idea is that memory pressure is created by mismatch between rates…
Recently, construction started at a park near my home. It has presented me with a unique opportunity to observe the intricacies of a construction site up close. Having majored in urban planning, I find it especially enlightening to witness these procedures firsthand. Just today, I noticed a new addition to the site – straw wattles. They were installed along the edges. A shallow trench was dug…
Luckily, I have never had to use fork() in my everyday work. Otherwise, I guess I would produce 10x more bugs. Here is an example why I think so. In a nutshell, fork() creates a child process who copies the parent’s current status, including the instruction pointer, data/stack/heap space and etc. Here’s a short example. // test.c #include <stdio.h> #include <unistd.h> int main () { int x = 42 ; if…
I did some fun combinatorial exercises to reach an optimal O(n) solution for an “easy” level leetcode problem (LeetCode 1588) . Look at the problem and think for 5 minutes. It is relatively easy to reach this approach: For each element \(a_i\), if you can find the count of odd-length sub-arrays containing it, denoted as \(n_i\), the sum of all odd-length sub-arrays will be equal to \(\sum a_i…
Can we implement duck typing in Java without using reflection? Consider there are 2 classes defined by an external library that is out of our control. class Duck { void swim () {...} } class Whale { void swim () {...} } We cannot do below. Stream . of ( new Duck (), new Whale ()). forEach ( obj -> { obj . swim (); // Compilation error since obj is of type `Object` which has no swim() method });…
Our newborn son just arrived in the early morning on July 26, Sunday. My wife and I decided to name him “Luke”. According to Wikipedia , The name Luke is the English form of the Latin name Lucas. It is derived from the Latin name Lucius, and it either means “the great Lucius”, or it is a shortened form of the Latin name. Lucius means “the bright one” or “the one born at dawn” Meanwhile, Luke is…
The official documentation of Java claims that the first argument of T Stream::reduce(T identity, BinaryOperator<T> accumulator) must be an identity. The identity value must be an identity for the accumulator function. This means that for all t, accumulator.apply(identity, t) is equal to t. The accumulator function must be an associative function. Stream::reduce works almost identically to foldl…
I discovered the following trick. from functools import partial curry = lambda n : partial ( * [ partial ] * n ) Usage: @ curry ( 3 ) def add ( x , y , z ): return x + y + z print ( add ( 2 )( 3 )( 4 )) # output = 9 A more obfuscated way will be: from functools import partial curry = lambda f : partial ( * [ partial ] * f . __code__ . co_argcount )( f ) Usage @ curry def add ( x , y , z ): return…