WO2023040389A1 - 转数方法、存储介质、装置及板卡 - Google Patents

转数方法、存储介质、装置及板卡 Download PDF

Info

Publication number
WO2023040389A1
WO2023040389A1 PCT/CN2022/099771 CN2022099771W WO2023040389A1 WO 2023040389 A1 WO2023040389 A1 WO 2023040389A1 CN 2022099771 W CN2022099771 W CN 2022099771W WO 2023040389 A1 WO2023040389 A1 WO 2023040389A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
mantissa
value
bit
exponent
Prior art date
Application number
PCT/CN2022/099771
Other languages
English (en)
French (fr)
Inventor
陈伟伦
Original Assignee
寒武纪(西安)集成电路有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 寒武纪(西安)集成电路有限公司 filed Critical 寒武纪(西安)集成电路有限公司
Publication of WO2023040389A1 publication Critical patent/WO2023040389A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/58Random or pseudo-random number generators
    • G06F7/588Random number generators, i.e. based on natural stochastic processes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F15/00Digital computers in general; Data processing equipment in general
    • G06F15/76Architectures of general purpose stored program computers
    • G06F15/78Architectures of general purpose stored program computers comprising a single central processing unit
    • G06F15/7807System on chip, i.e. computer system on a single chip; System in package, i.e. computer system on one or more chips in a single package
    • G06F15/7817Specially adapted for signal processing, e.g. Harvard architectures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • the present invention relates generally to the field of computers. More specifically, the present invention relates to a method, computer-readable storage medium, device and board for converting input data from a first data type to a second data type.
  • Quantization refers to the conversion of high-precision data types into low-precision data types when high-precision operations are not required. In order to save resource consumption during calculation, this process is also called the number of revolutions.
  • the core challenge of quantization is to reduce the accuracy while maintaining the accuracy of the model, that is, to strike a balance between the compression rate and the accuracy rate.
  • the data after the number of revolutions will be continuously calculated, stored, and re-quantified in the model. Often, the more times the data is iterated, the accuracy will become worse and worse after repeating the number of revolutions, so that the computing power of the neural network model Not ideal.
  • the solution of the present invention provides a method for converting input data from a first data type to a second data type, a computer-readable storage medium, a device, and a board.
  • the present invention discloses a method of converting input data from a first data type to a second data type.
  • the first data type includes a first exponent bit and a first mantissa bit
  • the second data type includes a second exponent bit and a second mantissa bit.
  • the method includes: judging whether the number of digits of the first mantissa and the second mantissa is the same; if so, performing the following steps: determining the number of digits difference between the first mantissa and the second mantissa in the first mantissa Comparing data; generating random data, the random data has the number of digits of the digit difference; judging whether the comparison data is larger than the random data; and if the comparison data is larger than the random data, carrying out the second mantissa.
  • the present invention discloses a computer-readable storage medium having stored thereon computer program code for converting input data from a first data type to a second data type, when said computer program code is executed by a processing device , execute the aforementioned method.
  • the present invention discloses a computing device that converts input data from a first data type to a second data type, the first data type includes a first exponent bit and a first mantissa bit, and the second data type includes a second Exponent and second mantissa.
  • the computing device includes: a control module, a storage module and a computing module.
  • the control module is used for sending multiple instructions.
  • the storage module is used for temporarily storing the input data and the random data, and sending the input data and the random data according to at least one of a plurality of instructions, wherein the random data has the number of bits of the bit difference.
  • the operation module is used to: determine whether the number of digits of the first exponent and the second exponent are the same; if so, determine the first mantissa and the second mantissa in the first mantissa comparison data of the number of differences; judging whether the comparison data is greater than the random data; and if the comparison data is greater than the random data, the second mantissa is carried.
  • the present invention discloses an integrated circuit device including the aforementioned computing device, and also discloses a board including the aforementioned integrated circuit device.
  • the present invention generates comparison data and compares them with randomly generated random data to determine whether the comparison data needs to be rounded up or discarded directly. Since the random data is different each time, the accuracy of the present invention can be maintained within an acceptable range during multiple iterations.
  • Fig. 1 is a schematic diagram showing a four-layer structure of a neural network
  • Fig. 2 is a structural diagram showing a board of an embodiment of the present invention.
  • FIG. 3 is a structural diagram illustrating an integrated circuit device according to an embodiment of the present invention.
  • FIG. 4 is a schematic diagram showing the internal structure of a computing device according to an embodiment of the present invention.
  • FIG. 5 is a schematic diagram showing the internal structure of a processor core according to an embodiment of the present invention.
  • Fig. 7 is a schematic diagram showing that comparison data is determined under the premise that the number of digits of the first exponent and the second exponent are the same;
  • Fig. 8 is a schematic diagram showing that when the value of the input data falls within the third interval, the comparison data is determined
  • Fig. 9 is a schematic diagram illustrating that when the value of the input data falls within the fourth interval, the mantissa digits are rotated.
  • the term “if” may be interpreted as “when” or “once” or “in response to determining” or “in response to detecting” depending on the context.
  • a neural network is a system of multiple neurons connected according to certain rules. Taking the convolutional neural network as an example, it is roughly composed of the following four layer structures: input layer, convolution layer, pooling layer, and fully connected layer.
  • FIG. 1 is a schematic diagram showing a four-layer structure of a neural network 100 .
  • the input layer 101 intercepts part of the information from the input data and converts it into a feature matrix for presentation, which contains features corresponding to the part of the information.
  • the input data here includes but not limited to image data, voice data or text data, and also includes weight data.
  • the convolutional layer 102 is configured to receive the feature matrix from the input layer 101, and perform feature extraction on the input data through a convolution operation.
  • the convolutional layer 102 can build multiple convolutional layers in actual use. Taking image data as an example, the first half of the convolutional layer is used to capture the local and detailed information of the image. For example, each pixel of the output image just feels that the input image is very As a result of calculating the values in a small range, the perception range of the subsequent convolutional layers increases layer by layer, which is used to capture more complex and abstract information of the image. After the operation of multiple convolutional layers, the abstract representation of the image at different scales is finally obtained.
  • the feature extraction of the input image is completed through the convolution operation, the feature image has too much information and the dimension is too high, which not only takes time to calculate, but also easily leads to overfitting, which requires further dimensionality reduction.
  • the pooling layer 103 is configured to replace a certain area of the data with a value, which is usually the maximum or average value among all the values in the area. If the maximum value is used, it is called maximum pooling; if the average value is used, it is called mean pooling. Through pooling, the size of the model can be reduced and the calculation speed can be improved without losing too much information.
  • the fully connected layer 104 plays the role of a classifier in the entire convolutional neural network 200, which is equivalent to a feature space transformation, and integrates all the previous useful information extraction, coupled with the nonlinear mapping of the aforementioned activation function, the multi-layer fully connected layer
  • any nonlinear transformation can be simulated to compare information based on different classifications, so as to judge whether the input data is similar to the comparison target.
  • the operations of the convolutional layer 102 and the fully connected layer 104 occupy most of the hardware resources, especially the convolutional layer 102 involves a large number of high-frequency transfer of neuron data and weight data and iterative operations off-chip and on-chip.
  • quantization or revolutions are generally performed before handling or calculation, that is, converting high-precision data into low-precision data.
  • a number is represented by a triplet, which includes a sign bit sign, an exponent bit exp, and a mantissa bit man.
  • the sign bit indicates the sign of the number, and the value of the sign bit is 0 for a positive number and 1 for a negative number; the exponent bit (also known as the order code) indicates the binary power, and the mantissa bit indicates a decimal value.
  • NAN non-number
  • INF infinity
  • normalization normalization
  • denormal denormalization
  • FP32[31] is the sign bit
  • FP32[30:23] is the exponent bit
  • FP32[22:0] is the mantissa bit
  • the 0th bit FP32[0] in the 32 bits stores the least significant bit LSB of the mantissa bit ( least significant bit)
  • the 22nd bit FP32[22] stores the most significant bit MSB (most significant bit) of the mantissa
  • the 23rd bit FP32[23] stores the least significant bit LSB of the exponent bit
  • the 30th bit FP32[30] stores The most significant bit MSB of the exponent bit
  • the highest bit FP32[31] of the entire array contains sign information.
  • the normalized form of FP32 is:
  • FIG. 3 is a block diagram showing the combined processing means in the chip 201 of this embodiment.
  • the combined processing device 30 includes a computing device 301 , an interface device 302 , a processing device 303 and an off-chip memory 304 .
  • each cluster 405 includes a plurality of processor cores (IPU core) 406 and a storage core (MEM core) 407.
  • processor cores IPU core
  • MEM core storage core
  • processor cores 406 are exemplarily shown in the figure, and the present invention does not limit the number of processor cores 406 . Its internal architecture is shown in Figure 5.
  • Each processor core 406 includes three modules: a control module 51 , an operation module 52 and a storage module 53 .
  • the control module 51 is used to coordinate and control the work of the operation module 52 and the storage module 53 to complete the task of deep learning, which includes an instruction fetch unit (instruction fetch unit, IFU) 511 and an instruction decoding unit (instruction decode unit, IDU) 512.
  • the instruction fetching unit 511 is used to obtain instructions from the processing device 303 , and the instruction decoding unit 512 decodes the obtained instructions, and sends the decoding results to the computing module 52 and the storage module 53 as control information.
  • the operation module 52 includes a vector operation unit 521 and a matrix operation unit 522 .
  • the vector operation unit 521 is used to perform vector operations, and can support complex operations such as vector multiplication, addition, and nonlinear transformation;
  • the matrix operation unit 522 is responsible for the core calculation of the deep learning algorithm, namely matrix multiplication and convolution.
  • the storage module 53 is used to store or transport relevant data, including a neuron storage unit (neuron RAM, NRAM) 541, a weight storage unit (weight RAM, WRAM) 532, an input/output direct memory access module (input/output direct memory access) , IODMA) 533, moving direct memory access module (move direct memory access, MVDMA) 534.
  • a neuron storage unit neuron RAM, NRAM
  • weight RAM weight RAM
  • WRAM weight RAM
  • IODMA input/output direct memory access
  • MVDMA moving direct memory access
  • the NRAM 541 is used to store the feature map and the intermediate results calculated by the processor core 406; the WRAM 532 is used to store the weights of the deep learning network; the IODMA 533 controls the NRAM 541/WRAM 532 and the off-chip memory through the broadcast bus 409 304 memory access; MVDMA 534 is used to control the memory access of NRAM 541/WRAM 532 and SRAM 408.
  • the storage core 407 is mainly used for storage and communication, that is, storing shared data or intermediate results between the processor cores 406, executing communication between the cluster 405 and the off-chip memory 304, communication between the clusters 405, The communication between the processor cores 406 and the like.
  • the storage core 407 is capable of scalar operations, and is used for performing scalar operations.
  • the storage core 407 includes a shared memory unit (SRAM) 408, a broadcast bus 409, a cluster direct memory access module (cluster direct memory access, CDMA) 410 and a global direct memory access module (global direct memory access, GDMA) 411.
  • SRAM shared memory unit
  • CDMA cluster direct memory access
  • GDMA global direct memory access module
  • the SRAM 408 assumes the role of a high-performance data transfer station. The data multiplexed between different processor cores 406 in the same cluster 405 does not need to be obtained from the processor cores 406 to the off-chip memory 304, but is stored in the SRAM 408.
  • the storage core 407 only needs to quickly distribute the multiplexed data from the SRAM 408 to multiple processor cores 406, so as to improve the communication efficiency between cores and greatly reduce on-chip and off-chip input/output access .
  • the broadcast bus 409 is used to complete high-speed communication among the processor cores 406 in the cluster 405 .
  • the broadcast bus 409 in this embodiment supports inter-core communication methods including unicast, multicast and broadcast.
  • Unicast refers to point-to-point (that is, a single processor core to a single processor core) data transmission
  • multicast is a communication method that transmits a piece of data from SRAM 408 to specific processor cores 406, and broadcasting is to transfer a data
  • the communication mode in which data is transmitted from SRAM 408 to all processor cores 406 belongs to a special case of multicast.
  • the CDMA 410 is used to control the memory access of the SRAM 408 between different clusters 405 in the same computing device 301.
  • the computing device 301 in this embodiment converts input data from high-precision data types to low-precision data types when performing neural network model operations, and then performs handling or calculation based on low-precision data types to save hardware resource.
  • the computing device 301 converts the input data from the first data type to the second data type, wherein the first data type is high-precision, such as FP32, and the second data type is low-precision, such as TF32 or PF16, exemplary To put it simply, the computing device 301 converts the input data from the data type of FP32 to TF32 or PF16, and then processes it.
  • the present invention does not limit the specific data types before and after the number of revolutions.
  • the sign of the floating-point number will not change during the rotation process, so the value of the second sign bit directly corresponds to the value of the first sign bit.
  • the special feature of the rotation number mechanism in this embodiment is that it uses a set of evaluation methods Converting the first exponent bits to the second exponent bits and converting the first mantissa bits to the second mantissa exponent bits implements the process of converting the input data from the first data type to the second data type.
  • control module 51 is used to send instructions to the operation module 52 and the storage module 53 when the number of rotations is performed, and the operation module 52 and the storage module 53 execute in response to the received instructions.
  • the instruction fetching unit 511 acquires instructions from the processing device 303, and the instruction decoding unit 512 decodes the acquired instructions, and sends the decoding results as a plurality of control information to the operation module 52 in a certain order. and the storage module 53, so that the calculation module 52 and the storage module 53 execute tasks sequentially according to these control information, and realize the number of revolutions as a whole.
  • step 601 the value of the second sign bit is set to the value of the first sign bit.
  • the operation module 52 directly sets the value of the second sign bit as the value of the first sign bit.
  • the operation module 52 directly sets the 10 mantissa bits of the second mantissa position 702 of the TF32 data as the highest first 10 bits of the first mantissa position 701, as shown in the figure, the values of B0 to B9 in the second mantissa position 702 are respectively Set to the value of A0 to A9 in the first mantissa digit 701.
  • step 605 random data is generated, and the random data has the number of digits of the difference in number of digits.
  • the random data can be generated by the processing device 303 and sent together with the input data to the storage module 53 for temporary storage, or the storage core 407 randomly generates the value of each digit in the random data, and then Along with the input data, it is sent to the storage module 53 for temporary storage.
  • the sequence 704 in FIG. 7 is random data, and its length is the same as that of the comparison data 703 , that is, the number of digits with a difference in digits is 13 digits, and the numbers from high to low are R0 to R12 respectively.
  • step 606 the operation module 52 then determines whether the comparison data 703 is larger than the random data.
  • the storage module 53 sends the random data 704 to the computing module 52 according to the control information, and the computing module 52 judges whether the value of the comparison data 703 is greater than the value of the random data 704 . If the comparison data 703 is greater than the random data 704, it means that the comparison data 703 is large enough to be carried to B9; if the comparison data 703 is not greater than the random data 704, it means that the comparison data 703 is not large enough and can be directly discarded.
  • the operation module 52 When judging whether the value of the comparison data 703 is greater than the value of the random data 704 , the operation module 52 will first judge the value of the MSB of the two, that is, judge the size of A10 and R0 . Assuming that A10 is 1 and R0 is 0, no matter what the value of other bits is, the comparison data 703 will be greater than the random data 704; if A10 is 0 and R0 is 1, no matter what the value of other bits is, the comparison data 703 will be smaller than Random data 704; if A10 and R0 are both 0 or 1, then the operation module 52 further judges the size of the next highest bit, that is, judges the size of A11 and R1, and the judging method is the same as judging the size of A10 and R0. If the two values in the same position are the same, continue to compare the next lowest value until A22 and R12. If A22 and R12 are still the same, it means that the comparison data 703 and the random data 704 have exactly the same values.
  • step 607 is executed to carry out the second mantissa 702 .
  • the arithmetic module 52 adds one to the value of the second mantissa digit 702 as the value of the second mantissa digit 702 after the rotation number.
  • the second mantissa position 702 in the first mantissa position 701 is 1, and when a carry is needed, the second mantissa position 702 has no extra bits to use. Holds carry information.
  • the second exponent bit is used to record the most significant bit information after the second mantissa bit 602 is carried out.
  • the method of comparing the number of revolutions in which the comparison data 603 is equal to the random data 604 can be applied to the method in which the comparison data 603 is greater than the number of revolutions of the random data 604.
  • the present invention does not limit the process of rounding down the carry in which the comparison data 603 is equal to the random data 604 You can choose to carry or round down according to the actual situation.
  • the comparison data 603 is equal to the random data 604 , it will be handled in this way, which will not be described in detail later.
  • step 609 if the operation module 52 judges that the number of digits of the first exponent and the second exponent are different, execute step 609, and the operation module 52 will further identify which interval the value of the input data falls in, and different intervals have different number of revolutions.
  • the value range of a normalized number depends on the number of exponent bits, while the value range of a denormalized number is related to the number of exponent bits plus the number of mantissa bits.
  • the value range of the normalized number of the first data type is between the first interval number of 2 and the first upper limit of 2
  • the value range of the unnormalized number of the first data type is between 2
  • the value range of the normalized number of the second data type is between the second interval number of 2 and the second upper limit of 2
  • the value range of the non-normalized number of the second data type Between 2 the second lower limit and 2 the second interval number .
  • the first interval is [2 the second upper limit , 2 the first upper limit ); the second interval is [2 the second interval number , 2 the second upper limit ); the third interval is [2 the second lower limit , 2 the second interval number ); the fourth interval is [2 the second lower limit- 1,2 the second lower limit ); the fifth interval is [2 the first lower limit , 2 the second lower limit-1 ).
  • step 610 the second mantissa bits are set based on different value intervals.
  • the operation module 52 will identify which interval the value of the input data of the first data type falls into. Different intervals will adopt different rotation number methods or rotation number rules. The following will continue to take FP32 rotation number to FP16 as an example to illustrate each interval. Corresponding rotation mode or rotation rule.
  • the operation module 52 determines the comparison data of the number of digit differences between the first mantissa and the second mantissa.
  • the comparison data refers to the continuous data intercepted from the low-order data to the high-order data in the first mantissa, that is, the 13-bit data is continuously intercepted from the lowest LSB in the first mantissa to the high-order, and the 13-bit data is the comparison data.
  • the operation module 52 sets the second mantissa as continuous data intercepted from the highest bit data to the lower bit data in the first mantissa, and the number of intercepted bits is equal to the number of second mantissa bits, that is, 10 bits.
  • the operation module 52 After deciding to compare data, generate random data having the number of digits of the number of digit differences. The operation module 52 then determines whether the comparison data is larger than the random data. When the comparison data is greater than the random data, the operation module 52 carries out the second mantissa. When the comparison data is not greater than the random data, the second mantissa is not carried. That is to say, when the value of the input data falls within the second interval [2 ⁇ 14 , 2 16 ), the setting method of the second mantissa is the same as that shown in FIG. 7 , which will not be repeated here.
  • the value of the second index position the value of the first index position-the first upper limit+the second upper limit.
  • the operation module 52 When in step 609, the value of the input data is identified as falling within the third interval [2 ⁇ 24 , 2 ⁇ 14 ), it means that the value of the input data falls within the range of the denormalized number of FP16.
  • the operation module 52 also needs to determine the comparison data of the number of digits difference between the first mantissa and the second mantissa in the first mantissa, and the number of digits difference between the first mantissa and the second mantissa. It is also 13, but it is decided that the comparison data is different from the above.
  • the operation module 52 will select the consecutive digits from the number of digits of the second mantissa from the highest digit-(the second interval number-the value of the first exponent position+1) in the first mantissa.
  • the bits with the difference number are used as comparison data.
  • FIG. 8 shows a schematic diagram of determining comparison data when the value of the input data falls within the third interval [2 ⁇ 24 , 2 ⁇ 14 ).
  • the first mantissa 801 of the input data of the FP32 data type is 23 bits, which are A0 to A22 from high to low respectively
  • the operation module 52 first sets the value of the second mantissa digit 802 counting a specific number of bits from the highest bit to 0, wherein the specific number is the initial digit, and its calculation formula is the number of digits of the second mantissa digit-( The second interval number - the value of the first exponent position + 1), so the values of B0 to B4 are 0, and then the second mantissa position 802 is set to the value of the (specific number + 1) digit (B5) from the highest position It is 1, and finally set the value of the second mantissa 802 (specific quantity-1) from the (specific quantity+2) to the first mantissa 801 (specific quantity-1) from the highest digit
  • the operation module 52 determines whether the comparison data 803 is greater than the random data 804 .
  • the comparison data 803 is greater than the random data 804, it indicates that a carry is required, specifically, the operation module 52 carries out a carry on B9.
  • the comparison data 803 is not greater than the random data 804, no carry is carried out.
  • step 611 the second exponent bit is set. Since this interval is the non-normalized representation range of the second data type, the operation module 52 sets all bits of the second index to 0.
  • FIG. 9 shows a schematic diagram of mantissa digits performing revolutions when the value of the input data falls within the fourth interval.
  • the mantissa bits 901 of the FP32 data type have 23 bits of mantissas A0 to A22.
  • the comparison data 903 is not greater than the random data 904, it means no carry, and the operation module 52 converts the input data FP32 to zero of FP16, that is, all values of the second mantissa are set to 0.
  • step 611 the second exponent bit is set.
  • the operation module 52 sets all values of the second exponent bits to 0.
  • step 609 when the numerical value of input data is identified and falls in the fifth interval [ 2-149,2-25 ), determine the representation range of the underflow FP16, regardless of whether its numerical value is all zero, in step 610
  • the middle operation module 52 directly converts the input data of the FP32 data type into zeros of the FP16 data type, that is, all values of the second mantissa are set to 0.
  • step 611 the operation module 52 sets all values of the second exponent to 0.
  • the storage module 53 will transmit data to the computing module 52 through two channels, wherein the first channel is used to transmit input data, and the second channel is used to transmit random data. In the case of converting FP32 to FP16 or TF32, each cycle The amount of transmitted data in the first path is twice the amount of transmitted data in the second path.
  • the instruction decoding unit 512 decodes the obtained dynamic rounding revolution instruction, and divides the decoding result into a plurality of microinstructions and sends them to the operation module 52 and the storage unit respectively.
  • Module 53 The storage module 53 knows the data volume of the input data that should be read according to the input data volume operation domain 1004, takes out a complete input data according to the address of the input data address operation domain 1002, and then reads the data volume according to the random data address operation domain 1003 Random data half the size of Input0_size.
  • the transmission bandwidth of the first channel and the second channel and the calculation bandwidth of the operation module 52 can be set to 128 bytes, that is, the storage module 53 will transmit 128 bytes of input data to the operation module 52 through the first channel every cycle. Since every 128 bytes of input data only consumes 64 bytes of random data, the storage module 53 transmits 64 bytes of random data to the computing module 52 through the second channel every cycle. Therefore, the calculation module 52 will receive the matching input data and random data synchronously, which is convenient for calculation of the number of revolutions.
  • the software product when the solution of the present invention is embodied in the form of a software product (such as a computer-readable storage medium), the software product can be stored in a memory, and it can include several instructions to make a computer device (such as a personal computer, server or network device, etc.) execute some or all of the steps of the method described in the embodiment of the present invention.
  • the aforementioned memory may include but not limited to U disk, flash disk, read only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), mobile hard disk, magnetic disk or optical disk, etc., which can store programs.
  • the medium of the code may include but not limited to U disk, flash disk, read only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), mobile hard disk, magnetic disk or optical disk, etc.
  • the electronic equipment or device of the present invention may include servers, cloud servers, server clusters, data processing devices, robots, computers, printers, scanners, tablet computers, smart terminals, PC equipment, Internet of Things terminals, mobile Terminals, mobile phones, driving recorders, navigators, sensors, cameras, cameras, video cameras, projectors, watches, earphones, mobile storage, wearable devices, visual terminals, automatic driving terminals, vehicles, household appliances, and/or medical equipment.
  • Said vehicles include airplanes, ships and/or vehicles;
  • said household appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, electric lights, gas stoves, range hoods;
  • said medical equipment includes nuclear magnetic resonance instruments, Ultrasound and/or electrocardiograph.
  • the hardware information of the cloud device and the hardware information of the terminal device and/or the edge device are compatible with each other, so that according to the hardware information of the terminal device and/or the edge device, the hardware resources of the cloud device can be Match appropriate hardware resources to simulate the hardware resources of terminal devices and/or edge devices, so as to complete the unified management, scheduling and collaborative work of device-cloud integration or cloud-edge-end integration.
  • the aforementioned storage unit or storage device can be any suitable storage medium (including magnetic storage medium or magneto-optical storage medium, etc.), which can be, for example, a variable resistance memory (Resistive Random Access Memory, RRAM), dynamic Random Access Memory (Dynamic Random Access Memory, DRAM), Static Random Access Memory (Static Random Access Memory, SRAM), Enhanced Dynamic Random Access Memory (Enhanced Dynamic Random Access Memory, EDRAM), High Bandwidth Memory (High Bandwidth Memory , HBM), hybrid memory cube (Hybrid Memory Cube, HMC), ROM and RAM, etc.
  • RRAM variable resistance memory
  • DRAM Dynamic Random Access Memory
  • SRAM Static Random Access Memory
  • EDRAM Enhanced Dynamic Random Access Memory
  • High Bandwidth Memory High Bandwidth Memory
  • HBM High Bandwidth Memory
  • HMC Hybrid Memory Cube
  • ROM and RAM etc.
  • a method of converting input data from a first data type including a first exponent bit and a first mantissa bit to a second data type, the second data type including a second exponent bit and the second mantissa includes: judging whether the number of digits of the first exponent and the second exponent are the same; if so, performing the following steps: determining the first mantissa, the first Comparison data of the number of digits difference between the mantissa and the second mantissa; generate random data, the random data has the number of digits of the digit difference; judge whether the comparison data is greater than the random data ; and if the comparison data is greater than the random data, carry out the second mantissa.
  • Clause A2 The method of Clause A1, wherein if the first exponent has the same number of digits as the second exponent, further comprising: setting the second exponent to the value of the first exponent The numeric value of the exponent.
  • Clause A3 The method according to Clause A2, wherein in the carrying step, if all the bits corresponding to the first mantissa bits corresponding to the second mantissa bits have a value of 1 before the carry, the following steps are performed : setting all the digits of the second mantissa digits to the value after the carry; and adding one to the value of the second exponent digit.
  • the method also The method includes: identifying a numerical interval of the input data; setting the second mantissa bit based on the numerical interval; and setting the second exponent bit based on the numerical interval.
  • Clause A5. The method according to Clause A4, wherein in said identifying step, when said value of said input data falls within [2 second upper limit , 2 first upper limit ), said setting said second In the step of mantissa bits, all values of the second mantissa bits are set to 0.
  • Clause A6 The method of Clause A5, wherein in said step of setting said second exponent bits, all values of said second exponent bits are set to one.
  • Clause A9 The method according to Clause A4, wherein in the identifying step, when the value of the input data falls within [2 second lower limit , 2 second interval number ), the setting of the second The step of the mantissa includes: determining the comparison data of the number of digits difference between the first mantissa and the second mantissa; setting the value of the second mantissa to be 0 for a specific number of bits counted from the highest bit ; Set the value of the (specific number+1) digit from the highest digit to 1; and set the second mantissa digit to count from the (specific number+2) digit (specific number -1) The value of the ones digit is the value of the (specific number-1) digits counted from the highest digit of the first mantissa.
  • Clause A10 The method according to Clause A9, wherein the comparison data is the number of consecutive digits difference from the start bit in the first mantissa, and the start bit is the number of bits from the highest bit The number of digits of the second mantissa digit-(the second interval number-the numerical value of the first exponent digit+1) is calculated from.
  • Clause A11 The method of Clause A10, wherein the particular number is the start bit.
  • Clause A12 The method according to Clause A4, wherein in said identifying step , said setting said first The step of the two mantissa digits includes: determining the comparison data of the number of digits difference between the first mantissa digit and the second mantissa digit; generating random data, the random data having the number of digits of the digit difference number ; judging whether the comparison data is greater than the random data; and if the comparison data is greater than the random data, setting the second mantissa to a minimum value.
  • Clause A13 The method according to Clause A12, wherein the step of determining the comparison data comprises: setting the value of the most significant digit of the comparison data to 1; and setting the other digits of the comparison data to the value of the first The value obtained by subtracting 1 from the number of digit differences mentioned above in the one-mantissa digits.
  • Clause A14 The method of Clause A12, wherein all values of the second mantissa bits are set to zero if the comparison data is not greater than the random data.
  • Clause A15 The method according to Clause A4, wherein in the identifying step, when the value of the input data falls within [2 first lower limit , 2 second lower limit-1 ], the setting The step of the two mantissa bits includes: setting all values of the second mantissa bits to 0.
  • Clause A16 The method of Clause A9, 12 or 15, wherein in said step of setting said second exponent bits, all values of said second exponent bits are set to zero.
  • Clause A17 The method of Clause A1, wherein the step of generating comprises randomly generating a value for each bit in the random data.
  • Clause A18 The method of Clause A1, wherein the first data type is FP32 and the second data type is one of TF32 and FP16.
  • a computer-readable storage medium having stored thereon computer program code for converting input data from a first data type to a second data type, said computer program code, when executed by a processing device, performing clauses A1 to The method of any one of 18.
  • a computing device that converts input data from a first data type to a second data type, the first data type comprising a first exponent bit and a first mantissa bit, the second data type Including the second exponent bit and the second mantissa bit, the calculation device includes: a control module, used to send a plurality of instructions; a storage module, used to temporarily store the input data and random data, and according to the plurality of instructions at least One of them, sending the input data and the random data, wherein the random data has the number of digits of the number of digits difference; the operation module, according to at least one of the multiple instructions, is used to: judge the Whether the number of digits of the first exponent position and the second exponent position is the same; if so, determine the number of differences between the first mantissa position and the second mantissa position in the first mantissa position Comparing data; judging whether the comparison data is greater than the random data; and carrying out the second mantis
  • Clause A21 The computing device of Clause A20, further comprising a memory core to generate said random data.
  • Clause A22 The computing device of Clause A21, wherein the storage core randomly generates a value for each bit in the random data.
  • Clause A23 The computing device of Clause A20, wherein the storage module allocates to the random data half the storage space of the input data of the first data type.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Evolutionary Computation (AREA)
  • Computer Hardware Design (AREA)
  • Artificial Intelligence (AREA)
  • Data Mining & Analysis (AREA)
  • Molecular Biology (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • General Health & Medical Sciences (AREA)
  • Computational Linguistics (AREA)
  • Biophysics (AREA)
  • Mathematical Optimization (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Pure & Applied Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Signal Processing (AREA)
  • Medical Informatics (AREA)
  • Microelectronics & Electronic Packaging (AREA)
  • Computational Mathematics (AREA)
  • Complex Calculations (AREA)
  • Executing Machine-Instructions (AREA)

Abstract

本发明涉及转换数据类型的方法、计算机可读存储介质、装置及板卡,其中本发明的计算装置包括在集成电路装置中,该集成电路装置包括通用互联接口和其他处理装置。计算装置与其他处理装置进行交互,共同完成用户指定的计算操作。集成电路装置还可以包括存储装置,存储装置分别与计算装置和其他处理装置连接,用于计算装置和其他处理装置的数据存储。

Description

转数方法、存储介质、装置及板卡
相关申请的交叉引用
本公开要求于2021年9月18日申请的、申请号为202111101381.9、发明名称为“转数方法、存储介质、装置及板卡”的中国专利申请的优先权。
技术领域
本发明一般地涉及计算机领域。更具体地,本发明涉及将输入数据由第一数据类型转换成第二数据类型的方法、计算机可读存储介质、装置及板卡。
背景技术
近年来深度学习在众多领域的亮眼表现使其成为如今机器学习的主流,但其巨大的计算量仍为人诟病。为了平衡算力需求与精度,模型压缩成为了业界研究的热点之一。
其中一种模型压缩的方式称为量化。神经网络需要大量的数据参与运算,在一些情况下这些数据的精度可以不用太高,量化指的是在不需要高精度的操作时,将高精度数据类型的数据转换成低精度的数据类型,以节省运算时的资源耗费,这过程又称为转数。而量化最核心的挑战在于降低精度的同时维持模型的准确度,也就是在压缩率与准确率之间要达成平衡。特别是转数后的数据会在模型中不停地被运算、存储、再量化,往往数据迭代的次数越多,重复转数后会使得精度越来越差,以至于神经网络模型的计算能力不尽理想。
因此,一种在多次迭代过程中维持精度的转数方案是迫切需要的。
发明内容
为了至少部分地解决背景技术中提到的技术问题,本发明的方案提供了一种将输入数据由第一数据类型转换成第二数据类型的方法、计算机可读存储介质、装置及板卡。
在一个方面中,本发明揭露一种将输入数据由第一数据类型转换成第二数据类型的方法。第一数据类型包括第一指数位及第一尾数位,第二数据类型包括第二指数位及第二尾数位。所述方法包括:判断第一指数位与第二指数位的位数是否相同;如是,执行下列步骤:决定第一尾数位中,第一尾数位与第二尾数位的位数差个数的比较数据;生成随机数据,随机数据具有位数差个数的位数;判断比较数据是否大于随机数据;以及如比较数据大于随机数据,对第二尾数位进位。
在另一个方面,本发明揭露一种计算机可读存储介质,其上存储有将输入数据由第一数据类型转换成第二数据类型的计算机程序代码,当所述计算机程序代码由处理装置运行时,执行前述的方法。
在另一个方面,本发明揭露一种计算装置,将输入数据由第一数据类型转换成第二数据类型,第一数据类型包括第一指数位及第一尾数位,第二数据类型包括第二指数位及第二尾数位。计算装置包括:控制模块、存储模块及运算模块。
控制模块用以发送多个指令。存储模块用以暂存输入数据及随机数据,并根据多个指令至少其中之一,发送输入数据及随机数据,其中随机数据具有位数差个数的位数。运算模块根据多个指令至少其中之一,用以:判断第一指数位与第二指数位的位数是否相同;如是,决定第一尾数位中,第一尾数位与第二尾数位的位数差个数的比较数据;判断比较数据是否大于随机数据;以及如比较数据大于随机数据,对第二尾数位进位。
在另一个方面,本发明揭露一种集成电路装置,包括前述的计算装置,又揭露一种板卡,包括前述的集成电路装置。
本发明通过生成比较数据,与随机生成的随机数据进行比较,以决定比较数据需要进位或直接舍去。由于每次的随机数据不同,故在多次迭代的过程中,本发明的精度可以被维持在可接受的范围内。
附图说明
通过参考附图阅读下文的详细描述,本发明示例性实施方式的上述以及其他目的、特征和优 点将变得易于理解。在附图中,以示例性而非限制性的方式示出了本发明的若干实施方式,并且相同或对应的标号表示相同或对应的部分其中:
图1是示出神经网络的四层结构示意图;
图2是示出本发明实施例的板卡的结构图;
图3是示出本发明实施例的集成电路装置的结构图;
图4是示出本发明实施例的计算装置的内部结构示意图;
图5是示出本发明实施例的处理器核的内部结构示意图;
图6是示出本发明实施例将输入数据由第一数据类型转换成第二数据类型的流程图;
图7是示在第一指数位与第二指数位的位数相同的前提下决定比较数据的示意图;
图8是示出当输入数据的数值落在第三区间时,决定比较数据的示意图;
图9是示出输入数据的数值落在第四区间时,尾数位进行转数的示意图;以及
图10是示出了本发明实施例的动态舍入转数指令的示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
应当理解,本发明的权利要求、说明书及附图中的术语“第一”、“第二”、“第三”和“第四”等是用于区别不同对象,而不是用于描述特定顺序。本发明的说明书和权利要求书中使用的术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在此本发明说明书中所使用的术语仅仅是出于描述特定实施例的目的,而并不意在限定本发明。如在本发明说明书和权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。还应当进一步理解,在本发明说明书和权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
如在本说明书和权利要求书中所使用的那样,术语“如果”可以依据上下文被解释为“当...时”或“一旦”或“响应于确定”或“响应于检测到”。
下面结合附图来详细描述本发明的具体实施方式。
神经网络是按照一定规则连接起来的多个神经元系统。以卷积神经网络为例,大致上是由以下四种层结构组成:输入层、卷积层(convolution layer)、池化层(pooling layer)、全连接层(fully connected layer)。图1是示出神经网络100的四层结构示意图。
输入层101是自输入数据中截取部分信息,转化成特征矩阵方式呈现,其中载有对应该部分信息的特征。此处的输入数据包括但不限于图像数据、语音数据或是文本数据,还包括权值数据。
卷积层102配置成接收来自输入层101的特征矩阵,通过卷积操作对输入数据进行特征抽取。卷积层102在实际运用时可以建制多层卷积层,以图像数据为例,前半部的卷积层用以捕捉图像局部、细节信息,例如输出图像的每个像素只是感受到输入图像很小范围数值进行计算的结果,后面的卷积层感受范围逐层加大,用于捕获图像更复杂、更抽象的信息。经过多个卷积层的运算,最后得到图像在各个不同尺度的抽象表示。虽然通过卷积操作,完成了对输入图像的特征抽取,但特征图像信息量太大,维数过高,不仅计算耗时,而且容易导致过拟合,需要进一步降维。
池化层103配置成对数据的某一个区域用一个值代替,这值通常是该区域所有数值里的最大值或平均值。如果采用最大值,称为最大池化;如果采用平均值,称为均值池化。通过池化,在不至于损失过多信息的前提下,可以缩减模型大小、提高计算速度。
全连接层104在整个卷积神经网络200中起到分类器的作用,相当于特征空间变换,把前面所有有用的信息提取整合,再加上前述激活函数的非线性映射,多层全连接层理论上可以模拟任 何非线性变换,以基于不同的分类做信息比对,借此判断输入数据是否相似于比对的标的。
卷积层102与全连接层104的运算占用了绝大部分的硬件资源,特别是卷积层102涉及大量且高频的在片外与片上搬移神经元数据及权值数据与迭代运算,为了降低硬件的负担,一般会在搬运或运算前进行量化或转数,即将高精度的数据转换为低精度的数据。
一个浮点数利用计算机可识别的数据类型来表达时,根据IEEE 754的浮点数标准,是以三元组来表示一个数的,这三元组包括符号位sign、指数位exp及尾数位man。符号位表示该数的正负号,符号位的数值为0表示正数,1表示负数;指数位(又称为阶码)表示二进制的幂次,尾数位表示小数值。数值的表达形式可分为非数(NAN)、无穷(INF)、规格化(normal)及非规格化(denormal),其中:非数表示非数值,其指数位的数值全为1,尾数位的数值不全为0;无穷表示无限大的数,其指数位的数值全为1,尾数位的数值全为0,再根据符号位的数值决定是正无穷或负无穷;规格化表示省略了小数点前面的数字1,其指数位不全为1亦不全为0;非规格化表示省略了小数点前面的数字0,其指数位全为0。
FP32就是一种高精度的数据类型,基于IEEE 754的格式规范,其数据类型包括1位的符号位、8位的指数位及23位的尾数位,一共有1+8+23=32位,其中FP32[31]是符号位,FP32[30:23]是指数位,FP32[22:0]是尾数位,即32位中的第0位FP32[0]存放尾数位的最低有效位LSB(least significant bit),第22位FP32[22]存放尾数位的最高有效位MSB(most significant bit),第23位FP32[23]存放指数位的最低有效位LSB,第30位FP32[30]存放指数位的最高有效位MSB,整个数列的最高位FP32[31]载有符号信息。FP32的规格化形式为:
数值=(-1) sign×1.man×2 exp-127
对于规格化形式来说,其取值范围(即浮点数的数量级范围)介于[2 -126,2 128)间。而FP32的非规格化形式为:
数值=(-1) sign×0.man×2 -126
虽然非规格化的指数位全为0,但由于其小数值为0.man而不是1.man,故如果尾数位的最高有效位MSB以降的连续几个位数皆为0的话,实际上等同于非规格化数的幂次往下降了,例如小数值为0.001等同于小数值为0.1且幂次往下移2位,即:
(-1) sign×0.001×2 -126
=(-1) sign×0.1×2 -2×2 -126
=(-1) sign×0.1×2 -128
由于FP32的尾数位共有23位,故FP32的非规格化表示形式的取值范围为[2 -149,2 -126)间,其中2 -149=2 -126-23
TF32则是一种相对精度较低的数据类型,其数据类型包括1位的符号位sign、8位的指数位exp及10位的尾数位man,因此TF32数据一共有1+8+10=19位,其中TF32[18]是符号位,TF32[17:10]是指数位,TF32[9:0]是尾数位,即19位中的第0位TF32[0]存放尾数位的最低有效位LSB,第10位TF32[9]存放尾数位的最高有效位MSB,第11位TF32[10]存放指数位的最低有效位LSB,第18位TF32[17]存放指数位的最高有效位MSB,整个数列的最高位TF32[18]载有符号信息。TF32的规格化形式为:
数值=(-1) sign×1.man×2 exp-127
而TF 32的非规格化形式为:
数值=(-1) sign×0.man×2 -126
由于指数位的位数与FP32相同,故TF32规格化表示形式的取值范围与FP32相同,但TF32数据的尾数位仅有10位,因此其非规格化表示形式的取值范围为[2 -136,2 -126)间,其中2 -136=2 -126-10
FP16又是一种相对精度较低的数据类型,其数据类型包括1位的符号位sign、5位的指数位exp及10位的尾数位man,因此FP16数据一共有1+5+10=16位,其中FP16[15]是符号位,FP16[14:10]是指数位,FP16[9:0]是尾数位,即16位中的第0位FP16[0]存放尾数位的最低有效位LSB,第10位FP16[9]存放尾数位的最高有效位MSB,第11位FP16[10]存放指数位的最低有效位LSB,第15位FP16[14]存放指数位的最高有效位MSB,整个数列的最高位FP16[15]载有符号信息。FP16的规格化形式为:
数值=(-1) sign×1.man×2 exp-15
其取值范围为[2 -14,2 16)间。而FP16的非规格化形式为:
数值=(-1) sign×0.man×2 -14
由于FP16数据的尾数位仅有10位,因此其非规格化表示形式的取值范围为[2 -24,2 -14)间。
可以理解的是,数列的位数越多,所能承载的信息量越大,故数据的数值精度越高。一般来说,输入数据都是高精度的数据类型,例如FP32,然而在神经网络模型中,高精度数据的搬运和运算耗费过多的硬件资源,因此在某些层中,像是卷积层或全连接层,可以在损失可控的前提下适当的降低精度来运算,例如将FP32的数据类型转数成TF32或是FP16的数据类型,只要损失的精度不至于使得运算结果误差过大,如此转数有助于释放硬件的压力。
本发明提供一种动态舍入(stochastic rounding)转数方案,其可以在反复迭代运算后仍然维持一定的精度。
图2示出本发明实施例的一种板卡20的结构示意图。如图2所示,板卡20包括芯片201,其是一种系统级芯片(System on Chip,SoC),或称片上系统,集成有一个或多个组合处理装置,组合处理装置是一种人工智能运算单元,用以支持各类深度学习和机器学习算法,满足计算机视觉、语音、自然语言处理、数据挖掘等领域复杂场景下的智能处理需求。
芯片201通过对外接口装置202与外部设备203相连接。外部设备203例如是服务器、计算机、摄像头、显示器、鼠标、键盘、网卡或wifi接口等。待处理的数据可以由外部设备203通过对外接口装置202传递至芯片201。芯片201的计算结果可以经由对外接口装置202传送回外部设备203。根据不同的应用场景,对外接口装置202可以具有不同的接口形式,例如PCIe接口等。
板卡20还包括用于存储数据的存储器件204,其包括一个或多个存储单元205。存储器件204通过总线与控制器件206和芯片201进行连接和数据传输。板卡20中的控制器件206配置用于对芯片201的状态进行调控。为此,在一个应用场景中,控制器件206可以包括单片机(Micro Controller Unit,MCU)。
图3是示出此实施例的芯片201中的组合处理装置的结构图。如图3中所示,组合处理装置30包括计算装置301、接口装置302、处理装置303和片外内存304。
计算装置301配置成执行用户指定的操作,主要实现为单核智能处理器或者多核智能处理器,用以执行深度学习或机器学习的计算,其可以通过接口装置302与处理装置303进行交互,以共同完成用户指定的操作。
接口装置302用于在计算装置301与处理装置303间传输数据和控制指令。例如,计算装置301可以经由接口装置302从处理装置303中获取输入数据,写入计算装置301片上的存储装置。进一步,计算装置301可以经由接口装置302从处理装置303中获取控制指令,写入计算装置301片上的控制缓存中。替代地或可选地,接口装置302也可以读取计算装置301的存储装置中的数据并传输给处理装置303。
处理装置303作为通用的处理装置,执行包括但不限于数据搬运、对计算装置301的开启和/或停止等基本控制。根据实现方式的不同,处理装置303可以是中央处理器(central processing unit,CPU)、图形处理器(graphics processing unit,GPU)或其他通用和/或专用处理器中的一种或多种类型的处理器,这些处理器包括但不限于数字信号处理器(digital signal processor,DSP)、专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等,并且其数目可以根据实际需要来确定。如前所述,仅就本发明的计算装置301而言,其可以视为具有单核结构或者同构多核结构。然而,当将计算装置301和处理装置303整合共同考虑时,二者视为形成异构多核结构。
片外内存304用以存储待处理的数据,为DDR内存,大小通常为16G或更大,用于保存计算装置301和/或处理装置303的数据。
图4示出了计算装置301的内部结构示意图。计算装置301用以处理计算机视觉、语音、自然语言、数据挖掘等输入数据,图中的计算装置301采用多核分层结构设计,计算装置301作为一个片上系统,其包括多个集群(cluster),每个集群又包括多个处理器核,换言之,计算装置301是以片上系统-集群-处理器核的层次所构成的。
以片上系统的层级来看,如图4所示,计算装置301包括外部存储控制器401、外设通信模块402、片上互联模块403、同步模块404以及多个集群405。
外部存储控制器401可以有多个,在图中示例性地展示2个,其用以响应处理器核发出的访问请求,访问外部存储设备,例如图3中的片外内存304,从而自片外读取数据或是将数据写入。外设通信模块402用以通过接口装置302接收来自处理装置303的控制信号,启动计算装置301执行任务。片上互联模块403将外部存储控制器401、外设通信模块402及多个集群405连接起来,用以在各个模块间传输数据和控制信号。同步模块404是一种全局同步屏障控制器(global barrier controller,GBC),用以协调各集群的工作进度,确保信息的同步。多个集群405是计算装置301的计算核心,在图中示例性地展示4个。
以集群的层级来看,如图4所示,每个集群405包括多个处理器核(IPU core)406及一个存储核(MEM core)407。
处理器核406在图中示例性地展示4个,本发明不限制处理器核406的数量。其内部架构如图5所示。每个处理器核406包括三大模块:控制模块51、运算模块52及存储模块53。
控制模块51用以协调并控制运算模块52和存储模块53的工作,以完成深度学习的任务,其包括取指单元(instruction fetch unit,IFU)511及指令译码单元(instruction decode unit,IDU)512。取指单元511用以获取来自处理装置303的指令,指令译码单元512则将获取的指令进行译码,并将译码结果作为控制信息发送给运算模块52和存储模块53。
运算模块52包括向量运算单元521及矩阵运算单元522。向量运算单元521用以执行向量运算,可支持向量乘、加、非线性变换等复杂运算;矩阵运算单元522负责深度学习算法的核心计算,即矩阵乘及卷积。
存储模块53用来存储或搬运相关数据,包括神经元存储单元(neuron RAM,NRAM)541、权值存储单元(weight RAM,WRAM)532、输入/输出直接内存访问模块(input/output direct memory access,IODMA)533、搬运直接内存访问模块(move direct memory access,MVDMA)534。NRAM 541用以存储供处理器核406计算的特征图及计算后的中间结果;WRAM 532则用以存储深度学习网络的权值;IODMA 533通过广播总线409控制NRAM 541/WRAM 532与片外内存304的访存;MVDMA 534则用以控制NRAM 541/WRAM 532与SRAM 408的访存。
回到图4,存储核407主要用以存储和通信,即存储处理器核406间的共享数据或中间结果、以及执行集群405与片外内存304之间的通信、集群405间彼此的通信、处理器核406间彼此的通信等。在其他实施例中,存储核407具有标量运算的能力,用以执行标量运算。
存储核407包括共享存储单元(SRAM)408、广播总线409、集群直接内存访问模块(cluster direct memory access,CDMA)410及全局直接内存访问模块(global direct memory access,GDMA) 411。SRAM 408承担高性能数据中转站的角色,在同一个集群405内不同处理器核406之间所复用的数据不需要通过处理器核406各自向片外内存304获得,而是经SRAM 408在处理器核406间中转,存储核407只需要将复用的数据从SRAM 408迅速分发给多个处理器核406即可,以提高核间通讯效率,亦大大减少片上片外的输入/输出访问。
广播总线409、CDMA 410及GDMA 411则分别用来执行处理器核406间的通信、集群405间的通信和集群405与片外内存304的数据传输。以下将分别说明。
广播总线409用以完成集群405内各处理器核406间的高速通信,此实施例的广播总线409支持核间通信方式包括单播、多播与广播。单播是指点对点(即单一处理器核至单一处理器核)的数据传输,多播是将一份数据从SRAM 408传输到特定几个处理器核406的通信方式,而广播则是将一份数据从SRAM 408传输到所有处理器核406的通信方式,属于多播的一种特例。
CDMA 410用以控制在同一个计算装置301内不同集群405间的SRAM 408的访存。
GDMA 411与外部存储控制器401协同,用以控制集群405的SRAM 408到片外内存304的访存,或是将数据自片外内存304读取至SRAM 408中。从前述可知,片外内存304与NRAM 541或WRAM 532间的通信可以经由2个渠道来实现。第一个渠道是通过IODAM 533直接联系片外内存304与NRAM 541或WRAM 532;第二个渠道是先经由GDMA 411使得数据在片外内存304与SRAM 408间传输,再经过MVDMA 534使得数据在SRAM 408与NRAM 541或WRAM 532间传输。
此实施例的计算装置301在进行神经网络模型运算时,会将输入数据从高精度的数据类型转数成低精度的数据类型,再基于低精度的数据类型来执行搬运或运算,以节省硬件资源。更详细来说,计算装置301将输入数据由第一数据类型转换成第二数据类型,其中第一数据类型为高精度,例如FP32,第二数据类型为低精度,例如TF32或PF16,示例性地来说就是计算装置301将输入数据由FP32的数据类型转数成TF32或PF16,再进行处理。本发明不限制转数前后的具体数据类型。
如前所述,每种数据类型都是由符号位、指数位及尾数位来表示的,只是不同数据类型的指数位及/或尾数位的位数不一定相同,为方便说明,在此定义第一数据类型由第一符号位、第一指数位及第一尾数位来表示,第二数据类型由第二符号位、第二指数位及第二尾数位来表示,第一指数位与第二指数位的位数可能不同,第一尾数位与第二尾数位的位数亦可能不同。在转数的过程中浮点数的正负号不会改变,因此第二符号位的数值直接对应至第一符号位的数值即可,此实施例的转数机制特殊处在于通过一套评估方式将第一指数位转换成第二指数位,以及将第一尾数位转换成第二尾数指数位,以实现将输入数据由第一数据类型转换成第二数据类型的过程。
此实施例在进行转数时,是由控制模块51用以发送指令给运算模块52及存储模块53,运算模块52及存储模块53响应接收到的指令来执行的。更详细来说,取指单元511获取来自处理装置303的指令,指令译码单元512则将获取的指令进行译码,并将译码结果作为多个控制信息并按照一定顺序发送给运算模块52和存储模块53,使运算模块52和存储模块53根据这些控制信息依序执行任务,整体实现转数。
进行运算所需的神经元数据及权值数据都属于此实施例的输入数据,这些输入数据从片外内存304被载入至SRAM 408,切分后再从SRAM 408被载入至各个处理器核406的存储模块53,其中神经元数据暂存在NRAM 531中,权值数据暂存在WRAM 532中。存储模块53再根据控制信息,在适当的时间点将暂存的输入数据发送至运算模块52进行转数。
运算模块52同样根据来自指令译码单元512的控制信息,来执行转数操作,更详细来说,此实施例是通过向量运算单元521来执行转数操作。图6示出此实施例将输入数据由第一数据类型转换成第二数据类型的流程图。
在步骤601中,将第二符号位的数值设定为第一符号位的数值。如前所述,不论如何进行转数,输入数据的正负号是不会改变的,因此运算模块52直接将第二符号位的数值设定为第一符号位的数值。
在步骤602中,运算模块52判断第一指数位与第二指数位的位数是否相同。如相同,执行 步骤603,运算模块52直接将第二指数位的数值设定为第一指数位的数值。以FP32转数成TF32为例,运算模块52判断FP32数据的指数位(第一指数位)为8位,而TF32数据的指数位(第二指数位)亦为8位,两者的指数位的位数相同,运算模块52直接将TF32数据的指数位的数值设定为FP32数据的指数位的数值。
在步骤604中,运算模块52进一步决定第一尾数位中,第一尾数位与第二尾数位的位数差个数的比较数据。由于FP32数据的尾数位(第一尾数位)为23位,TF32数据的尾数位(第二尾数位)仅为10位,故第一尾数位与第二尾数位的位数差个数为23-10=13。在第一指数位与第二指数位的位数相同的前提下,比较数据指的是第一尾数位中自最低位向高位截取到的连续数据,其位数为位数差个数,即从第一尾数位中最低位LSB起连续往高位截取13位的数据,这13位的数据便是比较数据。
图7示出在第一指数位与第二指数位的位数相同的前提下决定比较数据的示意图。FP32数据的第一尾数位701为23位,从高位至低位分别为A0至A22,TF32数据的第二尾数位702为10位,从高位至低位分别为B0至B9。运算模块52将TF32数据的第二尾数位702的10位尾数位直接设定为第一尾数位701的最高前10位,如图所示,将第二尾数位702中B0至B9的数值分别设定为第一尾数位701中A0至A9的数值。
再者,第一尾数位701与第二尾数位702的位数差个数为23-10=13,即第一尾数位701比第二尾数位702多了13位。运算模块52自第一尾数位701的最低位A22起连续往高位截取13位的数据,这13位的数据A10至A22便是比较数据703。
在步骤605中,生成随机数据,随机数据具有位数差个数的位数。在此实施例中,随机数据可以由处理装置303生成后随着输入数据一并发送到存储模块53中暂存,或是由存储核407随机生成随机数据中的每个位数的数值,再随着输入数据一并发送到存储模块53中暂存。图7中的数列704即为随机数据,其长度与比较数据703相同,也就是具有位数差个数的位数,为13位,从高位至低位分别为R0至R12。
在步骤606中,运算模块52接着判断比较数据703是否大于随机数据。存储模块53根据控制信息,发送随机数据704至运算模块52,供运算模块52判断比较数据703的数值是否大于随机数据704的数值。如果比较数据703大于随机数据704,表示比较数据703足够大以至于需要进位至B9;如果比较数据703不大于随机数据704,表示比较数据703不够大,直接舍去即可。
在判断比较数据703的数值是否大于随机数据704的数值时,运算模块52会先判断两者的最高位MSB的数值大小,即判断A10与R0的大小。假定A10为1且R0为0,则不论其他位的数值为何,比较数据703都将大于随机数据704;如果A10为0且R0为1,则不论其他位的数值为何,比较数据703都将小于随机数据704;如果A10和R0同为0或1,则运算模块52进一步判断次高位的大小,也就是判断A11与R1的大小,判断方式与判断A10与R0的大小相同。如果同位的两数值大小相同,就继续比较次低位的数值,直到A22与R12。如果A22与R12仍相同,表示比较数据703与随机数据704的数值完全相同。
当比较数据703大于随机数据704时,表示比较数据703足够大以至于在转数的过程中需要进位,执行步骤607,对第二尾数位702进位。运算模块52对第二尾数位702的数值加一,作为转数后的第二尾数位702的数值。举例来说,如果[A0 A1 A2 A3 A4 A5 A6 A7 A8 A9]=[1 0 0 1 0 0 1 1 1 0],则进位后的[B0 B1 B2 B3 B4 B5 B6 B7 B8 B9]=[1 0 0 1 0 0 1 1 1 1],B9的数值为A9的数值加一。如果A9的数值本为1,则B9为0,再进位至B8,以此类推。
在一种极端的情况下,如果第一尾数位701对应于第二尾数位702的所有位(A0至A9)的数值均为1,且需要进位时,第二尾数位702已无多余位可以容纳进位的信息。在这种情况下,第二尾数位702的所有位同样呈现进位后应有的数值,即[B0 B1 B2 B3 B4 B5 B6 B7 B8 B9]=[0 0 0 0 0 0 0 0 0 0],此实施例利用第二指数位来记载第二尾数位602进位后最高位的信息。更详细来说,运算模块52将第二指数位的数值加一,例如第一指数位为16,则第二指数位原本亦为16,在这种情况下,运算模块52将第二指数位调整为16+1=17,又例如第一指数位为-20,则第二指数位为-20+1=-19。在本发明揭露的范围内,只要发生这类极端的情况,也就是在进位 时尾数位的位数不足以记载进位信息时,均以此方式处理之,后续将不再赘述。
当比较数据603不大于随机数据604时,表示比较数据603的数值太小,执行步骤608,直接舍去即可,第二尾数位602不进位,即[B0 B1 B2 B3 B4 B5 B6 B7 B8 B9]=[A0 A1 A2 A3 A4 A5 A6 A7 A8 A9]。
在其他的情况下,比较数据603等于随机数据604的转数方式可适用比较数据603大于随机数据604的转数方式,换言之,本发明并不限制比较数据603等于随机数据604的进位舍去处理方式,可以依实际情况选择进位或舍去。在本发明揭露的范围内,只要发生比较数据603等于随机数据604的情况,均以此方式处理之,后续将不再赘述。
回到步骤602,如果运算模块52判断第一指数位与第二指数位的位数不相同时,执行步骤609,运算模块52会进一步识别输入数据的数值落在哪个区间,不同的区间有不同的转数方式。如前所述,规格化数的取值范围取决于指数位的位数,而非规格化数的取值范围则与指数位的位数加上尾数位的位数有关。
在此实施例中,具体分割出哪些区间以及各个区间的取值范围是基于第一数据类型和第二数据类型而定的。为方便说明,在此定义:第一数据类型的规格化数的取值范围介于2 第一区间数至2 第一上限间,第一数据类型的非规格化数的取值范围介于2 第一下限至2 第一区间数间,第二数据类型的规格化数的取值范围介于2 第二区间数至2 第二上限间,第二数据类型的非规格化数的取值范围介于2 第二下限至2 第二区间数间。
继续以FP32转数成FP16为例,如前所述,FP32的规格化数的取值范围为[2 -126,2 128)且FP32的非规格化数的取值范围为[2 -149,2 -126),则根据定义,第一上限为128、第一区间数为-126、第一下限为-149。FP16的规格化数的取值范围为[2 -14,2 16)且FP16的非规格化数的取值范围为[2 -24,2 -14),则第二上限为16、第二区间数为-14、第二下限为-24。
此实施例根据第一上限、第二上限、第二区间数、第二下限、第一下限的大小进行排序后,定义出5个不同的区间,即:第一区间为[2 第二上限,2 第一上限);第二区间为[2 第二区间数,2 第二上限);第三区间为[2 第二下限,2 第二区间数);第四区间为[2 第二下限-1,2 第二下限);第五区间为[2 第一下限,2 第二下限-1)。对应至FP32转数成FP16的例子,第一区间为[2 16,2 128);第二区间为[2 -14,2 16);第三区间为[2 -24,2 -14);第四区间为[2 -25,2 -24);第五区间为[2 -149,2 -25)。
在步骤610中,基于不同的数值区间设定第二尾数位。运算模块52会识别第一数据类型的输入数据的数值落在哪个区间,不同的区间会采用不同的转数方式或转数规则,下面将继续以FP32转数成FP16为例分别说明各区间所对应的转数方式或转数规则。
当在步骤609中,输入数据的数值被识别出落在第一区间[2 16,2 128)时,表示FP32数据类型的输入数据上溢出FP16的数据类型所能表示的范围,故在步骤610中运算模块52设定第二尾数位上溢,将具有FP32数据类型的输入数据转换为FP16数据类型的无穷,即运算模块52将第二尾数位的全部数值设定为0。接着在步骤611中,基于不同的数值区间设定第二指数位。由于为上溢,运算模块52将第二指数位的全部数值设定为1。
当在步骤609中,输入数据的数值被识别出落在第二区间[2 -14,2 16)时,表示输入数据的数值落在FP16的规格化数范围内。在步骤610中运算模块52进一步决定第一尾数位与第二尾数位的位数差个数的比较数据。在决定比较数据的操作中,由于FP32的尾数位(第一尾数位)为23位,FP16的尾数位(第二尾数位)仅为10位,故第一尾数位与第二尾数位的位数差个数为23-10=13。比较数据指的是第一尾数位中自低位数据向高位数据截取到的连续数据,即从第一尾数位中最低位LSB起连续往高位截取13位的数据,这13位的数据便是比较数据。运算模块52将第二尾数位设定为第一尾数位中自最高位数据向低位数据截取到的连续数据,截取的位数等于第二尾数位的位数,也就是10位。
决定比较数据后,生成随机数据,其具有所述位数差个数的位数。运算模块52接着判断比较数据是否大于随机数据。当比较数据大于随机数据时,运算模块52对第二尾数位进位。当比较数据不大于随机数据时,第二尾数位不进位。也就是说,当输入数据的数值落在第二区间 [2 -14,2 16)时,其第二尾数位的设定方式与图7所示的方式相同,不再赘述。
在步骤611中,基于不同的数值区间设定第二指数位。当输入数据的数值落在第二区间[2 -14,2 16)时,运算模块52将FP16数据的指数位数值设定与FP32的指数位数值相同,即:
2 第一指数位数值-第一上限=2 第二指数位数值-第二上限
故第二指数位的数值=第一指数位的数值-第一上限+第二上限。
当在步骤609中,输入数据的数值被识别出落在第三区间[2 -24,2 -14)时,表示输入数据的数值落在FP16的非规格化数范围内。在步骤610中运算模块52同样需要决定第一尾数位中,第一尾数位与第二尾数位的位数差个数的比较数据,第一尾数位与第二尾数位的位数差个数亦为13,但决定比较数据与前述不同。在这种情况下,运算模块52会选取在第一尾数位中,自最高位起算第二尾数位的位数-(第二区间数-第一指数位的数值+1)起的连续位数差个数的位元作为比较数据。
图8示出当输入数据的数值落在第三区间[2 -24,2 -14)时,决定比较数据的示意图。FP32数据类型的输入数据的第一尾数位801为23位,从高位至低位分别为A0至A22,转数后的FP16数据类型的数据的第二尾数位802为10位,从高位至低位分别为B0至B9,其中,第一尾数位801与第二尾数位802的位数差个数为23-10=13。以一个具体实例来说,假设FP32数据类型的输入数据的数值为(-1) sign×1.man×2 -20,即第一指数位的数值为-20。运算模块52先计算比较数据的起始位,即10-(-14-(-20)+1)=5,比较数据803则为从第一尾数位801的最高位起算第5个位(A4)起的连续13位,也就是A4至A16。
在设定第二尾数位802的数值时,运算模块52分别将B6至B9的数值分别设定为A0至A3的数值,由于FP32的规格化数的尾数形式为1.man,故将B5的数值设定为1.man中的数值1,再将B0至B4的数值设定为0,即第二尾数位802[B0 B1 B2 B3 B4 B5 B6 B7 B8 B9]=[0 0 0 0 0 1 A0 A1 A2 A3]。由上述说明可知,运算模块52先设定第二尾数位802自最高位起算特定数量的位的数值为0,其中特定数量就是起始位,其计算公式为第二尾数位的位数-(第二区间数-第一指数位的数值+1),故B0至B4的数值为0,接着设定第二尾数位802自最高位起算第(特定数量+1)个位(B5)的数值为1,最后设定第二尾数位802自第(特定数量+2)个位起算(特定数量-1)个位的数值为第一尾数位801自最高位起算(特定数量-1)个位的数值,也就是B6=A0,B7=A1,B8=A2,B9=A3。
第二尾数位802的数值设定完成后,运算模块52判断比较数据803是否大于随机数据804。当比较数据803大于随机数据804时,表示要进位,具体而言,运算模块52对B9进位。当比较数据803不大于随机数据804时,则不进位。
在步骤611中,设定第二指数位。由于这区间是第二数据类型的非规格化表示范围,故运算模块52将第二指数位全设为0。
当在步骤609中,输入数据的数值被识别出落在第四区间为[2-25,2-24)时,由于已超出FP16的表示范围,理应为下溢的情况。但考虑到这区间有可能因为进位而成为最小的非规格化数,故在步骤610中要进一步判断。
在这区间中,FP32的表示形式为:
(-1) sign×1.man 1×2 -25
而FP16的表示形式为:
(-1) sign×0.man 2×2 -24
如果FP32的尾数位进位了,考虑到第一指数位与第二指数位刚好差了一位,则进位后第一尾数位退一位后会成为第二尾数位,也就是man 2=[1 man 1]。图9示出输入数据的数值落在第四 区间时,尾数位进行转数的示意图。FP32数据类型的尾数位901具有23位尾数A0至A22。在决定比较数据的操作中,由于FP32的尾数位为23位,FP16的尾数位为10位,第一尾数位与第二尾数位的位数差个数为23-10=13,故比较数据902具有13位。运算模块52会先设定比较数据902的最高位的数值为1,再设定比较数据902的其他位数值为第一尾数位中前位数差个数减1个的数值,因此获得比较数据902为[1 A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11]。
接着,运算模块52判断比较数据902是否大于随机数据903。当比较数据903大于随机数据904时,表示要进位,运算模块52将第二尾数位设定为最小值,即[B0 B1 B2 B3 B4 B5 B6 B7 B8 B9]=[0 0 0 0 0 0 0 0 0 1]。
当比较数据903不大于随机数据904时,表示不进位,运算模块52将输入数据FP32转换为FP16的零,即第二尾数位的全部数值被设定为0。
在步骤611中,设定第二指数位。在此区间中,运算模块52将第二指数位的全部数值设定为0。
当在步骤609中,输入数据的数值被识别出落在第五区间[2 -149,2 -25)时,确定下溢出FP16的表示范围,不论进不进位其数值皆为零,在步骤610中运算模块52直接将FP32数据类型的输入数据转换为FP16数据类型的零,也就是第二尾数位的全部数值被设定为0。在步骤611中,运算模块52将第二指数位的全部数值设定为0。
此实施例在转数时,会重新生成新的随机数据和比较数据进行比较,由于每次随机生成的随机数据不同,使得每次在判断是否进位时的基准均不同。当一个输入数据在深度学习模型中被重复计算数十万遍甚至于上亿遍时,随机生成的随机数据时而大时而小,从大数上来看有助于将转数后数据的精度控制在一定范围内,不会随着迭代的次数越多导致大量的单方面运算(即大量的进位运算或舍去运算)使得误差越大。
前述这些数据存放在存储模块53时,都是以致密连续排布在NRAM 531或WRAM 532中。以FP32和FP16来说,其数据类型分别为32比特和16比特,每个比特都是有效数据,当SRAM 408一次发送多个FP32或FP16的输入数据时,这些数据会接续排列存储在NRAM 531或WRAM 532中。以TF32来说,其数据类型虽然为32比特,但仅有高位的19比特为有效数据,剩余的13比特为无用数据(默认为0),此实施例仍分配32比特的存储空间,使得TF32数据亦是连续排布于NRAM 531或WRAM 532中。
如前所述,当第一数据类型为FP32且第二数据类型为TF32或FP16时,随机数据的长度为13比特,但对于存储空间管理来说,13比特并不友好。为了方便硬件统一处理,此实施例分配给每个随机数据的存储空间为16个比特,也就是2字节,其中只有低位的13个比特数据是有效的,高位的3个比特数据是无用数据(默认为0)。
由于每个FP32数据占用4字节的存储空间,每个随机数据占用2字节的存储空间,而一个FP32数据的转数需要搭配一个随机数据,因此在NRAM 531或WRAM 532中,随机数据的数据量是FP32数据类型的输入数据的数据量的二分之一,即存储模块53分配给随机数据的存储空间为第一数据类型的输入数据的存储空间的二分之一。若将FP32转数成TF32时,则输出数据的数据量与输入数据的数据量相同;若将FP32转数成FP16时,则输出数据的数据量是输入数据的数据量的一半。存储模块53会通过两个通路向运算模块52传输数据,其中第一通路用以传输输入数据,第二通路用以传输随机数据,在将FP32转数成FP16或TF32的情况下,每个周期第一通路的传输数据量为第二通路的传输数据量的2倍。
此实施例是根据动态舍入转数指令来实现前述转数操作的。图10示出此实施例的动态舍入转数指令的示意图。动态舍入转数指令1001包括指代输入数据的首地址的输入数据地址操作域(Input0_addr)1002、指代对应的随机数据的首地址的随机数据地址操作域(Input1_addr)1003、指代输入数据的数据大小的输入数据量操作域(Input0_size)1004、指代转数后数据的首地址的输出数据地址操作域(Output_addr)1005、指代第一数据类型的输入数据类型操作域(Input_dtype)1006以及指代第二数据类型的输出数据类型操作域(Output_dtype)1007。
在将FP32转数成FP16或TF32的情况下,指令译码单元512将获取的动态舍入转数指令进 行译码,并将译码结果分为多个微指令分别发送给运算模块52和存储模块53。存储模块53根据输入数据量操作域1004得知应读取的输入数据的数据量,根据输入数据地址操作域1002的地址取出一个完整的输入数据,再根据随机数据地址操作域1003读取数据量为Input0_size的一半的随机数据。
具体地,第一通道与第二通道的传输带宽以及运算模块52的计算带宽可以设定128字节,即每周期存储模块53都会通过第一通道向运算模块52传输128字节的输入数据。由于每128字节的输入数据仅消耗64字节的随机数据,故每周期存储模块53会通过第二通道向运算模块52传输64字节的随机数据。因此运算模块52会同步收到匹配的输入数据和随机数据,方便进行转数运算。
运算模块52根据输入数据类型操作域1006获得第一数据类型的信息,并根据输出数据类型操作域1007获得第二数据类型的信息,从这2个操作域运算模块52便能得知转数前后的数据类型。如果第二数据类型为TF32,那么运算模块52每周期生成并输出128字节的TF32数据。如果第二数据类型为FP16,那么运算模块52每周期生成64字节的FP16数据,为了尽量满足带宽的要求,运算模块52会间隔1个周期才一次输出128字节的FP16数据,也就是间隔1个周期输出2个64字节的FP16数据。运算模块52再根据输出数据地址操作域1005里的地址,将转数后数据存储至存储模块53相应地址的存储空间中。
此实施例在转数时,都重新生成新的随机数据和比较数据进行比较,由于每次随机生成的随机数据不同,使得每次在判断是否进位时的基准均不同。当一个输入数据在深度学习模型中被重复计算数十万遍甚至于上亿遍时,随机生成的随机数据时而大时而小,从大数上来看有助于将转数后的数据的精度控制在一定范围内,不会随着计算的次数越多使得误差越大。
本发明另一个实施例为一种计算机可读存储介质,其上存储将输入数据由第一数据类型转换成第二数据类型的方法的计算机程序代码,当所述计算机程序代码由处理器运行时,执行如前述实施例的方法。在一些实现场景中,上述集成的单元可以采用软件程序模块的形式来实现。如果以软件程序模块的形式实现并作为独立的产品销售或使用时,所述集成的单元可以存储在计算机可读取存储器中。基于此,当本发明的方案以软件产品(例如计算机可读存储介质)的形式体现时,该软件产品可以存储在存储器中,其可以包括若干指令用以使得计算机设备(例如个人计算机、服务器或者网络设备等)执行本发明实施例所述方法的部分或全部步骤。前述的存储器可以包括但不限于U盘、闪存盘、只读存储器(Read Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
本发明通过生成比较数据,与随机数据进行比较,动态地决定进位或舍入。由于每次的随机数据不同,故同一个输入数据在大量反复转数迭代的过程中,其精度可以维持,不至于随着迭代导致误差越来越大。
根据不同的应用场景,本发明的电子设备或装置可以包括服务器、云端服务器、服务器集群、数据处理装置、机器人、电脑、打印机、扫描仪、平板电脑、智能终端、PC设备、物联网终端、移动终端、手机、行车记录仪、导航仪、传感器、摄像头、相机、摄像机、投影仪、手表、耳机、移动存储、可穿戴设备、视觉终端、自动驾驶终端、交通工具、家用电器、和/或医疗设备。所述交通工具包括飞机、轮船和/或车辆;所述家用电器包括电视、空调、微波炉、冰箱、电饭煲、加湿器、洗衣机、电灯、燃气灶、油烟机;所述医疗设备包括核磁共振仪、B超仪和/或心电图仪。本发明的电子设备或装置还可以被应用于互联网、物联网、数据中心、能源、交通、公共管理、制造、教育、电网、电信、金融、零售、工地、医疗等领域。进一步,本发明的电子设备或装置还可以用于云端、边缘端、终端等与人工智能、大数据和/或云计算相关的应用场景中。在一个或多个实施例中,根据本发明方案的算力高的电子设备或装置可以应用于云端设备(例如云端服务器),而功耗小的电子设备或装置可以应用于终端设备和/或边缘端设备(例如智能手机或摄像头)。在一个或多个实施例中,云端设备的硬件信息和终端设备和/或边缘端设备的硬件信息相互兼容,从而可以根据终端设备和/或边缘端设备的硬件信息,从云端设备的硬件资源中匹配出合适的硬件资源来模拟终端设备和/或边缘端设备的硬件资源,以便完成端云一体或云边端一体的统一管理、 调度和协同工作。
需要说明的是,为了简明的目的,本发明将一些方法及其实施例表述为一系列的动作及其组合,但是本领域技术人员可以理解本发明的方案并不受所描述的动作的顺序限制。因此,依据本发明的公开或教导,本领域技术人员可以理解其中的某些步骤可以采用其他顺序来执行或者同时执行。进一步,本领域技术人员可以理解本发明所描述的实施例可以视为可选实施例,即其中所涉及的动作或模块对于本发明某个或某些方案的实现并不一定是必需的。另外,根据方案的不同,本发明对一些实施例的描述也各有侧重。鉴于此,本领域技术人员可以理解本发明某个实施例中没有详述的部分,也可以参见其他实施例的相关描述。
在具体实现方面,基于本发明的公开和教导,本领域技术人员可以理解本发明所公开的若干实施例也可以通过本文未公开的其他方式来实现。例如,就前文所述的电子设备或装置实施例中的各个单元来说,本文在考虑了逻辑功能的基础上对其进行拆分,而实际实现时也可以有另外的拆分方式。又例如,可以将多个单元或组件结合或者集成到另一个系统,或者对单元或组件中的一些特征或功能进行选择性地禁用。就不同单元或组件之间的连接关系而言,前文结合附图所讨论的连接可以是单元或组件之间的直接或间接耦合。在一些场景中,前述的直接或间接耦合涉及利用接口的通信连接,其中通信接口可以支持电性、光学、声学、磁性或其它形式的信号传输。
在本发明中,作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元示出的部件可以是或者也可以不是物理单元。前述部件或单元可以位于同一位置或者分布到多个网络单元上。另外,根据实际的需要,可以选择其中的部分或者全部单元来实现本发明实施例所述方案的目的。另外,在一些场景中,本发明实施例中的多个单元可以集成于一个单元中或者各个单元物理上单独存在。
在另外一些实现场景中,上述集成的单元也可以采用硬件的形式实现,即为具体的硬件电路,其可以包括数字电路和/或模拟电路等。电路的硬件结构的物理实现可以包括但不限于物理器件,而物理器件可以包括但不限于晶体管或忆阻器等器件。鉴于此,本文所述的各类装置(例如计算装置或其他处理装置)可以通过适当的硬件处理器来实现,例如中央处理器、GPU、FPGA、DSP和ASIC等。进一步,前述的所述存储单元或存储装置可以是任意适当的存储介质(包括磁存储介质或磁光存储介质等),其例如可以是可变电阻式存储器(Resistive Random Access Memory,RRAM)、动态随机存取存储器(Dynamic Random Access Memory,DRAM)、静态随机存取存储器(Static Random Access Memory,SRAM)、增强动态随机存取存储器(Enhanced Dynamic Random Access Memory,EDRAM)、高带宽存储器(High Bandwidth Memory,HBM)、混合存储器立方体(Hybrid Memory Cube,HMC)、ROM和RAM等。
依据以下条款可更好地理解前述内容:
条款A1.一种将输入数据由第一数据类型转换成第二数据类型的方法,所述第一数据类型包括第一指数位及第一尾数位,所述第二数据类型包括第二指数位及第二尾数位,所述方法包括:判断所述第一指数位与所述第二指数位的位数是否相同;如是,执行下列步骤:决定所述第一尾数位中,所述第一尾数位与所述第二尾数位的位数差个数的比较数据;生成随机数据,所述随机数据具有所述位数差个数的位数;判断所述比较数据是否大于所述随机数据;以及如所述比较数据大于所述随机数据,对所述第二尾数位进位。
条款A2.根据条款A1所述的方法,其中如所述第一指数位与所述第二指数位的位数相同,还包括:将所述第二指数位的数值设定为所述第一指数位的数值。
条款A3.根据条款A2所述的方法,其中在所述进位步骤中,如果在进位前所述第一尾数位对应于所述第二尾数位的所有位的数值均为1时,执行下列步骤:设定所述第二尾数位的所有位为进位后的数值;以及将所述第二指数位的数值加一。
条款A4.根据条款A1所述的方法,其中所述第一数据类型的规格化数的取值范围介于2 第一区间数至2 第一上限间,所述第一数据类型的非规格化数的取值范围介于2 第一下限至2 第一区间数间,所述第二数据类型的规格化数的取值范围介于2 第二区间数至2 第二上限间,所述第二数据类型的非规 格化数的取值范围介于2 第二下限至2 第二区间数间,如所述第一指数位与所述第二指数位的位数不相同,所述方法还包括:识别所述输入数据的数值区间;基于所述数值区间设定所述第二尾数位;以及基于所述数值区间设定所述第二指数位。
条款A5.根据条款A4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二上限,2 第一上限)时,在所述设定所述第二尾数位的步骤中将所述第二尾数位的全部数值设定为0。
条款A6.根据条款A5所述的方法,其中在所述设定所述第二指数位的步骤中,所述第二指数位的全部数值被设定为1。
条款A7.根据条款A4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二区间数,2 第二上限)时,所述设定所述第二尾数位的步骤包括:决定所述第一尾数位与所述第二尾数位的位数差个数的比较数据;将所述第二尾数位设定为所述第一尾数位中自最高位数据向低位数据截取到的连续数据,所截取的位数等于所述第二尾数位的位数;生成随机数据,所述随机数据具有所述位数差个数的位数;判断所述比较数据是否大于所述随机数据;以及如所述比较数据大于所述随机数据,对所述第二尾数位进位。
条款A8.根据条款A7所述的方法,其中在所述设定所述第二指数位的步骤中,所述第二指数位的数值=所述第一指数位的数值-所述第一上限+所述第二上限。
条款A9.根据条款A4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二下限,2 第二区间数)时,所述设定所述第二尾数位的步骤包括:决定所述第一尾数位与所述第二尾数位的位数差个数的比较数据;设定所述第二尾数位自最高位起算特定数量的位的数值为0;设定所述第二尾数位自最高位起算第(特定数量+1)个位的数值为1;以及设定所述第二尾数位自第(特定数量+2)个位起算(特定数量-1)个位的数值为所述第一尾数自最高位起算(特定数量-1)个位的数值。
条款A10.根据条款A9所述的方法,其中所述比较数据为所述第一尾数位中,自起始位起的连续位数差个数的位元,所述起始位为自最高位起算所述第二尾数位的位数-(第二区间数-所述第一指数位的数值+1)。
条款A11.根据条款A10所述的方法,其中所述特定数量为所述起始位。
条款A12.根据条款A4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二下限-1,2 第二下限)时,所述设定所述第二尾数位的步骤包括:决定所述第一尾数位与所述第二尾数位的位数差个数的比较数据;生成随机数据,所述随机数据具有所述位数差个数的位数;判断所述比较数据是否大于所述随机数据;以及如所述比较数据大于所述随机数据,将所述第二尾数位设定为最小值。
条款A13.根据条款A12所述的方法,其中所述决定比较数据的步骤包括:设定所述比较数据的最高位的数值为1;以及设定所述比较数据的其他位数值为所述第一尾数位中前所述位数差个数减1个的数值。
条款A14.根据条款A12所述的方法,其中如所述比较数据不大于所述随机数据时,所述第二尾数位的全部数值被设定为0。
条款A15.根据条款A4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第一下限,2 第二下限-1]时,所述设定所述第二尾数位的步骤包括:设定所述第二尾数位的全部数值为0。
条款A16.根据条款A9、12或15所述的方法,其中在所述设定所述第二指数位的步骤中,所述第二指数位的全部数值被设定为0。
条款A17.根据条款A1所述的方法,其中所述生成步骤包括:随机生成所述随机数据中每个位数的数值。
条款A18.根据条款A1所述的方法,其中所述第一数据类型为FP32,且所述第二数据类型为TF32及FP16其中之一。
条款A19.一种计算机可读存储介质,其上存储有将输入数据由第一数据类型转换成第二数据类型的计算机程序代码,当所述计算机程序代码由处理装置运行时,执行条款A1至18任一项所述的方法。
条款A20.一种计算装置,所述计算装置将输入数据由第一数据类型转换成第二数据类型,所述第一数据类型包括第一指数位及第一尾数位,所述第二数据类型包括第二指数位及第二尾数位,所述计算装置包括:控制模块,用以发送多个指令;存储模块,用以暂存所述输入数据及随机数据,并根据所述多个指令至少其中之一,发送所述输入数据及所述随机数据,其中所述随机数据具有位数差个数的位数;运算模块,根据所述多个指令至少其中之一,用以:判断所述第一指数位与所述第二指数位的位数是否相同;如是,决定所述第一尾数位中,所述第一尾数位与所述第二尾数位的所述位数差个数的比较数据;判断所述比较数据是否大于所述随机数据;以及如所述比较数据大于所述随机数据,对所述第二尾数位进位。
条款A21.根据条款A20所述的计算装置,还包括存储核,用以生成所述随机数据。
条款A22.根据条款A21所述的计算装置,其中所述存储核随机生成所述随机数据中每个位数的数值。
条款A23.根据条款A20所述的计算装置,其中所述存储模块分配给所述随机数据的存储空间为所述第一数据类型的输入数据的存储空间的二分之一。
条款A24.根据条款A20所述的计算装置,其中所述指令包括:输入数据地址操作域,用以指代所述输入数据的首地址;随机数据地址操作域,用以指代所述随机数据的首地址;以及输入数据量操作域,用以指代所述输入数据的数据大小;其中,所述存储模块根据所述输入数据量操作域得知所述输入数据的数据量,根据所述输入数据地址操作域取出完整的所述输入数据,再根据所述随机数据地址操作域读取所述随机数据。
条款A25.根据条款A20所述的计算装置,其中所述指令包括:输出数据地址操作域,用以指代转数后数据的首地址;输入数据类型操作域,用以指代所述第一数据类型;以及输出数据类型操作域,用以指代所述第二数据类型;其中,所述运算模块根据所述输入数据类型操作域获得所述第一数据类型的信息,根据所述输出数据类型操作域获得所述第二数据类型的信息,根据所述输出数据地址操作域将所述转数后数据存储至所述存储模块相应地址的存储空间中。
条款A26.一种集成电路装置,包括根据条款A20至25任一项所述的计算装置。
条款A27.一种板卡,包括根据条款A26所述的集成电路装置。
以上对本发明实施例进行了详细介绍,本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想;同时,对于本领域的一般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。

Claims (27)

  1. 一种将输入数据由第一数据类型转换成第二数据类型的方法,所述第一数据类型包括第一指数位及第一尾数位,所述第二数据类型包括第二指数位及第二尾数位,所述方法包括:
    判断所述第一指数位与所述第二指数位的位数是否相同;
    如是,执行下列步骤:
    决定所述第一尾数位中,所述第一尾数位与所述第二尾数位的位数差个数的比较数据;
    生成随机数据,所述随机数据具有所述位数差个数的位数;
    判断所述比较数据是否大于所述随机数据;以及
    如所述比较数据大于所述随机数据,对所述第二尾数位进位。
  2. 根据权利要求1所述的方法,其中如所述第一指数位与所述第二指数位的位数相同,还包括:
    将所述第二指数位的数值设定为所述第一指数位的数值。
  3. 根据权利要求2所述的方法,其中在所述进位步骤中,如果在进位前所述第一尾数位对应于所述第二尾数位的所有位的数值均为1时,执行下列步骤:
    设定所述第二尾数位的所有位为进位后的数值;以及
    将所述第二指数位的数值加一。
  4. 根据权利要求1所述的方法,其中所述第一数据类型的规格化数的取值范围介于2 第一区间数至2 第一上限间,所述第一数据类型的非规格化数的取值范围介于2 第一下限至2 第一区间数间,所述第二数据类型的规格化数的取值范围介于2 第二区间数至2 第二上限间,所述第二数据类型的非规格化数的取值范围介于2 第二下限至2 第二区间数间,如所述第一指数位与所述第二指数位的位数不相同,所述方法还包括:
    识别所述输入数据的数值区间;
    基于所述数值区间设定所述第二尾数位;以及
    基于所述数值区间设定所述第二指数位。
  5. 根据权利要求4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二上限,2 第一上限)时,在所述设定所述第二尾数位的步骤中将所述第二尾数位的全部数值设定为0。
  6. 根据权利要求5所述的方法,其中在所述设定所述第二指数位的步骤中,所述第二指数位的全部数值被设定为1。
  7. 根据权利要求4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二区间数,2 第二上限)时,所述设定所述第二尾数位的步骤包括:
    决定所述第一尾数位与所述第二尾数位的位数差个数的比较数据;
    将所述第二尾数位设定为所述第一尾数位中自最高位数据向低位数据截取到的连续数据,所截取的位数等于所述第二尾数位的位数;
    生成随机数据,所述随机数据具有所述位数差个数的位数;
    判断所述比较数据是否大于所述随机数据;以及
    如所述比较数据大于所述随机数据,对所述第二尾数位进位。
  8. 根据权利要求7所述的方法,其中在所述设定所述第二指数位的步骤中,所述第二指数位的数值=所述第一指数位的数值-所述第一上限+所述第二上限。
  9. 根据权利要求4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二下限,2 第二区间数)时,所述设定所述第二尾数位的步骤包括:
    决定所述第一尾数位与所述第二尾数位的位数差个数的比较数据;
    设定所述第二尾数位自最高位起算特定数量的位的数值为0;
    设定所述第二尾数位自最高位起算第(特定数量+1)个位的数值为1;以及
    设定所述第二尾数位自第(特定数量+2)个位起算(特定数量-1)个位的数值为所述第一尾 数自最高位起算(特定数量-1)个位的数值。
  10. 根据权利要求9所述的方法,其中所述比较数据为所述第一尾数位中,自起始位起的连续位数差个数的位元,所述起始位为自最高位起算所述第二尾数位的位数-(第二区间数-所述第一指数位的数值+1)。
  11. 根据权利要求10所述的方法,其中所述特定数量为所述起始位。
  12. 根据权利要求4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第二下限-1,2 第二下限)时,所述设定所述第二尾数位的步骤包括:
    决定所述第一尾数位与所述第二尾数位的位数差个数的比较数据;
    生成随机数据,所述随机数据具有所述位数差个数的位数;
    判断所述比较数据是否大于所述随机数据;以及
    如所述比较数据大于所述随机数据,将所述第二尾数位设定为最小值。
  13. 根据权利要求12所述的方法,其中所述决定比较数据的步骤包括:
    设定所述比较数据的最高位的数值为1;以及
    设定所述比较数据的其他位数值为所述第一尾数位中前所述位数差个数减1个的数值。
  14. 根据权利要求12所述的方法,其中如所述比较数据不大于所述随机数据时,所述第二尾数位的全部数值被设定为0。
  15. 根据权利要求4所述的方法,其中在所述识别步骤中,当所述输入数据的数值落在[2 第一下限,2 第二下限-1]时,所述设定所述第二尾数位的步骤包括:
    设定所述第二尾数位的全部数值为0。
  16. 根据权利要求9、12或15所述的方法,其中在所述设定所述第二指数位的步骤中,所述第二指数位的全部数值被设定为0。
  17. 根据权利要求1所述的方法,其中所述生成步骤包括:随机生成所述随机数据中每个位数的数值。
  18. 根据权利要求1所述的方法,其中所述第一数据类型为FP32,且所述第二数据类型为TF32及FP16其中之一。
  19. 一种计算机可读存储介质,其上存储有将输入数据由第一数据类型转换成第二数据类型的计算机程序代码,当所述计算机程序代码由处理装置运行时,执行权利要求1至18任一项所述的方法。
  20. 一种计算装置,所述计算装置将输入数据由第一数据类型转换成第二数据类型,所述第一数据类型包括第一指数位及第一尾数位,所述第二数据类型包括第二指数位及第二尾数位,所述计算装置包括:
    控制模块,用以发送多个指令;
    存储模块,用以暂存所述输入数据及随机数据,并根据所述多个指令至少其中之一,发送所述输入数据及所述随机数据,其中所述随机数据具有位数差个数的位数;
    运算模块,根据所述多个指令至少其中之一,用以:
    判断所述第一指数位与所述第二指数位的位数是否相同;
    如是,决定所述第一尾数位中,所述第一尾数位与所述第二尾数位的所述位数差个数的比较数据;
    判断所述比较数据是否大于所述随机数据;以及
    如所述比较数据大于所述随机数据,对所述第二尾数位进位。
  21. 根据权利要求20所述的计算装置,还包括存储核,用以生成所述随机数据。
  22. 根据权利要求21所述的计算装置,其中所述存储核随机生成所述随机数据中每个位数的数值。
  23. 根据权利要求20所述的计算装置,其中所述存储模块分配给所述随机数据的存储空间为所述第一数据类型的输入数据的存储空间的二分之一。
  24. 根据权利要求20所述的计算装置,其中所述指令包括:
    输入数据地址操作域,用以指代所述输入数据的首地址;
    随机数据地址操作域,用以指代所述随机数据的首地址;以及
    输入数据量操作域,用以指代所述输入数据的数据大小;
    其中,所述存储模块根据所述输入数据量操作域得知所述输入数据的数据量,根据所述输入数据地址操作域取出完整的所述输入数据,再根据所述随机数据地址操作域读取所述随机数据。
  25. 根据权利要求20所述的计算装置,其中所述指令包括:
    输出数据地址操作域,用以指代转数后数据的首地址;
    输入数据类型操作域,用以指代所述第一数据类型;以及
    输出数据类型操作域,用以指代所述第二数据类型;
    其中,所述运算模块根据所述输入数据类型操作域获得所述第一数据类型的信息,根据所述输出数据类型操作域获得所述第二数据类型的信息,根据所述输出数据地址操作域将所述转数后数据存储至所述存储模块相应地址的存储空间中。
  26. 一种集成电路装置,包括根据权利要求20至25任一项所述的计算装置。
  27. 一种板卡,包括根据权利要求26所述的集成电路装置。
PCT/CN2022/099771 2021-09-18 2022-06-20 转数方法、存储介质、装置及板卡 WO2023040389A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111101381.9A CN113791756B (zh) 2021-09-18 2021-09-18 转数方法、存储介质、装置及板卡
CN202111101381.9 2021-09-18

Publications (1)

Publication Number Publication Date
WO2023040389A1 true WO2023040389A1 (zh) 2023-03-23

Family

ID=79184127

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/099771 WO2023040389A1 (zh) 2021-09-18 2022-06-20 转数方法、存储介质、装置及板卡

Country Status (2)

Country Link
CN (1) CN113791756B (zh)
WO (1) WO2023040389A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791756B (zh) * 2021-09-18 2022-12-23 中科寒武纪科技股份有限公司 转数方法、存储介质、装置及板卡

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200201602A1 (en) * 2018-12-21 2020-06-25 Graphcore Limited Converting floating point numbers to reduce the precision
CN111340207A (zh) * 2020-03-03 2020-06-26 南京大学 浮点数转换方法及装置
CN113791756A (zh) * 2021-09-18 2021-12-14 中科寒武纪科技股份有限公司 转数方法、存储介质、装置及板卡

Family Cites Families (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5892697A (en) * 1995-12-19 1999-04-06 Brakefield; James Charles Method and apparatus for handling overflow and underflow in processing floating-point numbers
US6996596B1 (en) * 2000-05-23 2006-02-07 Mips Technologies, Inc. Floating-point processor with operating mode having improved accuracy and high performance
JP4049792B2 (ja) * 2003-06-20 2008-02-20 日本電信電話株式会社 浮動小数点形式ディジタル信号可逆符号化方法、及び復号化方法と、その各装置、その各プログラム
JP2006101049A (ja) * 2004-09-29 2006-04-13 Victor Co Of Japan Ltd デジタルアナログ変換装置
CN101685383A (zh) * 2008-09-28 2010-03-31 杨高祥 计算器、基于直接对阶的自由精度浮点数的运算电路
CN101873138A (zh) * 2010-06-11 2010-10-27 江南大学 浮点量化数字信号的降位转换方法及转换器
CN106461758B (zh) * 2014-06-05 2020-01-21 康蒂-特米克微电子有限公司 带有优化的中间数据存储的雷达系统
CN107038016B (zh) * 2017-03-29 2019-11-15 广州酷狗计算机科技有限公司 一种基于gpu的浮点数转换方法及装置
CN107193530B (zh) * 2017-04-28 2020-04-24 广州酷狗计算机科技有限公司 一种生成随机数的方法和装置
CN109993301B (zh) * 2017-12-29 2020-05-19 中科寒武纪科技股份有限公司 神经网络训练装置及相关产品
US10628124B2 (en) * 2018-03-22 2020-04-21 Advanced Micro Devices, Inc. Stochastic rounding logic
US10929127B2 (en) * 2018-05-08 2021-02-23 Intel Corporation Systems, methods, and apparatuses utilizing an elastic floating-point number
GB2580160B (en) * 2018-12-21 2021-01-06 Graphcore Ltd Hardware module for converting numbers
GB2582145B (en) * 2019-03-11 2021-03-10 Graphcore Ltd Execution Unit for Determining a Result of an Exponential Function in a Processor
CN112712172B (zh) * 2019-10-25 2023-12-26 安徽寒武纪信息科技有限公司 用于神经网络运算的计算装置、方法、集成电路和设备
CN110955405B (zh) * 2019-11-26 2023-07-25 深圳鲲云信息科技有限公司 一种输入数据的处理及指数值获取方法、装置及电子设备
US11275560B2 (en) * 2020-02-19 2022-03-15 Meta Platforms, Inc. Hardware for floating-point arithmetic in multiple formats
CN113238989A (zh) * 2021-06-08 2021-08-10 中科寒武纪科技股份有限公司 将数据进行量化的设备、方法及计算机可读存储介质
CN113238987B (zh) * 2021-06-08 2022-11-22 中科寒武纪科技股份有限公司 量化数据的统计量化器、存储装置、处理装置及板卡

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200201602A1 (en) * 2018-12-21 2020-06-25 Graphcore Limited Converting floating point numbers to reduce the precision
CN111340207A (zh) * 2020-03-03 2020-06-26 南京大学 浮点数转换方法及装置
CN113791756A (zh) * 2021-09-18 2021-12-14 中科寒武纪科技股份有限公司 转数方法、存储介质、装置及板卡

Also Published As

Publication number Publication date
CN113791756A (zh) 2021-12-14
CN113791756B (zh) 2022-12-23

Similar Documents

Publication Publication Date Title
US20210224069A1 (en) Calculation method and related product
TWI795519B (zh) 計算裝置、機器學習運算裝置、組合處理裝置、神經網絡芯片、電子設備、板卡及執行機器學習計算的方法
CN110163363B (zh) 一种计算装置及方法
CN110515589B (zh) 乘法器、数据处理方法、芯片及电子设备
WO2023040389A1 (zh) 转数方法、存储介质、装置及板卡
CN111930681A (zh) 一种计算装置及相关产品
CN111258541B (zh) 乘法器、数据处理方法、芯片及电子设备
CN111258633B (zh) 乘法器、数据处理方法、芯片及电子设备
CN113031912A (zh) 乘法器、数据处理方法、装置及芯片
WO2022134873A1 (zh) 数据处理装置、数据处理方法及相关产品
CN111258544A (zh) 乘法器、数据处理方法、芯片及电子设备
CN209895329U (zh) 乘法器
CN111198714B (zh) 重训练方法及相关产品
CN210109789U (zh) 数据处理器
CN110515588B (zh) 乘法器、数据处理方法、芯片及电子设备
WO2023232079A1 (zh) 数据存储、访问、运算方法及相关产品
CN113031915A (zh) 乘法器、数据处理方法、装置及芯片
CN110688087A (zh) 数据处理器、方法、芯片及电子设备
CN111258545A (zh) 乘法器、数据处理方法、芯片及电子设备
CN111382835A (zh) 一种神经网络压缩方法、电子设备及计算机可读介质
WO2023279946A1 (zh) 一种处理装置、设备、方法及其相关产品
CN111047024A (zh) 一种计算装置及相关产品
CN111258540B (zh) 乘法器、数据处理方法、芯片及电子设备
CN113033788B (zh) 数据处理器、方法、装置及芯片
CN209879492U (zh) 乘法器、机器学习运算装置及组合处理装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22868766

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE