KR20140119619A - Apparatus and method for generating vector code - Google Patents

Apparatus and method for generating vector code Download PDF

Info

Publication number
KR20140119619A
KR20140119619A KR1020130135611A KR20130135611A KR20140119619A KR 20140119619 A KR20140119619 A KR 20140119619A KR 1020130135611 A KR1020130135611 A KR 1020130135611A KR 20130135611 A KR20130135611 A KR 20130135611A KR 20140119619 A KR20140119619 A KR 20140119619A
Authority
KR
South Korea
Prior art keywords
vector
variable
code
type
kernel code
Prior art date
Application number
KR1020130135611A
Other languages
Korean (ko)
Inventor
이재진
나정호
준 이
이진석
김성건
유동훈
황석중
Original Assignee
삼성전자주식회사
서울대학교산학협력단
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 삼성전자주식회사, 서울대학교산학협력단 filed Critical 삼성전자주식회사
Priority to US14/228,868 priority Critical patent/US9367291B2/en
Publication of KR20140119619A publication Critical patent/KR20140119619A/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline or look ahead

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The present invention relating to a vector code generating device and a method thereof, generates a vector code by using a scalar type kernel code without changing a code type or revising data layout by a user, thus, user convenience is increased and portability of OpenCL can be uninfluenced.

Description

벡터 코드 생성 장치 및 방법{APPARATUS AND METHOD FOR GENERATING VECTOR CODE}[0001] APPARATUS AND METHOD FOR GENERATING VECTOR CODE [0002]

개방형 범용 병렬 컴퓨팅 프레임워크와 관련된다.Open universal parallel computing framework.

최근 모바일 컴퓨팅에서 성능 가속기의 사용이 점점 늘어남에 따라서 이러한 환경을 지원하기 위한 프로그래밍 모델이 각광을 받고 있다. 특히, 개방형 범용 병렬 컴퓨팅 프레임워크(이하, OpenCL)는 다양한 디바이스 및 아키텍처를 지원하여 동일한 하나의 프로그램을 여러 디바이스 및 아키텍처에서 실행할 수 있는 장점이 있다. 그러나, 작성된 프로그램이 성능 이식성을 갖기 위해서는 해당 아키텍처를 위한 추가적인 최적화가 필요하다는 어려움을 가지게 된다. Recently, as the use of performance accelerators in mobile computing has increased, a programming model for supporting such environments has become popular. In particular, an open universal parallel computing framework (hereinafter referred to as OpenCL) supports various devices and architectures, so that one program can be executed in various devices and architectures. However, in order for the written program to have performance portability, additional optimization is required for the corresponding architecture.

이에 대한 해결책으로 OpenCL의 최적화 컴파일러가 하나의 방안이 될 수 있다. 그러나, OpenCL 최적화 컴파일러는 벡터 코드 생성을 지원하지 않는다. 따라서 벡터 유닛을 활용하는 아키텍처에서는 사용자가 직접 커널 코드에 사용된 배열 및 변수를 벡터 타입의 배열 및 변수로 바꿔야 하며, 이에 따라서 각 워크 아이템이 담당하는 데이터 레이아웃도 변경해야 한다. As a solution, OpenCL's optimizing compiler can be a solution. However, the OpenCL optimizing compiler does not support vector code generation. Therefore, in an architecture that utilizes vector units, the user must directly replace the arrays and variables used in the kernel code with vector type arrays and variables, and thus change the data layout that each work item is responsible for.

또한, 직접 벡터 코드를 사용하도록 작성된 커널 코드는 특정 디바이스에서 지원하는 벡터 유닛의 특성에 맞추어 최적화되기 때문에 성능 이식성을 보장하기 어려운 경우가 많다.In addition, since kernel code written using direct vector code is optimized according to the characteristics of vector units supported by a specific device, it is often difficult to guarantee performance portability.

개방형 범용 병렬 컴퓨팅 프레임워크의 소스 수준에서 벡터 코드를 생성하기 위한 장치 및 방법을 제공하는 것을 목적으로 한다.It is an object of the present invention to provide an apparatus and method for generating vector codes at the source level of an open general purpose parallel computing framework.

일 양상에 따른 벡터 코드 생성 방법은 워크 아이템의 인스턴스를 표현하는 중첩 루프를 포함하는 스칼라 타입의 커널 코드에서 인덕션 변수 및 인덱스 변수를 검출하는 단계, 상기 인덕션 변수 및 상기 인덱스 변수에 기초하여 상기 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환 하기 위한 조건을 만족하는지를 판단하는 단계 및 상기 조건을 만족하는 경우, 상기 스칼라 타입의 커널 코드를 상기 벡터 타입의 코드로 변환하는 단계를 포함한다.A method of generating vector code according to an aspect includes the steps of detecting an induction variable and an index variable in a scalar type kernel code including a nested loop representing an instance of a work item, Determining whether a condition for converting the kernel code of the scalar type code into a vector type code is satisfied; and if the condition is satisfied, converting the scalar type kernel code to the vector type code.

상기 판단하는 단계는 상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값이 불연속적인 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.The determining step may determine that the condition is not satisfied when the index value of the array included in the scalar type kernel code is discontinuous.

상기 판단하는 단계는 상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값을 정적으로 분석 할 수 없는 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.The determining step may determine that the condition is not satisfied when the index value of the array included in the scalar type kernel code can not be statistically analyzed.

상기 판단하는 단계는 상기 스칼라 타입의 커널 코드가 프라이빗(private) 배열에 대한 접근을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.If the scalar type kernel code includes an access to a private array, the determining step may determine that the condition is not satisfied.

상기 판단하는 단계는 상기 스칼라 타입의 커널 코드가 사용자 정의 타입 변수 또는 빌트인 함수 이외의 함수 호출을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.The determining step may determine that the scalar type kernel code does not satisfy the condition when the kernel code includes a function call other than a user-defined type variable or a built-in function.

상기 변환하는 단계는 상기 스칼라 타입의 커널 코드에서 함수의 인자로 사용되는 변수 또는 상기 스칼라 타입의 커널 코드에서 정의된 변수 중 상기 인덕션 변수를 제외한 변수를 벡터 타입의 변수로 재선언하는 단계 및 상기 스칼라 타입의 커널 코드에서 벡터 타입으로 변환할 수 있는 구문에 사용된 변수 참조를 상기 재선언된 벡터 타입의 변수 참조로 변환하는 단계를 더 포함할 수 있다.Wherein the step of converting includes the steps of redefining a variable used as a parameter of the function in the scalar type kernel code or a variable defined in the kernel code of the scalar type except for the induction variable as a variable of a vector type, And converting the variable reference used in the syntax convertible from the kernel code of the type to the variable reference of the redefined vector type.

상기 벡터 타입으로 변환할 수 있는 구문은 상기 인덕션 변수가 배열의 인덱스로 사용되고, 조건 분기문이 아닌 구문일 수 있다.The syntax that can be converted into the vector type may be a syntax other than the conditional branch statement, in which the induction variable is used as the index of the array.

상기 변환하는 단계는 상기 중첩 루프 중 최내각 루프의 인덕션 변수 및 배열의 인덱스로 사용된 인덕션 변수에 벡터화 팩터를 적용하는 단계를 더 포함할 수 있다.The transforming step may further include applying a vectorization factor to an induction variable used as an index of an induction variable and an array of an innermost loop of the overlapping loop.

상기 적용하는 단계는 상기 배열의 인덱스로 사용된 인덕션 변수를 상기 벡터화 팩터로 나누고, 상기 최내각 루프의 인덕션 변수 증가값을 상기 백터화 팩터로 변경할 수 있다.The applying step may divide the induction variable used as the index of the array by the vectorization factor and change the induction variable increase value of the array of the innermost loop to the vectorization factor.

상기 변환하는 단계는 상기 스칼라 타입의 커널 코드 중 상기 벡터 타입으로 변환할 수 없는 구문을 복사하는 단계를 더 포함할 수 있다.The converting step may further include copying a syntax of the scalar type kernel code that can not be converted into the vector type.

상기 변환하는 단계는 상기 스칼라 타입의 커널 코드가 조건 분기문을 포함하는 경우, 상기 조건 분기문을 벡터화 팩터만큼 복사하고, 복사된 조건 분기문에 포함된 변수 및 배열에 대한 접근을 순차적인 벡터 엘리먼트에 대한 접근으로 변환하는 단계를 더 포함할 수 있다.Wherein the step of converting includes copying the conditional branch statement by an vectorization factor when the scalar type kernel code includes a conditional branch statement and accessing the variables and arrays included in the copied conditional branch statement by using a sequential vector element To an access to the < / RTI >

일 양상에 따른 벡터 코드 생성 장치는 프로세서, 상기 프로세서를 이용하여 워크 아이템의 인스턴스를 표현하는 중첩 루프를 포함하는 스칼라 타입의 커널 코드에서 인덕션 변수 및 인덱스 변수를 검출하는 분석부, 상기 프로세서를 이용하여 상기 인덕션 변수 및 상기 인덱스 변수에 기초하여 상기 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환 하기 위한 조건을 만족하는지를 판단하는 판단부 및 상기 조건을 만족하는 경우, 상기 프로세서를 이용하여 상기 스칼라 타입의 커널 코드를 상기 벡터 타입의 코드로 변환하는 벡터 코드 생성부를 포함한다.An apparatus for generating a vector code according to an aspect of the present invention includes a processor, an analyzing unit for detecting an induction variable and an index variable in a scalar type kernel code including a nested loop expressing an instance of a work item using the processor, A determination unit for determining whether a condition for converting the scalar type kernel code into a vector type code is satisfied based on the induction variable and the index variable, And a vector code generation unit for converting the kernel code into the vector type code.

상기 판단부는 상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값이 불연속적인 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.The determining unit may determine that the condition is not satisfied when the index value of the array included in the scalar type kernel code is discontinuous.

상기 판단부는 상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값을 정적으로 분석 할 수 없는 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.If the index value of the array included in the kernel code of the scalar type can not be statistically analyzed, the determination unit may determine that the condition is not satisfied.

상기 판단부는 상기 스칼라 타입의 커널 코드가 프라이빗(private) 배열에 대한 접근을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.If the scalar type kernel code includes access to a private array, the determination unit may determine that the condition is not satisfied.

상기 판단부는 상기 스칼라 타입의 커널 코드가 사용자 정의 타입 변수 또는 빌트인 함수 이외의 함수 호출을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단할 수 있다.If the kernel code of the scalar type includes a function call other than a user-defined type variable or a built-in function, the determination unit may determine that the condition is not satisfied.

상기 벡터 코드 생성부는 상기 스칼라 타입의 커널 코드에서 함수의 인자로 사용되는 변수 또는 상기 스칼라 타입의 커널 코드에서 정의된 변수 중 상기 인덕션 변수를 제외한 변수를 벡터 타입의 변수로 재선언하고, 상기 스칼라 타입의 커널 코드에서 벡터 타입으로 변환할 수 있는 구문에 사용된 변수 참조를 상기 재선언된 벡터 타입의 변수 참조로 변환할 수 있다.Wherein the vector code generation unit redefines a variable used as a parameter of the function in the scalar type kernel code or a variable defined in the scalar type kernel code except for the induction variable as a vector type variable, A variable reference used in a syntax that can be converted from a kernel code of a vector type to a variable reference of the redefined vector type.

상기 벡터 타입으로 변환할 수 있는 구문은 상기 인덕션 변수가 배열의 인덱스로 사용되고, 조건 분기문이 아닌 구문일 수 있다.The syntax that can be converted into the vector type may be a syntax other than the conditional branch statement, in which the induction variable is used as the index of the array.

상기 벡터 코드 생성부는 상기 중첩 루프 중 최내각 루프의 인덕션 변수 및 배열의 인덱스로 사용된 인덕션 변수에 벡터화 팩터를 적용할 수 있다.The vector code generation unit may apply a vectorization factor to an induction variable used as an index of an induction variable and an array of an innermost loop of the overlapping loop.

상기 벡터 코드 생성부는 상기 배열의 인덱스로 사용된 인덕션 변수를 상기 벡터화 팩터로 나누고, 상기 최내각 루프의 인덕션 변수 증가값을 상기 백터화 팩터로 변경할 수 있다.The vector code generator may divide the induction variable used as the index of the array by the vectorization factor and change the increase factor of the induction variable of the innermost loop to the vectorization factor.

상기 벡터 코드 생성부는 상기 스칼라 타입의 커널 코드 중 상기 벡터 타입으로 변환할 수 없는 구문을 복사할 수 있다.The vector code generation unit may copy a syntax of the scalar type kernel code that can not be converted into the vector type.

상기 벡터 코드 생성부는 상기 스칼라 타입의 커널 코드가 조건 분기문을 포함하는 경우, 상기 조건 분기문을 벡터화 팩터만큼 복사하고, 복사된 조건 분기문에 포함된 변수 및 배열에 대한 접근을 순차적인 벡터 엘리먼트에 대한 접근으로 변경할 수 있다.Wherein the vector code generation unit copies the conditional branch statement by a vectorization factor when the scalar type kernel code includes a conditional branch statement and accesses the variables and arrays included in the copied conditional branching instruction to the sequential vector elements Can be changed to access to.

사용자에 의한 코드 타입의 변경이나 데이터 레이아웃의 수정 없이 스칼라 타입의 커널 코드를 벡터 타입으로 변환하여 해당 벡터 타입을 지원하는 모든 아키텍처에서 사용될 수 있는 벡터 코드를 생성함으로써, 사용자의 편의성을 증대시키고, OpenCL의 이식성을 유지할 수 있다.By converting a scalar type kernel code into a vector type without changing a code type or a data layout by a user and generating a vector code that can be used in all architectures that support the corresponding vector type, Can be maintained.

도 1은 OpenCL 프로그램이 동작하는 시스템 구조의 일 예를 나타내는 도면,
도 2(a) 및 2(b)는 사용자가 OpenCL 커널 코드의 변수를 벡터 타입의 변수로 수정하는 경우의 예시도,
도 3은 일 실시예에 따른 벡터 코드 생성 장치(300)의 구성도,
도 4(a) 내지 도 4(d)는 일 실시예에 따른 벡터 코드 생성을 설명하기 위한 도면,
도 5는 일 실시예에 따른 조건 분기문에 대한 벡터 코드 생성을 설명하기 위한 도면,
도 6(a) 내지 도 6(d)는 또 다른 실시예에 따른 벡터 코드 생성을 설명하기 위한 도면,
도 7은 일 실시예에 따른 스칼라 타입의 커널 코드로부터 벡터 코드 생성 가능 여부를 판단하는 과정을 나타낸 순서도,
도 8은 일 실시예에 따른 벡터 코드 생성 과정을 나타낸 순서도이다.
1 is a diagram showing an example of a system structure in which an OpenCL program operates;
2 (a) and 2 (b) illustrate examples in which a user modifies a variable of an OpenCL kernel code into a variable of a vector type,
3 is a block diagram of a vector code generation apparatus 300 according to an embodiment,
4 (a) to 4 (d) are diagrams for explaining vector code generation according to an embodiment,
5 is a diagram for explaining vector code generation for a conditional branch statement according to an embodiment;
6 (a) to 6 (d) are diagrams for explaining vector code generation according to another embodiment,
7 is a flowchart illustrating a process for determining whether a vector code can be generated from a scalar type kernel code according to an exemplary embodiment.
8 is a flowchart illustrating a vector code generation process according to an embodiment of the present invention.

이하, 첨부된 도면을 참조하여 실시예를 상세히 기술하기로 한다.Hereinafter, embodiments will be described in detail with reference to the accompanying drawings.

도 1은 OpenCL 프로그램이 동작하는 시스템 구조의 일 예를 나타내는 도면이다.1 is a diagram showing an example of a system structure in which an OpenCL program operates.

OpenCL 프로그램은 도 1에 도시된 바와 같이, 호스트 프로세서(110) 및 하나 이상의 컴퓨트 디바이스(120, 130, 140, 150)를 포함하는 플랫폼에서 동작한다.The OpenCL program operates on a platform that includes a host processor 110 and one or more compute devices 120,130, 140,150, as shown in FIG.

컴퓨트 디바이스(120, 130, 140, 150)는 하나 이상의 컴퓨트 유닛을 포함한다. 예를 들어, 컴퓨트 디바이스(120)는 복수 개의 컴퓨트 유닛(121, 122, 123)을 포함할 수 있다. 각 컴퓨트 유닛은 하나 이상의 프로세싱 엘리먼트들을 포함한다. 일 예로, 컴퓨트 유닛(121)은 프로세싱 엘리먼트(10, 20, 30)를 포함할 수 있다. 여기에서, 프로세싱 엘리먼트는 스칼라 프로세서 또는 벡터 프로세서일 수 있다. 각각의 프로세싱 엘리먼트(10, 20, 30)는 프라이빗 메모리(11, 21, 31)를 각각 포함할 수 있다.The compute devices 120, 130, 140, 150 include one or more compute units. For example, the compute device 120 may include a plurality of compute units 121, 122, and 123. Each compute unit includes one or more processing elements. As an example, the compute unit 121 may include processing elements 10,20, 30. Here, the processing element may be a scalar processor or a vector processor. Each processing element 10, 20, 30 may include a private memory 11, 21, 31, respectively.

OpenCL 프로그램은 호스트 프로세서에서 실행되는 호스트 프로그램이 커널을 디바이스에서 실행하는 형태이다. OpenCL 애플리케이션은 호스트 프로그램 및 커널들로 구성된다.The OpenCL program is a host program that runs on the host processor that executes the kernel on the device. An OpenCL application consists of a host program and kernels.

호스트 프로그램은 호스트 프로세서(110)상에서 동작하며, 컴퓨트 디바이스내(120)의 프로세싱 엘리먼트들(10, 20, 30)에서 수행되는 명령어들 또는 메모리 오브젝트들을 조작하는 명령어들을 출력한다.The host program operates on the host processor 110 and outputs instructions for manipulating the instructions or memory objects performed in the processing elements 10, 20, 30 in the compute device 120.

커널(kernel)은 OpenCL 디바이스에서 실행되는 함수를 의미한다. 커널은 커널 코드 또는 커널 함수로 불릴 수 있으며, 이하에서는 커널 코드라 한다. 커널 코드는 복수 개의 스테이트먼트(statement)로 구성될 수 있다. 호스트 프로그램이 커널 코드를 실행할 때에는, 워크 그룹의 수와 워크 아이템 의 수를 지정한다. A kernel is a function that runs on an OpenCL device. The kernel may be referred to as kernel code or kernel functions, hereinafter referred to as kernel code. The kernel code may be composed of a plurality of statements. When the host program executes the kernel code, it specifies the number of work groups and the number of work items.

워크 그룹은 워크 아이템들의 집합을 말한다. 워크 아이템은 병렬 실행되는 커널 코드의 실행 단위이며, 워크 그룹은 하나 이상의 워크 아이템을 포함한다. 하나의 워크 그룹은 하나의 컴퓨트 유닛에 할당되며, 컴퓨트 유닛에 할당된 워크 그룹에 포함된 각각의 워크 아이템은 하나 이상의 가상 엘리먼트들에서 동시에 실행되는 것처럼 동작한다.A workgroup is a collection of work items. A work item is a unit of execution of kernel code executed in parallel, and a work group contains one or more work items. One work group is assigned to one compute unit and each work item included in the work group assigned to the compute unit acts as if it is executed simultaneously on one or more virtual elements.

OpenCL에서 커널 코드는 호스트 프로그램에 의해 n차원 추상적 인덱스 공간(n-dimensional abstract index space)으로 정의된다. 여기에서, n은 1≤n≤3의 범위에 있다. 인덱스 공간에서 각 포인트는 각 차원이 0에서 시작하는, n??튜플 정수(n-tuple of integers)로 특정된다. 각 포인터는 워크 아이템으로 불리는 커널의 실행 인스턴스와 관련된다.In OpenCL, the kernel code is defined by the host program as an n-dimensional abstract index space. Here, n is in the range of 1? N? 3. In the index space, each point is specified by n ?? tuple of integers, where each dimension starts at zero. Each pointer is associated with a running instance of the kernel called a work item.

n-튜플은 대응하는 워크 아이템의 글로벌 ID를 나타낸다. 각 워크 아이템은 자신의 글로벌 ID를 질의할 수 있고, 글로벌 ID에 따라서 상이한 태스크를 수행하고 상이한 데이터를 액세스할 수 있다. The n-tuple represents the global ID of the corresponding work item. Each work item can query its global ID, perform different tasks according to its global ID, and access different data.

각 워크 그룹은 n-튜플인 유일한 ID를 가진다. 길이 n의 정수 어레이는 인덱스 공간의 각 차원에서 워크 그룹들의 개수를 특정한다. 워크 그룹에서 워크 아이템은 워크 그룹 내에 유일한 로컬 ID로 할당되고, 전체 워크 그룹을 로컬 인덱스 공간으로서 처리한다. 워크 아이템의 글로벌 ID는 그 로컬 ID 및 워크 그룹 ID로 계산될 수 있다. 워크 그룹에서 워크 아이템들은 동시에 하나의(single) 컴퓨트 유닛의 프로세싱 엘리먼트들 상에서 동시에 동작한다.Each workgroup has a unique ID that is an n-tuple. An integer array of length n specifies the number of workgroups in each dimension of the index space. In a work group, the work item is assigned a unique local ID within the work group, and the entire work group is treated as a local index space. The global ID of the work item can be calculated by its local ID and work group ID. Workgroups in a workgroup simultaneously operate simultaneously on the processing elements of a single compute unit.

OpenCL은 4개의 구별되는 메모리 영역 즉, 글로벌(global), 컨스턴트(constant), 로컬(local) 및 프라이빗(private)을 정의한다. 컴퓨트 디바이스 메모리는 글로벌 메모리 영역 및 컨스턴트 메모리 영역들로 구성된다. 커널은 컨스턴트 메모리 및 로컬 메모리에 메모리 오브젝트들을 정적으로 할당할 수 있다. OpenCL defines four distinct memory areas: global, constant, local, and private. The compute device memory consists of a global memory area and a constant memory area. The kernel can statically allocate memory objects to both constant memory and local memory.

로컬 메모리는 동일한 워크 그룹에서 모든 워크 아이템들에 의해 공유된다. 반면, 프라이빗 메모리는 하나의 워크 아이템에 국소적(local)이며, 프로세싱 엘리먼트에 포함된다.Local memory is shared by all work items in the same work group. On the other hand, the private memory is local to one work item and is included in the processing element.

OpenCL에 의해 정의된 메모리 영역들은 워크 아이템들에 의해 접근가능하며, OpenCL C는 이들 메모리를 구별 짓는 4개의 어드레스 공간 수식어(qualifier) 즉, __global, __constant, __local 및 __private를 가진다. 이러한 어드레스 공간 수식어는 커널 코드에서 변수 선언(declaration)에 이용된다.Memory regions defined by OpenCL are accessible by work items, and OpenCL C has four address space qualifiers: __global, __constant, __local, and __private to distinguish these memories. These address space qualifiers are used in variable declarations in kernel code.

OpenCL은 다양한 디바이스 및 아키텍처에서 실행 가능하도록 하는 것을 목적으로 하므로, 작성된 커널 코드는 모든 아키텍처에서 실행되어야 한다. 이를 위해, 소스 레벨 번역 방법을 사용하는 OpenCL 최적화 컴파일러를 이용할 수 있다. OpenCL 최적화 컴파일러는 예를 들어, 워크 아이템 합체(work-item coalescing)와 같이 아키텍처에 따라 최상의 성능을 이끌어낼 수 있는 방법을 이용하고 있다. Since OpenCL is intended to be executable on a variety of devices and architectures, the generated kernel code must be executed on all architectures. To do this, you can use the OpenCL optimizing compiler, which uses a source-level translation method. The OpenCL optimization compiler uses a way to get the best performance out of the architecture, such as work-item coalescing, for example.

예를 들어, OpenCL 최적화 컴파일러는 워크 아이템 합체 루프로 감싸질 수 있는 커널 코드 영역을 식별한다, 이후, OpenCL 최적화 컴파일러는 변수 확장을 적용하여 워크 아이템 합체 루프로 식별된 커널 코드 영역을 감쌈으로써 3 중첩 루프를 생성한다.For example, the OpenCL optimization compiler identifies the kernel code area that can be wrapped in a work item combination loop. The OpenCL optimization compiler then applies the variable extension to wrap the kernel code area identified by the work item combination loop, Create a loop.

그러나, 이 경우, 벡터 유닛을 활용하는 아키텍처에서는 사용자가 직접 코드를 벡터 코드 형태로 수정하여야 하는 문제가 있다. 예를 들어, 도 2(a)를 참조하면, 스칼라 타입의 배열 및 변수를 사용하는 커널 코드를 벡터 유닛에서 사용하고자 하는 경우, 도 2(b)에 도시된 예와 같이 사용자가 커널 코드에 사용된 스칼라 타입의 변수 및 상수 리터럴(literal)의 타입을 벡터 타입(int 4)으로 수정하여야 한다. However, in this case, in the architecture utilizing the vector unit, the user has to directly modify the code into the vector code form. For example, referring to FIG. 2 (a), when a kernel code using a scalar type array and variables is to be used in a vector unit, as shown in FIG. 2 (b) The type of a scalar type variable and constant literal must be modified to a vector type (int 4).

그러나, 도 2(b)에 도시된 예와 같이 변수의 타입을 벡터 타입으로 변경하는 경우, 변경된 커널 코드는 특정 디바이스에서 지원하는 벡터 유닛의 특성에 맞게 최적화된다. 이 경우, 변경된 커널 코드는 벡터 유닛을 포함하지 않는 장치에서는 사용할 수 없게 되며, OpenCL의 장점인 이식성이 떨어지게 된다. However, when the type of the variable is changed to the vector type as in the example shown in FIG. 2 (b), the changed kernel code is optimized according to the characteristics of the vector unit supported by the specific device. In this case, the modified kernel code can not be used in a device that does not include a vector unit, and the portability, which is an advantage of OpenCL, is lowered.

또한, 워크 아이템 합체는 단순히 중첩 루프를 만들어줄 뿐 메모리 접근에 대한 인덱스 크기를 줄여주지 않는다. 이로 인해, 벡터 타입을 사용하여 한번에 접근할 수 있는 메모리 크기가 커지므로, 메모리 영역을 벗어난 접근이 발생할 수 있다. 이러한 문제점을 방지하기 위해서는 사용자가 직접 호스트 프로그램에서 global work size를 수정하여 메모리 레이아웃(memory layout)을 사용자가 변경해 주어야 한다.Also, work item aggregation simply creates a nested loop, but does not reduce the index size for memory accesses. Because of this, the memory size that can be accessed at a time using the vector type becomes large, so access to the memory area may occur. To prevent this problem, the user must modify the global work size in the host program to change the memory layout.

도 3은 일 실시예에 따른 벡터 코드 생성 장치(300)의 구성도이다. 3 is a block diagram of a vector code generation apparatus 300 according to an embodiment.

벡터 코드 생성 장치(300)는 워크 아이템의 인스턴스를 표현하는 중첩 루프를 포함하는 스칼라 타입의 커널 코드를 이용하여 벡터 코드를 생성할 수 있다. 이때, 중첩 루프는 예를 들어, 한국 공개 특허 공보 제 10-2011-0077720호에 개시된 워크 아이템 합체(work-item coalescing)기법을 이용하여 생성될 수 있다. The vector code generating apparatus 300 may generate the vector code using a scalar type kernel code including a nested loop representing an instance of the work item. At this time, the nested loop can be generated using a work-item coalescing technique disclosed in, for example, Korean Patent Laid-Open No. 10-2011-0077720.

도 3을 참조하면, 일 실시예에 따른 벡터 코드 생성 장치(300)는 분석부(310), 판단부(320) 및 벡터 코드 생성부(330)를 포함할 수 있다. Referring to FIG. 3, the vector code generation apparatus 300 may include an analysis unit 310, a determination unit 320, and a vector code generation unit 330.

분석부(310)는 스칼라 타입의 커널 코드에서 워크 아이템 ID에 해당하는 인덕션 변수 및 인덱스 변수를 검출할 수 있다. 인덕션 변수는 루프의 반복마다 고정된 양으로 증가하거나 감소하는 변수 또는 다른 인덕션 변수의 선형 함수(linear function)를 의미한다. 예를 들어, for (i=0; i<10; ++i) {j=17+i;}와 같은 구문이 있는 경우, i 및 j는 인덕션 변수가 된다. The analyzer 310 may detect an index variable and an induction variable corresponding to the work item ID in the scalar type kernel code. An induction variable is a linear function of a variable or other induction variable that increases or decreases by a fixed amount every loop iteration. For example, if there is a statement such as for (i = 0; i <10; ++ i) {j = 17 + i;}, i and j become induction variables.

인덱스 변수는 배열에서 위치를 나타내는 변수를 의미한다. 예를 들어, int A[10]; A[i]=5;와 같은 구문이 있는 경우, i는 인덱스 변수가 된다.An index variable is a variable that represents a position in an array. For example, int A [10]; If there is a statement such as A [i] = 5; i becomes an index variable.

커널 코드를 수행하는 워크 아이템의 인스턴스는 3차원 인덱스 공간에 대한 중첩 루프로 표현된다. 이때, 최내각 루프의 각 반복(iteration)은 OpenCL 표준에 정의된 바와 같이 독립적으로 수행 가능하므로 벡터 코드 생성의 대상이 될 수 있다. 또한, 워크 아이템 아이디는 결국 중첩 루프에서 최내각 루프의 인덱스 변수에 대한 식으로 표현될 수 있다. 따라서, 분석부(310)는 스칼라 타입의 커널 코드에서 워크 아이템 ID에 해당하는 인덕션 변수와 인덱스 변수를 검출할 수 있다. An instance of a work item that executes kernel code is represented as a nested loop over a three-dimensional index space. At this time, each iteration of the innermost loop can be independently performed as defined in the OpenCL standard, and thus can be subject to vector code generation. In addition, the work item ID can be expressed as an expression for an index variable of the innermost loop in a nested loop. Accordingly, the analyzer 310 can detect the index variable and the induction variable corresponding to the work item ID in the scalar type kernel code.

판단부(320)는 검출된 인덕션 변수 및 인덱스 변수에 기초하여 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환할 수 있는지 여부를 판단할 수 있다. 구체적으로, 벡터 타입의 코드는 연속된 스칼라 값들을 벡터 값으로 묶는 것이므로, 배열의 인덱스 값은 연속적이어야 하고, 동적으로 변하지 않아야 한다. 따라서, 스칼라 타입의 커널 코드를 벡터 타입의 코드를 생성하기 위해서는 다음과 같은 1) 내지 4)의 조건을 만족하여야 한다. The determination unit 320 can determine whether or not the scalar type kernel code can be converted into the vector type code based on the detected induction variable and the index variable. Specifically, vector type code is to concatenate successive scalar values into vector values, so the index value of the array must be continuous and not dynamically changed. Therefore, in order to generate a scalar type kernel code as a vector type code, the following conditions 1) to 4) must be satisfied.

1) 배열(array)의 인덱스가 컴파일러에 의해 정적으로 분석 가능한 수식으로 표현되어야 한다. 1) The index of the array must be represented by a statically parsable expression by the compiler.

예를 들어, out [yid*w+xid]=col;와 같은 구문이 있다고 가정하면, 배열의 인덱스를 표현한 수식은 yid*w+xid이다. 여기서 yid와 xid는 중첩 루프에 대한 인덱스 변수이며, 특히 xid는 최내각 루프에 대한 인덱스 변수이다. 또한, w는 커널 함수의 인자이다. 즉, yid, xid 및 w는 컴파일러에 의한 컴파일 시에 알 수 있는 값이므로, yid*w+xid는 컴파일러에 의해 정적으로 분석 가능하다.For example, assuming you have a syntax like out [yid * w + xid] = col; the expression that represents the array index is yid * w + xid. Where yid and xid are index variables for nested loops, and xid is an index variable for the innermost loop. Also, w is a parameter of the kernel function. That is, yid, xid, and w are known values at compile time, so yid * w + xid can be analyzed statically by the compiler.

반면, out [yid*val+xid]=col;와 같은 구문이 있다고 가정하면, 배열의 인덱스를 표현한 수식은 yid*val+xid이다. 여기서, val는 메모리에서 읽어온 값이다. 이 경우, val의 값은 수행시간에 결정되기 때문에 컴파일 시에는 변수 val의 값을 알 수 없다. 따라서, yid*val+xid는 컴파일러에 의해 정적으로 분석할 수 없다. On the other hand, assuming there is a syntax like out [yid * val + xid] = col; the expression that expresses the array index is yid * val + xid. Where val is the value read from memory. In this case, since the value of val is determined at execution time, the value of the variable val can not be known at compile time. Therefore, yid * val + xid can not be parsed statically by the compiler.

2) 배열의 인덱스를 표현한 수식의 결과가 최내각 루프의 각 반복(iteration)에 대해서 연속된 값을 가져야 한다.2) The result of the expression representing the index of the array must have a continuous value for each iteration of the innermost loop.

예를 들어, out [yid*w+xid]=col;의 경우, yid*w+xid가 최내각 루프의 반복에 대해 연속된 값을 가진다.For example, in the case of out [yid * w + xid] = col; yid * w + xid has successive values for the iteration of the innermost loop.

반면, out [yid* w+xid*2]=col;의 경우, 각각의 워크 아이템이 연속된 값이 아닌 2의 배수로 배열에 접근하게 되므로, 배열의 인덱스를 표현한 수식의 결과가 최내각 루프의 반복에 대해 연속된 값을 가지지 않는다.On the other hand, in the case of out [yid * w + xid * 2] = col; each workitem approaches the array in multiples of 2 rather than consecutive values, so the result of the expression It does not have consecutive values for iteration.

3) 배열의 인덱스로 쓰인 변수가 인덕션 변수가 아닌 경우, 해당 변수는 루프 불변 값을 가져야 한다.3) If a variable written as an array index is not an induction variable, the variable must have a loop invariant value.

예를 들어, out [yid*w+xid]=col;의 경우, 인덕션 변수가 아닌 w가 배열의 인덱스를 표현한 수식에 사용되었으나, w는 커널 함수의 인자로서, 루프 불변 값이므로, 3)의 요건을 만족한다.For example, in the case of out [yid * w + xid] = col; w is used as an argument for expressing the index of an array, but w is an argument of the kernel function. Meets the requirements.

반면, out [yid*val+xid]=col;의 경우, 변수 val 값은 수행시간에 메모리에 저장된 값으로 결정되므로, 위의 2) 조건을 만족하는지 확인이 어렵다. 따라서, 이 경우, 벡터 코드의 생성이 불가능하다.On the other hand, in the case of out [yid * val + xid] = col; it is difficult to confirm whether the val value of the variable satisfies the above 2) condition because it is determined by the value stored in memory at the execution time. Therefore, in this case, it is impossible to generate the vector code.

4) 프라이빗(private) 배열에 대한 접근이나 사용자에 의해 정의된 변수의 사용이 없어야 하며, 빌트인(built-in) 함수 외의 다른 함수의 사용이 없어야 한다. 4) There should be no access to private arrays, no user-defined variables, and no use of any other function than the built-in function.

판단부(320)는 스칼라 타입의 커널 코드가 위의 4가지 조건을 모두 만족하는 경우, 벡터 타입의 코드로 변환 가능한 것으로 판단할 수 있다. The determination unit 320 can determine that the scalar type kernel code can be converted into a vector type code when all four conditions are satisfied.

벡터 코드 생성부(330)는 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환 가능하다고 판단된 경우, 스칼라 타입의 커널 코드에 포함된 구문을 벡터 타입의 구문으로 변환할 수 있다. If it is determined that the scalar type kernel code can be converted into the vector type code, the vector code generation unit 330 can convert the syntax included in the scalar type kernel code into the vector type syntax.

구체적으로, 벡터 코드 생성부(330)는 스칼라 타입의 커널 코드에서 함수의 인자로 사용된 변수 또는 스칼라 타입의 커널 코드에서 정의된 지역 변수 중 상기 인덕션 변수를 제외한 변수를 벡터 타입의 변수로 재선언할 수 있다. Specifically, the vector code generation unit 330 redefines a variable used as a function argument in the scalar-type kernel code or a variable other than the induction variable among local variables defined in the scalar-type kernel code as a variable of a vector type can do.

또한, 벡터 코드 생성부(330)는 스칼라 타입의 커널 코드에서 벡터 타입으로 변환할 수 있는 구문에 포함된 변수 참조를 재선언된 벡터 타입의 변수 참조로 변환할 수 있다. 이때, 벡터 타입으로 변환할 수 있는 구문은 예를 들어, 인덕션 변수가 배열의 인덱스로 사용되고 조건 분기가 아닌 구문을 포함할 수 있다.In addition, the vector code generation unit 330 may convert a variable reference included in a syntax that can be converted from a scalar type kernel code into a vector type to a variable reference of a redefined vector type. At this time, the syntax that can be converted into a vector type may include, for example, an induction variable used as an index of an array and not a conditional branch.

벡터 코드 생성부(330)는 스칼라 타입의 커널 코드에서 배열의 인덱스로 사용된 인덕션 변수 및 최내각 루프의 인덕션 변수에 팩터화 팩터를 적용할 수 있다. 구체적으로, 벡터 코드 생성부(330)는 인덕션 변수가 배열의 인덱스로 사용된 경우, 배열의 인덱스를 표현하는 수식이 벡터화 팩터(vectorization factor)만큼 나누어 지도록 변환할 수 있다. 또한, 벡터 코드 생성부(330)는 최내각 루프의 인덕션 변수가 최내각 루프의 인덕션 변수 증가값을 벡터화 팩터로 변경할 수 있다. 이때, 벡터화 팩터는 하드웨어에서 지원하는 벡터 사이즈에 따라 결정될 수 있다. 예를 들어, 16bytes의 벡터를 지원하는 것으로 가정하면, int의 경우 4, short의 경우 8, char의 경우 16이 벡터화 팩터가 된다. The vector code generation unit 330 may apply the factorization factor to the induction variable used as the index of array in the scalar type kernel code and the induction variable of the innermost loop. Specifically, when the induction variable is used as the index of the array, the vector code generator 330 may convert the expression representing the index of the array to be divided by a vectorization factor. In addition, the vector code generation unit 330 may change the induction variable of the innermost loop to the vectorization factor of the induction variable of the innermost loop. At this time, the vectorization factor may be determined according to the vector size supported by the hardware. For example, assuming that it supports a 16-byte vector, the vectorization factor is 4 for int, 8 for short, and 16 for char.

한편, 벡터 코드 생성부(330)는 스칼라 타입의 커널 코드 중에서 벡터 타입으로 변환할 수 없는 구문을 코드 복사 기법을 이용하여 복사할 수 있다. 일 실시예에 따르면, 스칼라 타입의 커널 코드가 조건 분기문을 포함하는 경우, 벡터 코드 생성부(330)는 조건 분기문을 벡터화 팩터만큼 복사할 수 있다. 또한, 벡터 코드 생성부(330)는 복사된 조건 분기문에서 사용된 변수 및 배열에 대한 접근 코드를 순차적인 벡터 엘리먼트에 대한 접근으로 변경할 수 있다.On the other hand, the vector code generation unit 330 can copy the syntax that can not be converted into the vector type from the scalar type kernel code by using the code copy technique. According to one embodiment, when the scalar type kernel code includes a conditional branch statement, the vector code generation unit 330 may copy the conditional branch statement by a vectorization factor. In addition, the vector code generator 330 may change access codes for the variables and arrays used in the copied conditional branching to access to the sequential vector elements.

한편, 일 실시예에 따르면, 도 3에 도시된 벡터 코드 생성 장치(300)는 프로그램 코드들의 집합 및 프로그램 코드들을 실행하는 마이크로프로세서로 구현될 수 있다. 예를 들어, 도 3에 도시된 벡터 코드 생성 장치(300)의 각 구성들은 호스트 프로세서(100)에 의해 실행되는 프로그램 코드의 특정한 집합일 수 있다. 또한, 벡터 코드 생성 장치(300)의 각 구성들은 프로세서 상에서 프로그램 코드가 구현하는 기능을 표현하며, 구체적인 동작에 있어 명확하게 구분되지 않을 수 있다.On the other hand, according to one embodiment, the vector code generation apparatus 300 shown in FIG. 3 may be implemented as a microprocessor that executes a set of program codes and program codes. For example, each configuration of the vector code generation apparatus 300 shown in FIG. 3 may be a specific set of program codes executed by the host processor 100. In addition, each configuration of the vector code generation apparatus 300 expresses the functions implemented by the program code on the processor, and may not be clearly distinguished in specific operations.

도 4(a) 내지 도 4(d)는 일 실시예에 따른 벡터 코드 생성을 설명하기 위한 도면이다.4 (a) to 4 (d) are diagrams for explaining vector code generation according to an embodiment.

도 4(a)는 예시적인 스칼라 타입의 커널 코드이다. Figure 4 (a) is an exemplary scalar type kernel code.

도 4(a) 및 도 4(b)를 참조하면, 벡터 벡터 코드 생성부(330)는 도 3(a)에 도시된 커널 코드에서 선언된 파라미터 및 인덕션 변수를 제외한 변수를 벡터 타입으로 변환한다.Referring to FIGS. 4A and 4B, the vector vector code generation unit 330 converts a variable except a parameter and an induction variable declared in the kernel code shown in FIG. 3A into a vector type .

구체적으로, 벡터 코드 생성부(330)는 도 3(a)에 도시된 커널 코드에서 포인터 변수인 int*output과 int*input을 벡터 타입으로 재선언한다(410). 또한, 벡터 코드 생성부(330)는 커널 코드에 포함된 상수 리터럴(literal)을 벡터 타입으로 변환한다(420).Specifically, the vector code generation unit 330 redefines the pointer variables int * output and int * input as vector types in the kernel code shown in FIG. 3 (a) (410). In addition, the vector code generation unit 330 converts a constant literal included in the kernel code into a vector type (420).

도 4(a)에서 output[id]=input[id]*2는 인덕션 변수인 id가 배열의 인덱스로 사용되고 있으며, 조건 분기문이 아니므로, 벡터 타입으로 변환할 수 있다. 도 4(c)를 참조하면, 벡터 코드 생성부(330)는 벡터 타입으로 변환할 수 있는 구문에 사용된 변수 참조를 재선언된 벡터 타입의 변수인 vOutput 및 vInput으로 변환할 수 있다(430).In Fig. 4 (a), output [id] = input [id] * 2 can be transformed into a vector type because id is an indefinite variable and is not an conditional branch. Referring to FIG. 4C, the vector code generation unit 330 may convert the variable references used in the syntax that can be converted into the vector type into variables vOutput and vInput, which are the re-declared vector type, .

도 4(d)에 도시된 예를 참조하면, 벡터 코드 생성부(330)는 벡터 코드 생성부(330)는 최내각 루프의 인덱스 변수 및 배열의 인덱스로 사용된 인덕션 변수에 벡터화 팩터(vectoriztion factor)를 적용할 수 있다. Referring to the example shown in FIG. 4 (d), the vector code generation unit 330 generates a vector code for the index variable of the innermost loop and the vectorization factor ) Can be applied.

구체적으로, 벡터 코드 생성부(330)는 최내각 루프의 인덱스 변수의 증가값을 벡터화 팩터인 4로 변경할 수 있다(440). 또한, 벡터 코드 생성부(330)는 배열의 인덱스로 사용된 인덕션 변수인 id를 벡터화 팩터인 4로 나눌 수 있다(450). 도시된 예에서, 벡터화 팩터는 4로 가정하였으나, 반드시 이에 한정되는 것은 아니며, 벡터화 팩터는 하드웨어에서 지원하는 벡터 사이즈에 따라 결정될 수 있다.Specifically, the vector code generation unit 330 may change the increment value of the index variable of the innermost loop to a vectorization factor of 4 (440). In addition, the vector code generation unit 330 may divide the id, which is the induction variable used as the array index, by the vectorization factor of 4 (450). In the illustrated example, the vectorization factor is assumed to be 4, but the vectorization factor is not necessarily limited to this, and the vectorization factor may be determined according to the vector size supported by the hardware.

도 5는 일 실시예에 따른 조건 분기문에 대한 벡터 코드 생성을 설명하기 위한 도면이다. 5 is a diagram for explaining vector code generation for a conditional branch statement according to an embodiment.

도 5를 참조하면, 스칼라 타입의 커널 코드에 조건 분기문이 포함되어 있는 경우, 벡터 코드 생성부(330)는 코드 복사 기법을 이용하여 벡터 코드를 생성할 수 있다. 구체적으로, 벡터 코드 생성부(330)는 벡터화 팩터 만큼 조건 분기문을 복사하고, 복사된 분기문에 사용된 변수 및 배열에 대한 접근을 순차적인 벡터 엘리먼트에 대한 접근으로 변환할 수 있다. Referring to FIG. 5, when a scalar type kernel code includes a conditional branch statement, the vector code generation unit 330 may generate a vector code using a code copy technique. Specifically, the vector code generation unit 330 may copy the conditional branch statement by the vectorization factor, and may convert the access to the variables and arrays used in the copied branch statement into the access to the sequential vector elements.

도시된 예에서 벡터화 팩터가 4인 것으로 가정하였다. 따라서, 조건 분기문은 4개가 복사되며, 각각의 복사된 분기문에서 사용되는 배열에 대한 접근이 순차적인 벡터 엘리먼트에 대한 접근으로 변환되었음을 알 수 있다. It is assumed that the vectorization factor is 4 in the illustrated example. Thus, the conditional branch statement is copied four times, and it can be seen that access to the array used in each copied branch statement has been transformed into access to the sequential vector elements.

도 6(a) 내지 도 6(d)는 또 다른 실시예에 따른 벡터 코드 생성을 설명하기 위한 도면이다.6 (a) to 6 (d) are diagrams for explaining vector code generation according to another embodiment.

도 6(a) 내지 도 6(d)에서 벡터화 팩터는 4인 것으로 가정한다.It is assumed that the vectorization factor is 4 in Figs. 6 (a) to 6 (d).

도 6(a)를 참조하면, 도시된 스칼라 타입의 커널 코드에서 인덕션 변수가 배열의 인덱스로 사용된 구문인 B[id]=A[id]+P는 조건 분기문이 아니므로 벡터 타입으로 변환될 수 있다.Referring to FIG. 6A, B [id] = A [id] + P, which is an index of an array variable in an illustrated scalar type kernel code, is not a conditional branch, .

도 6(b)를 참조하면, 벡터 코드 생성부(330)는 도 6(a)에 도시된 커널 코드에서 함수의 인자가 되는 포인터 변수 *A 및 *B와 변수 P를 벡터 타입으로 재선언할 수 있다(610).Referring to FIG. 6B, the vector code generating unit 330 re-declares the pointer variables * A and * B and the variable P as a function type in the kernel code shown in FIG. 6A as a vector type (610).

도 6(c)를 참조하면, 벡터 코드 생성부(330)는 벡터 타입으로 변환할 수 있는 구문에서 사용된 변수 참조를 도 5(b)에서 재선언된 벡터 타입의 변수 vB, vA 및 vP로 변환할 수 있다(620).Referring to FIG. 6 (c), the vector code generator 330 converts the variable references used in the syntax that can be converted into the vector types into the variables vB, vA, and vP of the redefined vector type in FIG. 5 (b) (620).

도 6(d)를 참조하면, 벡터 코드 생성부(330)는 최내각 루프의 인덕션 변수인 i의 증가값을 벡터화 벡터인 4로 변경할 수 있다(630). 또한, 벡터 코드 생성부(330)는 배열의 인덱스로 사용되는 인덕션 변수인 id를 벡터화 팩터인 4로 나눌 수 있다(640).Referring to FIG. 6 (d), the vector code generator 330 may change the increment value of i, which is the induction variable of the innermost loop, to a vectorization vector of 4 (630). In addition, the vector code generation unit 330 may divide the id, which is an induction variable used as an index of the array, by the vectorization factor of 4 (640).

도 7은 일 실시예에 따른 OpenCL 커널 코드로부터 벡터 코드 생성 가능 여부를 판단하는 과정을 나타낸 순서도이다. 7 is a flowchart illustrating a process for determining whether a vector code can be generated from OpenCL kernel code according to an embodiment.

도 7을 참조하면, 벡터 코드 생성 장치(300)는 스칼라 타입의 커널 코드에서 인덕션 변수 및 배열의 인덱스로 사용된 변수를 검출할 수 있다(710).Referring to FIG. 7, the vector code generation apparatus 300 may detect a variable used as an index of an induction variable and an array in a scalar type kernel code (710).

이후, 벡터 코드 생성 장치(300)는 인덕션 변수 및 상기 인덱스 변수에 기초하여 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환하기 위한 조건을 만족하는지 여부를 판단할 수 있다(720). 이때, 벡터 타입의 코드로 변환하기 위한 조건은 위에 기재된 1) 내지 4)조건과 동일하다.Thereafter, the vector code generation apparatus 300 may determine 720 whether the condition for converting the scalar type kernel code into the vector type code is satisfied based on the induction variable and the index variable. At this time, the conditions for converting into the vector type code are the same as the above 1) to 4) conditions.

벡터 타입의 코드로 변환하기 위한 조건을 만족하는 경우, 벡터 코드 생성 장치(300)는 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환할 수 있다(730). When the condition for converting into the vector type code is satisfied, the vector code generation device 300 can convert the scalar type kernel code into the vector type code (730).

도 8은 일 실시예에 따른 벡터 코드 생성 과정을 나타낸 순서도이다.8 is a flowchart illustrating a vector code generation process according to an embodiment of the present invention.

도 8을 참조하면, 벡터 코드 생성 장치(300)는 스칼라 타입의 커널 코드에서 함수의 인자로 사용된 변수 또는 직접 정의된 변수 중 인덕션 변수를 제외한 변수를 벡터 타입으로 재선언할 수 있다(810).Referring to FIG. 8, the vector code generation apparatus 300 may redefine a variable used as a function argument of a scalar-type kernel code or a variable other than an induction variable of a directly-defined variable as a vector type (810) .

이후, 벡터 코드 생성 장치(300)는 벡터 타입으로 변환 가능한 구문에서 사용된 변수 참조를 재선언된 벡터 타입의 변수 참조로 변환한다(820).Thereafter, the vector code generation apparatus 300 converts 820 the variable reference used in the syntax convertible to the vector type to the variable reference of the redefined vector type.

이후, 벡터 코드 생성 장치(300)는 최내각 루프의 인덱스 변수 및 배열 인덱스에 벡터화 팩터를 적용할 수 있다(830). 구체적으로, 벡터 코드 생성 장치(300) 스칼라 타입의 커널 코드에서 최내각 루프의 인덱스 변수의 증가값을 벡터화 팩터로 변경할 수 있다. 또한, 벡터 코드 생성 장치(300)는 배열의 인덱스로 사용된 인덕션 변수를 벡터화 팩터로 나눌 수 있다.Thereafter, the vector code generation apparatus 300 may apply the vectorization factor to the index variable and array index of the innermost loop (830). Specifically, in the vector code generation apparatus 300, in the scalar type kernel code, the increment value of the index variable of the innermost loop can be changed to the vectorization factor. In addition, the vector code generation apparatus 300 can divide the induction variable used as an index of the array into vectorization factors.

한편, 벡터 코드 생성 장치(300)는 코드 복사 기법을 이용하여 스칼라 타입의 커널 코드에서 벡터 타입으로 변환할 수 없는 구문을 복사할 수 있다(840). 일 실시예에 따르면, 벡터 코드 생성 장치(300)는 스칼라 타입의 커널 코드에 조건 분기문이 포함되어 있는 경우, 벡터화 팩터 만큼 조건 분기문을 복사할 수 있다. 이때, 벡터 코드 생성 장치(300)는 복사된 조건 분기문에 사용된 변수 및 배열에 대한 접근을 순차적인 벡터 엘리먼트에 대한 접근으로 변환할 수 있다.Meanwhile, the vector code generation apparatus 300 may copy the syntax that can not be converted from the scalar type kernel code into the vector type using the code copy technique (840). According to one embodiment, when the conditional branch statement is included in the scalar type kernel code, the vector code generation apparatus 300 can copy the conditional branch statement by the vectorization factor. At this time, the vector code generation apparatus 300 may convert the access to the variables and arrays used in the copied conditional branch statement into the access to the sequential vector elements.

한편, 본 실시 예들은 컴퓨터로 읽을 수 있는 기록 매체에 컴퓨터가 읽을 수 있는 코드로 구현하는 것이 가능하다. 컴퓨터가 읽을 수 있는 기록 매체는 컴퓨터 시스템에 의하여 읽혀질 수 있는 데이터가 저장되는 모든 종류의 기록 장치를 포함한다. 컴퓨터가 읽을 수 있는 기록 매체의 예로는 ROM, RAM, CD-ROM, 자기 테이프, 플로피디스크, 광 데이터 저장장치 등이 있으며, 또한 캐리어 웨이브(예를 들어 인터넷을 통한 전송)의 형태로 구현하는 것을 포함한다. 또한, 컴퓨터가 읽을 수 있는 기록 매체는 네트워크로 연결된 컴퓨터 시스템에 분산되어, 분산 방식으로 컴퓨터가 읽을 수 있는 코드가 저장되고 실행될 수 있다. 그리고 본 실시예들을 구현하기 위한 기능적인(functional) 프로그램, 코드 및 코드 세그먼트들은 해당 기술 분야의 프로그래머들에 의하여 용이하게 추론될 수 있다.In the meantime, the embodiments can be embodied in a computer-readable code on a computer-readable recording medium. A computer-readable recording medium includes all kinds of recording apparatuses in which data that can be read by a computer system is stored. Examples of the computer-readable recording medium include a ROM, a RAM, a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device and the like, and also a carrier wave (for example, transmission via the Internet) . In addition, the computer-readable recording medium may be distributed over network-connected computer systems so that computer readable codes can be stored and executed in a distributed manner. In addition, functional programs, codes, and code segments for implementing the embodiments can be easily deduced by programmers of the related art.

이상에서는 실시예들을 중심으로 기술적 특징들을 설명하였다. 하지만, 개시된 실시예들은 한정적인 관점이 아니라 설명적인 관점에서 고려되어야 하고, 권리 범위는 전술한 설명이 아니라 특허청구범위에 나타나 있으며, 그와 동등한 범위 내에 있는 모든 차이점은 권리범위에 포함된 것으로 해석되어야 할 것이다.The technical features of the embodiments have been described above. It is to be understood, however, that the disclosed embodiments are to be considered in all respects as illustrative and not restrictive, and the scope of the claims is not to be interpreted as being limited by the foregoing description, and all changes that fall within the scope of the appended claims are intended to be embraced therein .

300: 벡터 코드 생성 장치
310: 분석부
320: 판단부
330: 벡터 코드 생성부
300: vector code generation device
310:
320:
330: vector code generation unit

Claims (22)

워크 아이템의 인스턴스를 표현하는 중첩 루프를 포함하는 스칼라 타입의 커널 코드에서 인덕션 변수 및 인덱스 변수를 검출하는 단계;
상기 인덕션 변수 및 상기 인덱스 변수에 기초하여 상기 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환 하기 위한 조건을 만족하는지를 판단하는 단계; 및
상기 조건을 만족하는 경우, 상기 스칼라 타입의 커널 코드를 상기 벡터 타입의 코드로 변환하는 단계;를 포함하는 벡터 코드 생성 방법.
Detecting an induction variable and an index variable in a scalar type kernel code including a nested loop representing an instance of a work item;
Determining whether a condition for converting the scalar type kernel code into a vector type code is satisfied based on the induction variable and the index variable; And
And converting the scalar type kernel code into the vector type code when the condition is satisfied.
제 1 항에 있어서,
상기 판단하는 단계는,
상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값이 불연속적인 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the determining step comprises:
And determines that the condition is not satisfied when the index value of the array included in the scalar type kernel code is discontinuous.
제 1 항에 있어서,
상기 판단하는 단계는,
상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값을 정적으로 분석할 수 없는 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the determining step comprises:
If the index value of the array included in the scalar type kernel code can not be statistically analyzed, it is determined that the condition is not satisfied.
제 1 항에 있어서,
상기 판단하는 단계는,
상기 스칼라 타입의 커널 코드가 프라이빗(private) 배열에 대한 접근을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the determining step comprises:
If the scalar type kernel code includes access to a private array, determining that the scalar type kernel code does not satisfy the condition.
제 1 항에 있어서,
상기 판단하는 단계는,
상기 스칼라 타입의 커널 코드가 사용자 정의 타입 변수 또는 빌트인 함수 이외의 함수 호출을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the determining step comprises:
If the scalar type kernel code includes a function call other than a user-defined type variable or a built-in function, determines that the condition is not satisfied.
제 1 항에 있어서,
상기 변환하는 단계는,
상기 스칼라 타입의 커널 코드에서 함수의 인자로 사용되는 변수 또는 상기 스칼라 타입의 커널 코드에서 정의된 변수 중 상기 인덕션 변수를 제외한 변수를 벡터 타입의 변수로 재선언하는 단계; 및
상기 스칼라 타입의 커널 코드에서 벡터 타입으로 변환할 수 있는 구문에 사용된 변수 참조를 상기 재선언된 벡터 타입의 변수 참조로 변환하는 단계;를 더 포함하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the converting comprises:
Redefining a variable used as a function argument in the scalar type kernel code or a variable defined in the scalar type kernel code except for the induction variable as a variable of a vector type; And
And converting a variable reference used in a syntax convertible from the scalar type kernel code to a vector type into a variable reference of the redefined vector type.
제 6 항에 있어서,
상기 벡터 타입으로 변환할 수 있는 구문은,
상기 인덕션 변수가 배열의 인덱스로 사용되고, 조건 분기문이 아닌 구문인 벡터 코드 생성 방법.
The method according to claim 6,
The syntax that can be converted into the above-mentioned vector type is,
A vector code generation method in which the induction variable is used as an index of an array, and the syntax is not a conditional branch statement.
제 1 항에 있어서,
상기 변환하는 단계는,
상기 중첩 루프 중 최내각 루프의 인덕션 변수 및 배열의 인덱스로 사용된 인덕션 변수에 벡터화 팩터를 적용하는 단계;를 더 포함하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the converting comprises:
Applying a vectorization factor to an induction variable used as an index of an induction variable and an array of an innermost loop of the overlapping loop.
제 8 항에 있어서,
상기 적용하는 단계는,
상기 배열의 인덱스로 사용된 인덕션 변수를 상기 벡터화 팩터로 나누고, 상기 최내각 루프의 인덕션 변수 증가 값을 상기 백터화 팩터로 변경하는 벡터 코드 생성 방법.
9. The method of claim 8,
Wherein the applying comprises:
Dividing an induction variable used as an index of the array by the vectorization factor and changing an induction variable increment value of the innermost loop to the vectorization factor.
제 1 항에 있어서,
상기 변환하는 단계는,
상기 스칼라 타입의 커널 코드 중 상기 벡터 타입으로 변환할 수 없는 구문을 복사하는 단계;를 더 포함하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the converting comprises:
And copying a syntax of the scalar type kernel code that can not be converted into the vector type.
제 1 항에 있어서,
상기 변환하는 단계는,
상기 스칼라 타입의 커널 코드가 조건 분기문을 포함하는 경우, 상기 조건 분기문을 벡터화 팩터만큼 복사하고, 복사된 조건 분기문에 포함된 변수 및 배열에 대한 접근을 순차적인 벡터 엘리먼트에 대한 접근으로 변환하는 단계;를 더 포함하는 벡터 코드 생성 방법.
The method according to claim 1,
Wherein the converting comprises:
If the kernel code of the scalar type includes a conditional branch statement, the conditional branch statement is copied by an vectorization factor, and accesses to the variables and arrays included in the copied conditional branch statements are converted into accesses to the sequential vector elements The method comprising the steps of:
프로세서;
상기 프로세서를 이용하여 워크 아이템의 인스턴스를 표현하는 중첩 루프를 포함하는 스칼라 타입의 커널 코드에서 인덕션 변수 및 인덱스 변수를 검출하는 분석부;
상기 프로세서를 이용하여 상기 인덕션 변수 및 상기 인덱스 변수에 기초하여 상기 스칼라 타입의 커널 코드를 벡터 타입의 코드로 변환하기 위한 조건을 만족하는지를 판단하는 판단부; 및
상기 조건을 만족하는 경우, 상기 프로세서를 이용하여 상기 스칼라 타입의 커널 코드를 상기 벡터 타입의 코드로 변환하는 벡터 코드 생성부;를 포함하는 벡터 코드 생성 장치.
A processor;
An analysis unit for detecting an induction variable and an index variable in a scalar type kernel code including a nested loop expressing an instance of a work item using the processor;
A determiner for determining whether a condition for converting the scalar type kernel code into a vector type code is satisfied based on the induction variable and the index variable using the processor; And
And a vector code generation unit for converting the scalar type kernel code into the vector type code using the processor when the condition is satisfied.
제 12 항에 있어서,
상기 판단부는,
상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값이 불연속적인 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein,
And determines that the condition is not satisfied when the index value of the array included in the scalar type kernel code is discontinuous.
제 12 항에 있어서,
상기 판단부는,
상기 스칼라 타입의 커널 코드에 포함된 배열의 인덱스 값을 정적으로 분석할 수 없는 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein,
And determines that the condition is not satisfied when the index value of the array included in the scalar type kernel code can not be statistically analyzed.
제 12 항에 있어서,
상기 판단부는,
상기 스칼라 타입의 커널 코드가 프라이빗(private) 배열에 대한 접근을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein,
And determines that the condition is not satisfied when the scalar type kernel code includes access to a private array.
제 12 항에 있어서,
상기 판단부는,
상기 스칼라 타입의 커널 코드가 사용자 정의 타입 변수 또는 빌트인 함수 이외의 함수 호출을 포함하는 경우, 상기 조건을 만족하지 않는 것으로 판단하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein,
And determines that the condition is not satisfied when the scalar type kernel code includes a function call other than a user-defined type variable or a built-in function.
제 12 항에 있어서,
상기 벡터 코드 생성부는,
상기 스칼라 타입의 커널 코드에서 함수의 인자로 사용되는 변수 또는 상기 스칼라 타입의 커널 코드에서 정의된 변수 중 상기 인덕션 변수를 제외한 변수를 벡터 타입의 변수로 재선언하고, 상기 스칼라 타입의 커널 코드에서 벡터 타입으로 변환할 수 있는 구문에 사용된 변수 참조를 상기 재선언된 벡터 타입의 변수 참조로 변환하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein the vector code generating unit comprises:
Wherein the scalar type kernel code redefines a variable used as a function argument of the scalar type kernel code or a variable defined in the kernel code of the scalar type except for the induction variable as a vector type variable, And converting the variable reference used in the syntax convertible to the variable into a variable reference of the redefined vector type.
제 17 항에 있어서,
상기 벡터 타입으로 변환할 수 있는 구문은,
상기 인덕션 변수가 배열의 인덱스로 사용되고, 조건 분기문이 아닌 구문인 벡터 코드 생성 장치.
18. The method of claim 17,
The syntax that can be converted into the above-mentioned vector type is,
Wherein the induction variable is used as an index of the array, and the statement is not a conditional branch statement.
제 12 항에 있어서,
상기 벡터 코드 생성부는,
상기 중첩 루프 중 최내각 루프의 인덕션 변수 및 배열의 인덱스로 사용된 인덕션 변수에 벡터화 팩터를 적용하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein the vector code generating unit comprises:
Wherein a vectorization factor is applied to an induction variable used as an index of an induction variable and an array of an innermost loop of the nested loops.
제 19 항에 있어서,
상기 벡터 코드 생성부는,
상기 배열의 인덱스로 사용된 인덕션 변수를 상기 벡터화 팩터로 나누고, 상기 최내각 루프의 인덕션 변수 증가 값을 상기 백터화 팩터로 변경하는 벡터 코드 생성 장치.
20. The method of claim 19,
Wherein the vector code generating unit comprises:
Dividing the induction variable used as the index of the array by the vectorization factor and changing the induction variable increment value of the innermost loop to the vectorization factor.
제 12 항에 있어서,
상기 벡터 코드 생성부는,
상기 스칼라 타입의 커널 코드 중 상기 벡터 타입으로 변환할 수 없는 구문을 복사하는 벡터 코드 생성 장치.
13. The method of claim 12,
Wherein the vector code generating unit comprises:
And copying a syntax that can not be converted into the vector type among the scalar type kernel codes.
제 12 항에 있어서,
상기 벡터 코드 생성부는,
상기 스칼라 타입의 커널 코드가 조건 분기문을 포함하는 경우, 상기 조건 분기문을 벡터화 팩터만큼 복사하고, 복사된 조건 분기문에 포함된 변수 및 배열에 대한 접근을 순차적인 벡터 엘리먼트에 대한 접근으로 변경하는 벡터 코드 생성 장치.




13. The method of claim 12,
Wherein the vector code generating unit comprises:
If the scalar type kernel code includes a conditional branch statement, the conditional branch statement is copied by a vectorization factor, and access to the variables and arrays included in the copied conditional branch statement is changed to access to the sequential vector elements / RTI &gt;




KR1020130135611A 2013-03-29 2013-11-08 Apparatus and method for generating vector code KR20140119619A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US14/228,868 US9367291B2 (en) 2013-03-29 2014-03-28 Apparatus and method for generating vector code

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
US201361806451P 2013-03-29 2013-03-29
US61/806,451 2013-03-29

Publications (1)

Publication Number Publication Date
KR20140119619A true KR20140119619A (en) 2014-10-10

Family

ID=51991875

Family Applications (1)

Application Number Title Priority Date Filing Date
KR1020130135611A KR20140119619A (en) 2013-03-29 2013-11-08 Apparatus and method for generating vector code

Country Status (1)

Country Link
KR (1) KR20140119619A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016114532A1 (en) * 2015-01-16 2016-07-21 서울대학교 산학협력단 Program compile device and program compile method

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016114532A1 (en) * 2015-01-16 2016-07-21 서울대학교 산학협력단 Program compile device and program compile method

Similar Documents

Publication Publication Date Title
Kotsifakou et al. Hpvm: Heterogeneous parallel virtual machine
Lee et al. OpenMPC: Extended OpenMP programming and tuning for GPUs
US9015683B2 (en) Method and apparatus for transforming program code
Tian et al. Compiling a high-level directive-based programming model for gpgpus
KR101962484B1 (en) Extensible data parallel semantics
US8402429B2 (en) Generating object code that uses calculated contents for a variable determined from a predicate
JP2013539130A (en) Compile-time boundary checking for user-defined types
Hormati et al. Macross: Macro-simdization of streaming applications
Mikushin et al. KernelGen--The Design and Implementation of a Next Generation Compiler Platform for Accelerating Numerical Models on GPUs
JP2019049843A (en) Execution node selection program and execution node selection method and information processor
Lee et al. OpenMPC: extended OpenMP for efficient programming and tuning on GPUs
Poesia et al. Static placement of computation on heterogeneous devices
Daley et al. A case study of porting HPGMG from CUDA to OpenMP target offload
Bosboom et al. StreamJIT: A commensal compiler for high-performance stream programming
Cramer et al. OpenMP target device offloading for the SX-Aurora TSUBASA vector engine
Neves et al. Compiler-assisted data streaming for regular code structures
US9367291B2 (en) Apparatus and method for generating vector code
Lutz et al. LambdaJIT: a dynamic compiler for heterogeneous optimizations of STL algorithms
Wende et al. Portable simd performance with openmp* 4. x compiler directives
US20030126589A1 (en) Providing parallel computing reduction operations
Mehta et al. Evaluating performance portability of OpenMP for SNAP on NVIDIA, Intel, and AMD GPUs using the roofline methodology
Kwon et al. Automatic scaling of OpenMP beyond shared memory
Celik et al. Design, implementation, and application of GPU-based Java bytecode interpreters
KR20140119619A (en) Apparatus and method for generating vector code
WO2019136014A1 (en) Reduced instructions to generate global variable addresses

Legal Events

Date Code Title Description
A201 Request for examination
E902 Notification of reason for refusal
E701 Decision to grant or registration of patent right