Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
  • Prompting13
  • Trust and Verification14
  • Using AI for Engineering Work17
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
    • Cost Arithmetic
    • Latency and Throughput
    • Reducing Tokens
      • Prefix Caching
      • Summarisation and Information Loss
      • Retrieval Instead of Pasting
      • Trimming Logs and RTL
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

‹Reducing Tokens
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Tokens, Cost and Latency
  4. Reducing Tokens
  5. Trimming Logs and RTL

Reference: Tokens, Cost and Latency · Beginner to Intermediate

Trimming Logs and RTL

Keep the failing slice of logs and RTL, and weigh token cost against answer quality.

On this page

    Trim a log to its slice

    A failing run hides in a window around the first error. Passing heartbeats before and after add tokens without adding signal.

    The trimmer below keeps flagged lines plus 3 lines before and 5 after. On a 40-line toy log with flagged lines at 28 and 29, it keeps lines 25 to 34: 10 of 40 lines.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    import sys
    
    ERR = (28, 29)
    
    def build_log():
        lines = []
        for i in range(40):
            if i in ERR:
                lines.append(f"{i:04d} ERROR dma timeout on channel {i - 27}")
            elif i % 9 == 4:
                lines.append(f"{i:04d} WARN temperature {70 + i} C")
            else:
                lines.append(f"{i:04d} INFO heartbeat ok")
        return lines
    
    def trim(lines, before=3, after=5):
        keep = set()
        for i, ln in enumerate(lines):
            if "ERROR" in ln:
                for j in range(i - before, i + after + 1):
                    if 0 <= j < len(lines):
                        keep.add(j)
        return sorted(keep)
    
    def main():
        lines = build_log()
        kept = trim(lines)
        bad = 0
        if len(lines) != 40:
            bad += 1
        if kept != list(range(25, 35)):
            bad += 1
        if not all(i in kept for i in ERR):
            bad += 1
        if not (len(kept) < len(lines)):
            bad += 1
        if bad == 0:
            print(f"PASS: kept {len(kept)} of {len(lines)} lines around {len(ERR)} flagged lines")
        else:
            print(f"FAIL: {bad} checks wrong")
            sys.exit(1)
    
    main()

    Trim RTL to its slice

    The same rule applies to source context. Send the failing module with its interfaces, and drop unrelated blocks even when they feel relevant.

    Keep for a DMA timeout debug

    Drop for now

    The DMA channel module under suspicion

    Unrelated peripherals and their drivers.

    Interface definitions it instantiates

    Full commit history of the block.

    The constraint snippet driving the failing case

    Passing testbenches from other blocks.

    Trimming never justifies sending secrets or keys, or sending proprietary IP to a deployment not approved for it. Redact first, and treat log text as untrusted data that may carry injected instructions.

    Cost against answer quality

    Assume about 10 tokens per log line and 3 units per million input tokens as stated EXAMPLE figures. A 20000-line log then costs 0.6 units, while its 200-line slice costs 0.006 units.

    plaintext
    1
    2
    3
    4
    5
    6
    7
    8
    9
    EXAMPLE rule: about 10 tokens per log line
    full log: 20000 lines x 10 = 200000 tokens
    slice: 200 lines x 10 = 2000 tokens
    ratio = 200000 / 2000 = 100, so 100:1
    EXAMPLE rate: 3 units per million input tokens
    full cost = 200000 x 3 / 1000000 = 600000 / 1000000 = 0.6 units
    slice cost = 2000 x 3 / 1000000 = 6000 / 1000000 = 0.006 units
    budget split example: instructions 10% + chunks 30% + slice 40% + output 20%
    check: 10 + 30 + 40 + 20 = 100

    Budget share

    Spends tokens on

    If it grows too far

    Instructions, 10%

    Role, schema and the current question

    Repeated boilerplate crowds out evidence.

    Retrieved chunks, 30%

    Top-ranked background

    Low-ranked chunks dilute the prompt.

    Failing slice, 40%

    Log window and RTL under debug

    Wider windows regress toward the full dump.

    Output allowance, 20%

    Room for the answer itself

    Starved answers truncate before the verdict.

    Common mistakes

    Common pitfall

    A tight window can cut the error it was meant to frame. Always confirm the flagged lines survived the trim before sending.

    Common pitfall

    Sending the whole repository to avoid choosing feels thorough but buys mostly surplus. Quality effects vary by model, so compare trimmed and full prompts by measurement on local tasks.

    Interview

    Likely probes: the trim rule and the tradeoff.

    • Keep flagged lines plus a stated margin, and verify the flags survived.

    • The worked trim above is 100:1 under its stated EXAMPLE figures.

    • Cheaper prompts win only when answer quality holds, which is measured per task.

    Check yourself The toy keeps lines 25 to 34 for flagged lines at 28 and 29. Which margins produce that window?

    Three lines before the first flag and five lines after the last flag: 28 minus 3 is 25, and 29 plus 5 is 34.

    Check yourself Under the stated EXAMPLE figures, what does the full 20000-line log cost versus its 200-line slice?

    The full log costs 0.6 units and the slice costs 0.006 units, a 100:1 ratio.

    Related topics

    • Prefix caching

    • Debugging with AI

    • Data, privacy and IP

    Previous

    142 / 173

    Next: Agentic Workflows for Chip Teams

    Up next

    Up nextAgentic Workflows for Chip Teams

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Prefix Caching
    • Summarisation and Information Loss