Floating point data precision conversion method, device and computer equipment

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

CN120353433BActive Publication Date: 2025-10-28VASTAI TECH (SHANGHAI) INC
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In existing technologies, floating-point data precision conversion methods suffer from poor hardware adaptability, low computational efficiency, and high conversion overhead, especially in the conversion between different precisions, which is difficult to extend and optimize.

Method used

By constructing a lookup table to represent the correspondence between different data precisions, using the intermediate data precision BFP16 for conversion, and using the data-to-address mapping relationship, a simple and universal floating-point data precision conversion is achieved.

Benefits of technology

It provides a simple and universal method for converting floating-point data precision, which can flexibly adapt to the conversion requirements of different precisions, reduce hardware complexity and computation latency, and improve computational efficiency and hardware compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353433B_ABST
    Figure CN120353433B_ABST
Patent Text Reader

Abstract

This disclosure provides a method, apparatus, and computer device for converting floating-point data precision, relating to the field of data processing technology, and particularly to the field of floating-point precision data processing. The implementation scheme includes: constructing a lookup table to represent the correspondence between a first data precision and a second data precision, the lookup table comprising multiple consecutive addresses, each address corresponding to a value of the second data precision; converting target data with the first data precision into an intermediate data precision, which differs from the first and second data precisions; converting the target data with the intermediate data precision into a target address through a preset data-to-address mapping relationship, the preset data-to-address mapping relationship representing a function between data and address, the function having data as the independent variable and address as the dependent variable, and including parameters determined based on the range of the data; and determining the 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] This disclosure relates to the field of data processing technology, particularly to the field of floating-point precision data processing, and especially to a floating-point data precision conversion method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Technology

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

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

[0004] According to one aspect of this disclosure, a floating-point data precision conversion method is provided, comprising: constructing a lookup table for representing the correspondence between a first data precision and a second data precision, wherein the lookup table includes a plurality of consecutive addresses, each address corresponding 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 address, the function having data as an independent variable and address as a dependent variable, and including parameters determined based on the range of data; and determining the target data having the second data precision from the lookup table based on the target address.

[0005] According to another aspect of this disclosure, a floating-point data precision conversion apparatus is provided, comprising: a lookup table construction module configured to construct a lookup table representing a correspondence between a first data precision and a second data precision, wherein the lookup table includes a plurality of consecutive addresses, each address corresponding to a value of the second data precision; an intermediate precision conversion module configured to convert target data having the first data precision into intermediate data precision, the intermediate data precision being different from the first data precision and the second data precision; a data-to-address conversion module configured to convert 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 address, the function having data as an independent variable and address as a dependent variable, and including parameters determined based on the range of the data; and a data lookup module configured to determine target data having the second data precision from the lookup table based on the target address.

[0006] According to another aspect of this disclosure, a computer device is provided, comprising: at least one processor; and a memory having a computer program stored thereon, wherein the computer program, when executed by the at least one processor, causes the at least one processor to perform the methods provided above in this disclosure.

[0007] According to another aspect of this disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, causes the processor to perform the methods provided above in this disclosure.

[0008] According to another aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, causes the processor to perform the methods provided above in this disclosure.

[0009] According to one or more embodiments of this disclosure, a simpler and more universal floating-point data precision conversion can be provided.

[0010] These and other aspects of this disclosure will be apparent from the embodiments described below, and will be elucidated with reference to the embodiments described below. Attached Figure Description

[0011] The accompanying drawings exemplify embodiments and form part of the specification, serving together with the textual description to explain exemplary implementations of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of this disclosure. Throughout the drawings, the same reference numerals refer to similar but not necessarily identical elements.

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

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

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

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

[0016] Figure 5 This is a block diagram illustrating an exemplary computer device that can be applied to an exemplary embodiment. Detailed Implementation

[0017] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0018] In this disclosure, unless otherwise stated, the use of terms such as "first," "second," etc., to describe various elements is not intended to limit the positional, temporal, or importance relationships of these elements; such terms are merely used to distinguish one element from another. In some examples, the first element and the second element may refer to the same instance of that element, while in other cases, based on the context, they may refer to different instances.

[0019] The terminology used in the description of the various examples described in this disclosure is for the purpose of describing particular examples only and is not intended to be limiting. Unless the context explicitly indicates otherwise, an element may be one or more unless the number of elements is specifically limited. As used herein, the term "multiple" means two or more, and the term "based on" should be interpreted as "at least partially based on". Furthermore, the terms "and / or" and "at least one of..." cover any one of the listed items and all possible combinations thereof.

[0020] In related technologies, deep learning, high-performance computing, and other fields widely use various floating-point precisions, such as FP32, FP16, BFP16, FP8, FP6, and FP4, aiming to strike a balance between computational efficiency, memory usage, and model accuracy. For example, FP32 (32-bit floating-point, single precision) is the traditional standard, providing high precision but with high computational and storage costs, suitable for the training phase. FP16 (16-bit floating-point, half precision) and BFP16 (16-bit brain floating-point) can reduce memory usage by lowering the bit width and are often used for inference acceleration, but need to be combined with dynamic range expansion techniques (such as mixed precision training) to avoid precision loss. FP8, FP6, and FP4 (8-bit, 6-bit, and 4-bit floating-point, emerging low precision) can be optimized for edge computing and artificial intelligence inference, significantly reducing power consumption, but require customized hardware support.

[0021] Figure 1 This is a schematic diagram illustrating the traditional floating-point data precision conversion method.

[0022] like Figure 1 As shown, taking the conversion from FP8 to FP16, BFP16, FP32, and FP6 as examples, each precision conversion requires specific conversion logic, which necessitates specific hardware implementation. Due to the large number and complexity of conversion types, this may lead to complex and redundant hardware, making it impossible to expand to new precisions once the hardware design is finalized.

[0023] Furthermore, traditional floating-point data precision conversion methods also suffer from poor hardware adaptability. Traditional GPUs (Graphics Processing Units) or ASICs (Application-Specific Integrated Circuits) do not adequately support emerging precisions, leading to low computational efficiency. In addition, the conversion overhead is relatively high because the conversion between different precisions relies on software-level simulation, which may introduce additional latency. For example, the conversion from FP32 to FP16 requires frequent adjustments to the exponent offset, which may lead to a decrease in the utilization of computing units.

[0024] Therefore, embodiments of this disclosure provide a floating-point data precision conversion method that can provide precision conversion in a simple manner, and the method is universal and scalable.

[0025] Figure 2 This is a flowchart illustrating a floating-point data precision conversion method 200 according to an exemplary embodiment.

[0026] like Figure 2 As shown, method 200 includes steps S201, S202, S203 and S204.

[0027] In step S201, a lookup table is constructed to represent the correspondence between the first data precision and the second data precision. The lookup table includes a series of consecutive addresses, each address corresponding to a value of the second data precision.

[0028] In this paper, "first data precision" and "second data precision" refer to the two different precisions before and after the conversion. For example, when converting from FP16 to FP8, FP16 represents the first data precision, and FP8 represents the second data precision. Since the second data precision is the target format for the precision conversion, the lookup table is constructed specifically for this second data precision. Each address can represent an entry in the lookup table, i.e., an address entry, under which a value in the target format is stored. Therefore, the lookup table is pre-configurable.

[0029] In the example, the floating-point data precision conversion method of this disclosure embodiment can support conversion between arbitrary precisions. However, when the bit width of the precision to be converted, i.e., the bit width of the first data precision and the second data precision, is large, it may result in a large lookup table structure. Therefore, this method is also preferably applicable to the conversion between precisions with large bit widths and precisions with small bit widths.

[0030] In step S202, the target data with a 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 nor the second data precision is BFP16, the intermediate data precision can be BFP16. BFP16 can represent a numerical range similar to FP32, thus preserving the dynamic range of the data. Furthermore, BFP16 is a format optimized for deep learning inference, and many deep learning hardware devices natively support it, allowing full utilization of their optimization features. Therefore, a balance can be achieved between numerical range, precision, performance, and hardware compatibility during precision conversion.

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

[0033] In the example, the function mapping this data to an address can be a linear or non-linear function, or it can be expressed using a lookup table, as long as it can map one numerical value to another based on mathematical methods. The parameters in the function are not fixed but are determined based on the range of the input target data, which ensures the accuracy and flexibility of the function mapping.

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

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

[0036] Therefore, the method of this disclosure provides a simple and universal floating-point data precision conversion. Unlike traditional methods that use specific conversion logic for each precision conversion, this method pre-constructs lookup tables for various precision conversions, using addresses as lookup entries. Precision conversion is achieved by mapping the data to be converted to those addresses. Furthermore, if newer precisions emerge in the future, conversions for these new precisions can be implemented simply by adapting the method to meet the precision rules, thus demonstrating significant scalability.

[0037] In some embodiments, the first data precision and the second data precision may each include multiple bits of floating-point precision, and the number of multiple addresses of the lookup 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 a conversion between a larger and a smaller precision is required (i.e., the second data precision has a smaller bit width than the first data precision), the number of addresses in the lookup table can be determined based on the smaller bit width of the second data precision. For example, an FP8 lookup table can have 256 (2^8) addresses, an FP6 lookup table can have 64 (2^6) addresses, and an FP4 lookup table can have 16 (2^4) addresses. In this case, the data stored for each address entry in the lookup 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, with the 256th address storing the data 8'b01111111.

[0039] In the example, when a conversion between a smaller bit width precision and a larger bit width precision is required—that is, the bit width of the second data precision is greater than the bit width of the first data precision—as mentioned earlier, this can result in a larger lookup table structure. Therefore, it's also possible to determine the number of addresses in the lookup table based on the smaller bit width of the first data precision. In this case, the data stored for each address entry in the lookup table can be 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 FP16 format data corresponding to the FP8 format data 8'b11111111, and so on, with the 256th address storing FP16 format data corresponding to the FP8 format data 8'b01111111.

[0040] This approach allows for flexible determination of how to construct the lookup table based on address entries, taking into account the bit width of the first and second data precision.

[0041] In some embodiments, in response to one of a first data precision and a 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 the example, taking the conversion from FP16 to FP8 as an example, Table 1 below shows the lookup table for FP8. This is similar to the conversion from a larger bit width precision to a smaller bit width precision as described earlier. Therefore, the data stored for each address entry in the lookup table can be determined based on the numerical range of FP8 itself. For example, in the FP8 lookup table shown in Table 1, it can be determined based on the numerical range of FP8 itself: 8'b11111111~8'b01111111. As shown in Table 1, the value of the first address in the lookup table can start from "0" and increment sequentially, so the value of the 256th address can be "255". Correspondingly, the FP8 format data corresponding to addresses "0" to "127" are negative numbers, and the FP8 format data corresponding to addresses "129" to "255" are positive numbers.

[0043] Table 1

[0044]

[0045] In the example, contrary to the previous example, when a conversion from FP8 to FP16 is required, the situation is similar to the conversion from a smaller bit width precision to a larger bit width precision as described earlier. Therefore, the data stored for each address entry in the lookup table can also be determined based on the numerical range of FP8. For example, the first address of the second data precision can store FP16 format data corresponding to FP8 format data 8'b11111111, and so on, with the 256th address storing FP16 format data corresponding to FP8 format data 8'b01111111.

[0046] In this way, when performing precision conversion between FP8 and FP16, the number of address entries in the lookup table can be easily determined based on FP8, which helps to simplify the construction of the lookup table.

[0047] In some embodiments, the aforementioned preset data-to-address mapping relationship may include at least one linear function, and correspondingly, the parameters in the function may include the slope and intercept of each of the at least one linear function. In this case, as combined with Figure 2Step S203 may include: determining the slope and intercept of a corresponding linear function segment used for conversion within the at least one linear function segment based on the range of target data with a first data precision; and converting target data with intermediate data precision into a target address based on the slope and intercept.

[0048] In the example, taking the conversion from FP16 to FP8 as an example, two segments of linear functions can be configured to convert the data to the appropriate address. Accordingly, the slope A0 and intercept B0 of the first segment can satisfy the expression: 255 = FP16_min × A0 + B0, while the slope A1 and intercept B1 of the second segment can satisfy the expression: 0 = FP16_max × A1 + B1, where FP16_min and FP16_max represent the minimum and maximum values ​​in the FP16 format data, respectively. The segmentation of the linear function can be determined based on the minimum and maximum values ​​in the FP8 format data. Since FP16 format data can cover a larger numerical range than FP8 format data, the target FP16 data to be converted may be smaller than the minimum value FP8_min in the FP8 format data, or it may be between the minimum value FP8_min and the maximum value FP8_max in the FP8 format data. Accordingly, for cases where the value is less than the minimum value FP8_min, the slope A0 and intercept B0 of the first segment can be selected, while for cases between the minimum value FP8_min and the maximum value FP8_max, the slope A1 and intercept B1 of the second segment can be selected.

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

[0050] Therefore, in some embodiments, it is understood that the range of target data with a second data precision may include a first threshold and a second threshold greater than the first threshold. For example, in the FP16 to FP8 conversion example, 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 FP8 to FP16 conversion example, the first threshold and the second threshold may be the two values ​​FP16_0 and FP16_1 as described above.

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

[0052] In the example, taking the conversion from FP8 to FP16 as an example, when the value of the FP8 format data is negative, we can first determine 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, we can select the first set of slope A0 and intercept B0 to calculate the corresponding address; if it is between the first threshold and the second threshold, we can select the second set of slope A1 and intercept B1 to calculate the corresponding address.

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

[0054] In some embodiments, the steps of converting target data into a target address based on slope and intercept may include: multiplying the target data with 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, wherein the multiplier and adder support the calculation of intermediate data precision.

[0055] In the example, the intermediate data precision can be BFP16, so the multiplier and adder can support this precision (BFP16). Rounding up or rounding down functions can be applied to the sum of the multiplication result and the intercept.

[0056] Thus, by using multipliers and adders, the target data with intermediate precision is multiplied and added, and linearly converted into an address with the target precision.

[0057] Figure 3This is a schematic diagram illustrating a floating-point data precision conversion method according to an exemplary embodiment.

[0058] like Figure 3 As shown, the input target data has a first data precision, which is converted into an address via a data-to-address mapping. The corresponding second data precision is then determined from a lookup table based on the address, thus converting the first data precision to the second data precision for output. For this data-to-address mapping, the slope A and intercept B of the linear function are determined based on the data range of the target data, such as... Figure 3 The data A0, B0...An, Bn (where n is a natural number) are shown, and the data is converted into addresses through multiplication and addition. Floor functions (round up or round down) can be applied to the result of the multiplication and addition. Therefore, a lookup table can be read based on this address to determine the corresponding target precision (second data precision) from multiple address entries data0, data1...datan (where n is a natural number) in the lookup table for output.

[0059] Embodiments of this disclosure also provide a floating-point data precision conversion device.

[0060] Figure 4 This is a schematic block diagram illustrating a floating-point data precision conversion device 400 according to an exemplary embodiment.

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

[0062] The lookup table construction module 401 is configured to construct a lookup table representing the correspondence between a first data precision and a second data precision. The lookup table includes a series of consecutive addresses, each address corresponding to a value of the second data precision.

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

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

[0065] The data lookup module 404 is configured to determine target data with a second data precision from a lookup table based on the target address.

[0066] The operations of the aforementioned lookup table construction module 401, intermediate precision conversion module 402, data-to-address conversion module 403, and data lookup module 404 can be combined. Figure 2 The operations of steps S201, S202, S203 and S204 are the same, so the details of each aspect will not be repeated here.

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

[0068] In some embodiments, the range of target data with a second data precision includes a first threshold and a second threshold greater than the first threshold. Accordingly, 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 and second thresholds in response to the target data being negative; a second sub-determination module 4031b, configured to determine a first slope and a first intercept corresponding to a first segment of a linear function in response to the determination that the target data is less than the first threshold; and a third sub-determination module 4031c, configured to determine a second slope and a second intercept corresponding to a second segment of a linear function in response to the determination that the target data is between the first and second thresholds.

[0069] In some embodiments, the conversion execution module 4032 may include: a multiplication execution module 4032a, configured to multiply target data with intermediate data precision by a 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 the target address. The multiplier and adder support the calculation of intermediate data precision.

[0070] While specific functions have been discussed above with reference to specific modules, it should be noted that the functions of the modules discussed herein can be divided into multiple modules, and / or at least some functions of multiple modules can be combined into a single module. The specific actions performed by the 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 conjunction with the specific module). Therefore, a specific module performing an action can include the specific module performing the action itself and / or another module that performs the action, called or otherwise accessed by the specific module.

[0071] It should also be understood that the above regarding Figure 4 The described modules 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 execute in one or more processors and stored in a computer-readable storage medium. Alternatively, these modules can be implemented as hardware logic / circuit. For example, these modules can be implemented together in a System on Chip (SoC). An SoC may include an integrated circuit chip (which includes one or more components in a processor (e.g., a Central Processing Unit (CPU), microcontroller, microprocessor, digital signal processor (DSP), etc.), memory, one or more communication interfaces, and / or other circuitry) and may optionally execute received program code and / or include embedded firmware to perform functions.

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

[0073] According to one aspect of this disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of any of the method embodiments described above.

[0074] According to one aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the steps of any of the method embodiments described above.

[0075] In the following text, combined with Figure 5 Illustrative examples describing such computer devices, non-transitory computer-readable storage media, and computer program products.

[0076] Figure 5 An example configuration of a computer device 500 that can be used to implement the methods described herein is shown.

[0077] Computer device 500 can be a variety of different types of devices. Examples of computer device 500 include, but are not limited to: desktop computers, server computers, laptop or netbook computers, mobile devices (e.g., tablets, cellular or other wireless phones (e.g., smartphones), notebook 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.

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

[0079] Processor 502 may be a single processing unit or multiple processing units, and all processing units may include single or multiple computing units or multiple cores. Processor 502 may 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 operating instructions. Among other capabilities, processor 502 may be configured to acquire and execute computer-readable instructions stored in memory 504, mass storage device 512, or other computer-readable media, such as program code of operating system 516, program code of application program 518, program code of other program 520, etc.

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

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

[0082] Although Figure 5 The modules 516, 518, 520, and 522, or portions thereof, are illustrated as being stored in memory 504 of computer device 500; however, modules 516, 518, 520, and 522 may be implemented using any form of computer-readable medium accessible by computer device 500. As used herein, “computer-readable medium” includes at least two types of computer-readable media: computer-readable storage media and communication media.

[0083] Computer-readable storage media include 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 include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, DVD, or other optical storage devices, magnetic cassettes, magnetic tapes, disk storage devices or other magnetic storage devices, or any other non-transmission medium that can be used to store information for access by computer devices. In contrast, communication media can embody computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms. Computer-readable storage media as defined herein do not include communication media.

[0084] One or more communication interfaces 506 are used for exchanging 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., a network interface card (NIC)), wired or wireless (such as IEEE 802.11 Wireless LAN (WLAN)) wireless interface, Wi-MAX interface, Ethernet interface, Universal Serial Bus (USB) interface, cellular network interface, Bluetooth. TMInterfaces include near-field communication (NFC) interfaces. Communication interface 506 can facilitate communication across various network and protocol types, including wired networks (e.g., LAN, cable, etc.) and wireless networks (e.g., WLAN, cellular, satellite, etc.), the Internet, etc. Communication interface 506 can also provide communication with external storage devices (not shown) such as storage arrays, network-attached storage, storage area networks, etc.

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

[0086] The technologies described herein can be supported by these various configurations of computer device 500, and are not limited to specific examples of the technologies described herein. For example, the functionality can also be implemented wholly or partially on a “cloud” using a distributed system. A cloud includes and / or represents a platform for resources. The platform abstracts the underlying functionality of the cloud’s hardware (e.g., servers) and software resources. Resources may include applications and / or data that can be used when performing computational processing on servers remote from computer device 500. Resources may also include services provided via the Internet and / or via subscriber networks such as cellular or Wi-Fi networks. The platform can abstract resources and functionality to connect computer device 500 to other computer devices. Therefore, the implementation of the functionality described herein can be distributed throughout the cloud. For example, the functionality can be implemented partly on computer device 500 and partly through a platform that abstracts the functionality of the cloud.

Claims

1. A method for converting floating-point data precision, characterized in that, The method comprises: Construct a lookup table to represent the correspondence between a first data precision and a second data precision, wherein the lookup table includes a plurality of consecutive addresses, each address corresponding to a value of the second data precision; The target data with the first data precision is converted into 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 relationship. The preset data-to-address mapping relationship represents a function between data and address, where the function has the data as the independent variable and the address as the dependent variable, and includes parameters determined based on the range of the data. The preset data-to-address mapping relationship includes at least one linear function, and the parameters include the slope and intercept of each of the at least one linear function. The conversion of the target data with the intermediate data precision into a target address through the preset data-to-address mapping relationship includes: Based on the range of the target data having the first data precision, determine the slope and intercept of the corresponding linear function segment used for transformation within the at least one linear function segment; and Based on the slope and the intercept, the target data with the intermediate data precision is converted into the target address; and Based on the target address, the target data with the second data precision is determined from the lookup table.

2. The method according to claim 1, characterized in that, The first data precision and the second data precision each include multiple bits of floating-point precision, and the number of the multiple addresses of the lookup table is determined based on the multiple bits of either 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 8-bit floating-point precision and the other being 16-bit floating-point precision, the lookup table includes 256 addresses.

4. The method according to claim 1, characterized in that, The range of the target data having the second data precision includes a first threshold and a second threshold greater than the first threshold. Determining the slope and intercept of the corresponding linear function segment used for transformation within the at least one linear function segment, 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, it is determined 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, a first slope and a first intercept corresponding to a first segment of a linear function are determined; and In response to determining that the target data is between the first threshold and the second threshold, a second slope and a second intercept corresponding to the second segment of the linear function are determined.

5. The method according to claim 1, characterized in that, The process of converting the target data with the intermediate data precision into the target address based on the slope and the intercept includes: The target data having the intermediate data precision is multiplied by the slope via a multiplier to obtain the multiplication result; and The target address is obtained by adding the multiplication result to the intercept via an adder, wherein the multiplier and the adder support the calculation of the intermediate data precision.

6. A floating-point data precision conversion device, characterized in that, The device includes: The lookup table construction module is configured to construct a lookup table to represent the correspondence between a first data precision and a second data precision, wherein the lookup table includes a plurality of consecutive addresses, each address corresponding to a value of the second data precision; An intermediate precision conversion module is configured to convert target data having the first data precision into intermediate data precision, wherein the intermediate data precision is different from the first data precision and the second data precision. A data-to-address conversion module is configured to convert target data with the intermediate data precision into a target address through a preset data-to-address mapping relationship. The preset data-to-address mapping relationship represents a function between data and address, where the function has the data as the independent variable and the address as the dependent variable, and includes parameters determined based on the range of the data. The preset data-to-address mapping relationship includes at least one linear function, and the parameters include the slope and intercept of each of the at least one linear function. The data-to-address conversion module includes: The parameter determination module is configured to determine, based on the range of target data having the first data precision, the slope and intercept of a corresponding segment of the linear function used for transformation within the at least one segment of linear functions; and The conversion execution module is configured to convert the target data having the intermediate data precision into the target address based on the slope and the intercept; and The data lookup module is configured to determine the target data with the second data precision from the lookup table based on the target address.

7. A computer device, characterized in that, The computer device includes: At least one processor; and A memory having a computer program stored thereon, wherein, when executed by the at least one processor, the computer program causes the at least one processor to perform the method of any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the method of any one of claims 1-5.

9. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, causes the processor to perform the method of any one of claims 1-5.

Citation Information

Patent Citations

  • Calculation device and method of non-linear function

    CN107589935A

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

    CN118170347A