Bertha API¶
이 페이지는 legato.model.bertha.operations가 제공하는 Bertha 전용 Python API를 설명합니다.
Bertha API는 범용 Legato 언어 연산 위에 추가된 백엔드 전용 helper 모음입니다. Bertha compute model 생성자, executor 접근자, 메모리/타입 helper, MPU/TLB 연산, Bertha 동기화(synchronization) 연산이 여기에 포함됩니다.
전형적인 백엔드 설정¶
1 2 3 4 5 6 | |
이 백엔드 팩토리를 @legato.compile(backend=get_bertha)처럼 backend 인자에 넘겨 사용합니다.
대상 세대¶
Bertha(ctx, "bertha")는 EVT0 기본값으로 설정됩니다.
개별 파라미터를 바꾸려면 키워드 인자(num_cores=..., num_memory_channels=...)를 쓰거나
MLIRBerthaDeviceParams 인스턴스를 넘기십시오.
파라미터를 위치 순서대로 나열하던 예전 방식은 deprecated되었으며, EVT1을 표현할 수 없습니다.
bertha_v1 compute model과 EVT1 디바이스 파라미터를 쓰려면
backend=bertha.evt1 또는 Bertha(ctx, "bertha", revision="EVT1")을 사용하십시오.
파라미터 객체는 해당 세대의 것이어야 합니다.
EVT1은 lowering 파이프라인과 translator 파이프라인이 EVT0와 별도입니다.
따라서 EVT0 예제나 하드웨어 레이아웃 상수가 있다는 것을
EVT1에서도 지원된다는 근거로 삼을 수 없습니다.
EVT0 전용인 TLB, packed-weight 양자화 matmul, top_kp helper를 EVT1에서 호출하면
Python wrapper가 명시적으로 거부합니다.
device.sort는 EVT1에서도 지원되며, 현재는 내림차순 정렬만 가능하고
논리 입력이 유한한 값이어야 합니다.
개별 연산의 지원 여부는 원하는 컴파일 단계까지 진행해 보고,
그에 맞는 타겟 런타임에서 실행해 확인하십시오.
검증된 EVT1 경로¶
현재 EVT1 백엔드에는 아래 경로가 구현되어 있습니다. 이 표는 나열된 케이스를 컴파일러와 시뮬레이터가 지원한다는 뜻이며, 하드웨어 레퍼런스가 아니고 모든 EVT0 연산을 EVT1에서 쓸 수 있다는 뜻도 아닙니다.
| 연산 | 현재 검증 범위와 제약 |
|---|---|
텐서 -, *, / |
shape이 같은 BF16 텐서끼리의 연산이 기존 + 경로와 마찬가지로 EVT1 VPU에서 실행됩니다. 수치 검증 케이스는 [16, 256] 입력을 load해 계산한 뒤, 결과를 flatten해서 저장합니다. |
legato.tensor.memcpy로 SRAM에서 shared_dram으로 복사 |
word-interleaved DRAM으로 쓰는 경로는 BF16 출력 rank 1부터 6까지 수치 검증되어 있습니다. 입력과 출력의 저장 kind를 호환되게 유지하십시오. |
동적이거나 padding된 shared DRAM의 request_load / receive |
전송 크기는 런타임 행 수를 기준으로 DRAM line 단위로 정하고, 나머지 차원은 물리 크기를 사용합니다. 목적지 SRAM의 물리 크기는 여전히 정적이어야 합니다. |
| 마지막 축의 BF16 softmax | reduce_max → sub → exp → reduce_sum → div 패턴이 [32, 256] 입력에 대해 검증되어 있습니다. keepdim=True를 사용해야 하며, reduction 대상 폭은 BF16 원소 64개의 배수여야 합니다. |
device.sort |
유한한 값으로 이루어진 입력에 대해 내림차순 정렬을 지원합니다. 그렇다고 top_kp가 EVT1에서 지원되는 것은 아닙니다. |
| 명령어 테이블 읽기와 embedding gather | scalar 읽기와 정수 cast를 지원합니다. tensor.gather(weight, indices)는 명령어 테이블에서 읽은 정수 index와, 행 수가 DRAM 채널 수로 나누어떨어지는 sliced_dram 테이블의 조합을 지원합니다. 명령어 테이블에 대한 텐서 view나 임의의 SRAM index를 쓰는 gather까지 지원한다는 뜻은 아닙니다. |
런타임 while과, 가장 가까운 루프를 빠져나가는 break |
EVT0와 EVT1 모두 integer/index/bool 타입의 루프 전달 상태(carried state)를 지원합니다. continue, loop-else, 루프 본문에서의 조기 return, 텐서 타입의 전달 상태는 아직 지원하지 않습니다. |
| RoPE | 저장소에 있는 BF16 prefill·decode 커널을 EVT1 시뮬레이터에서 실행해 CPU 기준값과 비교합니다. 이 커널들은 padding된 cosine/sine 테이블을 미리 올려 두고(stage) 사용하며, 별도의 rope API가 있는 것이 아니라 검증된 커널 조합입니다. |
EVT1을 쓰려면 backend=bertha.evt1과 EVT1 런타임 또는 시뮬레이터를 명시적으로 선택하십시오.
receive가 DRAM line 전체 단위로 이루어져야 한다는 요구 사항은 여전히 적용됩니다.
짧은 전송이나 채널별 word 수가 서로 다른 전송은 별도의 lowering 케이스로 처리되는 것일 뿐이므로,
정렬되지 않은 임의의 복사가 유효하다고 가정해서는 안 됩니다.
메모리 연산과
산술 연산을 참고하십시오.
자주 쓰는 텐서 kind¶
Bertha.tensor_type(dtype, shape, kind)의 kind에는 Bertha 전용 문자열을 지정합니다.
자주 쓰는 값은 다음과 같습니다.
"shared_memory"와"shared_dram""row_major""value_dram"과"mpu_dram": 둘 다 동일한 value 방식 DRAM 레이아웃"key_dram"과"transposed_mpu_dram": 둘 다 동일한 key 방식 DRAM 레이아웃"mpu_weight""mpu_weight_sram": 코어 SRAM에 상주하는 MPU 형식 weight"mpu_packed_buffer": 내부 구조를 해석하지 않는(opaque) rank 1 packed-weight blob"sliced_dram"
레이아웃 제약과 메모리 배치(placement)는 Bertha 레이아웃을 참고하십시오.
SRAM으로 TLB load하기 (EVT0)¶
request_load_tlb와 request_load_tlb_dynamic은 마지막 인자로 목적지를 받습니다.
값은 "mpu_buffer"(기본값) 또는 "sram"입니다.
정적 API는 인터프리터 값인 코어 목록을, 동적 API는 컴파일된 값인 코어 bitmap을 받습니다.
1 2 | |
SRAM으로 load한 weight는 legato.tensor.receive(cache, handle, "sram")으로 수신합니다.
Bertha EVT0는 MPU 형식 레이아웃과 layout-family tag를 소스에서 추론하므로,
수신한 SRAM 텐서를 matmul의 RHS로 재사용할 수 있습니다.
tensor_type(..., "mpu_weight_sram")을 receive_type과 함께 써서
타입을 명시하는 방법도 지원합니다.
일반 legato.tensor.request_load(cache, core, "sram")에도 같은 추론이 적용됩니다.
목적지 인자를 생략하면 기존처럼 MPU 버퍼로 load되며,
이때는 tensor_type(..., "mpu_weight")과 "mpu_buffer" receive를 사용합니다.
다음 value-cache 예제는 weight 하나를 SRAM으로 load한 뒤, activation이 서로 다른 두 번의 matmul에 사용합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
커널을 launch하기 전에 EVT0 TLB를 초기화하고
해당 요청의 key/value 페이지를 할당해 두어야 합니다.
HART TLB API를 참고하십시오.
launch할 때 cache는 bertha.top에, 각 출력은 bertha.core(0)에 바인딩합니다.
위 예제의 weight는 한 번만 수신되며, 두 matmul이 실행되는 동안 SRAM에 그대로 남아 있습니다.
논리 shape이 [N, K]인 "key_dram" 입력은 [K, N]으로 수신되고,
"value_dram" 입력 [K, N]은 논리 shape을 유지합니다.
수신한 weight는 matmul의 RHS로 재사용할 수 있지만,
범용 matmul LHS나 산술·reduction·정규화 입력으로 사용할 수는 없습니다.
소스와 수신 shape을 선택한 텐서 kind에 맞추십시오.
Bertha 레이아웃을 참고하십시오.
Depthwise Convolution¶
legato.math.dwconv_1d와 legato.math.dwconv_2d는 각각 rank 2와 rank 3인
spatial 입력을 처리합니다. 2D의 기본값은 stride=(1, 1),
padding=(0, 0, 0, 0)입니다.
- 1D: 입력
[X, C], weight[KX, C], 결과[OX, C]. - 2D: 입력
[Y, X, C], weight[KY, KX, C], 결과[OY, OX, C]. - 현재 EVT0 구현에는 정적인 BF16 입력, 양수
C,X * Y <= 32, 커널 크기 1–8, stride 1–2, padding 0–7이 필요합니다. - activation은 코어 SRAM에 load하십시오. weight는 호환되는 텐서 kind를 사용해
request_load(..., "mpu_buffer")또는 SRAM으로 load할 수 있습니다. - bias와 SiLU는 별도 연산이며, 필요하면 명시적으로 추가합니다.
Weight 저장 공간 요구 사항¶
문서에 설명된 논리 weight shape을 유지하십시오. SDK의 텐서 kind와 할당 또는 변환 helper로 호환되는 저장 공간을 준비합니다. 필요한 weight 형식 변환과 padding은 컴파일러가 처리하므로, 애플리케이션에서 내부 바이트 표현을 직접 만들거나 그 표현에 의존해서는 안 됩니다.
물리 용량은 선택한 텐서 kind의 조건을 만족해야 합니다. padding된 텐서에는 backing 저장 공간을 할당하고 초기화한 뒤 논리 view를 넘기십시오. 재사용할 weight는 모든 consumer가 사용할 때까지 유지되어야 합니다. 한 번만 소비하는 스트림을 지속적으로 저장된 SRAM 텐서처럼 재사용할 수는 없습니다. Bertha 레이아웃을 참고하십시오.
1 2 3 4 5 6 7 8 9 | |
Convolution과 Pooling¶
legato.math.conv_1d / conv_2d와 max_pool_* / avg_pool_* API의
EVT0 입력 조건은 다음과 같습니다.
- 레이아웃은 channels-last입니다. 1D는
[N*, X, C], 2D는[N*, H, W, C]입니다. convolution weight는[KX, Cin, Cout]또는[KH, KW, Cin, Cout]이며, 선택적인 bias는[Cout]입니다. N*는 앞쪽 batch 차원입니다. Broadcasting과 Bertha에서의 Broadcasting을 참고하십시오.- 현재 EVT0는 BF16, 커널 크기 1–8, stride 1–2, padding 0–7,
모든 축의 dilation 1,
padding_mode="zeros"를 지원합니다. 숫자로 주는 padding은(left, right)또는(top, bottom, left, right)입니다. - weight를 여러 번 읽어야 하는 계산에는 재사용 가능한 저장 공간을 선택하십시오. Weight 저장 공간 요구 사항을 참고하십시오.
- average pooling은 padding된 위치를 포함한 커널 전체 면적으로 나눕니다.
max pooling은 padding된 위치를
-inf로 취급합니다.
1 2 3 4 5 6 7 8 9 | |
RMSNorm과 LayerNorm¶
legato.math.rms_norm과 legato.math.layer_norm은 마지막 논리 축을 정규화합니다.
affine 피연산자는 rank 1인 [D] 텐서이며, LayerNorm에는 선택적인 gain과 bias를
넘길 수 있습니다. 나눗셈의 분모에는 논리 축 길이를 사용하므로,
padding 용량이 수학적인 reduction의 원소 수에 더해지지는 않습니다.
Broadcasting과 정규화 예제를 참고하십시오.
Weight-Quantized Matmul¶
mm_weight_quant와 addmm_weight_quant는 변환을 마친 오른쪽 weight를 받습니다.
hart.weight_converter가 만든 opaque rank 1 i8 결과를
"mpu_packed_buffer"로 전달하고, SDK가 생성한 버퍼로 취급하십시오.
dtype과 shape은 변환 전의 양자화된 weight [C, M]를 나타냅니다.
granularity는 "per_output_channel" 또는 "per_input_channel"입니다.
입력 채널 단위의 quant_group_size는 기본값이 128이고,
128 이상의 128 배수이며 shape[0]을 나누어떨어지게 해야 합니다.
출력 채널 단위에서는 그룹 크기를 무시합니다.
Bertha 레이아웃과 Weight-Quantized Matmul 전체 예제를 참고하십시오.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Compute Model¶
Bertha¶
1 | |
Bertha compute model wrapper.
The revision device parameter selects the hardware backend. Parameters
default to Bertha EVT0; use legato.model.bertha.evt1 (or pass
revision="EVT1") to target EVT1.
A Bertha instance is normally created by the backend factory passed to
@legato.compile. The active MLIR context is supplied by the compiler, and
the returned compute model becomes available inside kernels through
legato.get_context().get_device() or legato.get_model().
The model exposes Bertha-specific helpers for executor selection, memory lookup, tensor type construction, TLB operations, MPU matmul operations, and top/core synchronization barriers.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
__init__¶
1 | |
Initialize the Bertha compute model.
This registers the Bertha dialect/model with the active MLIR context and
creates the underlying C++ wrapper: MLIRBertha for EVT0, MLIRBerthaV1
(the bertha_v1 compute model) for EVT1. Both are built from the same
params object, so the registered model and this wrapper cannot
describe different devices.
The revision parameter selects the hardware backend. Every device
hyperparameter defaults to that revision's value, defined once on the
C++ side (BerthaDeviceParams / BerthaV1DeviceParams). Pass params
to supply a fully built parameter object, or keyword overrides to
adjust individual fields of the defaults:
1 | |
Parameters:
ctx(MLIRContext): Active MLIR context supplied by the compiler.name(str): Symbolic name for this Bertha model instance.params(MLIRBerthaDeviceParams | MLIRBerthaV1DeviceParams | int | None): Device parameters:MLIRBerthaDeviceParamsfor EVT0 orMLIRBerthaV1DeviceParamsfor EVT1. Defaults to the description of the revision requested inoverrides, else Bertha EVT0. Default:None.*legacy_args(object): Deprecated. Trailing arguments of the old positional signature(num_cores, use_pim, num_memory_channels, shared_memory_size), in which caseparamsisnum_cores. Default:().**overrides(object): IndividualMLIRBerthaDeviceParamsfields to override. Default:{}.
Raises:
- (
AttributeError): If an override does not name a parameter field. - (
ValueError): Ifrevisionnames no known Bertha generation. - (
RuntimeError): If the model cannot be registered withctx.
revision¶
1 | |
Silicon revision this model targets, e.g. "EVT0".
Reaches the emitted ELF as the target-variant note, so it must match the device the binary will actually run on.
generation¶
1 | |
Silicon generation ("EVT0" or "EVT1") parsed from revision; it selects the compute model.
is_evt1¶
1 | |
Whether this model targets Bertha EVT1.
num_cores¶
1 | |
Number of Bertha cores exposed to the kernel.
use_pim¶
1 | |
Whether PIM support is enabled for this model.
num_memory_channels¶
1 | |
Number of DRAM memory channels.
shared_memory_size¶
1 | |
Total shared DRAM size in bytes.
bytes_per_channel¶
1 | |
Physical capacity of one DRAM channel, in bytes.
This is a capacity. It is not the address-space distance between
adjacent channel bases -- see dram_channel_stride_bytes, which is what
tensor layouts stride by.
dram_channel_stride_bytes¶
1 | |
Address-space distance between adjacent DRAM channel bases, in bytes.
register_model¶
1 | |
Register the compute model matching the params (EVT0 or EVT1) to the context.
run_backend_passes¶
1 | |
Run the backend passes of this revision's compute model (EVT0 or EVT1).
run_binary_backend_passes¶
1 | |
Run this revision's backend passes and translate to a binary.
run_translator¶
1 | |
Run this revision's translator ("asm" or "bin").
get_layout¶
1 | |
Return the Bertha layout object for a tensor kind.
This helper is used by tensor_type and is rarely called directly.
kind must be an interpreted string. Supported kinds are:
"shared_dram"and"shared_memory": DRAM word-distributed layout."key_dram"and"transposed_mpu_dram": same key-style DRAM layout."value_dram"and"mpu_dram": same value-style DRAM layout."mpu_weight"and"mpu_weight_sram": MPU tensor layout."mpu_packed_buffer": row-major layout in MPU buffer memory, for an already-packed opaque rank-1 buffer (no MPU tiling applied)."row_major": row-major layout."sliced_dram": sliced DRAM layout; requiresshape.
Parameters:
rank(Value): Interpreted tensor rank.dtype(Value): Interpreted tensor element type.kind(Value): Interpreted layout kind string.shape(Value | None): Interpreted tensor shape. Required for"sliced_dram". Default:None.
Returns:
- (
Callable[[CodeGenerator], Value]): A callable that produces the interpreted layout value during codegen.
Raises:
- (
ValueError): Ifkindis"sliced_dram"andshapeis missing. - (
NotImplementedError): Ifkindis not supported by this Bertha revision.
tensor_type¶
1 | |
Create a Bertha tensor type for the given dtype, shape, and kind.
This is the preferred way to annotate tensors that live in Bertha memory
spaces. It combines a generic tensor type with a Bertha memory object and
a Bertha layout derived from kind.
Common kind values:
"shared_memory"or"shared_dram"for shared DRAM tensors."row_major"for core-local SRAM tensors."mpu_dram"as an alias of"value_dram"for the value-style MPU/TLB path."transposed_mpu_dram"as an alias of"key_dram"for the key-style MPU/TLB path."mpu_weight"for values received through the MPU weight buffer."mpu_weight_sram"for MPU-format weights received into core SRAM and reused by matmul. Uses the same layout family as"mpu_weight"."mpu_packed_buffer"for an already-packed opaque rank-1 buffer (e.g. a weight-quantized weight blob) streamed straight from DRAM to the MPU buffer, with no MPU tiling applied."sliced_dram","key_dram", and"value_dram"for specialized DRAM layout names.
Dynamic dimensions are written with (-1, max_dim) in the shape.
Example:
1 2 3 4 5 | |
Parameters:
dtype(Value): Interpreted element type.shape(Value): Interpreted tensor shape.kind(Value): Interpreted Bertha tensor kind string.
Returns:
- (
Callable[[CodeGenerator], Value]): A callable that produces an interpreted tensor type during codegen.
Raises:
- (
NotImplementedError): Ifkinddoes not map to a Bertha memory kind.
get_num_cores¶
1 | |
Return the number of Bertha cores as an interpreted value.
This is useful for static generation patterns, for example unrolling a
request loop over all available cores with legato.range.
get_top¶
1 | |
Return the Bertha top executor.
Use this in a with statement to coordinate input requests and top/core synchronization.
Example:
1 2 3 | |
get_core¶
1 | |
Return one Bertha core executor by static core index.
Parameters:
index(Value): Interpreted integer core index.
Returns:
- (
Callable[[CodeGenerator], Value]): A callable that produces aBerthaCorevalue.
get_cores¶
1 | |
Return a list of Bertha core executors.
Parameters:
indices(Value): Interpreted list of interpreted integer core indices.
Returns:
- (
Callable[[CodeGenerator], list[Value]]): A callable that produces a list ofBerthaCorevalues.
get_all_cores¶
1 | |
Return all Bertha core executors.
Use this as a context when the region should be emitted for every core.
get_use_pim¶
1 | |
Return whether this Bertha model was configured to use PIM.
get_shared_memory_size¶
1 | |
Return the configured shared DRAM size in bytes.
get_shared_memory¶
1 | |
Return the shared Bertha memory object.
Tensor kinds such as "shared_dram" and "shared_memory" use this
memory object. Use "mpu_dram" / "transposed_mpu_dram" kinds for
layout-specific shared pool memories.
get_instruction_table¶
1 | |
Return the instruction table memory object.
get_mpu_dram¶
1 | |
Return the Bertha MPU value-layout shared DRAM memory.
get_mpu_transposed_dram¶
1 | |
Return the Bertha MPU key-layout shared DRAM memory.
get_mpu_buffer¶
1 | |
Return an MPU buffer memory object by index.
Parameters:
index(Value): Interpreted integer MPU buffer index.
Returns:
- (
Callable[[CodeGenerator], Value]): A callable that produces aMemoryvalue for the MPU buffer.
get_core_sram¶
1 | |
Return a core SRAM memory object by core index.
Parameters:
index(Value): Interpreted integer core index.
get_core_private_dram¶
1 | |
Return a core-private DRAM memory object by core index.
Parameters:
index(Value): Interpreted integer core index.
write_tlb¶
1 | |
Write a key or value tensor through the Bertha TLB path.
This Bertha EVT0 operation writes data into dst using the TLB
address path. is_key indicates whether the operation is in key mode or value mode.
If input is in key mode, but layout turns out to be incompatible, the operation will fail.
Value mode works same in vice versa.
request_id, layer, and head may be interpreted scalar constants or
compiled index values; interpreted values are forwarded to compiled
values before the operation is emitted.
Parameters:
is_key(Value): Interpreted boolean indicating whether the operation is in key mode.dst(Value): Destination tensor in a supported TLB DRAM layout.data(Value): Source tensor to write.request_id(Value): Request id index.layer(Value): Layer id index.head(Value): Head id index.
Returns:
- (
Callable[[CodeGenerator], Value]): The emitted TLB write operation result.
Example:
1 2 3 | |
mm_weight_quant¶
1 | |
Perform weight-quantized matrix multiplication on the Bertha MPU.
rhs is an already weight-quantized and packed rank-1 i8 buffer
received into the mpu_buffer storage (mpu_packed_buffer or mpu_weight).
SRAM is rejected. Use the SDK weight converter to prepare the opaque buffer.
dtype/shape describe rhs's pre-packing quantized layout,
granularity its quantization grouping. Result dtype matches lhs;
result shape follows the conventional matmul rule
[H, C] @ [C, M] => [H, M], where [C, M] = shape.
Parameters:
lhs(Value): Left-hand side compiled tensor, rank 2, shape [H, C].rhs(Value): Packed weight buffer in the MPU buffer, a compiled rank-1 i8 tensor.dtype(Value): Interpreted pre-packing quantized weight element type.shape(Value): Interpreted pre-packing quantized weight shape [C, M].granularity(Value): Interpreted quantization granularity,"per_input_channel"or"per_output_channel".quant_group_size(Value | None): Optional actual input-channel group size (128, 256, ...). Omitted values default to 128. Used whengranularityis"per_input_channel"; ignored for"per_output_channel". Default:None.
Returns:
- (
Callable[[CodeGenerator], Value]): Result tensor.
Example:
1 2 3 4 5 6 7 8 | |
addmm_weight_quant¶
1 | |
Perform weight-quantized matrix multiplication with fused bias on the Bertha MPU.
Same as mm_weight_quant, including the requirement that rhs live
in the MPU buffer, but rhs's packing additionally contains bias
data (opaque to Legato). bias_dtype records the pre-packing bias
element type.
Parameters:
lhs(Value): Left-hand side compiled tensor, rank 2, shape [H, C].rhs(Value): Packed weight+bias buffer in the MPU buffer, a compiled rank-1 i8 tensor.dtype(Value): Interpreted pre-packing quantized weight element type.shape(Value): Interpreted pre-packing quantized weight shape [C, M].granularity(Value): Interpreted quantization granularity,"per_input_channel"or"per_output_channel".bias_dtype(Value): Interpreted pre-packing bias element type.quant_group_size(Value | None): Optional actual input-channel group size (128, 256, ...). Omitted values default to 128. Used whengranularityis"per_input_channel"; ignored for"per_output_channel". Default:None.
Returns:
- (
Callable[[CodeGenerator], Value]): Result tensor.
Example:
1 2 3 4 5 6 | |
request_load_tlb¶
1 | |
Request a TLB load to interpreted target devices.
This Bertha-specific operation asks the TLB path to load src for one
or more target executors or memories. The target device list is known at
compile time, while request metadata is emitted as compiled index values.
Parameters:
src(Value): Source tensor in a TLB-backed DRAM layout.target_devices(Value): InterpretedExecutor,Memory, or list/tuple of interpretedExecutor/Memoryvalues.request_id(Value): Request id index.layer(Value): Layer id index.head(Value): Head id index.target_name(Value | None): Interpreted destination, "mpu_buffer" (default) or "sram". For SRAM,tensor.receive(src, handle, "sram")infers the MPU weight layout for matmul RHS use. Explicit"mpu_weight_sram"withreceive_typeis also supported. Default:None.
Returns:
- (
Callable[[CodeGenerator], Value]): No tensor value; emits the TLB load request side effect.
Example:
1 2 | |
request_load_tlb_dynamic¶
1 | |
Request a TLB load with a compiled target-device bitmap.
Use this variant when the target core set is a runtime/compiled index value rather than an interpreted list of executors.
Parameters:
src(Value): Source tensor in a TLB-backed DRAM layout.target_devices(Value): Compiled index-like device bitmap.request_id(Value): Request id index.layer(Value): Layer id index.head(Value): Head id index.target_name(Value | None): Interpreted destination, "mpu_buffer" (default) or "sram". For SRAM,tensor.receive(src, handle, "sram")infers the MPU weight layout for matmul RHS use. Explicit"mpu_weight_sram"withreceive_typeis also supported. Default:None.
Returns:
- (
Callable[[CodeGenerator], Value]): No tensor value; emits the dynamic TLB load request side effect.
sort¶
1 | |
Sort a logit vector on the selected backend.
The caller must supply only finite logical values: NaN and infinities are unsupported. Values are not checked at runtime. For static shapes, results retain the logical input length; physical capacity is the next power of two at or above the input's physical length.
Parameters:
logit(Value): 1-D tensor in SRAM to sort.descending(bool): Sort order. Only descending (True) is currently supported. Default:True.
Returns:
- (
Callable[[CodeGenerator], tuple[Value, Value]]): Tuple containing:- sorted_logit: 1-D sorted logit tensor in SRAM
- sorted_index: 1-D sorted index tensor in SRAM
top_kp¶
1 | |
Apply top-k/top-p filtering and sample a token on the selected backend.
Fused operation: applies top-k/top-p condition and returns the selected
logit-index pair. Parameters (top-k limit, top-p probability, random weight)
are referenced by the index/address value given in params.
Parameters:
sorted_logit(Value): 1-D sorted logit tensor in SRAM (output ofsort).sorted_index(Value): 1-D sorted index tensor in SRAM (output ofsort).params(Value): Index/address value referencing the prepared sampling-parameter block.
Returns:
- (
Callable[[CodeGenerator], tuple[Value, Value]]): Tuple containing:- sampled_logit: sampled logit in SRAM scalar tensor
- sampled_index: sampled index in SRAM scalar tensor
특정 디바이스에 종속되지 않는 sync barrier는 legato.sync에서 제공합니다
(Synchronization 참고).
예전의 top_consume / top_produce / core_consume / core_produce stub은
제거되었습니다.
Executor¶
BerthaTop¶
1 | |
Bertha top executor wrapper.
Values of this type are produced by Bertha.get_top() and are used in
with contexts to emit top-level Bertha work such as load requests and
top/core synchronization.
__init__¶
1 | |
Initialize a Bertha top executor wrapper.
Users should not instantiate this class directly. Instances are created
by the Bertha backend bindings and returned from Bertha.get_top().
Parameters:
core(MLIRExecutor): Underlying MLIR executor handle.
BerthaCore¶
1 | |
Bertha core executor wrapper.
Values of this type are produced by Bertha.get_core(),
Bertha.get_cores(), and Bertha.get_all_cores(). Use them in with
contexts to emit work for one core or a group of cores.
__init__¶
1 | |
Initialize a Bertha core executor wrapper.
Users should not instantiate this class directly. Instances are created by the Bertha backend bindings and returned from Bertha executor accessors.
Parameters:
core(MLIRExecutor): Underlying MLIR executor handle.core_id(int | None): Static core index this executor was created with, if known. Set byBertha.get_core()/get_cores()/get_all_cores(), since no core-id accessor is exposed on the underlying MLIR executor binding. Default:None.