다중 코어 덧셈
문서 상태
소유: CL팀 · 기준: Legato 0.14.1+public, PyTorch 2.10.0+cpu, Bertha EVT0 · 최종 확인: 2026-10-19
BF16 [32, 256] 입력을 행 단위로 나누어 32개 코어에서 덧셈.
코어 i는 입력의 i번째 행을 처리하고 독립된 [1, 256] 출력에 저장.
전체 실행 파일을 SDK 환경에 저장한 뒤 실행.
| HA_TOOLCHAIN=1 python3 multi_core_add.py
|
코어별 입력 적재
| with device.get_top():
def load_row(i):
region = (legato.range(i, i + 1), legato.range(0, 256))
legato.tensor.request_load(legato.tensor.view(a, region), device.get_core(i), "sram")
legato.tensor.request_load(legato.tensor.view(b, region), device.get_core(i), "sram")
legato.static.for_each(legato.range(0, 32), load_row)
|
static.for_each는 컴파일 시 32개 코어의 적재 요청 생성.
각 코어에 a의 한 행, b의 한 행 순서로 요청.
공통 연산과 출력 전달
| with device.get_all_cores():
tile_type = legato.types.tensor(legato.types.float("bfloat16"), [1, 256])
x = legato.tensor.receive_type(tile_type, 0, None, "sram")
y = legato.tensor.receive_type(tile_type, 1, None, "sram")
legato.tensor.memcpy(out, x + y)
|
커널의 param_kinds는 입력 a·b를 top, 출력 out을 core로 선언.
출력은 코어마다 별도 할당. 호출 시 legato.Args(outputs, bertha.all_cores)로 전달하면
리스트의 i번째 tensor가 코어 i의 out 인자에 연결.
32개 tensor의 dtype·shape는 출력 타입 선언과 일치해야 함.
| with legato.session(output_type=legato.OutputType.BINARY, output_path="multi_core_add"):
multi_core_add(
legato.Arg(a, bertha.top),
legato.Arg(b, bertha.top),
legato.Args(outputs, bertha.all_cores),
)
|
실행 후 모든 코어의 출력을 CPU로 회수하고 순서대로 연결하여 전체 [32, 256] 결과 비교.
코어마다 다른 입력을 사용하므로 잘못된 행 배정도 비교 대상에 포함.
성공 시 PASS: multi_core_add [32, 256], BF16, 32 cores 출력.