Data Processing Method, Apparatus, Device, and Medium

By dividing the matrix into submatrixes and storing the last bit using the local maximum value, converting it into other data formats for calculation, the problems of insufficient computing performance of traditional CPUs and complex data format conversion are solved, and efficient and accurate data processing is achieved.

CN116303722BActive Publication Date: 2025-08-05KUNLUNXIN TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310280938.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-21
Publication Date
2025-08-05
Estimated Expiration
2043-03-21

AI Technical Summary

Technical Problem

Traditional CPUs have insufficient performance in the calculation-intensive operator processing of artificial intelligence models, and the selection of data type has an important impact on computing accuracy and performance. The existing data format conversion process is complex and inefficient.

Method used

Divide the matrix to be calculated into multiple submatrices, determine the maximum absolute value of each submatrix, and store the local maximum using the last bit of the element in the submatrix, convert it into other data formats for calculation, simplifying the data reading process.

Benefits of technology

It improves the efficiency and computing efficiency of data format conversion, improves calculation accuracy and performance, and reduces calculation complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116303722B_ABST
    Figure CN116303722B_ABST
Patent Text Reader

Abstract

The present disclosure provides a data processing method, apparatus, device, and medium, relating to the field of chip technology, and particularly to the field of data processing technology. The implementation solution is as follows: obtain a first target matrix; divide the first target matrix into multiple sub-matrices each including a first preset number of elements; determine the maximum absolute value of each element in each sub-matrix; based on the maximum absolute value, determine a reference maximum value in binary representation, the digit width of the reference maximum value being equal to the first preset number; for each element, determine the bit in the first storage unit that stores the last mantissa bit of the element as the target bit; write the reference maximum value into the first preset number of target bits; for each element in the sub-matrix, read the reference maximum value from the target bit to convert the element into a conversion element in a second data format; and determine a target calculation result based on the conversion element corresponding to each element in the first target matrix and the target calculation type.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of chip technology, particularly to the field of data processing, and specifically to a data processing method, apparatus, electronic device, computer-readable storage medium, and computer program product. Background Art

[0002] Artificial intelligence is a discipline that studies the use of computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), including both hardware-level technologies and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include several major directions such as computer vision technology, speech recognition technology, natural language processing technology, and machine learning / deep learning, big data processing technology, and knowledge graph technology.

[0003] Artificial intelligence models have a large number of compute-intensive operators, mainly including matrix multiplication, convolution, pooling, activation, etc. These computations are very time-consuming, and the computing power of traditional CPUs is difficult to meet the requirements in terms of performance. Therefore, heterogeneous computing has become the mainstream, and various artificial intelligence processors including GPUs, FPGAs, and ASICs have been widely applied to artificial intelligence model computations. At the same time, the choice of data type also plays a very important role in the accuracy, performance, etc. of artificial intelligence computations.

[0004] The methods described in this section are not necessarily methods that have been previously conceived or adopted. Unless otherwise specified, no method described in this section should be considered prior art solely because it is included in this section. Similarly, unless otherwise specified, the problems mentioned in this section should not be considered to have been recognized in any prior art. Summary of the Invention

[0005] The present disclosure provides a data processing method, apparatus, electronic device, computer-readable storage medium, and computer program product.

[0006] According to one aspect of the present disclosure, a data processing method is provided, including: obtaining a first target matrix to be calculated, wherein each element in the first target matrix is stored in a first storage unit in a first data format, and the first data format includes floating-point type; dividing the first target matrix into multiple sub-matrices, wherein each sub-matrix in the multiple sub-matrices includes a first preset number of elements; for each sub-matrix in the multiple sub-matrices, determining the maximum absolute value of each element in the sub-matrix based on the absolute value of each element in the sub-matrix; determining a reference maximum value Max in binary representation corresponding to the maximum absolute value, and the digit width of the reference maximum value Max is equal to the first preset number; for each element in the sub-matrix, determining the bit of the last mantissa used to store the element in the first storage unit as the target bit to obtain a first preset number of target bits; writing the reference maximum value Max into the first preset number of target bits; and for each element in the sub-matrix, reading the reference maximum value Max from the first preset number of target bits, and based on the reference maximum value Max, converting the element into a conversion element in a second data format; and determining a target calculation result based on the conversion elements respectively corresponding to each element in the first target matrix and the target calculation type.

[0007] According to another aspect of the present disclosure, a data processing apparatus is provided, including: an obtaining unit configured to obtain a first target matrix to be calculated, wherein each element in the first target matrix is stored in a first storage unit in a first data format, and the first data format includes floating-point type; a dividing unit configured to divide the first target matrix into multiple sub-matrices, wherein each sub-matrix in the multiple sub-matrices includes a first preset number of elements; a first determining unit configured to, for each sub-matrix in the multiple sub-matrices, determine the maximum absolute value of each element in the sub-matrix based on the absolute value of each element in the sub-matrix; a second determining unit configured to determine a reference maximum value Max in binary representation corresponding to the maximum absolute value, and the digit width of the reference maximum value Max is equal to the first preset number; a third determining unit configured to, for each element in the sub-matrix, determine the bit of the last mantissa used to store the element in the first storage unit as the target bit to obtain a first preset number of target bits; a writing unit configured to write the reference maximum value Max into the first preset number of target bits; a converting unit configured to, for each element in the sub-matrix, read the reference maximum value Max from the first preset number of target bits, and based on the reference maximum value Max, convert the element into a conversion element in a second data format; and a calculating unit configured to determine a target calculation result based on the conversion elements respectively corresponding to each element in the first target matrix and the target calculation type.

[0008] According to another aspect of the present disclosure, there is provided a chip including the data processing device as described above.

[0009] According to another aspect of the present disclosure, there is provided an electronic device including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is enabled to execute the above data processing method.

[0010] According to another aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the above data processing method.

[0011] According to another aspect of the present disclosure, there is provided a computer program product including a computer program, wherein the computer program is capable of implementing the above data processing method when executed by a processor.

[0012] According to one or more embodiments of the present disclosure, the computing efficiency can be improved.

[0013] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it used to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] The drawings exemplarily show embodiments and form a part of the specification, and are used together with the textual description of the specification to explain the exemplary embodiments of the embodiments. The shown embodiments are for illustrative purposes only and do not limit the scope of the claims. In all the drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0015] Figure 1 A schematic diagram of an exemplary system in which various methods described herein can be implemented according to an exemplary embodiment of the present disclosure is shown;

[0016] Figure 2 A flowchart of a data processing method according to an exemplary embodiment of the present disclosure is shown;

[0017] Figure 3 A flowchart of a method for converting elements in a matrix into transformed elements according to an exemplary embodiment of the present disclosure is shown;

[0018] Figure 4 A block diagram of a data processing device according to an exemplary embodiment of the present disclosure is shown;

[0019] Figure 5 The block diagram of an exemplary electronic device that can be used to implement the embodiments of the present disclosure is shown. Detailed implementation manners

[0020] The exemplary embodiments of the present disclosure will be described below in conjunction with the accompanying drawings. Various details of the embodiments of the present disclosure are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0021] In the present disclosure, unless otherwise specified, the terms "first", "second", etc. are used to describe various elements and are not intended to limit the positional relationship, timing relationship or importance relationship of these elements. Such terms are only used to distinguish one element from another. In some examples, the first element and the second element may refer to the same instance of the element, and in certain cases, based on the context description, they may also refer to different instances.

[0022] In the description of various examples in the present disclosure, the terms used are only for the purpose of describing specific examples and are not intended to be restrictive. Unless the context clearly indicates otherwise, if the number of elements is not specifically limited, the element may be one or more. In addition, the term "and / or" used in the present disclosure covers any one of the listed items and all possible combinations.

[0023] In the related art, during the calculation process of an artificial intelligence model, the standard IEEE float type is mainly used. With the continuous development of technology, some new calculation types have emerged to replace the standard float, such as new half-precision calculation types like bfloat16, fp16, int16, etc. When data format conversion needs to be performed during the data processing process, quantization is usually performed based on the maximum value.

[0024] Based on this, the present disclosure provides a data processing method. During the matrix calculation process, the floating-point numbers in the matrix to be calculated are converted into other data formats, calculations are performed using the other data formats, and the matrix to be calculated is divided into multiple sub-matrices. After determining the local maximum value of each sub-matrix, the last bit of each element in the sub-matrix is used to jointly store the local maximum value, so that the local maximum value stored in the sub-matrix can be used to perform data format conversion, simplify the data reading process, and improve the efficiency of data format conversion. The embodiments of the present disclosure will be described in detail below in conjunction with the accompanying drawings.

[0025] Figure 1FIG. shows a schematic diagram of an exemplary system 100 in which the various methods and apparatuses described herein can be implemented according to embodiments of the present disclosure. Referring to Figure 1 , the system 100 includes one or more client devices 101, 102, 103, 104, 105, and 106, a server 120, and one or more communication networks 110 that couple the one or more client devices to the server 120. The client devices 101, 102, 103, 104, 105, and 106 can be configured to execute one or more application programs.

[0026] In embodiments of the present disclosure, the server 120 can run one or more services or software applications that enable the execution of data processing methods.

[0027] In certain embodiments, the server 120 can also provide other services or software applications, which can include non-virtual environments and virtual environments. In certain embodiments, these services can be provided as web-based services or cloud services, for example, provided to users of the client devices 101, 102, 103, 104, 105, and / or 106 under a software as a service (SaaS) model.

[0028] In Figure 1 the configuration shown, the server 120 can include one or more components that implement the functions performed by the server 120. These components can include software components, hardware components, or combinations thereof that can be executed by one or more processors. Users operating the client devices 101, 102, 103, 104, 105, and / or 106 can in turn utilize one or more client applications to interact with the server 120 to utilize the services provided by these components. It should be understood that various different system configurations are possible, which can be different from the system 100. Therefore, Figure 1 is an example of a system for implementing the various methods described herein and is not intended to be limiting.

[0029] Users can use the client devices 101, 102, 103, 104, 105, and / or 106 to send matrix data to be calculated. The client device can provide an interface that enables the user of the client device to interact with the client device. The client device can also output information to the user via the interface. Although Figure 1 only six client devices are depicted, those skilled in the art will be able to understand that the present disclosure can support any number of client devices.

[0030] Client devices 101, 102, 103, 104, 105, and / or 106 can include various categories of computing devices, such as portable handheld devices, general-purpose computers (such as personal computers and laptop computers), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, gaming systems, thin clients, various messaging devices, sensors, or other sensing devices, etc. These computing devices can run various categories and versions of software applications and operating systems, such as MICROSOFT Windows, APPLE iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as GOOGLE Chrome OS); or include various mobile operating systems, such as MICROSOFT WindowsMobile OS, iOS, Windows Phone, Android. Portable handheld devices can include cellular phones, smartphones, tablets, personal digital assistants (PDAs), etc. Wearable devices can include head-mounted displays (such as smart glasses) and other devices. Gaming systems can include various handheld gaming devices, Internet-enabled gaming devices, etc. Client devices are capable of executing various different applications, such as various Internet-related applications, communication applications (such as email applications), short message service (SMS) applications, and can use various communication protocols.

[0031] Network 110 can be any category of network well-known to those skilled in the art, which can support data communication using any one of a variety of available protocols (including but not limited to TCP / IP, SNA, IPX, etc.). By way of example only, one or more networks 110 can be a local area network (LAN), an Ethernet-based network, token ring, wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, a blockchain network, a public switched telephone network (PSTN), an infrared network, a wireless network (such as Bluetooth, WIFI), and / or any combination of these and / or other networks.

[0032] Server 120 can include one or more general-purpose computers, dedicated server computers (such as PC (personal computer) servers, UNIX servers, midrange servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and / or combination. Server 120 can include one or more virtual machines running a virtual operating system, or other computing architectures involving virtualization (such as one or more flexible pools of logical storage devices that can be virtualized to maintain virtual storage devices of the server). In various embodiments, server 120 can run one or more services or software applications that provide the functions described below.

[0033] The computing unit in server 120 can run one or more operating systems including any of the above operating systems and any commercially available server operating systems. Server 120 can also run any one of a variety of additional server applications and / or middleware applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, etc.

[0034] In some embodiments, server 120 can include one or more applications to analyze and merge data feeds and / or event updates received from users of client devices 101, 102, 103, 104, 105, and 106. Server 120 can also include one or more applications to display data feeds and / or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and 106.

[0035] In some embodiments, server 120 can be a server of a distributed system or a server incorporating blockchain technology. Server 120 can also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. A cloud server is a host product in the cloud computing service system, which addresses the deficiencies of traditional physical hosts and virtual private server (VPS) services, such as high management difficulty and weak business scalability.

[0036] System 100 can also include one or more databases 130. In certain embodiments, these databases can be used to store data and other information. For example, one or more of databases 130 can be used to store information such as audio files and video files. Databases 130 can reside in various locations. For example, the databases used by server 120 can be local to server 120, or can be remote from server 120 and can communicate with server 120 via a network-based or dedicated connection. Databases 130 can be of different categories. In certain embodiments, the databases used by server 120 can be, for example, relational databases. One or more of these databases can store, update, and retrieve data to and from the databases in response to commands.

[0037] In certain embodiments, one or more of databases 130 can also be used by applications to store application data. The databases used by applications can be different categories of databases, such as key-value repositories, object repositories, or conventional repositories supported by a file system.

[0038] Figure 1System 100 can be configured and operated in various ways to enable the application of the various methods and apparatuses described in this disclosure.

[0039] Figure 2 The flowchart of a data processing method 200 according to an exemplary embodiment of this disclosure is shown. As Figure 2 shown, method 200 includes:

[0040] Step S201, obtain a first target matrix to be calculated, wherein each element in the first target matrix is stored in a first storage unit in a first data format, and the first data format includes floating point type;

[0041] Step S202, divide the first target matrix into a plurality of sub-matrices, wherein each sub-matrix in the plurality of sub-matrices includes a first preset number of elements;

[0042] Step S203, for each sub-matrix in the plurality of sub-matrices, based on the absolute value of each element in the sub-matrix, determine the maximum absolute value of each element in the sub-matrix;

[0043] Step S204, determine a reference maximum value Max in binary representation corresponding to the maximum absolute value, and the digit width of the reference maximum value Max is equal to the first preset number;

[0044] Step S205, for each element in the sub-matrix, determine the bit of the last mantissa used to store the element in the first storage unit as the target bit, so as to obtain a first preset number of target bits;

[0045] Step S206, write the reference maximum value Max into the first preset number of target bits;

[0046] Step S207, for each element in the sub-matrix, read the reference maximum value Max from the first preset number of target bits, so as to convert the element into a conversion element in a second data format based on the reference maximum value Max; and

[0047] Step S208, determine a target calculation result based on the conversion element and the target calculation type respectively corresponding to each element in the first target matrix.

[0048] By utilizing the above method, the floating-point numbers in the target matrix to be calculated can be converted into other data formats during the matrix calculation process, and calculations can be performed using other data formats. In addition, the matrix to be calculated can be divided into multiple sub-matrices. After determining the local maximum value of each sub-matrix, the last bit of each element in the sub-matrix will be used to jointly store the local maximum value, so that the local maximum value stored in the sub-matrix can be used to perform data format conversion, simplifying the data reading process, improving the efficiency of data format conversion, and thus improving calculation efficiency.

[0049] In some examples, when the original digit width of the maximum absolute value is greater than a first predetermined number, a rounding operation may be performed on the maximum absolute value in step S204 to obtain a reference maximum digit width that meets a predetermined requirement. In other examples, when the original digit width of the maximum absolute value is less than the first predetermined number, the reference maximum digit may be obtained by padding the last digit with zeros.

[0050] In some examples, the target calculation type may include matrix multiplication or matrix multiplication. For example, when the target calculation type is matrix multiplication, after obtaining a target multiplication multiple, a calculation may be performed based on the target multiplication multiple and a conversion element to obtain a target calculation result.

[0051] According to some embodiments, the second data format includes at least one exponent bit and a plurality of mantissa bits, and in step S207, based on the reference maximum value Max, converting the element into the second data format includes: dividing the interval [0, Max] into 2 based on the digit width m of the exponent bit of the second data format and the reference maximum value Max. m continuous subintervals; based on the subinterval in which the element is located, determining the exponent bit of the conversion element corresponding to the element; and mapping the element to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to the element. Thus, the numerical distribution range of the elements in the submatrix can be determined to be [0, Max] based on the reference maximum value Max. The numerical distribution range in the submatrix is further segmented by determining the split points, so that mapping calculations are performed separately according to the subintervals into which each element falls, so that the data distribution range is divided more carefully, thereby obtaining higher calculation accuracy.

[0052] According to some embodiments, the interval [0, Max] is divided into 2 based on the digit width m of the exponent bits of the second data format and the reference maximum value Max. m The continuous sub-intervals include: Based on the reference maximum value Max, using the formula OK (2 m-1) segmentation points , where k is a positive integer less than 2 m ; and using the (2 m -1) segmentation points as the endpoints of sub-intervals to divide the interval [0, Max] into 2 m consecutive sub-intervals.

[0053] Figure 3 shows a flowchart of a method for converting elements in a matrix into conversion elements according to an embodiment of the present disclosure. As Figure 3 shown, in step S207, converting the element into a conversion element in the second data format based on the reference maximum value Max includes:

[0054] Step S301: Based on the reference maximum value Max, use the formula to determine (2 m -1) segmentation points , where k is a positive integer less than 2 m ;

[0055] Step S302: Use the (2 m -1) segmentation points as the endpoints of sub-intervals to divide the interval [0, Max] into 2 m consecutive sub-intervals;

[0056] Step S303: Based on the sub-interval where the element is located, determine the exponent bit of the conversion element corresponding to the element; and

[0057] Step S304: Based on the sub-interval where the element is located and the digit width n of the mantissa bit of the second data format, map the element to the interval [0, 2 n to determine the mantissa bit of the conversion element corresponding to the element.

[0058] Taking m as 1 and n as 6 as an example, that is, when the second data format has 1 exponent bit and 6 mantissa bits, each element in the sub-matrix needs to be mapped to the interval [0, , and use 6 mantissa bits to represent the absolute value of each element. The distribution interval [0, Max] of the elements in the sub-matrix can be divided into parts, and use the position of the first part as the segmentation point to divide the distribution interval [0, Max] into two sub-intervals and , so that the data represented in the second data format has at least accuracy. Thus, the second data format including 1 exponent bit and 6 mantissa bits can be used to more accurately represent the numerical values of the elements in the matrix to be calculated, improving the calculation accuracy.

[0059] Taking m as 2 and n as 5 as an example, that is, when the second data format has 2 exponent bits and 5 mantissa bits, each element in the sub-matrix needs to be mapped to the interval of [0, , so as to use 5 mantissa bits to represent the absolute value of each element. It can be determined based on the above formula , , Three cut-off points are used to divide the distribution interval [0, Max] of the elements in the sub-matrix into four sub-intervals, so that the data represented in the second data format has at least Precision. Thus, it is possible to use the second data format including 2 exponent bits and 5 mantissa bits to more accurately represent the element values in the matrix to be calculated, improving the calculation accuracy.

[0060] According to some embodiments, based on the sub-interval where the element is located and the digit width n of the mantissa bits of the second data format, mapping the element to the interval [0, 2 n to determine the mantissa bits of the conversion element corresponding to the element includes: determining the absolute value a of the element; and in response to determining that the maximum endpoint value of the sub-interval where the element is located is , mapping the element to the interval [0, 2 n to determine that the mantissa bits of the conversion element corresponding to the element are .

[0061] Furthermore, by determining the sub-interval where the element is located, the distribution range of the element can be more accurately determined, thereby obtaining higher calculation accuracy. When it is determined that the element falls into When the interval has a smaller value distribution, This interval is divided into 2 again n parts, so that The precision of the conversion element in the interval can be further improved to improve the calculation accuracy.

[0062] According to some embodiments, the second data format includes multiple mantissa bits. In step S207, converting the element into a conversion element in the second data format based on the reference maximum value Max includes: determining the absolute value a of the element; based on the reference maximum value Max, mapping the element to the interval [, 2 n to determine that the mantissa bits of the conversion element corresponding to the element are . Thus, it is possible to perform simple and efficient data format conversion based on the reference maximum value, that is, to obtain an integer conversion element based on the floating-point conversion method to simplify the calculation process.

[0063] According to some embodiments, the first data format and the second data format further include 1 sign bit, and the sign bit of the conversion element corresponding to each element in the first target matrix is the same as the sign bit of this element. Thereby, it is possible to implement data type conversion for floating-point numbers and improve the efficiency of floating-point calculations.

[0064] According to some embodiments, method 200 further includes: obtaining a second target matrix; for each element in the first target matrix and the second target matrix, determining the recovery factor corresponding to this element, where the recovery factor satisfies the following condition: the conversion element corresponding to this element multiplied by the recovery factor corresponding to this element is equal to the absolute value of this element, and where determining the target calculation result based on the conversion element corresponding to each element in the first target matrix and the target calculation type in step S208 includes: in response to determining that the target calculation type indicates performing a multiplication calculation based on the first target matrix and the second target matrix, calculating the product of the first target matrix and the second target matrix as the result matrix based on the conversion elements corresponding to each element in the first target matrix and the second target matrix, where the absolute value of each element in the result matrix is equal to the mantissa bit of the conversion element of the first element corresponding to this element in the first target matrix multiplied by the mantissa bit of the conversion element of the second element corresponding to this element in the second target matrix multiplied by the recovery factor corresponding to the first element multiplied by the recovery factor corresponding to the second element.

[0065] It can be understood that the data processing method 200 is used to convert the traditional floating-point data type into a second data type with n mantissa bits, so as to convert the matrix calculation of the floating-point type into a fixed-point calculation, thereby reducing the complexity of the calculation and achieving the purpose of saving hardware resources. After converting to fixed-point for matrix calculation, it is still necessary to convert the calculation result into the original data type so that this conversion process is not known to the user, in order to improve the user experience.

[0066] The process of converting the matrix calculation result into the original data type requires the above-mentioned recovery factor to achieve. Specifically, when converting an element of the first data format into a conversion element of the second data format, it is by multiplying the absolute value of this element by a factor to map this element to [0, 2 n , then it is possible to convert the matrix calculation result into the original data type by multiplying the calculation result by the reciprocal of this factor, and the reciprocal of this factor is the recovery factor. The recovery factor satisfies the following condition: the conversion element corresponding to this element multiplied by the recovery factor corresponding to this element is equal to the absolute value of this element, to achieve converting the matrix calculation result into the original data type.

[0067] According to some embodiments, when the first data format and the second data format further include 1 sign bit, the sign bit of each element in the result matrix is the exclusive OR value of the sign bit of the first element corresponding to the element in the first target matrix and the sign bit of the second element corresponding to the element in the second target matrix. Thereby, the matrix calculation of floating-point numbers is converted into fixed-point calculation with more mantissa bits, reducing the complexity of calculation and improving the calculation efficiency. Due to the increase in the mantissa bits, the precision of the data is also improved. At the same time, through the above process, automatic conversion of data is achieved, and the calculation result can be automatically converted back to the original data type. Users cannot feel the specific data type used in the calculation and the data conversion process during use, and can obtain calculation results and calculation processes with higher precision and higher efficiency.

[0068] According to another aspect of the present disclosure, a data processing device is provided. Figure 4 The structural block diagram of a data processing device 400 according to an exemplary embodiment of the present disclosure is shown. As Figure 4 shown, the device 400 includes:

[0069] An acquisition unit 401, configured to acquire a first target matrix to be calculated, wherein each element in the first target matrix is stored in a first storage unit in a first data format, and the first data format includes floating-point type;

[0070] A division unit 402, configured to divide the first target matrix into a plurality of sub-matrices, wherein each sub-matrix in the plurality of sub-matrices includes a first preset number of elements;

[0071] A first determination unit 403, configured to, for each sub-matrix in the plurality of sub-matrices, determine the maximum absolute value of each element in the sub-matrix based on the absolute value of each element in the sub-matrix;

[0072] A second determination unit 404, configured to determine a reference maximum value Max corresponding to the maximum absolute value in binary representation, and the digit width of the reference maximum value Max is equal to the first preset number;

[0073] A third determination unit 405, configured to, for each element in the sub-matrix, determine the bit of the last mantissa used to store the element in the first storage unit as the target bit, so as to obtain a first preset number of target bits;

[0074] A writing unit 406, configured to write the reference maximum value Max into the first preset number of target bits;

[0075] The conversion unit 407 is configured to, for each element in the sub-matrix, read the reference maximum value Max from the first preset number of target bits, and convert the element into a conversion element in a second data format based on the reference maximum value Max; and

[0076] The calculation unit 408 is configured to determine a target calculation result based on the conversion element corresponding to each element in the first target matrix and the target calculation type.

[0077] According to some embodiments, the second data format includes at least one exponent bit and a plurality of mantissa bits. The conversion unit 407 includes: a division sub-unit configured to divide the interval [0, Max] into 2 m consecutive sub-intervals based on the digit width m of the exponent bit of the second data format and the reference maximum value Max; a first determination sub-unit configured to determine the exponent bit of the conversion element corresponding to the element based on the sub-interval where the element is located; and a second determination sub-unit configured to map the element to the [0, 2 n interval based on the sub-interval where the element is located and the digit width n of the mantissa bit of the second data format to determine the mantissa bit of the conversion element corresponding to the element.

[0078] According to some embodiments, the division sub-unit is configured to: determine (2 -1) split points based on the reference maximum value Max using the formula m , where k is a positive integer less than 2 ; and use the (2 m -1) split points as the endpoints of the sub-intervals to divide the interval [0, Max] into 2 m consecutive sub-intervals. m

[0079] According to some embodiments, the second determination sub-unit is configured to: determine the absolute value a of the element; and in response to determining that the maximum endpoint value of the sub-interval where the element is located is , map the element to the [0, 2 n interval to determine that the mantissa bit of the conversion element corresponding to the element is .

[0080] According to some embodiments, the conversion unit is configured to: determine the absolute value a of the element; map the element to the [0, 2 n interval based on the reference maximum value Max to determine that the mantissa bit of the conversion element corresponding to the element is .

[0081] ​According to some embodiments, the first data format and the second data format further include 1 sign bit, and the sign bit of the conversion element corresponding to each element in the first target matrix is the same as the sign bit of this element.

[0082] According to some embodiments, the obtaining unit 401 is further configured to obtain a second target matrix, and the apparatus 400 further includes: a fourth determination unit, configured to determine, for each element in the first target matrix and the second target matrix, a recovery factor corresponding to this element, where the recovery factor satisfies the following condition: the conversion element corresponding to this element multiplied by the recovery factor corresponding to this element is equal to the absolute value of this element, and where the calculation unit 408 is configured to: in response to determining that the target calculation type indicates performing a multiplication calculation based on the first target matrix and the second target matrix, calculate the product of the first target matrix and the second target matrix as a result matrix based on the conversion elements respectively corresponding to each element in the first target matrix and the second target matrix, where the absolute value of each element in the result matrix is equal to the mantissa of the conversion element of the first element corresponding to this element in the first target matrix multiplied by the mantissa of the conversion element of the second element corresponding to this element in the second target matrix multiplied by the recovery factor corresponding to the first element multiplied by the recovery factor corresponding to the second element.

[0083] According to some embodiments, when the first data format and the second data format further include 1 sign bit, the sign bit of each element in the result matrix is the exclusive OR value of the sign bit of the first element corresponding to this element in the first target matrix and the sign bit of the second element corresponding to this element in the second target matrix.

[0084] According to another aspect of the present disclosure, there is also provided a chip including the data processing apparatus 400 as described above.

[0085] According to another aspect of the present disclosure, there is also provided an electronic device including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the above data processing method.

[0086] According to another aspect of the present disclosure, there is also provided a non-transitory computer-readable storage medium storing computer instructions, where the computer instructions are used to cause the computer to execute the above data processing method.

[0087] According to another aspect of the present disclosure, there is also provided a computer program product including a computer program, where the computer program implements the above data processing method when executed by a processor.

[0088] Reference Figure 5 Now, a block diagram of an electronic device 500 that can be a server or a client of the present disclosure will be described. It is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0089] As Figure 5 shown, the device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0090] Multiple components in the device 500 are connected to the I / O interface 505, including: an input unit 506, an output unit, 507, a storage unit 508, and a communication unit 509. The input unit 506 can be any type of device that can input information into the device 500. The input unit 506 can receive input digital or character information, and generate key signal inputs related to user settings and / or function controls of the electronic device, and can include, but is not limited to, a mouse, a keyboard, a touch screen, a trackpad, a trackball, a joystick, a microphone, and / or a remote control. The output unit 507 can be any type of device that can present information, and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 508 can include, but is not limited to, a magnetic disk, an optical disk. The communication unit 509 allows the device 500 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks, and can include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth device, an 802.11 device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0091] The computing unit 501 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 executes the various methods and processes described above, such as the data processing method. For example, in some embodiments, the data processing method can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as the storage unit 508. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device 500 via the ROM 502 and / or the communication unit 509. When the computer program is loaded into the RAM 503 and executed by the computing unit 501, one or more steps of the data processing method described above can be executed. Alternatively, in other embodiments, the computing unit 501 can be configured to execute the data processing method by any other suitable means (e.g., by means of firmware).

[0092] Various embodiments of the systems and techniques described above in this document can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor, and can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit the data and instructions to the storage system, the at least one input device, and the at least one output device.

[0093] The program code for implementing the methods of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the program codes are executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program codes can be executed entirely on the machine, partially on the machine, as an independent software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0094] In the context of this disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0095] In order to provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, speech input, or tactile input).

[0096] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.

[0097] A computer system may include a client and a server. The client and the server are generally far from each other and usually interact via a communication network. The relationship between the client and the server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server incorporating a blockchain.

[0098] It should be understood that various forms of the processes shown above can be used, steps can be reordered, added or deleted. For example, the steps described in this disclosure can be executed in parallel, sequentially or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and no limitation is imposed herein.

[0099] Although the embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it should be understood that the above methods, systems and devices are merely exemplary embodiments or examples, and the scope of the present invention is not limited by these embodiments or examples, but is only defined by the authorized claims and their equivalent scope. Various elements in the embodiments or examples can be omitted or replaced by their equivalent elements. In addition, the steps can be executed in a different order from that described in the present disclosure. Further, various elements in the embodiments or examples can be combined in various ways. Importantly, with the evolution of technology, many of the elements described herein can be replaced by equivalent elements that emerge after the present disclosure.

Claims

1. A data processing method, comprising: Obtaining a first target matrix to be calculated, wherein each element in the first target matrix is stored in a first storage unit in a first data format, and the first data format includes a floating point type; Dividing the first target matrix into a plurality of sub-matrices, wherein each sub-matrix of the plurality of sub-matrices includes a first preset number of elements; For each sub-matrix in the plurality of sub-matrices, Determine the maximum absolute value of each element in the submatrix based on the absolute value of each element in the submatrix; determining a reference maximum value Max represented in binary format and corresponding to the maximum absolute value, wherein a digit width of the reference maximum value Max is equal to the first preset number; For each element in the submatrix, determining a bit in the first storage unit used for storing the last mantissa of the element as a target bit to obtain a first preset number of target bits; Writing the reference maximum value Max into the first predetermined number of target bits; and For each element in the submatrix, read the reference maximum value Max from the first preset number of target bits, so as to convert the element into a conversion element in a second data format based on the reference maximum value Max; and A target calculation result is determined based on the conversion element and the target calculation type corresponding to each element in the first target matrix.

2. The method according to claim 1, wherein The second data format includes at least one exponent bit and a plurality of mantissa bits, and the conversion element of converting the element into the second data format based on the reference maximum value Max includes: Based on the digit width m of the exponent bit of the second data format and the reference maximum value Max, the interval [0, Max] is divided into 2 m consecutive subintervals; Determine the exponent bits of the conversion element corresponding to the element based on the subinterval in which the element is located; and Based on the subinterval in which the element is located and the digit width n of the mantissa of the second data format, the element is mapped to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to this element.

3. The method of claim 2, wherein: The digit width m of the exponent bit of the second data format and the reference maximum value Max are used to divide the interval [0, Max] into 2 m The continuous subintervals include: Based on the reference maximum value Max, using the formula OK (2 m -1) split point , where k is less than 2 m A positive integer of ; and According to the above (2 m -1) split points are the endpoints of the subintervals to divide the interval [0, Max] into 2 m consecutive subintervals.

4. The method of claim 3, wherein: The element is mapped to the range [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to the element includes: determining the absolute value a of the element; and In response to determining that the maximum endpoint value of the subinterval in which the element is located is , mapping the element to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to the element .

5. The method according to claim 1, wherein The second data format includes a plurality of mantissa bits, and the conversion element of converting the element into the second data format based on the reference maximum value Max includes: Determine the absolute value a of the element; Based on the reference maximum value Max, the element is mapped to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to the element .

6. The method according to any one of claims 2 to 5, wherein the first data format and the second data format further include one sign bit, and the sign bit of the conversion element corresponding to each element in the first target matrix is the same as the sign bit of the element.

7. The method according to any one of claims 1 to 5, further comprising: Get the second target matrix; For each element in the first target matrix and the second target matrix, a restoration factor corresponding to the element is determined, where the restoration factor satisfies the following condition: The conversion element corresponding to the element multiplied by the restoration factor corresponding to the element is equal to the absolute value of the element. And wherein, determining the target calculation result based on the conversion element and the target calculation type respectively corresponding to each element in the first target matrix includes: In response to determining that the target calculation type indicates that a multiplication calculation is to be performed based on the first target matrix and the second target matrix, based on the conversion elements corresponding to each element in the first target matrix and the second target matrix, the product of the first target matrix and the second target matrix is calculated as a result matrix, wherein the absolute value of each element in the result matrix is equal to the mantissa bits of the conversion element of the first element corresponding to the element in the first target matrix multiplied by the mantissa bits of the conversion element of the second element corresponding to the element in the second target matrix multiplied by the restoration factor corresponding to the first element multiplied by the restoration factor corresponding to the second element.

8. The method of claim 7, wherein: When the first data format and the second data format also include 1 sign bit, the sign bit of each element in the result matrix is the exclusive OR value of the sign bit of the first element corresponding to the element in the first target matrix and the sign bit of the second element corresponding to the element in the second target matrix.

9. A data processing device comprising: an acquiring unit configured to acquire a first target matrix to be calculated, wherein each element in the first target matrix is stored in a first storage unit in a first data format, and the first data format includes a floating point type; a dividing unit configured to divide the first target matrix into a plurality of sub-matrices, wherein each sub-matrix of the plurality of sub-matrices includes a first preset number of elements; a first determining unit configured to determine, for each submatrix of the plurality of submatrices, based on the absolute value of each element in the submatrix, a maximum absolute value of each element in the submatrix; a second determining unit configured to determine a reference maximum value Max represented in binary format and corresponding to the maximum absolute value, wherein a digit width of the reference maximum value Max is equal to the first preset number; a third determining unit configured to, for each element in the submatrix, determine a bit in the first storage unit for storing the last mantissa of the element as a target bit, so as to obtain a first preset number of target bits; A writing unit configured to write the reference maximum value Max into the first preset number of target bits; a conversion unit configured to, for each element in the submatrix, read the reference maximum value Max from the first preset number of target bits, so as to convert the element into a conversion element in a second data format based on the reference maximum value Max; and The calculation unit is configured to determine a target calculation result based on a conversion element and a target calculation type corresponding to each element in the first target matrix.

10. The device according to claim 9, wherein The second data format includes at least one exponent bit and a plurality of mantissa bits, and the conversion unit includes: The division subunit is configured to divide the interval [0, Max] into 2 based on the digit width m of the exponent bit of the second data format and the reference maximum value Max. m consecutive subintervals; A first determining subunit is configured to determine an exponent bit of a conversion element corresponding to the element based on the subinterval in which the element is located; and The second determining subunit is configured to map the element to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to this element.

11. The device according to claim 10, wherein The division subunit is configured to: Based on the reference maximum value Max, using the formula OK (2 m -1) split point , where k is less than 2 m A positive integer of ; and According to the above (2 m -1) split points are the endpoints of the subintervals to divide the interval [0, Max] into 2 m consecutive subintervals.

12. The device of claim 11, wherein: The second determining subunit is configured to: determining the absolute value a of the element; and In response to determining that the maximum endpoint value of the subinterval in which the element is located is , mapping the element to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to the element .

13. The apparatus of claim 9, wherein: The conversion unit is configured to: Determine the absolute value a of the element; Based on the reference maximum value Max, the element is mapped to [0, 2 n ] interval to determine the mantissa of the conversion element corresponding to the element .

14. The apparatus according to any one of claims 10 to 13, wherein the first data format and the second data format further include one sign bit, and the sign bit of the conversion element corresponding to each element in the first target matrix is the same as the sign bit of the element.

15. The device according to any one of claims 9 to 13, wherein: The acquisition unit is further configured to acquire a second target matrix, The device further comprises: The fourth determining unit is configured to determine, for each element in the first target matrix and the second target matrix, a restoration factor corresponding to the element, wherein the restoration factor satisfies the following condition: The conversion element corresponding to the element multiplied by the restoration factor corresponding to the element is equal to the absolute value of the element. And wherein the computing unit is configured to: In response to determining that the target calculation type indicates that a multiplication calculation is to be performed based on the first target matrix and the second target matrix, based on the conversion elements corresponding to each element in the first target matrix and the second target matrix, the product of the first target matrix and the second target matrix is calculated as a result matrix, wherein the absolute value of each element in the result matrix is equal to the mantissa bits of the conversion element of the first element corresponding to the element in the first target matrix multiplied by the mantissa bits of the conversion element of the second element corresponding to the element in the second target matrix multiplied by the restoration factor corresponding to the first element multiplied by the restoration factor corresponding to the second element.

16. The apparatus of claim 15, wherein: When the first data format and the second data format also include 1 sign bit, the sign bit of each element in the result matrix is the exclusive OR value of the sign bit of the first element corresponding to the element in the first target matrix and the sign bit of the second element corresponding to the element in the second target matrix.

17. A chip comprising the device according to any one of claims 9 to 16.

18. An electronic device comprising: at least one processor; as well as a memory communicatively coupled to the at least one processor; in The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.

19. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable a computer to execute the method according to any one of claims 1-8.

20. A computer program product comprising a computer program, wherein The computer program implements the method according to any one of claims 1 to 8 when executed by a processor.

Citation Information

Patent Citations

  • Data format conversion method and device and matrix processing method and device

    CN115237992A

  • Data processing method and device, electronic equipment, medium and chip

    CN115310035A