Sub-chapter 6.9

Hardware & Frameworks

The silicon and software that turn equations into intelligence — from a single CPU thread to a rack of TPUs orchestrating a trillion-parameter model.

22 min read Beginner — Intermediate 2 interactive demos 4 quiz questions

Why Hardware Suddenly Matters

For decades, civil engineers got along with a single workstation, a copy of STAAD or ETABS, and a printer. Modern AI broke that model. Training a deep network is not a few thousand FLOPs — it is quintillions. The reason AI feels “new” isn’t a single mathematical breakthrough; it is the collision of three trends: bigger datasets, deeper architectures, and the rise of massively parallel silicon. This chapter is your tour of that silicon and the software stack that drives it.

One sentence summary

Neural networks are mostly matrix multiplications, and matrix multiplications are embarrassingly parallel — that is exactly what GPUs, TPUs, and NPUs were designed to do faster than any CPU ever could.

CE Analogy — Choosing Construction Equipment

Picking a processor for an AI job is exactly like picking heavy equipment for a job site. None of these are “better” in the abstract — they are tuned for a specific kind of work:

  • CPU — a versatile excavator. It can dig, lift, demolish, and pivot. Slow at any single repetitive task, but unmatched at varied work and decision making (data prep, control flow, OS calls).
  • GPU — a fleet of 5,000 dump trucks rolling in lock-step. Useless if your job has one truckload of dirt; devastatingly fast if you have a million.
  • TPU — a custom tunnel-boring machine. It does one thing — tensor multiplication — better than anything else, but it cannot back out and dig a foundation.
  • NPU — a battery-powered jackhammer. Tiny, low-power, fits in your pocket (literally — it is in your phone). Perfect for on-device inference.

The Silicon Family Tree

Modern AI workloads run on four broad classes of processors. Each evolved for a different bottleneck.

CPU

Central Processing Unit

  • 8–32 powerful cores
  • Large multi-MB caches
  • Branch prediction, OOO execution
  • Best for: data prep, I/O, control logic, tiny models

GPU

Graphics Processing Unit

  • 5,000–18,000 CUDA cores
  • Massive SIMD parallelism
  • HBM / GDDR memory, >1 TB/s
  • Best for: training and inference of NNs

TPU

Tensor Processing Unit

  • Custom matrix-multiply ASIC (Google)
  • Systolic arrays of MAC units
  • Huge HBM bandwidth, BF16 native
  • Best for: large-scale training on GCP

NPU

Neural Processing Unit

  • Apple Neural Engine, Qualcomm Hexagon
  • Quantized INT8 inference
  • Watts, not kilowatts
  • Best for: on-device inference (phones, IoT)
Rule of thumb. If your job is mostly matmul on tensors that fit in VRAM, the GPU wins. If it is mostly Python loops, the CPU wins. If you have access to a Google Cloud TPU pod, a TPU wins for training. If your model needs to run inside a phone, an NPU wins.

Quick comparison

Feature CPU GPU TPU v4 NPU (mobile)
Cores / units 8–64 5,000–18,000 ~32k MACs ~16 cores
Peak FP16 TFLOPs 1–5 100–1000+ 275 5–30
Memory bandwidth 50–100 GB/s 500–3000 GB/s 1.2 TB/s 20–100 GB/s
Power draw 65–250 W 200–700 W 200 W (chip) 1–5 W
Strength Flexibility Throughput Matmul density Energy efficiency

Demo 1 — CPU vs GPU Matrix Race

A neural network forward pass is essentially many matrix multiplications. Below, two simulated processors race on the same $N \times N$ matmul. The CPU is a single worker walking cell-by-cell. The GPU is a grid of 64 workers each computing a tile in parallel. Watch how the GPU’s lead grows as $N$ increases — that compounding advantage is exactly why all of modern AI runs on GPUs.

Matrix multiplication race

CPU — 1 worker 0.000 s
0% 0 ops/sec
GPU — 64 workers 0.000 s
0% 0 ops/sec
Why the gap widens with $N$. CPU work scales like $N^3$ on one core. GPU work also scales like $N^3$, but divided across thousands of cores. As $N$ doubles, the CPU does $8\times$ more work; the GPU still finishes in roughly the same wall-clock time until you exhaust its parallelism.

VRAM — the Real Bottleneck

Beginners assume the limit on training big models is FLOPs. It is not. The limit is memory. A model has to fit in VRAM together with its activations, optimizer states, and gradients.

The math of fitting a 70B model

With a 70B-parameter model in FP32 you need:

  • Weights: $70 \times 10^9 \times 4 = 280$ GB
  • Adam optimizer states: another $\sim 560$ GB
  • Activations & gradients: another $\sim 200$ GB

That is over 1 TB of fast memory. A consumer RTX 4090 has 24 GB. This is why training frontier models requires data-center GPUs (H100, 80 GB) and many of them, with mixed precision and sharding tricks just to make the math close.

Mixed precision — the free 2×

Storing weights as 16-bit floats instead of 32-bit halves memory and roughly doubles throughput on modern tensor cores, with no measurable loss in final accuracy on most networks. BF16 (Brain Float 16) preserves the FP32 exponent range, which avoids the gradient-underflow issues older FP16 training had. In 2026 it is essentially the default.

mixed_precision.py PyTorch
from torch.cuda.amp import autocast, GradScaler

scaler = GradScaler()
for x, y in loader:
    optimizer.zero_grad()
    with autocast(dtype=torch.bfloat16):
        out = model(x)
        loss = criterion(out, y)
    scaler.scale(loss).backward()
    scaler.step(optimizer)
    scaler.update()

Tensor cores

From Volta (2017) onward, NVIDIA GPUs ship dedicated tensor cores that compute a $4 \times 4$ matrix multiply-accumulate in one cycle at FP16/BF16. This is where the 100× speedups in CNN/Transformer training come from. AMD and Intel have followed with similar units (Matrix Cores, XMX).

Distributed Training Strategies

Once a single GPU is saturated, you scale across many. There are four canonical strategies; large models combine them.

Data parallel

Replicate the whole model on every GPU. Each gets a different mini-batch. Gradients are averaged via all-reduce. Simplest, best for small-to-medium models.

Model parallel

Split the model itself across GPUs (e.g., layer 1–10 on GPU 0, 11–20 on GPU 1). Required when no single GPU can hold the model.

Pipeline parallel

Like an assembly line: GPU 0 processes batch 1 layer 1 while GPU 1 processes batch 0 layer 2. Reduces idle bubbles.

ZeRO sharding

DeepSpeed’s trick: shard optimizer states, gradients, and parameters across GPUs so each holds only $1/N$ of the model. Enables 1T-parameter training on modest clusters.

CE Analogy — A skyscraper construction crew

Data parallel is 10 identical crews each building a clone of the same building, then comparing notes. Model parallel is one crew per floor of one tall building. Pipeline parallel is a crew per trade (electrical, plumbing, drywall) cycling through floors. ZeRO is when the toolbox itself is split — nobody owns all the wrenches; they pass them around as needed.

The Framework Landscape

Hardware needs software. Three frameworks dominate research and production in 2026, surrounded by a constellation of high-level wrappers.

PyTorch

Meta · dominant in research

  • Dynamic (eager) graphs — debug like Python
  • Pythonic, intuitive API
  • torch.compile for graph capture
  • Strong production story since 2.0

TensorFlow / Keras

Google · production king

  • Keras high-level API (now multi-backend)
  • TF Serving, TFLite, TF.js for deployment
  • Strong on TPUs and mobile
  • TF2 added eager mode

JAX

Google Research · rising fast

  • Functional, NumPy-like
  • jit, grad, vmap, pmap
  • Best-in-class TPU support
  • Used by DeepMind, many LLM labs

Higher-level wrappers

PyTorch Lightning

Removes the training loop boilerplate. Multi-GPU with one flag.

HuggingFace Transformers

Pretrained models for NLP, vision, audio. Two-line inference.

Diffusers

Stable Diffusion and friends — a unified API for diffusion models.

Demo 2 — Same MLP, Three Frameworks

Below is the same task — define a 3-layer MLP and train one epoch — in PyTorch, TensorFlow/Keras, and JAX. Use the toggle to highlight equivalent operations across all three. The shapes of the syntax differ; the underlying math is identical.

Framework code compare

pytorch_mlp.py PyTorch 2.x
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset

# --- model ---
class MLP(nn.Module):
    def __init__(self):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(784, 128), nn.ReLU(),
            nn.Linear(128, 64),  nn.ReLU(),
            nn.Linear(64, 10)
        )
    def forward(self, x):
        return self.net(x)
model = MLP().cuda()

# --- loss ---
criterion = nn.CrossEntropyLoss()

# --- optimizer ---
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)

loader = DataLoader(TensorDataset(X, y), batch_size=64, shuffle=True)

# --- training step ---
for xb, yb in loader:
    xb, yb = xb.cuda(), yb.cuda()
    optimizer.zero_grad()
    out  = model(xb)
    loss = criterion(out, yb)
    loss.backward()
    optimizer.step()
tf_mlp.py TensorFlow 2 / Keras
import tensorflow as tf
from tensorflow import keras

# --- model ---
model = keras.Sequential([
    keras.layers.Dense(128, activation='relu', input_shape=(784,)),
    keras.layers.Dense(64,  activation='relu'),
    keras.layers.Dense(10)
])

# --- loss ---
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)

# --- optimizer ---
optimizer = keras.optimizers.Adam(learning_rate=1e-3)

model.compile(optimizer=optimizer, loss=loss_fn, metrics=['accuracy'])

# --- training step ---
model.fit(X, y, batch_size=64, epochs=1)

# Or, written as an explicit step:
# with tf.GradientTape() as tape:
#     out  = model(xb, training=True)
#     loss = loss_fn(yb, out)
# grads = tape.gradient(loss, model.trainable_variables)
# optimizer.apply_gradients(zip(grads, model.trainable_variables))
jax_mlp.py JAX + Flax + Optax
import jax, jax.numpy as jnp
import flax.linen as nn
import optax

# --- model ---
class MLP(nn.Module):
    @nn.compact
    def __call__(self, x):
        x = nn.relu(nn.Dense(128)(x))
        x = nn.relu(nn.Dense(64)(x))
        return nn.Dense(10)(x)

model  = MLP()
params = model.init(jax.random.PRNGKey(0), jnp.ones([1,784]))

# --- loss ---
def loss_fn(params, xb, yb):
    logits = model.apply(params, xb)
    return optax.softmax_cross_entropy_with_integer_labels(logits, yb).mean()

# --- optimizer ---
tx       = optax.adam(1e-3)
opt_state = tx.init(params)

# --- training step ---
@jax.jit
def step(params, opt_state, xb, yb):
    grads = jax.grad(loss_fn)(params, xb, yb)
    updates, opt_state = tx.update(grads, opt_state)
    params = optax.apply_updates(params, updates)
    return params, opt_state

for xb, yb in batches:
    params, opt_state = step(params, opt_state, xb, yb)
Same math, different ergonomics. PyTorch lets you step through training imperatively. Keras hides the loop entirely. JAX makes you write a pure function and then JIT-compiles the whole thing for the accelerator. Pick based on team taste, not capability.

ONNX & Edge Deployment

Training is one thing; shipping the model is another. You rarely deploy raw PyTorch into a phone or a microcontroller. Instead you convert it to a portable runtime.

ONNX

Open Neural Network eXchange. A vendor-neutral graph format. Train in PyTorch, export model.onnx, run it with ONNX Runtime on Windows, Linux, mobile, browser, or even NVIDIA TensorRT.

TFLite

TensorFlow’s mobile/embedded runtime. Quantizes models to INT8 for $\sim 4\times$ size reduction. Powers most Android ML features.

CoreML

Apple’s on-device format. Targets the Neural Engine directly. Used by every “magic” feature in iOS.

TensorRT

NVIDIA’s inference compiler. Fuses ops, picks kernels, quantizes — routinely 2–5× faster than vanilla PyTorch on the same GPU.

Cost Reality Check

The headlines about AI training costs are real, but they describe a tiny slice of the work that gets done.

Frontier scale

  • GPT-3 training: ~$5M of GPU-hours
  • GPT-4 class: estimated $50–100M+
  • Multi-thousand H100 clusters, weeks of training

What you actually need

  • One $1,000 RTX 4070/4080 trains 99% of CE-relevant models
  • Free: Google Colab, Kaggle, Lightning AI Studios
  • $1–3/hour: rented A100/H100 on Lambda, RunPod, Vast.ai
  • Fine-tuning a 7B LLM on a single 24 GB card is routine
Practical path for a civil engineer. Start on Colab. Move to a $1,500 desktop with an RTX 4080 once your datasets exceed 10 GB or your training runs exceed 30 minutes. That covers concrete-strength models, structural anomaly detectors, and even modest computer-vision pipelines.

Civil Engineering Application

Practical GPU Setup for CE

Most CE deep learning tasks (material property prediction, small image classification) don't need expensive hardware. A single NVIDIA RTX 3060 (6GB VRAM) trains a concrete strength MLP in seconds and a crack detection CNN in 30 minutes. Google Colab's free tier is enough for getting started.

PyTorch for CE Research

PyTorch dominates CE research papers because its imperative style matches how engineers think — define the model, run data through it, check results, adjust. TensorFlow/Keras is fine too, but if you're reading recent CE-AI journal papers, they'll likely use PyTorch.

Quick Quiz

1. Why are GPUs faster than CPUs for training neural networks?

  • Because GPU cores run at higher clock speeds.
  • Because thousands of GPU cores can perform the parallel matrix multiplies in a layer simultaneously.
  • Because GPUs have more cache than CPUs.
  • Because GPUs use less memory than CPUs.
GPU cores are individually slower than CPU cores. Their win is sheer count: SIMD parallelism over thousands of cores maps perfectly to the matmul-heavy structure of NNs.

2. Mixed-precision training (BF16) gives you...

  • Better generalization but slower training.
  • Higher accuracy at the cost of memory.
  • Roughly 2× speedup and half the memory, with negligible accuracy loss.
  • A purely cosmetic change.
BF16 keeps FP32’s exponent range (avoiding underflow) while using half the bytes. Tensor cores handle BF16 natively at full throughput, so you essentially get a free 2×.

3. ZeRO sharding helps when...

  • Your model is small enough to fit on one GPU.
  • You want to run inference on a phone.
  • You only have CPUs.
  • The model + optimizer states are too large to fit on a single GPU and you need to spread them across many.
ZeRO partitions optimizer states, gradients, and parameters across GPUs so each holds only $1/N$, enabling training of models that no single device could hold.

4. Which framework is most associated with TPUs and functional programming with vmap / pmap?

  • PyTorch
  • JAX
  • scikit-learn
  • XGBoost
JAX is built around pure functions and transforms (jit, grad, vmap, pmap), and has first-class TPU support via XLA.

Key Takeaways

Match silicon to job

CPU = control. GPU = throughput. TPU = matmul density. NPU = on-device efficiency.

Memory is the real wall

Mixed precision and sharding exist because VRAM — not FLOPs — is the limit at scale.

Frameworks converge

PyTorch, TF/Keras, and JAX are now within shouting distance on features. Pick by team familiarity and deployment target.

You don’t need a datacenter

A modern consumer GPU plus a free Colab account is enough to do real, useful AI work in civil engineering.

Mini case study

GPUs & frameworks for AEC: NVIDIA Omniverse + Bentley iTwin digital twins

At GTC 2023 Bentley Systems and NVIDIA announced Bentley iTwin integration with Omniverse — live, photoreal 4D digital twins of bridges, plants and offshore platforms streaming straight from the iTwin cloud onto RTX workstations and H100/B200 servers. The interesting engineering choice is the framework stack: Bentley standardised on PyTorch + CUDA + Triton inference, abandoning the in-house C++ pipelines that dominated AEC tooling for three decades.

0H100 FP16 TFLOPS
0B200 FP16 throughput
0PyTorch share of AI papers
0H100 vs V100 LLM speedup

A live offshore-platform digital twin has to render 30 FPS of photoreal geometry and run live AI inferences (corrosion segmentation, crack detection, anomaly detection on SCADA) on the same workstation. That requires shared GPU memory, async kernel scheduling, and a deep-learning framework that interoperates with USD (Universal Scene Description) — the data model Omniverse is built on.

“The framework that wins AEC is the one the GPU vendor already optimised.”

  • Inference on Triton. NVIDIA Triton Inference Server hosts the AEC AI models (crack U-Net, corrosion seg) and serves predictions to the Omniverse renderer over gRPC.
  • PyTorch + TorchScript for training, ONNX export, TensorRT for the deployed graph — the standard NVIDIA inference pipeline.
  • Mixed precision (FP16/BF16) on H100 Tensor Cores yields the bulk of the speed-up vs FP32 on older GPUs.
NVIDIA datacentre GPUs across the deep-learning era (click to sort)
GPUYearFP16 TFLOPSHBM (GB)Notes
V100201712532First Tensor Cores
A100202031280BF16, MIG partitioning
H100202298980Transformer Engine, FP8
H2002024989141Same compute, 1.7× memory
B20020252500192Blackwell, dual-die

FP16 throughput roughly doubles every generation; memory has lagged compute — which is why CE workloads with large mesh tensors love H200/B200.

  • Real-time AEC digital twins — geometry + AI inference share the same RTX workstation without dropping below 30 FPS.
  • Cross-platform reuse — the same PyTorch checkpoint runs on a laptop RTX, a workstation, and an H100 cluster.
  • AEC SDK adoption — Autodesk, Bentley, Hexagon and Trimble all now ship Omniverse / USD connectors.
  • PyTorch + CUDA is the safe default for AEC ML in 2025; TensorFlow share has collapsed outside Google.
  • Memory matters as much as TFLOPS for engineering meshes — H200 > H100 for the same kernel set.
  • Inference servers (Triton) decouple ML from the renderer — the AEC tool stays a thin client.