A Legalization Algorithm for Heterogeneous FPGAs

Heterogeneous cells are cells with special functions in Field-Programmable Gate Arrays (FPGA) and gradually become an important resource of FPGA chips. The legalization algorithm is a key step in resolving the global placement results of heterogeneous cells to their actual locations. The algorithm in this paper is improved on the abacus algorithm. We use subspaces to evaluate the degree of congestion of cells and sort them, and use optional columns to filter to achieve a reasonable allocation of resources. The experimental results show that our work has less average moving and worst movement in the case of high density and complex distribution.

is improved on the abacus algorithm.Subspace division will be carried out according to the location of heterogeneous cell resources, and the cell processing sequence will be determined by using the cell and resource information on both sides of the subspace.Resources will be reserved for post-processing cells by filtering selectable columns during cell legalization.Our algorithm reduces the worst movement and average movement for heterogeneous cell legalization.

The problem of Heterogeneous Cell Legalization
The analytical placement algorithm is widely used in FPGA placement [9,10] .Its smooth movement makes the placement more flexible, but it also makes it difficult for some cells to obtain a placement position close to the actual resource after the placement is completed.The heterogeneous cells in the FPGA are discretely distributed in the FPGA resources as columns, as shown in Figure 1 (a), where the Digital Signal Processor (DSP) and Random-Access Memory (RAM) cells are the main heterogeneous cells, which are larger than other cells and have a special distribution.After the end of the global placement, the cell target positions are randomly distributed in the placement area, as shown in Figure 1 (b).The mismatch between the target position and resources is the main problem to be solved by legalization, and because the distribution of these cells is not even, it will bring more difficulties to the legalization work.Heterogeneous cells typically have more nets, and their legalization also has a greater impact on the FPGA compilation process.Constraints in the placement should also be satisfied during the legalization process.After the end of the global placement, the cell target positions are randomly distributed in the placement space, as shown in Figure 1 (b).The mismatch between target positions and resources is the main problem to be solved by legalization.However, due to the small number of heterogeneous cells, it is difficult to effectively constrain their distribution density in the global placement, resulting in the concentrated distribution of cells in the placement results, which will bring more difficulties to the legalization work.The legalization of heterogeneous cells, which typically have more nets and a larger footprint, also has a greater impact on the FPGA compilation process.Keeping the movement of cells as low as possible is the main goal of legalization.Constraints in the placement should also be satisfied during the legalization process.

Abacus Algorithm
The abacus algorithm was first proposed for the standard cell circuit.All the cells in the standard cell circuit have the same height, and the legalization results are shown in Figure 2. The abacus algorithm sorts all cells according to the current X coordinate, and the cells will try to fit in each row.The conflicting cells within the row are merged into clusters, and the coordinates of the clusters are calculated as a whole to achieve the purpose of minimizing the total movement.The final cell selects the row with the least cost as the legalization result and proceeds to the next cell to legalize in turn.
When applied to the legalization of FPGA heterogeneous cells, the cells that are processed first will occupy the column.Due to the large distance between columns, subsequently, cells will have to move further.And the cells may be distributed centrally, and the cells put into the column first will also be pushed farther away, resulting in an unreasonable allocation result.

Overall Flow of Legalization
The problem of applying the abacus algorithm to the legalization of FPGA heterogeneous cells is mainly caused by the lack of global information.We divide all the cells according to the spatial position, sort the subspaces according to the degree of congestion, and process them sequentially.We use a column-filtering operation to constrain the column selection of cells, which reserves enough resources for post-processing cells.Figure 3 shows our method flow.

Divide Subspace
The heterogeneous cell resources in FPGA are distributed in the space according to the column.During the legalization process, whether the cell selects the adjacent column or determines the legalization cost of the cell, we use the resource column to divide the entire space.The division effect is shown in Figure 4 (a).The first processing space occupies continuous resources, forming a "no-resource area", and the cells in the second processing subspace will have difficulty crossing this area, which means that the first processing area will divide the entire legalization space into two in the horizontal direction.Therefore, for the cells in the subspace processed first, the columns that can be selected are limited to ensure that the subspaces processed later can find resources within a suitable range.As shown in Figure 4 (b), when subspace C is processed, sufficient resources are reserved for the right subspace D. If the resources on the right side of subspace C can not satisfy all subspaces on the right, subspace C should not be processed before them.
The subspace sorting will be based on the difference between the resource and cell ratios on both sides and we use the following equation to calculate the different degrees of the subspace: where N and R represent the number of cells and resources, and N 0 and R 0 represent the total number of cells and resources.The smaller the dif is, the more uniform the distribution on both sides, and the subspace should be legalized first.
(a) (b) Figure 4. Legalization of FPGA As the scale of the FPGA increases, dividing by resource columns will lead to too long subspaces, and the difference in the distribution of upper and lower cells on the chip will cause resource allocation failures.At this time, the space is divided here in the horizontal direction, and a group of adjacent subspaces in the horizontal direction is called a layer, and the spaces of each layer are sorted and prioritized separately.The cell division is only for the legalized space and does not divide the resource column.When legalized, all layers are processed in parallel, and the high-density area cells will spread to the low-density area in the horizontal and vertical directions at the same time, completing the reasonable allocation of resources.

Legalized Column
In the abacus algorithm, the conflicting cells within the column will be merged into clusters to achieve the minimum total displacement.Since the location of resources in the FPGA is discrete and fixed, a simpler method can be used to legalize inside the column.As shown in Figure 5 (a), when cell C0 joins the column and conflicts with other cells, the abacus algorithm will sort and form clusters in sequence, and calculate and solve the optimal position of all cells for the cluster as a whole, as shown in Figure 5 EEICE-2023 Journal of Physics: Conference Series 2625 (2023) 012076 (b).We directly select the nearest optional position of the cell as the cost of putting it in.After all the cells are assigned to the column, we sort all the cells in the column and recalculate the position.In this way, the cost of cell allocation to the column can be estimated more quickly and effectively by utilizing the characteristics of the discrete distribution of FPGA resources.The direct search method can solve the problem of obstacles more conveniently.For the immovable heterogeneous cells that have been placed, we directly cross the obstacles to find available resources to complete the conflict problem.When the obstacle is too large, this method may produce a certain error, and the cluster can be moved within a certain range to search for the best result.As shown in Figure 5 (d), clusters move up and down cells to find a better result.

EXPERIMENTAL RESULTS
This paper uses C++ to implement the algorithm and conduct experiments on the computer of AMD-Opteron-Processor-6380 computer with 504 G memory.The algorithm will be compared with the abacus algorithm enhanced by Dijkstra [4] .For each test case, we legalize its RAM and DSP separately.
The FPGA chip used in all test cases contains 1728 DSPs and 768 RAMs.We use the Euclidean distance to represent the movement from the placement result to the legalized position, and Table 1 shows our experimental results.According to the experimental results, the running time of the algorithm in this paper is the same as that of the comparison algorithm.This paper simplifies the internal legalization of columns, which offsets the increased time of complex sorting, so the running time does not increase.However, this article has a more reasonable allocation of resource usage, reducing the average movement and the worst movement by 15% and 46% respectively.The algorithm in this paper can achieve good results when dealing with the legalization of FPGA heterogeneous cells.

CONCLUSION
We divide all cells into subspaces according to their spatial location and sort them according to their degree of crowding.And we use the column filtering operation to constrain the column selection of cells to achieve a reasonable allocation of resources.According to the resource distribution of FPGA, the solution method of in-column legalization is simplified, and the scene containing obstacles can be flexibly solved.The experimental results show that the algorithm proposed in this paper effectively reduces both the average and worst displacement during legalization while maintaining the processing efficiency of the abacus algorithm.Additionally, the legalization quality of heterogeneous cells is improved.

Figure 2 .
Legalization of standard