Skip to content

Python TLB API

Function Signature
init_tlb (tlb_init_info: TLBInitInfo) -> None
alloc_tlb_page (tlb_alloc_info: TLBAllocInfo) -> None
dealloc_tlb_page (tlb_dealloc_info: TLBDeallocInfo) -> None
configure_tlb (page_size: int, shared_channel_number: int, auto_prefetch_enable: bool = False, auto_prefetch_len_x: int = 0, auto_prefetch_len_y: int = 0, auto_prefetch_stride_y: int = 0, transl_time_limit: int = 0) -> None
set_page_table_range (page_table_base_addr: int, page_table_size: int, effective_vpn_width: int, cache_invalidate: bool = True) -> None
flush_tlb () -> None

Import TLBInitInfo, TLBAllocInfo, TLBDeallocInfo, PageType and ValuePageMode from hart.hart (Types). init_tlb() is for Bertha DC EVT0 only; EVT1 configures the TLB with configure_tlb() and set_page_table_range(). Each function has the semantics of the C++ TLB API.


Example

alloc_tlb_page

Allocates pages of one page type for a request.

Example
1
2
3
4
5
6
7
from hart.hart import PageType, TLBAllocInfo

import hart

alloc = TLBAllocInfo(req_id=request_id, page_num=pages_needed, page_type=PageType.KEY)

hart.alloc_tlb_page(alloc)

dealloc_tlb_page

Releases the request's pages when the request finishes.

Example
1
2
3
4
5
6
7
from hart.hart import PageType, TLBDeallocInfo

import hart

dealloc = TLBDeallocInfo(req_id=request_id, page_num=pages_to_release, page_type=PageType.KEY)

hart.dealloc_tlb_page(dealloc)

init_tlb

Static KV-cache path, Bertha DC EVT0 only.

Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from hart.hart import TLBInitInfo, ValuePageMode

import hart

info = TLBInitInfo(
    page_size=page_size,
    base_addr=kv_base,
    layer_num=num_layers,
    head_num=num_kv_heads,
    max_page_num=max_pages,
    value_page_mode=ValuePageMode.CONTIGUOUS,
    value_stride=0,
    value_line_page_num=value_line_pages,
    log_value_stride=0,
)

hart.init_tlb(info)  # Bertha DC EVT0 static KV-cache TLB

See also