Unit 6 of 12 · about 3 hours · derive

Memory layout, strides and alignment, and fusion against intermediate traffic

Build on SwiGLU MLP and epilogue fusion boundaries and the earlier KV layout work. A serving optimization must include conversion and dispatch costs, not just the traffic of a convenient contiguous benchmark.

You'll be able to

  • Derive physical addresses from strides, storage offsets and element sizes for serving views.
  • Count intermediate traffic removed by a legal fusion while retaining required residual outputs.
  • Choose a fusion boundary that preserves reduction ownership, cast points and supported layouts.

Covers

Memory layout, strides and alignmentOperator fusion and intermediate traffic
1

Read

In this order, only the parts listed

0 of 3 done

  1. Physical KV layoutsFlashInfer Documentation

    FlashInfer documentation: Layout: NHD/HND and Page Table Layout (page read 2026-10-14, release 0.7.1)

    Skip MLA and cascade layouts. Use plan/run from the current API instead of the tutorial's older begin_forward example.

  2. Sparse gathers and fusion, arXiv:2501.01005v1FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving

    Sections 3.2.1 and 3.2.3, data movement and transformation functors; Section 4.3, fused versus unfused RoPE evaluation

    Read Section 4.3 for its comparison boundary, not the source's hardware-specific speedup as an expected result.

  3. Outputs that fusion must retainFlashInfer Documentation

    Step 1 and Step 2 of fused_add_rmsnorm (page read 2026-10-14, release 0.7.1)

2

Focus on

  • With element strides , storage offset and element size , byte address is , where is the storage base. Alignment depends on the resulting address, not just allocation alignment.
  • A transpose view changes strides without moving data. Making it contiguous performs a copy; include that read/write traffic and allocation when deployment needs it.
  • For a materialized intermediate with elements of bytes, removing one write and one read saves requested bytes. That is not a measurement of DRAM traffic after caches.
  • Residual fusion still writes the retained sum and normalized activation. A full-row norm cannot generally be fused into one projection tile without coordinating the row reduction.
Common mistakes · 3
  • Assuming a view's last dimension is contiguous because the original tensor was contiguous.
  • Counting a retained residual write as removed traffic. It is part of the output contract.
  • Treating fewer launches as proof of lower latency. Larger fusion can increase register pressure, spills or padding.
3

Try it yourself

Closed-book, before checking anything

On CPU, construct torch.arange(24, dtype=torch.float32).reshape(4, 6)[:, 1::2]. Derive shape [4, 3], element strides [6, 2] and storage offset 1, then verify every element by independent indexing. Explain why this view loses 16-byte base alignment despite an aligned storage allocation. For a hypothetical one-pass residual-add plus norm with both outputs required, derive vector bytes for separate add and norm versus for fusion: two input reads, two output writes and one eliminated reread. State that weights, statistics, repeated loads and cache effects are excluded.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Does changing an NHD tensor's layout label create HND storage?Answer

    No. The consumer needs matching dimensions and strides. A real contiguous conversion moves data; a view may be supported only if the kernel accepts its strides.

  2. 2.Why is the fused residual example saving only one vector read?Answer

    The sum must remain as a residual output. Fusion removes normalization's reread of that sum, but not its write.

  3. 3.Can nominal saved bytes predict speedup by themselves?Answer

    No. Cache filtering, transaction utilization, launch costs and resource changes determine actual time. The ledger gives a hypothesis to measure.

You're done when

Your address calculation matches the strided view, and your fusion diagram accounts for every required read, write, conversion and reduction boundary.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 12 more in the section
  • FlashInfer: Efficient and Customizable Attention Engine for LLM Inference ServingFlashInfer Project · primary

    Read the storage heterogeneity, plan and run separation, load-balanced scheduling, customization, CUDA Graph compatibility and end-to-end evaluation. Use it to connect serving-shaped attention kernels to dynamic workloads and dispatch constraints.

  • FlashInfer DocumentationFlashInfer Project · required

    Use the current attention, PageAttention, sampling, JIT and CUDA Graph interfaces while implementing. Pin the version and supported GPU architecture, and validate dispatch and fallback over the real workload shape distribution.

Also in this section