두 라이브러리, 한 API 모양
cuBLAS랑 MPSMatrixMultiplication은 다른 회사의 다른 product인데 본질적으로 같은 op 구현. 외울 만한 차이:
| 측면 | cuBLAS (NVIDIA) | MPS (Apple) |
|---|---|---|
| Layout default | Column-major (Fortran) | Row-major |
| Default 정밀도 focus | FP32, cublasGemmEx로 FP16/BF16 | Half-precision-first; FP32도 지원 |
| Lifecycle | Thread당 handle, default async | Dispatch당 command buffer, waitUntilCompleted에 sync |
| α/β scalar | 응 (full GEMM 시그니처) | 응 |
| Algorithm picker | cublasLt로 heuristic; algo ID로 manual | 라이브러리가 픽; 직접 통제 덜 |
cuBLAS 길의 룰
- Thread당 (또는 CUDA stream당)
cublasHandle_t하나 만들어; 호출 가로질러 재사용. - Default async — 다음 CPU 코드 전에 결과 필요하면
cudaStreamSynchronize호출. - Column-major 수학이라 대부분 C/C++ 사용자가 buffer transpose 대신
CUBLAS_OP_T로Cᵀ = Bᵀ · Aᵀ계산.
MPS 길의 룰
- Default row-major; numpy / Swift array가 자연스럽게 저장하는 방향이랑 동일.
- Command buffer lifecycle 명시적: encode, commit, wait. wait 단계 비선택.
- Half-precision
MPSMatrix가 first-class — inference엔 numerical stability 요구 없으면 FP16 선호.