This application is a U.S. National-Stage entry under 35 U.S.C. § 371 based on International Application No. PCT/EP2016/054542, filed Mar. 3, 2016 which was published under PCT Article 21(2) and which claims priority to European Application No. 15157809.3, filed Mar. 5, 2015, which are all hereby incorporated in their entirety by reference.
This application pertains to data processing by means of general-purpose computing on graphics processing units. In particular, it relates to a novel technique called “language-embedded programming”.
The term general-purpose computing on graphics processing units, GPGPU, is used for the use of specialized, highly parallel hardware, to do computationally demanding tasks that would normally be done on a normal processor. The hardware can be a video card or some other computing device. In most GPGPU programming environments, the main program, which can be run on a central processing unit, CPU, and the kernels running on the device for the computationally demanding tasks are parsed by separate compilers. The main program is parsed by an ordinary compiler and is written in an ordinary programming language, while the kernels are parsed by a dedicated compiler and are written in a specialized programming language.
A technique related to language embedded programming has first been described by Thomas C. Jansen in his doctoral thesis “GPU++—An Embedded GPU Development System for General-Purpose Computations”, Technical University Munich, 2007. Therein methods of flow control, such as loops or if-clauses are not included. Therefore the disclosure is limited to a very small set of programs and does not enable general-purpose programming.
WO2012/097316 describes techniques for extending the architecture of a general-purpose graphics processing unit with parallel processing units to allow efficient processing of pipeline-based applications. The techniques include configuring local memory buffers connected to parallel processing units operating as stages of a processing pipeline to hold data for transfer between the parallel processing units.
Object-oriented programming languages allow the definition of new data types, along with corresponding operators. In language-embedded programming, special data types are defined in such a way that instead of doing the actual computation, the steps of computation are recorded and used to generate the machine code for the device. In this way, the kernels are fully integrated into the main program and don't have to be parsed by a special compiler.
These special data types are used to represent values that reside on the device. These values will typically be stored in registers. In one example, the type names for the device values are the intrinsic type names prefixed by the expression “gpu_”, i.e., int becomes gpu_int, float becomes gpu_float, etc. Other naming conventions are possible as well. The kernels can be accessed as functions that use these special data types. When such a kernel function is executed on the CPU, the use of the device data types will create an expression graph, in which the steps of computation are represented. Each device variable holds a pointer to a node in the expression graph that determines how its value is computed. From this expression graph the kernel code is generated.
With the teachings of the prior art, the kernel cannot be integrated into the main program, unless two separate compilers are used.
In addition, other objects, desirable features and characteristics will become apparent from the subsequent summary and detailed description, and the appended claims, taken in conjunction with the accompanying drawings and this background.
The present invention overcomes the drawbacks of the prior art and as such allows the integration of the kernels into the main program. The whole parsing of the CPU program parts and the kernels is done by one single standard compiler. The actual compiler for the device can be linked as a library and does not need to do any parsing.
The invention further allows loops and if-clauses to be used in language-embedded GPGPU programming, enabling full general-purpose programming of the device in a way that is fully embedded in an ordinary programming language. The device can be a highly parallel computing device, such as a video card, or some other computing device
The above mentioned objectives are achieved by a method of flow control in a computing device, for processing of flow control statements to adapt a data structure of a program running on the computing device according to claim 1 and a computer program product according to claim 14. Further advantageous features are defined in the dependent claims.
The present invention will hereinafter be described in conjunction with the following drawing figures, wherein like numerals denote like elements, and:
The following detailed description is merely exemplary in nature and is not intended to limit the invention or the application and uses of the invention. Furthermore, there is no intention to be bound by any theory presented in the preceding background of the invention or the following detailed description.
The invention allows flow control statements, such as loops and if-clauses, to be used in language-embedded programming.
There are different kinds of flow control statements. The most common are if-clauses, while-loops and for-loops. This invention applies to all three of them, but the general principles of this invention can also be applied to other kinds of flow control statements.
Of the three flow control statements listed above, if-clauses are the most basic ones. Loops have some additional requirements.
In while-loops, the loop condition is modified inside the loop body. Therefore, special care has to be taken. One way to solve this is to instantiate the loop condition as a Boolean outside the loop.
For example,
can be implemented as
For-loops can always be expressed as while-loops, by declaring the loop variable before the loop and by incrementing it in the loop body.
To make the programming more user-friendly, it is advisable to mimic traditional loop syntax. According to the present invention, however, functions are required to be called at the beginning and at the end of the loop body. Instead of writing
something like the following needs to be written:
In order to achieve the former syntax, language features can be used. In C++, for instance, this can be achieved with the use of macros, for-loops, and constructors/destructors.
The ‘continue’ statement for skipping the rest of the loop body and continuing with the next loop cycle can be implemented as an if-clause that covers the rest of the loop body, or as multiple if-clauses in case the continue statement is in a sub-clause.
As an example the following loop is considered:
The gpu_continue( ) statement may be implementing by transforming the loop into the following program, preferably transformed by the compiler library:
The ‘break’ statement for exiting a loop can be implemented like the ‘continue’ statement, but where the loop condition is modified as well, so that the loop is exited.
As an example regarding the underlying techniques of the invention, the following program is an example:
In the example program, b serves as a loop variable, running over all odd natural numbers smaller than 10. Variable a will add up these numbers, and the result is returned. To execute it on the device, the program is modified as follows:
Variables are changed to the corresponding device data type, device values are indicated by the prefix gpu_, therefore int becomes gpu_int. At the beginning and at the end of the loop body, the special functions gpu_while_begin and gpu_while_end are called, respectively.
For other flow control statements, such as if-clauses, other functions can be used instead, such as gpu_if_begin and gpu_if_end. Instead of explicitly calling these functions here, a constructor/destructor mechanism, or other language features can be used, to make the loop declaration more user friendly. However, the present invention is not restricted to any such method, and a more basic approach will be used here, for explanatory reasons, of explicitly calling the gpu_while_begin and gpu_while_end functions in the example. The result is written to the resource res, which provides memory access. Implementation of resource access is well known to a person skilled in the art, and is therefore not detailed in this document. It will be assumed that the use of the ‘[ ]’ operator generates the appropriate instructions. The program code is accessible as some function or class. In this document, as an example, the function example_kernel( ) is used, so that it can be called from the compiler library.
The language-embedded programming technique is used. Before the kernel can run on the device, the kernel program instructions need to be generated. To do this, the kernel function is executed on the CPU. Contrary to the normal intrinsic variables, all variables declared as a device type—in this example, gpu_int and gpu_bool—will not immediately perform a computation, but the computational steps are recorded in an expression graph, which is a directed and acyclic graph. Each device variable contains a pointer to its current value in the expression graph. Whenever the device variable is assigned a new value, its pointer is changed to the new value. Nodes that are not referenced any more may be deleted. Two or more variables may point to the same node. This can happen if variables are copied, or after expressions are optimized. From this expression graph, the kernel code is generated. This can be direct machine code, or some intermediate code, such as OpenCL.
With the present invention, the following procedures can be implemented, individually or in combination:
The device variables are registered in some way, such that a computer can, at any time, access a list of all device variables that exist in the current scope. These variables are also called active variables. Most modern programming languages support the notion of scopes. Local variables are only valid within a given scope. Consider the following example:
In the code fragment above the variables are valid in the following ranges: Variable a from line 3 to line 9, variable i from line 4 to line 7, and variable b from line 6 to line 7.
The corresponding local variables, in this example variables a, i, and b, only exist from the point where they are defined to the end of the corresponding scope. At any point during execution, a well-defined set of variables is alive. In some programming languages, a constructor is called when the variable first comes into existence, and a destructor is called when the corresponding scope is left. Variables may also be allocated on the heap, in which case the programmer can choose when to create and when to destroy them. In the present invention device variables are destroyed in the same scope in which they have been created. Otherwise, dynamic memory management would be required on the device, and the variable could not be stored in a register.
With reference to
Then, when a device variable gets into scope, its constructor is called, which inserts the new variable into the list, by setting the pointers in the following way:
Therein ‘this’ points to the new variable and ‘root’ to the static root node.
With such a list all device variables that are currently in existence can be accessed by starting at the root node and by following the next pointers until the root node is reached again. Alternatively, other methods can be used to keep track of active variables, depending on what features are supported by the programming language.
The kernel program is executed on the CPU to generate the expression graph, which later on will be used to create the kernel instructions for the device.
Whenever a loop or an if-clause is encountered during the processing, the function gpu_while _begin( ) or gpu_if_begin( ), or any other function that is suitable for the flow control statement encountered, is called at the beginning of the loop body.
This function can have one or more of the following effects:
Referring to
For processing the expression graph of previous instructions the following is performed: The current expression graph is evaluated immediately. As detailed in
Referring to
For each device variable currently in existence, its current node pointer is stored as ‘original node pointer’, so that later on it can be compared with the value it has at the end of the loop body.
The loop body is then executed, and the device data types record all steps of computation in the expression graph. The expression graph at the end of the loop body is shown in
At the end of the loop body, the function gpu_while_end( ), or any other function that is suitable for the flow control statement encountered, is called.
This function can have one or more of the following effects:
Referring to
Referring to
Referring to
Then the rest of the kernel function is executed, and
The expression graph is turned into program instructions for the device. The final program code may be machine code, or some intermediate code. In the given example, the resulting code corresponds to the following pseudo code:
This code, whether it is direct code, for example machine code, or indirect code, for example OpenCL code or some other intermediary code, is ready to be executed on the device.
Referring to
Flow control statements must be ordered in the correct way, usually in the same order as the corresponding statements occur in the source code, or possibly slightly relaxed. This can be achieved by adding dependency pointers between the flow control nodes. Here input value pointers are used instead; they are marked as solid arrows in
Nodes that are replaced by other nodes need to be evaluated in the correct scope, before the entry node of the flow control statement, in which they are replaced. All nodes that use these nodes as input must be evaluated after that entry node. Nodes that are replacing other nodes must be anchored in the correct flow control scope, between the entry node and the exit node, by adding dependencies. Writes to memory must be evaluated in the correct scope. No node shall be evaluated in a sub-scope. This means that if there are recursive flow control statements, for example an if clause within a while loop, then all nodes that relate to the while loop must be evaluated either before the ‘if begin’ node or after the ‘if end’ node. Nodes may be pre-calculated in parent scopes, though, unless a dependency prevents this.
To increase performance, optimizations can be performed on the expression graph. For instance, in the example above, the ‘<’ (smaller than) node that takes the values 1 and 10 as input is a constant expression and can be replaced by the value ‘true’.
The subject-matter of this document may be implemented in a wide variety of devices or apparatuses. Aforementioned devices constitute only examples. Various examples of the invented methods have been described. These and other examples are within the scope of the following claims.
While at least one exemplary embodiment has been presented in the foregoing detailed description, it should be appreciated that a vast number of variations exist. It should also be appreciated that the exemplary embodiment or exemplary embodiments are only examples, and are not intended to limit the scope, applicability, or configuration of the invention in any way. Rather, the foregoing detailed description will provide those skilled in the art with a convenient road map for implementing an exemplary embodiment, it being understood that various changes may be made in the function and arrangement of elements described in an exemplary embodiment without departing from the scope of the invention as set forth in the appended claims and their legal equivalents.
Number | Date | Country | Kind |
---|---|---|---|
15157809 | Mar 2015 | EP | regional |
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/EP2016/054542 | 3/3/2016 | WO | 00 |
Publishing Document | Publishing Date | Country | Kind |
---|---|---|---|
WO2016/139305 | 9/9/2016 | WO | A |
Number | Name | Date | Kind |
---|---|---|---|
5671416 | Elson | Sep 1997 | A |
5701490 | Safonov | Dec 1997 | A |
5915255 | Schwartz | Jun 1999 | A |
6014518 | Steensgaard | Jan 2000 | A |
6298481 | Kosaka | Oct 2001 | B1 |
6832378 | Beatty, III | Dec 2004 | B1 |
7146606 | Mitchell | Dec 2006 | B2 |
7370321 | Radigan | May 2008 | B2 |
8281297 | Dasu | Oct 2012 | B2 |
8866827 | Zhou | Oct 2014 | B2 |
8930926 | Bastoul | Jan 2015 | B2 |
9009660 | Griffin | Apr 2015 | B1 |
9152427 | Vorbach | Oct 2015 | B2 |
9158513 | Girouard | Oct 2015 | B2 |
9275426 | Hoeg | Mar 2016 | B2 |
9477477 | Dally | Oct 2016 | B2 |
9557975 | Angerer | Jan 2017 | B2 |
9569304 | Girouard | Feb 2017 | B2 |
9582924 | McNabb | Feb 2017 | B2 |
9589312 | Poddar | Mar 2017 | B2 |
9691122 | Bleiweiss | Jun 2017 | B2 |
9697300 | Kummer | Jul 2017 | B2 |
9804995 | Bourd | Oct 2017 | B2 |
9805498 | Fu | Oct 2017 | B2 |
9824026 | Dong | Nov 2017 | B2 |
9830133 | Baskaran | Nov 2017 | B1 |
9898297 | Vorbach | Feb 2018 | B2 |
9952842 | Lee | Apr 2018 | B2 |
20020100029 | Bowen | Jul 2002 | A1 |
20040268331 | Mitchell | Dec 2004 | A1 |
20080001953 | Nagao | Jan 2008 | A1 |
20080109795 | Buck | May 2008 | A1 |
20090187897 | Asao | Jul 2009 | A1 |
20100218196 | Leung | Aug 2010 | A1 |
20110173224 | Toledo | Jul 2011 | A1 |
20120185671 | Bourd | Jul 2012 | A1 |
20120239706 | Steinfadt | Sep 2012 | A1 |
20130031536 | De | Jan 2013 | A1 |
20130055207 | Cui | Feb 2013 | A1 |
20130159982 | Lerios | Jun 2013 | A1 |
20150279092 | Ganestam | Oct 2015 | A1 |
20150309846 | Prasad | Oct 2015 | A1 |
20150339797 | Lerios | Nov 2015 | A1 |
20150379670 | Koker | Dec 2015 | A1 |
20150379762 | Bleiweiss | Dec 2015 | A1 |
20160042552 | McNabb | Feb 2016 | A1 |
20160055611 | Manevitch | Feb 2016 | A1 |
20160070246 | Nakagawa | Mar 2016 | A1 |
20160093012 | Rao | Mar 2016 | A1 |
20160093069 | Maiyuran | Mar 2016 | A1 |
20160180486 | Rao | Jun 2016 | A1 |
20160180488 | Poddar | Jun 2016 | A1 |
20160232702 | Fu | Aug 2016 | A1 |
20160291942 | Hutchison | Oct 2016 | A1 |
20160328333 | Dong | Nov 2016 | A1 |
20170212791 | Laskowski | Jul 2017 | A1 |
20170236246 | Mrozek | Aug 2017 | A1 |
20170330371 | Krol | Nov 2017 | A1 |
Number | Date | Country |
---|---|---|
2012097316 | Jul 2012 | WO |
Entry |
---|
Thomas C. Jansen, GPU++ An Embedded GPU Development System for General-Purpose Computations , p. 1-128, [Retrieved online on Jun. 15, 2018 <http://mediatunn.ub.tum.de/doc/617693/921256.pdf>] (Year: 2007). |
Bourgoin et al., Efficient Abstractions for GPGPU Programming, Published by Springer, Int J Parallel Prog (2014) 42:583-600, p. 583-600 (Year: 2014). |
Stromme et al., Chestnut: A GPU Programming Language for Non-Experts, published by ACM, PMAM '12 Feb. 26, 2012, p. 156-167, [Retrieved online Jun. 15, 2018 <https://dl.acm.org/citation.cfm?id=2141720>] (Year: 2012). |
Vinas et al., Improving OpenCL programmability with the Heterogeneous Programming Library, ICCS 2015 International Conference on Computational Science, published by Procedia Computer Science, vol. 51, 2015, pp. 110-119 (Year: 2015). |
Lee et al., GPU Kernels as Data-Parallel Array Computations in Haskell, Appeared in Workshop on Exploiting Parallelism using GPUs and other Hardware-Assisted Methods (EPHAM 2009), pp. 1-9 (Year: 2009). |
Catanzaro et al., Copperhead: Compiling an Embedded Data Parallel Language, published by ACM, pp. 47-56, PPoPP'11, Feb. 12-16, 2011 (Year: 2011). |
Mokhtari et al., BigKernel—High Performance CPU-GPU Communication Pipelining for Big Data-style Applications, published by IEEE computer society, 2014 IEEE 28th International Parallel & Distributed Processing Symposium, pp. 819-828 (Year: 2014). |
Hestness et al., GPU Computing Pipeline Inefficiencies and Optimization Opportunities in Heterogeneous CPU-GPU Processors, published by IEEE computer society, 2015 IEEE International Symposium on Workload Characterization, pp. 87-97 (Year: 2014). |
Mark Harris et al, GPU Gems 2, Chapter 31, GPU Flow-Control Idioms, Apr. 2005, XP055198276. |
Number | Date | Country | |
---|---|---|---|
20180046440 A1 | Feb 2018 | US |