[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AVQ7QKS2300W5FSZ4P17HM":3,"skill-same:01M7AVQ7QKS2300W5FSZ4P17HM":61},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":29,"updatedAt":30,"install":31,"resources":44},"01M7AVQ7QKS2300W5FSZ4P17HM","deepselect-topk-optimizer",null,"Optimize high-throughput TopK selection and DeepSeek Sparse Attention (DSA) workloads using randomized block scans, monotonic threshold filtering, denormal FP32 simulation, and Threadblock Clusters. Do not use for generic sorting or CPU-only arrays.","SpectreDeath\u002FBrain-Harness","SpectreDeath","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F207463416?v=4","01M7AVGR1D4X8ADT47APKGVH2Z","JL","01M7AVGR2HSGD23BA5DBTJJTVN",0,"MIT","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fdeepselect-topk-optimizer\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: deepselect-topk-optimizer\ndescription: Optimize high-throughput TopK selection and DeepSeek Sparse Attention (DSA) workloads using randomized block scans, monotonic threshold filtering, denormal FP32 simulation, and Threadblock Clusters. Do not use for generic sorting or CPU-only arrays.\n---\n\n# DeepSelect TopK Optimizer: High-Performance Kernel Architecture & DSA Routing\n\n`deepselect-topk-optimizer` provides domain engineering, performance bound estimation, hardware contention mitigation, and kernel dispatch configuration for high-performance TopK selection kernels derived from the DeepSeek Sparse Attention (DSA) architecture.\n\nSee [CARD.md](CARD.md) for the companion summary card, stage progression table, and invariants checklist.\nConsult [config.default.yaml](config.default.yaml) for baseline operational budgets and timeout thresholds.\n\n---\n\n## The 5-Stage TopK Optimization Lifecycle\n\n```\n[1. Workload Characterization & Stride Alignment]\n                       │\n                       ▼\n[2. Complexity Bound Estimation & Harmonic Calculus]\n                       │\n                       ▼\n[3. Hardware Contention Mitigation & ALU Planning]\n                       │\n                       ▼\n[4. Kernel Dispatch & Threadblock Cluster Sizing]\n                       │\n                       ▼\n[5. Monotonic Simulation & Verification Protocol]\n```\n\n---\n\n## 1. Workload Characterization & Stride Alignment\n\nAnalyze input tensor dimensions and hardware alignment requirements:\n- **Lightning Indexer Scenario**: `torch.bfloat16`, batch size $1 \\sim +\\infty$, vocab size $1 \\sim +\\infty$, small topk ($k \\le 4096$). Disable `sorted_index` unless index ordering is mandatory. Set `return_value=False` when values are not consumed (~10% throughput boost).\n- **Sampling Scenario**: `torch.float32`, vocab size around 128k, small topk ($k \\le 4096$).\n- **Stride Invariant**: Row stride of the input tensor must be aligned to `1024` bytes. Output strides must align to `32` bytes.\n\n---\n\n## 2. Complexity Bound Estimation & Harmonic Calculus\n\nEvaluate expected total elements processed across all in-loop TopK calls:\n- For input length $N$, block size $B$, and candidate compaction threshold $B_2$, define:\n  $$m = \\lceil N \u002F B \\rceil, \\quad L = k + B + B_2, \\quad H_m = \\sum_{i=1}^m \\frac{1}{i}$$\n- The expected total elements $W$ processed by RadixSelectTopK across the entire scan satisfies:\n  $$\\mathbb{E}[W] \\le \\left(1 + \\frac{k}{B_2}\\right) L H_m = O\\left(k \\log\\frac{N}{k}\\right) \\quad \\text{when } B, B_2 = \\Theta(k)$$\n- The compute complexity is completely decoupled from $N$ except logarithmically, ensuring uniform high memory bandwidth utilization.\n\n---\n\n## 3. Hardware Contention Mitigation & ALU Planning\n\nBypass CUDA Core instruction contention using low-level bit manipulation and IEEE-754 denormal emulation:\n- **Single-Pass Bitmask Accumulation**: Use PTX instructions (`set.s32.bf16x2`, `prmt.b32`, `dp4a.s32.s32`) to generate 32-bit boolean masks in registers during count pass. Traverse qualifying elements via hardware `__ffs(mask)` and `mask &= mask - 1u`, eliminating redundant memory passes.\n- **Denormal FP32 Simulated Addition**: For non-negative integer operands $x, y \\le 2^{22}$, integer addition is bitwise identical to floating-point addition on denormal numbers: `__float_as_uint(__uint_as_float(x) + __uint_as_float(y))`. DeepSelect uses this to bypass integer ALU contention with bitwise\u002Fcomparison instructions.\n\n---\n\n## 4. Kernel Dispatch & Threadblock Cluster Sizing\n\nMitigate wave quantization when batch sizes or active SM ratios are low:\n- When $\\text{batch\\_size} \u003C \\frac{\\text{active\\_SMs}}{2}$, enable Threadblock Clusters (`cluster_size = 16`).\n- Divide each sequence into segments across CTAs in the cluster; each CTA computes local TopK and streams candidates into CTA0 via distributed shared memory (DSMEM).\n- For large batch sizes ($\\ge \\text{active\\_SMs} \\times 2$), dispatch non-cluster variants (`cluster_size = 1`) to eliminate inter-CTA synchronization overhead.\n\n---\n\n## 5. Monotonic Simulation & Verification Protocol\n\nVerify selection accuracy and benchmark performance against standard baselines:\n- Execute python-level simulation of the randomized block scan, monotonic threshold filter, and shared-memory compaction.\n- Assert 100% TopK candidate parity with exact ground truth.\n- Verify that input row strides and output buffers adhere strictly to 1024-byte and 32-byte alignment invariants.\n\n---\n\n## The Three Foundational Pillars\n\n### 1. The Decoupled Complexity Bound Pillar\nCompaction work must scale as $O(k \\log(N\u002Fk))$ rather than $O(N \\log k)$. By reading global memory strictly once in contiguous blocks and maintaining a monotonic non-decreasing threshold $T$, later blocks rarely pass the filter.\n\n### 2. Hardware ALU Contention Elimination Pillar\nNever allow integer addition to bottleneck comparison-heavy kernels. Utilize denormal FP32 addition for values $\\le 2^{22}$ and single-pass PTX bitmasks to maximize SM execution pipe concurrency.\n\n### 3. Wave-Quantization Cluster Resilience Pillar\nNever allow GPU Streaming Multiprocessors to sit idle during tail execution waves. Partition small-batch sequences across Threadblock Clusters to sustain maximum occupancy.\n\n---\n\n## The Visual Brief Pillar\n\nWhen completing TopK selection benchmark runs or Sparse Attention (DSA) tuning sessions, synthesize throughput comparisons, denormal FP32 boundary test results, and Threadblock Cluster performance matrices into a standalone interactive HTML visual brief written to `%TEMP%\\deepselect-topk-\u003Ctimestamp>.html`. Render performance curves as inline SVG bar charts with P50\u002FP99 latency annotations.\n\n## Mandatory Checkpoint Gates\n\nBefore finalizing any TopK kernel implementation or DSA configuration:\n1. **Gate 1 (Correctness)**: Assert TopK selection results match reference brute-force output on all randomized test vectors (tolerance ≤ 1e-5).\n2. **Gate 2 (Denormal FP32 Guard)**: Assert zero denormal float inputs reach the hot selection loop (flush-to-zero confirmed).\n3. **Gate 3 (Timeout Bound)**: Assert no single benchmark run exceeds declared async timeout (≤ 5.0s per vector by default).\n\n---\n\n## Anti-Patterns\n\n- **Global Heap Exhaustion** — Inserting all elements of an N-element vector into a global priority queue or heap causing O(N log k) branch-divergent memory access.\n- **Two-Pass Filter Stall** — Reading global memory or registers twice for candidate counting and writing, doubling register pressure and stalling pipelines.\n- **Integer ALU Saturation** — Using integer multiply-add instructions when int ALU is saturated, delivering half the throughput of floating-point units.\n- **Single-CTA Sequence Confinement** — Forcing one threadblock to process an entire massive sequence alone while GPU SMs sit idle in the tail wave.\n- **Unbounded Float Denormal Emulation** — Applying denormal FP32 integer addition when operands exceed 2^22, triggering exponent overflow and data corruption.\n","# DeepSelect TopK Optimizer: High-Performance Kernel Architecture & DSA Routing\n\n`deepselect-topk-optimizer` provides domain engineering, performance bound estimation, hardware contention mitigation, and kernel dispatch configuration for high-performance TopK selection kernels derived from the DeepSeek Sparse Attention (DSA) architecture.\n\nSee [CARD.md](CARD.md) for the companion summary card, stage progression table, and invariants checklist.\nConsult [config.default.yaml](config.default.yaml) for baseline operational budgets and timeout thresholds.\n\n---\n\n## The 5-Stage TopK Optimization Lifecycle\n\n```\n[1. Workload Characterization & Stride Alignment]\n                       │\n                       ▼\n[2. Complexity Bound Estimation & Harmonic Calculus]\n                       │\n                       ▼\n[3. Hardware Contention Mitigation & ALU Planning]\n                       │\n                       ▼\n[4. Kernel Dispatch & Threadblock Cluster Sizing]\n                       │\n                       ▼\n[5. Monotonic Simulation & Verification Protocol]\n```\n\n---\n\n## 1. Workload Characterization & Stride Alignment\n\nAnalyze input tensor dimensions and hardware alignment requirements:\n- **Lightning Indexer Scenario**: `torch.bfloat16`, batch size $1 \\sim +\\infty$, vocab size $1 \\sim +\\infty$, small topk ($k \\le 4096$). Disable `sorted_index` unless index ordering is mandatory. Set `return_value=False` when values are not consumed (~10% throughput boost).\n- **Sampling Scenario**: `torch.float32`, vocab size around 128k, small topk ($k \\le 4096$).\n- **Stride Invariant**: Row stride of the input tensor must be aligned to `1024` bytes. Output strides must align to `32` bytes.\n\n---\n\n## 2. Complexity Bound Estimation & Harmonic Calculus\n\nEvaluate expected total elements processed across all in-loop TopK calls:\n- For input length $N$, block size $B$, and candidate compaction threshold $B_2$, define:\n  $$m = \\lceil N \u002F B \\rceil, \\quad L = k + B + B_2, \\quad H_m = \\sum_{i=1}^m \\frac{1}{i}$$\n- The expected total elements $W$ processed by RadixSelectTopK across the entire scan satisfies:\n  $$\\mathbb{E}[W] \\le \\left(1 + \\frac{k}{B_2}\\right) L H_m = O\\left(k \\log\\frac{N}{k}\\right) \\quad \\text{when } B, B_2 = \\Theta(k)$$\n- The compute complexity is completely decoupled from $N$ except logarithmically, ensuring uniform high memory bandwidth utilization.\n\n---\n\n## 3. Hardware Contention Mitigation & ALU Planning\n\nBypass CUDA Core instruction contention using low-level bit manipulation and IEEE-754 denormal emulation:\n- **Single-Pass Bitmask Accumulation**: Use PTX instructions (`set.s32.bf16x2`, `prmt.b32`, `dp4a.s32.s32`) to generate 32-bit boolean masks in registers during count pass. Traverse qualifying elements via hardware `__ffs(mask)` and `mask &= mask - 1u`, eliminating redundant memory passes.\n- **Denormal FP32 Simulated Addition**: For non-negative integer operands $x, y \\le 2^{22}$, integer addition is bitwise identical to floating-point addition on denormal numbers: `__float_as_uint(__uint_as_float(x) + __uint_as_float(y))`. DeepSelect uses this to bypass integer ALU contention with bitwise\u002Fcomparison instructions.\n\n---\n\n## 4. Kernel Dispatch & Threadblock Cluster Sizing\n\nMitigate wave quantization when batch sizes or active SM ratios are low:\n- When $\\text{batch\\_size} \u003C \\frac{\\text{active\\_SMs}}{2}$, enable Threadblock Clusters (`cluster_size = 16`).\n- Divide each sequence into segments across CTAs in the cluster; each CTA computes local TopK and streams candidates into CTA0 via distributed shared memory (DSMEM).\n- For large batch sizes ($\\ge \\text{active\\_SMs} \\times 2$), dispatch non-cluster variants (`cluster_size = 1`) to eliminate inter-CTA synchronization overhead.\n\n---\n\n## 5. Monotonic Simulation & Verification Protocol\n\nVerify selection accuracy and benchmark performance against standard baselines:\n- Execute python-level simulation of the randomized block scan, monotonic threshold filter, and shared-memory compaction.\n- Assert 100% TopK candidate parity with exact ground truth.\n- Verify that input row strides and output buffers adhere strictly to 1024-byte and 32-byte alignment invariants.\n\n---\n\n## The Three Foundational Pillars\n\n### 1. The Decoupled Complexity Bound Pillar\nCompaction work must scale as $O(k \\log(N\u002Fk))$ rather than $O(N \\log k)$. By reading global memory strictly once in contiguous blocks and maintaining a monotonic non-decreasing threshold $T$, later blocks rarely pass the filter.\n\n### 2. Hardware ALU Contention Elimination Pillar\nNever allow integer addition to bottleneck comparison-heavy kernels. Utilize denormal FP32 addition for values $\\le 2^{22}$ and single-pass PTX bitmasks to maximize SM execution pipe concurrency.\n\n### 3. Wave-Quantization Cluster Resilience Pillar\nNever allow GPU Streaming Multiprocessors to sit idle during tail execution waves. Partition small-batch sequences across Threadblock Clusters to sustain maximum occupancy.\n\n---\n\n## The Visual Brief Pillar\n\nWhen completing TopK selection benchmark runs or Sparse Attention (DSA) tuning sessions, synthesize throughput comparisons, denormal FP32 boundary test results, and Threadblock Cluster performance matrices into a standalone interactive HTML visual brief written to `%TEMP%\\deepselect-topk-\u003Ctimestamp>.html`. Render performance curves as inline SVG bar charts with P50\u002FP99 latency annotations.\n\n## Mandatory Checkpoint Gates\n\nBefore finalizing any TopK kernel implementation or DSA configuration:\n1. **Gate 1 (Correctness)**: Assert TopK selection results match reference brute-force output on all randomized test vectors (tolerance ≤ 1e-5).\n2. **Gate 2 (Denormal FP32 Guard)**: Assert zero denormal float inputs reach the hot selection loop (flush-to-zero confirmed).\n3. **Gate 3 (Timeout Bound)**: Assert no single benchmark run exceeds declared async timeout (≤ 5.0s per vector by default).\n\n---\n\n## Anti-Patterns\n\n- **Global Heap Exhaustion** — Inserting all elements of an N-element vector into a global priority queue or heap causing O(N log k) branch-divergent memory access.\n- **Two-Pass Filter Stall** — Reading global memory or registers twice for candidate counting and writing, doubling register pressure and stalling pipelines.\n- **Integer ALU Saturation** — Using integer multiply-add instructions when int ALU is saturated, delivering half the throughput of floating-point units.\n- **Single-CTA Sequence Confinement** — Forcing one threadblock to process an entire massive sequence alone while GPU SMs sit idle in the tail wave.\n- **Unbounded Float Denormal Emulation** — Applying denormal FP32 integer addition when operands exceed 2^22, triggering exponent overflow and data corruption.\n",{"name":5,"description":7},"main","eff3b00e36d1d233ad4a4389605c82fbfa0326d3",".agents\u002Fskills\u002Fdeepselect-topk-optimizer","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness","https:\u002F\u002Fgithub.com\u002FSpectreDeath","I'm here to manage stress so I wouldn't expect earth shattering break throughs I'm just an enthusiast that likes making stuff. ","2026-11-15 05:32:58",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add SpectreDeath\u002FBrain-Harness --skill deepselect-topk-optimizer",{"tool":37,"command":38},"bunx","bunx skills add SpectreDeath\u002FBrain-Harness --skill deepselect-topk-optimizer",{"tool":40,"command":41},"pnpm","pnpm dlx skills add SpectreDeath\u002FBrain-Harness --skill deepselect-topk-optimizer","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fdeepselect-topk-optimizer\u002FSKILL.md",true,[45,51,55],{"path":46,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":49,"sourceHtmlUrl":50},"CARD.md","REFERENCE","参考文档",3229,"https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fdeepselect-topk-optimizer\u002FCARD.md",{"path":52,"resourceType":47,"resourceTypeDesc":48,"sizeBytes":53,"sourceHtmlUrl":54},"config.default.yaml",332,"https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fdeepselect-topk-optimizer\u002Fconfig.default.yaml",{"path":56,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":60},"scripts\u002Fdeepselect_engine.py","SCRIPT","脚本",12080,"https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fdeepselect-topk-optimizer\u002Fscripts\u002Fdeepselect_engine.py",[62,69,76,83,90,97],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7E0W6FR68J2N9CXCZTAQJFX","ui-behavior-primitive-architect","Architect, audit, and verify zero-dependency headless UI behavior primitives, WebMCP agent bridges, WAI-ARIA\u002FSSR\u002FRTL tri-modal checks, and framework expert routing. Do not use for static CSS theme styling or backend database migrations.","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fui-behavior-primitive-architect\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7E0VZ7JQNW34G271DENFGYP","trustgraph-ontology-governor","Govern knowledge graphs, SHACL-AF triple policies, OntologyRAG subclass validation, PROV-O dual named graphs, and Laya entropy decision scoring. Do not use for relational SQL queries or generic web scraping.","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Ftrustgraph-ontology-governor\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7E0VQ6Z7R45Q8QAZ4MT39EK","shim-harness-governor","Govern universal CLI agent loops, 4-tier tool permissions, ancestor-symlink workspace sandboxes, deterministic-first command routing, collision-safe MCP namespacing, and layered skill loading. Do not use for static UI styling or external SQL analytics.","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fshim-harness-governor\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7E0VC18NMP1QBSRJ3TPQ7MB","graphiti-zep-memory-governor","Govern bi-temporal knowledge graphs with Graphiti future-edge clamping, MinHash\u002FLSH entity dedup, RRF\u002FMMR reranking, and Zep typed ontologies. Do not use for static SQL joins or generic web crawling.","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fgraphiti-zep-memory-governor\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M7E0V12ABE1RW3ZRCST8VH5Z","agora-mcp-workbench-architect","Architect, audit, and orchestrate Agora Workbench MCP servers, loopback sidecars, unified state graphs, gateway\u002Fdispatcher connectors, and policy-enforced data lakes. Do not use for static frontend CSS styling or non-MCP desktop GUI automation.","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fagora-mcp-workbench-architect\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M7BFYG6QT3484VC57TZ19V7P","skill-eval-assurance-runner","Evaluate and assure agent skills using small-N Wilson confidence intervals, unbiased pass^k reliability, deterministic trajectory graders, preflight boundary honesty, and sealed digest verification. Do not use for subjective prose review or unconstrained production deployment.","https:\u002F\u002Fgithub.com\u002FSpectreDeath\u002FBrain-Harness\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fskill-eval-assurance-runner\u002FSKILL.md",[],[]]