Python API¶
1 | |
의미는 C++ API와 동일하며, 다른 부분만 C++ API와의 차이에
정리했습니다. 디바이스 포인터는 int입니다.
섹션¶
| 페이지 | 내용 |
|---|---|
| Device | 디바이스 탐색, 선택, 리셋 |
| Memory | 할당, 전송, 텐서 레이아웃, 호스트·디바이스 메모리 통계 |
| Execution | 커널 실행, 커널 라이브러리 로드와 핸들 실행 |
| Streams | 비동기 작업의 순서 있는 큐 |
| Events | 스트림 표식과 스트림 간 순서 |
| TLB | 정적 KV 캐시 TLB 초기화와 페이지 관리 |
| VMM | KV 캐시 가상 메모리. Bertha DC EVT0에서는 C++ API나 PyTorch 연산을 사용 |
| Sampling | 토큰 샘플링 파라미터 |
| Weight Converter | 가중치 텐서를 디바이스 메모리 레이아웃으로 변환 (hart.weight_converter) |
| Types | 열거형과 구조체. TLB 타입은 hart.hart에서 import |
C++ API와의 차이¶
| C++ | Python | |
|---|---|---|
| Failure reporting | Returns HaError |
Raises RuntimeError whose message ends in the HaError name and value (... : HaKernelNotFound (err=196612)) |
| Device pointers | HaDevicePtr |
int |
| Default stream | HA_STREAM_DEFAULT (nullptr) |
HA_STREAM_DEFAULT (0) |
| Host buffers | HaDevicePtr cast from a host pointer |
bytes or any buffer-protocol object |
HaLaunchKernel overloads |
Overloaded on binary path vs kernel handle (HaKernel_t) |
Separate functions: launch_kernel_with_binary_path, launch_kernel_with_handle (and their _async_ forms) |
| Library and kernel handles | HaLibrary_t, HaKernel_t |
int |
| Launch arguments | HaLaunchArgs object filled with HaLaunchArgsAdd*(), released when destroyed |
HaLaunchArgs object (add_*), released with the object |
| Memory statistics | HaHostMemStats / HaDeviceMemStats struct with struct_size |
dict[str, int] keyed by field name |
프로세스 종료¶
hart는 reset_all_devices()를 호출하는 atexit 훅을 등록하지만, 런타임이
실제로 초기화된 경우에만 동작합니다. hart를 import했지만 디바이스를 사용하지 않은
프로세스는 디바이스를 열지 않고 종료합니다.
이 훅보다 나중에 실행되면서 런타임을 건드리는 atexit 핸들러를 등록하지 마십시오.