Floating point data precision conversion method and device and computer equipment

By constructing a lookup table and using linear function mapping using intermediate data accuracy BFP16, the problems of poor hardware adaptability and low computing efficiency in floating-point data accuracy conversion are solved, and simple and efficient precision conversion is achieved, which is suitable for a variety of floating-point precision conversion scenarios.

CN120353433AActive Publication Date: 2025-07-22VASTAI TECH (SHANGHAI) INC

Patent Information

Application Number
CN202510866611.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-07-22
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

In the prior art, floating-point data accuracy conversion methods have problems such as poor hardware adaptability, low computing efficiency and high conversion overhead. In particular, conversion between different precisions requires relying on software-layer simulation, resulting in a decrease in the utilization rate of the computing unit.

Method used

A lookup table is constructed to represent the correspondence between different floating point precisions, convert it through intermediate data accuracy BFP16, and use a linear function mapping from data to address to achieve simple and universal precision conversion.

Benefits of technology

It provides a simple and universal floating-point data accuracy conversion method, which can flexibly adapt to the conversion needs of different precisions, reduces hardware complexity and computing delays, and improves computing efficiency and hardware compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353433A_ABST
    Figure CN120353433A_ABST
Patent Text Reader

Abstract

The invention provides a floating point data precision conversion method and device and computer equipment, and relates to the technical field of data processing, in particular to the field of floating point precision data processing and the like. According to the implementation scheme, a lookup table used for representing the corresponding relation between first data precision and second data precision is constructed, the lookup table comprises a plurality of continuous addresses, and each address corresponds to the value of one second data precision; converting the target data having the first data precision to an intermediate data precision, which is different from the first data precision and the second data precision; the target data with the intermediate data precision is converted into a target address through a preset data-to-address mapping relation, the preset data-to-address mapping relation is used for representing a function between the data and the address, and the function takes the data as an independent variable and the address as a dependent variable and comprises parameters determined based on the range of the data; and determining target data with the second data precision from the lookup table based on the target address.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of data processing, particularly to fields such as floating-point precision data processing, and especially to a floating-point data precision conversion method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Art

[0002] Floating-point precision data conversion is a key technology in computer science and is widely used in fields such as deep learning, graphics processing, and high-performance computing. With the growth of the requirements for computing efficiency and data storage, the conversion between different precisions becomes particularly important. This conversion aims to optimize the numerical range, precision, and computing performance, while reducing the overhead of data storage and transmission to meet diverse requirements. The industry has been exploring more general conversion methods to meet the changing application requirements and performance expectations. Summary of the Invention

[0003] The present disclosure provides a floating-point data precision conversion method, apparatus, computer device, computer-readable storage medium, and computer program product.

[0004] According to one aspect of the present disclosure, there is provided a floating-point data precision conversion method, including: constructing a look-up table for representing the correspondence between a first data precision and a second data precision, wherein the look-up table includes a plurality of consecutive addresses, and each address corresponds to a value of the second data precision; converting target data having the first data precision into an intermediate data precision, where the intermediate data precision is different from the first data precision and the second data precision; converting the target data having the intermediate data precision into a target address through a preset data-to-address mapping relationship, where the preset data-to-address mapping relationship is used to represent the function between data and address, the function takes data as the independent variable and address as the dependent variable, and includes parameters determined based on the range of the data; and determining, based on the target address, the target data having the second data precision from the look-up table.

[0005] According to another aspect of the present disclosure, there is provided a floating-point data precision conversion device, including: a lookup table construction module configured to construct a lookup table representing the correspondence between a first data precision and a second data precision, wherein the lookup table includes a plurality of consecutive addresses, and each address corresponds to a value of the second data precision; an intermediate precision conversion module configured to convert target data with the first data precision into an intermediate data precision, which is different from the first data precision and the second data precision; a data-to-address conversion module configured to convert the target data with the intermediate data precision into a target address through a preset data-to-address mapping relationship, wherein the preset data-to-address mapping relationship is used to represent the function between data and address, the function takes data as an independent variable and address as a dependent variable, and includes parameters determined based on the range of data; and a data lookup module configured to determine, based on the target address, the target data with the second data precision from the lookup table.

[0006] According to another aspect of the present disclosure, there is provided a computer device, including: at least one processor; and a memory storing a computer program thereon, which, when executed by the at least one processor, causes the at least one processor to execute the method provided above in the present disclosure.

[0007] According to another aspect of the present disclosure, there is provided a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, causes the processor to execute the method provided above in the present disclosure.

[0008] According to another aspect of the present disclosure, there is provided a computer program product including a computer program, which, when executed by a processor, causes the processor to execute the method provided above in the present disclosure.

[0009] According to one or more embodiments of the present disclosure, simple and more general floating-point data precision conversion can be provided.

[0010] According to the embodiments described hereinafter, these and other aspects of the present disclosure will be apparent and will be elucidated with reference to the embodiments described hereinafter. Description of the Drawings

[0011] The drawings exemplarily illustrate embodiments and form a part of the specification, and are used together with the written description of the specification to explain the exemplary embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the present disclosure. In all the drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0012] Figure 1 is a schematic diagram illustrating a conventional floating-point data precision conversion method.

[0013] Figure 2 FIG. is a flowchart showing a floating-point data precision conversion method according to an exemplary embodiment.

[0014] Figure 3 FIG. is a schematic diagram showing a floating-point data precision conversion method according to an exemplary embodiment.

[0015] Figure 4 FIG. is a schematic block diagram showing a floating-point data precision conversion device according to an exemplary embodiment.

[0016] Figure 5 FIG. is a block diagram showing an exemplary computer device that can be applied to an exemplary embodiment. DETAILED DESCRIPTION

[0017] The following describes exemplary embodiments of the present disclosure with reference to the accompanying drawings. Various details of the embodiments of the present disclosure are included to assist 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.

[0018] 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, temporal 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.

[0019] 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 limiting. Unless the context clearly indicates otherwise, if the number of elements is not specifically limited, the element may be one or more. As used herein, the term "plurality" means two or more, and the term "based on" should be interpreted as "at least partially based on". In addition, the terms "and / or" and "at least one of..." cover any one of the listed items and all possible combinations.

[0020] In related technologies, various floating-point precisions are widely used in fields such as deep learning and high-performance computing, such as FP32, FP16, BFP16, FP8, FP6, FP4, etc., aiming to seek a balance among computing efficiency, memory occupancy, and model accuracy. For example, FP32 (32-bit floating-point number, single precision) is the traditional standard, which can provide high accuracy but has high computing and storage costs, and is suitable for the training stage. FP16 (16-bit floating-point number, half precision) and BFP16 (16-bit brain floating-point number) can reduce memory occupancy by reducing the bit width and are commonly used for inference acceleration, but need to be combined with dynamic range extension techniques (such as mixed-precision training) to avoid accuracy loss. FP8, FP6, and FP4 (8-bit, 6-bit, and 4-bit floating-point numbers, emerging low precisions) can be optimized for edge computing and artificial intelligence inference, significantly reducing power consumption, but require customized hardware support.

[0021] Figure 1 FIG. shows a schematic diagram of a traditional floating-point data precision conversion method.

[0022] Such as Figure 1 shown, taking the conversion from FP8 to FP16, BFP16, FP32, and FP6 as examples, each precision conversion requires specific conversion logic, such as specific hardware implementation. Due to the numerous and complex types of conversions, it may bring about complex redundancy of hardware, resulting in the inability to expand when new precisions appear after the hardware is designed.

[0023] In addition, the traditional floating-point data precision conversion method also has the problem of poor hardware adaptability, where traditional GPUs (graphics processing units) or ASICs (application-specific integrated circuits) have insufficient support for emerging precisions, resulting in low computing efficiency. Additionally, the conversion overhead is relatively high because the conversion between different precisions relies on software layer simulation, which may introduce additional latency. For example, the conversion from FP32 to FP16 requires frequent adjustment of the exponent offset, which may lead to a decrease in the utilization rate of the computing unit.

[0024] Therefore, the embodiments of the present disclosure provide a floating-point data precision conversion method that can provide precision conversion in a simple manner, and the method has universality and scalability.

[0025] Figure 2 FIG. shows a flowchart of a floating-point data precision conversion method 200 according to an exemplary embodiment.

[0026] Such as Figure 2 shown, the method 200 includes steps S201, S202, S203, and S204.

[0027] In step S201, a look-up table for representing the correspondence between a first data precision and a second data precision is constructed. The look-up table includes a plurality of consecutive addresses, and each address corresponds to a value of the second data precision.

[0028] In this text, the first data precision and the second data precision refer to two precisions before and after conversion. For example, when converting from FP16 to FP8, FP16 is the first data precision and FP8 is the second data precision. Since the second data precision is the target format of the precision conversion, the look-up table is constructed for this second data precision. Each address can represent an entry in the look-up table, that is, an address entry, and a value in the target format is correspondingly stored under this address entry. Therefore, the look-up table can be pre-configured.

[0029] In the example, the floating-point data precision conversion method of the present disclosure embodiment can support conversion between any precisions. However, when the bit widths of the precisions to be converted, that is, the bit widths of the first data precision and the second data precision, are both large, it may lead to a large structure of the look-up table. Therefore, this method can also be preferably applied to the conversion from a precision with a large bit width to a precision with a small bit width.

[0030] In step S202, the target data with the first data precision is converted into an intermediate data precision. This intermediate data precision is different from the first data precision and the second data precision.

[0031] In the example, when neither the first data precision nor the second data precision is BFP16, the intermediate data precision can be selected as BFP16. BFP16 can represent a numerical range similar to FP32, that is, the dynamic range of the data can be maintained. In addition, BFP16 is a format optimized for deep learning inference, and many deep learning hardware has native support for BFP16, which enables the full utilization of the optimization features of these hardware. Therefore, a balance among the numerical range, precision, performance, and hardware compatibility can be achieved during the precision conversion process.

[0032] In step S203, the target data with the intermediate data precision is converted into a target address through a preset data-to-address mapping relationship. This preset data-to-address mapping relationship is used to represent the function between data and address. This function takes data as the independent variable and address as the dependent variable, and includes parameters determined based on the range of the data.

[0033] In the example, the function of this data-to-address mapping relationship can be a linear function or a non-linear function, or this function can also be expressed through a look-up table, as long as one numerical value can be mapped to another numerical value based on a mathematical method. The parameters in the function are not fixed, but are determined according to the data range of the input target data, which can ensure the accuracy and flexibility of the function mapping.

[0034] In step S204, based on the target address, the target data with the second data precision is determined from the look-up table.

[0035] In the example, the data precision corresponding to the target address can be found from the look-up table, i.e., the second data precision, for output.

[0036] Thus, the method of the embodiments of the present disclosure can provide simple and general floating-point data precision conversion. In this process, there is no need to use specific conversion logic for each precision conversion as in the traditional method. Instead, a look-up table for converting between various precisions can be pre-constructed, with the address as the look-up entry in the look-up table, and the precision conversion can be achieved by mapping the data to be converted to this address. In addition, if more emerging precisions appear in the future, only by adapting according to this method on the basis of meeting the precision rules, the conversion for these emerging precisions can be achieved, so this method also has great scalability.

[0037] In some embodiments, the first data precision and the second data precision may each include a floating-point precision of multiple bits, and the number of multiple addresses in the look-up table may be determined based on the multiple bits of either the first data precision or the second data precision.

[0038] In the example, when converting from a precision with a larger bit width to a precision with a smaller bit width, that is, the bit width of the second data precision is smaller than the bit width of the first data precision, the number of multiple addresses in the look-up table can be determined based on the smaller bit width of the second data precision. For example, the look-up table for FP8 may have 256 (i.e., 2^8) addresses, the look-up table for FP6 may have 64 (i.e., 2^6) addresses, and the look-up table for FP4 may have 16 (i.e., 2^4) addresses. In this case, the data stored corresponding to each address entry in the look-up table can be determined based on the numerical range of the second data precision itself. For example, when the second data precision is FP8, the first address of the second data precision can store the data 8’b11111111, and so on, and the two hundred and fifty-sixth address can store the data 8’b01111111.

[0039] In the example, when converting from a precision with a smaller bit width to a precision with a larger bit width, that is, the bit width of the second data precision is greater than the bit width of the first data precision, as described above, in this case, it may result in a larger structure of the look-up table. Therefore, the number of multiple addresses in the look-up table can also be considered to be determined based on the smaller bit width of the first data precision. In this case, the data stored corresponding to each address entry in the look-up table can be correspondingly determined based on the numerical range of the first data precision. For example, when the first data precision is FP8 and the second data precision is FP16, the first address of the second data precision can store the FP16 format data corresponding to the FP8 format data 8’b11111111, and so on, and the two hundred and fifty-sixth address can store the FP16 format data corresponding to the FP8 format data 8’b01111111.

[0040] In this way, it is beneficial to flexibly determine how to construct the lookup table according to the address entries based on the bit widths of the first data precision and the second data precision.

[0041] In some embodiments, in response to one of the first data precision and the second data precision being 8-bit floating-point precision and the other being 16-bit floating-point precision, the lookup table may include 256 addresses.

[0042] In an example, taking the conversion from FP16 to FP8 as an example, Table 1 below shows the lookup table for FP8. This situation may be similar to the situation of converting a precision with a larger bit width to a precision with a smaller bit width as described above. Therefore, the data stored corresponding to each address entry in the lookup table can be determined based on the numerical range of FP8 itself. For example, in the lookup table for FP8 shown in Table 1, it can be determined based on the numerical range of FP8 itself, which is 8’b11111111~8’b01111111. As shown in Table 1, the value of the first address in the lookup table can start from "0" and increase sequentially. Therefore, the value of the two hundred and fifty-sixth address can be "255". Correspondingly, the FP8 format data corresponding to addresses "0" to "127" is negative, and the FP8 format data corresponding to addresses "129" to "255" is positive.

[0043] Table 1

[0044] In an example, contrary to the above example, when the conversion from FP8 to FP16 is required, this situation may be similar to the situation of converting a precision with a smaller bit width to a precision with a larger bit width as described above. Therefore, the data stored corresponding to each address entry in the lookup table can also be determined correspondingly based on the numerical range of FP8. For example, the first address of the second data precision can store the FP16 format data corresponding to the FP8 format data 8’b11111111, and so on. The two hundred and fifty-sixth address can store the FP16 format data corresponding to the FP8 format data 8’b01111111.

[0045] In this way, when performing the precision conversion between FP8 and FP16, it is possible to simply determine the number of address entries in the lookup table based on FP8, which helps to simplify the construction of the lookup table.

[0046] In some embodiments, the above-mentioned preset data-to-address mapping relationship may include at least one linear function. Correspondingly, the parameters in the function may include the slopes and intercepts of the at least one linear function respectively. In this case, as combined with Figure 2The step S203 may include: determining a slope and an intercept corresponding to a corresponding linear function segment for conversion in the at least one linear function segment based on a range of target data with a first data precision; and converting the target data with an intermediate data precision into a target address based on the slope and the intercept.

[0047] In an example, taking the conversion from FP16 to FP8 as an example, two linear function segments can be configured to convert the data into a suitable address. Correspondingly, the slope A0 and the intercept B0 of the first segment can satisfy the expression: 255 = FP16_min × A0 + B0, and the slope A1 and the intercept B1 of the second segment can satisfy the expression: 0 = FP16_max × A1 + B1, where FP16_min and FP16_max respectively represent the minimum value and the maximum value in the FP16 format data. The segmentation of the linear function can be determined according to the minimum value and the maximum value in the FP8 format data. Since the FP16 format data can cover a larger numerical range than the FP8 format data, the target data of FP16 to be converted may be less than the minimum value FP8_min in the FP8 format data, or may be between the minimum value FP8_min and the maximum value FP8_max in the FP8 format data. Correspondingly, for the case less than the minimum value FP8_min, the slope A0 and the intercept B0 of the first segment can be selected, and for the case between the minimum value FP8_min and the maximum value FP8_max, the slope A1 and the intercept B1 of the second segment can be selected.

[0048] Similarly, for the conversion from FP8 to FP16, two linear function segments can also be configured to convert the data into a suitable address. The slope A0 and the intercept B0 of the first segment can take values, for example, A0 = 2^8, B0 = 0, and the slope A1 and the intercept B1 of the second segment can take values, for example, A1 = -2^7, B1 = -255 / 2^7. The segmentation of the linear function can be determined, for example, according to the following three values: FP16_0 = 16'b0011111100000000, FP16_1 = 16'b0011111110000000, FP16_2 = 16'b0011111111111111. Since the FP8 format data covers a smaller numerical range than the FP16 format data, the value FP16_2 = 16'b0011111111111111 may not be used for comparison among the above three values. Correspondingly, similar to the above conversion from FP16 to FP8, for the case less than the FP16_0, the slope A0 and the intercept B0 of the first segment can be selected, and for the case between the FP16_0 and the FP16_1, the slope A1 and the intercept B1 of the second segment can be selected.

[0049] Thus, in some embodiments, it can be understood that the range of the target data with the second data precision may include a first threshold and a second threshold greater than the first threshold. For example, in the conversion example from FP16 to FP8, the first threshold and the second threshold may be the minimum value FP8_min and the maximum value FP8_max in the FP8 format data. In the conversion example from FP8 to FP16, the first threshold and the second threshold may be the two values FP16_0 and FP16_1 as described above.

[0050] In this case, the above steps of determining the slope and the intercept may include: in response to the target data with the first data precision being negative, determining whether the target data is less than the first threshold or between the first threshold and the second threshold; in response to determining that the target data is less than the first threshold, determining to use the first slope and the first intercept corresponding to the first linear function; and in response to determining that the target data is between the first threshold and the second threshold, determining to use the second slope and the second intercept corresponding to the second linear function.

[0051] In the example, taking the conversion from FP8 to FP16 as an example, when the value of the FP8 format data is negative, it can be first determined whether the value is between the first threshold and the second threshold or less than the first threshold. If it is less than the first threshold, the first set of slope A0 and intercept B0 can be selected to calculate the corresponding address, and if it is between the first threshold and the second threshold, the second set of slope A1 and intercept B1 can be selected to calculate the corresponding address.

[0052] Therefore, by segmenting the function and selecting the corresponding slope and intercept for each segment, the input data can be more precisely mapped to the output data, and the flexibility and adaptability of the method can be increased, thereby more effectively processing the dynamic range of the data.

[0053] In some embodiments, the above step of converting the target data into a target address based on the slope and the intercept may include: multiplying the target data with the intermediate data precision by the slope via a multiplier to obtain a multiplication result; and adding the multiplication result to the intercept via an adder to obtain the target address, where the multiplier and the adder support the calculation of the intermediate data precision.

[0054] In the example, the intermediate data precision may be BFP16, so the multiplier and the adder can support this precision BFP16. A ceiling or floor function may be applied to the addition result obtained by adding the multiplication result and the intercept.

[0055] Thus, the multiplication and addition of the target data with the intermediate data precision are realized through the multiplier and the adder, and it is linearly converted into an address with the target precision.

[0056] Figure 3FIG. is a schematic diagram showing a floating-point data precision conversion method according to an exemplary embodiment.

[0057] As Figure 3 shown, the input target data has a first data precision and is converted into an address via data-to-address mapping to determine a corresponding second data precision from a look-up table according to the address, thereby converting the first data precision into the second data precision for output. For this data-to-address mapping, the slope A and intercept B of a linear function are determined according to the data range of the target data, as Figure 3 shown by A0, B0……An, Bn (n is a natural number), and the data is converted into an address by means of multiplication and addition. A rounding-up or rounding-down function can be applied to the result of the multiplication and addition. Thus, the look-up table can be read according to this address to determine the corresponding target precision, i.e., the second data precision, from multiple address entries data0, data1……datan (n is a natural number) of the look-up table for output.

[0058] Embodiments of the present disclosure also provide a floating-point data precision conversion device.

[0059] Figure 4 FIG. is a schematic block diagram showing a floating-point data precision conversion device 400 according to an exemplary embodiment.

[0060] As Figure 4 shown, the device 400 includes a look-up table construction module 401, an intermediate precision conversion module 402, a data-to-address conversion module 403, and a data search module 404.

[0061] The look-up table construction module 401 is configured to construct a look-up table for representing the correspondence between the first data precision and the second data precision. The look-up table includes a plurality of consecutive addresses, and each address corresponds to a value of the second data precision.

[0062] The intermediate precision conversion module 402 is configured to convert the target data having the first data precision into an intermediate data precision, which is different from the first data precision and the second data precision.

[0063] The data-to-address conversion module 403 is configured to convert the target data having the intermediate data precision into a target address through a preset data-to-address mapping relationship. The preset data-to-address mapping relationship is used to represent the function between the data and the address, the function takes the data as the independent variable and the address as the dependent variable, and includes parameters determined based on the range of the data.

[0064] The data search module 404 is configured to determine the target data having the second data precision from the look-up table based on the target address.

[0065] The operations of the above-mentioned lookup table construction module 401, intermediate precision conversion module 402, data-to-address conversion module 403, and data lookup module 404 can be combined with Figure 2 the operations of steps S201, S202, S203, and S204 described above, and thus details of each aspect thereof will not be elaborated here.

[0066] In some embodiments, the preset data-to-address mapping relationship includes at least one segment of a linear function, and the parameters include the slope and intercept of each of the at least one segment of the linear function. Correspondingly, the data-to-address conversion module 403 may include: a parameter determination module 4031, configured to determine the slope and intercept corresponding to the corresponding segment of the linear function for conversion in the at least one segment of the linear function based on the range of the target data with the first data precision; and a conversion execution module 4032, configured to convert the target data with the intermediate data precision into a target address based on the slope and intercept.

[0067] In some embodiments, the range of the target data with the second data precision includes a first threshold and a second threshold greater than the first threshold. Correspondingly, the parameter determination module 4031 may include: a first sub-determination module 4031a, configured to determine whether the target data with the first data precision is less than the first threshold or between the first threshold and the second threshold in response to the target data being negative; a second sub-determination module 4031b, configured to determine to use the first slope and the first intercept corresponding to the first segment of the linear function in response to determining that the target data is less than the first threshold; and a third sub-determination module 4031c, configured to determine to use the second slope and the second intercept corresponding to the second segment of the linear function in response to determining that the target data is between the first threshold and the second threshold.

[0068] In some embodiments, the conversion execution module 4032 may include: a multiplication execution module 4032a, configured to multiply the target data with the intermediate data precision by the slope via a multiplier to obtain a multiplication result; and an addition execution module 4032b, configured to add the multiplication result to the intercept via an adder to obtain a target address. The multiplier and the adder support calculations with intermediate data precision.

[0069] Although the specific functions have been discussed above with reference to specific modules, it should be noted that the functions of the various modules discussed herein can be divided into multiple modules, and / or at least some of the functions of multiple modules can be combined into a single module. The specific actions performed by the specific modules discussed herein include the specific module itself performing the action, or alternatively the specific module calling or otherwise accessing another component or module that performs the action (or performs the action in combination with the specific module). Therefore, the specific module that performs the action may include the specific module itself that performs the action and / or another module that the specific module calls or otherwise accesses and that performs the action.

[0070] It should also be understood that each of the modules described above Figure 4 can be implemented in hardware or in hardware in combination with software and / or firmware. For example, these modules can be implemented as computer program code / instructions configured to be executed in one or more processors and stored in a computer-readable storage medium. Alternatively, these modules can be implemented as hardware logic / circuits. For example, these modules can be implemented together in a System on Chip (SoC). The SoC can include an integrated circuit chip (which includes one or more components such as a processor (e.g., a Central Processing Unit (CPU), a microcontroller, a microprocessor, a Digital Signal Processor (DSP), etc.), a memory, one or more communication interfaces, and / or other circuits), and can optionally execute the received program code and / or include embedded firmware to perform functions.

[0071] According to one aspect of the present disclosure, there is provided a computer device including a memory, a processor, and a computer program stored on the memory. The processor is configured to execute the computer program to implement the steps of any of the method embodiments described above.

[0072] According to one aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of any of the method embodiments described above are implemented.

[0073] According to one aspect of the present disclosure, there is provided a computer program product including a computer program, and when the computer program is executed by a processor, the steps of any of the method embodiments described above are implemented.

[0074] Hereinafter, illustrative examples of such computer devices, non-transitory computer-readable storage media, and computer program products will be described in conjunction with Figure 5 the description.

[0075] Figure 5 FIG. shows an example configuration of a computer device 500 that can be used to implement the methods described herein.

[0076] The computer device 500 can be various different types of devices. Examples of the computer device 500 include, but are not limited to: desktop computers, server computers, laptop or netbook computers, mobile devices (e.g., tablet computers, cellular or other wireless telephones (e.g., smart phones), notepad computers, mobile stations), wearable devices (e.g., glasses, watches), entertainment devices (e.g., entertainment appliances, set-top boxes communicatively coupled to a display device, game consoles), televisions or other display devices, automotive computers, and so on.

[0077] The computer device 500 can include at least one processor 502, a memory 504, one or more communication interfaces 506, a display device 508, other input / output (I / O) devices 510, and one or more mass storage devices 512 that are capable of communicating with each other, such as via a system bus 514 or other suitable connections.

[0078] The processor 502 can be a single processing unit or multiple processing units, and all processing units can include a single or multiple computing units or multiple cores. The processor 502 can be implemented as one or more microprocessors, microcomputers, microcontrollers, digital signal processors, central processing units, state machines, logic circuits, and / or any device that manipulates signals based on operation instructions. Among other capabilities, the processor 502 can be configured to obtain and execute computer-readable instructions stored in the memory 504, the mass storage device 512, or other computer-readable media, such as program code of an operating system 516, program code of an application 518, program code of other programs 520, and so on.

[0079] The memory 504 and the mass storage device 512 are examples of computer-readable storage media for storing instructions that are executed by the processor 502 to implement the various functions described above. For example, the memory 504 generally can include both volatile and non-volatile memories (e.g., RAM, ROM, etc.). In addition, the mass storage device 512 generally can include a hard disk drive, a solid state drive, removable media, including external and removable drives, memory cards, flash memory, floppy disks, optical discs (e.g., CDs, DVDs), storage arrays, network-attached storage, storage area networks, and so on. The memory 504 and the mass storage device 512 can both be collectively referred to as memory or computer-readable storage media in this document, and can be non-transitory media capable of storing computer-readable, processor-executable program instructions as computer program code that can be executed by the processor 502 as a specific machine configured to implement the operations and functions described in the examples herein.

[0080] Multiple programs can be stored on the mass storage device 512. These programs include an operating system 516, one or more application programs 518, other programs 520, and program data 522, and they can be loaded into the memory 504 for execution. Examples of such application programs or program modules can include, for example, the method 200 as shown in Figure 2 and / or the computer program logic (e.g., computer program code or instructions) of additional embodiments described herein.

[0081] Although illustrated as being stored in the memory 504 of the computer device 500 in Figure 5 , the modules 516, 518, 520, and 522 or portions thereof can be implemented using any form of computer-readable medium accessible by the computer device 500. As used herein, "computer-readable medium" includes at least two types of computer-readable media, namely computer-readable storage media and communication media.

[0082] Computer-readable storage media includes volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer-readable storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVDs), or other optical storage devices, magnetic cassettes, magnetic tapes, magnetic disk storage devices or other magnetic storage devices, or any other non-transitory medium that can be used to store information accessible by a computer device. In contrast, communication media can embody computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transmission mechanism. Computer-readable storage media as defined herein does not include communication media.

[0083] One or more communication interfaces 506 are used to exchange data with other devices, such as via a network, direct connection, etc. Such communication interfaces can be one or more of the following: any type of network interface (e.g., network interface card (NIC)), wired or wireless (such as IEEE 802.11 wireless LAN (WLAN)) wireless interface, Worldwide Interoperability for Microwave Access (WiMAX) interface, Ethernet interface, Universal Serial Bus (USB) interface, cellular network interface, Bluetooth TMCommunication interfaces, such as a near field communication (NFC) interface, etc. The communication interface 506 can facilitate communication within a variety of network and protocol types, including wired networks (such as LAN, cable, etc.) and wireless networks (such as WLAN, cellular, satellite, etc.), the Internet, etc. The communication interface 506 can also provide communication with external storage devices (not shown) such as those in storage arrays, network attached storage, storage area networks, etc.

[0084] In some examples, a display device 508, such as a monitor, can be included for displaying information and images to a user. Other I / O devices 510 can be devices that receive various inputs from a user and provide various outputs to the user, and can include touch input devices, gesture input devices, cameras, keyboards, remote controls, mice, printers, audio input / output devices, etc.

[0085] The techniques described herein can be supported by these various configurations of the computer device 500 and are not limited to the specific examples of the techniques described herein. For example, the functionality can also be implemented in whole or in part using a distributed system on a "cloud". The cloud includes and / or represents a platform for resources. The platform abstracts the underlying functionality of the hardware (e.g., servers) and software resources of the cloud. Resources can include applications and / or data that can be used when performing computational processing on servers remote from the computer device 500. Resources can also include services provided over the Internet and / or over a subscriber network such as a cellular or Wi-Fi network. The platform can abstract the resources and functionality to connect the computer device 500 with other computer devices. Thus, the implementation of the functionality described herein can be distributed throughout the cloud. For example, the functionality can be implemented partially on the computer device 500 and partially through a platform that abstracts the functionality of the cloud.

Claims

1. A floating-point data precision conversion method, characterized in that, The method includes: Constructing a look-up table for representing the correspondence between a first data precision and a second data precision, wherein the look-up table includes a plurality of consecutive addresses, and each address corresponds to a value of the second data precision; Converting target data having the first data precision into an intermediate data precision, the intermediate data precision being different from the first data precision and the second data precision; Converting the target data having the intermediate data precision into a target address through a preset data-to-address mapping relationship, wherein the preset data-to-address mapping relationship is used to represent a function between data and an address, the function taking the data as an independent variable and the address as a dependent variable, and including parameters determined based on the range of the data; and Determining the target data having the second data precision from the look-up table based on the target address.

2. The method according to claim 1, wherein The first data precision and the second data precision respectively include floating-point precisions of a plurality of bits, and the number of the plurality of addresses of the look-up table is determined based on any one of the plurality of bits of the first data precision or the second data precision.

3. The method according to claim 2, characterized in that In response to one of the first data precision and the second data precision being an 8-bit floating-point precision and the other being a 16-bit floating-point precision, the look-up table includes 256 addresses.

4. The method according to any one of claims 1 to 3, characterized in that, The preset data-to-address mapping relationship includes at least one segment of a linear function, and the parameters include the slope and intercept of each of the at least one segment of the linear function. The converting the target data having the intermediate data precision into a target address through the preset data-to-address mapping relationship includes: Determining the slope and the intercept corresponding to the corresponding segment of the linear function for conversion in the at least one segment of the linear function based on the range of the target data having the first data precision; and Converting the target data having the intermediate data precision into the target address based on the slope and the intercept.

5. The method according to claim 4, wherein The range of the target data having the second data precision includes a first threshold and a second threshold greater than the first threshold. The determining the slope and the intercept corresponding to the corresponding segment of the linear function for conversion in the at least one segment of the linear function based on the range of the target data having the first data precision includes: In response to the target data having the first data precision being negative, determining whether the target data is less than the first threshold or between the first threshold and the second threshold; In response to determining that the target data is less than the first threshold, determining to use the first slope and the first intercept corresponding to the first segment of the linear function; and In response to determining that the target data is between the first threshold and the second threshold, determining to use the second slope and the second intercept corresponding to the second segment of the linear function.

6. The method according to claim 4, characterized in that The converting the target data having the intermediate data precision into the target address based on the slope and the intercept includes: Multiplying the target data having the intermediate data precision by the slope via a multiplier to obtain a multiplication result; and The multiplied result is added to the intercept via an adder to obtain the target address, where the multiplier and the adder support calculations with the intermediate data precision.

7. A floating-point data precision conversion device, characterized in that The device includes: A lookup table construction module configured to construct a lookup table for representing the correspondence between a first data precision and a second data precision, where the lookup table includes a plurality of consecutive addresses, and each address corresponds to a value of the second data precision; An intermediate precision conversion module configured to convert target data with the first data precision into an intermediate data precision, where the intermediate data precision is different from the first data precision and the second data precision; A data-to-address conversion module configured to convert the target data with the intermediate data precision into a target address through a preset data-to-address mapping relationship, where the preset data-to-address mapping relationship is used to represent a function between data and an address, the function takes the data as an independent variable and the address as a dependent variable, and includes parameters determined based on the range of the data; and A data lookup module configured to determine the target data with the second data precision from the lookup table based on the target address.

8. A computer device, characterized in that, The computer device includes: At least one processor; and A memory storing a computer program thereon, where when the computer program is executed by the at least one processor, the at least one processor is caused to execute the method according to any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the processor is caused to execute the method according to any one of claims 1-6.

10. A computer program product, characterized in that, The computer program product includes a computer program, and when the computer program is executed by a processor, the processor is caused to execute the method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Calculation device and method of non-linear function

    CN107589935A

  • Mechanism to perform single precision floating point extended math operations

    CN111796795A

  • Precision conversion method and device, data processing method, processor and electronic equipment

    CN118170347A

  • Method, apparatus, device, medium and program product for precision conversion

    CN118690797A

  • Residue number arithmetic logic unit

    US20130311532A1

Cited By

  • Efficient format conversion method

    CN121742797A