본문 바로가기
목차
CE

[CE] Compilation 의 종류

by ds31x 2024. 1. 18.
728x90
반응형

기존의 compilation

원래 compilation(컴파일)은

  • programming language로 작성된 소스코드(source code, 원시코드)를
  • 타겟 하드웨어에서 동작할 수 있는 기계 코드 (machine code, binary code, opcode)로 바꾸어주는 것을 의미했다.

https://dsaint31.me/mkdocs_site/CE/ch08/ce08_compiler_interpreter/

 

BME

Compiler Language and Interpreter Language compiled language 와 interpreted language라고도 불림. Compiler Language Compiler(High-level language를 machine language로 번역)를 사용하는 고급 언어. 프로그램 전체를 읽어들여 이를 o

dsaint31.me


오늘날 compilation

C, C++ 과 같은 프로그래밍 언어들이 채택한 방식으로

Basic등의 interperter를 사용하는 script언어와 구분된다.

 

하지만, interpreter 방식의 언어들의 성능향상을 위해서 JIT Compiler등을 사용하면서,

기존의 Compiler를 Static Compiler라고 부르면서 여러 종류의 compiler방식이 제안됨.

 


Compilation의 종류

아이콘들을 연결한 수평의 화살표들은 등장 순서를 의미하는 것임.

현재 많이 사용되는 컴파일은 다음 네가지임.

  • Static Compilation (정적컴파일):
    • source code(원시코드)를 빌드 과정에서
    • 곧바로 binary code 형태의 machine code로 변환.
  • Bytecode Compilation (바이트코드 컴파일):
    • source code를 VM등에서 동작하는 bytecode 로  변환
    • 초기 제안된 javac가 이에 해당함.
  • Just-In-Time Compilation (JIT 컴파일):
    • interpreter등에서 매번 실행될 때 source code를 해석하여 machine code로 바꾸던 것을 개선하여,
    • 최초 실행될 때에 machine code (or bytecode)로 바꾸고 이를 caching하여
    • 해당 source code가 변경되지 않는한 cached machine code를 사용하는 방식임.
  • Ahead-Of-Time Compilation (AOT 컴파일):
    • 빌드 과정에서 source code가 bytecode로 변경시키는 bytescode compilation을 하고 나서,
    • 얻은 결과물인 bytecode를 실행 전에 target H/W에서 동작 가능한 machine code미리 변환하는 방식임.

 

AOT 컴파일의 경우,

미리 machine code(=native code)로 바꾸기 때문에 

JIT 컴파일이 최초 실행시 지나치게 느린 단점을 개선하며,

Static Compilation이 가지고 있는 최적화를 수행할 수 있는 장점을 가짐.

 

PyTorch 로 작성된 계산 그래프 등을 TPU에서 실행시키도록 해주는 XLA (Accelerated Linear Algbra)는 JIT Compiler의 일종으로 분류되나 AOT 컴파일도 일부 채용하고 있음.

2024.03.21 - [Python] - [DL] PyTorch: TPU사용하기 - XLA

 

[DL] PyTorch: TPU사용하기 - XLA

https://github.com/pytorch/xla GitHub - pytorch/xla: Enabling PyTorch on XLA Devices (e.g. Google TPU)Enabling PyTorch on XLA Devices (e.g. Google TPU). Contribute to pytorch/xla development by creating an account on GitHub.github.com 다음 문서도 참

ds31x.tistory.com


같이 보면 좋은 자료들

2024.06.05 - [CE] - [CE] Bytecode (바이트코드)

 

[CE] Bytecode (바이트코드)

Bytecode (바이트코드)정의:Bytecode는 고수준 프로그래밍 언어로 작성된 source code를 중간 형태로 변환한 code 임.이는 특정 Virtual Machine (VM)에서 실행될 수 있도록 설계됨.가장 대표적인 예로 Java 및 Pyt

ds31x.tistory.com

https://dsaint31.tistory.com/496

 

[Python] Interpreter and PVM (Python Virtual Machine)

Interpreter and PVM (Python Virtual Machine)더보기대학을 막 졸업해서 초보 프로그래머로 일을 할 때 개인적으로 가지고 있던 편견 중 하나가 script language를 매우 하찮게 생각하면서 오직 compiler language

dsaint31.tistory.com

2024.04.22 - [CE] - [CE] Virtual Machine, Web Browser and Bytecode.

 

[CE] Virtual Machine, Web Browser and Bytecode.

Virtual Machine (가상 머신) An abstract computer with an incredibly complicated instruction set (=Bytecode)implemented entirely in software bytecode란?2024.06.05 - [CE] - [CE] Bytecode (바이트코드) [CE] Bytecode (바이트코드)Bytecode (바이

ds31x.tistory.com


 

728x90