Electronic devices have become an integral part of daily life. Many electronic applications utilize ranking of results using TopK operation. For example, in one particular application in machine learning (ML), a TopK is used to identify the top K indices or entries with the highest probabilities among a large set of data entries, e.g., classifying an image among thousands of classes. Similarly, TopK operation has become a common operator in other applications such as ad-hoc search and retrieval in relational databases, document and multimedia databases, etc.
In general, to perform TopK, elements in a vector are compared to one another in order to identify the largest K values in sorted order and the index locations associated with each of those largest K values are also tracked at the same time. The amount of data being processed has increased substantially in recent years given an increase in ML applications as well as increased amount of data being exchanged. While comparing elements of a vector to identify the largest K values in sorted order may be feasible for small vectors, it has become computationally expensive for larger vector lengths (especially given the increase in the amount of data) because large amount of computation power is wasted on sorting elements of the vector that are not even in the top K elements. Other conventional methods sequentially identify the maximum value within a given vector and repeat that for the next maximum value until the top K values are sorted. Unfortunately, sequentially identifying the maximum values to obtain the top K values in a sorted fashion requires repeating certain instructions multiple times, e.g., reading the vector elements multiple times, performing comparison instructions multiple times, etc., which results in computation inefficiencies.
Aspects of the present disclosure are best understood from the following detailed description when read with the accompanying figures. It is noted that, in accordance with the standard practice in the industry, various features are not drawn to scale. In fact, the dimensions of the various features may be arbitrarily increased or reduced for clarity of discussion.
The following disclosure provides many different embodiments, or examples, for implementing different features of the subject matter. Specific examples of components and arrangements are described below to simplify the present disclosure. These are, of course, merely examples and are not intended to be limiting. In addition, the present disclosure may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed.
Before various embodiments are described in greater detail, it should be understood that the embodiments are not limiting, as elements in such embodiments may vary. It should likewise be understood that a particular embodiment described and/or illustrated herein has elements which may be readily separated from the particular embodiment and optionally combined with any of several other embodiments or substituted for elements in any of several other embodiments described herein. It should also be understood that the terminology used herein is for the purpose of describing the certain concepts, and the terminology is not intended to be limiting. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood in the art to which the embodiments pertain.
As discussed, TopK operation has become prevalent for ranking results in various applications such as ML applications. Unfortunately, TopK operation has traditionally been implemented in an inefficient and wasteful manner, e.g., unnecessary use of memory, excessive processing power, etc. Accordingly, a need has arisen to reduce the amount of computing resources, e.g., memory, processing power, etc., used in performing a TopK operation. Moreover, a need has arisen to perform a TopK operation as fast as possible. Some embodiments, as presented herein, leverage the arithmetic logic units (ALUs) and registers (e.g., register depths) within a ML hardware to perform the TopK operation in an efficient manner. It is appreciated that in some embodiments, for a small K (that depends on the relative size of the register and ALUs), a single path through the vector may be sufficient while for a large K, the vector is read once from the memory where the original vector is stored while intermediate stages of the data processing are stored in on-chip memories and where multiple reads/writes may occur.
In general, a TopK operation identifies the top K index locations of a vector having the largest data. For illustrative purposes, a vector data may be V=[100, 2, 101, 53, 33, 53, 67, 94] and it may have eight elements. A TopK operation for K=4 identifies the indices (in this illustrative example, the index starts with 0 but in other embodiments, the index may start with 1) of the largest four values. In other words, index 2 corresponding to element 101, index 0 corresponding to element 100, index 7 corresponding to element 94, and index 6 corresponding to element 67. As such, the TopK operation with K=4 results in [2, 0, 7, 6]. It is appreciated that if two elements of the vector data have the same value (e.g., index 3 and 5 for element 53) then the index of the first occurrence of the element (i.e. index 3) is taken, followed by a later element (i.e. index 5).
The proposed approach leverages and utilizes the architecture of a ML hardware-based system in some embodiments that are implemented with an instruction set architecture (ISA) to utilize the processing element registers in an efficient manner to limit the amount of data movement. According to some embodiments, a register width is used to track the top K values when performing a TopK operation. For illustrative purposes, the width of register is presumed to be 8 and that K is also 8. However, it is appreciated that the register width may be any width and that the value of K may be any value. As such, the register width of 8 and K of 8 is used for illustrative purposes and should not be construed as limiting the scope of the embodiments. The vector data may have any number of elements, e.g., 1000 elements, 1024 elements, 256 elements, etc. It is appreciated that in general the value of K is less than or equal to the width of the register.
In some embodiments, the first K elements of the vector data are read, sorted, and stored in the register. When a new element of the vector data is read, if the newly read element does not have a value within the range of the first K elements, or greater, that are sorted and stored in the register, then the next element is read and the process is repeated. However, if the newly read element has a value within the range of the first K elements that are sorted and stored in the register, then elements within the register that are smaller than the read element are moved and shifted to make room for the new element that was read. The elements within the register that are greater than or equal to the read element are also moved and the newly read element is inserted in the vacant position. As such, the register is updated with new top K elements. It is appreciated that the process is repeated until every element of the vector data is processed and final top K elements are obtained. It is appreciated that the index associated with each element of the vector data may be tracked throughout process.
In the example of
It is appreciated that the next element of the vector data may be read, i.e. m9. Once read, the processor 120 may determine whether the new element, i.e. m9, has a value that is within a range of values already stored in the register 130 or higher, i.e. whether m9 has a value higher than or between the highest value element m3 and the lowest value element m6. For illustrative purposes, it is determined that m9 has a value that is less than m6. Accordingly, no further processing is performed for element m9 of the vector data.
It is appreciated that the next element, i.e. m10, from the vector data stored in the register 110 is read by the processor 120. Similar to element m9, the processor 120 determines whether the newly read element m10 has a value that is greater than or within the range of values corresponding to elements stored in register 130, i.e. in this example between the highest value element m3 and lowest value element m6.
In one nonlimiting example, m10 is determined to be greater than element m7 but less than element m5. As such, the processor 120 identifies the position 126 where m10 is to be inserted. The smallest value element, i.e., m6 in this example, will be shifted out as it will no longer be in the top K elements. In some embodiments a subset of elements, e.g., m7, m4, and m6, are shifted. Thus, m6 is eliminated from register 130 while the position of m7 and m4 is changed. Accordingly, a vacant position is created to insert the element value m10. Once m10 is inserted, its index i10 may also be tracked. As such, register 130 contains the updated top K (in this example top 8) elements of the first 10 elements of the vector data read from register 110. The process is repeated for each remaining element of the vector data that is stored in the register 110 until all elements are read and the top K elements are updated. Once all elements are read and processed, as described above, the register 130 will contain the top K elements of the vector data.
As illustrated by the example above, the number of data movements and data read is reduced in comparison to the conventional method. For example, the elements of vector data stored in the register 110 are read once. The intermediate values are stored in other registers and updated, as needed, to form an updated top K elements, thereby reducing the amount of resource usage, e.g., processing power, memory usage, data movement, etc.
Referring now to
Referring now to
In some embodiments, the registers 146 and 145 contain higher order subset elements and the lower order subset elements respectively. As such, if merged, the result will contain the updated top K elements. The processor 120 may perform a merge 220 operation between the registers 146 and 145 and store the result in the register 130. In some embodiments, the merge operation may be a logical OR operation between the two registers. As such, the register 130 now contains updated top K elements. The process is repeated for each remaining element of the vector data stored in the register 110 until all elements are processed accordingly and the top K elements are updated in the register 130.
Referring now to
The foregoing description of various embodiments of the claimed subject matter has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the claimed subject matter to the precise forms disclosed. Many modifications and variations will be apparent to the practitioner skilled in the art. Embodiments were chosen and described in order to best describe the principles of the invention and its practical application, thereby enabling others skilled in the relevant art to understand the claimed subject matter, the various embodiments and the various modifications that are suited to the particular use contemplated.
This application claims the benefit and priority to the U.S. Provisional Patent Application No. 63/105,140, filed Oct. 23, 2020, which is incorporated herein in its entirety by reference.
| Number | Date | Country | |
|---|---|---|---|
| 63105140 | Oct 2020 | US |