Data prefetching method and device, electronic equipment and storage medium

By adding prefetch prompt instructions to the target program code during the compilation and optimization stage, the problem of insufficient identification information of the hardware prefetcher is solved, the timeliness and accuracy of data prefetching is achieved, and the performance of the processor is improved.

CN118964234APending Publication Date: 2024-11-15PHYTIUM TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411127306.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-15
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

The existing hardware prefetcher has limited identification information during data prefetching, resulting in untimely prefetching and cannot guarantee the rapidity of data acquisition.

Method used

In the compilation optimization stage, the prefetch prompt instructions are added to the target program code. The prefetch prompt instructions in the compiled program code determine the data prefetch trigger information and perform data prefetching, which simplifies the detection process of the hardware processor and improves the Timeliness of data prefetching.

Benefits of technology

Through software prefetch prompt instructions, the hardware processor can quickly determine the data prefetch trigger information, realize fast data prefetching, eliminate cumbersome detection process, improve the timeliness and accuracy of data prefetching, and reduce error prefetching Cache pollution caused.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964234A_ABST
    Figure CN118964234A_ABST
Patent Text Reader

Abstract

The invention provides a data prefetching method and device, electronic equipment and a storage medium, and relates to the technical field of data processing. The data prefetching method comprises the following steps: acquiring a target program code in a compilation optimization stage; adding a prefetching prompt instruction into the target program code to obtain the added target program code; compiling the added target program code to obtain a compiled program code; wherein the compiled program code is used for enabling the processor to determine data prefetching trigger information according to a prefetching prompt instruction in the compiled program code and perform data prefetching according to the data prefetching trigger information. According to the method, the compiling device adds the pre-fetching prompt instruction for the target program code, the processor can quickly determine the data pre-fetching trigger information based on the pre-fetching prompt instruction in the compiled program code, quick data pre-fetching can be performed based on the data pre-fetching trigger information, and the timeliness of data pre-fetching is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a data pre-fetching method, device, electronic device and storage medium. Background Art

[0002] Data prefetching means obtaining the data that may be needed in advance and storing it in cache or temporary storage before the user requests the data. The purpose of data prefetching is to reduce the time cost of obtaining data and improve the response speed and performance of information services.

[0003] In the related art, data pre-fetching is usually performed by a hardware pre-fetcher. However, the hardware pre-fetcher can recognize less information and takes a long time to perform data pre-fetching, and the timeliness of pre-fetching cannot be guaranteed. Summary of the invention

[0004] The purpose of this application is to provide a data pre-fetching method, device, electronic device and storage medium to address the deficiencies in the above-mentioned prior art, so as to solve the above-mentioned technical problems existing in the related art.

[0005] To achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:

[0006] In a first aspect, an embodiment of the present application provides a data prefetching method, which is applied to a compiling device, and the method includes:

[0007] Obtain target program code during the compilation and optimization phase;

[0008] Adding a prefetch prompt instruction to the target program code to obtain the added target program code;

[0009] Compiling the added target program code to obtain a compiled program code;

[0010] The compiled program code is used to enable the processor to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetch according to the data prefetch trigger information.

[0011] Optionally, the adding a prefetch hint instruction to the target program code to obtain the added target program code includes:

[0012] Adding a preload prompt instruction PRFM instruction not allocated in the processor to the target program code to obtain the added target program code;

[0013] Alternatively, a hint instruction HINT instruction in the processor is added to the target program code to obtain the added target program code.

[0014] Optionally, obtaining the target program code in the compilation optimization stage includes:

[0015] In the target optimization stage of the compile-link optimization stage, the intermediate program code corresponding to the source program code is obtained as the target program code;

[0016] Adding a prefetch hint instruction to the target program code to obtain the added target program code includes:

[0017] A prefetch start prompt instruction and a prefetch end prompt instruction are added to the target program code to obtain the added target program code.

[0018] Optionally, the adding a prefetch start prompt instruction and a prefetch end prompt instruction to the target program code to obtain the added target program code includes:

[0019] Adding a prefetch start prompt instruction, a first memory barrier instruction corresponding to the prefetch start prompt instruction, the prefetch end prompt instruction, and a second memory barrier instruction corresponding to the prefetch end prompt instruction in the target program code;

[0020] Among them, the first memory barrier instruction is used to fix the execution position of the prefetch start prompt instruction, and the second memory barrier instruction is used to fix the execution position of the prefetch end prompt instruction.

[0021] Optionally, the adding a prefetch start prompt instruction and a prefetch end prompt instruction to the target program code to obtain the added target program code includes:

[0022] According to the target program code, identifying a memory access mode;

[0023] The pre-fetch start prompt instruction and the pre-fetch end prompt instruction are added to the target program code by using a preset adding method corresponding to the memory access mode, so as to obtain the added target program code.

[0024] Optionally, the adopting a preset adding method corresponding to the memory access mode to add the prefetch start prompt instruction and the prefetch end prompt instruction to the target program code to obtain the added target program code includes:

[0025] Obtaining a loop body corresponding to the target program code;

[0026] If the memory access mode is a fixed-stride memory access mode, determining a preceding basic program code block and an exit basic program code block in the loop body;

[0027] According to the preceding basic program code block and the exiting basic program code block, the prefetch start prompt instruction and the prefetch end prompt instruction are added to the target program code.

[0028] Optionally, the adding the prefetch start prompt instruction and the prefetch end prompt instruction in the target program code according to the preceding basic program code block and the exiting basic program code block includes:

[0029] Determining a first target statement sequence of the preceding basic program code block in the target program code;

[0030] Adding the prefetch start prompt instruction at the end of the first target statement sequence;

[0031] Determining a second target statement sequence of the exit basic program code block in the target program code;

[0032] The prefetch end prompt instruction is added at the beginning of the second target statement sequence.

[0033] In a second aspect, an embodiment of the present application further provides a data pre-fetching method, which is applied to a processor, and the method includes:

[0034] Obtaining compiled program code; wherein the compiled program code is obtained by obtaining a target program code by a compiling device during a compilation optimization phase, adding a prefetch hint instruction to the target program code to obtain the added target program code, and compiling the added target program code;

[0035] Determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code;

[0036] Data prefetching is performed according to the data prefetching triggering information.

[0037] Optionally, before determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, the method further includes:

[0038] Determining a method for adding the prefetch prompt instruction in the compiled program code;

[0039] Determining a memory access mode corresponding to the compiled program code according to the adding method of the prefetch hint instruction;

[0040] The step of determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code includes:

[0041] Determining the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction;

[0042] The performing data prefetching according to the data prefetch triggering information includes:

[0043] Data prefetching is performed according to the memory access mode and the data prefetching triggering information.

[0044] Optionally, the prefetch prompt instruction includes: a prefetch start prompt instruction and a prefetch end prompt instruction; and determining the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction includes:

[0045] If the memory access mode is a fixed-stride memory access mode, a first number threshold and a second number threshold are determined respectively according to the prefetch start prompt instruction and the prefetch end prompt instruction, and the data prefetch trigger information includes: the first number threshold and the second number threshold;

[0046] Performing data prefetching according to the memory access mode and the data prefetch triggering information includes:

[0047] If the memory access mode is a fixed-stride memory access mode, and the number of times the address span is detected to be the same is greater than or equal to the first threshold number, data prefetching is started; if the number of times the address span error is detected to be greater than or equal to the second threshold number, data prefetching is stopped.

[0048] Optionally, after determining the memory access mode corresponding to the compiled program code according to the adding manner of the prefetch hint instruction, the method includes:

[0049] Determining a target hardware prefetcher from a plurality of preset hardware prefetchers built into the processor according to the memory access mode;

[0050] The step of determining the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction includes:

[0051] Using the target hardware prefetcher, according to the memory access mode and the prefetch prompt instruction, determining the data prefetch trigger information;

[0052] The performing data prefetching according to the memory access mode and the data prefetch triggering information includes:

[0053] The target hardware prefetcher is used to perform data prefetching according to the memory access mode and the data prefetching trigger information.

[0054] In a third aspect, an embodiment of the present application further provides a data pre-fetching device, which is applied to a compiling device, and the device includes:

[0055] The acquisition module is used to obtain the target program code during the compilation and optimization stage;

[0056] An adding module, used for adding a pre-fetch prompt instruction to the target program code to obtain the added target program code;

[0057] A compiling module, used for compiling the added target program code to obtain a compiled program code;

[0058] The compiled program code is used to enable the processor to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetch according to the data prefetch trigger information.

[0059] Optionally, the adding module is specifically used to add the unallocated preload hint instruction PRFM instruction in the processor to the target program code to obtain the added target program code; or, to add the hint instruction HINT instruction in the processor to the target program code to obtain the added target program code.

[0060] Optionally, the acquisition module is specifically used to acquire the intermediate program code corresponding to the source program code as the target program code in the target optimization phase of the compile-link optimization phase;

[0061] The adding module is specifically used to add a prefetch start prompt instruction and a prefetch end prompt instruction to the target program code to obtain the added target program code.

[0062] Optionally, the adding module is specifically used to add a prefetch start prompt instruction, a first memory barrier instruction corresponding to the prefetch start prompt instruction, the prefetch end prompt instruction and a second memory barrier instruction corresponding to the prefetch end prompt instruction in the target program code; wherein, the first memory barrier instruction is used to fix the execution position of the prefetch start prompt instruction, and the second memory barrier instruction is used to fix the execution position of the prefetch end prompt instruction.

[0063] Optionally, the adding module is specifically used to identify a memory access mode according to the target program code; and to add the pre-fetch start prompt instruction and the pre-fetch end prompt instruction to the target program code using a preset adding method corresponding to the memory access mode to obtain the added target program code.

[0064] Optionally, the adding module is specifically used to obtain a loop body corresponding to the target program code; if the memory access mode is a fixed-stride memory access mode, determine a preceding basic program code block and an exit basic program code block in the loop body; and according to the preceding basic program code block and the exit basic program code block, add the prefetch start prompt instruction and the prefetch end prompt instruction in the target program code.

[0065] Optionally, the adding module is specifically used to determine the first target statement sequence of the preceding basic program code block in the target program code; add the prefetch start prompt instruction at the end of the first target statement sequence; determine the second target statement sequence of the exit basic program code block in the target program code; and add the prefetch end prompt instruction at the beginning of the second target statement sequence.

[0066] In a fourth aspect, an embodiment of the present application further provides a data pre-fetching device, applied to a processor, the device comprising:

[0067] An acquisition module is used to acquire a compiled program code; wherein the compiled program code is obtained by acquiring a target program code in a compilation optimization phase by a compiling device, adding a prefetch hint instruction to the target program code to obtain the added target program code, and compiling the added target program code;

[0068] A determination module, configured to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code;

[0069] A data pre-fetching module is used to perform data pre-fetching according to the data pre-fetching triggering information.

[0070] Optionally, the device further comprises:

[0071] The determination module is further used to determine a method for adding the prefetch prompt instruction in the compiled program code; and determine a memory access mode corresponding to the compiled program code according to the method for adding the prefetch prompt instruction;

[0072] The determining module is specifically used to determine the data prefetch triggering information according to the memory access mode and the prefetch prompt instruction;

[0073] The data pre-fetch module is specifically used to perform data pre-fetch according to the memory access mode and the data pre-fetch trigger information.

[0074] Optionally, the prefetch prompt instruction includes: a prefetch start prompt instruction and a prefetch end prompt instruction; the determination module is specifically used to determine a first number threshold and a second number threshold respectively according to the prefetch start prompt instruction and the prefetch end prompt instruction if the memory access mode is a fixed-stride memory access mode, and the data prefetch trigger information includes: the first number threshold and the second number threshold;

[0075] The data prefetch module is specifically used to start data prefetching if the memory access mode is a fixed-stride memory access mode and the number of times the address span is detected to be the same is greater than or equal to the first number threshold; and to stop data prefetching if the number of times the address span error is detected to be greater than or equal to the second number threshold.

[0076] Optionally, the device comprises:

[0077] The determination module is further configured to determine a target hardware prefetcher from a plurality of preset hardware prefetchers built into the processor according to the memory access mode;

[0078] The determination module is specifically used to determine the data prefetch trigger information using the target hardware prefetcher according to the memory access mode and the prefetch prompt instruction;

[0079] The data prefetch module is specifically configured to adopt the target hardware prefetcher to perform data prefetching according to the memory access mode and the data prefetch trigger information.

[0080] In a fifth aspect, an embodiment of the present application further provides an electronic device, comprising: a memory and a processor, wherein the memory stores a computer program executable by the processor, and when the processor executes the computer program, the processor implements the data prefetching method described in any one of the first aspect above, or the data prefetching method described in any one of the second aspect above.

[0081] In the sixth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is read and executed, the data pre-fetching method described in any one of the first aspect above, or the data pre-fetching method described in any one of the second aspect above is implemented.

[0082] The beneficial effect of the present application is as follows: the embodiment of the present application provides a data prefetching method, the method comprising: obtaining the target program code in the compilation optimization stage; adding a prefetch prompt instruction in the target program code to obtain the added target program code; compiling the added target program code to obtain the compiled program code; wherein the compiled program code is used to enable the processor to determine the data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetching according to the data prefetch trigger information. On the compilation device, the software prefetch prompt instruction is added to the target program code, and the hardware processor can quickly determine the data prefetch trigger information based on the prefetch prompt instruction in the compiled program code, and can perform fast data prefetching based on the data prefetch trigger information, that is, the hardware processor performs data prefetching based on the provided prefetch prompt instruction, so that the processor saves the cumbersome and time-consuming detection process and improves the timeliness of data prefetching. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0084] Figure 1 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 1 ;

[0085] Figure 2 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 2 ;

[0086] Figure 3 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 3 ;

[0087] Figure 4 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 4 ;

[0088] Figure 5 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 5 ;

[0089] Figure 6 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 6 ;

[0090] Figure 7 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 7 ;

[0091] Figure 8 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 8 ;

[0092] Fig. 9 A schematic diagram of the structure of a processor core provided in an embodiment of the present application;

[0093] Fig.10 A schematic diagram of the information refresh principle in a fixed-stride hardware prefetcher provided in an embodiment of the present application;

[0094] Fig.11 A schematic diagram of the working principle of a hardware prefetcher provided in an embodiment of the present application;

[0095] Fig.12A schematic diagram of a data pre-fetching device provided in an embodiment of the present application Figure 1 ;

[0096] Fig.13 A schematic diagram of a data pre-fetching device provided in an embodiment of the present application Figure 2 ;

[0097] Fig.14 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0098] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments.

[0099] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0100] In the description of the present application, it should be noted that if the terms "upper", "lower", etc. appear, the orientation or position relationship indicated is based on the orientation or position relationship shown in the drawings, or is the orientation or position relationship in which the product of the application is usually placed when used. It is only for the convenience of describing the present application and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application.

[0101] In addition, the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0102] It should be noted that, in the absence of conflict, the features in the embodiments of the present application may be combined with each other.

[0103] An embodiment of the present application provides a data prefetching method, which is applied to a compilation device. The following explains a data prefetching method provided by an embodiment of the present application.

[0104] Figure 1 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 1 ,like Figure 1 As shown, the method may include:

[0105] S101, obtaining target program code in the compilation optimization stage.

[0106] The target program code may be a program code obtained by converting the source program code.

[0107] In addition, a compiler is running in the compilation device, and the compilation optimization phase may be a compilation and linking optimization phase of the compiler, during which the target program code is obtained.

[0108] S102: Add a prefetch hint instruction to the target program code to obtain the added target program code.

[0109] In some implementations, an adding position in the target program code is determined, and a prefetch hint instruction is added to the target program code according to the adding position to obtain the added target program code.

[0110] For different memory access modes, different methods are used to determine the adding position in the target program code, and the determined adding position in the target program code is also different.

[0111] S103, compile the added target program code to obtain a compiled program code.

[0112] The compiled program code is used to enable the processor to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetch according to the data prefetch trigger information.

[0113] In an embodiment of the present application, the compiling device uses a compiler to compile the added target program code to obtain a compiled program code in binary form; the compiling device transmits the compiled program code to the processor, and the processor can obtain the compiled program code.

[0114] In some embodiments, the processor can quickly determine data prefetch trigger information based on the compiled program code. The data prefetch trigger information indicates parameter information for starting data prefetch and parameter information for ending data prefetch. Prefetch can be started and ended quickly based on the data prefetch trigger information.

[0115] Optionally, the processor uses a target hardware prefetcher to determine data prefetch trigger information according to a prefetch hint instruction in the compiled program code, and performs data prefetch according to the data prefetch trigger information.

[0116] It should be noted that after the processor determines the data prefetch trigger information based on the prefetch prompt instruction, it can quickly and efficiently perform data prefetching, eliminating the tedious and time-consuming identification and detection process.

[0117] In summary, the embodiment of the present application provides a data prefetching method, which includes: obtaining a target program code in the compilation optimization stage; adding a prefetch prompt instruction to the target program code to obtain the added target program code; compiling the added target program code to obtain the compiled program code; wherein the compiled program code is used to enable the processor to determine the data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetching according to the data prefetch trigger information. On the compilation device, the software prefetch prompt instruction is added to the target program code, and the hardware processor can quickly determine the data prefetch trigger information based on the prefetch prompt instruction in the compiled program code, and can perform fast data prefetching based on the data prefetch trigger information, that is, the hardware processor performs data prefetching based on the provided prefetch prompt instruction, so that the processor saves the cumbersome and time-consuming detection process and improves the timeliness of data prefetching.

[0118] Moreover, the data prefetch trigger information determined based on the prefetch hint instruction is more accurate, which can also improve the accuracy of data prefetching, greatly improve the data prefetching efficiency, and reduce cache pollution caused by erroneous data prefetching.

[0119] Optionally, the process of adding a prefetch hint instruction to the target program code in S102 to obtain the added target program code may include:

[0120] Adding a preload prompt instruction PRFM instruction not allocated in the processor to the target program code to obtain the added target program code;

[0121] Alternatively, a hint instruction HINT instruction in the processor is added to the target program code to obtain the added target program code.

[0122] Among them, the unallocated HINT instructions and PRFM instructions are instructions in the processor architecture. Optionally, the processor architecture can be an ARM64 architecture (a 64-bit processor architecture). For HINT instructions, if you want the processor to support HINT instructions, you must set the corresponding encoding, and implement the required operations in the hardware processor, including adding support for the instruction in the decoder, parsing micro-operations and virtual addresses. In the execution phase, some logic modules are added to read data from the memory. In the write-back phase, the data is written to the cache. Unallocated HINT instructions are reserved for future processor architecture function expansions, and new functions may be given in future versions, so unallocated PRFM instructions can be used first.

[0123] It should be noted that for unassigned PRFM instructions, most processors can support the PRFM instructions and can use the unassigned PRFM instructions directly. The unassigned PRFM instructions serve as prompts, and the specific functions depend on the specific hardware implementation. If not implemented, the processor will treat the unassigned PRFM instructions as NOP (No Operation) instructions.

[0124] In some implementations, some instruction space is reserved for hint instructions in the processor architecture. The instruction encoding corresponding to the unallocated HINT instruction can be expressed as: HINT# <imm>There are two types of PRFM instructions, specifically: prfm pldl1keep addr, prfm pldl2keep addr, prfm pldl3keep addr and prfm pldl1strmaddr, l1 means prefetch to L1 cache (first level cache); L2 means prefetch to L2 cache (second level cache); L3 means prefetch to L3 cache (third level cache). Among them, keep means that the prefetched data has temporal locality and will be treated the same as the loaded data in the cache (cache memory), and strm means that the prefetched data does not have temporal locality and will only be used once. The loop prefetch function in the compiler will calculate the reuse distance of each memory access data to determine whether the data has temporal locality. addr (address) can be selected at will, and is a sign to start and end data prefetching.

[0125] Temporal locality means that data accessed at a certain time will be accessed again soon. For temporal locality, you can refer to the following example:

[0126] int counter = 0;

[0127] while(condition){

[0128] / / some operations

[0129] counter++; / / counter is used for counting, and is frequently accessed in a short time

[0130] }

[0131] There is no temporal locality. Please refer to the following example:

[0132] for(int i=0; i <N;i++){

[0133] / / The diagonal elements in the matrix are only accessed once

[0134] if (matrix[i][i]!=0){

[0135] process(matrix[i][i]);

[0136] }

[0137] }

[0138] In actual applications, the compiler's built-in prefetch function can analyze whether the total source code data has temporal locality. If so, the prfm pldlxkeep instruction is used to indicate that it is retained in the cache. If not, the prfmpldlxstrm instruction is used to indicate that it is discarded after use.

[0139] Optionally, the process of obtaining the target program code in the compilation optimization phase in S101 may include:

[0140] In the target optimization stage of the compile-link optimization stage, the intermediate program code corresponding to the source program code is obtained as the target program code.

[0141] Among them, the target optimization stage of the compile-link optimization stage can be the Gimple optimization stage. GCC mainly uses three intermediate languages ​​to represent programs during the compilation process: Generic, Gimple, and Rtl. Gimple is a tree-based three-address representation converted from Generic. It is an intermediate representation language that is independent of the target machine and the front-end language. Almost all tree optimizations are based on GIMPLE, including: inter-procedural optimization, traditional scalar optimization, loop optimization, vectorization, inline expansion, constant propagation, redundancy elimination, etc.

[0142] In some implementations, the source program code is converted into an intermediate program code, and the intermediate program code is used as the target program code.

[0143] The process of adding the prefetch hint instruction to the target program code in S102 to obtain the added target program code may include:

[0144] A prefetch start prompt instruction and a prefetch end prompt instruction are added to the target program code to obtain the added target program code.

[0145] In some implementations, a first adding position and a second adding position in the target program code are determined, a prefetch start prompt instruction is added at the first adding position, and a prefetch end prompt instruction is added at the second adding position to obtain the added target program code.

[0146] In addition, if a preload hint instruction PRFM instruction not allocated in the processor is added to the target program code. The PRFM instruction may include a prefetch start PRFM instruction and a prefetch end PRFM instruction, wherein the prefetch start PRFM instruction may be represented as prfm pldl3strm#0, indicating the start of prefetch, and the prefetch end PRFM instruction may be represented as prfmpldl3strm#1, indicating the end of prefetch. Because these instructions have not been implemented, they will not be actually prefetched, but will only be treated as no-operation instructions. #0 and #1 are used as start and end marks. When these two special addresses are read, it is known that this is the start and end of prefetch.

[0147] Optionally, the process of adding the prefetch start prompt instruction and the prefetch end prompt instruction to the target program code to obtain the added target program code may include:

[0148] A prefetch start prompt instruction, a first memory barrier instruction corresponding to the prefetch start prompt instruction, a prefetch end prompt instruction, and a second memory barrier instruction corresponding to the prefetch end prompt instruction are added to the target program code.

[0149] Among them, the first memory barrier instruction is used to fix the execution position of the prefetch start prompt instruction, and the second memory barrier instruction is used to fix the execution position of the prefetch end prompt instruction.

[0150] It is worth noting that current processors generally use pipelines, superscalar technology, out-of-order emission, out-of-order execution, and branch prediction to improve instruction-level parallelism, which causes the execution sequence of instructions to be disrupted in the processor pipeline. In order to ensure that the order of the prefetch prompt instruction is not disrupted during execution, the present application implements the addition of a first memory barrier instruction and a second memory barrier instruction. Among them, the first memory barrier instruction can be added before and after the prefetch start prompt instruction, and the second memory barrier instruction can be added before and after the prefetch end prompt instruction.

[0151] In some embodiments, in order to minimize the impact of memory barrier instructions on processor performance, for unallocated PRFM instructions, the first memory barrier instruction and the second memory barrier instruction may be dmb instructions (a memory barrier instruction), wherein the parameter of the dmb instruction may be ishld. It is ensured that the memory read instruction following the instruction must wait for the execution of the previous memory read instruction, and the memory write instruction and the non-memory access instruction are not affected and can still be executed out of order. This is the benefit of using PRFM instructions as prefetch hint instructions. Because PRFM instructions belong to memory access instructions, only memory barrier instructions that ensure the order of memory access instructions need to be used. Memory barrier instructions are added during the compilation process, and can be added together with hint instructions. In addition, only the order of memory read instructions needs to be restricted, because the current data prefetch is mainly for read data. Among them, dmb instructions are added before and after the prefetch start hint instruction, and dmb instructions are added before and after the prefetch end hint instruction.

[0152] In the embodiment of the present application, whether the position of the prefetch prompt instruction is correct is a key problem solved by this design. For the following program code, a[i] and b[i] can be prefetched, so ideally, the prefetch start prompt instruction should be before the for loop, and the prefetch end prompt instruction should be after the entire for loop. Although the position of the prompt instruction inserted during the compilation phase is correct, out-of-order execution will completely disrupt the execution order of the instructions. It is possible that the instruction start prompt instruction is executed after the entire loop body, which will not play the role of the prefetch prompt; it is also possible that the prefetch end prompt instruction is executed before the start of the loop, which will cause logic problems.

[0153] int ip, a

[10000] , b

[10000] ;

[0154] / / Other instructions

[0155] / / …

[0156] / / Prefetch start prompt instruction

[0157] for(i=0;i <N;i++)

[0158] ip=ip+a[i]*b[i];

[0159] / / Prefetch end prompt instruction

[0160] / / …

[0161] / / Other instructions

[0162] Inserting dmb instructions before and after the prefetch start prompt instruction will ensure that all memory access instructions before the prefetch start prompt instruction are executed before the prefetch start prompt instruction is executed. Then, after the prefetch start prompt instruction is executed, the memory access instructions after it are executed, which fixes the position of the prefetch start prompt instruction. For the prefetch end prompt instruction, the dmb instruction can be inserted before and after the prefetch end prompt instruction.

[0163] For the above example, the code after inserting the dmb instruction is as follows:

[0164] / / Other instructions

[0165] / / …

[0166] dmb ishld

[0167] prfm pldl3strm#0

[0168] dmb ishld

[0169] for(i=0;i <N;i++)

[0170] ip=ip+a[i]*b[i];

[0171] dmb ishld

[0172] prfm pldl3strm#1

[0173] dmb ishld

[0174] / / …

[0175] / / Other instructions

[0176] In other embodiments, for unallocated HINT instructions, the first memory barrier instruction and the second memory barrier instruction may include: dsb instruction (a memory barrier instruction) and isb instruction (a memory barrier instruction). Memory barrier instructions restrict the execution order of all instructions, including non-memory access instructions, to be accurate, which will increase delay overhead. In addition, only the order of memory read instructions is restricted because the current data prefetching is mainly for read data. Among them, the dsb instruction is added before the prefetch start prompt instruction and the prefetch end prompt instruction, and the isb instruction is added after the prefetch start prompt instruction and the prefetch end prompt instruction.

[0177] It should be noted that if the new HINT instruction is used, because it does not belong to the memory access instruction, it is necessary to use the dsb and isb memory barrier instructions to limit the execution order of all instructions, including non-memory access instructions, which will increase the latency overhead. Specifically, it is necessary to insert the dsb instruction before the prefetch start hint instruction and the prefetch end hint instruction, and then insert the isb instruction. Because the HINT instruction does not belong to the memory access instruction, the dsb instruction can only ensure that the subsequent instruction will be executed after the previous memory access instruction is executed. Therefore, dsb can ensure the order of the following three instructions:

[0178] load x1

[0179] dsb

[0180] HINT# <imm>

[0181] However, the order of the following three instructions cannot be guaranteed. You can only use the isb instruction to ensure that the following instructions will be executed only after all the instructions before the isb instruction are executed.

[0182] HINT# <imm>

[0183] dsb

[0184] load x1

[0185] For the example above, the inserted instructions are:

[0186] / / Other instructions

[0187] / / …

[0188] dsb ishld

[0189] HINT# <imm1>

[0190] isb ishld

[0191] for(i=0;i<N;i++)

[0192] ip=ip+a[i]*b[i];

[0193] dsb ishld

[0194] HINT# <imm2>

[0195] isb ishld

[0196] / / …

[0197] / / Other instructions

[0198] Optionally, Figure 2 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 2 ,like Figure 2 As shown, the process of adding the prefetch start prompt instruction and the prefetch end prompt instruction to the target program code to obtain the added target program code may include:

[0199] S201. Identify a memory access mode according to a target program code.

[0200] Among them, the memory access mode can be a fixed-stride memory access mode or a spatial memory stream mode. Of course, the memory access mode can be other types of memory access modes, and the embodiments of the present application do not impose specific restrictions on this.

[0201] S202 , using a preset adding method corresponding to the memory access mode, adding a prefetch start prompt instruction and a prefetch end prompt instruction to the target program code to obtain the added target program code.

[0202] In the embodiment of the present application, the preset adding method is different for different memory access modes.

[0203] Optionally, Figure 3 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 3 ,like Figure 3 As shown, the process of adding a pre-fetch start prompt instruction and a pre-fetch end prompt instruction to the target program code by using the preset adding method corresponding to the memory access mode in the above S202 to obtain the added target program code may include:

[0204] S301, obtaining a loop body corresponding to the target program code.

[0205] In some implementations, in the Gimple optimization phase of the link optimization phase of the compiler, a new code processing process is added to identify all loop bodies in the target program code. Example loop bodies may include: for loops, while loops, do..while loops, loops generated by goto statements, etc.

[0206] S302: If the memory access mode is the fixed-stride memory access mode, determine the preceding basic program code block and the exit basic program code block in the loop body.

[0207] Among them, the memory access in the loop body can be analyzed to determine whether there is a fixed-stride memory read. If so, the memory access mode is determined to be a fixed-stride memory access mode, and all preceding basic program code blocks of the header block of the loop body and all exit basic program code blocks are determined.

[0208] It should be noted that GCC maintains a control flow graph (CFG) throughout the compilation process, which includes basic program code blocks. The control flow graph is built on the basis of Gimple and is used to abstract the control flow behavior of the function being compiled. The control flow graph is a directed graph in which the vertices represent basic blocks and the edges represent possible control flow transfers from one basic program code block to another.

[0209] GCC's code generation and optimization processes are complicated. To facilitate organization, GCC encapsulates these processes into individual passes. Each pass completes a specific process and then enters the next pass, like a pipeline.

[0210] In actual applications, a basic program code block is a linear sequence of code with only one entry point and one exit point. If any of the instructions is executed, all instructions will be executed, and they will be executed in order from the first to the last.

[0211] S303: Add a prefetch start prompt instruction and a prefetch end prompt instruction to the target program code according to the preceding basic program code block and the exiting basic program code block.

[0212] Wherein, according to the target statement sequence in the preceding basic program code block and the target statement sequence in the exiting basic program code block, a prefetch start prompt instruction and a prefetch end prompt instruction are added to the target program code.

[0213] In an embodiment of the present application, since the hot segment is usually in the loop body, if the memory access mode is other memory access modes, such as the spatial memory stream (SMS) mode, when adding prefetch hint instructions, prefetch hint instructions can also be added outside the loop.

[0214] Optionally, Figure 4 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 4 ,like Figure 4 As shown, according to the preceding basic program code block and the exiting basic program code block, a prefetch start prompt instruction and a prefetch end prompt instruction are added to the target program code, including:

[0215] S401, determining a first target statement sequence of a preceding basic program code block in a target program code.

[0216] S402: Add a prefetch start prompt instruction at the end of the first target statement sequence.

[0217] S403: Determine a second target statement sequence for exiting a basic program code block in the target program code.

[0218] S404: Add a pre-fetch end prompt instruction at the beginning of the second target statement sequence.

[0219] Among them, the first target statement sequence of the preceding basic program code block can be the Gimple statement sequence of the preceding basic program code block; the second target statement sequence of the exiting basic program code block can be the Gimple statement sequence of the exiting basic program code block.

[0220] In some implementations, a prefetch start hint instruction is added at the end of the Gimple statement sequence of all preceding basic program code blocks of the head block of the loop body; and a prefetch end hint instruction is added at the beginning of the Gimple statement sequence of all exit basic blocks of the loop body.

[0221] An embodiment of the present application also provides a data pre-fetching method, which is applied to a processor. The following is an explanation of a data pre-fetching method provided in an embodiment of the present application.

[0222] Figure 5 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 5 ,like Figure 5 As shown, the method may include:

[0223] S501, obtaining compiled program code.

[0224] The compiled program code is obtained by obtaining the target program code by the compiling device during the compiling optimization phase, adding a pre-fetch hint instruction to the target program code, obtaining the added target program code, and compiling the added target program code.

[0225] The compiled program code is the compiled program code obtained by the compiling device using the methods in S101 to S103 above. The specific process can refer to the relevant contents of S101 to S103 above, which will not be described again here.

[0226] S502: Determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code.

[0227] The data prefetch trigger information indicates parameter information for starting data prefetch and parameter information for ending data prefetch. Prefetch can be started and ended quickly according to the data prefetch trigger information.

[0228] In some implementations, the compiled program code may be interpreted to obtain the interpreted program code; and the data prefetch trigger information may be determined according to the interpreted program code.

[0229] S503: Perform data prefetching according to the data prefetching triggering information.

[0230] In an embodiment of the present application, the data prefetch start timing and the data prefetch end timing can be determined according to the data prefetch trigger information, and data prefetch can be started and ended quickly based on the data prefetch start timing and the data prefetch end timing.

[0231] It should be noted that after the processor determines the data prefetch trigger information based on the prefetch prompt instruction, it can quickly and efficiently perform data prefetching, eliminating the tedious and time-consuming identification and detection process.

[0232] In the embodiments of the present application, for some loops, the number of loop iterations can be determined during the compilation phase, and the stride of the loop induction variable is a constant. By passing this information to the hardware processor, the hardware processor can be guided to issue more accurate prefetches. For example, if the hardware processor knows the number of loop iterations, it can confirm how many prefetches to issue, preventing too many erroneous prefetches from being issued, occupying bandwidth, polluting the cache, or exiting too early without achieving the effect of prefetching. In addition, for particularly large spans, such as more than a few hundred cache lines, due to resource limitations, the processor cannot recognize it using a hardware prefetcher. If the software tells the loop memory access span, it can be prefetched directly, greatly improving processor performance.

[0233] In summary, a data prefetching method provided by an embodiment of the present application includes: obtaining compiled program code; wherein the compiled program code is obtained by a compiling device obtaining a target program code in a compilation optimization phase, adding a prefetch prompt instruction to the target program code, obtaining the added target program code, and compiling the added target program code; determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code; and performing data prefetching according to the data prefetch trigger information. Adding software prefetch prompt instructions to the target program code on the compiling device, the hardware processor can quickly determine the data prefetch trigger information based on the prefetch prompt instruction in the compiled program code, and can perform fast data prefetching based on the data prefetch trigger information, that is, the hardware processor performs data prefetching based on the provided prefetch prompt instruction, so that the processor saves the tedious and time-consuming detection process and improves the timeliness of data prefetching.

[0234] Moreover, the data prefetch trigger information determined based on the prefetch hint instruction is more accurate, which can also improve the accuracy of data prefetching, greatly improve the data prefetching efficiency, and reduce cache pollution caused by erroneous data prefetching.

[0235] Optionally, Figure 6 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 6 ,like Figure 6 As shown, before determining the data prefetch trigger information according to the prefetch prompt instruction in the compiled program code in the above S502, the method may further include:

[0236] S601, determining a method for adding prefetch hint instructions in a compiled program code.

[0237] S602: Determine a memory access mode corresponding to the compiled program code according to a method of adding the prefetch hint instruction.

[0238] In the embodiment of the present application, when the compiling device adds the pre-fetch hint instruction to the target program code, the preset hint instruction is added in different ways for different memory access modes. Therefore, the processing device can determine the memory access mode corresponding to the compiled program code according to the way the pre-fetch hint instruction is added.

[0239] In some implementations, the processing device may store a correspondence between multiple preset addition methods of prefetch hint instructions and multiple preset memory access modes. Based on the correspondence and the addition method of the prefetch hint instructions, the memory access mode corresponding to the compiled program code may be determined.

[0240] The process of determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code in S502 may include:

[0241] S603: Determine data prefetch trigger information according to the memory access mode and the prefetch prompt instruction.

[0242] Wherein, for different memory access modes, different methods are adopted to determine data prefetch trigger information according to the prefetch hint instruction.

[0243] The process of performing data prefetching according to the data prefetching triggering information in S503 may include:

[0244] S604: Perform data prefetching according to the memory access mode and the data prefetching trigger information.

[0245] It should be noted that, for different memory access modes, different methods are used to start data prefetching and end data prefetching according to data prefetch trigger information.

[0246] Optionally, the pre-fetch prompt instruction includes: a pre-fetch start prompt instruction and a pre-fetch end prompt instruction; Figure 7 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 7 ,like Figure 7 As shown, the process of determining data prefetch trigger information according to the memory access mode and the prefetch prompt instruction in the above S603 may include:

[0247] S701: If the memory access mode is the fixed-stride memory access mode, determine a first count threshold and a second count threshold respectively according to a prefetch start prompt instruction and a prefetch end prompt instruction.

[0248] The data pre-fetch trigger information includes: a first count threshold and a second count threshold.

[0249] It should be noted that, for the fixed-stride memory access mode, the prefetch start prompt instruction and the prefetch end prompt instruction can indicate the start of data prefetching after several identical address spans and the end of data prefetching after several incorrect address spans, that is, the first count threshold and the second count threshold can be indicated. Data prefetching starts after the number of identical address spans reaches the first count threshold, and data prefetching ends after the number of incorrect address spans reaches the second count threshold.

[0250] The process of performing data prefetching according to the memory access mode and the data prefetching trigger information in S604 may include:

[0251] S702: If the memory access mode is a fixed-stride memory access mode, and the number of times the same address span is detected is greater than or equal to the first count threshold, data prefetching is started; if the number of times the address span error is detected is greater than or equal to the second count threshold, data prefetching is stopped.

[0252] The processor may have a function of detecting the same address span and a function of detecting an address span error.

[0253] For example, the first count threshold may be 3, the second count threshold may be 8, and if the number of times the same address span is detected is greater than or equal to 3 times, data prefetching is started; if the number of times the address span error is detected is greater than or equal to 8 times, data prefetching is stopped.

[0254] It is worth noting that the processor can quickly pre-fetch data based on the number of times the address span is the same, the first count threshold, the number of times the address span is wrong, and the second count threshold, thereby eliminating the processor's lag in data pre-fetching and greatly improving the efficiency of data pre-fetching. At the same time, it avoids cache pollution caused by pre-fetching a large amount of erroneous data.

[0255] In the embodiment of the present application, for different memory access modes, different methods are used to start data prefetching and end data prefetching according to data prefetching trigger information. If the memory access mode is SMS mode, it is necessary not only to analyze whether a single memory access in the loop is a fixed stride, but also to analyze the correlation between multiple memory accesses in the loop and the regularity of the memory access address. If a certain memory access mode is found, data prefetching is required.

[0256] Optionally, Figure 8 A schematic diagram of a data pre-fetching method provided in an embodiment of the present application Figure 8 ,like Figure 8 As shown, after determining the memory access mode corresponding to the compiled program code according to the adding method of the prefetch hint instruction in the above S602, the method may include:

[0257] S801. Determine a target hardware prefetcher from a plurality of preset hardware prefetchers built into a processor according to a memory access mode.

[0258] In some embodiments, if the memory access mode is a fixed-stride memory access mode, the target hardware prefetcher is a fixed-stride hardware prefetcher; if the memory access mode is a spatial memory stream memory access mode, the target hardware prefetcher is a spatial memory stream hardware prefetcher.

[0259] Of course, the memory access mode may also be other memory access modes, and correspondingly, the target hardware prefetcher may also be other hardware prefetchers, and the embodiments of the present application do not impose any specific restrictions on this.

[0260] The process of determining data prefetch trigger information according to the memory access mode and the prefetch prompt instruction in S603 may include:

[0261] S802: Using a target hardware prefetcher, determine data prefetch trigger information according to a memory access mode and a prefetch prompt instruction.

[0262] The process of performing data prefetching according to the memory access mode and the data prefetching trigger information in S604 may include:

[0263] S803: Use the target hardware prefetcher to perform data prefetching according to the memory access mode and the data prefetching trigger information.

[0264] In the embodiment of the present application, the data prefetch triggering rule in the target hardware prefetcher is improved. The target hardware prefetcher can quickly determine the data prefetch triggering information based on the memory access mode and the prefetch prompt instruction, and quickly prefetch data according to the memory access mode and the data prefetch triggering information, thereby eliminating the hysteresis of the target hardware prefetcher and greatly improving the prefetching efficiency. At the same time, cache pollution caused by a large number of erroneous prefetching is avoided.

[0265] In some embodiments, the target hardware prefetcher is a fixed-stride hardware prefetcher, and the fixed-stride hardware prefetcher is used to determine the first count threshold and the second count threshold according to the fixed-stride memory access mode and the prefetch hint instruction; when the fixed-stride hardware prefetcher detects that the number of times the address span is the same is greater than or equal to the first count threshold, it starts data prefetching; when the fixed-stride hardware prefetcher detects that the number of times the address span is wrong is greater than or equal to the second count threshold, it stops data prefetching.

[0266] A data prefetching method provided in the application embodiment can be applicable to all system architectures. Prefetching prompt instructions are added in the compilation optimization stage, and the compiled program code is applicable to all hardware prefetchers.

[0267] Fig. 9 A schematic diagram of the structure of a processor core provided in an embodiment of the present application is shown in FIG. Fig. 9 As shown, the processor core includes: an instruction fetch module, a decoding module, an execution module, a memory access mode, a cache memory, and a memory management system. The memory access module includes a prefetch module, and the prefetch module includes: a stream prefetcher and a fixed stride prefetcher.

[0268] The instruction fetch module is connected to the decoding module, the decoding module is connected to the execution module, the decoding module is connected to the memory access module, and the memory access module is connected to the memory management system and the high-speed cache memory respectively.

[0269] Fig.10 A schematic diagram of the information refresh principle in a fixed-stride hardware prefetcher provided in an embodiment of the present application is shown in FIG. Fig.10 As shown, the virtual address and the program counter are transmitted to 8 table entries, which affect the stride state strength; based on the special address in the virtual address, the strength initial value is modified, and the state machine updates the stride state strength; based on the special address in the virtual address, the trigger rule is modified, and the prefetch is issued based on the prefetch trigger rule.

[0270] Each of the 8 entries contains stride, state, and strength. The refreshing of this information is completed by a state machine.

[0271] Fig.11 A schematic diagram of the working principle of a hardware prefetcher provided in an embodiment of the present application is shown in FIG. Fig.11 As shown, state: indicates the state of the prefetcher, 10->01->00->11 (weak->strong). hit: stride is consistent with the stride stored in the table entry (matches any one). miss: stride is inconsistent with the stride stored in the table entry, or does not match. strength: strength counter, records the number of tolerable stride inconsistencies. Set to 0 when State! = 11, set to 111 when state = 11 and hit, and -1 if inconsistent. stride: address span, that is, stride. When state! = 11, stride is the address accessed by the current training - the address stored in the current table entry, otherwise it remains. The prefetch trigger condition is: state = 11 or state! = 10 and hit.

[0272] The embodiment of the present application fine-tunes the prefetch triggering rules of the fixed-stride hardware prefetcher in the hardware prefetcher. When the prefetch start prompt is received, the prefetcher reads VA (virtual address) as a specific address #0, then the prefetch trigger condition is modified to: state = 11 or hit, and the reset value of the strength is changed from 111 to 001. In this way, the fixed-stride prefetcher will become more "confident" and only needs to detect the same address span twice to start prefetching, that is, when state = 10 and hit, it will start prefetching. Prefetching will end when two consecutive incorrect address spans are detected. When the prefetch end prompt instruction is received, the prefetcher detects a specific address #1, then the prefetch trigger condition is reset to: state = 11 or state! = 10 and hit, and the reset value of the strength is restored to 111.

[0273] In summary, a data prefetching method provided in an embodiment of the present application proposes a new software-hardware collaborative enhanced prefetching design in order to solve the lag of the hardware prefetcher and improve the efficiency of prefetching. The design uses a compiler device to identify the memory access mode, and the compiler device inserts prefetch start and end prompt instructions, and sends the compiled program code, that is, the executable file to the hardware prefetcher in the processor. The file contains prefetch prompt instructions. After the hardware prefetcher obtains the prefetch start and end signals, it eliminates the cumbersome and time-consuming detection process and can quickly turn on and off prefetching. This design greatly improves the prefetching efficiency and reduces cache pollution caused by erroneous prefetching.

[0274] Moreover, a data prefetching method provided in an embodiment of the present application is applicable to almost all memory access modes. For example, in the spatial memory stream (SMS) mode and the fixed stride mode, the hardware prefetcher in the prior art requires a large pattern history table to record the memory access space mode, and the start and end of the prefetching require cumbersome matching and verification processes. In an embodiment of the present application, a compiler device is used to identify the memory access mode, and a prefetch prompt instruction is added based on the memory access mode, so that the processor can use the hardware prefetcher to perform data prefetching according to the prefetch prompt instruction, which greatly simplifies the matching process and prevents the pattern history table from being polluted by continuing to issue erroneous prefetches after the cycle ends.

[0275] The following describes a data pre-fetching device, an electronic device, a storage medium, etc., used to execute the data pre-fetching method provided in the present application. The specific implementation process and technical effects thereof refer to the relevant contents of the above-mentioned data pre-fetching method, which will not be repeated below.

[0276] Fig.12 A schematic diagram of a data pre-fetching device provided in an embodiment of the present application Figure 1 ,like Fig.12 As shown, the device comprises:

[0277] The acquisition module 101 is used to acquire the target program code in the compilation optimization stage;

[0278] An adding module 102, used for adding a pre-fetch prompt instruction to the target program code to obtain the added target program code;

[0279] A compiling module 103, used to compile the added target program code to obtain a compiled program code;

[0280] The compiled program code is used to enable the processor to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetch according to the data prefetch trigger information.

[0281] Optionally, the adding module 102 is specifically used to add the unallocated preload hint instruction PRFM instruction in the processor to the target program code to obtain the added target program code; or, to add the hint instruction HINT instruction in the processor to the target program code to obtain the added target program code.

[0282] Optionally, the acquisition module 101 is specifically used to acquire the intermediate program code corresponding to the source program code as the target program code in the target optimization phase of the compile and link optimization phase;

[0283] The adding module is specifically used to add a prefetch start prompt instruction and a prefetch end prompt instruction to the target program code to obtain the added target program code.

[0284] Optionally, the adding module 102 is specifically used to add a prefetch start prompt instruction, a first memory barrier instruction corresponding to the prefetch start prompt instruction, the prefetch end prompt instruction and a second memory barrier instruction corresponding to the prefetch end prompt instruction in the target program code; wherein, the first memory barrier instruction is used to fix the execution position of the prefetch start prompt instruction, and the second memory barrier instruction is used to fix the execution position of the prefetch end prompt instruction.

[0285] Optionally, the adding module 102 is specifically used to identify a memory access mode according to the target program code; and to add the pre-fetch start prompt instruction and the pre-fetch end prompt instruction to the target program code using a preset adding method corresponding to the memory access mode to obtain the added target program code.

[0286] Optionally, the adding module 102 is specifically used to obtain a loop body corresponding to the target program code; if the memory access mode is a fixed-stride memory access mode, determine a preceding basic program code block and an exit basic program code block in the loop body; and according to the preceding basic program code block and the exit basic program code block, add the prefetch start prompt instruction and the prefetch end prompt instruction in the target program code.

[0287] Optionally, the adding module 102 is specifically used to determine the first target statement sequence of the preceding basic program code block in the target program code; add the prefetch start prompt instruction at the end of the first target statement sequence; determine the second target statement sequence of the exit basic program code block in the target program code; and add the prefetch end prompt instruction at the beginning of the second target statement sequence.

[0288] Fig.13 A schematic diagram of a data pre-fetching device provided in an embodiment of the present application Figure 2 ,like Fig.13 As shown, the device comprises:

[0289] The acquisition module 201 is used to acquire the compiled program code; wherein the compiled program code is obtained by acquiring the target program code by the compiling device in the compilation optimization stage, adding the prefetch hint instruction to the target program code to obtain the added target program code, and compiling the added target program code;

[0290] A determination module 202, configured to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code;

[0291] The data pre-fetching module 203 is used to perform data pre-fetching according to the data pre-fetching triggering information.

[0292] Optionally, the device further comprises:

[0293] The determination module 202 is further used to determine a method for adding the prefetch hint instruction in the compiled program code; and determine a memory access mode corresponding to the compiled program code according to the method for adding the prefetch hint instruction;

[0294] The determining module 202 is specifically configured to determine the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction;

[0295] The data pre-fetch module 203 is specifically configured to perform data pre-fetch according to the memory access mode and the data pre-fetch trigger information.

[0296] Optionally, the pre-fetch prompt instruction includes: a pre-fetch start prompt instruction and a pre-fetch end prompt instruction; the determination module 202 is specifically used to determine a first number threshold and a second number threshold respectively according to the pre-fetch start prompt instruction and the pre-fetch end prompt instruction if the memory access mode is a fixed-stride memory access mode, and the data pre-fetch trigger information includes: the first number threshold and the second number threshold;

[0297] The data prefetch module 203 is specifically used to start data prefetching if the memory access mode is a fixed-stride memory access mode and the number of times the address span is detected to be the same is greater than or equal to the first number threshold; and to stop data prefetching if the number of times the address span error is detected to be greater than or equal to the second number threshold.

[0298] Optionally, the device comprises:

[0299] The determination module 202 is further configured to determine a target hardware prefetcher from a plurality of preset hardware prefetchers built into the processor according to the memory access mode;

[0300] The determination module 202 is specifically configured to use the target hardware prefetcher to determine the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction;

[0301] The data prefetch module 203 is specifically configured to use the target hardware prefetcher to perform data prefetching according to the memory access mode and the data prefetch trigger information.

[0302] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0303] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital singnal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0304] Fig.14 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Fig.14 As shown, the electronic device includes: a processor 301 and a memory 302.

[0305] The memory 302 is used to store programs, and the processor 301 calls the programs stored in the memory 302 to execute the above method embodiment. The specific implementation method and technical effect are similar and will not be repeated here.

[0306] Optionally, the present application also provides a program product, such as a computer-readable storage medium, including a program, which is used to execute the above method embodiment when executed by a processor.

[0307] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as 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 devices or units, which can be electrical, mechanical or other forms.

[0308] 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 network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0309] In addition, each functional unit in each embodiment of the present application 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 hardware plus software functional units.

[0310] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit 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.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (English: Read-Only Memory, abbreviated: ROM), random access memory (English: Random Access Memory, abbreviated: RAM), disk or optical disk and other media that can store program codes.

[0311] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. < / imm> < / imm> < / imm>

Claims

1. A data pre-fetching method, characterized in that: Applied to a compiling device, the method comprises: Obtain target program code during the compilation and optimization phase; Adding a prefetch prompt instruction to the target program code to obtain the added target program code; Compiling the added target program code to obtain a compiled program code; The compiled program code is used to enable the processor to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetch according to the data prefetch trigger information.

2. The method according to claim 1, characterized in that The step of adding a prefetch prompt instruction to the target program code to obtain the added target program code comprises: Adding a preload prompt instruction PRFM instruction not allocated in the processor to the target program code to obtain the added target program code; Alternatively, a hint instruction HINT instruction in the processor is added to the target program code to obtain the added target program code.

3. The method according to claim 1, characterized in that The obtaining of the target program code in the compilation optimization stage includes: In the target optimization stage of the compile-link optimization stage, the intermediate program code corresponding to the source program code is obtained as the target program code; Adding a prefetch hint instruction to the target program code to obtain the added target program code includes: A prefetch start prompt instruction and a prefetch end prompt instruction are added to the target program code to obtain the added target program code.

4. The method according to claim 3, characterized in that: The adding of the prefetch start prompt instruction and the prefetch end prompt instruction in the target program code to obtain the added target program code comprises: Adding a prefetch start prompt instruction, a first memory barrier instruction corresponding to the prefetch start prompt instruction, the prefetch end prompt instruction, and a second memory barrier instruction corresponding to the prefetch end prompt instruction in the target program code; Among them, the first memory barrier instruction is used to fix the execution position of the prefetch start prompt instruction, and the second memory barrier instruction is used to fix the execution position of the prefetch end prompt instruction.

5. The method according to claim 3, characterized in that: The adding of the prefetch start prompt instruction and the prefetch end prompt instruction in the target program code to obtain the added target program code comprises: According to the target program code, identifying a memory access mode; The pre-fetch start prompt instruction and the pre-fetch end prompt instruction are added to the target program code by using a preset adding method corresponding to the memory access mode, so as to obtain the added target program code.

6. The method according to claim 5, characterized in that The method of adding the pre-fetch start prompt instruction and the pre-fetch end prompt instruction to the target program code by adopting the preset adding method corresponding to the memory access mode to obtain the added target program code includes: Obtaining a loop body corresponding to the target program code; If the memory access mode is a fixed-stride memory access mode, determining a preceding basic program code block and an exit basic program code block in the loop body; According to the preceding basic program code block and the exiting basic program code block, the prefetch start prompt instruction and the prefetch end prompt instruction are added to the target program code.

7. The method according to claim 6, characterized in that The adding the prefetch start prompt instruction and the prefetch end prompt instruction in the target program code according to the preceding basic program code block and the exiting basic program code block comprises: Determining a first target statement sequence of the preceding basic program code block in the target program code; Adding the prefetch start prompt instruction at the end of the first target statement sequence; Determining a second target statement sequence of the exit basic program code block in the target program code; The prefetch end prompt instruction is added at the beginning of the second target statement sequence.

8. A data pre-fetching method, characterized in that: Applied to a processor, the method comprises: Obtaining compiled program code; wherein the compiled program code is obtained by obtaining a target program code by a compiling device during a compilation optimization phase, adding a prefetch hint instruction to the target program code to obtain the added target program code, and compiling the added target program code; Determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code; Data prefetching is performed according to the data prefetching triggering information.

9. The method according to claim 8, characterized in that Before determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, the method further includes: Determining a method for adding the prefetch prompt instruction in the compiled program code; Determining a memory access mode corresponding to the compiled program code according to a method of adding the prefetch hint instruction; The step of determining data prefetch trigger information according to the prefetch prompt instruction in the compiled program code includes: Determining the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction; The performing data prefetching according to the data prefetch triggering information includes: Data prefetching is performed according to the memory access mode and the data prefetching triggering information.

10. The method according to claim 9, characterized in that The prefetch prompt instruction includes: a prefetch start prompt instruction and a prefetch end prompt instruction; the determining the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction includes: If the memory access mode is a fixed-stride memory access mode, a first number threshold and a second number threshold are determined respectively according to the prefetch start prompt instruction and the prefetch end prompt instruction, and the data prefetch trigger information includes: the first number threshold and the second number threshold; Performing data prefetching according to the memory access mode and the data prefetch triggering information includes: If the memory access mode is a fixed-stride memory access mode, and the number of times the address span is detected to be the same is greater than or equal to the first threshold number, data prefetching is started; if the number of times the address span error is detected to be greater than or equal to the second threshold number, data prefetching is stopped.

11. The method according to claim 9, characterized in that After determining the memory access mode corresponding to the compiled program code according to the adding method of the prefetch hint instruction, the method includes: Determining a target hardware prefetcher from a plurality of preset hardware prefetchers built into the processor according to the memory access mode; The step of determining the data prefetch trigger information according to the memory access mode and the prefetch prompt instruction includes: Using the target hardware prefetcher, according to the memory access mode and the prefetch prompt instruction, determining the data prefetch trigger information; The performing data prefetching according to the memory access mode and the data prefetch triggering information includes: The target hardware prefetcher is used to perform data prefetching according to the memory access mode and the data prefetching trigger information.

12. A data pre-fetching device, characterized in that: Applied to a compiling device, the device comprises: The acquisition module is used to obtain the target program code during the compilation and optimization stage; An adding module, used for adding a pre-fetch prompt instruction to the target program code to obtain the added target program code; A compiling module, used for compiling the added target program code to obtain a compiled program code; The compiled program code is used to enable the processor to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code, and perform data prefetch according to the data prefetch trigger information.

13. A data pre-fetching device, characterized in that: Applied to a processor, the device comprises: An acquisition module is used to acquire a compiled program code; wherein the compiled program code is obtained by acquiring a target program code in a compilation optimization phase by a compiling device, adding a prefetch hint instruction to the target program code to obtain the added target program code, and compiling the added target program code; A determination module, configured to determine data prefetch trigger information according to the prefetch prompt instruction in the compiled program code; A data pre-fetching module is used to perform data pre-fetching according to the data pre-fetching triggering information.

14. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program executable by the processor, and when the processor executes the computer program, the data prefetching method described in any one of claims 1 to 7 or the data prefetching method described in any one of claims 8 to 11 is implemented.

15. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is read and executed, the data pre-fetching method described in any one of claims 1 to 7 or the data pre-fetching method described in any one of claims 8 to 11 is implemented.

Citation Information

Cited By

  • Dynamic instruction conversion optimization method based on write prefetching

    CN119415156A

  • A dynamic instruction conversion optimization method based on write prefetch

    CN119415156B

  • Data processing method and device in assembly line, medium and program product

    CN119883382A