Data segmentation method, device, electronic device, storage medium and program product

By loading preset-size data blocks at one time and storing and reusing effective data blocks in shared memory, the performance problems caused by a large number of Load instructions and frequent global memory access in Strided Slice operations are solved, and more efficient data splitting is achieved.

CN119781978APending Publication Date: 2025-04-08北京壁仞科技开发有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411944515.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

When implementing Strided Slice operations, the prior art relies on a large number of Load instructions and frequent global memory access, resulting in poor performance of data segmentation operators.

Method used

By loading the preset sized data blocks into the TLR at one time, determining the valid data blocks based on the slicing step size, storing them into shared memory until the effective data block size stored in shared memory reaches the preset size, then moving them into global memory.

Benefits of technology

It greatly reduces the number of data loading instructions, reduces the number of accesses to global memory, and improves the performance of data segmentation operators.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781978A_ABST
    Figure CN119781978A_ABST
Patent Text Reader

Abstract

The present invention relates to the field of data processing technology, and provides a data segmentation method, device, electronic device, storage medium and program product, wherein the method comprises: based on a preset size and the starting coordinates of a current data block to be loaded, loading a target data block from input data; based on the segmentation step length, determining a valid data block from the target data block and storing it in a shared memory; storing the valid data block of the preset size in the shared memory in a global memory to obtain data slices; based on the starting coordinates and the preset size, determining the starting coordinates of the next data block to be loaded, and using it as the starting coordinates of the current data block to be loaded, and continuing to load data blocks from the input data until the starting coordinates exceed the boundary of the input data. The present invention can significantly reduce the number of data loading instructions and the number of global memory accesses by loading data blocks of a preset size and fully reusing the loaded data, thereby improving the performance of a data segmentation operator.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a data segmentation method, device, electronic device, storage medium and program product. Background Art

[0002] Data slicing is a critical technology in data processing and computationally intensive applications. Data slicing allows large data sets to be divided into smaller, more manageable parts for efficient processing in a parallel computing environment. Strided Slice is a special data slicing operation that allows users to extract subsets from the original data set according to a specified stride. This operation is particularly common in deep learning, image processing, scientific computing and other fields because it can flexibly access and manipulate data to meet a variety of complex computing needs.

[0003] However, there are significant challenges in implementing Strided Slice operations. Existing implementations rely on a large number of Load instructions, which are responsible for loading data from global memory into local registers one by one. Since the access speed of global memory is much lower than the computing speed of the processor, these instructions frequently perform data loading operations, which becomes a performance bottleneck, not only incurring large overhead, but also affecting the performance of the data slicing operator. Summary of the invention

[0004] The present invention provides a data segmentation method, device, electronic device, storage medium and program product, which are used to solve the defect in the related art that data segmentation relies on a large number of data loading instructions and frequent global memory access, resulting in poor performance of the data segmentation operator.

[0005] The present invention provides a data segmentation method, comprising: Determine the starting coordinates of the data block to be loaded, and load the data block from the input data based on the preset size and the starting coordinates to obtain the target data block; Based on the segmentation step length, determining a valid data block from the target data block, and storing the valid data block in a shared memory; When the size of the valid data block stored in the shared memory reaches the preset size, storing the valid data block of the preset size in the shared memory into the global memory to obtain a data slice; Based on the starting coordinates and the preset size, the starting coordinates of the next data block to be loaded are determined, and the starting coordinates of the next data block to be loaded are used as the starting coordinates of the current data block to be loaded, and data blocks continue to be loaded from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0006] According to a data segmentation method provided by the present invention, the valid data block is stored in a shared memory, and then the method further includes: In the case that the current data block loading is the last loading in the current row direction of the input data, the remaining valid data blocks in the shared memory are stored in the global memory to obtain data slices.

[0007] According to a data segmentation method provided by the present invention, the step of determining the starting coordinates of the current data block to be loaded includes: Get the original coordinates of the data block to be loaded; Based on the preset size, the original coordinates are aligned to obtain the starting coordinates of the data block to be loaded.

[0008] According to a data segmentation method provided by the present invention, determining a valid data block from the target data block based on the segmentation step size includes: In the case where the starting coordinates are different from the original coordinates, based on the segmentation step, a valid data block is determined within the range from the original coordinates to the end coordinates of the target data block, wherein the end coordinates are determined based on the starting coordinates and the preset size; In the case where the starting coordinates are the same as the original coordinates, a valid data block is determined within the range from the starting coordinates to the ending coordinates of the target data block based on the segmentation step.

[0009] According to a data segmentation method provided by the present invention, the step of determining the coordinates of each valid data in the valid data block comprises: In the case where the starting coordinates are different from the original coordinates, determining the coordinates of each valid data based on the original coordinates and a first offset, wherein the first offset is determined based on the segmentation step, the original coordinates and the preset size; In the case that the starting coordinates are the same as the original coordinates, the coordinates of each valid data are determined based on the starting coordinates and a second offset, where the second offset is determined based on the segmentation step and the preset size.

[0010] According to a data segmentation method provided by the present invention, storing the valid data blocks of a preset size in the shared memory into the global memory, and then further comprising: The remaining valid data blocks in the shared memory are shifted to the left to be spliced ​​with the valid data blocks loaded in the next round, and the valid data blocks are stored in the shared memory in a continuous order from left to right.

[0011] According to a data segmentation method provided by the present invention, the target data block is stored in a thread local register.

[0012] The present invention also provides a data segmentation device, comprising: A loading unit, used to determine the starting coordinates of the data block to be loaded, and load the data block from the input data based on a preset size and the starting coordinates to obtain a target data block; A segmentation unit, configured to determine a valid data block from the target data block based on a segmentation step length, and store the valid data block in a shared memory; A storage unit, configured to store the valid data blocks of the preset size in the shared memory into a global memory to obtain data slices when the size of the valid data blocks stored in the shared memory reaches the preset size; A loop unit is used to determine the starting coordinates of the next data block to be loaded based on the starting coordinates and the preset size, and use the starting coordinates of the next data block to be loaded as the starting coordinates of the current data block to be loaded, and continue to load data blocks from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0013] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, any of the data segmentation methods described above is implemented.

[0014] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data segmentation method described in any one of the above methods is implemented.

[0015] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the data segmentation methods described above.

[0016] The data segmentation method, device, electronic device, storage medium and program product provided by the present invention can load a data block of a preset size from the input data at one time based on the preset size and the starting coordinates of the current data block to be loaded, instead of loading data elements one by one, thereby greatly reducing the number of data loading instructions and improving the performance of the data segmentation operator. After the target data block is loaded, the valid data block is determined based on the segmentation step length, and is stored in the shared memory, until the size of the valid data block stored in the shared memory reaches the preset size, the valid data block of the preset size will be moved to the global memory for storage, so that not only the data segmentation operation can be realized, but also the number of accesses to the global memory can be reduced. In addition, after the valid data block of the preset size is stored in the global memory, the remaining valid data blocks in the shared memory can be reused without reloading from the input data, and the remaining valid data blocks can be spliced ​​with the valid data blocks subsequently moved to the shared memory, until the valid data blocks stored in the shared memory reach the preset size again and are stored in the global memory, this data reuse strategy can reduce the number of data loading instructions, thereby reducing the number of times data is read from the global memory, and improving the operator performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 It is a flow chart of the data segmentation method provided by the present invention; Figure 2 It is a schematic diagram of data block loading provided by the present invention; Figure 3 It is a flow chart of a data segmentation optimization method based on multiplexed input data provided by the present invention; Figure 4 It is a schematic diagram of multiplexing input data in the data segmentation process provided by the present invention; Figure 5 It is a structural schematic diagram of the data segmentation device provided by the present invention; Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0020] Strided Slice is an operation performed on multidimensional arrays (such as tensors), which allows users to slice arrays in any dimension according to the specified stride. The stride determines how many elements are moved each time to select data in each dimension of the multidimensional array. In a multidimensional array or matrix, the stride can be a vector, in which each component corresponds to the stride on the corresponding dimension. The components in the stride vector can determine how to move and select elements in each dimension of the multidimensional array. For example, in a two-dimensional matrix, the stride vector can be expressed as stride=(s1, s2), where s1 is called the row stride, which means advancing s1 elements each time in the row dimension. When the row stride s1 is 1, it means continuous access to the elements in the row; s2 is called the column stride, which means advancing s2 elements each time in the column dimension. When the column stride s2 is 1, it means continuous access to the elements in the column.

[0021] The Strided Slice operation is very common in scenarios such as deep learning and data preprocessing because it allows flexible selection and reorganization of data. When using the Strided Slice operation, the required data may not be stored continuously in the global memory due to the existence of the stride. Therefore, the Load instruction is usually used to load the required data from the global memory to the TLR (Thread-Local Register) one by one, which generates a large number of Load instructions and frequently loads data from the global memory. Here, the Load instruction refers to the instruction used to read data from the memory into the processor's register.

[0022] Global memory refers to the memory area that all threads or processors can access. For example, in a GPU (Graphics Processing Unit), global memory usually refers to the device's DRAM, which is a data storage space shared by all computing units. The access speed of global memory is relatively slow because accessing global memory requires long delays and possible data transfer bandwidth limitations. TLR (Thread-Local Register) refers to the storage area that each thread can quickly access locally.

[0023] Since the access speed of global memory is much lower than the computing speed of the processor, this frequent data loading operation has become a performance bottleneck. Whenever a new data element needs to be accessed, the processor must issue a Load instruction, wait for the data to be loaded from the global memory to the TLR, then calculate the location where the currently loaded data should be stored in each thread, and finally store the data from the TLR to the global memory through the data storage instruction. It should be understood that the process of loading data from the global memory to the TLR and storing it back to the global memory after determining the storage location is a common memory access and data processing mode in Strided Slice operations. The data slices finally stored back in the global memory can be easily accessed and used by subsequent computing tasks.

[0024] The drawback of the above implementation of the Strided Slice operation is that it greatly increases the number of instructions to load data from global memory. As the size of the data set increases and the computational complexity increases, this overhead becomes increasingly large, seriously affecting the performance of the operator.

[0025] In this regard, the present invention provides a data segmentation method, which loads a data block of a preset size into the TLR at one time, then moves the data to be stored in the output (i.e., the valid data block) to the shared memory, and finally moves the data to be output from the shared memory to the global memory for storage. Since the data block is loaded at one time according to the preset size, by fully reusing these data, the number of data loading instructions and the number of global memory accesses can be greatly reduced, and the operator performance can be improved, thereby overcoming the above-mentioned defects.

[0026] Figure 1 It is a flow chart of the data segmentation method provided by the present invention, such as Figure 1 As shown, the method includes: Step 110, determining the starting coordinates of the data block to be loaded, and loading the data block from the input data based on the preset size and the starting coordinates to obtain the target data block.

[0027] Specifically, the current data block to be loaded refers to the data block to be extracted from the input data during the data segmentation process. The starting coordinates of the current data block to be loaded refer to the starting position of the current data block to be loaded when loading data. The starting position can be represented by some form of coordinates or indexes, such as the starting index in one-dimensional data, or the starting row and column index in a two-dimensional matrix.

[0028] The determination of the starting coordinates usually depends on the loading of the previous data block, the size of the data block (i.e., the preset size), and the overall structure of the input data. For the first load, the starting coordinates are usually 0 or the starting position of the input data; for subsequent loads, the starting coordinates are determined based on the end position of the previous data block, and the end position of the previous data block can be determined based on the starting position and preset size of the data block.

[0029] Here, the preset size refers to the size or dimension that each data block should have before data segmentation. This size can be fixed or dynamically determined according to a certain rule. The preset size determines the amount of data loaded from the input data each time. For example, the preset size can be M×N, which means that the size of the loaded data block is M×N, that is, M rows and N columns of data are loaded from the input data each time. It should be understood that the input data refers to the original data to be segmented and processed, which is usually stored in the global memory. The input data can be any form of data collection, such as an array, a matrix, a list, etc.

[0030] After determining the starting coordinates of the current data block to be loaded, the data block can be loaded from the input data stored in the global memory into the TLR according to the starting coordinates and the preset size. Specifically, some form of read instruction or operation can be used to extract data according to the preset size starting from the starting coordinates. For example, assuming the preset size is M×N, according to the starting coordinates of the current data block to be loaded, the LDM (Load Matrix) instruction can be used to load M rows and N columns of data into the TLR to obtain the target data block. Here, the target data block refers to the data block loaded from the input data through the LDM instruction, which is the basis for subsequent processing (such as segmentation, storage, etc.).

[0031] It is understandable that the LDM instruction refers to an instruction for loading matrix data, which can load multiple data elements from the memory into the processor register at one time. Since the input data is stored in the global memory, by using the LDM instruction to load a data block of a preset size from the global memory at one time, there is no need to load data elements one by one, which can reduce the number of global memory accesses and thus improve operator performance.

[0032] Step 120: determine valid data blocks from the target data blocks based on the segmentation step size, and store the valid data blocks in a shared memory.

[0033] Specifically, after loading the data into the TLR and obtaining the target data block, the valid data block can be determined from the target data block according to the segmentation step. Here, the segmentation step determines the interval or step length for selecting valid data in the target data block. Specifically, the valid data block can be determined by the following steps: first, determine a starting point in the target data block, which can be the first element of the target data block or a starting element selected according to a certain rule; starting from the starting point, select data according to the segmentation step length, and combine all the data selected according to the segmentation step length to form a valid data block. For example, in a one-dimensional array data=[1, 2, 3, 4, 5], if the segmentation step length is 2, then every other element is selected as a valid data, and the selected data elements are [1, 3, 5], and these data elements form a valid data block. Here, the valid data block refers to a set of data points selected according to the segmentation step length in the target data block.

[0034] It can be understood that the step of determining the valid data block according to the segmentation step is actually data segmentation, which is achieved by screening and selecting the data in the target data block, extracting the data points that meet the conditions, and forming a new data block (i.e., the valid data block), thereby achieving data segmentation.

[0035] After the valid data block is determined, the valid data block can be moved from the TLR to the shared memory for storage. Here, shared memory refers to a memory architecture used to implement data sharing in a multi-processor or parallel computing environment. For example, the shared memory can be GSM (Group Shared Memory), in which a group of processors or computing units can share the same memory area, allowing them to exchange data efficiently. In addition, shared memory has a faster access speed than global memory, which helps to speed up data access and processing. By temporarily storing valid data blocks in shared memory, it is convenient to reuse the data later.

[0036] Step 130: When the size of the valid data block stored in the shared memory reaches the preset size, the valid data block of the preset size in the shared memory is stored in the global memory to obtain a data slice.

[0037] Specifically, the size of the valid data block stored in the shared memory refers to the size of the space occupied by the valid data filtered and stored from the target data block according to the segmentation step in the shared memory. This size changes dynamically and increases as valid data is continuously added until it reaches the preset size.

[0038] When the size of the valid data block stored in the shared memory reaches the preset size, it indicates that a sufficient amount of valid data has been screened out according to the segmentation step size. The size of these valid data may be the preset size or may exceed the preset size. In this case, the valid data of the preset size can be stored as a whole in the global memory through a certain instruction to obtain data slices, so that subsequent computing tasks can access and use them. Here, data slices refer to a collection of one or more data blocks obtained during the data segmentation process. These data blocks are screened and extracted from the original input data according to certain rules (such as preset size, segmentation step size, etc.). Data slices can be used in subsequent data processing, analysis, or machine learning tasks.

[0039] Exemplarily, a valid data block of a preset size in the shared memory can be transferred to a specified location in the global memory by executing an STM (Store Matrix) instruction. Here, the STM instruction refers to an instruction for storing matrix data, which can load multiple data elements from the shared memory to the global memory at one time. By using the STM instruction to load a valid data block of a preset size into the global memory at one time, there is no need to load data elements one by one, thereby reducing the number of accesses to the global memory.

[0040] It is understandable that for STM instructions, data storage operations are usually performed according to a fixed size each time they are executed. If the size of the valid data block stored in the shared memory does not reach the preset size, then executing an STM instruction once will cause a partial waste of bandwidth. Moreover, moving the valid data block from the shared memory to the global memory is a relatively time-consuming operation. When the size of the valid data block in the shared memory is the preset size or exceeds the preset size, the valid data block of the preset size will be stored in the global memory at one time, which can reduce the number of times data is moved between the shared memory and the global memory, that is, reduce the number of accesses to the global memory, thereby improving the efficiency of data processing.

[0041] In addition, if the size of the valid data block stored in the shared memory has not reached the preset size, and there is more data available to be loaded in the input data, steps 110 and 120 will continue to be executed to load more data blocks from the input data and filter out more valid data until the size of the valid data block in the shared memory reaches the preset size. Only then will the STM instruction be executed to move the valid data to the global memory for storage.

[0042] Furthermore, after the valid data block of the preset size in the shared memory is moved to the global memory, if there is still some valid data left in the shared memory, then this part of the valid data will continue to be stored in the shared memory, waiting to be spliced ​​with the valid data block obtained by the next round of data loading, until the size of the valid data block stored in the shared memory reaches the preset size again, the STM instruction will be executed again. This process realizes the reuse of valid data without having to reload and obtain it from the input data, thereby reducing the number of data loading instructions.

[0043] Step 140, based on the starting coordinates and the preset size, determine the starting coordinates of the next data block to be loaded, and use the starting coordinates of the next data block to be loaded as the starting coordinates of the current data block to be loaded, and continue to load data blocks from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0044] Specifically, after the current round of data loading is completed, the starting coordinates of the next round of data loading can be determined. If the coordinates do not exceed the boundary of the input data, a new round of data loading can be started. Specifically, the ending coordinates of the current loaded data block can be calculated based on the starting coordinates and the preset size of the current loaded data block determined in step 110. The ending coordinates here can be obtained by adding the current starting coordinates to the preset size; then, the next position of the ending coordinates of the current data block can be used as the starting coordinates of the next data block to be loaded.

[0045] Here, the next data block to be loaded refers to the next data block that needs to be loaded from the input data in the same way (i.e. based on the starting coordinates and the preset size) after the current data block is loaded and processed. The starting coordinates of the next data block to be loaded refer to the starting position of the data to be read from the input data when the next data block is loaded.

[0046] After determining the starting coordinates of the next data block to be loaded, it can be determined whether the starting coordinates exceed the boundary of the input data. If not, the starting coordinates are used as the starting coordinates of the current data block to be loaded, and the process returns to step 110 to continue to load the data block from the input data according to the starting coordinates and the preset size; if it exceeds the boundary of the input data, the data loading and segmentation process ends. It should be understood that each time a data block is loaded and processed, the starting coordinates of the currently loaded data block will be updated to the starting coordinates of the next data block to be loaded, and the next data block will continue to be loaded from the input data. This process will be repeated until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0047] It is understood that the boundary of the input data refers to the range between the starting position and the ending position of the input data. During the data segmentation process, it is necessary to ensure that the loaded data blocks do not exceed this range. If the starting coordinates of the next data block to be loaded exceed the boundary of the input data, it indicates that all valid data blocks in the input data have been loaded, and the data segmentation process can be terminated.

[0048] The method provided by the embodiment of the present invention can load a data block of a preset size from the input data at one time based on the preset size and the starting coordinates of the current data block to be loaded, instead of loading data elements one by one, thereby greatly reducing the number of data loading instructions and improving the performance of the data segmentation operator. After the target data block is loaded, the valid data block is determined based on the segmentation step length, and stored in the shared memory until the size of the valid data block stored in the shared memory reaches the preset size, and then the valid data block of the preset size is moved to the global memory for storage, which can reduce the number of accesses to the global memory, thereby avoiding the degradation of the operator performance due to frequent access to the global memory. In addition, after the valid data block of the preset size is stored in the global memory, the remaining valid data blocks in the shared memory can be reused without reloading from the input data, and the remaining valid data blocks can be spliced ​​with the valid data blocks subsequently moved to the shared memory, until the valid data blocks stored in the shared memory reach the preset size again and are stored in the global memory, this data reuse strategy can reduce the number of data loading instructions, thereby reducing the number of times data is read from the global memory, and improving the operator performance.

[0049] Based on the above embodiment, after step 120, the method further includes: In the case that the current data block loading is the last loading in the current row direction of the input data, the remaining valid data blocks in the shared memory are stored in the global memory to obtain data slices.

[0050] It should be noted that in the global memory, the input data can be stored in the form of a row-column matrix. When loading data blocks from the input data, they can be loaded in the row direction (i.e., horizontal direction). After the data loading in the current row direction is completed, it can be switched to the next row direction for loading. Since the storage locations of data in different row directions are different, in order to avoid the storage order of valid data in the global memory being disordered, when the data block is loaded as the last load in the current row direction, even if the size of the valid data block stored in the shared memory does not reach the preset size, all the remaining valid data blocks in the shared memory will be stored in the global memory without waiting for splicing with the data block loaded in the next row direction, thereby avoiding data disorder.

[0051] Specifically, the current row direction in the input data refers to the direction of the data row currently being processed during the data loading process. In other words, it refers to the data loading path along the row (horizontal direction) from left to right or from right to left in the matrix of the input data. If the current data block is loaded as the last load in the current row direction in the input data, it indicates that in the current data loading process, the loaded target data block is the last data block along the current row direction. After the data block is loaded, there will be no more data blocks to load along the current row direction, and it is necessary to switch to the next row direction for loading.

[0052] In order to determine whether the current data block loading is the last loading in the current row direction, a row counter and a column counter can be maintained, and these counters can be updated each time a data block is loaded, and the counter value can be compared with the matrix size of the input data to determine whether it is the last loading. It is also possible to first calculate how many times the data block needs to be loaded in the row direction to cover the entire row based on the matrix size of the input data and the size of the data block loaded by each LDM instruction, and then during the loading process, a counter or index is used to track and record how many data blocks have been loaded, thereby determining whether it is the last data block in the row direction.

[0053] It is understandable that, since data is loaded in the row direction, if the remaining valid data blocks are not immediately stored in the global memory at the last load in the row direction, but waiting for the next data load in the row direction, the storage order of the data in the global memory may be disrupted. This is because the valid data loaded in the next row direction may be inserted after the remaining data blocks of the current row, that is, in the same row as the remaining data blocks of the current row, thereby destroying the original position order of the data. In addition, if data is loaded in the column direction, when the data block is loaded as the last load in the current column direction, the remaining valid data blocks in the shared memory will also be stored in the global memory to avoid data storage disorder.

[0054] Based on any of the above embodiments, in step 110, determining the starting coordinates of the current data block to be loaded includes: Step 111, obtaining the original coordinates of the data block to be loaded; Step 112: align the original coordinates based on the preset size to obtain the starting coordinates of the data block to be loaded.

[0055] Specifically, the original coordinates of the data to be loaded refer to the starting coordinates that directly reflect the location of the data block in the global memory without any adjustment or processing during the data loading process. The starting coordinates of the data block to be loaded refer to the actual starting coordinates used by the LDM instruction to load the data block after alignment processing.

[0056] When loading data through the LDM instruction, it is usually required that the starting address (i.e., starting coordinate) of the data loading operation is aligned with the data block size (i.e., preset size) required by the LDM instruction. In other words, the starting coordinate of each data loading needs to be an integer multiple of the data block size to ensure that the complete data block can be loaded at one time without crossing the data block boundary.

[0057] Specifically, for the data block to be loaded, after determining the original coordinates of the data block, the original coordinates can be aligned according to the preset size to obtain the starting coordinates for actual data loading. If the coordinate alignment is not performed, additional operations may be required to handle boundary conditions, such as reading partial data, etc. These additional operations will increase the complexity and time cost of instruction execution.

[0058] For example, assuming that the original coordinates of the data block to be loaded are (m, n), and the size of the data block loaded by the LDM instruction is M×N, that is, the preset size is M×N, then the starting coordinates after alignment are Here, " / / " indicates integer division, i.e., floor division. By using floor operations to determine the maximum integer that can divide M and N respectively, and then multiplying by M and N to obtain the aligned starting coordinates, it is possible to ensure that the starting coordinates are integer multiples of the preset size, thereby satisfying the alignment requirements of the LDM instruction. For example, the original coordinates of the current data block to be loaded are (0, 2), the preset size is 4×4, and the aligned starting coordinates are (0, 0).

[0059] Based on any of the above embodiments, in step 120, determining a valid data block from the target data block based on the segmentation step size includes: Step 121, when the starting coordinates are different from the original coordinates, based on the segmentation step, determining a valid data block within the range from the original coordinates to the end coordinates of the target data block, wherein the end coordinates are determined based on the starting coordinates and the preset size; Step 122, when the starting coordinates are the same as the original coordinates, based on the segmentation step, determine a valid data block within the range from the starting coordinates to the ending coordinates of the target data block.

[0060] Specifically, when the starting coordinates of the data block to be loaded are different from the original coordinates, it indicates that during the current data loading process, the data block is not loaded from the actual starting position stored in the global memory. This situation usually occurs during the first data loading process in the row direction. When the starting coordinates of the data block to be loaded are the same as the original coordinates, it indicates that during the current data loading process, the data block is loaded from the actual starting position stored in the global memory. For each data loading in the row direction, usually except for the first data block, the starting coordinates of other data blocks will be the same as the original coordinates.

[0061] For example, assuming that the original coordinates of the data block to be loaded are (m, n), the preset size (i.e., the data block size) is M×N, and the starting coordinates after alignment are ,if If it is different from (m, n) (this usually happens when the LDM instruction is executed for the first time in the current row direction), it is loaded into the target data block on the TLR, and the coordinate range is arrive The data between is invalid data. Therefore, at this time, according to the segmentation step, from the original coordinates (m, n) to the terminal coordinates Determine the valid data block from the data between. Here, That is, the end coordinate of the target data block in the global memory, which is determined according to the start coordinate and preset size of the data block.

[0062] If the starting coordinates of the data block to be loaded are the same as the original coordinates, that is, Same as (m,n), the data in the starting coordinate and ending coordinate range of the target data block may be valid data (when the segmentation step is 1), or may contain some invalid data (when the segmentation step is not 1). Therefore, the target data block can be segmented from the starting coordinate to the ending coordinate according to the segmentation step. To the end coordinate Determine the valid data block within the range.

[0063] Figure 2 is a schematic diagram of data block loading provided by the present invention, such as Figure 2As shown in the figure, each square shows the coordinates of the respective data elements, where the green part in the figure is the input data to be loaded, with the starting coordinates (0, 2) and the ending coordinates (7, 7). Assuming that the size of the data block loaded each time is 4×4, the orange square in the figure is the 4×4 data block loaded by the first LDM instruction in the current row direction. For this orange data block, its original coordinates are the starting coordinates of the input data (0, 2). According to the alignment requirements of the LDM instruction, the starting coordinates when actually loading data are (0, 0). For the orange data block, its starting coordinates are different from the original coordinates. When loaded into the target data block of the TLR, the data between the coordinates (0, 0) and (3, 1) are invalid data. If the segmentation step length stride=(1, 1), the data between the original coordinates (0, 2) and the ending coordinates (3, 3) are all valid data. If the segmentation step length is not (1, 1), the data between the coordinates (0, 2) and (3, 3) need to be further filtered according to the segmentation step length, so that the determined valid data can be stored in the shared memory.

[0064] Subsequently, for the data block loaded by the second LDM instruction in the current row direction (i.e. Figure 2 ), its original coordinates are (0, 4), and after alignment according to the preset size, the starting coordinates are also (0, 4). For this yellow data block, its starting coordinates are the same as the original coordinates. Therefore, we can directly filter out valid data blocks from the data between the starting coordinates (0, 4) and the ending coordinates (3, 7) according to the segmentation step size and store them in the shared memory.

[0065] Based on any of the above embodiments, the step of determining the coordinates of each valid data in the valid data block includes: In the case where the starting coordinates are different from the original coordinates, determining the coordinates of each valid data based on the original coordinates and a first offset, wherein the first offset is determined based on the segmentation step, the original coordinates and the preset size; In the case that the starting coordinates are the same as the original coordinates, the coordinates of each valid data are determined based on the starting coordinates and a second offset, where the second offset is determined based on the segmentation step and the preset size.

[0066] Specifically, after the target data block is loaded into the TLR, when each valid data is determined from the target data block to form a valid data block, if the starting coordinates of the currently loaded data block are different from the original coordinates, the coordinates of each valid data within the range from the original coordinates to the end coordinates can be determined based on the original coordinates and the first offset. Here, the first offset refers to an offset introduced to filter out valid data within the range from the original coordinates to the end coordinates, which is determined comprehensively based on the segmentation step, the original coordinates and the preset size to ensure that the valid data can be correctly located and extracted.

[0067] If the starting coordinates of the currently loaded data block are the same as the original coordinates, the valid data coordinates within the range from the starting coordinates to the ending coordinates can be determined based on the starting coordinates and the second offset. Here, the second offset refers to an offset introduced to filter out valid data within the range from the starting coordinates to the ending coordinates, which is determined based on the segmentation step size and the preset size.

[0068] For example, assuming that the segmentation step length stride=(s1, s2), the original coordinates of the currently loaded data block are (m,n), and the preset size is M×N, then the starting coordinates of the data block are If the starting coordinates If it is different from the original coordinates (m, n), then the original coordinates (m, n) to the final coordinates The valid data coordinates between are ,in , i and j are both positive integers. This is the first offset.

[0069] If the starting coordinates The starting coordinates are the same as the original coordinates (m, n). To the end coordinate The valid data coordinates between ,in , i and j are both positive integers. This is the second offset.

[0070] like Figure 2 As shown, assuming that the segmentation step length stride=(1, 1), then for the first data block loaded by the LDM instruction in the row direction (i.e. Figure 2 The orange data block in the figure shows that the data between the original coordinates (0, 2) and the terminal coordinates (3, 3) are all valid data and can be moved to the shared memory for storage. Figure 2The data between the starting coordinates (0, 4) and the ending coordinates (3, 7) are all valid data, and the data block can be moved to the shared memory for storage.

[0071] If the segmentation step length stride=(1, 2), that is, s1=1, s2=2, then for the first loaded orange data block, according to and The formula can be determined Based on this, we can further calculate that the valid data coordinates between the original coordinate (0, 2) and the final coordinate (3,3) include: (0, 2), (1, 2), (2, 2), (3, 2). For the second loaded yellow data block, according to The formula can be determined Based on this, we further calculate that the valid data coordinates between the starting coordinate (0, 4) and the ending coordinate (3, 7) include: (0,4), (1, 4), (2, 4), (3, 4), (0, 6), (1, 6), (2, 6), (3, 6).

[0072] Based on any of the above embodiments, after step 130, the method further includes: The remaining valid data blocks in the shared memory are shifted to the left to be spliced ​​with the valid data blocks loaded in the next round, and the valid data blocks are stored in the shared memory in a continuous order from left to right.

[0073] Specifically, when performing a Strided Slice operation, the data (i.e., valid data) that needs to be retained and used for subsequent calculations or storage, which is filtered out according to the stride value, is arranged in a continuous, left-to-right order when it is moved to the shared memory (GSM). When the size of the valid data block stored in the GSM reaches or exceeds the preset size, after the valid data block of the preset size is moved to the global memory for storage, the remaining valid data blocks in the GSM can be shifted to the left to achieve continuous storage and efficient use of valid data.

[0074] During the execution of Strided Slice, each data block loaded by the LDM instruction may contain only part of the valid data, while the rest is invalid or unnecessary. As the operation proceeds, the valid data in these data blocks will gradually accumulate in the GSM. By shifting the remaining valid data to the left, it can be ensured that the newly loaded valid data can be seamlessly spliced ​​to the previous data to form a larger, continuous data block. In this way, when the size of the valid data stored in the GSM reaches or exceeds the preset size M×N, the M×N data block can be stored in the global memory at one time, thereby improving the overall storage efficiency and reducing the number of accesses to the global memory.

[0075] Based on any of the above embodiments, the target data block is stored in a thread local register.

[0076] Specifically, according to the preset size and the starting coordinates of the data block to be loaded, the target data block can be loaded into the TLR (thread local register) using the LDM instruction. After the data block is loaded into the TLR, the thread can access the data faster, reducing memory access latency, facilitating subsequent data segmentation operations, and helping to improve the overall efficiency of data processing. In addition, in a parallel processing environment, by loading the data block into the thread local registers of multiple threads, each thread can process the data independently, thereby improving the efficiency of parallel processing and reducing global memory access conflicts.

[0077] Based on any of the above embodiments, Figure 3 The present invention provides a flow chart of a data segmentation optimization method based on multiplexing input data. The method uses the LDM instruction to load M rows and N columns of data into the TLR, then puts the data to be stored in the GSM, and finally stores the data to be output from the GSM to the global memory. Since the LDM instruction can load M×N data from the global memory to the TLR at one time, after fully multiplexing these data, the number of data loading instructions can be greatly reduced, thereby improving the operator performance. The overall process of the method includes the following steps: Step S1, determine the starting coordinates of the data block to be loaded. Assuming that the original coordinates (i.e., the actual storage coordinates) of the data to be loaded are (m, n), and the size of the data block loaded by the LDM instruction is M×N, then the actual starting coordinates for loading after alignment are .

[0078] Step S2, according to the starting coordinates of the currently loaded data block, execute the LDM instruction, load M×N data from the global memory to the TLR, then, according to the segmentation step length, determine the valid data from the M×N data on the TLR, and move these valid data to the GSM. At the same time, according to the ending coordinates of the currently loaded data block, update the starting coordinates of the next load.

[0079] Step S3, determine whether the size of the valid data stored in GSM reaches M×N, or whether the current load is the last execution of the LDM instruction in the current row direction. If the size of the valid data stored in GSM reaches M×N, or the current row direction is the last execution of the LDM instruction, then execute the STM instruction to store the first M×N data on GSM to the global memory; otherwise, use the starting coordinates of the next load as the new starting coordinates of the current load, and return to step S2.

[0080] Step S4, after executing the STM instruction, determine whether the starting coordinates of the next load exceed the boundary of the input data. If not, repeat steps S2 and S3 until the coordinates exceed the boundary of the input data.

[0081] Figure 4 is a schematic diagram of multiplexing input data in the data segmentation process provided by the present invention, such as Figure 4As shown in the figure, taking the starting coordinates of the input data (0, 2) and the segmentation step length stride=(1, 1) as an example, the green part in the figure is the actual data to be loaded. In the 4×4 data block (i.e., the orange data block) loaded by the first LDM instruction in the row direction, only the right half is valid. Therefore, after loading the data block into the TLR, only the valid data is moved to the GSM for storage. After the first data block is loaded, since the size of the valid data stored in the GSM does not reach 4×4, the STM instruction is not executed. Next, except for the last LDM load in the current row direction, each 4×4 data block loaded must be valid data, so it is directly moved to the back of the GSM valid data for storage. After completing the second data block loading (i.e., the yellow data block in the figure), the size of the valid data block stored in the GSM exceeds 4×4. At this time, the STM instruction can be used to store the 4×4 data block with coordinates between (0, 0) and (3,3) in the GSM into the global memory, and then the remaining valid data in the GSM is shifted to the left and spliced ​​with the next round of loaded data into 4×4 output data. For the data loaded by the last LDM in the current row direction, after the valid data is moved to GSM, the STM instruction can be directly used to store it in the global memory. It should be understood that the embodiment of the present invention introduces a relatively simple scenario. When the stride is not 1, it is only necessary to copy the valid data to GSM according to the stride value in the process of moving the data on the TLR to GSM.

[0082] It should be noted that Figure 4 In the example, LDM(0, 0) means loading a 4×4 data block from the starting coordinate (0, 0) in the global memory; LDM(0, 4) means loading a 4×4 data block from the starting coordinate (0, 4) in the global memory. STM(0, 0) means moving a 4×4 data block from the starting coordinate (0, 0) in the GSM and storing it in the global memory.

[0083] The method provided by the embodiment of the present invention greatly reduces the number of data loading instructions by reusing the data loaded by LDM, thereby reducing the number of times data is read from the global memory, thereby improving the performance of the Strided Slice operator.

[0084] Based on any of the above embodiments, Figure 5 is a schematic diagram of the structure of the data segmentation device provided by the present invention, such as Figure 5 As shown, the device comprises: The loading unit 510 is used to determine the starting coordinates of the data block to be loaded, and load the data block from the input data based on the preset size and the starting coordinates to obtain the target data block; A segmentation unit 520, configured to determine a valid data block from the target data block based on a segmentation step length, and store the valid data block in a shared memory; A storage unit 530 is configured to store the valid data block of the preset size in the shared memory into a global memory to obtain a data slice when the size of the valid data block stored in the shared memory reaches the preset size; The loop unit 540 is used to determine the starting coordinates of the next data block to be loaded based on the starting coordinates and the preset size, and use the starting coordinates of the next data block to be loaded as the starting coordinates of the current data block to be loaded, and continue to load data blocks from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0085] The device provided by the embodiment of the present invention can load a data block of a preset size from the input data at one time based on the preset size and the starting coordinates of the current data block to be loaded, instead of loading data elements one by one, thereby greatly reducing the number of data loading instructions and improving the performance of the data segmentation operator. After the target data block is loaded, the valid data block is determined based on the segmentation step length, and stored in the shared memory until the size of the valid data block stored in the shared memory reaches the preset size, and then the valid data block of the preset size is moved to the global memory for storage, which can reduce the number of accesses to the global memory, thereby avoiding the degradation of the operator performance due to frequent access to the global memory. In addition, after the valid data block of the preset size is stored in the global memory, the remaining valid data blocks in the shared memory can be reused without reloading from the input data, and the remaining valid data blocks can be spliced ​​with the valid data blocks subsequently moved to the shared memory until the valid data blocks stored in the shared memory reach the preset size again and are stored in the global memory. This data reuse strategy can reduce the number of data loading instructions, thereby reducing the number of times data is read from the global memory and improving the operator performance.

[0086] Based on any of the above embodiments, the storage unit 530 is further configured to: In the case that the current data block loading is the last loading in the current row direction of the input data, the remaining valid data blocks in the shared memory are stored in the global memory to obtain data slices.

[0087] Based on any of the above embodiments, the loading unit 510 includes a coordinate determining subunit, and the coordinate determining subunit is used to: Get the original coordinates of the data block to be loaded; Based on the preset size, the original coordinates are aligned to obtain the starting coordinates of the data block to be loaded.

[0088] Based on any of the above embodiments, the segmentation unit 520 includes a valid data determination subunit, and the valid data determination subunit is used to: In the case where the starting coordinates are different from the original coordinates, based on the segmentation step, a valid data block is determined within the range from the original coordinates to the end coordinates of the target data block, wherein the end coordinates are determined based on the starting coordinates and the preset size; In the case where the starting coordinates are the same as the original coordinates, a valid data block is determined within the range from the starting coordinates to the ending coordinates of the target data block based on the segmentation step.

[0089] Based on any of the above embodiments, the valid data determination subunit is specifically used for: In the case where the starting coordinates are different from the original coordinates, determining the coordinates of each valid data based on the original coordinates and a first offset, wherein the first offset is determined based on the segmentation step, the original coordinates and the preset size; In the case that the starting coordinates are the same as the original coordinates, the coordinates of each valid data are determined based on the starting coordinates and a second offset, where the second offset is determined based on the segmentation step and the preset size.

[0090] Based on any of the above embodiments, the storage unit 530 is further configured to: The remaining valid data blocks in the shared memory are shifted to the left to be spliced ​​with the valid data blocks loaded in the next round, and the valid data blocks are stored in the shared memory in a continuous order from left to right.

[0091] Based on any of the above embodiments, the target data block is stored in a thread local register.

[0092] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the data segmentation method, which includes: determining the starting coordinates of the current data block to be loaded, and loading the data block from the input data based on the preset size and the starting coordinates to obtain the target data block; determining the valid data block from the target data block based on the segmentation step, and storing the valid data block in the shared memory; when the size of the valid data block stored in the shared memory reaches the preset size, storing the valid data block of the preset size in the shared memory in the global memory to obtain data slices; determining the starting coordinates of the next data block to be loaded based on the starting coordinates and the preset size, and using the starting coordinates of the next data block to be loaded as the starting coordinates of the current data block to be loaded, and continuing to load data blocks from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0093] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0094] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the data segmentation method provided by the above methods, which includes: determining the starting coordinates of the current data block to be loaded, and loading the data block from the input data based on a preset size and the starting coordinates to obtain a target data block; based on the segmentation step, determining a valid data block from the target data block, and storing the valid data block in a shared memory; when the size of the valid data block stored in the shared memory reaches the preset size, storing the valid data block of the preset size in the shared memory in the global memory to obtain a data slice; based on the starting coordinates and the preset size, determining the starting coordinates of the next data block to be loaded, and using the starting coordinates of the next data block to be loaded as the starting coordinates of the current data block to be loaded, and continuing to load data blocks from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0095] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the data segmentation method provided by the above-mentioned methods, the method comprising: determining the starting coordinates of the current data block to be loaded, and based on a preset size and the starting coordinates, loading the data block from the input data to obtain a target data block; based on the segmentation step, determining a valid data block from the target data block, and storing the valid data block in a shared memory; when the size of the valid data block stored in the shared memory reaches the preset size, storing the valid data block of the preset size in the shared memory in a global memory to obtain a data slice; based on the starting coordinates and the preset size, determining the starting coordinates of the next data block to be loaded, and using the starting coordinates of the next data block to be loaded as the starting coordinates of the current data block to be loaded, and continuing to load data blocks from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

[0096] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0097] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.

[0098] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data segmentation method, characterized in that: include: Determine the starting coordinates of the data block to be loaded, and load the data block from the input data based on the preset size and the starting coordinates to obtain the target data block; Based on the segmentation step length, determining a valid data block from the target data block, and storing the valid data block in a shared memory; When the size of the valid data block stored in the shared memory reaches the preset size, storing the valid data block of the preset size in the shared memory into the global memory to obtain a data slice; Based on the starting coordinates and the preset size, the starting coordinates of the next data block to be loaded are determined, and the starting coordinates of the next data block to be loaded are used as the starting coordinates of the current data block to be loaded, and data blocks continue to be loaded from the input data until the starting coordinates of the next data block to be loaded exceed the boundary of the input data.

2. The data segmentation method according to claim 1, characterized in that: The storing of the valid data block into the shared memory further comprises: In the case that the current data block loading is the last loading in the current row direction of the input data, the remaining valid data blocks in the shared memory are stored in the global memory to obtain data slices.

3. The data segmentation method according to claim 1, characterized in that: The step of determining the starting coordinates of the data block to be loaded includes: Get the original coordinates of the data block to be loaded; Based on the preset size, the original coordinates are aligned to obtain the starting coordinates of the data block to be loaded.

4. The data segmentation method according to claim 3, characterized in that: The determining of a valid data block from the target data block based on the segmentation step size includes: In the case where the starting coordinates are different from the original coordinates, based on the segmentation step, a valid data block is determined within the range from the original coordinates to the end coordinates of the target data block, wherein the end coordinates are determined based on the starting coordinates and the preset size; In the case where the starting coordinates are the same as the original coordinates, a valid data block is determined within the range from the starting coordinates to the ending coordinates of the target data block based on the segmentation step.

5. The data segmentation method according to claim 4, characterized in that: The step of determining the coordinates of each valid data in the valid data block comprises: In the case where the starting coordinates are different from the original coordinates, determining the coordinates of each valid data based on the original coordinates and a first offset, wherein the first offset is determined based on the segmentation step, the original coordinates and the preset size; In the case that the starting coordinates are the same as the original coordinates, the coordinates of each valid data are determined based on the starting coordinates and a second offset, where the second offset is determined based on the segmentation step and the preset size.

6. The data segmentation method according to any one of claims 1 to 5, characterized in that: The storing of the valid data blocks of the preset size in the shared memory into the global memory further includes: The remaining valid data blocks in the shared memory are shifted to the left to be spliced ​​with the valid data blocks loaded in the next round, and the valid data blocks are stored in the shared memory in a continuous order from left to right.

7. The data segmentation method according to any one of claims 1 to 5, characterized in that: The target data block is stored in a thread local register.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the data segmentation method as described in any one of claims 1 to 7 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data segmentation method as described in any one of claims 1 to 7 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the data segmentation method as described in any one of claims 1 to 7 is implemented.