• bitcoinBitcoin(BTC)$83,726.00-2.82%
  • ethereumEthereum(ETH)$2,580.06-4.92%
  • tetherTether(USDT)$1.000.00%
  • binancecoinBNB(BNB)$766.82-2.15%
  • rippleXRP(XRP)$1.45-3.77%
  • usd-coinUSDC(USDC)$1.00-0.01%
  • solanaSolana(SOL)$117.67-2.18%
  • tronTRON(TRX)$0.333211-0.68%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.040.00%
  • zcashZcash(ZEC)$1,306.29-4.18%
  • HyperliquidHyperliquid(HYPE)$89.47-4.13%
  • dogecoinDogecoin(DOGE)$0.089403-6.25%
  • moneroMonero(XMR)$554.91-0.14%
  • USDSUSDS(USDS)$1.00-0.06%
  • chainlinkChainlink(LINK)$13.48-3.88%
  • whitebitWhiteBIT Coin(WBT)$83.25-3.25%
  • cardanoCardano(ADA)$0.255099-7.71%
  • leo-tokenLEO Token(LEO)$8.88-0.17%
  • RainRain(RAIN)$0.011117-2.53%
  • stellarStellar(XLM)$0.203553-5.81%
  • nearNEAR Protocol(NEAR)$5.04-3.74%
  • bitcoin-cashBitcoin Cash(BCH)$304.01-4.23%
  • litecoinLitecoin(LTC)$67.40-4.28%
  • uniswapUniswap(UNI)$7.98-10.05%
  • Ethena USDeEthena USDe(USDE)$1.00-0.03%
  • avalanche-2Avalanche(AVAX)$11.05-2.46%
  • CantonCanton(CC)$0.117813-8.87%
  • suiSui(SUI)$1.13-5.85%
  • daiDai(DAI)$1.00-0.01%
  • USD1USD1(USD1)$1.00-0.02%
  • hedera-hashgraphHedera(HBAR)$0.094714-6.20%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.47-5.60%
  • quant-networkQuant(QNT)$244.71-3.73%
  • BitwayBitway(BTW)$1.235.57%
  • tether-goldTether Gold(XAUT)$4,119.91-0.86%
  • BittensorBittensor(TAO)$292.75-3.78%
  • shiba-inuShiba Inu(SHIB)$0.000005-6.91%
  • Global DollarGlobal Dollar(USDG)$1.000.01%
  • crypto-com-chainCronos(CRO)$0.063528-7.05%
  • EthenaEthena(ENA)$0.233802-2.85%
  • Pump.funPump.fun(PUMP)$0.0064931.64%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.02%
  • okbOKB(OKB)$133.141.62%
  • aaveAave(AAVE)$173.10-4.44%
  • Ripple USDRipple USD(RLUSD)$1.000.00%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • MemeCoreMemeCore(M)$1.033.92%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.05%
  • OndoOndo(ONDO)$0.465224-6.90%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

Inside NVIDIA’s cuDNN Graph API: Fusion, Autotuning, and Plan Reuse with cuDNN Frontend

September 15, 2026
in AI & Technology
Reading Time: 3 mins read
A A
Inside NVIDIA’s cuDNN Graph API: Fusion, Autotuning, and Plan Reuse with cuDNN Frontend
ShareShareShareShareShare
@section("5. SDPA (Flash Attention) with causal masking")
def sdpa_demo():
   if not HAS_SDPA:
       raise RuntimeError(f"fused SDPA needs SM80+ (Ampere), this GPU is sm_{SM}")
   b, h, s, d = 4, 16, 1024, 64
   scale = 1.0 / math.sqrt(d)
   SDPA_FLOPS = 4 * b * h * s * s * d * 0.5
   q = torch.randn(b, h, s, d, device=DEV, dtype=DTYPE)
   k = torch.randn(b, h, s, d, device=DEV, dtype=DTYPE)
   v = torch.randn(b, h, s, d, device=DEV, dtype=DTYPE)
   o = torch.empty(b, h, s, d, device=DEV, dtype=DTYPE)
   g = cudnn.pygraph(
       handle=HANDLE, name="sdpa",
       io_data_type=TORCH2CUDNN[DTYPE],
       intermediate_data_type=cudnn.data_type.FLOAT,
       compute_data_type=cudnn.data_type.FLOAT,
   )
   Q, Kt, V = tensor_of(g, q, "Q"), tensor_of(g, k, "K"), tensor_of(g, v, "V")
   causal = True
   try:
       O, _stats = g.sdpa(name="sdpa", q=Q, k=Kt, v=V,
                          is_inference=True, attn_scale=scale, use_causal_mask=True)
   except TypeError:
       try:
           O, _stats = g.sdpa(name="sdpa", q=Q, k=Kt, v=V,
                              is_inference=True, attn_scale=scale,
                              diagonal_alignment=cudnn.diagonal_alignment.TOP_LEFT,
                              right_bound=0)
       except Exception:
           causal = False
           O, _stats = g.sdpa(name="sdpa", q=Q, k=Kt, v=V,
                              is_inference=True, attn_scale=scale)
   print(f"    causal masking: {causal}")
   O.set_output(True).set_data_type(TORCH2CUDNN[DTYPE])
   O.set_dim(list(o.size())).set_stride(list(o.stride()))
   build(g)
   ws = workspace_for(g)
   pack = {Q: q, Kt: k, V: v, O: o}
   g.execute(pack, ws)
   torch.cuda.synchronize()
   ref = torch.nn.functional.scaled_dot_product_attention(q, k, v, is_causal=causal, scale=scale)
   rel = ((o.float() - ref.float()).abs().max() / ref.float().abs().max()).item()
   print(f"    shape   : b{b} h{h} s{s} d{d}   workspace {ws.numel()/1024:.1f} KiB")
   print(f"    rel err : {rel:.2e}")
   ms = bench(lambda: g.execute(pack, ws))
   ms_t = bench(lambda: torch.nn.functional.scaled_dot_product_attention(
       q, k, v, is_causal=causal, scale=scale))
   print()
   report("cuDNN FE SDPA", ms, SDPA_FLOPS)
   report("torch SDPA (backend's choice)", ms_t, SDPA_FLOPS)
   print("    Note: torch may already be dispatching to cuDNN or FlashAttention,")
   print("    so parity here is the expected, healthy outcome.")
   return f"{ms:.3f} ms, {tflops(SDPA_FLOPS, ms):.1f} TFLOP/s"
sdpa_demo()
@section("6. Serialize a built graph, reload it, execute by UID")
def serialization():
   Bsz, M, Kd, Nd = 8, 256, 512, 256
   a = torch.randn(Bsz, M, Kd, device=DEV, dtype=DTYPE)
   bm = torch.randn(Bsz, Kd, Nd, device=DEV, dtype=DTYPE)
   out = torch.empty(Bsz, M, Nd, device=DEV, dtype=DTYPE)
   UID_A, UID_B, UID_C = 1, 2, 3
   g = cudnn.pygraph(
       handle=HANDLE, name="serializable_mm",
       io_data_type=TORCH2CUDNN[DTYPE],
       intermediate_data_type=cudnn.data_type.FLOAT,
       compute_data_type=cudnn.data_type.FLOAT,
   )
   A = tensor_of(g, a, "A").set_uid(UID_A)
   Bt = tensor_of(g, bm, "B").set_uid(UID_B)
   C = g.matmul(A=A, B=Bt, compute_data_type=cudnn.data_type.FLOAT)
   C.set_output(True).set_data_type(TORCH2CUDNN[DTYPE]).set_uid(UID_C)
   t0 = time.perf_counter()
   build(g)
   cold_ms = (time.perf_counter() - t0) * 1e3
   blob = g.serialize()
   print(f"    cold build      : {cold_ms:.1f} ms")
   print(f"    serialized plan : {len(blob)} bytes (cache this to disk / ship it)")
   t0 = time.perf_counter()
   g2 = cudnn.pygraph()
   try:
       g2.deserialize(HANDLE, blob)
   except TypeError:
       g2.deserialize(blob)
   warm_ms = (time.perf_counter() - t0) * 1e3
   print(f"    deserialize     : {warm_ms:.1f} ms  -> {cold_ms/max(warm_ms,1e-6):.1f}x faster startup")
   ws = torch.empty(max(g2.get_workspace_size(), 1), device=DEV, dtype=torch.uint8)
   g2.execute({UID_A: a, UID_B: bm, UID_C: out}, ws, handle=HANDLE)
   torch.cuda.synchronize()
   ref = torch.bmm(a.float(), bm.float())
   rel = ((out.float() - ref).abs().max() / ref.abs().max()).item()
   print(f"    rel err after reload: {rel:.2e}")
   return f"{len(blob)} B blob, reload {cold_ms/max(warm_ms,1e-6):.1f}x faster than rebuild"
serialization()

Credit: Source link

YOU MAY ALSO LIKE

Apple TV’s F1 Coverage Will Now Support Dolby Atmos

Meta AI Open-Sources Rebalancer: A C++ Assignment Solver That Runs About 40 Million Placement Problems a Day

ShareTweetSendSharePin

Related Posts

Apple TV’s F1 Coverage Will Now Support Dolby Atmos
AI & Technology

Apple TV’s F1 Coverage Will Now Support Dolby Atmos

October 7, 2026
Meta AI Open-Sources Rebalancer: A C++ Assignment Solver That Runs About 40 Million Placement Problems a Day
AI & Technology

Meta AI Open-Sources Rebalancer: A C++ Assignment Solver That Runs About 40 Million Placement Problems a Day

October 7, 2026
Telstra Launches Longest Aura Network Route Linking Perth and Sydney – Unite.AI
AI & Technology

Telstra Launches Longest Aura Network Route Linking Perth and Sydney – Unite.AI

October 7, 2026
Redpine Opens 20 Million Research Papers to AI Agents Through Publisher Licensing Deals – Unite.AI
AI & Technology

Redpine Opens 20 Million Research Papers to AI Agents Through Publisher Licensing Deals – Unite.AI

October 7, 2026
Next Post
Israeli strike in Lebanon injures reporter and cameraman

Israeli strike in Lebanon injures reporter and cameraman

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Six Flags shuts down X2 after alleged brain injuries

Six Flags shuts down X2 after alleged brain injuries

October 3, 2026
SpaceX’s Starship rocket launches into orbit

SpaceX’s Starship rocket launches into orbit

October 6, 2026
Reflecting Pool damage case dropped after Trump comments

Reflecting Pool damage case dropped after Trump comments

October 2, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!