Compute units? Yeah, they're basically the fuel for your blockchain transactions or AI jobs. If you're messing with Solana - which is what most folks mean these days - it's all about not getting your tx dropped because you ran out of gas. Or if you're in Qualcomm AI Hub land, it's picking which chip brains your model uses. But honestly, from what I see, you're probably here for Solana compute units. That's the hot one right now. Default's 200k per tx, but you can crank it up to 1.4 million max. Why? So your trades or swaps don't fail in a mempool bloodbath.
I usually start here because newbies waste SOL on failed txs without knowing this. Sound familiar? Let's fix that. We'll go step by step for Solana first - it's practical, saves you real money like ~0.000005 SOL per extra CU if you price it right. Then I'll hit Qualcomm and AMD quick, 'cause contexts matter.
Transactions eat compute units (CUs) like candy. Too few? Boom, "out of compute" error. Network's congested? Your tx sits forever unless you pay priority fees tied to CUs. As of late 2025, blocks cap at 60 million CUs total, 1.4M per tx, 12M per account. Default 200k? Fine for simple transfers. But DeFi swaps? NFT mints? You're looking at 300k-800k easy.
The thing is, you simulate first to see exact usage. Add 10-20% margin. Then set a limit with SetComputeUnitLimit. Pair it with SetComputeUnitPrice for priority - that's microLamports per CU, like 10,000 means ~0.00001 SOL extra fee on a 400k CU tx. Pretty much pays validators to process you first.
| Limit Type | Amount |
|---|---|
| Per Transaction (max) | 1.4 million CU |
| Default per tx | 200,000 CU |
| Per Block | 60 million CU |
| Per Account per Block | 12 million CU |
See? Don't guess. Simulate.
Grab your connection and instructions. Say you're doing a swap.
Write a sim function. Here's mine - copy paste it.
async function getSimulationUnits(connection, instructions, payer) { const testInstructions = [ ComputeBudgetProgram.setComputeUnitLimit({ units: 1400000 }), // Max for sim ..instructions ]; const tx = new Transaction().add(..testInstructions); tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; tx.feePayer = payer; const simulation = await connection.simulateTransaction(tx, { sigVerify: false }); if (simulation.value.err) return undefined; return simulation.value.unitsConsumed;
}Call it: const units = await getSimulationUnits(connection, yourInstructions, payerKey);
Add margin. I do 10%: const adjusted = Math.ceil(units * 1.1); Caps at 1.4M obv.
Build real tx. Add these first in instructions array:
transaction.add( ComputeBudgetProgram.setComputeUnitLimit({ units: adjusted }), ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 10000 }) // Tune this
);
transaction.add(..yourInstructions);Sign, send. Watch it fly.
What's next? Test on devnet first. Costs nothing. In my experience, forgetting the recentBlockhash in sim kills it every time.
Okay, if you're on @solana/kit - faster, cleaner. Same logic.
import { pipe, createTransactionMessage, appendTransactionMessageInstructions } from "@solana/kit";
import { getSetComputeUnitLimitInstruction, getSetComputeUnitPriceInstruction } from "@solana program/compute budget"; const limitIx = getSetComputeUnitLimitInstruction({ units: 1400000 });
const priceIx = getSetComputeUnitPriceInstruction({ microLamports: 10000 }); const testMsg = pipe( createTransactionMessage({ version: 0 }), (tx) => appendTransactionMessageInstructions([limitIx, ..instructions], tx) // .. set payer etc.
); // Sim it, get units, adjust, rebuild real msg with unshifted instrs.
Pro tip: For priority fees, hit an RPC like QuickNode's fetchEstimatePriorityFees. Grabs network congestion data. Set microLamports to their "high" rec - say 50k-200k in peak times. Saves failed tx retries.
Tx fails with "Compute Budget Exceeded"? Your sim lied or no margin. Add 20% next time. Or sim failed - check for err in sim response.
Fees too high? Drop price to 0 - just sets limit, no priority. But good luck in congestion.
Max units but still drops? Account limit hit (12M/block). Wait a block or spread txs.
And simulation undefined? Instructions broken or bad payer. Log the sim.err - it's your friend.
No price set? Base fee only (~0.000005 SOL/tx). With price, it's price * CUs / 1e6 lamports. So 10k microLamports on 400k CUs = 4 SOL micro? Wait no:
Formula: total priority = (microLamportsPerCU * units) / 1000000 lamports. For 10,000 micro / 400k units = 4,000,000 microLamports = 0.004 SOL. Cheap insurance.
I usually start at 5k-20k. Bots run 100k+. Why does this matter? Friday pumps - network melts, low priority txs die.
Different beast. You're deploying ML models to edge devices. Compute units = CPU, GPU, NPU. Don't want your gaming app's AI hogging GPU? Set compute_unit=NPU,CPU.
Steps? Super simple.
qai hub job submit mobile_net.onnx --compute unit NPU Or comma list: --compute unit NPU,CPU--compute unit all or skip.Example: Gaming app? GPU's for graphics, so NPU only. All 70 MobileNet layers hit NPU - boom, no overlap.
Issues? Syntax wrong - comma no spaces. Or unit unavailable on target device.
Setting CUs on ROCm? Env vars. For compute workloads, not games.
export ROCGLOBALCU_MASK=0,2-4:0x337F GPU0 + GPUs2-4, specific CU masks.0-3:0,5-10;4:0xFFNot all configs valid - WGPs pair CUs, can't half disable. Test or crash.
Look, start with Solana if you're trading. Simulate every tx - it's 2 mins setup, saves hours debugging. I ran a bot last month, forgot margin once - ate 0.5 SOL in fails. Never again.
Qualcomm? Model devs, pick NPU for power sip. AMD? ML training tweaks.
Questions? "How much for my swap?" Sim it. Paste code if stuck. You'll get it quick.
One more: In code, always unshift CU instrs. Order matters - budget first. Gotcha city otherwise.