1. Field of the Invention
The present invention relates generally to the data processing field and, more particularly, to a computer implemented method, system and computer program product for aligning vectors to be processed by SIMD code.
2. Description of the Related Art
Modern processors are using Single Issue Multiple Data (SIMD) units with greater frequency in order to significantly increase processing power without having to significantly increase issue bandwidth. Although SIMD units can be programmed by hand, especially for dedicated libraries and a small number of kernels, the performance impact of SIMD units will likely remain limited until compiler technology permits automatic generation of SIMD code, referred to hereinafter as “simdization”, for a wide range of applications.
The SIMD process is basically a set of operations that enables efficient handling of large quantities of data in parallel.
In a non-simdized environment, for each iteration of a loop, the “b[i]+c[i]” data would have to be added individually. That is, the result of the first non-simdized operation would yield b0+c0, the result of the second would yield b1+c1, and so on. In contradistinction, as shown at 114, the result of one operation in the SIMD environment yields b0+c0, b1+c1, b2+c2 and b3+c3.
A problem that is encountered in connection with simdization relates to data alignment in that data does not properly align with system hardware. Current procedures for effecting data alignment tend to be rather complex and to require significant processing. This can be best understood by reference to the following example of a known alignment handling procedure for a simple code:
where it is assumed that all array bases are aligned at 16-byte boundaries. In the sample code noted above, the references “a” and “b” are each to a particular array, and the references “a[i]” and “b[i]” are to a specific address within array “a” and array “b”, respectively. Accordingly, there is misalignment between “b[i]” and “b[i+1]” (it is assumed that array “a” and array “b” are aligned relative to one another). This misalignment is shown in
In order to handle the misalignment of “b[i+1]” with respect to the 2 other references, a stream-shift operation is introduced as follows:
The notation “a[i+0 . . . 3]” is a contraction of “a[i+0, i+1, i+2, i+3], and this contracted notation will be used throughout this specification. The notation “i+=4” denotes the fact that the code segment above computes four values per iteration. Above, shift-pair-left(X, Y, offset) selects bytes offset, offset+1, . . . , offset+V−1 from a double-length vector constructed by concatenating A and B. V is the vector byte size, e.g. 16 bytes in this example. This misalignment correction is shown in
Consider the above example from the perspective of common subexpression elimination (CSE) or predictive commoning (PC). Since the alignment of array b is known, it is also known that vload(b[i+1]) is the same as vload(b[i+0]) because it is known that the non-aligning load truncates the last 4 bits of the address. This translates into truncating the offset in the array computation by a factor of 4. Thus, the above example can be rewritten truncating all the array computations by 4 as follows:
Predictive commoning is capable of seeing the reuse of the two “b[i+0 . . . 3]” and the reuse of the “b[i+4 . . . 7]” with the “b[i+0 . . . 3]” of the next iteration. As a result, the code would look as follows after predictive commoning:
It should be noted that there is a single load of array b that is used 3 times, 1 time in the current loop iteration and 2 times in the next iteration. Note also that the copy at the end of the loop trivially goes away with an unrolling of the loop by a multiple of 2.
Now consider this same example with a minor modification, namely with a runtime lower bound, denoted by “lb”:
The code segment above is normalized as follows:
Because the actual runtime alignment is not known, the system would have to load three data sets on its first iteration. In particular, the system would have to issue a SIMD load of b[i+lb+1] and a SIMD load of b[i+lb+5], and then stream-shift these two vectors to generate the vector b[i+lb+1, i+lb+2, i+lb+3, i+lb+4]. Because the system cannot determine in advance the congruence class in which a particular instance of b[i+lb] and b[i+lb+1] will fall, we cannot eliminate one of the SIMD loads to b[i+lb] and b[i+lb+1].
Consider the example illustrated in
As is apparent from
As seen above, the (absolute) alignment of all references are runtime, inasmuch as the value of lb is only known at runtime (in this example). The relative alignment of any two pairs of memory references, however, is known at compile time. Relative alignment is computed as the difference between two addresses mod V (V=16 on VMX/SPE).
Current robust alignment handling procedures, which are able to handle any combination of conversions and runtime alignments, proceed by 1) appropriately prepending bytes to the stream that needs to be shifted; and 2) shifting the prepended stream to offset zero. In the absence of conversions, the prepended amount is the actual alignment of the destination stream.
In particular, if it is desired to align a stream b[i+lb+1] with runtime alignment (lb+1)*4 mod 16 to the runtime alignment of a[i+lb], namely 4*lb mod 16, in the absence of conversions, the following is performed:
Given that the other b[i+lb] is relatively aligned to a[i+lb], the following code is obtained for the example after simdization:
From the perspective of CSE, the expression b[ . . . i+lb . . . ] and b[ . . . i+1+lb&!3 . . . ] cannot be commoned out, in general. This can be seen from the values in Table 1 wherein truncation occurs at different places depending on runtime ‘lb’:
In addition, predictive commoning has difficulties seen in the reuse between b[ . . . i+1+lb&!3 . . . ] and b[ . . . i+5+lb&!3 . . . ]. Thus, in the presence of a runtime lower bound, the number of loads for the b memory streams increases from 1 (compile time lower bound) to 3.
The present invention provides a computer implemented method, system and computer program product for aligning vectors to be processed by SIMD code. The method begins by identifying a pair of vectors to be aligned at runtime and having a known relative alignment at compile time. A modified second memory reference is generated by modifying an address of the second memory reference to be in a same congruence class as the first memory reference, wherein the congruence class is mod V and wherein V is SIMD byte width. A first SIMD load located at the modified second memory reference and a next adjacent SIMD load located at a third memory reference corresponding to the modified second memory reference address plus V are loaded, and the first SIMD load and the next adjacent SIMD load are concatenated to generate a resultant vector of length 2V. The resultant vector is left shifted by an amount corresponding to a difference between the addresses of the first memory reference and the second memory reference mod V, and the leftmost V bytes of the resultant vector are retained to align the first and second vectors.
The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein:
With reference now to the figures and in particular with reference to
With reference now to the figures,
In the depicted example, server 504 and server 506 are coupled to network 502 along with storage unit 508. In addition, clients 510, 512, and 514 are coupled to network 502. These clients 510, 512, and 514 may be, for example, personal computers or network computers. In the depicted example, server 504 provides data, such as boot files, operating system images, and applications to clients 510, 512, and 514. Clients 510, 512, and 514 are clients to server 504 in this example. Network data processing system 500 may include additional servers, clients, and other devices not shown.
In the depicted example, network data processing system 500 is the Internet with network 502 representing a worldwide collection of networks and gateways that use the Transmission Control Protocol/Internet Protocol (TCP/IP) suite of protocols to communicate with one another. At the heart of the Internet is a backbone of high-speed data communication lines between major nodes or host computers, consisting of thousands of commercial, governmental, educational and other computer systems that route data and messages. Of course, network data processing system 500 also may be implemented as a number of different types of networks, such as for example, an intranet, a local area network (LAN), or a wide area network (WAN).
With reference now to
In the depicted example, data processing system 600 employs a hub architecture including north bridge and memory controller hub (NB/MCH) 602 and south bridge and input/output (I/O) controller hub (SB/ICH) 604. Processing unit 606, main memory 608, and graphics processor 610 are coupled to NB/MCH 602. Graphics processor 610 may be coupled to NB/MCH 602 through an accelerated graphics port (AGP).
In the depicted example, local area network (LAN) adapter 612 is coupled to SB/ICH 604. Audio adapter 616, keyboard and mouse adapter 620, modem 622, read only memory (ROM) 624, universal serial bus (USB) ports and other communication ports 632, and PCI/PCIe devices 634 are coupled to SB/ICH 604 through bus 638, and hard disk drive (HDD) 626 and CD-ROM drive 630 are coupled to SB/ICH 604 through bus 640. PCI/PCIe devices may include, for example, Ethernet adapters, add-in cards, and PC cards for notebook computers. PCI uses a card bus controller, while PCIe does not. ROM 624 may be, for example, a flash binary input/output system (BIOS).
HDD 626 and CD-ROM drive 630 are coupled to SB/ICH 604 through bus 640. HDD 626 and CD-ROM drive 630 may use, for example, an integrated drive electronics (IDE) or serial advanced technology attachment (SATA) interface. Super I/O (SIO) device 636 may be coupled to SB/ICH 604.
An operating system runs on processing unit 606 and coordinates and provides control of various components within data processing system 600 in
As a server, data processing system 600 may be, for example, an IBM® eServer™ pSeries® computer system, running the Advanced Interactive Executive (AIX®) operating system or the LINUX® operating system (eServer, pSeries and AIX are trademarks of International Business Machines Corporation in the United States, other countries, or both while LINUX is a trademark of Linus Torvalds in the United States, other countries, or both). Data processing system 600 may be a symmetric multiprocessor (SMP) system including a plurality of processors in processing unit 606. Alternatively, a single processor system may be employed.
Instructions for the operating system, the object-oriented programming system, and applications or programs are located on storage devices, such as HDD 626, and may be loaded into main memory 608 for execution by processing unit 606. The processes for embodiments of the present invention are performed by processing unit 606 using computer usable program code, which may be located in a memory such as, for example, main memory 608, ROM 624, or in one or more peripheral devices 626 and 630.
Those of ordinary skill in the art will appreciate that the hardware in
In some illustrative examples, data processing system 600 may be a personal digital assistant (PDA), which is configured with flash memory to provide non-volatile memory for storing operating system files and/or user-generated data.
A bus system may be comprised of one or more buses, such as bus 638 or bus 640 as shown in
The present invention provides a computer implemented method, system and computer program product for aligning vectors to be processed by SIMD code. A system of the present invention may be implemented in a processor, such as processing unit 606 in data processing system 600 illustrated in
A problem with the known alignment processing approach described previously occurs in connection with the “+1” in the two b[i+lb] and b[i+lb+1] references. In accordance with exemplary embodiments of the present invention, it is recorded that the two addresses are 4 bytes apart, and then load in both cases b[i+lb] and shift that value by 4 bytes to get the second stream. In other words, the addresses are normalized aggressively, even in the presence of runtime alignment, and then the normalization step is corrected by shifting the loaded values. The objective is to make sure that the truncation that occurs in the load (as seen in Table 1) occurs at the same value of lb (or whatever makes the alignment runtime alignment).
As will become apparent hereinafter, the present invention may significantly reduce the number of memory references in real code, which can result in a significant speedup when executing.
In order to provide a clear understanding of aspects of the present invention, the following example is provided. In particular, consider two references A[i+X+Oa] and B[i+X+Ob] where X is some runtime variable and Oa and Ob are compile time offsets. Assume that it is desired to align the B array stored at the reference to the alignment of the A array stored at the reference. Assuming the arrays are aligned and are arrays of integers, the alignments of A and B are, respectively, 4(X+Oa) mod 16 and 4(X+Ob) mod 16. Their relative alignment is 4(Ob−Oa) mod 16.
For statements without conversions, and with relative alignment known at compile time, the following may be done to align B to the alignment of A:
Using the above value for references A and B provides:
Assuming Oa=0, consider a few values for Ob as shown in Table 2:
It can be seen that no matter the value of Ob, only compile time multiples of 4 are added to/subtracted from the addresses of B, which makes it very easy for the compiler to detect redundancy in the address streams.
Assuming Oa=7, consider a few values for Ob as shown in Table 3:
Again it can be seen that regardless of the value only compile time multiples of 4 are added/subtracted to the address of B.
Accordingly, using this new formula in the example, the following is obtained after simdization:
In this example, predictive commoning succeeds in collapsing all b references to a single one, as below:
If a pair of vectors to be aligned at runtime is identified (Yes output of Step 704), a modified second memory reference is generated by modifying an address of the second memory reference to be in a same congruence class as the first memory reference, wherein the congruence class is mod V and wherein V is SIMD byte width (Step 706). A first SIMD load located at the modified second memory reference and a next adjacent SIMD load located at a third memory reference corresponding to the modified second memory reference address plus V are loaded (Step 708), and the first SIMD load and the next adjacent SIMD load are concatenated to generate a resultant vector of length 2V (Step 710). The resultant vector is left shifted by an amount corresponding to a difference between the addresses of the first memory reference and the second memory reference mod V (Step 712), and the leftmost V bytes of the resultant vector are retained to align the first and second vectors(Step 714). According to an exemplary embodiment of the invention, the step of left shifting the resultant vector by an amount corresponding to a difference between the addresses of the first memory reference and the second memory reference mod V is accomplished by concatenating each of V bytes of data initially loaded from the modified address of the second memory reference and from the loaded modified second memory address plus V of the third memory reference for obtaining a 2*V bytes of concatenated data. A number of bytes that corresponds to a difference between the addresses of the first and second memory reference addresses mod V from a beginning of the concatenated data are discarded, keeping the next V bytes from the concatenated data. The remaining data in the concatenated data is also discarded such that the kept V bytes from the concatenated data corresponds to desired data from the second memory reference, and are properly aligned with the first memory reference.
The method then returns to Step 704 to determine whether another pair of vectors to be aligned at runtime and having a known relative alignment at compile time is identified, and if so, the method is repeated. If no further pairs of vectors are identified (No output of Step 704), the method ends.
The present invention thus provides a computer implemented method, system and computer program product for aligning vectors to be processed by SIMD code. The method begins by identifying a pair of vectors to be aligned at runtime and having a known relative alignment at compile time. A modified second memory reference is generated by modifying an address of the second memory reference to be in a same congruence class as the first memory reference, wherein the congruence class is mod V and wherein V is SIMD byte width. A first SIMD load located at the modified second memory reference and a next adjacent SIMD load located at a third memory reference corresponding to the modified second memory reference address plus V are loaded, and the first SIMD load and the next adjacent SIMD load are concatenated to generate a resultant vector of length 2V. The resultant vector is left shifted by an amount corresponding to a difference between the addresses of the first memory reference and the second memory reference mod V, and the leftmost V bytes of the resultant vector are retained to align the first and second vectors.
The invention can take the form of an entirely software embodiment, or an embodiment containing both hardware and software elements. In a preferred embodiment, the invention is implemented in software, which includes but is not limited to firmware, resident software, microcode, etc.
Furthermore, the invention can take the form of a computer program product accessible from a computer-usable or computer-readable medium providing program code for use by or in connection with a computer or any instruction execution system. For the purposes of this description, a computer-usable or computer readable medium can be any tangible apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
The medium can be an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system (or apparatus or device) or a propagation medium. Examples of a computer-readable medium include a semiconductor or solid state memory, magnetic tape, a removable computer diskette, a random access memory (RAM), a read-only memory (ROM), a rigid magnetic disk and an optical disk. Current examples of optical disks include compact disk-read only memory (CD-ROM), compact disk-read/write (CD-R/W) and DVD.
A data processing system suitable for storing and/or executing program code will include at least one processor coupled directly or indirectly to memory elements through a system bus. The memory elements can include local memory employed during actual execution of the program code, bulk storage, and cache memories which provide temporary storage of at least some program code in order to reduce the number of times code must be retrieved from bulk storage during execution. Input/output or I/O devices (including but not limited to keyboards, displays, pointing devices, etc.) can be coupled to the system either directly or through intervening I/O controllers.
Network adapters may also be coupled to the system to enable the data processing system to become coupled to other data processing systems or remote printers or storage devices through intervening private or public networks. Modems, cable modem and Ethernet cards are just a few of the currently available types of network adapters.
The description of the present invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiment was chosen and described in order to best explain the principles of the invention, the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.
This invention was made with Government support under the National Security Agency, Contract No. H98230-04-C-0920. THE GOVERNMENT HAS CERTAIN RIGHTS IN THIS INVENTION.