US9665354B2 - Apparatus and method for translating multithread program code - Google Patents

Apparatus and method for translating multithread program code Download PDF

Info

Publication number
US9665354B2
US9665354B2 US14/268,383 US201414268383A US9665354B2 US 9665354 B2 US9665354 B2 US 9665354B2 US 201414268383 A US201414268383 A US 201414268383A US 9665354 B2 US9665354 B2 US 9665354B2
Authority
US
United States
Prior art keywords
statement
work
loop
group
statements
Prior art date
Legal status (The legal status 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 status listed.)
Active, expires
Application number
US14/268,383
Other languages
English (en)
Other versions
US20140331216A1 (en
Inventor
Seong-Gun KIM
Dong-hoon Yoo
Jin-Seok Lee
Seok-joong Hwang
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Samsung Electronics Co Ltd
Original Assignee
Samsung Electronics Co Ltd
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 Samsung Electronics Co Ltd filed Critical Samsung Electronics Co Ltd
Assigned to SAMSUNG ELECTRONICS CO., LTD. reassignment SAMSUNG ELECTRONICS CO., LTD. ASSIGNMENT OF ASSIGNORS INTEREST (SEE DOCUMENT FOR DETAILS). Assignors: HWANG, SEOK-JOONG, LEE, JIN-SEOK, YOO, DONG-HOON, KIM, SEONG-GUN
Publication of US20140331216A1 publication Critical patent/US20140331216A1/en
Application granted granted Critical
Publication of US9665354B2 publication Critical patent/US9665354B2/en
Active legal-status Critical Current
Adjusted expiration legal-status Critical

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
    • G06F9/38Concurrent instruction execution, e.g. pipeline or look ahead
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/433Dependency analysis; Data or control flow analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/45Exploiting coarse grain parallelism in compilation, i.e. parallelism between groups of instructions
    • G06F8/451Code distribution
    • G06F8/452Loops
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/45Exploiting coarse grain parallelism in compilation, i.e. parallelism between groups of instructions
    • G06F8/456Parallelism detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/45Exploiting coarse grain parallelism in compilation, i.e. parallelism between groups of instructions
    • G06F8/458Synchronisation, e.g. post-wait, barriers, locks
    • 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/46Multiprogramming arrangements

Definitions

  • Apparatuses and methods consistent with exemplary embodiments relate to compiling a program, and more particularly, to translating a multithread program code.
  • OpenCL Open Computing Language
  • CPUs central processing units
  • GPUs graphics processing units
  • DSPs digital signal processors
  • OpenCL allows the use of the same program source on various platforms, thereby giving software developers portability and enabling them to easily use the processing power of the platforms.
  • aspects of one or more exemplary embodiments provide an apparatus and method for translating a multithread program code.
  • a method for translating a multithread program code including: dividing a multithread program code into a plurality of statements according to a synchronization point; generating at least one loop group by combining one or more adjacent statements based on a number of instructions included in the plurality of statements; expanding or renaming variables in each of the plurality of statements so that each statement included in the generated at least one loop group is executed with respect to a work item of a different work group; and enclosing each of the generated at least one loop group respectively with a work item coalescing loop.
  • the multithread program code may be an OpenCL kernel code or a Compute Unified Device Architecture (CUDA) kernel code.
  • CUDA Compute Unified Device Architecture
  • the synchronization point may include at least one of an entry point of the multithread program code, a barrier function, and an entry point of a control structure.
  • the method may further include calculating a number of work groups that are executable alternatively within a single loop group based on a capacity of a memory used by the multithread program code, wherein the generating the at least one loop group may include generating the at least one loop group by combining the one or more adjacent statement such that a number of instructions in each of the generated at least one loop group is close or equal to another and such that a number of statements of each of the generated at least one loop group does not exceed the calculated number of work groups.
  • the method may further include optimizing a translated code in a predetermined scheme.
  • the method may further include adding a variable rotation code that sets variables in each statement to indicate a memory offset at which the work group to be executed is stored.
  • the method may further include translating a code of a statement so that the statement is executed for only a valid work group.
  • the translating the code of the statement may include translating the statement using a conditional statement or predication.
  • the method may further include enclosing the work item coalescing loop and the variable rotation code with a work group interleaving loop so that all work groups are executed with respect to each statement.
  • an apparatus for translating a multithread program code including: a code divider configured to divide a multithread program code into a plurality of statements according to a synchronization point; a loop group generator configured to generate at least one loop group by combining one or more adjacent statements based on a number of instructions included in the plurality of statements; a variable expander/renamer configured to expand or rename variables in each of the plurality of statements so that statements in a same loop group execute work items of a different work group serially; a work item coalescing loop adder configured to enclose each of the generated at least one loop group respectively with a work item coalescing loop.
  • the multithread program code may be an OpenCL kernel code or a CUDA kernel code.
  • the synchronization point may include at least one of an entry point of the multithread program code, a barrier function, and an entry point of a control structure.
  • the apparatus may further include a work group number calculator configured to calculate a number of executable work groups in a loop group based on a capacity of a memory used by the multithread program code, wherein the loop group generator is further configured to generate the at least one loop group by combining the one or more adjacent statements such that a number of instructions in each of the generated at least one loop group is close or equal to another and a number of statements of each of the generated at least one loop group does not exceed the calculated number of work groups.
  • a work group number calculator configured to calculate a number of executable work groups in a loop group based on a capacity of a memory used by the multithread program code
  • the loop group generator is further configured to generate the at least one loop group by combining the one or more adjacent statements such that a number of instructions in each of the generated at least one loop group is close or equal to another and a number of statements of each of the generated at least one loop group does not exceed the calculated number of work groups.
  • the apparatus may further include a code optimizer configured to optimize a translated code in a predetermined scheme.
  • the apparatus may further include a variable rotation code adder configured to add a variable rotation code that sets variables in each statement to indicate a memory offset at which the work group to be executed is stored.
  • the apparatus may further include a code translator configured to translate a code of a statement so that the statement is executed for only a valid work group.
  • the code translator may be further configured to translate the code of the statement using a conditional state or predication.
  • the apparatus may further include a work group interleaving loop adder configured to enclose a work item coalescing loop and the variable rotation code with a work group interleaving loop so that all work groups are executed with respect to each statement.
  • a work group interleaving loop adder configured to enclose a work item coalescing loop and the variable rotation code with a work group interleaving loop so that all work groups are executed with respect to each statement.
  • a method for translating a multithread program code including: generating at least one loop group by combining one or more adjacent statements, among a plurality of statements divided from a multithread program code, based on a number of instructions included in the plurality of statements; modifying the plurality of statements so that each statement included in the generated at least one loop group is executed with respect to a work item of a different work group; and enclosing each of the generated at least one loop group respectively with a work item coalescing loop.
  • FIG. 1 is a diagram illustrating a multithread program execution model
  • FIG. 2A is a diagram illustrating an example of a kernel code including a barrier function
  • FIG. 2B is a diagram illustrating an example of a resultant code that is translated from the kernel code in FIG. 2A by serializing work items on a basis of a work group basis;
  • FIG. 2C is a diagram illustrating an execution sequence of the resultant code in FIG. 2B with respect to work items;
  • FIG. 3 is a block diagram illustrating an apparatus for translating a code according to an exemplary embodiment
  • FIG. 4A is a diagram illustrating a resultant code that is translated from the kernel code in FIG. 2A according to an exemplary embodiment
  • FIG. 4B is a diagram illustrating an execution sequence of the resultant code in FIG. 4A with respect to work items;
  • FIG. 4C is a diagram illustrating a mnemonic code that represents the resultant code in FIG. 4A ;
  • FIG. 5 is a diagram illustrating a mnemonic code that represents a translation result when a work group to be processed is dynamically assigned, according to an exemplary embodiment
  • FIG. 6 is a diagram illustrating an example of layout of a memory space according to an exemplary embodiment.
  • FIG. 7 is a flowchart illustrating a method for translating a kernel code according to an exemplary embodiment.
  • FIG. 1 is a diagram illustrating a multithread program execution model.
  • a multithread program is a program written in a fine-grained multithread programming language, such as OpenCL and CUDA, which shares a program code.
  • the multithread program may include a Fine-grained Single Program Multiple Data-threaded program.
  • the multithread program code includes a kernel code written in OpenCL or CUDA, and descriptions hereinafter are provided with reference to a kernel code.
  • a kernel code may include one or more statements.
  • a statement is an individual instruction or significant expression which composes a program, and may include an instruction sequence.
  • an execution domain is divided into multiple work items (e.g., work items 111 , 112 , and 113 ) so that a kernel code may be executed with respect to each work item (e.g., work items 111 , 112 , and 113 ).
  • each work item e.g., work items 111 , 112 , and 113
  • the work items to be synchronized may be classified into one work group 110 . That is, a work group is a group of work items to be synchronized, and may include one or more work items. Synchronization between work items (e.g., the work items 111 and 112 ) belonging to the same work group is possible, but synchronization between work items (e.g., the work items 112 and 113 ) belonging to a different work group may not be possible.
  • FIG. 1 demonstrates a case in which an execution domain is divided into 15 ⁇ 15 work items or 5 ⁇ 5 work groups.
  • a kernel code may include a barrier function (i.e., a barrier instruction).
  • a barrier function is used to synchronize work items in the same work group.
  • the barrier function may be called a synchronization barrier function, a synchronization function, or a barrier. If a kernel code includes a barrier function, all the work items in each work group are to be synchronized, and it is not possible to proceed to a statement beyond the barrier function until all the work items in a work group reach the barrier function.
  • FIG. 2A is a diagram illustrating an example of a kernel code that includes a barrier function
  • FIG. 2B is a diagram illustrating a resultant code that is translated from the kernel code in FIG. 2A by serializing work items on a basis of a work group unit
  • FIG. 2C is a diagram illustrating an execution sequence of the resultant code in FIG. 2B with respect to work items.
  • a work item may be represented by T(i, j), where i denotes a numerical value that indicates a corresponding work group in the range of 0 ⁇ i ⁇ N, and j denotes a numerical value that indicates a corresponding work item in the range of 0 ⁇ j ⁇ M.
  • various work items are processed in a single processing element.
  • the work items are to be serialized in a process referred to as work item serialization, structured microthreading, or work-item coalescing.
  • the work item serialization is a process of translating a kernel code by enclosing the kernel code with an iterative statement so that the kernel code may be executed a number of times equal to the number of work items to be serialized.
  • the iterative statement may be referred to as a work-item coalescing loop (WCL) or a thread loop.
  • work item serialization may be performed on a basis of a work group unit such that the statement S 1 220 and the statement S 2 240 , which are separate with reference to the barrier function 230 , are respectively translated into a statement S 1 ′ 261 and a statement S 2 ′ 271 , which lead to the same result of the statement S 1 220 and the statement S 2 240 .
  • two work item coalescing loops 260 and 270 each of which iteratively executes the statement S 1 ′ 261 and the statement S 2 ′ 271 , are generated to enclose the statement S 1 ′ 261 and the statement S 2 ′ 271 , respectively.
  • a code 250 which has been translated by performing work item serialization on a basis of a work group unit, executes work items of each work group. Accordingly, the statement S 1 ′ 261 and the statement S 2 ′ 271 in FIG. 2B are executed with respect to each work item in a sequence shown in FIG. 2C .
  • the statement S 1 ′ 261 is executed with respect to all the work items (from T(i, 0) to T(i, M ⁇ 1)) belonging to a work group i, and then the statement S 2 ′ 271 is executed with respect to all the work items (from T(i, 0) to T(i, M ⁇ 1)) belonging to the work group i Furthermore, the statement S 1 ′ 261 and the statement S 2 ′ 271 are executed sequentially for all the work items (from T(i+1, 0) to T(i+1, M ⁇ 1)) belonging to a work group i+1. As such, a translated code on which work item serialization is performed on a basis of a work group unit in the above-described sequence is provided.
  • a kernel code is translated by performing work item serialization on a basis of work group unit
  • the kernel code with a barrier function is translated into various small-sized iterative statements (that is, multiple iterative statements, each of which has less instructions).
  • Reduction in the number of instructions in an iterative statement leads to a lower possibility of finding out an instruction that directs an instruction scheduler of a compiler or an out-of-order scheduler of a Central Processing Unit (CPU) to execute simultaneously, but also increasing overheads for iteration of an instruction with semantics (e.g., comparison of instruction variables, an increase in instruction variables, and branch), so that the instruction-level parallelism (ILP) may be degraded.
  • ILP instruction-level parallelism
  • FIG. 3 is a block diagram of an apparatus 300 for translating a code according to an exemplary embodiment.
  • the apparatus 300 for translating a code includes a code divider 310 , a loop group generator 320 , a variable expander/renamer 330 , and a work item coalescing loop adder 340 .
  • the code divider 310 may divide an input kernel code into one or more statements according to a synchronization point.
  • the synchronization point may include an entry point of a kernel code, a barrier function, and an entry point of a control structure.
  • the kernel code itself may be determined as a single statement. In this case, the kernel code becomes a single statement.
  • a kernel code includes a barrier function
  • the kernel code may be divided into two statements with reference to the barrier function, that is, one statement before the barrier function and the other statement after the barrier function.
  • conditional statement if a barrier function is included in a conditional statement, the outside of the conditional statement may be divided into a statement before the conditional statement and a statement after the conditional statement.
  • the inside of the conditional statement may be divided with reference to the barrier function into a statement before the barrier function and a statement after the barrier function.
  • a barrier function is included in a loop statement
  • a code outside of the loop statement is executed once with respect to each work item, but a code inside of the loop statement is executed a number of times equal to the number of iterations of the loop statement with respect to each work item.
  • the code outside of the loop statement and the code inside of the loop statement may be separate.
  • a kernel code may be divided into a statement before the loop statement and a statement after the loop statement.
  • a kernel code may be divided into a statement specifying a condition of a loop, a statement before the barrier function, and a statement after the barrier function.
  • the loop group generator 320 may generate a loop group that includes one or more statements, which are to be enclosed by a work item coalescing loop, based on the number of instructions in the statements divided by the code divider 310 .
  • the loop group generator 320 may generate a loop group by combining adjacent statements based on the number of instructions in each separate statement, so that the number of instructions in each loop group may become close or equal to that of each other.
  • variable expander/renamer 330 may expand or rename variables in each statement so that statements in the same loop group execute work items of a different work group, serially.
  • variable expander/renamer 330 may perform scalar expansion on variables in each statement or rename the variables so that each statement in the same loop group serially executes a work item of a different work group.
  • a variable on which scalar expansion is performed may be a private variable that is used exclusively by each work item, and a variable to be renamed may be a local variable that is shared within each work group.
  • a work items belonging to each work group may have variables at different locations due to scalar expansion.
  • variables at different locations due to scalar expansion.
  • a different data location may be set for a work group to be executed with respect to each statement.
  • a translated code may be executed in a way that all the statements are executed with respect to all the work groups or that each statement is executed with respect to a different work group when multiple statement are executed within a single loop group.
  • adjacent statements belonging to different loop groups of a translated code are to be executed with respect to the same work group.
  • adjacent statements belonging to the same loop group of a translated code are to be executed with respect to different work groups such that the faster a statement appears in the kernel code, the greater number a work group is given with respect to which the statement is executed.
  • the statement S 1 belongs to a first loop group
  • the statements S 2 , S 3 , and S 4 belong to a second loop group
  • the statement S 5 belongs to a third loop group
  • the statement S 2 is executed with respect to a work group i.
  • the statement S 2 appears first in the kernel code so that the statements S 3 and S 4 are executed with respect to work groups i ⁇ 1 and i ⁇ 2, respectively.
  • the statements S 1 and S 2 are adjacent statements belonging to different loop groups, so the statements S 1 and S 2 are executed with respect to the same work group i, and similarly, the statements S 4 and S 5 are executed with respect to the same work group i ⁇ 2.
  • variable expander/renamer 330 may consider work groups of each statement.
  • the work item coalescing loop adder 340 may generate and add a work item coalescing loop that encloses each loop group that is generated in the loop group generator 320 .
  • the apparatus 300 may further include a work group number calculator 315 configured to calculate the number of work groups that are executable alternatively within the same work item coalescing loop.
  • the work group number calculator 315 may calculate the number of work groups that are executable alternatively at the same time. For example, if a disposable memory size is large enough, the work group number calculator 315 may determine the number of alternatively executable work groups to be close or equal to the number of the separate statements. Alternatively, if a disposable memory size is not large enough, the work group number calculator 315 may accordingly reduce the number of alternatively executable work groups and properly calculate the number of alternatively executable work groups by taking into consideration the disposable memory size.
  • the loop group generator 320 may consider the calculated number of work groups when generating a loop group.
  • the code translator 350 may add a conditional statement in order to cause each statement to be executed only for a valid work group, or may translate a code of a corresponding statement to use predication.
  • the apparatus 300 may further include an optimizer 350 configured to optimize a translated code.
  • the code optimizer 350 may optimize a code using various preset loop optimization schemes or scalar optimization schemes. For example, if a code has been translated such that each statement is executed only for a valid work group, the code optimizer 350 may optimize the translated code through loop unswitching or may change a private variable from an array into an ordinary variable through scalar replacement.
  • the apparatus 300 may further include a variable rotation code adder 370 configured to add a variable rotation code that results in variables in each statement to indicate a memory offset at which a work group to be executed is stored. That is, the variable rotation code is a code to set variables in each statement to indicate a memory offset at which a work group to be executed is stored.
  • the apparatus 300 may further include a work group interleaving loop adder 380 configured to generate and add a work group interleaving loop to enclose all the work item coalescing loops and variable rotation codes, so that statements may be executed with respect to all the work groups.
  • a work group interleaving loop adder 380 configured to generate and add a work group interleaving loop to enclose all the work item coalescing loops and variable rotation codes, so that statements may be executed with respect to all the work groups.
  • FIG. 4A is a diagram illustrating a resultant code translated from the kernel code in FIG. 2A
  • FIG. 4B is a diagram illustrating an execution sequence of the resultant code with respect to work items
  • FIG. 4C is a diagram illustrating a mnemonic code that represents the resultant code in FIG. 4A .
  • FIGS. 4A to 4C a resultant code 410 translated according to an exemplary embodiment is illustrated.
  • the resultant code 410 in FIG. 4A two work groups are executed alternatively. That is, the resultant code is executed in a sequence where the statement S 1 ′′ 441 is executed with respect to a work item 0(T(i, 0)) of a work group i, then the statement S 2 ′′ 443 is executed with respect to a work item 0(T(i ⁇ 1, 0)) of a work group i ⁇ 1 and then the statement S 1 ′′ 441 is executed with respect to the work item 1(T(i, 1)) of the work group i, rather than in a sequence where the statement S 1 ′′ 441 is executed with respect to a work item 0(T(i, 0)) of a work group i and then the statement S 1 ′′ 441 is executed with respect to a work item 1(T(i, 1)) of the work group i.
  • a following statement executes a work item with a numerical value that is smaller by one, compared with that of a preceding statement.
  • Such an execution sequence can be presented as a single iterative statement (that is, a work item coalescing loop), and thus, less iterative statements may be generated during serialization processing.
  • statement S 1 ′′ 441 and the statement S 2 ′′ 443 are arranged sequentially in the code, but use independent data, so that data-level parallelism (DLP) is achieved.
  • DLP data-level parallelism
  • variable rotation code 430 is a code that sets variables in each statement to indicate a memory offset at which a work group to be executed is stored, and the variable rotation code 430 is added by the variable rotation code adder 370 .
  • the variable rotation code 430 may be configured to adjust an offset of a reference/pointer of a variable.
  • a code includes two variables, x and y
  • renaming may be performed by declaring a structure with fields of x′ and y′, which is similar to a structure with fields of x and y, and then inputting the variables in the fields of x and y to the fields of x and y, respectively.
  • a variable rotation code may be a code that inputs a specific offset address to a reference/pointer of a structure that is used in remaining a variable.
  • the work group interleaving loop 420 is a loop that is inserted in order to execute all the statements 441 and 443 with respect to all the work groups.
  • the statement S 1 ′′ 441 or the statement S 2 ′′ 443 are not to be executed at the beginning or end of an iterative statement that constitutes the work group interleaving loop 420 .
  • a work group is in the range of 0 ⁇ i ⁇ N
  • a work group i if a work group i is 0, a work group ⁇ 1 does not exist, so that the statement S 2 ′′ 443 cannot be executed.
  • the statement S 1 ′′ 441 cannot be executed.
  • the code translator 450 translates each code of the statement S 1 ′′ 441 or the statement S 2 ′′ 443 .
  • a conditional statement or predication may be utilized.
  • the code optimizer 360 may optimize a translated code through loop unswitching, and, when predication is used, the code optimizer 360 may optimize a translated code through predicate analysis.
  • FIG. 5 is a diagram illustrating a mnemonic code that represents a translated code when a work group to be processed is dynamically given, according to an exemplary embodiment.
  • FIG. 4C demonstrates an example in which work groups to be processed are given numerical values from 0 to N ⁇ 1, and the same processing method may be adapted in a case where a work group to be processed is dynamically given.
  • WG work group
  • V 1 set of variables
  • FIG. 6 is a diagram illustrating a layout of a memory space according to an exemplary embodiment.
  • a system memory address space may be divided into a global memory, a local memory, and a private memory.
  • the global memory is a memory shared between all the work groups/work items of an entire domain to store data
  • the local memory is a memory shared between work items of the same work group to store data
  • the private memory is a memory used exclusively by a single work item to store data.
  • a different set of a local memory and a private memory are assigned to each work group, and used for a lifetime of a corresponding work group.
  • various work groups may use the local memory and private memory. Accordingly, as shown in the example of FIG. 6 , all the work groups may be executed such that three sets of a local memory LM 1 , LM 2 , and LM 3 and a private memory PM 1 , PM 2 , and PM 3 are secured and sequentially assigned to corresponding work groups.
  • work groups may be executed with a work group 0 assigned with a local memory LM 1 and a private memory PM 1 , a work group 1 assigned with a local memory LM 2 and a private memory PM 2 , and a work group 2 assigned with a local memory LM 3 and a private memory PM 3 .
  • the work group 0 is finished, the local memory LM 1 and the private memory PM 1 are re-assigned to the next work group (e.g., a work group 3).
  • FIG. 7 is a flowchart illustrating a method for translating a kernel code according to an exemplary embodiment.
  • the method for translating a kernel code includes dividing a kernel code into one or more statements according to a synchronization point in operation 710 .
  • the synchronization point may include an entry point of the kernel code, a barrier function, and an entry point of a control structure.
  • the entire kernel code is regarded a single statement with reference to the entry point of the kernel code.
  • the kernel code may be divided into a statement before the barrier function and a statement after the barrier function with reference to the barrier function.
  • the outside of the conditional statement may be divided into a statement before the conditional statement and a statement after the conditional statement with reference to the barrier function.
  • the inside of the conditional statement may be divided into a statement before the barrier function and a statement after the barrier function with reference to the barrier function.
  • a barrier function is included in a loop statement
  • a code outside of the loop statement is executed once with respect to each work item, but a code inside of the loop statement is executed a number of times equal to the number of iterations of the loop statement with respect to each work item.
  • the outside of the loop statement may be divided into a statement before the loop statement and a statement after the loop statement.
  • the inside of the loop statement may be divided into a statement specifying a condition of a loop, a statement before the barrier function, and a statement after the barrier function.
  • a loop group which includes one or more statements and to be enclosed by a work item coalescing loop, is generated based on the number of instructions included in each separate statement in operation 720 .
  • a loop group is generated by combining adjacent statements based on the number of instructions in each separate statement, so that the number of instructions included in each loop group may become close or equal to that of each other.
  • a kernel code is divided into five statements, including a statement S 1 with 100 instructions, a statement S 2 with 20 instructions, a statement S 3 with 30 instructions, a statement S 4 with 30 instructions and a statement S 5 with 110 instructions, and that three work groups can be executed alternatively within one loop.
  • Variables in each statement may be expanded using scalar expansion or the variables are renamed in operation 730 .
  • variables in each statement in a loop group may be expanded using scalar expansion or may be renamed so that each statement of the loop group serially executes work items of a different work group.
  • a variable to be expanded may be a private variable that is used exclusively by each work item, and a variable to be renamed may be a local variable that is shared only within the same work group.
  • each work item of the same work group may have variables at different locations.
  • each statement may designate a different data location of a work group to be executed.
  • a translated code is to be executed in a way that all the statements are executed with respect to all the work groups or that each statement is executed with respect to a different work group when multiple statement are executed within a single loop group.
  • adjacent statements belonging to different loop groups of a translated code are to be executed with respect to the same work group.
  • adjacent statements belonging to the same loop group of a translated code are to be executed with respect to different work groups such that the faster a statement appears in the kernel code, the greater number a work group is given with respect to which the statement is executed.
  • statement S 1 belongs to a first loop group
  • the statements S 2 , S 3 , and S 4 belong to a second loop group
  • the statement S 5 belongs to a third loop group
  • the statement S 2 is executed with respect to a work group i.
  • the statement S 2 appears first in the kernel code so that the statements S 3 and S 4 are executed with respect to work groups i ⁇ 1 and i ⁇ 2, respectively.
  • the statements S 1 and S 2 are adjacent statements belonging to different loop groups, so that the statements S 1 and S 2 are executed with respect to the same work group i, and similarly, the statements S 4 and S 5 are executed with respect to the same work group i ⁇ 2.
  • the above described work group of each statement may be considered when expanding variables in each statement using scalar expansion or renaming the variables.
  • Each generated loop group is enclosed by a work item coalescing loop in operation 740 .
  • the method for translating a code may further include calculating the number of alternatively executable work groups within a single work item coalescing loop in operation 715 .
  • the number of alternatively executable work groups may be determined to be equal to the number of separate statements.
  • the number of alternatively executable work groups may be reduced properly and according to the disposable memory size.
  • the number of work groups calculated in operation 715 is taken into consideration so that the number of statements belonging to a single loop group may not exceed the calculated number of work groups.
  • the method for translating a code may further include an operation 750 of adding or translating a code so that each statement may be executed with respect to a valid work group.
  • statements S 1 and S 2 execute work groups i and i ⁇ 1, respectively, and that each work group is in the range of 0 ⁇ i ⁇ N.
  • the statement S 2 is to execute a work group ⁇ 1, although the work group ⁇ 1 is invalid.
  • the method for translating a code may further include an operation 760 of optimizing a code in a predetermined scheme.
  • at least one of a loop optimization and a scalar optimization may be employed. For example, if a code has been translated so that each statement may be executed only for a valid work group, it is possible to optimize the translated code through loop unswitching or to change some private variables from array into normal variables through scalar replacement.
  • the method for translating a code may further include an operation 770 of adding a variable rotation code that sets variables in each statement to indicate a memory offset at which a work group to be executed is stored.
  • the method for translating a code may further include an operation 780 of enclosing all the work item coalescing loops with a work group interleaving loop so that a statement is able to be executed with respect to all the work groups.
  • a work group interleaving loop may enclose the variable rotation code and the work item coalescing loops all together.
  • the methods and/or operations described above may be recorded, stored, or fixed in one or more computer-readable storage media that includes program instructions to be implemented by a computer to cause a processor to execute or perform the program instructions.
  • the media may also include, alone or in combination with the program instructions, data files, data structures, and the like.
  • Examples of computer-readable storage media include magnetic media, such as hard disks, floppy disks, and magnetic tape; optical media such as CD ROM disks and DVDs; magneto-optical media, such as optical disks; and hardware devices that are specially configured to store and perform program instructions, such as read-only memory (ROM), random access memory (RAM), flash memory, and the like.
  • Examples of program instructions include machine code, such as produced by a compiler, and files containing higher level code that may be executed by the computer using an interpreter.
  • the described hardware devices may be configured to act as one or more software modules in order to perform the operations and methods described above, or vice versa.
  • a computer-readable storage medium may be distributed among computer systems connected through a network and computer-readable codes or program instructions may be stored and executed in a decentralized manner.
  • functional programs, codes and code segments to implement those exemplary embodiments may be easily inferred by programmers who are skilled in the related art.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)
US14/268,383 2013-05-03 2014-05-02 Apparatus and method for translating multithread program code Active 2034-09-03 US9665354B2 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
KR1020130050251A KR102062208B1 (ko) 2013-05-03 2013-05-03 멀티스레드 프로그램 코드의 변환 장치 및 방법
KR10-2013-0050251 2013-05-03

Publications (2)

Publication Number Publication Date
US20140331216A1 US20140331216A1 (en) 2014-11-06
US9665354B2 true US9665354B2 (en) 2017-05-30

Family

ID=50774626

Family Applications (1)

Application Number Title Priority Date Filing Date
US14/268,383 Active 2034-09-03 US9665354B2 (en) 2013-05-03 2014-05-02 Apparatus and method for translating multithread program code

Country Status (4)

Country Link
US (1) US9665354B2 (ko)
EP (1) EP2799986B1 (ko)
KR (1) KR102062208B1 (ko)
CN (1) CN104133668B (ko)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9864584B2 (en) 2014-11-14 2018-01-09 Cavium, Inc. Code generator for programmable network devices
KR102592330B1 (ko) * 2016-12-27 2023-10-20 삼성전자주식회사 OpenCL 커널을 처리하는 방법과 이를 수행하는 컴퓨팅 장치
WO2019157743A1 (zh) * 2018-02-14 2019-08-22 华为技术有限公司 线程处理方法和图形处理器
CN109901840B (zh) * 2019-02-14 2020-10-27 中国科学院计算技术研究所 一种线程间冗余删除的异构编译优化方法
CN112130898A (zh) * 2019-06-24 2020-12-25 华为技术有限公司 一种插入同步指令的方法及装置

Citations (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6820250B2 (en) 1999-06-07 2004-11-16 Intel Corporation Mechanism for software pipelining loop nests
US20050039167A1 (en) * 2001-10-12 2005-02-17 Fernandes Marcio Merino Processors and compiling methods for processors
US20050050529A1 (en) * 2003-08-07 2005-03-03 Aljosa Vrancic Graphical program having a hierarchy of timed loops
US7386864B2 (en) * 2003-11-12 2008-06-10 Microsoft Corporation Automatic serialization for event driven multi-threaded programs in an object structured system
US20080294882A1 (en) * 2005-12-05 2008-11-27 Interuniversitair Microelektronica Centrum Vzw (Imec) Distributed loop controller architecture for multi-threading in uni-threaded processors
KR20090107972A (ko) 2008-04-09 2009-10-14 엔비디아 코포레이션 범용 프로세서에 의해 실행하기 위한 어플리케이션 프로그램의 리타게팅
US20090259828A1 (en) 2008-04-09 2009-10-15 Vinod Grover Execution of retargetted graphics processor accelerated code by a general purpose processor
US20090259996A1 (en) 2008-04-09 2009-10-15 Vinod Grover Partitioning cuda code for execution by a general purpose processor
US20090307660A1 (en) * 2008-10-14 2009-12-10 Edss, Inc. Ticc-paradigm to build verified parallel software for multi-core chips
US20110067014A1 (en) * 2009-09-14 2011-03-17 Yonghong Song Pipelined parallelization with localized self-helper threading
US20110161944A1 (en) * 2009-12-30 2011-06-30 Samsung Electronics Co., Ltd. Method and apparatus for transforming program code
US20110314442A1 (en) * 2010-06-17 2011-12-22 International Business Machines Corporation Reducing parallelism of computer source code
US20120102496A1 (en) 2010-10-21 2012-04-26 Samsung Electronics Co., Ltd. Reconfigurable processor and method for processing a nested loop
US20120144376A1 (en) * 2009-06-02 2012-06-07 Vector Fabrics B.V. Embedded system development
US20120254875A1 (en) * 2011-03-30 2012-10-04 Marathe Jaydeep Method for Transforming a Multithreaded Program for General Execution
US8726251B2 (en) * 2011-03-29 2014-05-13 Oracle International Corporation Pipelined loop parallelization with pre-computations

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101329638B (zh) * 2007-06-18 2011-11-09 国际商业机器公司 程序代码的并行性的分析方法和系统
US9354944B2 (en) * 2009-07-27 2016-05-31 Advanced Micro Devices, Inc. Mapping processing logic having data-parallel threads across processors
JP5148674B2 (ja) * 2010-09-27 2013-02-20 株式会社東芝 プログラム並列化装置およびプログラム
CN103020494B (zh) * 2012-12-03 2015-06-24 哈尔滨工业大学 一种利用程序代码编程模式著作权归属检测模型检测著作权归属的方法

Patent Citations (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6820250B2 (en) 1999-06-07 2004-11-16 Intel Corporation Mechanism for software pipelining loop nests
US20050039167A1 (en) * 2001-10-12 2005-02-17 Fernandes Marcio Merino Processors and compiling methods for processors
US20050050529A1 (en) * 2003-08-07 2005-03-03 Aljosa Vrancic Graphical program having a hierarchy of timed loops
US7386864B2 (en) * 2003-11-12 2008-06-10 Microsoft Corporation Automatic serialization for event driven multi-threaded programs in an object structured system
US20080294882A1 (en) * 2005-12-05 2008-11-27 Interuniversitair Microelektronica Centrum Vzw (Imec) Distributed loop controller architecture for multi-threading in uni-threaded processors
US20090259828A1 (en) 2008-04-09 2009-10-15 Vinod Grover Execution of retargetted graphics processor accelerated code by a general purpose processor
US20090259832A1 (en) 2008-04-09 2009-10-15 Vinod Grover Retargetting an application program for execution by a general purpose processor
US20090259997A1 (en) 2008-04-09 2009-10-15 Vinod Grover Variance analysis for translating cuda code for execution by a general purpose processor
US20090259996A1 (en) 2008-04-09 2009-10-15 Vinod Grover Partitioning cuda code for execution by a general purpose processor
US20090259829A1 (en) 2008-04-09 2009-10-15 Vinod Grover Thread-local memory reference promotion for translating cuda code for execution by a general purpose processor
KR20090107972A (ko) 2008-04-09 2009-10-14 엔비디아 코포레이션 범용 프로세서에 의해 실행하기 위한 어플리케이션 프로그램의 리타게팅
US7979844B2 (en) * 2008-10-14 2011-07-12 Edss, Inc. TICC-paradigm to build formally verified parallel software for multi-core chips
US20090307660A1 (en) * 2008-10-14 2009-12-10 Edss, Inc. Ticc-paradigm to build verified parallel software for multi-core chips
US20120144376A1 (en) * 2009-06-02 2012-06-07 Vector Fabrics B.V. Embedded system development
US9081928B2 (en) * 2009-06-02 2015-07-14 Vector Fabrics, B.V. Embedded system development
US20110067014A1 (en) * 2009-09-14 2011-03-17 Yonghong Song Pipelined parallelization with localized self-helper threading
US8561046B2 (en) * 2009-09-14 2013-10-15 Oracle America, Inc. Pipelined parallelization with localized self-helper threading
US20110161944A1 (en) * 2009-12-30 2011-06-30 Samsung Electronics Co., Ltd. Method and apparatus for transforming program code
US20110314442A1 (en) * 2010-06-17 2011-12-22 International Business Machines Corporation Reducing parallelism of computer source code
US8584103B2 (en) * 2010-06-17 2013-11-12 International Business Machines Corporation Reducing parallelism of computer source code
US20120102496A1 (en) 2010-10-21 2012-04-26 Samsung Electronics Co., Ltd. Reconfigurable processor and method for processing a nested loop
KR20120041581A (ko) 2010-10-21 2012-05-02 삼성전자주식회사 중첩 루프를 처리하기 위한 재구성 가능 프로세서 및 방법
US8726251B2 (en) * 2011-03-29 2014-05-13 Oracle International Corporation Pipelined loop parallelization with pre-computations
US20120254875A1 (en) * 2011-03-30 2012-10-04 Marathe Jaydeep Method for Transforming a Multithreaded Program for General Execution

Non-Patent Citations (11)

* Cited by examiner, † Cited by third party
Title
Andrade, Diego et al., "Using an analytical model of shared caches for selecting the optimal parallelization scheme", 2012, pp. 588-594. *
Communication dated Jul. 30, 2014, issued by the European Patent Office in counterpart European Application No. 14166856.6.
Curtis-Maury, Matthew et al., "Online Power-Performance Adaptation of Multithreaded Programs using Hardware Event-Based Prediction", 2006, pp. 157-166. *
Kandemir, Mahmut et al., "Cache Topology Aware Computation Mapping for Multicores", 2010, pp. 74-85. *
Kejariwal, Arun et al., "Parallelization Spectroscopy: Analysis of Thread-level Parallelism in HPC Programs", 2009, pp. 293-294. *
Kwon, Seongnam et al., "Serialized Multitasking Code Generation from Dataflow Specification," vol. 35, No. 9, Oct. 2008, pp. 429-440.
Ottoni, et al.; "Automatic Thread Extraction with Decoupled Software Pipelining", Proceedings of the 38th Annual IEEE/ACM International Symposium on Microarchitecture, Nov. 2005, 12 pages total.
Raman, Easwaran et al., "Parallel-Stage Decoupled Software Pipelining", 2008, pp. 114-120. *
Raman, Easwaran et al., "Structure Layout Optimization for Multithreaded Programs", 2007, pp. 1-12. *
Stratton, John A. et al., "MCUDA: An Efficient Implementation of CUDA Kernels on Multi-cores," IMPACT Technical Report, Mar. 12, 2008, 19 pages total.
Wolfe, "Scalar vs. Parallel Optimizations", CSETech, Jun. 1990, 18 pages total.

Also Published As

Publication number Publication date
CN104133668B (zh) 2019-05-03
KR102062208B1 (ko) 2020-02-11
CN104133668A (zh) 2014-11-05
US20140331216A1 (en) 2014-11-06
EP2799986B1 (en) 2020-01-22
EP2799986A1 (en) 2014-11-05
KR20140131200A (ko) 2014-11-12

Similar Documents

Publication Publication Date Title
JP6525286B2 (ja) プロセッサコア及びプロセッサシステム
US8572588B2 (en) Thread-local memory reference promotion for translating CUDA code for execution by a general purpose processor
US8776030B2 (en) Partitioning CUDA code for execution by a general purpose processor
CN103353834B (zh) 对零谓词分支误预测的分支误预测行为抑制
US9665354B2 (en) Apparatus and method for translating multithread program code
US20150150019A1 (en) Scheduling computing tasks for multi-processor systems
JP6427054B2 (ja) 並列化コンパイル方法、及び並列化コンパイラ
Baudisch et al. Multithreaded code from synchronous programs: Extracting independent threads for OpenMP
US10761821B1 (en) Object oriented programming model for graphics processing units (GPUS)
US20150277874A1 (en) Compiler method and compiler apparatus
Samadi et al. Paragon: Collaborative speculative loop execution on gpu and cpu
JP2014216021A (ja) バッチスレッド処理のためのプロセッサ、コード生成装置及びバッチスレッド処理方法
Memeti et al. HSTREAM: a directive-based language extension for heterogeneous stream computing
Katagiri et al. Early experiences for adaptation of auto-tuning by ppOpen-AT to an explicit method
US9569185B2 (en) Changing de-optimization guard representation during the compilation process
Jenista et al. OoOJava: An out-of-order approach to parallel programming
KR20240090423A (ko) 최적화된 레이턴시를 가진 멀티-프로세서 시스템을 위한 프로세싱 코드들의 자동-병렬화를 위한 시스템 및 그의 방법
Tian et al. Compiler transformation of nested loops for general purpose GPUs
Zhang et al. GPU-TLS: An efficient runtime for speculative loop parallelization on gpus
Jacob et al. ALPyNA: acceleration of loops in Python for novel architectures
Andon et al. Programming high-performance parallel computations: formal models and graphics processing units
Neelima et al. Communication and computation optimization of concurrent kernels using kernel coalesce on a GPU
Nie et al. Parallel Region Reconstruction Technique for Sunway High-Performance Multi-core Processors
Feng et al. Optimistic parallelism on GPUs
Clarkson Compiler and Runtime Support for Heterogeneous Programming

Legal Events

Date Code Title Description
AS Assignment

Owner name: SAMSUNG ELECTRONICS CO., LTD., KOREA, REPUBLIC OF

Free format text: ASSIGNMENT OF ASSIGNORS INTEREST;ASSIGNORS:KIM, SEONG-GUN;YOO, DONG-HOON;LEE, JIN-SEOK;AND OTHERS;SIGNING DATES FROM 20140422 TO 20140423;REEL/FRAME:032810/0663

STCF Information on status: patent grant

Free format text: PATENTED CASE

FEPP Fee payment procedure

Free format text: PAYOR NUMBER ASSIGNED (ORIGINAL EVENT CODE: ASPN)

MAFP Maintenance fee payment

Free format text: PAYMENT OF MAINTENANCE FEE, 4TH YEAR, LARGE ENTITY (ORIGINAL EVENT CODE: M1551); ENTITY STATUS OF PATENT OWNER: LARGE ENTITY

Year of fee payment: 4