Syllabus Lesson 117 of 246 · Module 10: Networks that see (CNNs)
Module 10: Networks that see (CNNs)

Why the same maths can run several times faster

Why it matters This course runs on any laptop with no graphics card. That works because a matrix multiply can be done slowly or very fast on the same CPU, and the course uses the fast way.

A matrix multiply of an (n, k) by a (k, m) matrix costs about 2 times n times k times m floating-point operations (FLOPs). Libraries called BLAS do it in carefully tuned code that keeps the numbers in the CPU's fastest memory and uses its vector instructions. In this browser's Python, plain NumPy multiplies without such a library; the course's nnsim.engine.mm routes through SciPy's BLAS instead, which measured 2 to 5 times faster in the browser in the course's own tests. On a laptop's ordinary Python, NumPy already uses a tuned BLAS, so mm is no faster there and can be slower (about 0.4 times the speed of @ in one test): the speedup is a fact about this browser, not about the maths.

Divide FLOPs by seconds to get speed in FLOPs per second. That one number, together with the FLOP Ledger, lets you predict how long any training run will take before you start it.

BLAS: Basic Linear Algebra Subprograms, the standard fast routines for vector and matrix maths.

Words and symbols in this lesson
BLAS, GFLOP/s
fast standard maths routines; billions of operations per second
Your turn

Write flops(n, k, m) and gflops_per_s(n, k, m, seconds). Then run the timing and set my_speedup to how many times faster mm was than @ here (any honest measured value; it depends on the machine).

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.