The present invention relates to a computer architecture and in particular to an architecture that provides for exception handling with reduced demands for storage of the computer state.
Exceptions are occurrences during the execution of a computer program that interrupt the normal program flow dictated by the instructions themselves. Example exceptions include: arithmetic exceptions caused by an instruction whose executed results do not map into a valid range of the instruction output, for example a division by zero which does not map into a finite floating-point output. Another example would be an ASCII to integer conversion function receiving a non-numeric ASCII string (e.g. “cat”). Page faults, where a memory resource relied upon is unavailable (for example in high-speed memory), may also be considered a class of exceptions, as may other hardware interrupt occurrences.
An exception is normally handled by a special circuit of the computer processor which detects the exception in response by saving the state of the processor (e.g. processor registers) and jumping to an exception handler being a subroutine written to treat a specific exception. Page faults and other hardware interrupts are typically resolved (for example, a page fault is resolved by loading the necessary data from disk) and the program may resume from the point of the exception. Some exceptions, for example division by zero, may not be resolved.
Graphic processors use a computer architecture in which a large number of processing elements may operate in parallel on graphic tasks, for example, shading, rasterization, rotation and other geometric manipulations, to provide for graphic displays of data. The large number of processing elements used in a graphic processor is practical because each processing element is relatively simple. Graphic processors are normally used in conjunction with a conventional processor having separate memory from the memory of the graphic processor. Graphic operations are conducted through a series of steps in which the conventional processor moves data from its memory to the memory of the graphic processor and then, upon completion of the graphic processing, moves the data from the memory of the graphic processor back to its own memory.
Support for exception handling in graphic processors, for example to handle page faults, would permit merging of the memory models of the main computer processor and a graphic processor simplifying the use of the graphic processor system. The ability to incorporate exception handling into graphic processors, however, is hampered by the complex architectural state of the graphic processor. While saving the architectural state in a conventional processor requires saving and restoring a few tens of registers, in a graphic processor, saving the architectural state could require saving and storing hundreds and thousands of registers. Adding the necessary circuit to save this architectural state would largely defeat the simplified architecture of the processing units underlying the scalability of its architecture.
The present invention provides sophisticated exception handling for a processing unit, such as those used in graphic processing units, without the need for extensive storage capacity for recording architectural state. The problem of storing architectural state for exception handling is managed through the identification of idempotent regions of the executed code. An idempotent region is a set of instructions that may be re-executed without reinitialization of variables at the start of re-execution either because variables do not change as a result of the execution or the variables are self-initialized during the execution. By identifying idempotent regions, a restoration of architectural state can be implemented simply by moving backward in the program without storage of the architectural state.
Specifically, in one embodiment the invention provides an electronic computer including an idempotent region identifier circuit identifying boundaries between instructions defining groups of instructions whose execution is idempotent. An exception management circuit responds to an exception thrown during execution of a given instruction to restart execution of instructions by the processing unit at a preceding boundary of an idempotent region.
It is thus a feature of at least one embodiment of the invention to provide a method of handling exceptions that greatly reduces the hardware overhead of storing architectural state.
The exception management circuit may block handling of the exception before restarting execution of the instructions and, after restarting execution, handle the exception routine immediately prior to the given instruction without executing the given instruction.
It is thus a feature of at least one embodiment of the invention to ensure exception handling results in a correct live program state, that is, a correct state of the program going forward from the exception.
The exception management circuit may patch into the instructions an emulation of the given instruction before the given instruction, the emulation duplicating the exception thrown by the given instruction, before restarting execution of the instructions at the preceding boundary and removes the patch instruction after a calling of the exception handling routine by the patch, and resumes execution of instructions after the given instruction.
It is thus a feature of at least one embodiment of the invention to provide a simple mechanism applicable to a wide variety of computer architectures for properly timing handling of the exception.
The exception management circuit may detect the occurrence of an exception thrown by a second given instruction during the restarting of execution by the processing unit as a live-lock.
It is thus a feature of at least one embodiment of the invention to detect live-lock situations.
The exception management circuit may further respond to detection of a live-lock by dynamic recompilation of the instructions to separate the given and second given instructions into separate idempotent regions.
It is thus a feature of at least one embodiment of the invention to provide a versatile method for overcoming live-lock such as can occur when repeating execution of idempotent regions.
The exception may be an arithmetic exception indicating an improper execution of an arithmetic instruction or a page fault indicating data of an accessed virtual memory page is not available.
It is thus a feature of at least one embodiment of the invention to provide a technique widely applicable to different types of exceptions
The idempotent region identifier circuit may further identify live-in variables at the boundaries and store those live-in variables based on this identification and the exception management circuit may load the stored live-in variables upon the restarting of execution of the instructions by the processing unit at the previous boundary.
It is thus a feature of at least one embodiment of the invention to provide a system that may accommodate page faults having rapid context switching.
The idempotent region identifier circuit may identify first and second boundaries between instructions, defining groups of instructions whose execution is idempotent, the second boundaries defining subgroups of instructions within groups of instructions defined by the first boundaries.
It is thus a feature of at least one embodiment of the invention to provide regions tailored to different exception conditions, for example, including regions suitable for handling this speculation.
The processing unit may be a graphic processing unit processing graphics commands for the display of graphical information.
It is thus a feature of at least one embodiment of the invention to provide an exception handling technique useful for graphic processing units or the like where storage of architectural state would be difficult or impossible.
The idempotent region identifier circuit may identify idempotent regions by detecting region-start instructions inserted into the instructions.
It is thus a feature of at least one embodiment of the invention to provide a simple method of identifying idempotent regions at runtime using compiler-inserted instructions.
The present invention may correspondingly provide a computer program used to provide a set of instructions for executing on an electronic computer. The computer program may identify within a target program multiple idempotent regions being regions of sequentially executed instructions of the target program that may be executed multiple times while having a same effect on variables used in the idempotent region and, later in the target program, as if the idempotent region were executed a single time, and further may identify for each idempotent region live-in variables that may be read before their next write after execution of the idempotent region. After this identification the compiler may mark regions for identification by a processor executing the target program and may to mark the regions to identify the live-in variables for the region.
It is thus a feature of at least one embodiment of the invention to separate processing software to mark live-in variables for runtime consideration.
The computer program may select among idempotent regions based on optimization criteria to mark particular regions in order to minimize live-in variables associated with the region.
It is thus a feature of at least one embodiment of the invention to select idempotent region so as to minimize the need for storage of live-in variables.
The computer program may further identify first idempotent regions being subsets of second idempotent regions and mark the regions to indicate whether they are first idempotent regions or second idempotent regions.
It is thus a feature of at least one embodiment of the invention to permit selection of different sizes of idempotent regions during runtime based on the type of exception being handled (e.g. arithmetic faults, page faults, and mis-speculation).
These particular objects and advantages may apply to only some embodiments falling within the claims and thus do not define the scope of the invention
Referring now to
In one embodiment, present invention may be used with one or more compilers 16, to be described below, serving to convert the source code program 10 to a compiled program 18 having object instructions 20. The compiled program 18 may be divided by the compiler into multiple idempotent regions 22.
Each idempotent region 22 includes instructions 20 which, when executed multiple times (the last time to completion), have the same effects on variables used in the idempotent regions 22 and, used later in the compiled program 18, that would be obtained if the idempotent region 22 were executed a single time. More generally, each idempotent region 22 does not overwrite its live-in variables.
The compiler 16 may then mark each idempotent region 22 with a region-start instruction 24 being specialized instructions that may be detected by the processing units of the present invention so that they can determine the extent of the idempotent regions 22. Other methods may also be used to identify each idempotent region 22, for example, a table of the instruction addresses or the like.
Referring still to
Based on the analysis of the live-in variables, the compiler 16 may collect one or more of the fine idempotent regions 32 into coarse idempotent regions 30, denoted A and B in
The boundaries of the coarse idempotent regions 30 and fine idempotent regions 32 may be identified by a tag 29, for example added to the region-start instructions 24 at a start of either a coarse idempotent region 30 or the beginning of a fine idempotent region 32. It will be appreciated that these tags are simply logical constructs and may be represented in any number of ways either within the instructions 24 as bit patterns or a table linked to the instruction address (program counter).
Referring now to
Flow dependencies are read-after-write data dependencies in which a first instruction 20 writes to a data value and then is followed by a second instruction 20 that reads from the same data value. Flow dependencies are consistent with idempotency because, on repetition of the flow dependency instructions, the first write instruction returns the program to an identical state for each subsequent execution.
Anti-dependencies, in contrast, are “write-after-read” dependencies in which an instruction that reads a variable is followed by an instruction that writes the same variable. It will be understood that this second writing of the variable can defeat idempotency because it changes the variable so if the instructions including the dependency bar are repeated, that variable will have a changed value.
Not all anti-dependencies destroy idempotency, however. If an anti-dependency is preceded by a writing of the variable at issue then, like a flow dependency, re-executing the program restores the program to its initial state of that first writing. This preceding write permits idempotency even with a following anti-dependency.
If the anti-dependency is not preceded by a writing of the variable (a flow dependency), it will be termed a “clobber anti-dependency” which is generally fatal to idempotency. Thus, regions 22 of idempotency may be identified by detecting the presence or absence of clobber anti-dependencies. The following chart summarizes this general principle:
Idempotent regions 22 are identified by collecting contiguous instructions 20 that do not straddle a clobber anti-dependency, a process enforced by process block 33 which forms the idempotent regions 22 to cut clobber anti-dependencies. Contiguous in this context refers to the execution sequence of the instructions 20 rather than their place in the source code program 10 or in computer memory.
The concept of the idempotent region 22 is discussed in detail in co-pending U.S. application Ser. No. 13/100,517 entitled “Computer Processor Providing Error Recovery with Item Potent Regions” filed May 4, 2011, assigned to the same assignee as the present invention and hereby incorporated by reference.
As indicated by process block 35, idempotent regions 22 identified are then marked by special region-start instructions 24 that indicate the live-in variables associated with that region (as discussed above).
As indicated by process block 37, a collection of idempotent regions 22, divided into coarse idempotent regions 30 and fine idempotent regions 32 according to the number of live-in variables, is then made and the region-start instructions 24 marked to indicate the boundaries of those coarse idempotent regions 30 and fine idempotent regions 32.
Referring now to
In one application of the invention, the processor system 40 may be a graphic processing unit or GPU having a large number of processing units 42 for processing image data stored in memory 34 for display of that image data on a display screen or for other similar purposes. Referring still to
Importantly, each processing unit 42 will provide for exception handling circuit 54 for handling exceptions in the execution of computer instructions, for example arithmetic exceptions and page faults related to failure of necessary data to be in the memory 34. In addition each processing unit 42 will also provide for idempotent circuit 56 implementing features of the present invention as will be described below.
Referring now to
Upon detection of the boundary, the value of the program counter 48 (shown in
At succeeding process block 66, any ongoing speculation may be terminated, for example, by forcing a commitment of speculation.
Referring now to
Upon detecting the exception 70, the idempotent circuit 52 proceeds to decision block 72 to check to see if the current execution (during which the exception 70 has been thrown) is in fact already a restarting of the program 18 at the beginning of an idempotent coarse idempotent region 30 caused by an earlier exception 70. This check addresses problems of live-lock as will be discussed below.
If the current execution is not part of a previous exception handling (as assumed in the example of
Sometime before the restarting of process block 77 and as indicated by process block 74, a patch 76 is inserted into the compiled program 18 around the instruction 20′ throwing the exception 70, the patch 76 serving to emulate the instruction 20′ yet to provide exception handling otherwise unachievable by the processing unit 42. For example, the exception 70 may produce multiple page faults (for example with a wide address load) that overwhelm the hardware resources required for the context switching. In this case, the emulating instructions of the patch 76 may divide up the function of the instruction 20′ to handle each page faults sequentially. Thus, when the execution of the program 18 arrives at instruction 20′ for the second time, the patch 76 is executed instead of the instruction 20′ ensuring successful handling of the exception 70. The handling of the thrown exception 70 can in this way be handled with limited hardware resources for storing architectural state.
In the case where program control is returned after the exception handling (resolved), the patch 76 concludes and removes itself and removes the flag indicating that a restart has occurred (used by decision block 72). The idempotent circuit 52 then begins execution again at the instruction immediately succeeding instruction 20′.
Referring now to
This restarting causes the necessary patch to be added around instruction 20″ but, before that patch 76 can be executed, the program 18 again arrives at instruction 20′ this time without a patch 76. It will be appreciated that this second encounter with instruction 20′, if not detected, could again cause a restarting of the program 18, a patching of instruction 20′ and a handling of the exception of instruction 20′ that has already been handled instead of handling of the exception of instruction 20″.
Accordingly at decision block 72, as described above, when an exception 70 is encountered during an ongoing restarting of the idempotent coarse idempotent region 30 (indicated by the flag discussed above), that exception 70 is identified as providing for live-lock. This live-lock situation may be remedied by single-step re-execution or dynamic recompilation of the instructions so that the two exception throwing instructions 20′ and 20″ are placed in separate idempotent regions 22. While each of these solutions is slow to execute, such live lock situations should be rare. Single-stepped execution refers to execution without speculation and at a sufficiently slow speed so that in the event of an exception, the exception may be handled so that architectural state reaches a consistent value before proceeding to a next instruction.
Referring now to
The context switch may move the processing unit 42 to the beginning of different coarse idempotent region 30 of the new task or program 18′. The processing unit 42 may then load the live-in variables associated with that coarse idempotent region 30 indicated by the instruction 24 stored in registers associated with this particular context. When the reason for the context switching is resolved (by resolution of the page fault according to methods well known in the art), the context may switch back as indicated by dotted segment 84 to the beginning of the original coarse idempotent region 30 in which the page fault 81 occurred again per process block 77. The live-in variables at the beginning of the coarse idempotent region 30 as designated by the instruction 24 are loaded and the processing unit 42 may proceed to execute instructions of the original coarse idempotent region 30 without the need for extensive state restoration. Note that the program execution does not return to the point of the page fault 81 in the original coarse idempotent region 30, as is typically done in recovery from a page fault. This is possible because, as noted above, the coarse idempotent region 30 is idempotent and only a small penalty is realized by re-executing earlier instructions at the relatively low occurrence rate of page faults. The size of the coarse idempotent regions 30 may be set flexibly to ensure the proper trade-off between exception handling penalty and frequency of the exceptions, exceptions in this case referring both to arithmetic exceptions, page fault exceptions, and other kinds of exceptions.
Referring now again to
It will be appreciated that the work in identifying the idempotent regions and the live-in variables by a compiler may alternatively be done by manual insertion of instructions by the programmer or by automatic identification of the regions by the computer itself during runtime, for example, looking for proxies for such idempotent regions in types or patterns of instructions or by providing a dedicated thread preprocessing the program.
Certain terminology is used herein for purposes of reference only, and thus is not intended to be limiting. For example, terms such as “upper”, “lower”, “above”, and “below” refer to directions in the drawings to which reference is made. Terms such as “front”, “back”, “rear”, “bottom” and “side”, describe the orientation of portions of the component within a consistent but arbitrary frame of reference which is made clear by reference to the text and the associated drawings describing the component under discussion. Such terminology may include the words specifically mentioned above, derivatives thereof, and words of similar import. Similarly, the terms “first”, “second” and other such numerical terms referring to structures do not imply a sequence or order unless clearly indicated by the context.
When introducing elements or features of the present disclosure and the exemplary embodiments, the articles “a”, “an”, “the” and “said” are intended to mean that there are one or more of such elements or features. The terms “comprising”, “including” and “having” are intended to be inclusive and mean that there may be additional elements or features other than those specifically noted. It is further to be understood that the method steps, processes, and operations described herein are not to be construed as necessarily requiring their performance in the particular order discussed or illustrated, unless specifically identified as an order of performance. It is also to be understood that additional or alternative steps may be employed.
References to “a circuit” a “microprocessor” and “a processor” or “the microprocessor” and “the processor,” can be understood to include one or more circuits or microprocessors that can communicate in a stand-alone and/or a distributed environment(s), and can thus be configured to communicate via wired or wireless communications with other processors, where such one or more processor can be configured to operate on one or more processor-controlled devices that can be similar or different devices. Furthermore, references to memory, unless otherwise specified, can include one or more processor-readable and accessible memory elements and/or components that can be internal to the processor-controlled device, external to the processor-controlled device, and can be accessed via a wired or wireless network. A single microprocessor or similar computer executing different programs may provide different circuits by virtue of the programs control of current flow in hardware. Accordingly, it will be understood that the invention contemplates that the described circuits for example the exception management circuitry, may be implemented flexibly through discrete circuitry, microcoding (firmware) and associated processing circuitry, gate arrays, and general-purpose processors executing programs including special application programs and/or operating system functions.
It is specifically intended that the present invention not be limited to the embodiments and illustrations contained herein and the claims should be understood to include modified forms of those embodiments including portions of the embodiments and combinations of elements of different embodiments as come within the scope of the following claims. All of the publications described herein, including patents and non-patent publications, are hereby incorporated herein by reference in their entireties.
This invention was made with government support under 0845751 and 0917238 awarded by the National Science Foundation. The government has certain rights in the invention.
Number | Name | Date | Kind |
---|---|---|---|
5043867 | Bhandarkar et al. | Aug 1991 | A |
5668971 | Neufeld | Sep 1997 | A |
20110078427 | Shebanow et al. | Mar 2011 | A1 |
20120284562 | Sankaralingam et al. | Nov 2012 | A1 |
Entry |
---|
Hampton, Mark, et al, Implementing Virtual Memory in a Vector Processor with Software Restart Markers, 20th ACM International Conference on Supercomputing (ICS06), Cairns, Australia, Jun. 2006. |
Mahlke, Scott A., et al., Sentinel Scheduling: A Model for Compiler-Controlled Speculative Execution, ACM Transactions on Computer Systems, pp. 1-47, Nov. 1993. |
Number | Date | Country | |
---|---|---|---|
20140019735 A1 | Jan 2014 | US |