Shared memory access methods and apparatus, electronic devices and software products
By setting control bits and a splitting judgment mechanism in the shared memory access instructions, the problems of data rearrangement and repository conflicts in the shared memory access scheme are solved, thereby improving memory access efficiency and parallel computing performance.
Patent Information
- Application Number
- CN202680002490.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-26
- Publication Date
- 2026-11-17
AI Technical Summary
Existing shared memory access schemes suffer from efficiency bottlenecks, failing to efficiently support the data rearrangement operations required for matrix calculations. Furthermore, multi-channel access is prone to causing repository conflicts, leading to increased memory access latency, decreased bandwidth utilization, and limiting parallel computing performance.
By setting control bits in shared memory access instructions to select horizontal or vertical data access modes, and determining whether to split instructions based on address and data information, vertical or horizontal data reorganization can be achieved, reducing multi-channel access conflicts.
It improves the access efficiency of shared memory and the data throughput performance of parallel computing, meets the data layout transformation requirements in matrix computing scenarios, and reduces access latency.
Smart Images

Figure CN123125580A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computers, and in particular to a shared memory access method and apparatus, electronic device and program product. Background Technology
[0002] In parallel computing on graphics processing units (GPUs) and general-purpose graphics processing units (GPGPUs), especially when performing matrix calculations in deep neural networks (DNNs), the source data required for computation is usually first loaded into shared memory (SM) and then scheduled into the common register file (CRF) to reduce the time spent loading data from high-latency global memory, so that the computing unit can perform efficient multiplication and addition operations.
[0003] Traditional shared memory access methods suffer from two efficiency bottlenecks. First, there's the mismatch between access patterns and computational characteristics. Traditional shared memory read / write operations typically only support writing data from the shared memory storage (SM) horizontally to the common memory flow (CRF) or vice versa. This data arrangement doesn't align with the multi-dimensional, parallel-accessible nature of matrix computations and cannot efficiently support the data rearrangement requirements (transposition, merging, and block partitioning) in computationally intensive tasks like deep neural networks (DNNs), making it computationally inefficient. Second, there's the hardware-level issue of parallel access conflicts. Shared memory consists of multiple parallel banks. When multiple channels of a work item initiate access, regardless of whether the operation is read or write, a bank conflict occurs if these channels' addresses map to the same physical bank. This conflict forces otherwise parallel access instructions to be executed serially, increasing access latency and reducing SM bandwidth utilization.
[0004] Existing shared memory access schemes read and write data in a fixed horizontal manner, which cannot efficiently support the data rearrangement operations required for matrix calculations. At the same time, multi-channel access is prone to causing repository conflicts, resulting in increased memory access latency and decreased bandwidth utilization, thus restricting the overall performance of parallel computing. Summary of the Invention Technical issues
[0005] The technical problem to be solved by this application is to provide a shared memory access method, apparatus, electronic device, and program product that improves the overall performance of parallel computing.
[0006] Technical solution
[0007] To address the aforementioned technical problems, according to one aspect of this application, a shared memory access method is provided, comprising: acquiring a shared memory access instruction, the shared memory access instruction including address information, control information, and data information, wherein the control information includes control bits for controlling the data access mode to be horizontal or vertical and opcodes for distinguishing between read and write operations; determining a multi-channel data integration mode for a work item corresponding to the shared memory access instruction based on the address information and the data information; determining whether the shared memory access instruction needs to be split based on the data integration mode; if the shared memory access instruction does not need to be split, performing a read operation or a write operation on the shared memory based on the opcode; if a read operation is performed on the shared memory, and when the data access mode is determined to be vertical based on the control bits, writing the data in the shared memory into a general-purpose register file in a vertical manner; and if a write operation is performed on the shared memory, and when the data access mode is determined to be vertical based on the control bits, writing the data arranged vertically in the general-purpose register file into the shared memory in a horizontal manner.
[0008] In one possible implementation of the first aspect, the method may further include: if it is necessary to split the shared memory access instruction, splitting the same shared memory access instruction into multiple sub-access requests, each sub-access request carrying address information, control information, and data integration mode of the shared memory access instruction; for each sub-access request, performing a read operation or a write operation on the shared memory according to the opcode carried by the sub-access request.
[0009] By decomposing shared memory access instructions that need to be split into multiple sub-access requests, and each sub-instruction fully carries the address information, control information and data integration mode of the original instruction, each sub-access after splitting can be executed independently and accurately, thereby facilitating the fine-grained processing of complex or non-contiguous memory access instructions.
[0010] In one possible implementation of the first aspect, for each of the sub-access requests, when a read operation is performed on the shared memory according to the opcode, and when the data access mode is determined to be vertical according to the control bit, the following steps are performed: reading the corresponding data block from the shared memory according to the data integration mode; calculating the write position of each data in the data block in the general-purpose register file according to the address information and the work item index and channel index determined by the data integration mode, the write position including the register index and channel index; and writing the data in the data block to the calculated write position in a vertical manner.
[0011] In this way, for the split sub-access requests, when determined to be vertical read operations, the corresponding data block is first read from shared memory according to the data integration mode. Then, the write position of each data in the general-purpose register file is accurately calculated by combining the address information and the data integration mode information, and finally the data is written vertically. This process achieves efficient and accurate data reorganization from shared memory to the general-purpose register file, meeting the needs of data layout transformation in scenarios such as matrix calculations.
[0012] In one possible implementation of the first aspect, for each of the sub-access requests, when a write operation is performed on the shared memory according to the opcode, and when the data access mode is determined to be vertical according to the control bit, the following steps may be performed: according to the data integration mode, obtaining a portion of the data to be written that corresponds to the sub-access request from the general-purpose register file arranged vertically; calculating the target address of the portion of data in the shared memory according to the address information and the data integration mode; and writing the portion of data horizontally to the calculated target address.
[0013] This ensures that during write operations, data can be correctly and efficiently stored back from the vertical layout of the general-purpose register file to the designated location in shared memory.
[0014] In one possible implementation of the first aspect, the data information may include at least the number of work items and the number of channels. The step of determining the multi-channel data integration mode of the work item corresponding to the shared memory access instruction based on the address information and the data information may include: performing channel address continuity detection on multiple channels of the work item based on the address information to determine the storage location relationship of the multiple channels in shared memory; determining the actual number of channels stored in each repository based on the storage location relationship and the number of work items and the number of channels; and determining the data integration mode based on the actual number of channels stored in each repository.
[0015] In this way, by performing address continuity detection on multiple channels of work items based on address information, the storage location relationship of channels in shared memory is clarified. Then, by combining the number of work items and the number of channels, the actual number of channels occupied by each repository is determined. Based on the number of channels, the data integration mode is determined, which provides a key basis for subsequent access decisions and enables the access strategy to adapt to the specific data storage distribution.
[0016] In one possible implementation of the first aspect, the step of determining whether to split the shared memory access instruction based on the data integration mode may include: obtaining the address information; determining whether to split the current shared memory request based on the data integration mode and the address information: if the shared memory request address satisfies the data integration mode, then it is determined that the shared memory access instruction needs to be split; and if the shared memory request address does not satisfy the data integration mode, then it is determined that the shared memory access instruction does not need to be split.
[0017] In one possible implementation of the first aspect, determining whether a read or write operation needs to be performed on the shared memory based on the opcode may include: parsing the encoded value of the opcode; performing a read operation on the shared memory if the encoded value of the opcode matches a predefined read opcode; and performing a write operation on the shared memory if the encoded value of the opcode matches a predefined write opcode.
[0018] By parsing the encoded value of the opcode and matching it with a predefined read opcode or write opcode, it can be clearly determined whether the current instruction needs to perform a read operation or a write operation, thus facilitating subsequent read control or write control.
[0019] In one possible implementation of the first aspect, the method may further include, before obtaining the shared memory access instruction, receiving the shared memory access instruction and caching the received shared memory access instruction.
[0020] By caching shared memory access instructions, a stable instruction source is provided for subsequent processing steps such as integration mode checks and splitting decisions. Furthermore, caching shared memory access instructions allows for batch processing or optimized scheduling of a accumulated number of instructions, thereby improving the efficiency and resource utilization of subsequent processing units.
[0021] According to a second aspect of this application, a shared memory access apparatus is provided, comprising: an instruction information control unit for acquiring a shared memory access instruction, the shared memory access instruction including address information, control information, and data information, wherein the control information includes control bits for controlling the data access mode to be horizontal or vertical and opcodes for distinguishing between read and write operations; an integration mode checking unit for determining, based on the address information and the data information, a multi-channel data integration mode for a work item corresponding to the shared memory access instruction; a splitting judgment unit for determining, based on the data integration mode, whether the shared memory access instruction needs to be split; a shared memory operation judgment unit for performing a read operation or a write operation on the shared memory based on the opcode if splitting the shared memory access instruction is not required; a read control unit for writing data in the shared memory vertically to a general-purpose register file when performing a read operation on the shared memory and determining, based on the control bits, that the data access mode is vertical; and a write control unit for writing data in the shared memory horizontally to the shared memory when performing a write operation on the shared memory and determining, based on the control bits, that the data access mode is vertical.
[0022] The shared memory access device provided by this invention provides a hardware implementation scheme for the shared memory access method by integrating an instruction information control unit, an integration mode checking unit, a splitting judgment unit, a shared memory operation judgment unit, a read control unit, and a write control unit. Since the instructions acquired by the instruction information control unit include control bits for controlling the data access mode to be horizontal or vertical, the read control unit and write control unit can select the vertical mode for data reading and writing based on these control bits, thereby supporting data rearrangement operations in scenarios such as matrix calculations. Simultaneously, the integration mode checking unit and the splitting judgment unit can determine the data integration mode and judge the necessity of splitting based on address and data information, thereby identifying the storage distribution of multi-channel data before access, reducing conflicts caused by multiple channels accessing the same repository, reducing access latency, and ultimately improving the access efficiency of shared memory and the data throughput performance of parallel computing.
[0023] In one possible implementation of the second aspect, the shared memory access device may further include: the shared memory operation determination unit is further configured to, when it is necessary to split the shared memory access instruction into multiple sub-access requests, each sub-access request carrying address information, control information, and data integration mode of the shared memory access instruction; the shared memory operation determination unit is further configured to, for each sub-access request, perform a read operation or a write operation on the shared memory according to the opcode carried by the sub-access request.
[0024] By adding an instruction splitting unit to the shared memory access device, when it is necessary to split the shared memory access instruction, it can be split into multiple sub-access requests. At the same time, the function of the shared memory operation judgment unit is extended to handle the operation judgment of these sub-access requests. This can enhance the ability of the shared memory access device to handle complex memory access patterns. The instruction splitting and distribution logic is realized through modular design.
[0025] In one possible implementation of the second aspect, the shared memory access device may further include a shared memory cache unit for caching acquired shared memory access instructions.
[0026] By adding a shared memory cache unit to the shared memory access device, temporary storage space is provided for the received shared memory access instructions, which can alleviate the instantaneous pressure of access instructions, realize instruction buffering and queuing, and provide rate matching between upstream instruction sending and downstream instruction processing units, which helps to improve the overall processing stability and efficiency of the shared memory access device.
[0027] According to a third aspect of this application, an electronic device is provided, including a memory and a processor, the memory being used to store a computer program executable by the processor; the processor being used to execute the computer program in the memory to implement a shared memory access method as described in the first aspect and any possible implementation thereof.
[0028] According to a fourth aspect of this application, a computer-readable storage medium is provided having a computer program stored thereon, wherein when the executable computer program in the storage medium is executed by a processor, it is capable of implementing the shared memory access method as described in the first aspect and any possible implementation thereof.
[0029] According to a fifth aspect of this application, a computer program product is provided, comprising a computer program that, when executed by a processor, implements a shared memory access method as described in the first aspect and any possible implementation thereof. Beneficial effects
[0030] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0031] The technical solution of this invention sets a control bit in the shared memory access instruction to control whether the data access mode is horizontal or vertical. This allows the selection of vertical mode for data reading and writing according to computing needs, supporting data rearrangement operations in scenarios such as matrix calculations. At the same time, by determining the data integration mode based on address information and data information, and judging whether the shared memory access instruction needs to be split based on the data integration mode, the storage distribution of multi-channel data can be identified before access, thereby reducing conflicts caused by multiple channels accessing the same repository, reducing access latency, and improving the access efficiency of shared memory and the data throughput performance of parallel computing. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 According to some embodiments of the present invention, a size of m*2 is shown. n Storage layout of SM in *k bytes;
[0034] Figure 2 According to some embodiments of the present invention, a data placement method in two modes in a CRF is shown;
[0035] Figure 3 According to some embodiments of the present invention, a schematic diagram is shown of writing matrix data stored in SM to CRF via SM_RD instructions;
[0036] Figure 4 According to some embodiments of the present invention, a schematic diagram is shown of writing matrix data stored in CRF to SM via SM_WR instruction;
[0037] Figure 5 According to some embodiments of the present invention, a flowchart of a shared memory access method is shown;
[0038] Figure 6 According to some embodiments of the present invention, an architectural diagram of a shared memory access device is shown;
[0039] Figure 7 According to some embodiments of the present invention, an execution flowchart of a read control unit is shown;
[0040] Figure 8According to some embodiments of the present invention, a schematic diagram of a horizontal control unit writing a CRF in a horizontal manner is shown;
[0041] Figure 9 According to some embodiments of the present invention, an execution flowchart of a read vertical control unit is shown;
[0042] Figure 10 shows an execution flowchart of a write control unit according to some embodiments of the present invention;
[0043] Figure 11 shows an execution flowchart of writing a vertical control unit according to some embodiments of the present invention;
[0044] Figure 12 illustrates a numerical example of data reading from an SM in a horizontal and vertical manner according to some embodiments of the present invention;
[0045] Figure 13 illustrates a numerical example of writing data into an SM in a horizontal and vertical manner according to some embodiments of the present invention;
[0046] Figure 14 shows a structural block diagram of an electronic device according to some embodiments of the present invention. Embodiments of the present invention
[0047] The illustrative embodiments of the present invention include, but are not limited to, a shared memory access method and apparatus, electronic devices, media, and program products.
[0048] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0049] To facilitate understanding of the technical solution of this invention, the following first combines... Figure 1 The storage layout of SM will be explained. Figure 1 This illustrates a size of m*2 n For the storage layout of a *k-byte (bytes) SM, refer to... Figure 1 In GPUs or GPGPUs, the SM (Small Module) provides fast read and write capabilities for the Arithmetic Logic Unit (ALU), and the read and write latency of the SM should be as short as possible.
[0050] Work items within the same work group can access the same SM space. The SM can be configured using positive integers greater than 1 for the three parameters m, n, and k. Here, m is the number of repositories; n is the exponent in bytes of the repository width, i.e., 2^k. nLet k be the width of the repository; k is the number of storage lines contained in the SM, and the size of the entire SM is m*2. n *k. The specifications of SM can be adjusted by configuring the three parameters m, n, and k to adapt to different computing needs.
[0051] The following is combined Figure 2 This section introduces two data placement methods in CRF. (Reference) Figure 2 In CRF, the data arrangement methods are horizontal and vertical. Horizontal mode means that the data from the four RGBA channels of the same pixel is stored in four CRFs: RFi, RFi+1, RFi+2, and RFi+3. For details, refer to... Figure 2 For horizontal mode, the RGBA data of pixel P0 are stored in RFi, RFi+1, RFi+2, and RFi+3 respectively; the RGBA data of pixel P1 are stored in RFi, RFi+1, RFi+2, and RFi+3 respectively; the RGBA data of pixel P2 are stored in RFi, RFi+1, RFi+2, and RFi+3 respectively; and the RGBA data of pixel P3 are also stored in RFi, RFi+1, RFi+2, and RFi+3 respectively. Vertical mode refers to the storage of the RGBA data of the same pixel in the same CRF. For details, refer to... Figure 2 For vertical mode, the data of all four RGBA channels of pixel P0 is stored in RFi; the data of all four RGBA channels of pixel P1 is stored in RFi+1; the data of all four RGBA channels of pixel P2 is stored in RFi+2; and the data of all four RGBA channels of pixel P3 is stored in RFi+3. It should be noted that RFi is an index of the CRF. Data stored in RFi means that the data is stored in the CRF with index RFi. Correspondingly, data stored in RFi+1 means that the data is stored in the CRF with index RFi+1, data stored in RFi+2 means that the data is stored in the CRF with index RFi+2, and data stored in RFi+3 means that the data is stored in the CRF with index RFi+3.
[0052] Based on the above introduction to the storage layout of SM and the two data placement methods in CRF, the following will combine them with... Figure 3 and Figure 4 This paper compares and contrasts existing technologies that use a fixed horizontal approach to access shared memory, i.e., a fixed horizontal approach to read data from and write data to the shared memory storage (SM), with the shared memory access method provided by this invention that uses a vertical approach to access shared memory.
[0053] Figure 3 This diagram illustrates writing matrix data stored in the SM to the CRF using the SM_RD instruction. (Reference) Figure 3 Taking a 4×4 matrix data stored in SM as an example, assuming SM has 4 storage rows, that is... Figure 3 Lines 0 to 3 on the left side of the middle section each contain 4 repositories, that is, each line contains 4 repositories from bank0 to bank3. Figure 3 The upper right corner shows the process of reading SM data in a horizontal manner using the SM_RD instruction. The SM_RD instruction indicates that the CRF needs to read data from the SM and write the SM data to the CRF. In the horizontal reading mode, a row of data in the matrix stored in the SM, such as the data in the Line 0 row, spans four CRFs. That is, a row of data in the matrix stored in the SM is stored in four different CRFs. This will increase the conflict of reading the CRF storage stores, which is not conducive to matrix calculation. Figure 3 The lower right corner illustrates the process of reading data from the SM using the SM_RD instruction in a vertical manner after adopting the technical solution of this invention. Figure 3 As can be seen intuitively, after adopting the technical solution of this invention, the data read from the SM is written to the CRF in a vertical manner. In the vertical reading mode, the data of a row of the matrix stored in the SM, such as the data in the Line 0 row, are all written to the same CRF. This can reduce CRF repository conflicts and improve matrix calculation efficiency.
[0054] Figure 4 This diagram illustrates writing matrix data stored in the CRF to the SM using the SM_WR instruction. (Reference) Figure 4 Taking a 4×4 matrix data stored in a CRF as an example, assuming that each row of the CRF can store data from 4 channels, that is... Figure 4 Each row of the four CRFs corresponding to RF0 to RFi+3 on the left side can store data for four channels. Figure 4 The upper right corner shows the process of writing data to the SM in a horizontal manner using the SM_WR instruction. The SM_WR instruction indicates that the CRF needs to write data to the SM. In the horizontal writing mode, a row of data in the matrix stored in each CRF (the four CRFs corresponding to indices RF0 to RFi+3) will be written to the same repository in the SM. For example, the four data in the row of RF0 will be written to bank0 in the SM. This will increase the conflict in the SM repository and result in low efficiency of SM writing. Figure 4 The lower right corner illustrates the process of writing vertically arranged data from the CRF into the SM using the SM_WR instruction after adopting the technical solution of this invention. Figure 4As can be seen intuitively, after adopting the technical solution of this invention, the data arranged vertically in the CRF is written into the SM in a vertical manner. This can reduce SM repository conflicts, improve SM writing efficiency, and thus improve matrix calculation efficiency.
[0055] As mentioned earlier, existing shared memory access schemes cannot efficiently support the data rearrangement operations required for matrix calculations due to their fixed horizontal data reading and writing methods. At the same time, multi-channel access is prone to causing repository conflicts, resulting in increased memory access latency and decreased bandwidth utilization, thus constraining the overall performance of parallel computing.
[0056] In view of this, the technical solution of the present invention sets a control bit in the shared memory access instruction to control whether the data access mode is horizontal or vertical, thereby enabling the selection of vertical mode for data reading and writing according to computing needs, so as to support data rearrangement operations in scenarios such as matrix calculation; at the same time, by determining the data integration mode based on address information and data information, and judging whether the shared memory access instruction needs to be split according to the data integration mode, the storage distribution of multi-channel data can be identified before access, thereby reducing conflicts caused by multiple channels accessing the same repository, reducing access latency, improving the access efficiency of shared memory and the data throughput performance of parallel computing, and realizing the conversion of data mode in shared memory and general-purpose register file.
[0057] The following will combine Figure 5 The flowchart shown illustrates in detail a shared memory access method provided by this invention. (See reference...) Figure 5 The shared memory access method provided by the present invention includes the following steps S11 to S17:
[0058] Step S11: Obtain the shared memory access instruction. The shared memory access instruction includes address information, control information, and data information. The control information includes control bits for controlling the data access mode to be horizontal or vertical, and opcodes for distinguishing between read and write operations.
[0059] Specifically, the address information refers to the address accessed by the shared memory access instruction. This address information serves as the input basis for subsequent calculations such as row indexing, repository indexing, and starting byte indexing.
[0060] refer to Figure 3When data is written from the SM to the CRF, horizontal mode means that data is consecutively placed in multiple channels corresponding to the same work item. Simply put, a single access operation reads or writes multiple consecutive data channels within a single work item. Vertical mode means that data is distributed across the same channel locations corresponding to multiple different work items. Simply put, a single access operation reads or writes the same data channel within multiple different work items.
[0061] refer to Figure 4 When data is written from the CRF to the SM, the horizontal approach means that data from multiple channels corresponding to the same work item is continuously written to adjacent address locations in the SM. The vertical approach means that data from the same channel location corresponding to multiple different work items is written to scattered address locations in the SM that are arranged according to specific rules.
[0062] Step S12: Based on the address information and data information, determine the multi-channel data integration mode of the work item corresponding to the shared memory access instruction.
[0063] The data integration mode, based on the address information, data information, and the repository distribution determined through channel address continuity detection, defines the access granularity for each repository in this shared memory access. The data integration mode defines how, for a repository, data from several consecutive channels should be packaged into a single access instruction unit. This mode is typically reflected directly in the number of integration channels for each repository.
[0064] Step S13: Determine whether the shared memory access instructions need to be split based on the data integration mode.
[0065] Step S14: If there is no need to split the shared memory access instruction, then perform a read or write operation on the shared memory according to the opcode.
[0066] Step S15: If a read operation is performed on the shared memory, and the data access mode is determined to be vertical according to the control bits, then the data in the shared memory is written to the general-purpose register file in a vertical manner.
[0067] When the control bits determine that the data access mode is not vertical, the data in the shared memory is written to the general-purpose register file in a horizontal manner.
[0068] Step S16: If a write operation is performed on the shared memory, and the data access mode is determined to be vertical according to the control bits, then the data arranged vertically in the general-purpose register file is written to the shared memory in a horizontal manner.
[0069] When the control bits determine that the data access mode is not vertical, the data arranged horizontally in the general-purpose register file is written to the shared memory.
[0070] It is understood that the execution order of steps S11 to S17 above is only an illustration. In other embodiments, other execution orders may be used, and some steps may be split or combined. This is not limited here.
[0071] exist Figure 5 In the embodiment shown, the shared memory access method provided by the present invention further includes step S17: if it is necessary to split the shared memory access instruction, the shared memory access instruction is split into multiple sub-access requests, each sub-access request carrying the address information, control information and data integration mode of the shared memory access instruction; for each sub-access request, a read operation or a write operation is performed on the shared memory according to the opcode carried by the sub-access request.
[0072] By decomposing shared memory access instructions that need to be split into multiple sub-access requests, and each sub-instruction fully carries the address information, control information and data integration mode of the original instruction, each sub-access after splitting can be executed independently and accurately, thereby facilitating the fine-grained processing of complex or non-contiguous memory access instructions.
[0073] In some embodiments, for each sub-access request, when a read operation is performed on shared memory according to the opcode, and when the data access mode is determined to be vertical according to the control bits, the following steps are executed: The corresponding data block is read from shared memory according to the data integration mode; the write position of each data item in the data block in the general-purpose register file is calculated based on the address information and the work item index and channel index determined by the data integration mode, where the write position includes the register index and channel index; the data in the data block is written to the calculated write position in a vertical manner. Thus, for the split sub-access request, when a vertical read operation is determined, the corresponding data block is first read from shared memory according to the data integration mode, then the write position of each data item in the general-purpose register file is accurately calculated by combining the address information and the data integration mode information, and finally the data is written in a vertical manner. This process achieves efficient and accurate data reorganization from shared memory to the general-purpose register file, meeting the needs for data layout transformation in scenarios such as matrix calculations.
[0074] The register index identifies a specific register in the CRF. In vertical access mode, the register index specifies which target register in the CRF the data should be written to. The channel index identifies the specific channel location within the target register. Each register in the CRF is typically divided into multiple parallel data channels, and the channel index specifies which particular channel of that register the data should be written to. In vertical access mode, the register index and channel index together constitute the precise write location of the data in the CRF. These two indices are calculated based on the work item index and channel index determined by the address information and data integration mode. This ensures that data blocks read from the SM can be correctly and vertically distributed and written to different registers and channels in the CRF, thus meeting the data layout requirements of scenarios such as matrix calculations.
[0075] In some embodiments, for each sub-access request, when a write operation is performed on shared memory according to the opcode, and when the data access mode is determined to be vertical according to the control bits, the following steps are performed: Based on the data consolidation mode, a portion of the data to be written, arranged vertically, corresponding to the sub-access request is retrieved from the general-purpose register file; based on the address information and the data consolidation mode, the target address of the portion of data in shared memory is calculated; and the portion of data is written vertically to the calculated target address. This ensures that during write operations, data can be correctly and efficiently stored back to the specified location in shared memory from the vertical layout of the general-purpose register file.
[0076] In some embodiments, the data information includes at least the number of work items and the number of channels. Based on the address information and the data information, the multi-channel data integration mode of the work item corresponding to the shared memory access instruction is determined, including: performing channel address continuity detection on multiple channels of the work item based on the address information to determine the storage location relationship of multiple channels in shared memory; determining the actual number of channels stored in each repository based on the storage location relationship, the number of work items, and the number of channels; and determining the data integration mode based on the actual number of channels stored in each repository. Thus, by performing address continuity detection on multiple channels of the work item based on address information, the storage location relationship of channels in shared memory is clarified. Then, by combining the number of work items and the number of channels, the actual number of channels occupied by each repository is determined. Based on this number of channels, the data integration mode is determined, providing a crucial basis for subsequent access decisions and enabling the access strategy to adapt to the specific data storage distribution.
[0077] In some embodiments, the data information may also include the data format of the channels, i.e., the number of bits per channel.
[0078] In some embodiments, determining whether to split a shared memory access instruction based on a data integration mode includes: obtaining the address information; determining whether to split the current shared memory request based on the data integration mode and the address information: if the shared memory request address satisfies the data integration mode, then it is determined that the shared memory access instruction needs to be split; if the shared memory request address does not satisfy the data integration mode, then it is determined that the shared memory access instruction does not need to be split.
[0079] In some embodiments, a shared memory request address satisfying the data integration mode specifically means that: after channel address continuity detection based on address information, it is determined that multiple channels of a work item span at least two repositories of shared memory, and integration access conforming to the data integration mode cannot be completed within a single repository; a shared memory request address not satisfying the data integration mode specifically means that: after channel address continuity detection based on address information, it is determined that multiple channels of a work item do not span at least two repositories of shared memory, and integration access conforming to the data integration mode can be completed within a single repository.
[0080] In some embodiments, determining whether a read or write operation needs to be performed on shared memory based on the opcode includes: parsing the encoded value of the opcode; if the encoded value of the opcode matches a predefined read opcode, then a read operation is performed on the shared memory; if the encoded value of the opcode matches a predefined write opcode, then a write operation is performed on the shared memory. By parsing the encoded value of the opcode and matching it with predefined read or write opcodes, it is possible to clearly determine whether the current instruction requires a read or write operation, thereby facilitating subsequent read or write control.
[0081] In some embodiments, before obtaining the shared memory access instruction, the shared memory access method provided by the present invention further includes: receiving the shared memory access instruction; and caching the received shared memory access instruction. Caching the shared memory access instruction provides a stable instruction source for subsequent processing steps such as integration mode checking and splitting judgment. Simultaneously, caching the shared memory access instruction also enables batch processing or optimized scheduling of a certain number of accumulated instructions, thereby improving the working efficiency and resource utilization of subsequent processing units.
[0082] Embodiments of the present invention also provide a shared memory access device 10, see reference. Figure 6 The shared memory access device 10 provided in this embodiment of the invention includes:
[0083] The instruction information control unit 11 is used to acquire shared memory access instructions. The shared memory access instructions include address information, control information, and data information. The control information includes control bits for controlling the data access mode to be horizontal or vertical, and opcodes for distinguishing between read and write operations.
[0084] Integration mode checking unit 12 is used to determine the multi-channel data integration mode of the work item corresponding to the shared memory access instruction based on address information and data information;
[0085] The splitting judgment unit 13 is used to determine whether the shared memory access instructions need to be split based on the data integration mode;
[0086] The shared memory operation judgment unit 14 is used to perform read or write operations on the shared memory according to the opcode when there is no need to split the shared memory access instruction.
[0087] The read control unit 17 is used to write the data in the shared memory into the general-purpose register file in a vertical manner when performing a read operation on the shared memory and when the data access mode is determined to be vertical according to the control bit.
[0088] Write control unit 16 performs write operations on shared memory, and when the data access mode is determined to be vertical according to the control bit, the data arranged vertically in the general register file is written to the shared memory in a horizontal manner.
[0089] The shared memory access device 10 provided by this invention provides a hardware implementation scheme for a shared memory access method by integrating an instruction information control unit 11, an integration mode checking unit 12, a splitting judgment unit 13, a shared memory operation judgment unit 14, a read control unit 17, and a write control unit 16. Since the instruction obtained by the instruction information control unit 11 includes control bits for controlling the data access mode to be horizontal or vertical, the read control unit 17 and the write control unit 16 can select the vertical mode for data reading and writing based on these control bits, thereby supporting data rearrangement operations in scenarios such as matrix calculations. Simultaneously, the integration mode checking unit 12 and the splitting judgment unit 13 can determine the data integration mode and judge the necessity of splitting based on address and data information, thereby identifying the storage distribution of multi-channel data before access, reducing conflicts caused by multiple channels accessing the same repository, reducing access latency, and ultimately improving the access efficiency of shared memory and the data throughput performance of parallel computing.
[0090] exist Figure 6In the illustrated embodiment, the shared memory operation judgment unit 14 is further configured to split the shared memory access instruction into multiple sub-access requests when it is necessary to split the shared memory access instruction. Each sub-access request carries the address information, control information, and data integration mode of the shared memory access instruction. The shared memory operation judgment unit 14 is also configured to perform a read operation or a write operation on the shared memory according to the opcode carried by each sub-access request. By adding an instruction splitting unit 14 to the shared memory access device 10, the shared memory access instruction can be split into multiple sub-access requests when it is necessary to split the shared memory access instruction. At the same time, the function of the shared memory operation judgment unit 14 is extended to handle the operation judgment of these sub-access requests. This enhances the ability of the shared memory access device 10 to handle complex memory access patterns. The instruction splitting and distribution logic is realized through modular design.
[0091] exist Figure 6 In the illustrated embodiment, the shared memory access device 10 further includes a shared memory cache unit 18 for caching acquired shared memory access instructions. By adding a shared memory cache unit 18 to the shared memory access device 10, temporary storage space is provided for the received shared memory access instructions, which can alleviate the instantaneous pressure of access instructions, realize instruction buffering and queuing, and help improve the overall processing stability and efficiency of the shared memory access device 10.
[0092] exist Figure 6 In the illustrated embodiment, the shared memory access device 10 further includes a read control unit 17 and a write control unit 16. The read control unit 17 is used to write data in the SM to the CRF according to the data access mode determined by the control bits when the shared memory operation judgment unit 14 determines that a read operation needs to be performed on the SM. The write control unit 16 is used to write data in the CRF to the SM according to the data access mode determined by the control bits when the shared memory operation judgment unit 14 determines that a write operation needs to be performed on the SM.
[0093] The read control unit 17 includes a read horizontal control unit 171 and a read vertical control unit 172. The read horizontal control unit 171 writes data from the SM to the CRF in a horizontal manner when the data access mode is horizontal. The read vertical control unit 172, when the data access mode is vertical, reads the corresponding data block from the SM according to the data integration mode, and calculates the write position of each data item in the data block in the CRF based on the address information and the work item index and channel index determined by the data integration mode. The write position includes the register index and channel index, and then writes the data to the calculated write position in a vertical manner.
[0094] The write control unit 16 includes a horizontal write control unit 161 and a vertical write control unit 162. The horizontal write control unit 161, when the data access mode is horizontal, writes data arranged horizontally in the CRF to the SM. The vertical write control unit 162, when the data access mode is vertical, retrieves the portion of data corresponding to the current instruction from the vertically arranged data to be written in the CRF according to the data integration mode, calculates the target address of the portion of data in the SM based on address information and the data integration mode, and then writes the portion of data to the calculated target address vertically.
[0095] The specific manner in which the processor performs the operation in the apparatus described in the above embodiments has been described in detail in the embodiments related to the method, and will not be elaborated here.
[0096] The following will be based on Figure 6 The shared memory access device 10 shown is used as an example to illustrate the shared memory method provided by the present invention.
[0097] First, the shared memory access device 10 receives and caches instructions. Specifically, the arithmetic logic unit (ALU) 20 generates and issues shared memory access instructions, which can be, for example, a read instruction SM_RD or a write instruction SM_WR. Then, the received shared memory access instructions are stored in the shared memory cache unit 18.
[0098] The instruction information control unit 11 parses the instruction. Specifically, the instruction information control unit 11 obtains the shared memory access instruction from the shared memory cache unit 18, and then parses and extracts the key information in the shared memory access instruction, including address information, control information and data information. The control information includes control bits for controlling the data access mode to be horizontal or vertical and opcodes for distinguishing between read and write operations. The data information includes the number of work items and the number of channels, etc.
[0099] Then, the integration mode checking unit 12 performs a data integration mode check. Specifically, based on the address information and data information received from the instruction information control unit 11, the integration mode checking unit 12 performs channel address continuity detection on multiple channels of the work item corresponding to the current instruction, and determines the data integration mode applicable to this access accordingly. The purpose of this checking process is to identify the distribution of channels in each repository of SM to determine whether the data of multiple channels can be integrated into a single access instruction. Data integration can effectively reduce the number of accesses to shared memory, reduce repository conflicts, and thus improve the access efficiency of shared memory.
[0100] Then, the splitting judgment unit 13 performs the splitting judgment of the instruction. Specifically, the splitting judgment unit 13 determines whether the current shared memory access instruction needs to be split based on the data integration mode determined by the integration mode check unit 12. The instruction splitting unit 14 splits the shared memory access instruction that needs to be split according to the conclusion of the splitting judgment unit 13, generating multiple sub-access requests. Each sub-access request carries the address information, control information, and data integration mode of the original instruction completely.
[0101] For multiple sub-access requests or shared memory access instructions that do not require splitting, obtained after processing by instruction splitting unit 14, shared memory operation judgment unit 14 determines whether a read or write operation is required based on the opcode in the instruction. Subsequently, the instruction is routed to the corresponding control unit: if it is a read operation, it is processed by read control unit 17. Read control unit 17, based on the data access mode determined by control bits, calls its internal read horizontal control unit 171 or read vertical control unit 172 to perform the corresponding operation, reading data from shared memory (SM) 30 and writing it to general-purpose register file (CRF) 40. If it is a write operation, it is processed by write control unit 16. Write control unit 16, based on the data access mode determined by control bits, calls its internal write horizontal control unit 161 or write vertical control unit 162 to perform the corresponding operation, writing data from general-purpose register file (CRF) 40 to shared memory (SM) 30.
[0102] Furthermore, for the read control unit 17, for each sub-access request, when the shared memory operation judgment unit 14 determines that a read operation on the shared memory is required, and the control bit indicates that the data access mode is vertical, the read vertical control unit 172 in the read control unit 17 is invoked to perform a vertical read operation. The following will combine... Figures 7 to 9 The specific process of the read operation is explained in detail.
[0103] The vertical control unit 172 initiates a read request to the shared memory based on the data integration pattern carried in the sub-access request. This data integration pattern can be specifically represented as mPnC, which means integrating data from m work items, each with n channels. P is an abbreviation for "Per," and C represents "Channel." The shared memory responds to this read request by returning the corresponding data block organized according to the mPnC data integration pattern: that is, data from m work items × n channels.
[0104] like Figure 7 As shown, if the control bit indicates that the data access mode is horizontal, the returned data is processed by the horizontal control unit 171. In this mode, the read horizontal control unit 171 writes the data to the general-purpose register file in horizontal mode. Specifically, as... Figure 8 As shown, n CRFs (i.e. Figure 8 (nCRFs therein) are arranged horizontally, and each register contains m channels. Data is continuously written into a plurality of consecutive channels corresponding to the same work item according to the starting CRF index i and the starting channel index j.
[0105] If the control bit indicates that the data access mode is a vertical mode, the vertical control unit 172 follows Figure 9 the process shown for processing. The read vertical control unit 172 performs the following core calculation and mapping steps according to the address information of the sub-access request and the parameters determined by the data integration mode mPnC:
[0106] Calculate the target CRF index t and the number k of output CRFs. Specifically, based on the starting CRF index i, the number m of work items, the number n of channels, and the number SIMD_NUM of single-instruction multiple-data channels, the target CRF index t = i + floor((f+m*n) / SIMD_NUM) is calculated, and the number k of output CRFs is k = ceil((m*n) / SIMD_NUM). Where f is the relevant offset, and k represents the number of consecutive CRFs that need to be occupied to complete this vertical write. Then the data is output in a loop. Specifically, the output index out_idx is initialized to 0. When out_idx<k, the loop is executed. Subsequently, the data placement operation is performed. Specifically, the returned mPnC data block is placed in a vertical manner according to the (m / k)PnC mode: that is, the data of m work items is averagely distributed to k CRFs. This means that each target CRF will receive data from a plurality of different work items but at the same relative channel position. Thereafter, the data placed in the vertical manner is output to the CRF with the index of t+out_idx. Then out_idx is updated to out_idx+1 until all data is output. This process realizes reorganizing the data block returned linearly in the SM according to the calculated register index and channel index and writing the data block into the general register file in the vertical manner.
[0107] Thereafter, through the above-mentioned horizontal control or vertical control path, the data is finally written into the CRF, and this read operation is completed.
[0108] Further, for the write control unit 16, for each sub-access request, when the shared memory operation judgment unit 14 judges that a write operation to the shared memory is required and the control bit indicates that the data access mode is the vertical mode, the write vertical control unit 162 in the write control unit 16 is called to perform the vertical write operation. Hereinafter, the specific flow of the write operation will be described in detail with reference to FIG. 10 and FIG. 11.
[0109] Specifically, the write vertical control unit 162 prepares to retrieve the data to be written from the CRF according to the data integration mode carried by the sub-access request: namely the mPnC mode, such as 4P4C, and organizes the write request initiated to the SM according to the mode.
[0110] Subsequently, the write vertical control unit 162 performs crucial data preparation and address mapping calculations, corresponding to the logic shown in Figure 11. This calculation aims to precisely locate and retrieve the data to be written corresponding to the current mPnC mode from the vertically arranged source data (verti_data) in the CRF. Its core is to traverse each work item (cur_idx from 0 to m-1) and each channel (ch_idx from 0 to n-1) using nested loops. For each data unit, based on address information such as the starting channel index j, the number of SIMD_NUM channels, the number of channels (n), the current work item index (cur_idx), and the current channel index (ch_idx), two key coordinates are calculated using a specific formula: the index of the target register (i.e., the target CRF) and the target channel index. These two indices together determine the precise position of the data within the vertically arranged source data array verti_data. Through this loop, the write vertical control unit 162 completes the process of extracting all the data to be written from the vertical layout of the general-purpose register file.
[0111] Finally, the vertical write control unit 162 will write the data block, which has been organized in mPnC mode, to the corresponding target address of the shared memory in a vertical manner according to the calculated target address information, thus completing the write operation. If the control bit indicates horizontal mode, the horizontal control unit 161 will perform the corresponding operation. At the end of the entire process, the shared memory has completed the data writing.
[0112] The following configuration uses SM (m, n, k) = (16, 2, 1024), meaning there are 16 repositories and the repository width is 2. 2 = 4 bytes, with 1024 rows of storage lines. By adding 1 bit of control information to the SM_RD and SM_WR instructions, and referring to the schematic diagram of the read operation corresponding to SM_RD shown in Figure 12 and the schematic diagram of the write operation corresponding to SM_WR shown in Figure 13, the technical solution of the present invention is illustrated by example.
[0113] Assume the instruction format is: [Pn]SM_RD / WR.[hori / verti]Rd,Rs,data_fmt / / SM read / writeinstruction.
[0114] Wherein, Pn: indicates the number of channels currently active in the instruction. The control bit horizontal / verti: indicates that this 1-bit control bit is used to control the data access mode. When this control bit is 0, it indicates horizontal access; when this control bit is 1, it indicates vertical access. Rd: In the SM_RD instruction, it indicates the index of the target CRF; in the SM_WR instruction, it indicates the index of the source CRF. Rs: In the SM_RD instruction, it indicates the source address of the SM; in the SM_WR instruction, it indicates the destination address of the SM. data_fmt: indicates the data format involved in this access, such as the number of bits per channel (bpc).
[0115] For the read operation corresponding to SM_RD, taking Figure 12 as an example, for a shared memory instruction with the format [P2]SM_RD.hori R4,R0,32bit, the control bit hori indicates horizontal access. In horizontal mode, starting from the source address of the SM read specified by register R0, data in 32-bit per channel format is read and written horizontally to the CRF with R4 as the target index. As shown in the "SM_RD + Horizontal Mode" table on the left of Figure 12, a total of 8 data points are read from addresses 0, 4, 8, etc. in SM: corresponding to two work items, each work item has 4 channels, which are continuously and sequentially written into the corresponding channels (x,y,z,w) of R4, R5, R6, and R7 of the CRF. Specifically, multiple channel data belonging to the same work item, such as addresses 0, 1, 2, 3, are horizontally distributed in four different CRFs: R4.x, R5.y, R6.z, and R7.w.
[0116] For a shared memory instruction of the format [P2]SM_RD.verti R4,R0,32bit, the control bit verti indicates vertical access. In vertical mode, the same data is read from the same SM source address, but the data is written to the CRF in a vertical manner. As shown in the "SM_RD + Vertical Mode" table on the right side of Figure 12, the read data is reorganized: data from the same channel of all work items is written to the same CRF. For example, the first channel data of all work items (data corresponding to addresses 0, 4, 8, 12, 24, 28, 32, 36) is written vertically to R4.x; the second channel data of all work items (data corresponding to addresses 1, 5, 9, 13, 25, 29, 33, 37) is written vertically to R5.y, and so on.
[0117] For the write operation corresponding to SM_WR, taking Figure 13 as an example, for a shared memory access instruction with the format [P2]SM_WR.hori R4,R0,32bit, where the control bit hori indicates that horizontal access is used. In horizontal mode, the data stored in the CRF starting at index R4 is written horizontally to the SM target address specified by R0. As shown in the "SM_WR+Horizontal Mode" table below Figure 13, the data values in CRF registers R4.x, R5.y, R6.z, and R7.w are as follows: R4.x: 0, 4, 8, 12, 24, 28, 32, 36; R5.y: 1, 5, 9, 13, 25, 29, 33, 37; R6.z: 2, 6, 10, 14, 26, 30, 34, 38; R7.w: 3, 7, 11, 15, 27, 31, 35, 39. These values are horizontally written to adjacent addresses in the SM register (e.g., 0, 1, 2, 3, 4, 5, 6, 7) in the order of their channels in the registers. This is equivalent to storing multiple channels of the same work item consecutively in the SM. For a shared memory access instruction with the format [P2]SM_WR.verti R4,R0,32bit, the control bit verti indicates that vertical access is used. In this method, data arranged vertically in the CRF, i.e., the data layout shown in Figure 12 (vertical read result), is written vertically to the SM. As shown in the "SM_WR + Vertical Method" table below Figure 13, all data in R4.x, coming from the first channel of different work items, is written to addresses 0, 1, 2, 3, 4, 5, 6, 7 in the SM; all data in R5.y, coming from the second channel of different work items, is written to addresses 8, 9, 10, 11, 12, 13, 14, 15, and so on. This achieves the mapping of data from the vertical layout of the CRF to specific distributed addresses in the SM, contrasting with the horizontal write method and demonstrating the characteristics of the vertical access mode in data rearrangement.
[0118] As can be seen from the above specific examples, the technical solution of the present invention, whether for read or write operations, can achieve more efficient data transfer between shared memory and general register files that better meets the needs of matrix calculation through specific data integration modes and corresponding address calculation and data rearrangement logic, thereby effectively reducing repository conflicts and improving access efficiency.
[0119] Embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, wherein when the executable computer program in the storage medium is executed by a processor, the shared memory access method in any of the above embodiments can be implemented.
[0120] Embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements a shared memory access method as described in the first aspect and any possible implementation thereof.
[0121] An embodiment of the present invention also provides an electronic device 50, as shown in FIG14. The electronic device 50 includes a memory 501 and a processor 502. The memory 501 is used to store computer programs executable by the processor 502; the processor 502 is used to execute the computer programs in the memory 501 to implement the shared memory access method in any of the above embodiments.
[0122] The electronic device 50 shown in Figure 14 also includes a communication interface 503. The processor 502, memory 501, and communication interface 503 are connected via a communication bus and communicate with each other.
[0123] Processor 502 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of programs in the above scheme.
[0124] Communication interface 503 is used to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Networks (WLAN), etc.
[0125] Memory 501 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or, or, or, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory may exist independently and be connected to the processor via a bus. Memory may also be integrated with the processor.
[0126] In the accompanying drawings, some structural or methodological features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be necessary. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. Furthermore, the inclusion of structural or methodological features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may be omitted or may be combined with other features. Industrial applicability
[0127] According to embodiments of this application, the technical solution of the present invention, since the acquired shared memory access instruction contains control bits for controlling the data access mode to be horizontal or vertical, can select the vertical mode for data reading and writing according to computing needs, so as to support data rearrangement operations in scenarios such as matrix calculation; at the same time, by determining the data integration mode based on address information and data information, and judging whether the shared memory access instruction needs to be split according to the data integration mode, the storage distribution of multi-channel data can be identified before access, thereby reducing conflicts caused by multiple channels accessing the same repository, reducing access latency, improving the access efficiency of shared memory and the data throughput performance of parallel computing, and thus can be applied to improve the working efficiency of computers.
[0128] It should be noted that the units / modules mentioned in the various device embodiments of the present invention are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, a part of a physical unit / module, or a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important factor; the combination of functions implemented by these logical units / modules is the key to solving the technical problem proposed by the present invention. Furthermore, to highlight the innovative aspects of the present invention, the above-described device embodiments of the present invention have not introduced units / modules that are not closely related to solving the technical problem proposed by the present invention. This does not mean that the above-described device embodiments do not contain other units / modules.
[0129] It should be noted that in the examples and description of this invention, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0130] Although the invention has been illustrated and described with reference to certain preferred embodiments thereof, those skilled in the art will understand that various changes in form and detail may be made therein without departing from the spirit and scope of the invention.
Claims
1. A method for accessing shared memory, comprising: The instruction retrieves shared memory access information, including address information, control information, and data information. The control information includes control bits for controlling whether the data access mode is horizontal or vertical, and an opcode for distinguishing between read and write operations. Based on the address information and the data information, determine the multi-channel data integration mode of the work item corresponding to the shared memory access instruction; Determine whether it is necessary to split the shared memory access instructions based on the data integration mode; If there is no need to split the shared memory access instructions, then perform a read or write operation on the shared memory according to the opcode; If a read operation is performed on the shared memory, and the data access mode is determined to be vertical according to the control bit, then the data in the shared memory is written to the general-purpose register file in a vertical manner. as well as If a write operation is performed on the shared memory, and the data access mode is determined to be vertical based on the control bit, then the data arranged vertically in the general register file is written horizontally to the shared memory.
2. The shared memory access method according to claim 1 further includes: If the shared memory access instruction needs to be split, the same shared memory access instruction is split into multiple sub-access requests. Each sub-access request carries the address information, control information, and data integration mode of the shared memory access instruction. For each sub-access request, a read operation or a write operation is performed on the shared memory according to the opcode carried by the sub-access request.
3. The shared memory access method according to claim 2 further includes, for each sub-access request, when a read operation is performed on the shared memory according to the opcode, and when the data access mode is determined to be vertical according to the control bit, performing the following steps: According to the data integration mode, the corresponding data block is read from the shared memory; Based on the address information and the work item index and channel index determined by the data integration mode, calculate the write position of each data item in the data block in the general-purpose register file, where the write position includes the register index and channel index; and The data in the data block is written vertically to the calculated write position.
4. The shared memory access method according to claim 2 further includes, for each sub-access request, when a write operation is performed on the shared memory according to the opcode, and when the data access mode is determined to be vertical according to the control bit, performing the following steps: According to the data integration mode, the portion of data corresponding to the sub-access request is obtained from the vertically arranged data to be written in the general register file. Based on the address information and the data integration mode, calculate the target address of the partial data in the shared memory; as well as The data is written horizontally to the calculated target address.
5. The shared memory access method according to claim 1, further comprising, when the data information includes at least the number of work items and the number of channels, determining the multi-channel data integration mode of the work item corresponding to the shared memory access instruction based on the address information and the data information: Based on the address information, channel address continuity detection is performed on multiple channels of the work item to determine the storage location relationship of the multiple channels in shared memory; Based on the storage location relationship and the number of work items and channels, determine the actual number of channels stored in each repository; as well as The data integration mode is determined based on the actual number of channels stored in each repository.
6. The shared memory access method according to claim 1, further comprising the following steps when determining whether the shared memory access instructions need to be split based on the data integration mode: Obtain the address information; Based on the data integration mode and the address information, determine whether the current shared memory request needs to be split: If the shared memory request address satisfies the data integration mode, then it is determined that the shared memory access instruction needs to be split; and If the shared memory request address does not meet the data integration mode, it is determined that the shared memory access instruction does not need to be split.
7. The shared memory access method according to claim 1, further comprising the case where a read operation or a write operation is performed on the shared memory according to the opcode: Parse the encoded value of the opcode; If the encoded value of the opcode matches a predefined read opcode, then a read operation is performed on the shared memory; and If the encoded value of the opcode matches the predefined write opcode, then a write operation is performed on the shared memory.
8. The shared memory access method according to claim 1, further comprising, before obtaining the shared memory access instruction: Receive the shared memory access instruction; and The received shared memory access instructions are cached.
9. A shared memory access device, comprising: The instruction information control unit is configured to acquire shared memory access instructions, including address information, control bits for controlling the data access mode to be horizontal or vertical, and opcodes for distinguishing between read and write operations, as well as data information. The integration mode checking unit is used to determine the multi-channel data integration mode of the work item corresponding to the shared memory access instruction based on the address information and the data information. The splitting judgment unit is used to determine whether the shared memory access instructions need to be split based on the data integration mode; A shared memory operation determination unit is used to perform a read operation or a write operation on the shared memory based on the opcode without splitting the shared memory access instruction; A read control unit is used to write data in the shared memory into a general-purpose register file in a vertical manner when performing a read operation on the shared memory and when the data access mode is determined to be vertical according to the control bit. as well as The write control unit is used to perform write operations on the shared memory, and when the data access mode is determined to be vertical according to the control bit, the data arranged vertically in the general register file is written to the shared memory in a horizontal manner.
10. The shared memory access device according to claim 9, wherein, The shared memory operation judgment unit is further configured to split the shared memory access instruction into multiple sub-access requests when it is necessary to split the shared memory access instruction, each sub-access request carrying the address information, control information, and data integration mode of the shared memory access instruction; and the shared memory operation judgment unit is further configured to perform a read operation or a write operation on the shared memory according to the operation code carried by the sub-access request for each sub-access request.
11. The shared memory access apparatus according to claim 9 further includes a shared memory cache unit for caching shared memory access instructions.
12. An electronic device configured to implement the shared memory access method as described in any one of claims 1 to 8.
13. A computer program product configured to implement the shared memory access method as described in any one of claims 1 to 8.
