# US 11,954,093 B2 · Performing a top-k function using a binary heap tree

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 11,954,093 B2
- Document ID: US11954093B2
- Status: Granted
- Kind: B2
- Application number: 16/892,507
- Filed: 2020-06-04
- Published: 2021-12-09
- Granted: 2024-04-09
- Earliest claimed: 2020-06-04
- Assignees: Alibaba Group Holding Limited
- Applicants: Alibaba Group Holding Limited
- Inventors: Fei Sun; Shuangchen Li; Dimin Niu; Fei Xue; Yuanwei Fang
- Web page: https://patentgrep.com/patent/US11954093B2

## CPC

- G06F 7/026: {Magnitude comparison, i.e. determining the relative order of operands based on their numerical value, e.g. window comparator}
- G06F 16/2379: {Updates performed during online database operations; commit processing}
- G06F 5/16: Multiplexed systems, i.e. using two or more similar devices which are alternately accessed for enqueue and dequeue operations, e.g. ping-pong buffers
- G06F 7/08: Sorting, i.e. grouping record carriers in numerical or other ordered sequence according to the classification of at least some of the information they carry (by merging two or more sets of carriers in ordered sequence G06F7/16)
- G06F 16/245: Query processing
- G06F 16/9027: {Trees}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Embodiments of the disclosure provide devices and methods for performing a top-k function. The device can include: a memory comprising a plurality of register files for storing the data elements, the plurality of register files comprising a parent register file and a first child register file associated with the parent register file, wherein the parent register file is associated with: first interface circuitry configured for reading a first parent data element from the parent register file and receiving a first child data element and a second child data element from the first child register file; and first comparison circuitry configured for updating the parent register file and the first child register file based on the first parent data element, the first child data element, and the second child data element according to a given principle.

## Claims

### Claim 1

A computer processing unit for heapifying data elements, comprising:
a memory comprising storage circuitry forming a plurality of register files for storing the data elements, the plurality of register files comprising a parent register file and a first child register file associated with the parent register file;
a plurality of hardware nodes including a parent hardware node and children hardware nodes, each parent hardware node comprising:
first interface circuitry associated with the parent register file and configured for reading a first parent data element from the parent register file and receiving a first child data element and a second child data element from the first child register file; and
first comparison circuitry associated with the parent register file and configured for updating the parent register file and the first child register file, by generating one or more indication signals, based on the first parent data element, the first child data element, and the second child data element according to a given principle;
a multiplexer configured to transceive data elements with other hardware nodes, wherein the first comparison circuitry is configured to receive the first parent data element, the first child data element, and the second child data element from the multiplexer and sequentially perform comparison on two of the first parent data element, the first child data element, and the second child data element.

### Claim 2 (depends on 1)

The computer processing unit according to claim 1, wherein, before the updating, the first parent data element is associated with a first parent node of the plurality of hardware nodes, the first child data element is associated with a first child node of the plurality of hardware nodes, the second child data element is associated with a second child node of the plurality of hardware nodes, the first parent node being associated with the first and second child nodes.

### Claim 3 (depends on 2)

The computer processing unit according to claim 2, wherein in updating the parent register file and the first child register file, the first comparison circuitry is further configured for:
performing a first determination of whether the first parent data element and the first child data element satisfy a first given condition;
performing a second determination of whether the first and second child data elements satisfy a second given condition;
performing a third determination of whether the first parent data element and the second child data element satisfy a third given condition; and
updating the parent register file and the first child register file based on the first, second, and third determinations according to the given principle.

### Claim 4 (depends on 3)

The computer processing unit according to claim 3, wherein
the given principle comprises selecting a minimum data element among the first parent data element, the first child data element, and the second child data element, or selecting a maximum data element among the first parent data element, the first child data element, and the second child data element;
the first given condition comprises the first parent data element being less than the first child data element;
the second given condition comprises the first child data element being less than the second child data element;
the third given condition comprises the first parent data element being less than the second child data element.

### Claim 5 (depends on 4)

The computer processing unit according to claim 4, wherein when the given principle comprises selecting a minimum data element among the first parent data element, the first child data element, and the second child data element, in updating the parent register file and the first child register file, the first comparison circuitry is further configured for:
determining whether the first child data element is the minimum data element, and
in response to the determination that the first child data element is the minimum data element, swapping the first child data element and the first parent data element between the first parent node and the first child node; or
determining whether the second child data element is the minimum data element, and
in response to the determination that the second child data element is the minimum data element, swapping the second child data element and the first parent data element between the first parent node and the second child node.

### Claim 6 (depends on 4)

The computer processing unit according to claim 4, wherein when the given principle comprises selecting a maximum data element among the first parent data element, the first child data element, and the second child data element, in updating a non-leaf node, the first child node, and the second child node, the first comparison circuitry is further configured for:
determining whether the first child data element is the maximum data element, and
in response to the determination that the first child data element is the maximum data element, swapping the first child data element and the first parent data element between the first parent node and the first child node; or
determining whether the second child data element is the maximum data element, and
in response to the determination that the second child data element is the maximum data element, swapping the second child data element and the first parent data element between the first parent node and the second child node.

### Claim 7 (depends on 2)

The computer processing unit according to claim 2, further comprising:
second interface circuitry configured for receiving an initial data element from a host system for initializing the first parent node.

### Claim 8 (depends on 2)

The computer processing unit according to claim 2, wherein the first child register file is a leaf register file, and the leaf register file is associated with:
third interface circuitry configured for sending the first child data element to the first interface circuitry associated with the parent register file; and
fourth interface circuitry configured for receiving an initial data element from a host system for initializing the first child node.

### Claim 9 (depends on 1)

The computer processing unit according to claim 1, wherein the plurality of register files further comprises a second child register file associated with the parent register file, the second child register file further comprises a third child data element and a fourth child data element, the first interface circuitry is further configured for reading a second parent data element from the parent register file and receiving the third child data element and the fourth data element from the second child register file, and the device further comprises:
second comparison circuitry configured for updating the parent register file and the second child register file based on the second parent data element, the third child data element, and the fourth child data element according to the given principle.

### Claim 10 (depends on 9)

The computer processing unit according to claim 9, wherein the second parent data element is associated with a second parent node of the plurality of hardware nodes, the third child data element is associated with a third child node of the plurality of hardware nodes, the fourth child data element is associated with a fourth child node of the plurality of hardware nodes, the second parent node being associated with the third and fourth child nodes.

### Claim 11

A method for heapifying a hardware binary tree that comprises K nodes distributed across N node levels, each of the K nodes being a hardware node comprising interface circuitry and storage circuitry, wherein K and N are integers greater than three, the method comprising:
assigning and storing K initial data elements received by the interface circuitry of the K nodes from a host system to the storage circuitry of the K nodes, the N node levels comprising a first node level, a second node level that is a child level of the first node level, a third node level that is a child level of the second node level, and a fourth node level that is a child level of the third node level; and
heapifying the hardware binary tree by heapifying the first and third node levels and the second node level in an interleaving manner in machine cycles of the host system, by generating one or more indication signals, wherein heapifying the hardware binary tree comprises:
heapifying data elements stored in nodes of the first node level and the third node level in a first cycle of the machine cycles; and
heapifying data elements stored in nodes of the second node level in a second cycle of the machine cycles,
wherein heapifying the data elements stored in the nodes comprises receiving the data elements from a corresponding multiplexer, sequentially performing comparison on two of the received data elements, and updating the node according to a result of the comparison.

### Claim 12 (depends on 11)

The method according to claim 11, wherein heapifying the data elements stored in the nodes comprises:
receiving, among the nodes, a parent data element for a node, a first child data element for a first child node of the node, and a second child data element for a second child data of the node;
determining a maximum or minimum data element among the parent data element, the first child data element, and the second child data element; and
updating the node using the determined maximum or minimum data element.

### Claim 13 (depends on 11)

The method according to claim 11, wherein the K initial data elements are first K data elements of a plurality of data elements to be processed.

### Claim 14 (depends on 13)

The method according to claim 13, further comprising:
sequentially receiving the data elements from the host system; and
determining top K data elements among the received data elements and the K initial data elements.

### Claim 15 (depends on 14)

The method according to claim 14, wherein
when the hardware binary tree is a maximum binary heap tree, the top K data elements comprises smallest K data elements among the received data elements and the K initial data elements; or
when the hardware binary tree is a minimum binary heap tree, the top K data elements comprises greatest K data elements among the received data elements and the K initial data elements.

### Claim 16

A non-transitory computer readable medium that stores a set of instructions that is executable by at least one processor of a computer system to cause the computer system to perform a method for heapifying a hardware binary tree that comprises K nodes distributed across N node levels, each of the K nodes being a hardware node comprising interface circuitry and storage circuitry, wherein K and N are integers greater than three, the method comprising:
assigning and storing K initial data elements received by the interface circuitry of the K nodes from a host system to the storage circuitry of the K nodes, the N node levels comprising a first node level, a second node level that is a child level of the first node level, a third node level that is a child level of the second node level, and a fourth node level that is a child level of the third node level; and
heapifying the hardware binary tree by heapifying the first and third node levels and the second node level in an interleaving manner in machine cycles of the host system, by generating one or more indication signals, wherein heapifying the hardware binary tree comprises:
heapifying data elements stored in nodes of the first node level and the third node level in a first cycle of the machine cycles; and
heapifying data elements stored in nodes of the second node level in a second cycle of the machine cycles,
wherein heapifying the data elements stored in the nodes comprises receiving the data elements from a corresponding multiplexer, sequentially performing comparison on two of the received data elements, and updating the node according to a result of the comparison.

### Claim 17 (depends on 16)

The non-transitory computer readable medium according to claim 16, wherein heapifying the data elements stored in the nodes further comprises:
receiving, among the nodes, a parent data element for a node, a first child data element for a first child node of the node, and a second child data element for a second child data of the node;
determining a maximum or minimum data element among the parent data element, the first child data element, and the second child data element; and
updating the node using the determined maximum or minimum data element.

### Claim 18 (depends on 16)

The non-transitory computer readable medium according to claim 16, wherein the K initial data elements are first K data elements of a plurality of data elements to be processed.

### Claim 19 (depends on 18)

The non-transitory computer readable medium according to claim 18, wherein the set of instructions is executable by the at least one processor of the computer system to cause the computer system to perform:
sequentially receiving the data elements from the host system; and
determining top K data elements among the received data elements and the K initial data elements.
