Shared memory variable address allocation method, device, electronic device and chip

By classifying and grouping shared memory variables, and generating interferograms for address allocation, the problem of redundant address allocation for shared memory variables is solved, and memory space utilization and access efficiency are optimized.

CN119938329BActive Publication Date: 2025-10-28BEIJING X RING TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510027060.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2025-10-28
Estimated Expiration
2045-01-07

AI Technical Summary

Technical Problem

In existing technologies, the address allocation methods for shared memory variables are redundant, leading to increased memory space consumption and failing to effectively optimize address allocation.

Method used

By classifying shared memory variables into local shared memory variables and global shared memory variables, and generating interferograms based on the kernel function groups of global shared memory variables, grouping and address allocation are performed to determine the starting position and alignment information of each group, thereby optimizing the address allocation of global shared memory variables.

Benefits of technology

It reduces redundancy in address allocation, optimizes memory space utilization, and improves memory access efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938329B_ABST
    Figure CN119938329B_ABST
Patent Text Reader

Abstract

This disclosure proposes a method, apparatus, electronic device, and chip for address allocation of shared memory variables, relating to the fields of computer technology and image processing. The method includes: determining local shared memory variables, global shared memory variables, and a kernel function group corresponding to each global shared memory variable based on the call information of each shared memory variable; generating an interferogram corresponding to each global shared memory variable based on the kernel function group; grouping the global shared memory variables based on the interferogram, and determining the starting position and alignment information of the global shared memory variables contained in each group; and determining the ending address of the local shared memory variables based on the total size of all global shared memory variables and the size of the local shared memory variables. This optimizes the address allocation of shared memory variables, effectively reduces address allocation redundancy, and saves memory space consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the fields of computer technology and intelligent computing, and in particular to a method, apparatus, electronic device and chip for address allocation of shared memory variables. Background Technology

[0002] In the field of heterogeneous computing, applications can execute in parallel to improve computing performance. In a Single Instruction Multiple Threads (SIMT) processor, the pipeline control unit creates thread groups and schedules their execution. During this process, all threads within the group execute the same instructions simultaneously. In a specific processor, each group has 32 threads, corresponding to the 32 execution pipelines or channels in the SIMT processor. Typically, these thread groups can be organized into a large execution module called a thread block. Threads within a thread block generally share a portion of computing and storage resources on the hardware, including shared memory. All threads within a thread block can access the same shared memory.

[0003] Shared memory is a memory interface released by the hardware to the user for programming. Users can declare variables stored in shared memory within their applications, and the compiler and other software stacks will then allocate addresses for these variables and generate memory access instructions for reading and writing. Shared memory is a powerful tool for writing well-optimized parallel programming code, which can significantly improve program execution performance. Summary of the Invention

[0004] This disclosure aims to at least partially address one of the technical problems in the related art.

[0005] The first aspect of this disclosure proposes a method for address allocation of shared memory variables, including:

[0006] Based on the call information of each shared memory variable, determine the local shared memory variables, global shared memory variables, and the kernel function group corresponding to each global shared memory variable;

[0007] Based on the kernel function group corresponding to each global shared memory variable, an interferogram corresponding to the global shared memory variable is generated, wherein the global shared memory variable is a node in the interferogram, and the connecting edge in the interferogram represents that the kernel function groups corresponding to two connected global shared memory variables respectively include at least one identical kernel function;

[0008] Based on the interferogram, the global shared memory variables are grouped, and the starting position and alignment information of the global shared memory variables contained in each group are determined.

[0009] The termination address of the local shared memory variable is determined based on the total size of all global shared memory variables and the size of the local shared memory variable.

[0010] A second aspect of this disclosure provides an address allocation device for shared memory variables, comprising:

[0011] The first determination module is used to determine the local shared memory variables, the global shared memory variables, and the kernel function group corresponding to each global shared memory variable based on the call information of each shared memory variable;

[0012] The generation module is used to generate an interferogram corresponding to each global shared memory variable based on the kernel function group corresponding to each global shared memory variable, wherein the global shared memory variable is a node in the interferogram, and the connecting edge in the interferogram represents that the kernel function groups corresponding to two connected global shared memory variables respectively include at least one identical kernel function;

[0013] The second determining module is used to group the global shared memory variables based on the interferogram and determine the starting position and alignment information of the global shared memory variables contained in each group.

[0014] The third determining module is used to determine the termination address of the local shared memory variable based on the total size of all global shared memory variables and the size of the local shared memory variable.

[0015] A third aspect of this disclosure provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements the address allocation method for shared memory variables as proposed in the first aspect of this disclosure.

[0016] A fourth aspect of this disclosure provides a chip including a processing circuit and an interface circuit; wherein the interface circuit is used to acquire instructions and send the instructions to the processing circuit, and the processing circuit is used to execute the instructions to implement the address allocation method for shared memory variables proposed in the first aspect of this disclosure.

[0017] A fifth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the address allocation method for shared memory variables as proposed in a first aspect of this disclosure.

[0018] The address allocation method, apparatus, electronic device, and storage medium for shared memory variables disclosed herein contain the following:

[0019] Beneficial effects:

[0020] In this embodiment, all shared memory variables are first classified into local shared memory variables and global shared memory variables. Then, based on the kernel function groups corresponding to the global shared memory variables, the global shared memory variables are grouped, and the starting position and alignment information of each group in memory space are determined to complete the address allocation of the global shared memory variables. Afterwards, based on the total size of the global shared memory variables after group alignment and the size of the local shared memory variables, the ending address of the local shared memory variables is determined to complete the address allocation of the local shared memory variables. This optimizes the address allocation of global shared memory variables, effectively reduces address allocation redundancy, and reduces memory space consumption.

[0021] Additional aspects and advantages of this disclosure will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this disclosure. Attached Figure Description

[0022] The above and / or additional aspects and advantages of this disclosure will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, in which:

[0023] Figure 1 This is a flowchart illustrating a method for allocating the address of a shared memory variable according to an embodiment of this disclosure.

[0024] Figure 2 This is a schematic diagram of an interference pattern provided in an embodiment of this disclosure;

[0025] Figure 3 This is a schematic diagram of an address allocation result provided in an embodiment of this disclosure;

[0026] Figure 4a This is a schematic diagram illustrating a kernel function calling a device-side function and the device-side function referencing shared memory variables, as proposed in an embodiment of this disclosure.

[0027] Figure 4b This is a schematic diagram illustrating the grouping of globally shared memory variables according to an embodiment of this disclosure;

[0028] Figure 4c This is a schematic diagram of the allocation results corresponding to the address allocation method proposed in this disclosure;

[0029] Figure 4d This is a schematic diagram of the allocation results corresponding to the existing address allocation methods;

[0030] Figure 5 This is a flowchart illustrating a method for allocating the address of a shared memory variable according to another embodiment of this disclosure;

[0031] Figure 6 A flowchart illustrating the classification of shared memory variables provided in this embodiment of the disclosure;

[0032] Figure 7 A flowchart illustrating a method for allocating the address of a shared memory variable, as provided in another embodiment of this disclosure;

[0033] Figure 8 This is a schematic diagram of the structure of an address allocation device for shared memory variables provided in an embodiment of this disclosure;

[0034] Figure 9 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown;

[0035] Figure 10 This is a schematic diagram of the structure of a chip proposed in an embodiment of this disclosure. Detailed Implementation

[0036] Embodiments of this disclosure are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this disclosure, and should not be construed as limiting this disclosure.

[0037] The following description, with reference to the accompanying drawings, outlines a method, apparatus, electronic device, and storage medium for allocating the address of shared memory variables according to embodiments of the present disclosure.

[0038] In related technologies, the shared memory compiler allocates the addresses of shared memory variables within kernel functions by collecting shared memory variables that will be called by multiple kernel functions, sorting them using an optimization algorithm to obtain the most compact address allocation possible, and then performing the same address allocation within each kernel function. While this method solves the problem of address consistency for the same shared memory variable across different kernel functions, there may be cases where some kernel functions do not use certain shared memory variables. In such cases, allocating a separate address for all global shared memory variables would lead to address redundancy and increase the consumption of shared memory space.

[0039] Therefore, in this disclosure, shared memory variables can be classified and grouped according to their calling behavior in different kernel functions before address allocation, so that some shared memory variables can reuse the same address, thereby optimizing the space allocation of shared memory variables and reducing space consumption.

[0040] Figure 1 This is a flowchart illustrating a method for allocating the address of a shared memory variable according to an embodiment of this disclosure.

[0041] It should be noted that the shared memory variable address allocation method of the present disclosure embodiments can be applied to a shared memory variable address allocation device. In some possible embodiments, the device can be configured in an electronic device or chip so that the electronic device or chip can perform the function of allocating addresses to shared memory variables.

[0042] like Figure 1 As shown, the method for allocating the address of this shared memory variable may include the following steps:

[0043] Step 101: Based on the call information of each shared memory variable, determine the local shared memory variable, the global shared memory variable, and the kernel function group corresponding to each global shared memory variable.

[0044] Understandably, the entry point function of a heterogeneous device program typically consists of one or more called device-side functions (func). This entry point function, often called a kernel function, is responsible for executing parallel computing tasks on the device side. Multiple parallel threads within a device block can access shared memory through a unified kernel function. Since the kernel function serves as the entry point for all programs, it benefits from the hardware resource allocation of the thread block. Therefore, within a parallel programming kernel function, shared memory variables can be declared to indicate that when the program uses these variables, it needs to read from or write to shared memory.

[0045] It should be noted that shared memory variables can be accessed in two ways: one is by directly declaring the shared memory variable in a kernel function, allowing the kernel function to directly access it; the other is by declaring the shared memory variable in a regular device-side function, and then the kernel function accesses the shared memory variable by calling the regular device-side function. Therefore, the access information for each shared memory variable can include at least one of the following: a direct call to one or more kernel functions of the shared memory variable, a call to the device-side function of the shared memory variable, and one or more kernel functions that call the device-side function. In this embodiment, the compiler can be used to collect all shared memory variables in the heterogeneous device-side program, analyze the call relationships between these shared memory variables and their respective functions and kernel functions, thereby determining the access information for each shared memory variable.

[0046] In this implementation, all shared memory variables can be classified based on their call information. Specifically, if a shared memory variable declaration is called by multiple kernel functions simultaneously, it can be classified as a global shared memory variable; that is, a global shared memory variable can be used to indicate a variable called by multiple kernel functions. Conversely, if a shared memory variable declaration is called by only a single kernel function, it can be classified as a local shared memory variable; that is, a local shared memory variable can be used to indicate a variable called by a single kernel function. This allows for the classification of all shared memory variables, the identification of local and global shared memory variables, and the formation of a kernel function group corresponding to each global shared memory variable by including all kernel functions called by that global shared memory variable.

[0047] For example, in a heterogeneous device program, all shared memory variables include shared memory variable A, shared memory variable B, and shared memory variable C. Shared memory variables A and C are both called by kernel functions kernel0 and kernel1 simultaneously, while shared memory variable B is only called by kernel1. Therefore, shared memory variables A and C are global shared memory variables, and shared memory variable B is a local shared memory variable.

[0048] Step 102: Generate an interferogram corresponding to each global shared memory variable based on the kernel function group corresponding to each global shared memory variable.

[0049] In this embodiment of the disclosure, the interference graph corresponding to the global shared memory variables is used to characterize whether the global shared memory variables correspond to the same kernel function. The global shared memory variables are nodes in the interference graph, and the connecting edges in the interference graph indicate that the kernel function groups corresponding to two connected global shared memory variables each include at least one of the same kernel functions.

[0050] In this embodiment of the disclosure, each global shared memory variable can be treated as a node in the interferogram. Then, based on the same kernel function in the kernel function group corresponding to each pair of global shared memory variables, the nodes representing the two global shared memory variables are connected in the interferogram with the kernel function as the edge, thereby generating the interferogram corresponding to the global shared memory variables.

[0051] The following is based on Figure 2 The generation of interferograms will be explained using an example. Figure 2 This is a schematic diagram of an interference pattern provided in an embodiment of this disclosure.

[0052] The kernel function group corresponding to global shared memory variable A contains kernel0 and kernel1, and the kernel function group corresponding to global shared memory variable C contains kernel0, kernel1, and kernel2. Therefore, in the interferogram, global shared memory variables A and C can each be represented as a node. Since the kernel function groups corresponding to the two global shared memory variables contain two identical kernel functions, kernel0 and kernel1, two edges can be connected between the two nodes corresponding to global shared memory variables A and C, representing kernel0 and kernel1 respectively, thus generating the interferogram. Figure 2 As shown.

[0053] It should be noted that, in Figure 2 The text only provides an illustrative explanation of how to generate an interferogram containing two nodes, and does not cover the entire process. Figure 2 As a limitation of this disclosure, the interferometric diagram may contain a greater number of nodes, and the connection edges between these nodes are determined in the same way as described above.

[0054] Understandably, between any two nodes in the interferogram, there may be one or more connecting edges, indicating that the global shared memory variables corresponding to these two nodes are called by one or more identical kernel functions. Alternatively, there may be no connecting edges, indicating that the global shared memory variables corresponding to these two nodes are not called by the same kernel function.

[0055] Step 103: Based on the interferogram, group the global shared memory variables and determine the starting position and alignment information of the global shared memory variables contained in each group.

[0056] It should be noted that when two global shared memory variables are called by the same kernel function, it means that the use of these two global shared memory variables is interfering with each other and they cannot be allocated the same address. Therefore, when allocating addresses by group, these two global shared memory variables should be allocated to different groups.

[0057] In this embodiment of the disclosure, the connection between nodes in the interference diagram can be used to determine whether any two global shared memory variables are mutually interfering. Global shared memory variables that interfere with each other are assigned to different groups, while global shared memory variables that do not interfere with each other are assigned to the same group. This allows for the grouping of all global shared memory variables, enabling the reuse of address allocations within the same group and saving shared memory space overall.

[0058] It should be noted that, in the embodiments of this disclosure, a graph coloring algorithm can be used to color and group the nodes in the interferogram, and the global shared memory variables corresponding to the nodes with the same coloring can be determined as a group.

[0059] In this embodiment of the disclosure, in order to improve memory access speed, variables in the same group need to be aligned according to the boundary when allocating addresses. Therefore, the maximum value of the alignment information corresponding to all global shared memory variables in each group can be determined as the alignment information of the group based on the alignment information contained in the declaration of each shared memory variable. This ensures that after allocating addresses to the variables in the group, each variable can satisfy the boundary alignment.

[0060] In this embodiment of the disclosure, after determining the alignment information for each group, the starting position of each group can be allocated sequentially according to the descending order of the alignment information. Then, within each group, the starting position and alignment information of the group can be assigned to each global shared memory variable, ensuring that global shared memory variables within the same group reuse the allocated address.

[0061] Step 104: Determine the termination address of the local shared memory variables based on the total size of all global shared memory variables and the size of the local shared memory variables.

[0062] The total size of all global shared memory variables is the sum of the maximum memory occupied by the global shared memory variables in each group after aligning the global shared memory variables within each group.

[0063] In this embodiment, previously allocated global shared memory variables and local shared memory variables can be combined. Within each kernel function, address allocation is performed in the order of global shared memory variables first, followed by local shared memory variables. That is, global shared memory variables are allocated starting from address 0. The starting address of the local shared memory variables is the ending address of all global shared memory variables. The final address of the local shared memory variables can be obtained by adding the size of the local shared memory variables to the total size of the aligned global shared memory variables.

[0064] It should be noted that if a kernel function does not call any global shared memory variables, the address of local shared memory variables can be allocated starting from address 0.

[0065] It should be noted that, in this embodiment, local shared memory variables only need to be allocated addresses when used by kernel functions, while global shared memory variables need to be allocated the same addresses in every kernel function. This is because global shared memory variables are treated as a whole, and each kernel function must maintain an identical copy to ensure that the addresses of these global shared memory variables are consistent.

[0066] For example, if shared memory variables A and C are both called by kernel functions kernel0 and kernel1 simultaneously, while shared memory variable B is only called by kernel1, meaning shared memory variables A and C are global shared variables and shared memory variable B is a local shared variable, then the address allocation of shared memory variables A, B, and C can be as follows: Figure 3 As shown, Figure 3 This is a schematic diagram of an address allocation result.

[0067] exist Figure 3 In this diagram, `intA`, `intB`, and `intC` represent shared memory variables. Since shared memory variables are integers, according to the alignment information, the starting address of each shared memory variable should be a multiple of 4. `intA` and `intC` are both global shared memory variables and interfere with each other; therefore, they can be grouped separately and allocated an address. Based on the allocation order of global shared memory variables first, then local shared memory variables, we can determine that the starting address of `intA` is 0, and the starting address of `intC` is 4, with the same address allocated in kernel functions `kernel0` and `kernel1`. `intB` is only called by `kernel1`, so it only needs to be allocated an address in the shared memory of `kernel1`; therefore, the starting address of `intB` is 8, and the ending address is 12.

[0068] In this embodiment, all shared memory variables are first classified into local shared memory variables and global shared memory variables. Then, based on the kernel function groups corresponding to the global shared memory variables, the global shared memory variables are grouped, and the starting position and alignment information of each group in memory space are determined to complete the address allocation of the global shared memory variables. Afterwards, based on the total size of the global shared memory variables after group alignment and the size of the local shared memory variables, the ending address of the local shared memory variables is determined to complete the address allocation of the local shared memory variables. This optimizes the address allocation of global shared memory variables, effectively reduces address allocation redundancy, and reduces memory space consumption.

[0069] The following description, with reference to Figure 4, provides an exemplary illustration of the shared memory variable classification, global shared memory variable grouping, and address allocation proposed in the embodiments of this disclosure.

[0070] First, the shared memory variables include a, b, c, d, and e. The calling information for each shared memory variable is as follows: Figure 4a As shown, Figure 4a This is a diagram illustrating kernel function calls to device-side functions and how device-side functions reference shared memory variables. Figure 4aIt can be seen that the device-side function `func1` declares the shared memory variable `a`, the device-side function `func2` declares the shared memory variable `b`, the device-side function `func3` declares the shared memory variable `c`, the device-side function `func4` declares the shared memory variable `d`, and the device-side function `func5` declares the shared memory variable `e`. Furthermore, the kernel function `kernel1` calls `func1`, the kernel function `kernel2` calls `func1`, `func4`, and `func5`, the kernel functions `kernel3` and `kernel4` both call `func1`, `func2`, and `func3`, and the kernel function `kernel5` calls `func2` and `func4`.

[0071] Since the device-side functions referencing shared memory variables a, b, c, d, and e are all called by two or more kernel functions, it can be determined that shared memory variables a, b, c, d, and e are all global shared memory variables. Furthermore, in Figure 4a As can be seen from this, func3 and func4 are not used on the same kernel. The global shared memory variables c and d do not interfere with each other in address allocation, so c and d can be grouped together. Similarly, func3 and func5 are not used on the same kernel, and func2 and func5 are also not used on the same kernel. c and e or b and e can also be grouped together.

[0072] It should be noted that c and d can be a group, and c and e can also be a group, but d and e cannot be a group. In this disclosure, the grouping order can be determined. That is, when it is determined that c and d can be a group, c and d are directly grouped together. If it is subsequently determined that c and e can be a group, then it is determined whether e and d can be a group. If they cannot be grouped, e is placed in another group.

[0073] Since the device-side function `func1` corresponding to the global shared memory variable `a` shares the same kernel function call with any other device-side function, the global shared memory variable `a` can be grouped separately. The grouping of global shared memory variables is as follows: Figure 4b As shown, the global shared memory variables a, b, c, d, and e can be divided into three groups: the first group (group1) contains global shared memory variable a, the second group (group2) contains global shared memory variables b and e, and the third group (group3) contains global shared memory variables c and d.

[0074] Then, the maximum value can be taken from the size and alignment information of the global shared memory variables within each group to obtain the size corresponding to each group (i.e., Figure 4b The value corresponding to size) and alignment information (i.e. Figure 4bThe value corresponding to `align`). If all variables within each group are integers (int), meaning the size is 4 bytes, and the alignment information is based on 4-byte boundaries, then the size and alignment information for each group are both 4. Figure 4b As shown, the starting position of each group can be determined sequentially to complete the address allocation of the global shared memory variables. The allocation result is as follows: Figure 4c As shown.

[0075] It should be noted that, Figure 4c This diagram illustrates the address allocation results corresponding to the address allocation method proposed in this disclosure. Figure 4d Compared to the existing diagrams illustrating the allocation results after address allocation for shared memory variables, the address allocation scheme of this disclosure allows shared memory variables to share address allocation, resulting in a reduction of 8 bytes in shared memory usage per kernel in the final address layout. Therefore, this demonstrates that the address allocation method proposed in this disclosure can effectively save memory space and improve address allocation performance.

[0076] Figure 5 This is a flowchart illustrating a method for allocating the address of a shared memory variable according to an embodiment of this disclosure, as shown below. Figure 5 As shown, the method for allocating the address of this shared memory variable may include the following steps:

[0077] Step 501: Based on the call information of each shared memory variable, determine the local shared memory variable, the global shared memory variable, and the kernel function group corresponding to each global shared memory variable.

[0078] In this embodiment of the disclosure, shared memory variables can be directly called by kernel functions, or kernel functions can call shared memory variables by calling device-side functions that reference shared memory variables. Therefore, when classifying shared memory variables into two categories based on the call information of each shared memory variable, at least one of the following can be included:

[0079] Optionally, the call information of each shared memory variable can be traversed, and if any shared memory variable is called by only one kernel function, then that shared memory variable can be determined to be a local shared memory variable.

[0080] Alternatively, we can iterate through the call information of each shared memory variable, and determine that any shared memory variable is a local shared memory variable if no shared memory variable is called by any kernel function and the function containing that shared memory variable is called by only one kernel function.

[0081] The following combination Figure 5 The classification of shared memory variables is explained. Figure 5This is a flowchart illustrating a shared memory variable classification method provided in this disclosure.

[0082] Depend on Figure 5 Therefore, for shared memory variables to be categorized, we can first determine whether the reference (or call) of the variable occurs only within a single kernel function. If it is determined that the variable is only called within a single kernel function, then the variable is classified as a local shared memory variable. Otherwise, we further determine whether the function referenced by the variable is called by a single kernel function. If it is called by a single kernel function, then the variable can be classified as a local shared memory variable; otherwise, the variable is classified as a global shared memory variable.

[0083] In this embodiment of the disclosure, the classification of shared memory variables is determined by judging the shared memory variables and the calls of the kernel function to the function containing the shared memory variables. This ensures the accuracy and reliability of the classification results of shared memory variables and provides a reliable data foundation for subsequent address allocation.

[0084] Step 502: Generate an interferogram corresponding to each global shared memory variable based on the kernel function group corresponding to each global shared memory variable.

[0085] For a detailed description of steps 501 and 502 above, please refer to other embodiments of this disclosure, which will not be repeated here.

[0086] Step 503: Group the global shared memory variables in the interference diagram that do not have connecting edges.

[0087] In this embodiment of the disclosure, in the interference graph, global shared memory variables that do not have connecting edges can be determined to be global shared memory variables whose use will not interfere with each other and can be allocated the same address. Therefore, these global shared memory variables can be identified as a group to reuse the same address.

[0088] It should be noted that because the interferogram is generated based on global shared memory variables, each global shared memory variable in the interferogram has at least one connecting edge. When any global shared memory variable has connecting edges with all other global shared memory variables in the interferogram, that global shared memory variable can be considered as a group. In this disclosure, all global shared memory variables can be divided into one or more groups.

[0089] For example, if there are global shared memory variables A, B, C, D, and E, and in the interferogram, A is connected to B, C, D, and E, while B and E are not connected, and C and D are not connected, then A can be identified as one group, B and E as one group, and C and D as one group.

[0090] Step 504: Determine the alignment information corresponding to each group based on the alignment information corresponding to each global shared memory variable contained in each group.

[0091] In this embodiment of the disclosure, the heterogeneous device program can determine the alignment information corresponding to each global shared memory variable in each group by examining the alignment information contained in the declaration of each shared memory variable. Then, the alignment information corresponding to all global shared memory variables in the group can be sorted to determine the alignment information corresponding to the group.

[0092] Optionally, the maximum value among the alignment information corresponding to all global shared memory variables within each group can be determined as the alignment information for that group. This ensures that the alignment information for each group satisfies the alignment information corresponding to all global shared memory variables within the group, thereby ensuring correct data alignment and efficient access in memory, as well as data integrity and optimizing memory layout.

[0093] Step 505: Determine the starting position of each group based on the alignment information corresponding to each group.

[0094] In this embodiment of the disclosure, the starting position of each group can be determined sequentially according to the alignment information corresponding to each group in descending order.

[0095] Optionally, the starting position of the shared memory can be determined as the starting position of the group with the largest value in the corresponding alignment information.

[0096] In this embodiment of the disclosure, in order to optimize memory layout and access efficiency and reduce the complexity of memory allocation and management, the starting position of each group can be allocated in descending order of alignment information. Therefore, the starting position of the shared memory (marked as 0) can be determined as the starting position of the group with the largest value in the corresponding alignment information.

[0097] Then, the remaining groups can be sorted in descending order of alignment information, and the starting position of each group in the remaining groups can be determined in turn.

[0098] In this embodiment, the remaining groups can be sorted in descending order of alignment information according to the rules that the starting position of each group in memory must meet (such as an integer multiple of a fixed value (such as 2, 4, 8, etc.) specified by the alignment information of each group), and the starting position of each group in the remaining groups can be determined sequentially. This can improve the orderliness of address allocation, make the address allocation result more reliable, and avoid memory allocation failure.

[0099] Step 506: Determine the alignment information and starting position corresponding to each group as the alignment information and starting position corresponding to the global shared memory variables contained in that group.

[0100] In this embodiment of the disclosure, since all global shared memory variables within the same group reuse the same address, the alignment information and starting position corresponding to each group can be determined as the alignment information and starting position corresponding to the global shared memory variables contained in that group.

[0101] Step 507: Determine the termination address of the local shared memory variables based on the total size of all global shared memory variables and the size of the local shared memory variables.

[0102] For a detailed description of step 507 above, please refer to other embodiments of this disclosure, which will not be repeated here.

[0103] In this embodiment, the alignment information for each group is determined based on the alignment information corresponding to the global shared memory variables. Then, the starting position of each group is determined sequentially according to the size of the alignment information. Finally, the alignment information and starting position of each group are used to unify the alignment information and starting position of all shared memory variables within that group. This improves the reliability and accuracy of address allocation results, ensures that all global shared memory variables within the same group can reuse the same address, and thus improves memory space utilization.

[0104] Figure 7 This is a flowchart illustrating a method for allocating the address of a shared memory variable according to an embodiment of this disclosure, as shown below. Figure 7 As shown, the method for allocating the address of this shared memory variable may include the following steps:

[0105] Step 701: Based on the call information of each shared memory variable, determine the local shared memory variable, the global shared memory variable, and the kernel function group corresponding to each global shared memory variable.

[0106] Step 702: Generate an interferogram corresponding to each global shared memory variable based on the kernel function group corresponding to each global shared memory variable.

[0107] Step 703: Based on the interferogram, group the global shared memory variables and determine the starting position and alignment information of the global shared memory variables contained in each group.

[0108] For a detailed description of steps 701 to 703 above, please refer to other embodiments of this disclosure, which will not be repeated here.

[0109] Step 704: When there are multiple local shared memory variables, obtain the alignment information, size, and initial order of appearance of the multiple local shared memory variables.

[0110] In this embodiment of the disclosure, for local shared memory variables, address allocation can be performed on these variables separately within the kernel function that calls them. Therefore, when there are multiple local shared memory variables, it is necessary to consider the address allocation order of these local shared memory variables to ensure optimal address allocation and save memory space as much as possible. Thus, the alignment information, size, and initial appearance order of multiple local shared memory variables can be obtained.

[0111] Step 705: Based on the alignment information, size, and initial order of occurrence of multiple local shared memory variables, sort the multiple local shared memory variables and determine the starting position of each local shared memory variable.

[0112] In this embodiment of the disclosure, a structure element optimization sorting algorithm can be used to sort multiple local shared memory variables by combining the alignment information, size, and priority of the initial appearance order of multiple local shared memory variables.

[0113] Optionally, multiple local shared memory variables can be first sorted in descending order of alignment information. Then, if any two local shared memory variables have the same alignment information, they can be sorted in descending order of size. Afterward, if any two local shared memory variables have the same size, they can be sorted in their initial order of appearance, until the starting positions of all local shared memory variables are determined. This improves the orderliness of address allocation for local shared memory variables, optimizes address allocation, and helps save memory space.

[0114] It's important to note that after determining the starting positions of all locally shared memory variables, it's possible to check for gaps in the allocated addresses. Gaps occupy memory space, preventing its efficient use and leading to wasted memory resources and reduced access efficiency. Therefore, if no gaps exist, the allocation of locally shared memory variables can be terminated. Otherwise, if gaps exist, methods such as greedy algorithms are needed to minimize them.

[0115] Optionally, when there are gaps between multiple local shared memory variables, the local shared memory variable with the largest alignment information and the largest size can be determined as the first local shared memory variable.

[0116] Then, based on the alignment information and size of the remaining local shared memory variables, the remaining local shared memory variables can be traversed until a second local shared memory variable with no gap between it and the first local shared memory variable is determined.

[0117] In this embodiment of the disclosure, the traversal can be performed in reverse order of the alignment information and size of the remaining local shared memory variables, and it can be determined in turn whether there is a gap between each local shared memory variable and the first local shared memory variable determined above. When it is determined that there is no gap between a certain local shared memory variable and the first local shared memory variable, the local shared memory variable can be directly determined as the second local shared memory variable, and the traversal ends.

[0118] It should be noted that after traversing the remaining local shared memory variables, there might be a gap between each remaining local shared memory variable and the first local shared memory variable. In this case, the local shared memory variable with the smallest gap can be determined as the second local shared memory variable. Alternatively, if the gaps between all remaining local shared memory variables and the first local shared memory variable are the same, then the remaining local shared memory variable with the largest alignment information and size can be taken as the second local shared memory variable.

[0119] Then, return to perform operations on the remaining local shared memory variables based on their alignment information and size, traversing the remaining local shared memory variables until the order of all local shared memory variables is determined.

[0120] It is understandable that each time the next local shared memory variable is determined, the traversal is completed during the calculation gap between the previous and the last local shared memory variable determined.

[0121] Therefore, after determining the order of all local shared memory variables, the starting position of each local shared memory variable can be re-determined based on the order of all local shared memory variables and the alignment information of each local shared memory variable. This makes the addresses allocated to multiple local shared memory variables as close as possible, reduces the analysis between addresses, further optimizes the address allocation effect, and saves memory space.

[0122] Step 706: Determine the termination address of the local shared memory variables based on the total size of all global shared memory variables and the size of the local shared memory variables.

[0123] For a detailed description of step 706 above, please refer to other embodiments of this disclosure, which will not be repeated here.

[0124] In this embodiment, multiple local shared memory variables are sorted based on their alignment information, size, and initial order of appearance, and addresses are allocated sequentially in that order. This reduces gaps between the addresses allocated to local shared memory variables, saves memory space, and optimizes the address allocation effect.

[0125] To implement the above embodiments, this disclosure also proposes an address allocation device for shared memory variables.

[0126] Figure 8 This is a schematic diagram of the structure of the address allocation device for shared memory variables provided in an embodiment of this disclosure.

[0127] like Figure 8 As shown, the address allocation device 800 for the shared memory variable may include:

[0128] The first determining module 801 is used to determine the local shared memory variable, the global shared memory variable, and the kernel function group corresponding to each global shared memory variable based on the calling information of each shared memory variable;

[0129] The generation module 802 is used to generate an interferogram corresponding to each global shared memory variable based on the kernel function group corresponding to each global shared memory variable. The global shared memory variable is a node in the interferogram, and the connecting edge in the interferogram represents that the kernel function groups corresponding to two connected global shared memory variables contain at least one identical kernel function.

[0130] The second determining module 803 is used to group the global shared memory variables based on the interferogram and determine the starting position and alignment information of the global shared memory variables contained in each group.

[0131] The third determining module 804 is used to determine the termination address of the local shared memory variable based on the total size of all global shared memory variables and the size of the local shared memory variable.

[0132] In some possible embodiments, the first determining module 801 may specifically be used for at least one of the following:

[0133] Iterate through the call information of each shared memory variable, and if any shared memory variable is called by only one kernel function, determine that any shared memory variable is a local shared memory variable;

[0134] Iterate through the call information of each shared memory variable. If any shared memory variable is not called by any kernel function and the function containing that shared memory variable is called by only one kernel function, then determine that any shared memory variable as a local shared memory variable.

[0135] In some possible embodiments, the second determining module 803 may specifically be used for:

[0136] Global shared memory variables in the interferogram that do not have connecting edges are grouped together;

[0137] The alignment information for each group is determined based on the alignment information corresponding to each global shared memory variable contained within each group.

[0138] Based on the alignment information corresponding to each group, determine the starting position of each group;

[0139] The alignment information and starting position corresponding to each group are determined as the alignment information and starting position corresponding to the global shared memory variables contained in that group.

[0140] In some possible embodiments, the second determining module 803 may specifically be used for:

[0141] The maximum value among the alignment information corresponding to all global shared memory variables contained in each group is determined as the alignment information corresponding to that group.

[0142] In some possible embodiments, the second determining module 803 may specifically be used for:

[0143] The starting position of the shared memory is determined as the starting position of the group with the largest value in the corresponding alignment information;

[0144] Sort the remaining groups in descending order of alignment information, and determine the starting position of each group in the remaining groups in turn.

[0145] In some possible embodiments, the third determining module 804 may also be used for:

[0146] When there are multiple local shared memory variables, obtain the alignment information, size, and initial order of appearance of the multiple local shared memory variables;

[0147] Based on the alignment information, size, and initial order of occurrence of multiple local shared memory variables, the multiple local shared memory variables are sorted, and the starting position of each local shared memory variable is determined.

[0148] In some possible embodiments, the third determining module 804 may specifically be used for:

[0149] Sort the multiple local shared memory variables in descending order of their alignment information.

[0150] If any two local shared memory variables have the same alignment information, sort the two local shared memory variables in descending order of size.

[0151] If any two local shared memory variables have the same size, sort the two local shared memory variables according to their initial order of appearance until the starting position of each local shared memory variable is determined.

[0152] In some possible embodiments, the third determining module 804 may also be used for:

[0153] In the case of gaps between multiple local shared memory variables, the local shared memory variable with the largest alignment information and the largest size is determined as the first local shared memory variable;

[0154] Based on the alignment information and size of the remaining local shared memory variables, traverse the remaining local shared memory variables until a second local shared memory variable with no gap between it and the first local shared memory variable is determined.

[0155] Returns to the operation performed based on the alignment information and size of the remaining local shared memory variables, traversing the remaining local shared memory variables until the order of all local shared memory variables is determined;

[0156] Based on the order of all local shared memory variables and the alignment information of each local shared memory variable, the starting position corresponding to each local shared memory variable is re-determined.

[0157] The functions and specific implementation principles of the modules described in this embodiment can be found in the above method embodiments, and will not be repeated here.

[0158] The address allocation device for shared memory variables in this embodiment first classifies all shared memory variables into local shared memory variables and global shared memory variables. Then, based on the kernel function group corresponding to the global shared memory variables, it groups the global shared memory variables, determines the starting position and alignment information of each group in memory space, and completes the address allocation for the global shared memory variables. Afterwards, based on the total size of the aligned global shared memory variables and the size of the local shared memory variables, it determines the ending address of the local shared memory variables to complete the address allocation for the local shared memory variables. This optimizes the address allocation of global shared memory variables, effectively reduces address allocation redundancy, and reduces memory space consumption.

[0159] To implement the above embodiments, this disclosure also proposes an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the address allocation method for shared memory variables as proposed in the foregoing embodiments of this disclosure.

[0160] Figure 9 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown. Figure 9 The electronic device 12 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments disclosed herein.

[0161] like Figure 9As shown, the electronic device 12 is represented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting different system components (including system memory 28 and processing unit 16).

[0162] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. Examples of these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0163] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0164] Memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and / or cache memory 32. Electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (… Figure 9 Not shown; usually referred to as a "hard drive"). Although Figure 9Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disc drive for reading and writing to a removable non-volatile optical disc (e.g., a compact disc read-only memory (CD-ROM), a digital video disc read-only memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this disclosure.

[0165] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of this disclosure.

[0166] Electronic device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with electronic device 12, and / or with any device that enables electronic device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 22. Furthermore, electronic device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with other modules of electronic device 12 via bus 18. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0167] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the methods mentioned in the foregoing embodiments.

[0168] To implement the above embodiments, this disclosure also proposes a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the address allocation method for shared memory variables as proposed in the foregoing embodiments of this disclosure.

[0169] To implement the above embodiments, this disclosure also proposes a chip, which includes a processing circuit and an interface circuit; wherein the interface circuit is used to acquire instructions and send the instructions to the processing circuit, and the processing circuit is used to execute the instructions to implement the address allocation method for shared memory variables as proposed in the foregoing embodiments of this disclosure.

[0170] Figure 10 This is a schematic diagram of the chip structure proposed in an embodiment of this disclosure. See also... Figure 10 The diagram shown is a schematic representation of the structure of chip 1000, but it is not limited to this.

[0171] Chip 1000 includes processing circuit 1001, which is configured to perform any of the above methods.

[0172] In some embodiments, the chip 1000 further includes one or more interface circuits 1002. Optionally, the interface circuit 1002 is connected to the memory 1003, and the interface circuit 1002 can be used to receive signals from the memory 1003 or other devices, and the interface circuit 1002 can be used to send signals to the memory 1003 or other devices. For example, the interface circuit 1002 can read instructions stored in the memory 1003 and send the instructions to the processing circuit 1001.

[0173] In some embodiments, the interface circuit 1002 performs at least one of the communication steps such as sending and / or receiving in the above method, and the processing circuit 1001 performs other steps.

[0174] In some embodiments, the terms interface circuit, interface, transceiver pin, transceiver, etc., can be used interchangeably.

[0175] In some embodiments, chip 1000 further includes one or more memories 1003 for storing instructions. Optionally, all or part of the memories 1003 may be located outside of chip 1000.

[0176] The technical solution disclosed herein can classify and group shared memory variables according to their calling behavior in different kernel functions, and then allocate addresses accordingly. This allows some shared memory variables to reuse the same address, optimizes the space allocation of shared memory variables, and reduces space consumption.

[0177] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this disclosure. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0178] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this disclosure, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0179] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing custom logic functions or processes, and the scope of preferred embodiments of this disclosure includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of this disclosure pertain.

[0180] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.

[0181] It should be understood that various parts of this disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0182] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0183] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.

[0184] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of the present disclosure have been shown and described above, it is to be understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present disclosure.

Claims

1. A method for allocating addresses for shared memory variables, characterized in that, include: Based on the call information of each shared memory variable, determine the local shared memory variables, global shared memory variables, and the kernel function group corresponding to each global shared memory variable; Based on the kernel function group corresponding to each global shared memory variable, an interferogram corresponding to the global shared memory variable is generated, wherein the global shared memory variable is a node in the interferogram, and the connecting edge in the interferogram represents that the kernel function groups corresponding to two connected global shared memory variables respectively include at least one identical kernel function; Based on the interferogram, the global shared memory variables are grouped, and the starting position and alignment information of the global shared memory variables contained in each group are determined. The termination address of the local shared memory variable is determined based on the total size of all global shared memory variables and the size of the local shared memory variable.

2. The method as described in claim 1, characterized in that, The step of determining local shared memory variables, global shared memory variables, and the kernel function group corresponding to each global shared memory variable based on the call information of each shared memory variable includes at least one of the following: Iterate through the call information of each shared memory variable, and if any shared memory variable is called by only one kernel function, determine that any shared memory variable is a local shared memory variable; Iterate through the call information of each shared memory variable. If any shared memory variable is not called by any kernel function and the function containing the shared memory variable is called by only one kernel function, then the shared memory variable is determined to be a local shared memory variable.

3. The method as described in claim 1, characterized in that, Based on the interferogram, the global shared memory variables are grouped, and the starting position and alignment information of the global shared memory variables in each group are determined, including: The global shared memory variables in the interference graph that do not have connecting edges are grouped together. The alignment information for each group is determined based on the alignment information corresponding to each global shared memory variable contained within each group. Based on the alignment information corresponding to each group, determine the starting position of each group; The alignment information and starting position corresponding to each group are determined as the alignment information and starting position corresponding to the global shared memory variables contained in that group.

4. The method as described in claim 3, characterized in that, The step of determining the alignment information corresponding to a group based on the alignment information corresponding to each global shared memory variable contained in each group includes: The maximum value among the alignment information corresponding to all global shared memory variables contained in each group is determined as the alignment information corresponding to that group.

5. The method as described in claim 3, characterized in that, The step of determining the starting position for each group based on the alignment information corresponding to each group includes: The starting position of the shared memory is determined as the starting position of the group with the largest value in the corresponding alignment information; Sort the remaining groups in descending order of alignment information, and determine the starting position of each group in the remaining groups in turn.

6. The method according to any one of claims 1-5, characterized in that, Before determining the termination address of the local shared memory variable based on the total size of all global shared memory variables and the size of the local shared memory variable, the method further includes: When there are multiple local shared memory variables, obtain the alignment information, size, and initial order of appearance of the multiple local shared memory variables; Based on the alignment information, size, and initial order of occurrence of the plurality of local shared memory variables, the plurality of local shared memory variables are sorted, and the starting position of each local shared memory variable is determined.

7. The method as described in claim 6, characterized in that, The step of sorting the multiple local shared memory variables based on their alignment information, size, and initial order of appearance, and determining the starting position of each local shared memory variable, includes: The multiple local shared memory variables are sorted in descending order according to their alignment information. If any two local shared memory variables have the same alignment information, sort the two local shared memory variables in descending order of size. If any two local shared memory variables have the same size, sort the two local shared memory variables according to their initial order of appearance until the starting positions of all local shared memory variables are determined.

8. The method as described in claim 7, characterized in that, After determining the starting positions corresponding to all local shared memory variables, the process further includes: In the case of gaps between the multiple local shared memory variables, the local shared memory variable with the largest alignment information and the largest size is determined as the first local shared memory variable; Based on the alignment information and size of the remaining local shared memory variables, the remaining local shared memory variables are traversed until a second local shared memory variable with no gap between it and the first local shared memory variable is determined. Return to the operation based on the alignment information and size of the remaining local shared memory variables, traverse the remaining local shared memory variables, until the order of all local shared memory variables is determined; Based on the order of all the local shared memory variables and the alignment information of each local shared memory variable, the starting position corresponding to each local shared memory variable is re-determined.

9. A device for allocating addresses for shared memory variables, characterized in that, The device includes: The first determination module is used to determine the local shared memory variables, the global shared memory variables, and the kernel function group corresponding to each global shared memory variable based on the call information of each shared memory variable; The generation module is used to generate an interferogram corresponding to each global shared memory variable based on the kernel function group corresponding to each global shared memory variable, wherein the global shared memory variable is a node in the interferogram, and the connecting edge in the interferogram represents that the kernel function groups corresponding to two connected global shared memory variables respectively include at least one identical kernel function; The second determining module is used to group the global shared memory variables based on the interferogram and determine the starting position and alignment information of the global shared memory variables contained in each group. The third determining module is used to determine the termination address of the local shared memory variable based on the total size of all global shared memory variables and the size of the local shared memory variable.

10. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements the address allocation method for shared memory variables as described in any one of claims 1-8.

11. A chip, characterized in that, The chip includes a processing circuit and an interface circuit; wherein the interface circuit is used to acquire instructions and send the instructions to the processing circuit, and the processing circuit is used to execute the instructions to implement the address allocation method for shared memory variables as described in any one of claims 1-8.

12. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the address allocation method for shared memory variables as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Memory sharing method and related device

    CN116560878A

  • Sample component analysis method and system, storage medium and computer

    CN117473233A