Parallel Programming 1

Parallel Programming Abstractions

Intel SPMD Program Compiler (ISPC)

SPMD : Single Program Multiple Data

사용자가 지정한 코드의 형태에 따라 스칼라 방식과 벡터 방식으로 컴파일 함

 

SPMD programming abstraction

Call to ISPC function spawns “gang” of ISPC “program instances”

  • All instances run ISPC code concurrently
  • Each instance has its own copy of local variables

image

gang이라고 불리는 instance의 집합이 생겨나고, 각각의 instance가 ‘동시에’ ISPC코드를 실행한다.

programCount : gang의 크기

programIndex : gang 내 instance들의 index

Uniform : 모든 instances들이 공통으로 가지는 변수

ISPC compiler가 ISPC코드를 통해 binary file (.o)를 만들면 C++ code와 link하여 실행파일을 생성한다.

각 instance에 메모리를 할당하는 방식은 blocked 방식과 interleaved 방식이 있다.

image

interleaved 방식

image

blocked 방식

  • interleaved 방식에 비해 blocked 방식은 연속적이지 않은 메모리를 참조하므로 일반적으로 느리다.
  • foreach(i=0 … N)을 사용하면 ISPC가 parallel loop iteration이 있음을 인지하고 컴파일을 한다.

 

Abstraction vs Implementation

Abstraction

  • Programmer “thinks” : running a gang is spawning programCount logical instruction streams
  • API를 사용할 때 input, output에 관심이 있다.

Implementation

  • ISPC compiler handles mapping of conditional control flow to vector instructions
  • API가 어떻게 구현되는지, how something is done “under the hood”

 

지금까지의 내용은 multi-core환경에서 그 중 하나의 core에서 실행된다.

 

Shared address space model

메모리 기본 접근 단위 : byte

각각의 byte들은 memory내의 주소로 식별될 수 있다. (byte-addressable)

threads들이 communication을 하기위해 shared variables를 사용할 수도 있다.

하지만 mutual exclusion을 보장하기 위해 lock과 같은 synchronization을 위한 도구가 필요함

NUMA : Non-Uniform Memory Access

각 코어에서 메모리에 접근하는 latency에 차이가 있다.

Requires hardware support to implement efficiently

 

Message passing model of communication

threads communicate by sending/receiving messages

 

Data-parallel model

ISPC에서 foreach를 사용하면 각각의 instruction이 independent 하다는 것을 보장함

Data-parallel model provides no specification of order in which iterations occur