Method, medium and device for realizing ping-pong cache by using single memory
By analyzing and classifying the data flow rate of functional units, selecting a suitable single memory and adding cache, the problem of large memory resource requirements in ping-pong cache operations in functional units is solved, and the effects of resource saving and design complexity reduction are achieved.
Patent Information
- Application Number
- CN202410757069.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-10
Smart Images

Figure CN118626423A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electronic technology, and in particular to a method, medium and device for implementing ping-pong cache using a single memory. Background Art
[0002] In many occasions in the field of electronic technology, in order to control the data rate or system data synchronization, the system requires each functional unit to receive and send data according to a certain beat. The data received by the functional unit in each beat is first cached locally and then output in the next beat. This requires the functional unit to use a memory to cache the data. Usually, the functional unit will use two memories for ping-pong operations: taking memory A and memory B as an example, in a beat, the input data is written to memory A, and the data of memory B is read and output at the same time. In the next beat, the input data is written to memory B, and the data of memory A is read and output at the same time, and the cycle repeats. The functional unit needs to select a memory of corresponding capacity according to the amount of data that needs to be written in each beat, and the total memory capacity will not be less than twice the amount of data that needs to be cached. This places a large demand on the memory hardware resources in the functional unit, which is not conducive to low-cost design. Summary of the invention
[0003] In order to solve the above-mentioned problems, the present invention provides a method, medium and device for implementing ping-pong cache using a single memory, so as to save memory hardware resources and reduce costs and hardware design complexity.
[0004] The present invention provides a method for implementing ping-pong caching using a single memory, comprising:
[0005] By analyzing and classifying the data flow rates of the functional units, selecting memories that match the read and write rates, and adding appropriate caches, the need to implement ping-pong cache using only a single memory is met.
[0006] Furthermore, according to the data flow rate of the functional unit in each beat, the data flow type is divided into the following two categories:
[0007] Data flow type 1: The input data volume is never greater than the output data volume and they are equal in the end;
[0008] Data flow type 2: The amount of input data will exceed the amount of output data, and eventually they will be equal.
[0009] Furthermore, the read and write rate of the selected memory should at least not be lower than the total input and output rate of the functional unit data flow.
[0010] Furthermore, the total read and write time of each memory beat is: the time for the memory to read data + the time for the memory to write data + the total time for the memory to read and write conversion;
[0011] The total reading and writing time of each memory beat is not greater than the sum of the input data time and the output data time of the functional unit data flow.
[0012] Furthermore, for data stream type 1, there is no need to add a cache, and it is only necessary to read data from the memory and then write data to the memory in each beat.
[0013] Furthermore, for data stream type 2, it is necessary to increase the buffer.
[0014] Furthermore, a cache is added in the processor controlling the memory, and the size of the cache is the difference between the maximum write data amount and the maximum read data amount.
[0015] Furthermore, the control flow of the processor includes:
[0016] S1, reads data from the memory regularly and outputs it. This task has a higher priority than writing to the memory.
[0017] S2, the input data first enters the processor's cache, and the processor determines whether there is data in the cache to be written into the memory;
[0018] S3, the processor determines whether the memory is being read at this time;
[0019] S4, if the memory is read normally at this time, continue to wait, if the memory is not read at this time, write a section of cache data into the memory.
[0020] The present invention also provides a computer terminal storage medium storing computer terminal executable instructions, wherein the computer terminal executable instructions are used to execute the control flow of the above-mentioned processor.
[0021] The present invention also provides a computing device, comprising:
[0022] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the control flow of the above-mentioned processor.
[0023] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:
[0024] The present invention is mainly used in application scenarios of controlling data rate or system data synchronization. Through the present invention, two memories required in ping-pong cache operation can be reduced to one memory, saving memory resources and reducing costs and hardware design complexity. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention 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 creative work.
[0026] Figure 1 The following is a simplified model diagram for a typical functional unit.
[0027] Figure 2 This is a schematic diagram of data stream type 1 in an embodiment of the present invention.
[0028] Figure 3 This is a schematic diagram of data stream type 2 in an embodiment of the present invention.
[0029] Figure 4 4 is a control flow chart of a processor in an embodiment of the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions 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 part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0031] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] Example
[0033] This embodiment provides a method for implementing ping-pong caching using a single memory, including:
[0034] 1. Analysis and classification of data flow rate.
[0035] A typical functional unit can be simplified as follows Figure 1 The input data of each beat first enters the processor, which performs certain processing (such as validity judgment, etc.), and then writes it into the memory. When the next beat arrives, the processor reads the data in the memory and outputs it as output data.
[0036] According to the data flow rate of the functional unit within each beat, it can be divided into the following two categories:
[0037] Data flow type 1: The input data volume is always less than the output data volume and they are equal in the end, such as Figure 2 shown. Figure 2 The amount of read data is normalized in the figure.
[0038] Data flow type 2: The amount of input data will exceed the amount of output data, and eventually they will be equal. Figure 3 shown. Figure 3 The amount of read data is normalized in the figure.
[0039] 2. The method of selecting storage.
[0040] In addition to capacity, the selection of memory also requires consideration of the read and write speed of the memory.
[0041] The read and write rate of the memory must not be lower than the total input and output rate of the functional unit data flow, otherwise data will be lost. Since the conversion of the read and write operations of the memory usually takes a certain amount of time, the total read and write time of each memory beat is: the time for the memory to read data + the time for the memory to write data + the total time for the memory to read and write conversion. This time must not be greater than the sum of the time for input data and the time for output data of the functional unit data flow.
[0042] 3. Design of control software.
[0043] The flowchart of the processor software is as follows Figure 4 shown.
[0044] For data stream type 1, it is only necessary to read data from the memory and then write data to the memory in each beat.
[0045] For data flow type 2, additional cache is required, usually in the processor that controls the memory. The size of the cache is the difference between the maximum amount of write data and the maximum amount of read data, such as Figure 3 to ensure that the input data of the functional unit will not be lost.
[0046] The control flow of the processor is:
[0047] S1, reads data from the memory regularly and outputs it. This task has a higher priority than writing to the memory.
[0048] S2, the input data first enters the processor's cache, and the processor determines whether there is data in the cache to be written into the memory;
[0049] S3, the processor determines whether the memory is being read at this time;
[0050] S4, if the memory is read normally at this time, continue to wait, if the memory is not read at this time, write a section of cache data into the memory. Since the read priority is higher, the data in the cache may need to be written into the memory multiple times, and the specific strategy needs to be determined according to the application scenario.
[0051] The above method can be used to implement ping-pong caching using a single memory. This method also has certain limitations, that is, if the "maximum gap" is too large, the cache in the processor will be too large, and ultimately it cannot be implemented in the processor or the implementation cost is too high.
[0052] Example:
[0053] For a certain scenario: the input data rate is 1600Mbps, the data volume of each beat is 25M*32bit (800Mbit), and the output data rate is 1600Mbps. Traditional ping-pong operation requires the use of 2 memory chips. Applying the method of the present invention, only one 32M*32bit (1024Mbit) memory is selected in the hardware design, and the rate of the memory is 133M*32bit (3192Mbps). After evaluation, the read-write conversion time of the memory in the current application scenario is less than 10% of the total read-write time. A cache of 4096*32bit (131072bit) size is designed in the processor software. That is, the ping-pong cache with input and output according to the beat is completed. The memory hardware resources and the complexity of hardware design are saved.
[0054] In addition, in some embodiments, a computer terminal storage medium is provided, which stores computer terminal executable instructions, and the computer terminal executable instructions are used to execute the control flow described in the above embodiments. Examples of computer storage media include magnetic storage media (e.g., floppy disks, hard disks, etc.), optical recording media (e.g., CD-ROMs, DVDs, etc.), or memories, such as memory cards, ROMs, or RAMs, etc. Computer storage media can also be distributed on network-connected computer systems, such as application stores.
[0055] In addition, in some embodiments, a computing device is proposed, comprising: at least one processor; and a memory in communication with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the control flow of the processor as described in the above embodiments. Examples of computing devices include PCs, tablet computers, smart phones, or PDAs.
[0056] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for implementing ping-pong caching using a single memory, characterized in that: include: By analyzing and classifying the data flow rates of the functional units, selecting memories that match the read and write rates, and adding appropriate caches, the requirement of implementing ping-pong cache using only a single memory is met.
2. The method for implementing ping-pong cache using a single memory according to claim 1, characterized in that: According to the data flow rate of the functional unit in each beat, the data flow type is divided into the following two categories: Data flow type 1: The input data volume is never greater than the output data volume and they are equal in the end; Data flow type 2: The amount of input data will exceed the amount of output data, and eventually they will be equal.
3. The method for implementing ping-pong cache using a single memory according to claim 1, characterized in that: The read and write rate of the selected memory must at least not be lower than the total input and output rate of the functional unit data flow.
4. The method for implementing ping-pong caching using a single memory according to claim 3, characterized in that: The total read and write time of each memory beat is: the time for the memory to read data + the time for the memory to write data + the total time for the memory to read and write conversion; The total reading and writing time of each memory beat is not greater than the sum of the input data time and the output data time of the functional unit data flow.
5. The method for implementing ping-pong cache using a single memory according to claim 2, characterized in that: For data stream type 1, there is no need to add a cache. Instead, data needs to be read from the memory and then written to the memory in each beat.
6. The method for implementing ping-pong cache using a single memory according to claim 2, characterized in that: For data stream type 2, additional buffering is required.
7. The method for implementing ping-pong cache using a single memory according to claim 6, characterized in that: A cache is added to the processor that controls the memory, and the size of the cache is the difference between the maximum write data amount and the maximum read data amount.
8. The method for implementing ping-pong cache using a single memory according to claim 7, characterized in that: The control flow of the processor includes: S1, reads data from the memory regularly and outputs it. This task has a higher priority than writing to the memory. S2, the input data first enters the processor's cache, and the processor determines whether there is data in the cache to be written into the memory; S3, the processor determines whether the memory is being read at this time; S4, if the memory is read normally at this time, continue to wait, if the memory is not read at this time, write a section of cache data into the memory.
9. A computer terminal storage medium storing computer terminal executable instructions, characterized in that: The computer terminal executable instructions are used to execute the control flow of the processor as claimed in claim 8.
10. A computing device, characterized in that: include: at least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the control flow of the processor as described in claim 8.
