The content of the invention
The present invention proposes a kind of hardware thread implementation method based on FPGA.
The present invention is as follows to solve the technical scheme that its technical problem uses:A kind of hardware thread realization side based on FPGA
Method, comprise the following steps:
The first step, cutting application program:
It is main thread and from thread by application program cutting;
Second step, Hardware main thread:
Main thread is realized using hardware description language, constructs the main thread of Hardware;
3rd step, Hardware are from thread:
Using hardware description language to being realized from thread, construct Hardware from thread;
4th step, establish application program stream file:
All hardware code, data and the configuration information of application program are established as application flow text on the local computer
Part;
In 5th step, programming application program stream file to FPGA:
By in application program stream file programming to FPGA;
6th step, dynamic creation and configuration sub-line journey.
Further, the main thread be responsible in application program from starting until terminate all in the thread of execution from
The management of thread;It is described from thread be created in application program in special time period, the thread that exists and perform task.
Further, in the 5th step, in application program stream file programming to FPGA after, hardware main thread first by
Create and be configured on FPGA, then start to perform.
Further, the 6th step is specially:
In hardware main thread implementation procedure, specific task is completed from thread if necessary to a hardware, then hardware main line
Corresponding hardware is from thread part in journey reading application program stream file, and creates a hardware from thread;Hardware main thread from
FPGA apply a block space, by the hardware from thread configuration on this block space, then start the hardware holding from thread
OK, hardware performs calculating task since thread, and after the completion of calculating task, result of calculation is sent to hardware by hardware from thread
Main thread.
Further, in implementation procedure of the hardware from thread, if the execution of hardware main thread depends on hardware from line
The result of calculation of journey, then hardware main thread pause performs, when hardware main thread receives hardware after the result of calculation of thread
It is further continued for performing;If result of calculation of the execution of hardware main thread independent of hardware from thread, hardware main thread continues
Perform, the result of calculation from hardware from thread is reprocessed until receiving hardware after the result of calculation of thread.
Further, after the completion of the execution of hardware sub-line journey, this performs the FPGA shared by the hardware sub-line journey completed
Space is recovered.
The present invention has an advantageous effect in that compared with background technology:
(1) high efficiency.The present invention is dynamically generated the hardware thread of application program by FPGA Resources on Chip, passes through hardware
Thread execution efficiency is higher, while also higher to the utilization ratio of FPGA resource.
(2) it is easily achieved.The present invention takes full advantage of FPGA Resources on Chip, should to realize by FPGA own resources
With the hardware thread of program, it is not necessary to communicated with general processor, so that this method is more easily realized.
Embodiment
The present invention will be further described with reference to the accompanying drawings and detailed description, not to the limit of its protection domain
System.
A kind of hardware thread implementation method based on FPGA, it is as follows that it implements flow.
The first step, cutting application program:
It is main thread and from thread by application program cutting.Wherein main thread is until terminating all to exist in application program from beginning
The thread of execution, it is responsible for the management from thread;It is to be created in application program in special time period, exist and perform task from thread
Thread.At least one main thread of each application program.If from thread return result of calculation, main thread need wait from
The result of calculation that thread returns, now main thread pause performs, until receiving the result of calculation returned from thread.If from thread
Result of calculation is not returned to, then main thread withouts waiting for the result of calculation returned from thread, and now main thread continues executing with.
As shown in Fig. 2 in one embodiment, for application program P, by application program P cuttings be main thread PM and 5 from
Thread, this 5 are respectively from thread:From thread P1, from thread P2, from thread P3, from thread P4, from thread P5.From thread P1,
It is respectively completed from thread P2, from thread P3, from thread P4, from thread P5:
1)Calculating task C1 is completed from thread P1, and returns to result of calculation.Main thread PM needs to wait the meter returned from thread P1
Calculate result.
2)Calculating task C2 is completed from thread P2, and returns to result of calculation.Main thread PM needs to wait to be returned from thread P2
Result of calculation.
3)Calculating task C3 is completed from thread P3, does not return to result of calculation.Main thread PM withouts waiting for returning from thread P3
The result of calculation returned, is continued executing with.
4)Calculating task C4 is completed from thread P4, and returns to result of calculation.Main thread PM needs to wait to be returned from thread P4
Result of calculation.
5)Calculating task C5 is completed from thread P5, does not return to result of calculation.Main thread PM withouts waiting for returning from thread P5
The result of calculation returned, is continued executing with.
Second step, Hardware main thread:
Using hardware description language to being realized from thread, the main thread of Hardware is constructed.
As shown in figure 3, in one embodiment, for application program P, its main thread PM forms hardware master after carrying out Hardware
Thread PM '.
3rd step, Hardware are from thread:
Using hardware description language to being realized from thread, construct Hardware from thread.
As shown in figure 3, in one embodiment, for application program P, be syncopated as by application program P 5 from thread:From
Thread P1, from thread P2, from thread P3, from thread P4, from thread P5, after being realized using hardware description language respectively
For:Hardware is from thread P1 ', hardware from thread P2 ', hardware from thread P3 ', hardware from thread P4 ', hardware from thread P5 '.Then with
From thread P1, from thread P2, from thread P3, from thread P4, it is corresponding from thread P5, hardware from thread P1 ', hardware from thread P2 ',
Hardware is respectively completed from thread P3 ', hardware from thread P4 ', hardware from thread P5 ':
1)Hardware completes calculating task C1 from thread P1 ';
2)Hardware completes calculating task C2 from thread P2 ';
3)Hardware completes calculating task C3 from thread P3 ';
4)Hardware completes calculating task C4 from thread P4 ';
5)Hardware completes calculating task C5 from thread P5 '.
4th step, establish application program stream file:
All hardware code, data and the configuration information of application program are established as application flow text on the local computer
Part.
For application program P, by the hardware main thread PM ' after Hardware, hardware from thread P1 ', hardware from thread P2 ',
Hardware exists from thread P3 ', hardware from thread P4 ', hardware from the configuration information of thread P5 ', the data of application program, application program
Application program stream file SP is established as on local computer.
In 5th step, programming application program stream file to FPGA:
By in application program stream file programming to FPGA.After in application program stream file programming to FPGA, hardware main thread is first
First it is created and is configured on FPGA, then starts to perform.Because hardware main thread corresponds to main thread, therefore work as hardware master
When thread starts to perform, mean that application program starts to perform on FPGA.Because hardware main thread is real with hardware description language
Hardware module is configured to now and on FPGA, therefore hardware main thread realizes the main thread example, in hardware on FPGA.
In one embodiment, for application program P, by application program P stream file SP programmings to FPGA.Using journey
To after on FPGA, hardware main thread PM ' is created and is configured on FPGA first, then starts to hold for sequence stream file SP programmings
OK.
6th step, dynamic creation and configuration sub-line journey:
In hardware main thread implementation procedure, specific task is completed from thread if necessary to a hardware, then hardware main line
Corresponding hardware is from thread part in journey reading application program stream file, and creates a hardware from thread, is completed on FPGA
Configuration of this hardware from thread.Hardware main thread applies for a block space from FPGA, by hardware from thread configuration in this block space
On, then start execution of the hardware from thread.Hardware performs calculating task, after the completion of calculating task, hardware since thread
Hardware main thread is sent to from thread by result of calculation.In implementation procedure of the hardware from thread, if hardware main thread is held
Row depend on result of calculation of the hardware from thread, then hardware main thread pause execution, when hardware main thread receive hardware from
It is further continued for performing after the result of calculation of thread;If result of calculation of the execution of hardware main thread independent of hardware from thread,
Then hardware main thread is continued executing with, and the calculating from hardware from thread is reprocessed until receiving hardware after the result of calculation of thread
As a result.
After the completion of the execution of hardware sub-line journey, this FPGA space for performing shared by the hardware sub-line journey completed will be returned
Receive.
As shown in figure 4, in one embodiment, for application program P, hardware main thread PM ' has needed in the process of implementation
Into calculating task C1, hardware main thread PM ' needs hardware from thread P1 ' to complete calculating task C1.Then hardware main thread is read
Corresponding hardware is from thread P1 ' in application program stream file, and creates a hardware from thread P1 ', and hardware is completed on FPGA
From thread P1 ' configuration.Hardware main thread PM ' applies for a block space from FPGA, and hardware is configured in this block space from thread P1 '
On, then start execution of the hardware from thread P1 '.Hardware performs calculating task C1 since thread P1 ', complete in calculating task C1
Result of calculation is sent to hardware main thread PM ' by Cheng Hou, hardware from thread P1 '.In hardware from thread P1 ' implementation procedure,
Hardware main thread PM ' execution depends on result of calculation of the hardware from thread P1 ', then hardware main thread PM ' pauses perform, and wait until
Hardware main thread PM ' receives hardware and is further continued for performing after thread P1 ' result of calculation.Hardware from thread P2 ' and hardware from
The two hardware of thread P4 ' are required for returning to result of calculation upon execution from thread, therefore are performed in the two hardware from thread
When, hardware main thread stops performing, and is transferred to halted state.
Because hardware from thread P3 ' and hardware from thread P5 ' need not return to result of calculation upon execution, thus this two
Individual hardware from thread perform when, hardware main thread does not stop performing.
In hardware sub-line journey P1 ', hardware from thread P2 ', hardware from thread P3 ', hardware from thread P4 ', hardware from thread
After the completion of P5 ' is performed respectively, this five FPGA spaces performed shared by the hardware sub-line journey completed will perform in each of which
After the completion of be recovered.
In a word, the foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in the present invention
Spirit and principle within all any modification, equivalent and improvement made etc., should be included in protection scope of the present invention it
It is interior.