Code processing method, device, storage medium and processor
Through the optimization and mapping technology of the polyhedral model, the problem of loop code parallelism optimization in high-level synthesis is solved, the utilization of hardware resources and the computing speed are improved, and a more efficient comprehensive effect is achieved.
Patent Information
- Application Number
- CN202011567536.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-25
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-12-25
AI Technical Summary
In high-level synthesis, loop codes are difficult to optimize for parallelism, resulting in a waste of hardware resources and insufficient computing speed.
By obtaining the loop code, determining the polyhedral model, optimizing the polyhedral model, and mapping it to the processing unit of the hardware structure, generating a pulsation mapping template to support parallel processing, optimizing the parallelism and resource occupation of the hardware language.
The parallelism optimization of loop codes is realized, the utilization efficiency of synthesis time and hardware resources is improved, and the problem that loop codes are difficult to be processed in parallel in high-level synthesis is solved.
Smart Images

Figure CN112559033B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of reconfigurable computing, and in particular to a code processing method, device, storage medium and processor. Background Art
[0002] Hardware description language is a language that describes the structure and behavior of digital system hardware in text form. FPGA high-level synthesis refers to the synthesis of information expressed in high-level programming languages into register transfer level (RTL) circuit designs described in hardware languages, automatically realizing the conversion from high-level languages to hardware languages. By optimizing the code structure, a hardware structure with faster operation speed and less resource consumption can be designed.
[0003] When using high-level synthesis to synthesize high-level languages into hardware circuits, it is necessary to write or reconstruct high-level language codes into hardware synthesizable formats according to certain synthesizability criteria, while also considering the occupation of underlying hardware resources. Loop structures are commonly used syntactic structures in high-level codes, and they are executed in the order of the loops during compilation. If the loop code of a high-level language is synthesized into a hardware language according to the loop order, the parallelism of the hardware language is not fully utilized, and hardware resources are also wasted.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present invention provide a code processing method, device, storage medium and processor to at least solve the technical problem that it is difficult to perform parallel optimization on loop codes in high-level synthesis.
[0006] According to one aspect of an embodiment of the present invention, there is provided a code processing method, comprising: obtaining loop code in a predetermined program; determining a first polyhedron model according to the loop code, wherein the first polyhedron model includes data dependencies for performing operations on variables in the loop code; optimizing the first polyhedron model to obtain a second polyhedron model; mapping the second polyhedron model to a processing unit of a hardware structure to obtain a pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations without data dependencies.
[0007] Optionally, determining the first polyhedron model according to the loop code includes: extracting intrinsic information of the loop code, wherein the intrinsic information includes: variables in the loop code, the number of scheduling times of the loop code, the data access method and the loop boundary; determining the data dependencies of the operations in the loop code according to the intrinsic information of the loop code; determining the first polyhedron model according to the variables in the loop code and the data dependencies.
[0008] Optionally, optimizing the first polyhedron model to obtain the second polyhedron model includes: constructing a code iteration space according to the first polyhedron model, wherein the code iteration space includes multiple nodes, and the nodes represent operations in the loop code; when the multiple nodes all include operations on variables in the loop code, changing the polyhedron structure corresponding to the first polyhedron model according to the data dependencies and boundary constraints to obtain the second polyhedron model.
[0009] Optionally, when the multiple nodes all include operations on variables in the loop code, the polyhedron structure corresponding to the first polyhedron model is changed according to the data dependencies and boundary constraints to obtain the second polyhedron model, including: creating a temporary node in the code iteration space; determining the value of the temporary node according to the position of the current node in the code iteration space; when the operation represented by the current node is the final iterative operation of the boundary constraint, replacing the final node with the value of the temporary node to obtain the second polyhedron model.
[0010] Optionally, mapping the second polyhedron model to a processing unit of a hardware structure to obtain a pulsation mapping template includes: mapping the second polyhedron model into an intermediate virtual model according to time occupancy and processor resource occupancy; and mapping the intermediate virtual model to a processing unit of a hardware structure to obtain a pulsation mapping template.
[0011] Optionally, mapping the second polyhedral model into an intermediate virtual model according to the occupancy of time and processor resources includes: determining the iteration in the loop code according to the second polyhedral model; mapping the iteration into a time function according to predetermined timing constraints; mapping the iteration into a constructor of the processor dimension; and generating the intermediate virtual model according to the time function and the constructor.
[0012] Optionally, mapping the intermediate virtual model to a processing unit of a hardware structure to obtain a pulsation mapping template includes: disassembling operations in the loop code; allocating the disassembled operations to corresponding clock cycles according to the time function and the calculation order to obtain iterative operations to be executed; and obtaining a computing circuit and port connection information of the computing circuit using a predetermined operation expression mapping model according to the iterative operations to be executed to obtain the pulsation mapping template.
[0013] Optionally, the loop code includes: a regular loop pipeline code with the same number of operations in each iteration, fixed rules for dependencies between data, and fixed loop boundaries.
[0014] According to another aspect of an embodiment of the present invention, there is further provided a code processing device, comprising: an acquisition module, for acquiring loop codes in a predetermined program; a determination module, for determining a first polyhedron model according to the loop codes, wherein the first polyhedron model includes data dependencies for performing operations on variables in the loop codes; an optimization module, for optimizing the first polyhedron model to obtain a second polyhedron model; and a mapping module, for mapping the second polyhedron model to a processing unit of a hardware structure to obtain a pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations without data dependencies.
[0015] According to another aspect of an embodiment of the present invention, a storage medium is provided, wherein the storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute any one of the above-mentioned code processing methods.
[0016] According to yet another aspect of the embodiments of the present invention, a processor is provided, wherein the processor is used to run a program, wherein the program executes any one of the above-mentioned code processing methods when running.
[0017] In the embodiment of the present invention, a polyhedron model is determined according to the loop code in the program. By optimizing the polyhedron model corresponding to the loop code and mapping the optimized second polyhedron model to a systolic mapping template, the purpose of optimizing the parallelism of the hardware language when synthesizing the loop code in the predetermined program into the systolic mapping template is achieved, thereby achieving the technical effect of optimizing the synthesis time and the occupied hardware resources, and further solving the technical problem that it is difficult to optimize the parallelism of the loop code in high-level synthesis. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0019] Figure 1 is a flowchart of a code processing method according to Embodiment 1 of the present invention;
[0020] Figure 2 is a schematic diagram of a comprehensive optimization method for a circulating pipeline code according to an optional embodiment of the present invention;
[0021] Figure 3 4 is a structural block diagram of a code processing device according to embodiment 2 of the present invention. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0024] Example 1
[0025] According to an embodiment of the present invention, a code processing method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0026] Figure 1 is a flowchart of a code processing method according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0027] Step S102, obtaining a loop code in a predetermined program;
[0028] Step S104, determining a first polyhedron model according to the loop code, wherein the first polyhedron model includes dependencies between data for performing calculation operations on variables in the loop code;
[0029] Step S106, optimizing the first polyhedron model to obtain a second polyhedron model;
[0030] Step S108, mapping the second polyhedron model to the processing units of the hardware structure to obtain a systolic mapping template, wherein the processing units included in the systolic mapping template support parallel processing of operations without data dependencies.
[0031] Through the above steps, a method of determining a polyhedron model according to a loop code in a program is adopted, the polyhedron model corresponding to the loop code is optimized, and the second polyhedron model obtained after optimization is mapped as a systolic mapping template, so as to achieve the purpose of optimizing the parallelism of the hardware language when synthesizing the loop code in a predetermined program into a systolic mapping template, thereby achieving the technical effect of optimizing the synthesis time and the occupied hardware resources, and further solving the technical problem that it is difficult to optimize the parallelism of the loop code in high-level synthesis.
[0032] As an optional embodiment, the loop code in the predetermined program can be a high-level language such as C / C++, and the high-level synthesis synthesizes the high-level language into a hardware language, such as the hardware language of FPGA. FPGA high-level synthesis can synthesize the information represented by the high-level programming language into a register transfer level (RTL) circuit design described in the hardware language, and automatically realize the conversion from the high-level language to the hardware language. Optionally, the loop code can include a regular loop pipeline code, which is a code with the same number of operations per iteration, fixed rules for data dependencies, and fixed loop boundaries.
[0033] As an optional embodiment, determining the first polyhedral model according to the loop code can be implemented in the following manner: extracting the intrinsic information of the loop code, wherein the intrinsic information includes: variables in the loop code, the number of scheduling of the loop code, the method of data access and the loop boundary; determining the data dependencies between operations in the loop code according to the intrinsic information of the loop code; determining the first polyhedral model according to the variables and the data dependencies in the loop code. Optionally, this embodiment can perform front-end processing on the loop code to obtain a polyhedral model (Polyhedral Model, PM for short) including the intrinsic information of the loop code, and the PM can include information such as the number of scheduling of the loop code, the method of data access and the loop boundary, which can be used to characterize the structure of the loop code. In addition, PM is based on the variables in the loop code, and PM can be constructed based on the data dependencies between operations performed on the variables in the loop code. In the case where the loop code includes more than one variable, PM can be a polyhedral structure, and the polyhedral structure includes different data dependencies.
[0034] As an optional embodiment, the first polyhedron model can be optimized in the following manner to obtain a second polyhedron model: construct a code iteration space according to the first polyhedron model, wherein the code iteration space includes multiple nodes, and the nodes represent operations in the loop code; when multiple nodes all include operations on variables in the loop code, the polyhedron structure corresponding to the first polyhedron model is changed according to the dependencies between data and boundary constraints to obtain the second polyhedron model. Create a code iteration space corresponding to PM, optimize PM in the code iteration space, and improve the parallelism after mapping the loop code in the high-level language to the hardware language. Optionally, when there are multiple nodes in the model, that is, there are multiple operation methods in the loop iteration space, and these operation methods all include operations on a certain variable, this global data dependency can be preprocessed and eliminated.
[0035] As an optional embodiment, when multiple nodes all include operations on variables in the loop code, the polyhedron structure corresponding to the first polyhedron model is changed according to the dependencies between data and boundary constraints to obtain a second polyhedron model. This can be achieved in the following way: creating a temporary node in the code iteration space; determining the value of the temporary node according to the position of the current node in the code iteration space; when the operation represented by the current node is the final iterative operation of the boundary constraint, replacing the final node with the value of the temporary node to obtain the second polyhedron model.
[0036] Optionally, after eliminating the global data dependency in the code iteration space through preprocessing, the local data dependency can be eliminated or reduced by creating temporary nodes in the code iteration space. When the polyhedron structure is locally optimized, a temporary node can be added, and the value of the temporary node can be determined by analyzing the position of the current node to be optimized, and whether to terminate the optimization can be determined by comparing the relationship between the temporary node and the loop boundary. If the operation represented by the current node is not the final iterative operation, the analysis continues. If it is the final iterative operation, the final node is replaced with the value represented by the temporary node. Local optimization can be performed in the code iteration space. According to the local dependency and boundary constraints, the loop code can be scheduled through geometric operations to change the structure of the polyhedron, thereby realizing the loop transformation in the loop code. After local optimization, it can also prevent excessive wiring resources from being occupied during subsequent mapping, reduce frequent access to memory space, and increase the clock frequency to a certain extent.
[0037] As an optional embodiment, mapping the second polyhedron model to the processing unit of the hardware structure to obtain the pulsation mapping template can be implemented in the following manner: mapping the second polyhedron model into an intermediate virtual model according to the time occupation and the processor resource occupation; mapping the intermediate virtual model to the processing unit of the hardware structure to obtain the pulsation mapping template. Through this embodiment, after the PM is constructed, the PM can be reprocessed in terms of time occupation and processor resource occupation. Through reprocessing, the execution efficiency of the hardware language obtained after synthesis can be improved, and the execution time and resource occupation can be reduced.
[0038] As an optional embodiment, the second polyhedron model can be mapped into an intermediate virtual model according to the occupation of time and the occupation of processor resources in the following manner: according to the second polyhedron model, the iteration in the loop code is determined; according to the predetermined timing constraints, the iteration is mapped into a time function; the iteration is mapped into a constructor of the processor dimension; according to the time function and the constructor, the intermediate virtual model is generated. Optionally, in the case where the loop code is a regular loop pipeline code, the iteration of the loop pipeline code can be mapped into a time function of logical execution, and at the same time, different iterations are mapped to the processor dimension through another constructor, and finally an intermediate virtual model (Virtual Module, referred to as VM) is generated. When constructing the time function, this embodiment adds timing constraints so that data nodes with dependencies in the code iteration space will not be executed at the same time, so that the solved time function can have the shortest execution time.
[0039] As an optional embodiment, the intermediate virtual model is mapped to the processing unit of the hardware structure, and the pulsation mapping template can be obtained by the following method: disassembling the operation in the loop code; according to the time function and the calculation order, the disassembled operation is assigned to the corresponding clock cycle to obtain the iterative operation to be executed; according to the iterative operation to be executed, the predetermined operation expression mapping model is used to obtain the calculation circuit and the port connection information of the calculation circuit to obtain the pulsation mapping template. The dependency between the loop codes will be converted into an enable signal when mapped into the hardware code. After the predecessor operation node completes the operation, the enable signal of the current node will become valid, and the value of the predecessor node will be transmitted to the current node, so that the consistency of the data can be guaranteed.
[0040] Optionally, the intermediate virtual model can be mapped to a processing unit of a hardware structure. The processing unit of the hardware structure can be composed of an input unit, a computing unit, a control unit, and an output delay unit. In this embodiment, the intermediate virtual model can be firstly decomposed according to the operation mode in the original loop code, such as addition, subtraction, multiplication, and division, and then the operation obtained after the decomposition is allocated to the corresponding clock cycle according to the time function and the calculation order, and finally the iterative operation type to be executed is obtained, and then the calculation circuit and the port connection information of the calculation circuit are designed adaptively according to different operations. In addition, the design of the calculation circuit can be completed according to a pre-designed operation expression mapping model, including logical operations and conventional addition, subtraction, multiplication, and division.
[0041] Optionally, the input data of the computing unit can be completed through an input selection unit, which first traverses all data information in the information table connected to the input port, then determines whether the input information comes from the same circuit module, and sets corresponding input selection units for ports from different circuit modules. The number of input unit ports is determined by the number of different circuit modules to which the input data belongs. The control unit can use a fixed clock cycle as a state interval and adopt a data-driven mode to send the control signal of the input unit and the valid signal of the final data.
[0042] Optionally, the pulsation mapping template may be composed of interconnected processing units. In addition, in order to effectively perform data interaction and improve the interaction efficiency between the pulsation mapping template and the code to be processed, the processing unit may also be connected to an external storage module. If the port of the processing unit is directly connected to the port of the internal computing unit, the port information of the computing unit can be searched to obtain the connection information between the computing unit and the external storage module for direct port connection. If the port of the processing unit is connected to the port of the computing unit through the input unit, the connection information of the input port and the external storage module can be obtained by searching the port connection information of the computing unit, and then the input port of the processing unit is interconnected with the external port that is not connected in the connection information.
[0043] The pulsation mapping template of this embodiment can not only complete the interconnection between internal processing units, but also handle the connection relationship with the external storage module, and finally map the cyclic process into a parallel module operating in the external storage module.
[0044] Optionally, the present invention can perform parallel optimization processing on regular loop pipeline codes in high-level languages. Regular loop pipeline codes, that is, loop code structures with the same number of operations in each iteration, fixed rules for the dependencies between the data of the operations, and fixed loop boundaries. Due to the regularity of regular loop pipeline codes, their intrinsic information, such as the number of scheduling times of the loop code, the way of data access, and loop boundaries, are relatively fixed. Improving the performance of regular loop pipeline codes can be achieved by utilizing concurrency and taking serial processes, making the loop as pipelined as possible to accelerate the loop. This embodiment can analyze the loop structure in the regular loop pipeline code in the high-level language, and parallelize the steps in the loop that have no dependencies after optimization, thereby improving the speed of hardware processing calculations and further improving the overall quality.
[0045] Figure 2 is a schematic diagram of a comprehensive optimization method for a circulation pipeline code according to an optional embodiment of the present invention, such as Figure 2 As shown, the method comprises the following steps:
[0046] S1, read the loop pipeline code as the object for high-level synthesis;
[0047] S2, extracting information from the loop pipeline code, and analyzing dependencies between data in the loop pipeline code based on the information;
[0048] S3, construct the PM polyhedron model corresponding to the circulation pipeline code;
[0049] S4, optimize the PM polyhedron model. The optimization process is as follows:
[0050] S4.1, construct a temporary node in the code iteration space corresponding to the PM polyhedron model; S4.2, determine whether the optimization operation of the node is completed, and when the optimization operation is completed, enter step S4.3; S4.3, analyze the position of the current node; S4.4, determine whether the current node is the final node, and when the current node is determined to be the final node, enter step S4.5; S4.5, assign the value of the temporary node to the final node to obtain the optimized polyhedron model;
[0051] S5, constructing an intermediate virtual model according to the optimized polyhedron model;
[0052] S6, generating a pulsation mapping template according to the intermediate virtual model.
[0053] Example 2
[0054] According to an embodiment of the present invention, a code processing device for implementing the above code processing method is also provided. Figure 3 is a structural block diagram of a code processing device according to Embodiment 2 of the present invention. Figure 3 As shown, the code processing device includes: an acquisition module 32, a determination module 34, an optimization module 36 and a mapping module 38. The code processing device is described below.
[0055] An acquisition module 32, used for acquiring a loop code in a predetermined program;
[0056] A determination module 34, connected to the acquisition module 32, is used to determine a first polyhedron model according to the loop code, wherein the first polyhedron model includes dependencies between data for performing calculation operations on variables in the loop code;
[0057] An optimization module 36, connected to the determination module 34, is used to optimize the first polyhedron model to obtain a second polyhedron model;
[0058] The mapping module 38 is connected to the optimization module 36 and is used to map the second polyhedral model to the processing unit of the hardware structure to obtain a pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations without data dependencies.
[0059] It should be noted here that the above-mentioned acquisition module 32, determination module 34, optimization module 36 and mapping module 38 correspond to steps S102 to S108 in Example 1, and the instances and application scenarios implemented by multiple modules and corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned Example 1.
[0060] Example 3
[0061] An embodiment of the present invention may provide a computer device. Optionally, in this embodiment, the computer device may be located in at least one network device among multiple network devices of a computer network. The computer device includes a memory and a processor.
[0062] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the data processing method and device in the embodiment of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned data processing method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0063] The processor can call the information and application program stored in the memory through the transmission device to perform the following steps: obtain the loop code in the predetermined program; determine the first polyhedron model according to the loop code, wherein the first polyhedron model includes the data dependency relationship between the operation operations on the variables in the loop code; optimize the first polyhedron model to obtain the second polyhedron model; map the second polyhedron model to the processing unit of the hardware structure to obtain the pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations without data dependency relationship.
[0064] Optionally, the processor may also execute the following steps of program code: determining the first polyhedron model according to the loop code includes: extracting intrinsic information of the loop code, wherein the intrinsic information includes: variables in the loop code, the number of scheduling times of the loop code, the data access method and the loop boundary; determining the data dependency of operations in the loop code according to the intrinsic information of the loop code; determining the first polyhedron model according to the variables and data dependency in the loop code.
[0065] Optionally, the processor may also execute program code for the following steps: optimizing the first polyhedron model to obtain a second polyhedron model, including: constructing a code iteration space based on the first polyhedron model, wherein the code iteration space includes a plurality of nodes, and the nodes represent operations in the loop code; when the plurality of nodes all include operations on variables in the loop code, changing the polyhedron structure corresponding to the first polyhedron model according to dependencies between data and boundary constraints to obtain a second polyhedron model.
[0066] Optionally, the processor may also execute program code for the following steps: when multiple nodes all include operations on variables in the loop code, the polyhedron structure corresponding to the first polyhedron model is changed according to the dependencies between data and boundary constraints to obtain a second polyhedron model, including: creating a temporary node in the code iteration space; determining the value of the temporary node according to the position of the current node in the code iteration space; and when the operation represented by the current node is the final iterative operation of the boundary constraint, replacing the final node with the value of the temporary node to obtain a second polyhedron model.
[0067] Optionally, the processor may also execute the program code of the following steps: mapping the second polyhedron model to the processing unit of the hardware structure to obtain a pulsation mapping template, including: mapping the second polyhedron model into an intermediate virtual model according to the time occupancy and the occupancy of the processor resources; mapping the intermediate virtual model to the processing unit of the hardware structure to obtain a pulsation mapping template.
[0068] Optionally, the processor may also execute the program code of the following steps: mapping the second polyhedral model into an intermediate virtual model according to the time occupancy and the processor resource occupancy includes: determining the iteration in the loop code according to the second polyhedral model; mapping the iteration into a time function according to predetermined timing constraints; mapping the iteration into a constructor of the processor dimension; and generating an intermediate virtual model according to the time function and the constructor.
[0069] Optionally, the processor may also execute the program code of the following steps: mapping the intermediate virtual model to the processing unit of the hardware structure to obtain a pulsation mapping template, including: disassembling the operations in the loop code; allocating the disassembled operations to corresponding clock cycles according to the time function and the calculation order to obtain iterative operations to be executed; according to the iterative operations to be executed, using a predetermined operation expression mapping model to obtain the computing circuit and the port connection information of the computing circuit to obtain the pulsation mapping template.
[0070] Optionally, the processor may also execute program code of the following steps: the loop code includes: a regular loop pipeline code in which each iteration has the same number of operations, the dependency between data has fixed rules, and the loop boundary is fixed.
[0071] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0072] Example 4
[0073] The embodiment of the present invention further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the code processing method provided in the above embodiment 1.
[0074] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0075] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: obtaining a loop code in a predetermined program; determining a first polyhedron model based on the loop code, wherein the first polyhedron model includes data dependencies for performing operations on variables in the loop code; optimizing the first polyhedron model to obtain a second polyhedron model; mapping the second polyhedron model to a processing unit of a hardware structure to obtain a pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations that do not have data dependencies.
[0076] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: determining, based on the loop code, a first polyhedron model, including: extracting intrinsic information of the loop code, wherein the intrinsic information includes: variables in the loop code, the number of scheduling times of the loop code, a data access method and a loop boundary; determining, based on the intrinsic information of the loop code, data dependencies between operations in the loop code; determining the first polyhedron model based on the variables in the loop code and the data dependencies.
[0077] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: optimizing the first polyhedron model to obtain the second polyhedron model includes: constructing a code iteration space based on the first polyhedron model, wherein the code iteration space includes multiple nodes, and the nodes represent operations in the loop code; when multiple nodes all include operations on variables in the loop code, changing the polyhedron structure corresponding to the first polyhedron model according to the data dependency and boundary constraints to obtain the second polyhedron model.
[0078] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: when multiple nodes all include operations on variables in the loop code, changing the polyhedron structure corresponding to the first polyhedron model according to the dependencies between data and boundary constraints to obtain a second polyhedron model, including: creating a temporary node in the code iteration space; determining the value of the temporary node according to the position of the current node in the code iteration space; when the operation represented by the current node is the final iterative operation of the boundary constraint, replacing the final node with the value of the temporary node to obtain the second polyhedron model.
[0079] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: mapping the second polyhedron model to a processing unit of a hardware structure to obtain a pulsation mapping template, including: mapping the second polyhedron model into an intermediate virtual model according to time occupancy and processor resource occupancy; mapping the intermediate virtual model to a processing unit of a hardware structure to obtain a pulsation mapping template.
[0080] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: mapping the second polyhedral model into an intermediate virtual model according to the occupancy of time and the occupancy of processor resources includes: determining the iterations in the loop code according to the second polyhedral model; mapping the iterations into a time function according to predetermined timing constraints; mapping the iterations into a constructor of the processor dimension; and generating an intermediate virtual model according to the time function and the constructor.
[0081] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: mapping the intermediate virtual model to the processing unit of the hardware structure to obtain a pulsation mapping template including: disassembling the operations in the loop code; allocating the disassembled operations to corresponding clock cycles according to the time function and the calculation order to obtain iterative operations to be executed; according to the iterative operations to be executed, using a predetermined operation expression mapping model to obtain the computing circuit and the port connection information of the computing circuit to obtain the pulsation mapping template.
[0082] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps: the loop code includes: a regular loop pipeline code in which each iteration has the same number of operations, data dependencies have fixed rules, and loop boundaries are fixed.
[0083] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0084] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0085] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0086] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0087] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0088] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0089] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A code processing method, characterized in that: include: Get the loop code in the predetermined program; Determining a first polyhedral model according to the loop code, wherein the first polyhedral model includes dependencies between data for performing calculation operations on variables in the loop code; Optimizing the first polyhedron model to obtain a second polyhedron model; Mapping the second polyhedral model to a processing unit of a hardware structure to obtain a pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations without data dependencies; The step of mapping the second polyhedron model to a processing unit of a hardware structure to obtain a pulsation mapping template includes: mapping the second polyhedron model to an intermediate virtual model according to time occupancy and processor resource occupancy; mapping the intermediate virtual model to a processing unit of a hardware structure to obtain a pulsation mapping template; The pulsation mapping template supports connection with an external storage module, and maps the cyclic process into a parallel module operating in the external storage module.
2. The method according to claim 1, characterized in that: According to the loop code, determining the first polyhedron model includes: Extracting intrinsic information of the loop code, wherein the intrinsic information includes: variables in the loop code, the number of scheduling times of the loop code, the data access method and the loop boundary; Determining, according to the intrinsic information of the loop code, dependencies between data operated in the loop code; The first polyhedron model is determined according to the variables in the loop code and the dependencies between the data.
3. The method according to claim 1, characterized in that Optimizing the first polyhedron model to obtain a second polyhedron model includes: Constructing a code iteration space according to the first polyhedron model, wherein the code iteration space includes a plurality of nodes, and the nodes represent operations in the loop code; In the case where the multiple nodes all include operations on variables in the loop code, the polyhedral structure corresponding to the first polyhedral model is changed according to the inter-data dependency and boundary constraints to obtain the second polyhedral model.
4. The method according to claim 3, characterized in that In a case where the plurality of nodes all include operations on variables in the loop code, changing the polyhedral structure corresponding to the first polyhedral model according to the inter-data dependency and boundary constraints to obtain the second polyhedral model includes: Creating a temporary node in the code iteration space; Determining the value of the temporary node according to the position of the current node in the code iteration space; When the operation represented by the current node is the final iterative operation of the boundary constraint condition, the final node is replaced by the value of the temporary node to obtain the second polyhedron model.
5. The method according to claim 1, characterized in that Mapping the second polyhedral model into an intermediate virtual model according to the time occupation and the processor resource occupation includes: determining an iteration in the loop code according to the second polyhedral model; Mapping the iterations into a time function according to a predetermined timing constraint; A constructor that maps the iteration to a processor dimension; The intermediate virtual model is generated according to the time function and the constructor.
6. The method according to claim 5, characterized in that Mapping the intermediate virtual model to a processing unit of a hardware structure to obtain a pulsation mapping template includes: Disassembling the operations in the loop code; According to the time function and the calculation order, the disassembled operations are allocated to corresponding clock cycles to obtain iterative operations to be executed; According to the iterative operation to be performed, a predetermined operation expression mapping model is used to obtain the computing circuit and the port connection information of the computing circuit to obtain the pulsation mapping template.
7. The method according to any one of claims 1 to 6, characterized in that The loop code includes: a regular loop pipeline code with the same number of operations in each iteration, fixed rules for dependencies between data, and fixed loop boundaries.
8. A code processing device, characterized in that: include: An acquisition module, used for acquiring a loop code in a predetermined program; A determination module, configured to determine a first polyhedral model according to the loop code, wherein the first polyhedral model includes dependencies between data for performing calculation operations on variables in the loop code; An optimization module, used for optimizing the first polyhedron model to obtain a second polyhedron model; A mapping module, configured to map the second polyhedral model to a processing unit of a hardware structure to obtain a pulsation mapping template, wherein the processing unit included in the pulsation mapping template supports parallel processing of operations without data dependencies; The mapping module is further used to map the second polyhedral model into an intermediate virtual model according to the time occupancy and the processor resource occupancy; map the intermediate virtual model to the processing unit of the hardware structure to obtain a pulsation mapping template; wherein the pulsation mapping template supports connection with an external storage module, and maps the cyclic process into a parallel module operating on the external storage module.
9. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the code processing method according to any one of claims 1 to 7.
10. A processor, characterized in that: The processor is used to run a program, wherein the program executes the code processing method described in any one of claims 1 to 7 when running.
Citation Information
Patent Citations
Optimization method and system of cyclic mapping of processor
CN103106067A
Parallelization and loop optimization method and system for a high-level language of reconfigurable processor
CN105700933A
System and Method for Stable Transitions in the Presence of Conditionals for an Advanced Dual-Representation Polyhedral Loop Transformation Framework
US20090083722A1
Loop optimization with mapping code on an architecture
US6772415B1
