# Adapting the GACT-X Aligner to Accelerate Minimap2 in an FPGA Cloud Instance
## 2 Materials and Methods
### Integrating GACT-X into Minimap2  
As the main objective of this work, the optimized version of GACT-X, as defined in Section 2.5, was totally integrated with Minimap2, substituting for the SK block. The software-hardware implementation was tested under different configurations. Minimap2's original implementation allows multi-threading, during which each thread performs the sequential processing of seeding, chaining, and aligning one read at a time. Threads can be distributed to cores in the host server for concurrent processing. On the hardware end, OpenCL supports multi-kernels in the same FPGA, with as many kernels as the resources can fit. The AWS f1.2 xlarge instance allows for implementations with up to 64 kernels and eight cores. However, only two GACT-X kernels can fit in total in the AWS instance's FPGA due to the number of BRAMs available in the FPGA device. Generally speaking, any thread could be assigned to any kernel to optimize concurrent processing. However, in Minimap2, only a limited form of concurrency in using the kernels related to GACT-X is possible because of the sequential aspect of data processing, as mentioned in the previous paragraph: the number of threads needs to correspond to at  
Figure 8: Processing times for the ksw function from Minimap2 and for GACT-X with different tile sizes for first-anchor-extended sub-sequences (for the first 100,000 reads of the simulated dataset). The first bar corresponds to the original ksw function. All other bars correspond to GACT-X’s implementations configured to different tile sizes (from 1000 to 8000 bases). The shortest processing time was measured for a tile size of 4000.  
least the number of kernels; otherwise, the excess kernels will be idle. A kernel cannot carry the execution of different threads interchangeably before completing the alignment of the read. The restrictions above require that, whenever there are more threads than kernels running, and the corresponding sequences generated by the chaining steps are ready for the alignment processing, a waiting list must be used for the threads in order to access an available/free kernel. On the other hand, in situations of a single thread run (single core), whatever the number of kernels, only one may be used. GACT-X was integrated into Minimap2 in a hybrid system that accommodates the multi-threading and multi-kernel capabilities of the AWS instance. To implement it, a new C++ file containing the hardware's host lines was added to the original Minimap2's source code. To add one more GACT-X kernel, in the host code, the OpenCL cl_kernel variable was converted into an array of size two. When creating the kernels, they were assigned to separate memory banks. Similarly, different buffers and other variables were created for each of the two kernels. The kernel's variables were declared global variables to be shared among the threads. The configuration and setup of the kernels, which included the creation of the buffers, was added to a function, which was called once at the beginning of Minimap2's main function. Shutdown and cleanup was added to another function and called at the end of the main. A new function was created for decoding the input sequences from Minimap2, writing them to the buffers, executing the kernels, and retrieving and encoding the results back to Minimap2. This function is called in the function \"mm_align1\" from file \"align.c\", right after the execution of the sub-sequence that precedes the first anchor. An OpenCL cl_event variable \"write_read_event\" was used as a synchronization flag to avoid transfer clashes, since both of the kernels and all the threads use the same PCIe channel. Before being processed, each thread enters a global FIFO queue. The thread stays in a loop until it is first in line and until there is one kernel available. The selected kernel is then set as unavailable to other threads. This process is protected by a mutex resource. The tests were run with up to eight Minimap2 cores and up to two GACT-X kernels.