For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo struct
KVPipelineGeneric
struct KVPipelineGeneric[num_kv_stages: Int, num_qk_stages: Int, num_producer: Int, num_consumer: Int]
KVPipeline has num_kv_stages * num_qk_stages stages. num_kv_stages refers to how many K and V tiles we pipeline for performing the S = Q@K' and O += P@V MMAs. Each of these MMAs is broken up into num_qk_stages pipelined MMAs. We set step=False for all but the last MMA that completes the operation. An alternative implementation would separate the two, and potentially allow for more overall stages at the cost of slightly more bookkeeping.
Parametersβ
- βnum_kv_stages (
Int): Number of KV tiles pipelined for theS = Q@K'andO += P@VMMAs. - βnum_qk_stages (
Int): Number of pipelined sub-MMAs each QK or PV MMA is broken into. - βnum_producer (
Int): Number of producer threads arriving on each producer mbarrier. - βnum_consumer (
Int): Number of consumer threads arriving on each consumer mbarrier.
Fieldsβ
- βmbar (
MBarType): - βstate (
PipelineState[num_kv_stages]):
Implemented traitsβ
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDeletable,
Movable,
RegisterPassable,
TrivialRegisterPassable
comptime membersβ
num_stagesβ
comptime num_stages = (num_kv_stages * num_qk_stages)
Methodsβ
__init__β
def __init__(mbar: Pointer[SharedMemBarrier, MutAnyOrigin, address_space=AddressSpace.SHARED, _safe=False]) -> Self
initβ
def init(self)
producer_mbarβ
def producer_mbar[qk_stage: Int](self) -> MBarType
Returns:
MBarType
consumer_mbarβ
def consumer_mbar[qk_stage: Int](self, idx: UInt32) -> MBarType
Returns:
MBarType
def consumer_mbar[qk_stage: Int](self) -> MBarType
Returns:
MBarType
producer_acquireβ
def producer_acquire[qk_stage: Int = (num_qk_stages - Int(1))](self)
Returns the dynamic pipe idx.
Parameters:
- βqk_stage (
Int): QK sub-stage index whose consumer mbarrier to wait on (defaults to the last QK stage).
consumer_waitβ
def consumer_wait[qk_stage: Int = (num_qk_stages - Int(1))](self)
consumer_releaseβ
def consumer_release[qk_stage: Int = (num_qk_stages - Int(1))](mut self, e: Int32)
num_mbarsβ
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!