명령어 테이블 ABI
개요
명령어 테이블은 Legato 커널을 호출할 때 인자를 전달하는 데 쓰는
바이너리 데이터 구조입니다.
함수 파라미터를 marshaling(정해진 바이트 형식으로 직렬화)해서
호스트-디바이스 경계 너머로 전달하는 저수준 인터페이스를 제공합니다.
하드웨어가 메모리에 올바르게 접근할 수 있도록,
테이블 레이아웃은 엄격한 64-bit 정렬 규칙을 따릅니다.
InstructionTable은 논리 테이블 두 개를 관리합니다.
- Top 명령어 테이블
- Core 명령어 테이블
인자를 추가할 때 그 인자를 넣을 테이블을 다음 중에서 지정할 수 있습니다.
- top: top 테이블에만 삽입
- core: core 테이블에만 삽입
- universal: 두 테이블 모두에 삽입
이 문서의 바이너리 ABI 레이아웃 규칙은 각 테이블에 똑같이 적용됩니다.
생성되는 각 테이블은 고정된 shared memory 영역 헤더(64-bit 필드 6개)로 시작합니다.
1. standard 영역 base 주소
2. standard 영역 크기
3. cache 영역 base 주소
4. cache 영역 크기
5. reserved 영역 base 주소
6. reserved 영역 크기
이 48바이트 헤더는 항상 인자 payload 앞에 생성되며,
top 테이블과 core 테이블에 같은 값이 들어갑니다.
Core 명령어 테이블에는 shared memory 영역 헤더 바로 뒤에 필수 64-bit 메타데이터 필드가 하나 더 있습니다.
7. core id (bitmask가 아니라 core id 값 그대로)
따라서 메타데이터 prefix의 크기는 다음과 같습니다.
- top 메타데이터 prefix 크기: 48바이트 (64-bit × 6)
- core 메타데이터 prefix 크기: 56바이트 (64-bit × 7)
목적
Legato 커널을 호출하면 각 파라미터는 파라미터 kind에 따라
명령어 테이블 하나 또는 둘 모두에 packing됩니다.
생성되는 각 테이블은 연속된 메모리 영역 하나이며, 다음 내용이 들어 있습니다.
- shared memory 영역 헤더 (64-bit 값 6개)
- core id 메타데이터 (64-bit 값 1개, core 테이블에만 있음)
- 텐서 메타데이터 (base 주소와 동적 차원)
- scalar 값
- 튜플 구조 (원소 타입 단위로 flatten됨)
데이터 타입
명령어 테이블은 세 가지 기본 파라미터 타입을 지원합니다.
참고: 아래의 데이터 타입 규칙과 정렬 규칙은 메타데이터 prefix 바로 뒤에서 시작하는
인자 payload의 레이아웃을 설명합니다.
- top 테이블 payload는 48바이트 뒤에서 시작
- core 테이블 payload는 56바이트 뒤에서 시작
1. 텐서 타입
형식: tensor := <base_address (64-bit)> <offset (64-bit)> <stride (32-bit unsigned)>* <dim (32-bit unsigned)>*
크기: 16 + 4 * <rank> + 4 * <num_dynamic_dims>바이트
텐서는 다음과 같이 표현됩니다.
- Base 주소 (8바이트): DRAM 텐서에서는 메모리에 있는 텐서 데이터를 가리키는 포인터입니다.
명령어 테이블 텐서에서는 같은 명령어 테이블 버퍼 안에 저장된 원소 데이터의 위치를 나타내는,
명령어 테이블 기준 바이트 offset입니다.
- Offset (8바이트): base 주소를 기준으로 한 원소 offset입니다. 명령어 테이블 텐서에서는 항상 0입니다.
- Stride (각 4바이트): 텐서의 차원마다 stride가 하나씩 있으며, rank 순서로 저장됩니다.
stride는 항상 존재하며, 명시하지 않으면 기본값 1이 들어갑니다.
- 동적 차원 (각 4바이트): 각 동적 차원의 크기이며, stride 뒤에 순서대로 저장됩니다.
- 텐서 자체의 뒤쪽 padding은 없음: 텐서 payload 다음에 오는 인자는
일반적인 scalar/텐서 정렬 규칙을 따릅니다.
2. Scalar 타입
형식: <data (type-dependent size)>
크기: 최대 8바이트
scalar는 타입 본래의 크기 그대로 명령어 테이블에 직접 저장됩니다.
- int8: 1바이트
- int16: 2바이트
- int32: 4바이트
- int64: 8바이트
- float32: 4바이트
- float64: 8바이트
3. 튜플 타입
형식: tuple := <flattened dtype>*
크기: flatten된 dtype 각각에 필요한 바이트 수를 모두 합하고, 여기에 정렬 규칙에 따른 padding을 더한 값
튜플은 순서대로 flatten된 뒤, 각 원소가 텐서 규칙과 scalar 규칙에 따라 배치됩니다.
정렬 규칙
규칙 1: 텐서와 64-bit scalar의 64-bit 정렬
모든 텐서는 8바이트 경계에서 시작합니다.
64-bit scalar(int64, float64, 포인터)도 8바이트 경계에 맞춰 정렬됩니다.
규칙 2: 텐서 레이아웃 (Base 주소 + Offset + Stride + 동적 차원)
텐서 인자는 다음과 같이 배치됩니다.
| <base_address (64-bit)> <offset (64-bit)> <stride0 (32-bit)> ... <strideR (32-bit)> <dim0 (32-bit)> ... <dimN (32-bit)>
|
- offset은 base 주소 바로 뒤에 저장됩니다.
- stride는 rank 오름차순으로 저장되며,
호출자가 stride를 주지 않은 텐서에도 항상 생성됩니다.
- 동적 차원은 오름차순(
dim0, dim1, ...)으로 저장됩니다.
- 64-bit word 안에서 인접한 32-bit stride나 차원 값은 little-endian으로 packing됩니다.
즉 앞의 값이 **하위 32비트**를, 다음 값이 **상위 32비트**를 차지합니다.
- 텐서가 32-bit 경계에서 끝나면 다음 인자는 그 바로 뒤에서 시작합니다.
단, 다음 인자 자체에 더 엄격한 정렬이 필요한 경우는 제외합니다.
예 (rank 3, 동적 차원 3개, 기본 stride):
| Memory (bytes, little-endian):
| 64-bit base addr | 64-bit offset | stride0 | stride1 | stride2 | dim0 | dim1 | dim2 |
64-bit word contents (little-endian):
Word0: <base addr>
Word1: <offset>
Word2: <stride1> <stride0>
Word3: <dim0> <stride2>
Word4: <dim2> <dim1>
|
규칙 3: 64-bit slot 안의 scalar packing
scalar는 **인자 순서**대로 64-bit slot에 packing됩니다.
- 현재 64-bit 정렬 주소부터 scalar를 차례로 기록합니다.
- scalar가 64-bit 경계를 넘게 되면 현재 slot의 남은 바이트를 padding으로 채우고,
그 scalar는 다음 64-bit 정렬 주소에서 시작합니다.
- slot에 공간이 남아 있으면 다음 scalar가 그 공간을 채웁니다
(미리 padding하지 않음).
핵심 원칙: arg0은 첫 64-bit slot의 **최하위 바이트**에 놓입니다(little-endian).
규칙 4: 튜플 flatten
튜플은 순서대로 flatten된 뒤, 위의 텐서 규칙과 scalar 규칙에 따라 packing됩니다.
튜플 예:
| tuple<scalar, tuple<scalar, tensor>, scalar>
|
flatten된 순서:
| scalar, scalar, tensor, scalar
|
메모리 레이아웃 예제
예제 1: 단순 scalar 인자 (int64)
| Offset | Size | Content
-------|------|--------
0x00 | 8 | arg0 (int64)
0x08 | 8 | arg1 (int64)
-------|------|--------
Total: 16 bytes
|
예제 2: 경계 padding이 있는 scalar packing
인자 순서: arg0: int32, arg1: int16, arg2: int32
| Memory (bytes, little-endian):
| arg0 (32) | arg1 (16) | padding (16) | arg2 (32) |
64-bit word contents:
Word0: <padding (16)> <arg1 (16)> <arg0 (32)>
Word1: <padding (32)> <arg2 (32)>
|
예제 3: 빈 공간을 채우는 scalar packing
인자 순서: arg0: int32, arg1: int16, arg2: int8, arg3: int32
| Memory (bytes, little-endian):
| arg0 (32) | arg1 (16) | arg2 (8) | padding (8) | arg3 (32) |
64-bit word contents:
Word0: <padding (8)> <arg2 (8)> <arg1 (16)> <arg0 (32)>
Word1: <padding (32)> <arg3 (32)>
|
예제 4: 동적 텐서 인자 (동적 차원 1개)
| Offset | Size | Content
-------|------|--------
0x00 | 8 | Base address of tensor
0x08 | 8 | Offset
0x10 | 4 | stride0 (defaults to 1)
0x14 | 4 | dim0 (dynamic)
-------|------|--------
Total: 24 bytes payload
|
예제 5: 튜플 flatten
튜플: tuple<scalar, tuple<scalar, tensor>, scalar>
flatten된 순서:
| scalar, scalar, tensor, scalar
|
그다음 각 원소는 규칙 2(텐서)와 규칙 3(scalar)에 따라 그 순서대로 배치됩니다.
InstructionTable API 사용하기
InstructionTable 클래스는 명령어 테이블을 만드는 C++ API를 제공합니다.
인자 만들기
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
37
38
39
40
41
42
43
44
45 | // shared memory 영역 설정 (setupInstructionTable 호출 전에 필수)
instructionTable.setMemoryRegions(
standardRegionBaseAddress,
standardRegionSize,
cacheRegionBaseAddress,
cacheRegionSize,
reservedRegionBaseAddress,
reservedRegionSize);
// scalar 인자 생성
instructionTable.createAndPushArgument<ScalarType>(value);
// top 테이블에만 들어가는 scalar 인자 생성
instructionTable.createAndPushArgument<ScalarType>(
InstructionTable::ArgumentTarget::Top, value);
// 텐서 인자 생성
std::vector<std::uint32_t> dynamicDims = {dim0, dim1, ...};
instructionTable.createAndPushArgument<TensorType>(basePtr, dynamicDims);
// offset과 stride를 명시한 텐서 인자 생성
std::uint64_t offset = 0;
std::vector<std::uint32_t> strides = {stride0, stride1, ...};
instructionTable.createAndPushArgument<TensorType>(
basePtr, offset, strides, dynamicDims);
// core 테이블에만 들어가는 텐서 인자 생성
instructionTable.createAndPushArgument<TensorType>(
InstructionTable::ArgumentTarget::Core, basePtr, dynamicDims);
// 튜플 인자 생성
std::vector<Argument *> elements = {...};
instructionTable.createAndPushArgument<TupleType>(elements);
// 명령어 테이블 텐서(ArrayType) 인자 생성.
// stack 필드(heap 주소, offset, stride, 동적 차원)는 TensorType과 같은
// 레이아웃을 따르지만, 원소의 raw 바이트는 명령어 테이블의 heap 영역에
// 덧붙여집니다. heapAddr 값은 setupInstructionTable()이 자동으로 계산하며,
// ArrayType에서는 offset이 항상 0입니다.
std::vector<std::uint32_t> arrayStrides = {stride0, stride1, ...};
std::vector<std::uint32_t> arrayDynamicDims = {dim0, dim1, ...};
std::vector<std::uint8_t> rawData = {...}; // 원소의 raw 바이트
std::uint64_t allocSizeByte = rawData.size();
instructionTable.createAndPushArgument<ArrayType>(
arrayStrides, arrayDynamicDims, allocSizeByte, rawData);
|
테이블 설정하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | // top 명령어 테이블과 core 명령어 테이블에 쓸 메모리 할당
void *topTable = malloc(topTableSize);
void *coreTable = malloc(coreTableSize);
// 메모리 영역을 설정하지 않았으면 setupInstructionTable은 nullptr을 반환합니다.
// top 명령어 테이블 생성
void *setupTopTable = instructionTable.setupInstructionTable(
topTable, topTableSize, InstructionTable::TableTarget::Top);
// core 명령어 테이블 생성
std::uint64_t coreId = 3; // core id 값 그대로
void *setupCoreTable = instructionTable.setupInstructionTable(
coreTable, coreTableSize, InstructionTable::TableTarget::Core, coreId);
// 이 테이블을 커널 dispatch에 사용
// ...
// 정리
free(topTable);
free(coreTable);
|
권장 사항
- 테이블 크기 미리 계산: 파라미터 타입을 바탕으로
명령어 테이블의 최대 크기를 컴파일 시점에 구해 두십시오.
- 정렬 준수: 올바른 동작과 최적의 성능을 위해 정렬 규칙을 항상 따르십시오.
- 동적 차원 최소화: 가능하면 정적 shape을 써서 명령어 테이블 크기를 줄이고
캐시 지역성을 높이십시오.
- 작은 scalar 묶기: 작은 scalar 인자끼리 모아 두어
64-bit slot으로 자동 packing되는 이점을 활용하십시오.
- 컴파일 시점 검증: 컴파일러는 커널을 컴파일하는 동안
명령어 테이블 레이아웃 제약을 검증해야 합니다.
구현 참고
- 명령어 테이블은 little-endian 순서로 인코딩합니다
- 포인터는 호스트 아키텍처와 무관하게 모두 64-bit입니다
- 동적 차원의 개수는 컴파일 시점에 알 수 있어야 합니다 (차원의 값 자체는 런타임에 정해짐)
- 명령어 테이블의 최대 크기는 함수 시그니처에서 정적으로 계산할 수 있습니다
- padding 바이트의 값은 정의되어 있지 않으므로 그 값에 의존해서는 안 됩니다
메모리 레이아웃 예제
예제 1: 단순 scalar 인자
Legato 커널:
| @legato.compile(backend=prepare_bertha)
def add_scalars(a: legato.types.integer("int64"),
b: legato.types.integer("int32")):
return a + b
|
C++ 사용 예:
| InstructionTable instructionTable;
instructionTable.createAndPushArgument<ScalarType>(
static_cast<std::int64_t>(100)); // 8바이트
instructionTable.createAndPushArgument<ScalarType>(
static_cast<std::int32_t>(200)); // 4바이트
|
명령어 테이블 레이아웃:
| Offset | Size | Content
-------|------|--------
0x00 | 8 | arg0 (int64) value (100)
0x08 | 4 | arg1 (int32) value (200)
-------|------|--------
Total: 16 bytes
|
| Offset | Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 | Byte 7
-------|--------|--------|--------|--------|--------|--------|--------|--------
0x00 | 0x64 | 0x00 | 0x00 | 0x00 | 0xC8 | 0x00 | 0x00 | 0x00
| arg0(L)| arg0(L)| arg0(H)| arg1(L)| arg1(L)| arg1(H)|
| int64 | int64 | int64 | int64 | | |
| 100 | 0 | 0 | 0 | | |
-------|--------|--------|--------|--------|--------|--------|--------|--------|
Total: 8 bytes (4 bytes data, 4 bytes padding)
참고: 인자는 64-bit 단위의 맨 앞부터 채워지며, 내부 바이트 순서는 little-endian을 따릅니다.
|
예제 2: 정적 텐서 인자
Legato 커널:
| @legato.compile(backend=prepare_bertha)
def copy_tensor(x: legato.types.tensor(legato.types.float("float32"), [10, 10])):
device = legato.get_context().get_device()
with device.get_all_cores():
y = legato.tensor.copy(x, None)
yield y
|
명령어 테이블 레이아웃:
| Offset | Size | Content
-------|------|--------
0x00 | 8 | Base address of tensor x (pointer)
-------|------|--------
Total: 8 bytes
참고: 정적 차원 [10, 10]은 컴파일 시점에 알 수 있으므로
명령어 테이블에 저장되지 않습니다.
|
예제 3: 동적 텐서 인자
Legato 커널:
| @legato.compile(backend=prepare_bertha)
def process_dynamic_tensor(
x: legato.types.tensor(legato.types.float("float32"), [10, -1])
):
device = legato.get_context().get_device()
with device.get_top():
y = legato.tensor.request_load(
x, [device.get_core(0)],
(arith.cast(10, legato.types.index()), )
)
yield y
|
명령어 테이블 레이아웃 (런타임 shape이 [10 (정적), 15 (동적)]인 경우):
| Offset | Size | Content
-------|------|--------
0x00 | 8 | Base address of tensor x (pointer)
0x08 | 4 | dim1 = 15 (dynamic dim data)
0x0C | 4 | padding (to align to 64-bit boundary)
-------|------|--------
Total: 16 bytes
참고: 동적 차원은 base 주소 바로 뒤에 기록됩니다.
다음 인자에 64-bit 정렬이 필요하면, padding은 그 다음 인자 쪽에서 추가합니다.
|
예제 8: 완전한 실제 예제 (InstTableExample.cpp에서)
대응하는 Legato 커널:
이 C++ 예제는 다음과 같은 시그니처의 Legato 커널에 해당합니다.
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
37
38
39
40 | import legato
import torch
@legato.compile(backend=prepare_bertha)
def example_kernel(
arg0: legato.types.integer("int32"), # Scalar: int32
arg1: legato.types.integer("int32"), # Scalar: int32
arg2: legato.types.integer("int32"), # Scalar: int32
arg3: legato.types.integer("int16"), # Scalar: int16
arg4: legato.types.integer("int8"), # Scalar: int8
tensor_arg: legato.types.tensor( # 동적 차원이 10개인 텐서
legato.types.float("float32"),
[(-1, 100), (-1, 100), (-1, 100), (-1, 100), (-1, 100),
(-1, 100), (-1, 100), (-1, 100), (-1, 100), (-1, 100)]
),
arg5: legato.types.integer("int16"), # Scalar: int16
arg6: legato.types.integer("int32"), # Scalar: int32
tuple_arg: legato.types.tuple([ # int8 값 두 개로 이루어진 튜플
legato.types.integer("int8"),
legato.types.integer("int8")
])
):
"""Example kernel demonstrating instruction table layout."""
device = legato.get_context().get_device()
with device.get_all_cores():
# 커널 본문 (구현 세부 사항)
pass
# 실제 값으로 커널 호출:
example_kernel(
1, # arg0: int32 = 1
2, # arg1: int32 = 2
3, # arg2: int32 = 3
4, # arg3: int16 = 4
5, # arg4: int8 = 5
torch.randn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), # 10차원 텐서
7, # arg5: int16 = 7
8, # arg6: int32 = 8
(-1, -2) # tuple_arg: (int8, int8)
)
|
인자와 명령어 테이블의 대응:
| 인자 |
타입 |
값 |
명령어 테이블 위치 |
바이트 |
비고 |
arg0 |
int32 |
1 |
slot 0, 바이트 0-3 |
4 |
첫 번째 scalar, LSB 쪽에 배치 |
arg1 |
int32 |
2 |
slot 0, 바이트 4-7 |
4 |
arg0 뒤에 packing |
arg2 |
int32 |
3 |
slot 1, 바이트 0-3 |
4 |
더 작은 scalar들 앞에 packing |
arg3 |
int16 |
4 |
slot 1, 바이트 4-5 |
2 |
arg2 뒤에 packing |
arg4 |
int8 |
5 |
slot 1, 바이트 6 |
1 |
arg3 뒤에 packing |
tensor_arg |
tensor<?x?x?x?x?x?x?x?x?x?xf32> |
(rank 10, 차원 10개) |
바이트 0x10-0x6F |
96 |
8바이트 포인터 + 8바이트 offset + stride 40바이트 (10×4) + 차원 40바이트 (10×4) |
arg5 |
int16 |
7 |
0x70 위치의 slot, 바이트 0-1 |
2 |
arg6 앞에 packing |
arg6 |
int32 |
8 |
0x70 위치의 slot, 바이트 2-5 |
4 |
arg5 뒤에 packing |
tuple_arg |
tuple |
(-1, -2) |
바이트 0x76-0x77 |
2 |
튜플 원소를 순서대로 저장 |
인자별 상세 설명:
-
Scalar 인자 (arg0-arg2): 연속된 int32 값 세 개가 64-bit slot 두 개에 걸쳐 저장됨
arg0=1과 arg1=2는 첫 slot(0x00-0x07)을 공유
- 인자 순서대로 packing:
[arg0][arg1]
-
크기가 서로 다른 scalar 인자 (arg2-arg4): 크기가 다른 scalar들을 효율적으로 packing
arg2=3 (int32, 4바이트)
arg3=4 (int16, 2바이트)
arg4=5 (int8, 1바이트)
- 여기에 더해, 뒤따르는 텐서의 정렬을 맞추기 위한 padding 1바이트가 0x0F에 들어감
- 순서대로 packing:
[arg2][arg3][arg4][pad]
-
텐서 인자: 동적 차원이 있는 다차원 텐서
- base 주소:
0x0123456789ABCD (offset 0x10에 8바이트)
- offset:
0 (offset 0x18에 8바이트)
- stride 10개(각 4바이트), offset 0x20-0x47에 저장
- stride를 명시하지 않으면 기본값
1
- 동적 차원 10개(각 4바이트)
- 차원은 두 개씩 짝지어 64-bit slot 하나에 저장: (dim0, dim1), (dim2, dim3), ..., (dim8, dim9)
- 각 쌍에서 앞의 값이 64-bit slot의 하위 32비트를, 다음 값이 상위 32비트를 차지
- 합계: 96바이트 (포인터 8 + offset 8 + stride 40 + 차원 40)
-
텐서 뒤의 scalar (arg5-arg6): 텐서 다음에 이어지는 scalar들
arg5=7 (int16, 2바이트)
arg6=8 (int32, 4바이트)
- 순서대로 packing:
[arg5][arg6]
-
튜플 인자: int8 값 두 개를 담은 복합 타입
tuple_arg[0] = -1 (int8)
tuple_arg[1] = -2 (int8)
arg6 바로 뒤에 순서대로 저장
C++ 사용 예:
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
37
38
39
40 | InstructionTable instructionTable;
// 32-bit 정수 세 개
instructionTable.createAndPushArgument<ScalarType>(1); // arg0: int32
instructionTable.createAndPushArgument<ScalarType>(2); // arg1: int32
instructionTable.createAndPushArgument<ScalarType>(3); // arg2: int32
// packing될 더 작은 scalar들
instructionTable.createAndPushArgument<ScalarType>(
static_cast<std::int16_t>(4) // arg3: int16
);
instructionTable.createAndPushArgument<ScalarType>(
static_cast<std::int8_t>(5) // arg4: int8
);
// 동적 차원이 있는 텐서
std::vector<std::uint32_t> dynamicDims = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
instructionTable.createAndPushArgument<TensorType>(
reinterpret_cast<void *>(0x0123456789ABCD), // 예시 주소
dynamicDims
);
// 텐서 뒤에 오는 scalar들
instructionTable.createAndPushArgument<ScalarType>(
static_cast<std::int16_t>(7) // arg5: int16
);
instructionTable.createAndPushArgument<ScalarType>(
static_cast<std::int32_t>(8) // arg6: int32
);
// 마지막에 오는 튜플
std::vector<Argument *> tupleArgs = {
instructionTable.createArgument<ScalarType>(
static_cast<std::int8_t>(-1) // tuple.elem0
),
instructionTable.createArgument<ScalarType>(
static_cast<std::int8_t>(-2) // tuple.elem1
),
};
instructionTable.createAndPushArgument<TupleType>(tupleArgs);
|
실제 메모리 레이아웃
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | Offset | Bytes (little-endian) | Interpretation
-------|--------------------------|------------------------------------------
| 64-bit slot 0: Two int32 values (in order)
0x00 | 0x01 0x00 0x00 0x00 | arg0: int32 = 1
0x04 | 0x02 0x00 0x00 0x00 | arg1: int32 = 2
-------|--------------------------|------------------------------------------
| 64-bit slot 1: One int32, one int16, one int8 (in order)
0x08 | 0x03 0x00 0x00 0x00 | arg2: int32 = 3
0x0C | 0x04 0x00 | arg3: int16 = 4
0x0E | 0x05 | arg4: int8 = 5
0x0F | 0x00 | padding for tensor alignment
-------|--------------------------|------------------------------------------
| Tensor base address (8 bytes, little-endian)
0x10 | 0xcd 0xab 0x89 0x67 | Low 4 bytes of address
0x14 | 0x45 0x23 0x01 0x00 | High 4 bytes: 0x00 0x01 0x23 0x45
| | Full address: 0x0000_0123_4567_89AB_CD
-------|--------------------------|------------------------------------------
| Tensor offset (8 bytes, little-endian)
0x18 | 0x00 0x00 0x00 0x00 | Low 4 bytes of offset
0x1C | 0x00 0x00 0x00 0x00 | High 4 bytes of offset
-------|--------------------------|------------------------------------------
| Tensor strides (rank order, defaulted to 1)
0x20 | 0x01 0x00 0x00 0x00 | stride0 = 1
0x24 | 0x01 0x00 0x00 0x00 | stride1 = 1
0x28 | 0x01 0x00 0x00 0x00 | stride2 = 1
0x2C | 0x01 0x00 0x00 0x00 | stride3 = 1
0x30 | 0x01 0x00 0x00 0x00 | stride4 = 1
0x34 | 0x01 0x00 0x00 0x00 | stride5 = 1
0x38 | 0x01 0x00 0x00 0x00 | stride6 = 1
0x3C | 0x01 0x00 0x00 0x00 | stride7 = 1
0x40 | 0x01 0x00 0x00 0x00 | stride8 = 1
0x44 | 0x01 0x00 0x00 0x00 | stride9 = 1
-------|--------------------------|------------------------------------------
| Tensor dimensions (logical order: dim0, dim1, dim2, dim3, ...)
0x48 | 0x01 0x00 0x00 0x00 | dim0 = 1 (stored in low 32 bits of pair0)
0x4C | 0x02 0x00 0x00 0x00 | dim1 = 2 (stored in high 32 bits of pair0)
0x50 | 0x03 0x00 0x00 0x00 | dim2 = 3 (stored in low 32 bits of pair1)
0x54 | 0x04 0x00 0x00 0x00 | dim3 = 4 (stored in high 32 bits of pair1)
0x58 | 0x05 0x00 0x00 0x00 | dim4 = 5 (stored in low 32 bits of pair2)
0x5C | 0x06 0x00 0x00 0x00 | dim5 = 6 (stored in high 32 bits of pair2)
0x60 | 0x07 0x00 0x00 0x00 | dim6 = 7 (stored in low 32 bits of pair3)
0x64 | 0x08 0x00 0x00 0x00 | dim7 = 8 (stored in high 32 bits of pair3)
0x68 | 0x09 0x00 0x00 0x00 | dim8 = 9 (stored in low 32 bits of pair4)
0x6C | 0x0a 0x00 0x00 0x00 | dim9 = 10 (stored in high 32 bits of pair4)
-------|--------------------------|------------------------------------------
| 64-bit slot: int16, int32, tuple<int8,int8> (in order)
0x70 | 0x07 0x00 | arg5: int16 = 7
0x72 | 0x08 0x00 0x00 0x00 | arg6: int32 = 8
0x76 | 0xff | tuple.elem0: int8 = -1 (0xff = -1 in two's complement)
0x77 | 0xfe | tuple.elem1: int8 = -2 (0xfe = -2 in two's complement)
-------|--------------------------|------------------------------------------
Total: 120 bytes
|
구현 참고
- 명령어 테이블은 little-endian 순서로 인코딩합니다
- 포인터는 호스트 아키텍처와 무관하게 모두 64-bit입니다
- 동적 차원의 개수는 컴파일 시점에 알 수 있어야 합니다 (차원의 값 자체는 런타임에 정해짐)
- 명령어 테이블의 최대 크기는 함수 시그니처에서 정적으로 계산할 수 있습니다
- padding 바이트의 값은 정의되어 있지 않으므로 그 값에 의존해서는 안 됩니다