WO2021068249A1 - Method and apparatus for hardware simulation and emulation during running, and device and storage medium - Google Patents

Method and apparatus for hardware simulation and emulation during running, and device and storage medium Download PDF

Info

Publication number
WO2021068249A1
WO2021068249A1 PCT/CN2019/110840 CN2019110840W WO2021068249A1 WO 2021068249 A1 WO2021068249 A1 WO 2021068249A1 CN 2019110840 W CN2019110840 W CN 2019110840W WO 2021068249 A1 WO2021068249 A1 WO 2021068249A1
Authority
WO
WIPO (PCT)
Prior art keywords
neural network
simulation
data
result
simulated
Prior art date
Application number
PCT/CN2019/110840
Other languages
French (fr)
Chinese (zh)
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 深圳鲲云信息科技有限公司
Priority to PCT/CN2019/110840 priority Critical patent/WO2021068249A1/en
Priority to CN201980067042.8A priority patent/CN113228056B/en
Publication of WO2021068249A1 publication Critical patent/WO2021068249A1/en

Links

Images

Classifications

    • 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the invention belongs to the field of artificial intelligence technology, and in particular relates to a runtime hardware simulation simulation method, device, equipment and storage medium.
  • Artificial neural network artificial neural network, abbreviation ANN
  • neural network neural network
  • NN neural network
  • Mathematical model or calculation model used to estimate or approximate the function.
  • the neural network is mainly composed of: input layer, hidden layer, and output layer.
  • the network is a two-layer neural network. Since the input layer has not undergone any transformation, it can not be regarded as a separate layer.
  • each neuron in the input layer of the network represents a feature, and the number of output layers represents the number of classification labels (when doing binary classification, if a sigmoid classifier is used, the number of neurons in the output layer is 1 ; If the softmax classifier is used, the number of neurons in the output layer is 2), and the number of hidden layers and hidden layer neurons are manually set.
  • a neural network needs to be simulated and tested continuously from development to delivery.
  • the simulation test generally occurs before the delivery of the neural network product to simulate the real operating environment of the neural network, and the software is configured to the real state of use.
  • the embodiment of the present invention provides a runtime hardware simulation simulation method, which aims to solve the problem of inconsistency between pure floating-point calculation results and hardware calculation results in the existing neural network simulation methods.
  • the embodiment of the present invention is implemented in this way and provides a runtime hardware simulation simulation method, which includes the steps:
  • the step of obtaining the data to be simulated and quantizing the data to be simulated according to the quantization information to obtain the simulation input data includes:
  • the data to be simulated is floating-point type data
  • the neural network parameters are neural network parameters with a unit length of 8 bits
  • the step of quantizing the data to be simulated according to the quantization information specifically further includes:
  • the step of inputting the neural network parameters and the simulation input data to the neural network for convolution calculation, and obtaining the convolution result specifically includes:
  • the neural network parameters include bias parameters
  • the step of obtaining a simulation result based on the convolution result and outputting it specifically includes:
  • the step of obtaining a simulation result for output based on the convolution result includes:
  • the quantization information includes a scaling value
  • the step of dequantizing the convolution result according to the quantization information and the offset value to obtain a simulation result includes:
  • the present invention also provides a runtime hardware simulation simulation device, the device includes:
  • An obtaining module used to obtain a neural network structure diagram and neural network parameters, the neural network structure diagram including quantitative information
  • the construction module is used to simulate and construct a corresponding neural network according to the neural network structure diagram
  • the quantization module is used to obtain the data to be simulated, and quantify the data to be simulated according to the quantization information to obtain simulation input data, and the simulation input data and the neural network parameters are of the same data type;
  • a calculation module configured to input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain a convolution result
  • the output module is used to obtain a simulation result for output based on the convolution result.
  • the quantization module is also used to obtain data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits to obtain simulated input data with a unit length of 8 bits.
  • the present invention also provides a computer device, including a memory and a processor, and a computer program is stored in the memory.
  • a computer program is stored in the memory.
  • the processor executes the computer program, the runtime hardware simulation described in any one of the embodiments of the present invention is implemented. The steps of the simulation method.
  • the present invention also provides a computer-readable storage medium on which a computer program is stored.
  • the computer program is executed by a processor, the runtime hardware simulation described in any one of the embodiments of the present invention is implemented. The steps of the simulation method.
  • the present invention quantifies the data to be simulated into the same hardware data type as the neural network parameters, when software simulation is used, the simulation calculation is closer to the result of the hardware calculation, and the amount of data calculation of the hardware data type Less than the calculation amount of floating point type, it can also improve the calculation speed of neural network simulation.
  • FIG. 1 is a schematic flowchart of a runtime hardware simulation method provided by an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of another runtime hardware simulation method provided by an embodiment of the present invention.
  • FIG. 3 is a schematic flowchart of another runtime hardware simulation method provided by an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of a hardware simulation device at runtime according to an embodiment of the present invention.
  • FIG. 5 is a schematic diagram of a specific flow of an output module 405 according to an embodiment of the present invention.
  • FIG. 6 is a schematic diagram of a specific flow of another output module 405 according to an embodiment of the present invention.
  • Fig. 7 is a schematic structural diagram of an embodiment of a computer device according to an embodiment of the present invention.
  • the simulation of the existing neural network is mainly carried out through hardware simulation or software simulation.
  • the hardware simulation is closer to the calculation logic of the neural network when it is running.
  • the calculation speed of hardware simulation is extremely slow, and it is not suitable for large-scale simulation testing, which leads to the use of software simulation. More.
  • the present invention quantifies the data to be simulated into the same hardware data type as the neural network parameters.
  • the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type. , Can also improve the calculation speed of neural network simulation.
  • FIG. 1 it is a flowchart of an embodiment provided by a runtime hardware simulation method according to the present application.
  • the foregoing method of hardware simulation at runtime includes the steps:
  • the above-mentioned neural network structure diagram includes quantization information, and the above-mentioned quantization information includes information about how long the data is quantized.
  • the simulation software can quantify the data to be simulated according to the above-mentioned quantization information, for example, quantize it into 8bit data.
  • the above-mentioned neural network structure diagram can be a neural network structure diagram of recognition type, such as face recognition, vehicle recognition, etc., or a neural network structure diagram of detection type, such as object detection, vehicle detection, etc.
  • the above-mentioned neural network structure diagram may also be a single-layer network structure diagram, such as a convolutional neural network corresponding to a convolutional layer.
  • the above-mentioned neural network structure diagram can be understood as a neural network structure, and further, can be understood as a neural network structure used for various neural network models.
  • the above-mentioned neural network structure uses layers as computing units, including but not limited to: convolutional layer, pooling layer, ReLU, fully connected layer, and so on.
  • the aforementioned neural network parameters refer to the parameters corresponding to each layer in the neural network structure, and may be weight parameters, bias parameters, and so on.
  • the above-mentioned various neural network models can be pre-trained corresponding neural network models. Since the neural network model is pre-trained, the attributes of the neural network parameters are also trained. Therefore, the neural network configured in the simulation software It can be used directly according to the configured neural network parameters, and there is no need to train the neural network. According to the pre-trained neural network model, the neural network structure diagram and parameters can be uniformly described.
  • the neural network structure diagram and neural network parameters described above can be acquired locally or on a cloud server.
  • the neural network structure diagram and neural network parameters described above can be stored locally and automatically when used.
  • the selection or the user selects, or uploads the neural network structure diagram and neural network parameters to the cloud server, and downloads the neural network structure diagram and neural network parameters in the cloud server through the network when in use.
  • S102 Simulate and construct a corresponding neural network according to the neural network structure diagram.
  • the neural network structure diagram is the neural network structure diagram obtained in step S101, and the obtained neural network structure diagram is simulated in the simulation software, so as to construct the corresponding neural network in the software.
  • S103 Obtain the data to be simulated, and quantify the simulated data according to the quantization information to obtain simulation input data.
  • the aforementioned data to be simulated is data input by the user.
  • the neural network is an image processing type neural network
  • the data input by the user is image data.
  • the above-mentioned quantization can be done by a compiler.
  • r refers to the floating point value, which is the data input by the user
  • q refers to the quantized data
  • z is the offset value
  • s is the zoom
  • the values, s and z are generated by the compiler.
  • the input data to be simulated is quantized by the compiler to obtain the quantized simulation input data.
  • the obtained simulation input data and neural network parameters are the same data type.
  • the neural network parameters are different from the data to be simulated.
  • the neural network parameters are of the hardware data type, and the data to be simulated are of the floating point data type. After being quantized by the compiler, the data to be simulated becomes simulation input data, which is the same data type as the neural network parameters.
  • the above steps of acquiring the data to be simulated, and quantizing the data to be simulated according to the quantization information to obtain the simulation input data include:
  • the neural network parameters are also 8-bit unit length data, and the neural network parameters include weight parameters and bias parameters.
  • S104 Input the neural network parameters and the simulation input data to the neural network for convolution calculation, and obtain the convolution result.
  • the aforementioned neural network includes a convolutional layer, which can perform convolution calculations on the neural network parameters and simulation input data.
  • the convolution calculation process in the neural network is consistent with the floating-point calculation process, that is, the data of the hardware data type is calculated through the floating-point calculation process, so that the floating-point calculation is The result is closer to the hardware calculation result.
  • the aforementioned convolution result is the convolution result calculated in step S104, and the aforementioned convolution result can be output as a simulation result after being processed by the activation layer.
  • the convolution result is obtained, there is no active layer, and the convolution result is input to the next layer of the network for calculation, for example, the pooling layer is performed to pool the convolution result.
  • the neural network structure diagram and neural network parameters are obtained, and the neural network structure diagram includes quantitative information; the corresponding neural network is simulated and constructed according to the neural network structure diagram; the data to be simulated is obtained, and the simulated data is quantified according to the quantitative information ,
  • the simulation input data and the neural network parameters are the same hardware data type; input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain the convolution result; based on the convolution result, the simulation result is obtained. Output.
  • the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type.
  • the calculation speed of neural network simulation can be improved.
  • FIG. 2 it is a flowchart of an embodiment provided by another runtime hardware simulation method according to the present application.
  • S202 Simulate and construct a corresponding neural network according to the neural network structure diagram.
  • S203 Obtain data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits to obtain simulation input data with a unit length of 8 bits.
  • the neural network parameters are also 8-bit unit length data, and the neural network parameters include weight parameters and bias parameters.
  • the integer data is the calculation data of the hardware, which makes the simulation calculation of the software closer to the calculation logic of the hardware, so that the simulation calculation result of the software is closer to the calculation result of the hardware.
  • S204 Input the neural network parameters of the int32 and the simulation input data into the neural network for convolution calculation, and obtain the convolution result of the int32.
  • the above-mentioned bias parameters are the bias parameters in the neural network parameters, and the above-mentioned process of adding the bias parameters is to perform addition calculation in the bias layer.
  • y is the output
  • x is the input
  • w*x is the convolution of the weight parameter and the input value
  • b is the bias parameter.
  • the bias result is activated by the activation function of the activation layer to output the bias result.
  • the bias result will be input to the next calculation node for calculation.
  • S207 Perform inverse quantization on the bias result passing through the active layer to obtain a simulation result.
  • r refers to the floating point value, which is the data input by the user
  • q refers to the quantized data
  • z is the offset value
  • s is the scaling value
  • s and z are generated by the compiler.
  • the simulation result is output to the user so that the user knows the simulation result.
  • the simulation result is used to provide benchmark data as a hardware reference, and to provide a calculation model for algorithm testing. Provide guidance for hardware design.
  • the neural network structure diagram and neural network parameters are obtained, and the neural network structure diagram includes quantitative information; the corresponding neural network is simulated and constructed according to the neural network structure diagram; the data to be simulated is obtained, and the simulated data is quantified according to the quantitative information ,
  • the simulation input data and the neural network parameters are the same hardware data type; input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain the convolution result; based on the convolution result, the simulation result is obtained. Output.
  • the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type.
  • the calculation speed of neural network simulation can be improved.
  • the entire calculation process is closer to the calculation mode of the hardware, reducing irrelevant content in floating-point calculations, and facilitating the hardware to be used for output verification.
  • the calculation mode and operation mode are consistent with the hardware, the final calculation result of the hardware can be directly simulated, which can be used for algorithm testing of neural networks.
  • the specific steps include:
  • S301 The user inputs picture data.
  • S302 quantize the input picture data, and quantize the image data of Float32 into picture data with a unit length of 8 bits.
  • the user inputs a neural network weight parameter
  • the neural network weight parameter is a neural network weight parameter with a unit length of 8 bits.
  • step S305 the neural network weight parameter is also subtracted from the offset value to become an int32 neural network weight parameter for input to the convolutional layer, and step S306 is entered.
  • S306 Perform convolution calculation on the processed image data and the processed neural network weight parameter to obtain a convolution result.
  • step S308 Determine whether there is an activation layer or an activation function. If it does, dequantize the feature map and output it to the user; if it does not exist, go to step S309.
  • the neural network structure diagram and neural network parameters are obtained, and the neural network structure diagram includes quantitative information; the corresponding neural network is simulated and constructed according to the neural network structure diagram; the data to be simulated is obtained, and the simulated data is quantified according to the quantitative information ,
  • the simulation input data and the neural network parameters are the same hardware data type; input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain the convolution result; based on the convolution result, the simulation result is obtained. Output.
  • the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type.
  • the calculation speed of neural network simulation can be improved.
  • the entire calculation process is closer to the calculation mode of the hardware, reducing irrelevant content in floating-point calculations, and facilitating the hardware to be used for output verification.
  • the calculation mode and operation mode are consistent with the hardware, the final calculation result of the hardware can be directly simulated, which can be used for algorithm testing of neural networks.
  • the computer program can be stored in a computer readable storage medium, and the program can be stored in a computer readable storage medium. When executed, it may include the procedures of the above-mentioned method embodiments.
  • the aforementioned storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.
  • the foregoing device 400 includes:
  • the obtaining module 401 is configured to obtain a neural network structure diagram and neural network parameters, where the neural network structure diagram includes quantitative information;
  • the construction module 402 is used to simulate and construct a corresponding neural network according to the neural network structure diagram
  • the quantization module 403 is configured to obtain the data to be simulated, and quantify the data to be simulated according to the quantization information to obtain simulation input data, and the simulation input data and the neural network parameters are of the same data type;
  • the calculation module 404 is configured to input the neural network parameters and the simulation input data into the neural network for convolution calculation, and obtain a convolution result;
  • the output module 405 is configured to obtain a simulation result for output based on the convolution result.
  • the quantization module is also used to obtain the data to be simulated, and according to the quantization information, convert the data to be simulated into the data to be simulated with a unit length of 8 bits to obtain a simulation with a unit length of 8 bits. Input data.
  • the data to be simulated is floating-point type data
  • the neural network parameter is a neural network parameter with a length of 8bit unit
  • the quantization module 403 is also used to calculate the neural network with a length of 8bit unit.
  • the network data and the simulation input data of the 8-bit unit length are respectively subtracted from their own floating-point offset values to obtain integer data of int32;
  • the calculation module 404 is also used to input the neural network parameters of the int32 and the simulation input data into the neural network for convolution calculation to obtain the convolution result of the int32.
  • the neural network parameters include bias parameters
  • the output module 405 includes:
  • the bias unit 4051 is configured to add a bias parameter to the convolution result of the int32 to obtain the bias result of the int32;
  • the first output unit 4052 is configured to obtain a simulation result for output based on the bias result.
  • the output module 405 includes:
  • the dequantization unit 4053 is configured to dequantize the convolution result according to the quantization information and the offset value to obtain a simulation result;
  • the second output unit 4054 is configured to output the simulation result.
  • the quantization information includes a scaling value
  • the inverse quantization unit 4053 is further configured to perform inverse quantization on the convolution result according to the scaling value and the offset value to obtain a simulation result.
  • the runtime hardware simulation device provided by the embodiment of the present application can realize the various implementation manners in the method embodiments of FIG. 1 to FIG. 3 and the corresponding beneficial effects. In order to avoid repetition, details are not described herein again.
  • FIG. 7 is a block diagram of the basic structure of the computer device in this embodiment.
  • the computer device 7 includes a memory 701, a processor 702, and a network interface 703 that are connected to each other in communication through a system bus. It should be pointed out that only the computer device 70 with components 701-703 is shown in the figure, but it should be understood that it is not required to implement all the illustrated components, and more or fewer components may be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculation and/or information processing in accordance with pre-set or stored instructions.
  • Its hardware includes, but is not limited to, a microprocessor, a dedicated Integrated Circuit (Application Specific Integrated Circuit, ASIC), Programmable Gate Array (Field-Programmable GateArray, FPGA), Digital Processor (Digital Signal Processor, DSP), embedded equipment, etc.
  • ASIC Application Specific Integrated Circuit
  • ASIC Application Specific Integrated Circuit
  • FPGA Field-Programmable GateArray
  • DSP Digital Processor
  • the computer equipment can be computing equipment such as desktop computers, notebooks, palmtop computers, and cloud servers. Computer equipment can interact with customers through keyboard, mouse, remote control, touchpad or voice control equipment.
  • the memory 701 includes at least one type of readable storage medium.
  • the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory ( SRAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), magnetic memory, magnetic disks, optical disks, etc.
  • the memory 701 may be an internal storage unit of the computer device 7, such as a hard disk or a memory of the computer device 7.
  • the memory 701 may also be an external storage device of the computer device 7, such as a plug-in hard disk, a smart media card (SMC), and a secure digital (Secure Digital, SD) card, flash card (Flash Card), etc.
  • the memory 701 may also include both the internal storage unit of the computer device 7 and its external storage device.
  • the memory 701 is generally used to store an operating system and various application software installed in the computer device 7, such as a program code of a real-time hardware simulation method.
  • the memory 701 can also be used to temporarily store various types of data that have been output or will be output.
  • the processor 702 may be a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments.
  • the processor 702 is generally used to control the overall operation of the computer device 7.
  • the processor 702 is configured to run the program code stored in the memory 701 or process data, for example, run the program code of a real-time hardware simulation method.
  • the network interface 703 may include a wireless network interface or a wired network interface, and the network interface 703 is generally used to establish a communication connection between the computer device 7 and other electronic devices.
  • This application also provides another implementation manner, that is, a computer-readable storage medium is provided.
  • the computer-readable storage medium stores a runtime hardware simulation simulation program, and the aforementioned runtime hardware simulation simulation program can be processed by at least one The processor executes, so that at least one processor executes the steps of the above-mentioned runtime hardware simulation method.
  • the technical solution of this application essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM/RAM, magnetic disk, The optical disc) includes a number of instructions to make a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute a runtime hardware simulation method of each embodiment of the present application.
  • a terminal device which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

Provided are a method and apparatus for hardware simulation and emulation during running, and a computer device and a storage medium, wherein same are applied to the field of artificial intelligence. The method comprises: acquiring a neural network structure graph and a neural network parameter (S101); constructing a corresponding neural network in a simulated manner according to the neural network structure graph (S102); acquiring data to be emulated, and quantizing the data according to quantization information to obtain emulation input data (S103), wherein the emulation input data and the neural network parameter are of the same hardware data type; inputting the neural network parameter and the emulation input data into the neural network for convolution calculation to obtain a convolution result (S104); and on the basis of the convolution result, obtaining an emulation result and outputting same (S105). Since data to be emulated is quantized to be of the same hardware data type as a neural network parameter, when software is used for emulation, a result of emulation calculation is closer to that of hardware calculation; and the data calculation amount of the hardware data type is less than the calculation amount of a floating-point type, such that the calculation speed of neural network emulation can also be increased.

Description

运行时硬件模拟仿真方法、装置、设备及存储介质Run-time hardware simulation simulation method, device, equipment and storage medium 技术领域Technical field
本发明属于人工智能技术领域,尤其涉及一种运行时硬件模拟仿真方法、装置、设备及存储介质。The invention belongs to the field of artificial intelligence technology, and in particular relates to a runtime hardware simulation simulation method, device, equipment and storage medium.
背景技术Background technique
人工神经网络(artificial neural network,缩写ANN),简称神经网络(neural network,缩写NN)或类神经网络,是一种模仿生物神经网络(动物的中枢神经系统,特别是大脑)的结构和功能的数学模型或计算模型,用于对函数进行估计或近似。Artificial neural network (artificial neural network, abbreviation ANN), abbreviated as neural network (neural network, abbreviation NN) or neural network, is a kind of imitating the structure and function of biological neural network (animal central nervous system, especially brain) Mathematical model or calculation model, used to estimate or approximate the function.
神经网络主要由:输入层,隐藏层,输出层构成。当隐藏层只有一层时,该网络为两层神经网络,由于输入层未做任何变换,可以不看做单独的一层。实际中,网络输入层的每个神经元代表了一个特征,输出层个数代表了分类标签的个数(在做二分类时,如果采用sigmoid分类器,输出层的神经元个数为1个;如果采用softmax分类器,输出层神经元个数为2个),而隐藏层层数以及隐藏层神经元是由人工设定。The neural network is mainly composed of: input layer, hidden layer, and output layer. When there is only one hidden layer, the network is a two-layer neural network. Since the input layer has not undergone any transformation, it can not be regarded as a separate layer. In practice, each neuron in the input layer of the network represents a feature, and the number of output layers represents the number of classification labels (when doing binary classification, if a sigmoid classifier is used, the number of neurons in the output layer is 1 ; If the softmax classifier is used, the number of neurons in the output layer is 2), and the number of hidden layers and hidden layer neurons are manually set.
一个神经网络在开发到交付的过程中,需要不断进行仿真测试。仿真测试一般发生在神经网络产品交付使用前,模拟神经网络的真实运行环境,软件配置到真实的使用状态进行的测试。A neural network needs to be simulated and tested continuously from development to delivery. The simulation test generally occurs before the delivery of the neural network product to simulate the real operating environment of the neural network, and the software is configured to the real state of use.
现有的仿真测试一般是通过验证工具链接到硬件上进行仿真模拟,或者是使用软件模拟硬件计算结果。然而,在硬件上进行仿真模拟,仿真速度极慢,且大规模测试需要硬件资源更多,不容易实现,导致使用软件仿真的较多。而使用软件仿真时,由于软件仿真采用的纯浮点计算结果与硬件计算结果存在一定的数值差别,无法达到完全的数值一致。因此,现有的神经网络仿真方法存 在纯浮点计算结果与硬件计算结果不一致的问题,导致神经网络在交付的产品上运行时得到的结果与仿真的结果不一致。Existing simulation tests generally use verification tools to link to the hardware for simulation simulation, or use software to simulate hardware calculation results. However, the simulation is performed on hardware, the simulation speed is extremely slow, and large-scale testing requires more hardware resources, which is not easy to implement, resulting in more software simulations. When using software simulation, there is a certain numerical difference between the pure floating-point calculation results used in the software simulation and the hardware calculation results, and the complete numerical consistency cannot be achieved. Therefore, the existing neural network simulation method has the problem of inconsistency between pure floating-point calculation results and hardware calculation results, resulting in inconsistencies between the results of the neural network and the simulation results when the neural network runs on the delivered product.
发明内容Summary of the invention
本发明实施例提供一种运行时硬件模拟仿真方法,旨在解决现有的神经网络仿真方法存在纯浮点计算结果与硬件计算结果不一致的问题。The embodiment of the present invention provides a runtime hardware simulation simulation method, which aims to solve the problem of inconsistency between pure floating-point calculation results and hardware calculation results in the existing neural network simulation methods.
本发明实施例是这样实现的,提供一种运行时硬件模拟仿真方法,包括步骤:The embodiment of the present invention is implemented in this way and provides a runtime hardware simulation simulation method, which includes the steps:
获取神经网络结构图与神经网络参数,所述神经网络结构图包括量化信息;Acquiring a neural network structure diagram and neural network parameters, where the neural network structure diagram includes quantitative information;
根据所述神经网络结构图模拟构建对应的神经网络;Simulate and construct a corresponding neural network according to the neural network structure diagram;
获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据,所述仿真输入数据与所述神经网络参数为同一硬件数据类型;Acquiring data to be simulated, and quantizing the data to be simulated according to the quantization information to obtain simulation input data, where the simulation input data and the neural network parameters are of the same hardware data type;
将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果;Inputting the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain a convolution result;
基于所述卷积结果,得到仿真结果进行输出。Based on the convolution result, the simulation result is obtained and output.
更进一步的,所述获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据的步骤包括:Furthermore, the step of obtaining the data to be simulated and quantizing the data to be simulated according to the quantization information to obtain the simulation input data includes:
获取待仿真数据,并根据所述量化信息,将所述待仿真数据转换为8bit单元长度的待仿真数据,得到8bit单元长度的仿真输入数据。Obtain the data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits to obtain simulation input data with a unit length of 8 bits.
更进一步的,所述待仿真数据为浮点类型数据,所述神经网络参数为8bit单元长度的神经网络参数,所述对所述待仿真数据按所述量化信息进行量化的步骤具体还包括:Furthermore, the data to be simulated is floating-point type data, the neural network parameters are neural network parameters with a unit length of 8 bits, and the step of quantizing the data to be simulated according to the quantization information specifically further includes:
对所述8bit单元长度的神经网络数据与所述8bit单元长度的仿真输入数据分别减去自身的浮点偏移值,得到int32的整型数据;Subtracting the floating-point offset value of the neural network data of the 8-bit unit length and the simulation input data of the 8-bit unit length respectively to obtain the integer data of int32;
所述将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果的步骤具体包括:The step of inputting the neural network parameters and the simulation input data to the neural network for convolution calculation, and obtaining the convolution result specifically includes:
将int32的神经网络参数与仿真输入数据输入到神经网络中进行卷积计算,得到int32的卷积结果。Input the neural network parameters of int32 and the simulation input data into the neural network for convolution calculation, and get the convolution result of int32.
更进一步的,所述神经网络参数包括偏置参数,所述基于所述卷积结果,得到仿真结果进行输出的步骤具体包括:Furthermore, the neural network parameters include bias parameters, and the step of obtaining a simulation result based on the convolution result and outputting it specifically includes:
将所述int32的卷积结果加上偏置参数,得到int32的偏置结果;Add the offset parameter to the convolution result of the int32 to obtain the offset result of the int32;
基于所述偏置结果,得到仿真结果进行输出。Based on the offset result, the simulation result is obtained and output.
更进一步的,所述基于所述卷积结果,得到仿真结果进行输出的步骤包括:Furthermore, the step of obtaining a simulation result for output based on the convolution result includes:
根据所述量化信息以及所述偏移值对所述卷积结果进行反量化,得到仿真结果;Performing inverse quantization on the convolution result according to the quantization information and the offset value to obtain a simulation result;
对所述仿真结果进行输出。Output the simulation result.
更进一步的,所述量化信息包括缩放值,所述根据所述量化信息以及所述偏移值对所述卷积结果进行反量化,得到仿真结果的步骤包括:Furthermore, the quantization information includes a scaling value, and the step of dequantizing the convolution result according to the quantization information and the offset value to obtain a simulation result includes:
根据所述缩放值以及所述偏移值对所述卷积结果进行反量化,得到仿真结果。Perform inverse quantization on the convolution result according to the scaling value and the offset value to obtain a simulation result.
本发明还提供一种运行时硬件模拟仿真装置,所述装置包括:The present invention also provides a runtime hardware simulation simulation device, the device includes:
获取模块,用于获取神经网络结构图与神经网络参数,所述神经网络结构图包括量化信息;An obtaining module, used to obtain a neural network structure diagram and neural network parameters, the neural network structure diagram including quantitative information;
构建模块,用于根据所述神经网络结构图模拟构建对应的神经网络;The construction module is used to simulate and construct a corresponding neural network according to the neural network structure diagram;
量化模块,用于获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据,所述仿真输入数据与所述神经网络参数为同一数据类型;The quantization module is used to obtain the data to be simulated, and quantify the data to be simulated according to the quantization information to obtain simulation input data, and the simulation input data and the neural network parameters are of the same data type;
计算模块,用于将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果;A calculation module, configured to input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain a convolution result;
输出模块,用于基于所述卷积结果,得到仿真结果进行输出。The output module is used to obtain a simulation result for output based on the convolution result.
更进一步的,所述量化模块还用于获取待仿真数据,并根据所述量化信息,将所述待仿真数据转换为8bit单元长度的待仿真数据,得到8bit单元长度的仿 真输入数据。Furthermore, the quantization module is also used to obtain data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits to obtain simulated input data with a unit length of 8 bits.
本发明还提供一种计算机设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器执行所述计算机程序时实现本发明实施例中任一项所述的运行时硬件模拟仿真方法的步骤。The present invention also provides a computer device, including a memory and a processor, and a computer program is stored in the memory. When the processor executes the computer program, the runtime hardware simulation described in any one of the embodiments of the present invention is implemented. The steps of the simulation method.
本发明还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现本发明实施例中任一项所述的运行时硬件模拟仿真方法的步骤。The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the runtime hardware simulation described in any one of the embodiments of the present invention is implemented. The steps of the simulation method.
本发明实现的有益效果:本发明由于将待仿真数据量化为与神经网络参数相同的硬件数据类型,在使用软件仿真时,使得仿真计算更贴近硬件计算的结果,且硬件数据类型的数据计算量小于浮点类型的计算量,还可以提高神经网络仿真的计算速度。The beneficial effects achieved by the present invention: because the present invention quantifies the data to be simulated into the same hardware data type as the neural network parameters, when software simulation is used, the simulation calculation is closer to the result of the hardware calculation, and the amount of data calculation of the hardware data type Less than the calculation amount of floating point type, it can also improve the calculation speed of neural network simulation.
附图说明Description of the drawings
图1是本发明实施例提供的一种运行时硬件模拟仿真方法的流程示意图;FIG. 1 is a schematic flowchart of a runtime hardware simulation method provided by an embodiment of the present invention;
图2是本发明实施例提供的另一种运行时硬件模拟仿真方法的流程示意图;2 is a schematic flowchart of another runtime hardware simulation method provided by an embodiment of the present invention;
图3是本发明实施例提供的另一种运行时硬件模拟仿真方法的流程示意图;3 is a schematic flowchart of another runtime hardware simulation method provided by an embodiment of the present invention;
图4是本发明实施例提供的一种运行时硬件模拟仿真装置的结构示意图;4 is a schematic structural diagram of a hardware simulation device at runtime according to an embodiment of the present invention;
图5是本发明实施例提供的一种输出模块405的具体流程示意图;FIG. 5 is a schematic diagram of a specific flow of an output module 405 according to an embodiment of the present invention;
图6是本发明实施例提供的另一种输出模块405的具体流程示意图;FIG. 6 is a schematic diagram of a specific flow of another output module 405 according to an embodiment of the present invention;
图7是本发明实施例的计算机设备的一个实施例的结构示意图。Fig. 7 is a schematic structural diagram of an embodiment of a computer device according to an embodiment of the present invention.
具体实施方式Detailed ways
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。In order to make the objectives, technical solutions, and advantages of the present invention clearer, the following further describes the present invention in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention, but not to limit the present invention.
现有神经网络的仿真主要是通过硬件仿真或软件仿真进行,硬件仿真更贴 近神经网络运行时的计算逻辑,但硬件仿真的计算速度极慢,不适于大规模的仿真测试,导致使用软件仿真的较多。而使用软件仿真时,由于软件仿真采用的纯浮点计算结果与硬件计算结果存在一定的数值差别,无法达到完全的数值一致。本发明由于将待仿真数据量化为与神经网络参数相同的硬件数据类型,在使用软件仿真时,使得仿真计算更贴近硬件计算的结果,且硬件数据类型的数据计算量小于浮点类型的计算量,还可以提高神经网络仿真的计算速度。The simulation of the existing neural network is mainly carried out through hardware simulation or software simulation. The hardware simulation is closer to the calculation logic of the neural network when it is running. However, the calculation speed of hardware simulation is extremely slow, and it is not suitable for large-scale simulation testing, which leads to the use of software simulation. More. When using software simulation, there is a certain numerical difference between the pure floating-point calculation results used in the software simulation and the hardware calculation results, and the complete numerical consistency cannot be achieved. The present invention quantifies the data to be simulated into the same hardware data type as the neural network parameters. When using software simulation, the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type. , Can also improve the calculation speed of neural network simulation.
如图1所示,为根据本申请的一种运行时硬件模拟仿真方法所提供的一个实施例的流程图。上述的一种运行时硬件模拟仿真方法,包括步骤:As shown in FIG. 1, it is a flowchart of an embodiment provided by a runtime hardware simulation method according to the present application. The foregoing method of hardware simulation at runtime includes the steps:
S101,获取神经网络结构图与神经网络参数。S101: Obtain a neural network structure diagram and neural network parameters.
其中,上述的神经网络结构图包括量化信息,上述的量化信息包括将数据量化为多少长度的信息。Wherein, the above-mentioned neural network structure diagram includes quantization information, and the above-mentioned quantization information includes information about how long the data is quantized.
仿真软件可以根据上述的量化信息将待仿真数据进行量化,比如量化为8bit数据等。The simulation software can quantify the data to be simulated according to the above-mentioned quantization information, for example, quantize it into 8bit data.
上述的神经网络结构图可以是识别类的神经网络结构图,比如人脸识别,车辆识别等,也可以是检测类的神经网络结构图,比如物体检测,车辆检测等。The above-mentioned neural network structure diagram can be a neural network structure diagram of recognition type, such as face recognition, vehicle recognition, etc., or a neural network structure diagram of detection type, such as object detection, vehicle detection, etc.
上述的神经网络结构图也可以是单层的网络结构图,比如卷积层对应的卷积神经网络等。The above-mentioned neural network structure diagram may also be a single-layer network structure diagram, such as a convolutional neural network corresponding to a convolutional layer.
上述的神经网络结构图可以理解为神经网络结构,进一步的,可以理解为用于各类神经网络模型的神经网络结构。上述的神经网络结构是以层为计算单元的,包含且不限于:卷积层、池化层、ReLU、全连接层等。The above-mentioned neural network structure diagram can be understood as a neural network structure, and further, can be understood as a neural network structure used for various neural network models. The above-mentioned neural network structure uses layers as computing units, including but not limited to: convolutional layer, pooling layer, ReLU, fully connected layer, and so on.
上述的神经网络参数是指的神经网络结构中的每一层对应的参数,可以是权重参数、偏置参数等。上述的各类神经网络模型可以是预先训练好的对应神经网络模型,由于神经网络模型是预先训练好的,其神经网络参数的属性也是训练好的,因此,在仿真软件中配置好的神经网络可以根据配置的神经网络参数直接使用,不需要再对神经网络进行训练,根据该预先训练好的神经网络模型,可以通过神经网络结构图以及参数进行统一描述。The aforementioned neural network parameters refer to the parameters corresponding to each layer in the neural network structure, and may be weight parameters, bias parameters, and so on. The above-mentioned various neural network models can be pre-trained corresponding neural network models. Since the neural network model is pre-trained, the attributes of the neural network parameters are also trained. Therefore, the neural network configured in the simulation software It can be used directly according to the configured neural network parameters, and there is no need to train the neural network. According to the pre-trained neural network model, the neural network structure diagram and parameters can be uniformly described.
上述获取神经网络结构图以及神经网络参数可以是在本地进行获取,也可以是云服务器上进行获取,比如:上述的神经网络结构图以及神经网络参数可以成套的存储在本地,在使用时自动进行选择或者用户进行选择,或者是将神经网络结构图以及神经网络参数上传到云服务器中,在使用时通过网络将云服务器中的神经网络结构图以及神经网络参数下载下来。The neural network structure diagram and neural network parameters described above can be acquired locally or on a cloud server. For example, the neural network structure diagram and neural network parameters described above can be stored locally and automatically when used. The selection or the user selects, or uploads the neural network structure diagram and neural network parameters to the cloud server, and downloads the neural network structure diagram and neural network parameters in the cloud server through the network when in use.
S102,根据神经网络结构图模拟构建对应的神经网络。S102: Simulate and construct a corresponding neural network according to the neural network structure diagram.
其中,神经网络结构图为步骤S101中获取到神经网络结构图,将获取到的神经网络结构图在仿真软件中进行模拟,从而在软件中构建出对应的神经网络。Among them, the neural network structure diagram is the neural network structure diagram obtained in step S101, and the obtained neural network structure diagram is simulated in the simulation software, so as to construct the corresponding neural network in the software.
S103,获取待仿真数据,并对待仿真数据按量化信息进行量化,得到仿真输入数据。S103: Obtain the data to be simulated, and quantify the simulated data according to the quantization information to obtain simulation input data.
上述的待仿真数据为用户输入的数据,当神经网络为图像处理类型的神经网络时,则用户输入的数据为图像数据。The aforementioned data to be simulated is data input by the user. When the neural network is an image processing type neural network, the data input by the user is image data.
上述的量化可以是通过编译器进行完成。The above-mentioned quantization can be done by a compiler.
具体的,可以通过公式r=s×(q-z)进行计算,其中,r指的是浮点数值,就是用户输入的数据,q指的是量化后的数据,z是偏移值,s是缩放值,s和z是编译器产生的。Specifically, it can be calculated by the formula r=s×(qz), where r refers to the floating point value, which is the data input by the user, q refers to the quantized data, z is the offset value, and s is the zoom The values, s and z are generated by the compiler.
根据公式r=s×(q-z)可得,量化后的数据为q=r/s+z。According to the formula r=s×(q-z), the quantized data is q=r/s+z.
由于s和z是编译器产生的,r是用户输入的待仿真数据,所以通过编译器对输入的待仿真数据进行量化,得到量化后的仿真输入数据。Since s and z are generated by the compiler and r is the data to be simulated input by the user, the input data to be simulated is quantized by the compiler to obtain the quantized simulation input data.
其中,经过量化后,得到的仿真输入数据与神经网络参数为同一数据类型。Among them, after quantization, the obtained simulation input data and neural network parameters are the same data type.
需要说明的是,神经网络参数与待仿真数据不同,神经网络参数为硬件数据类型,而待仿真数据为浮点数据类型。在经过编译器的量化后,待仿真数据变成仿真输入数据,与神经网络参数为同一数据类型。It should be noted that the neural network parameters are different from the data to be simulated. The neural network parameters are of the hardware data type, and the data to be simulated are of the floating point data type. After being quantized by the compiler, the data to be simulated becomes simulation input data, which is the same data type as the neural network parameters.
进一步的,上述获取待仿真数据,并对待仿真数据按所述量化信息进行量化,得到仿真输入数据的步骤包括:Further, the above steps of acquiring the data to be simulated, and quantizing the data to be simulated according to the quantization information to obtain the simulation input data include:
获取待仿真数据,并根据量化信息,将待仿真数据转换为8bit单元长度的 待仿真数据,得到8bit单元长度的仿真输入数据。Obtain the data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits, and obtain simulation input data with a unit length of 8 bits.
其中,神经网络参数也是8bit单元长度的数据,神经网络参数包括权重参数及偏置参数。Among them, the neural network parameters are also 8-bit unit length data, and the neural network parameters include weight parameters and bias parameters.
S104,将神经网络参数与仿真输入数据输入到神经网络进行卷积计算,得到卷积结果。S104: Input the neural network parameters and the simulation input data to the neural network for convolution calculation, and obtain the convolution result.
上述的神经网络包括卷积层,可以对神经网络参数与仿真输入数据进行卷积计算。The aforementioned neural network includes a convolutional layer, which can perform convolution calculations on the neural network parameters and simulation input data.
由于是在软件中模拟的神经网络,所以在神经网络中的卷积计算过程与浮点的计算过程一致,即是将硬件数据类型的数据通过浮点计算过程来实现计算,使得浮点计算的结果更贴近硬件计算结果。Because it is a neural network simulated in software, the convolution calculation process in the neural network is consistent with the floating-point calculation process, that is, the data of the hardware data type is calculated through the floating-point calculation process, so that the floating-point calculation is The result is closer to the hardware calculation result.
S105,基于卷积结果,得到仿真结果进行输出。S105: Based on the convolution result, a simulation result is obtained and output.
上述的卷积结果为步骤S104中计算得到的卷积结果,上述的卷积结果经过激活层处理后,可以作为仿真结果进行输出。The aforementioned convolution result is the convolution result calculated in step S104, and the aforementioned convolution result can be output as a simulation result after being processed by the activation layer.
在一种可能的实施例中,得到卷积结果后,没有激活层,则会将卷积结果输入下一层网络中进行计算,比如进行入池化层对卷积结果进行池化等。In a possible embodiment, after the convolution result is obtained, there is no active layer, and the convolution result is input to the next layer of the network for calculation, for example, the pooling layer is performed to pool the convolution result.
本发明实施例中,获取神经网络结构图与神经网络参数,神经网络结构图包括量化信息;根据神经网络结构图模拟构建对应的神经网络;获取待仿真数据,并对待仿真数据按量化信息进行量化,得到仿真输入数据,仿真输入数据与神经网络参数为同一硬件数据类型;将神经网络参数与仿真输入数据输入到神经网络进行卷积计算,得到卷积结果;基于卷积结果,得到仿真结果进行输出。由于将待仿真数据量化为与神经网络参数相同的硬件数据类型,在使用软件仿真时,使得仿真计算更贴近硬件计算的结果,且硬件数据类型的数据计算量小于浮点类型的计算量,还可以提高神经网络仿真的计算速度。In the embodiment of the present invention, the neural network structure diagram and neural network parameters are obtained, and the neural network structure diagram includes quantitative information; the corresponding neural network is simulated and constructed according to the neural network structure diagram; the data to be simulated is obtained, and the simulated data is quantified according to the quantitative information , To obtain the simulation input data, the simulation input data and the neural network parameters are the same hardware data type; input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain the convolution result; based on the convolution result, the simulation result is obtained. Output. Since the data to be simulated is quantified into the same hardware data type as the neural network parameters, when using software simulation, the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type. The calculation speed of neural network simulation can be improved.
可选的,如图2所示,为根据本申请的另一种运行时硬件模拟仿真方法所提供的一个实施例的流程图。Optionally, as shown in FIG. 2, it is a flowchart of an embodiment provided by another runtime hardware simulation method according to the present application.
S201,获取神经网络结构图与神经网络参数。S201: Obtain a neural network structure diagram and neural network parameters.
S202,根据神经网络结构图模拟构建对应的神经网络。S202: Simulate and construct a corresponding neural network according to the neural network structure diagram.
S203,获取待仿真数据,并根据量化信息,将待仿真数据转换为8bit单元长度的待仿真数据,得到8bit单元长度的仿真输入数据。S203: Obtain data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits to obtain simulation input data with a unit length of 8 bits.
其中,神经网络参数也是8bit单元长度的数据,神经网络参数包括权重参数及偏置参数。Among them, the neural network parameters are also 8-bit unit length data, and the neural network parameters include weight parameters and bias parameters.
S203,对8bit单元长度的神经网络数据与8bit单元长度的仿真输入数据分别减去自身的浮点偏移值,得到int32的整型数据。S203: Subtract the floating point offset value of the neural network data with the length of 8bit unit and the simulation input data with the length of 8bit unit respectively to obtain the integer data of int32.
整型数据为硬件的计算数据,使得软件的仿真计算更贴近硬件的计算逻辑,从而使得软件的仿真计算结果更贴近硬件的计算结果。The integer data is the calculation data of the hardware, which makes the simulation calculation of the software closer to the calculation logic of the hardware, so that the simulation calculation result of the software is closer to the calculation result of the hardware.
S204,将int32的神经网络参数与仿真输入数据输入到神经网络中进行卷积计算,得到int32的卷积结果。S204: Input the neural network parameters of the int32 and the simulation input data into the neural network for convolution calculation, and obtain the convolution result of the int32.
将int32的神经网络参数与仿真输入数据输入到神经网络中的卷积层中进行卷积计算,得到的卷积结果也是int32的的整型数据,贴近硬件计算的结果。Input the neural network parameters of int32 and the simulation input data into the convolutional layer in the neural network for convolution calculation, and the convolution result obtained is also the integer data of int32, which is close to the result of hardware calculation.
S205,将int32的卷积结果加上偏置参数,得到int32的偏置结果。S205: Add the offset parameter to the convolution result of int32 to obtain the offset result of int32.
上述的偏置参数为神经网络参数中的偏置参数,上述的加上偏置参数的过程是在偏置层进行加法计算。The above-mentioned bias parameters are the bias parameters in the neural network parameters, and the above-mentioned process of adding the bias parameters is to perform addition calculation in the bias layer.
具体的,神经网络的计算公式是y=w*x+b。Specifically, the calculation formula of the neural network is y=w*x+b.
其中,y为输出,x为输入,w*x为权重参数与输入值的卷积,b为偏置参数。Among them, y is the output, x is the input, w*x is the convolution of the weight parameter and the input value, and b is the bias parameter.
S206,对偏置结果进行激活。S206: Activate the bias result.
通过激活层的激活函数对偏置结果进行激活,以将偏置结果进行输出。当然,若不对偏置结果进行激活,则偏置结果会输入下一个计算节点进行计算。The bias result is activated by the activation function of the activation layer to output the bias result. Of course, if the bias result is not activated, the bias result will be input to the next calculation node for calculation.
S207,对经过激活层的偏置结果进行反量化,得到仿真结果。S207: Perform inverse quantization on the bias result passing through the active layer to obtain a simulation result.
上述的反量化过程为r=s×(q-z),通过编译器进行反量化操作。The above-mentioned dequantization process is r=s×(q-z), and the dequantization operation is performed by the compiler.
其中,r指的是浮点数值,就是用户输入的数据,q指的是量化后的数据,z是偏移值,s是缩放值,s和z是编译器产生的。Among them, r refers to the floating point value, which is the data input by the user, q refers to the quantized data, z is the offset value, s is the scaling value, and s and z are generated by the compiler.
S208,对仿真结果进行输出。S208: Output the simulation result.
将仿真结果输出给用户,以使用户得知仿真结果,该仿真结果用于提供基准数据用作硬件参照,提供计算模型,用于算法测试。为硬件设计提供指导。The simulation result is output to the user so that the user knows the simulation result. The simulation result is used to provide benchmark data as a hardware reference, and to provide a calculation model for algorithm testing. Provide guidance for hardware design.
本发明实施例中,获取神经网络结构图与神经网络参数,神经网络结构图包括量化信息;根据神经网络结构图模拟构建对应的神经网络;获取待仿真数据,并对待仿真数据按量化信息进行量化,得到仿真输入数据,仿真输入数据与神经网络参数为同一硬件数据类型;将神经网络参数与仿真输入数据输入到神经网络进行卷积计算,得到卷积结果;基于卷积结果,得到仿真结果进行输出。由于将待仿真数据量化为与神经网络参数相同的硬件数据类型,在使用软件仿真时,使得仿真计算更贴近硬件计算的结果,且硬件数据类型的数据计算量小于浮点类型的计算量,还可以提高神经网络仿真的计算速度。整个计算流程更贴近硬件的计算模式,减少浮点计算中的不相关内容,便于硬件用作输出校验。同时,由于计算模式和操作模式和硬件一致,所以可以直接模拟硬件的最终计算结果,可以用于神经网络的算法测试。In the embodiment of the present invention, the neural network structure diagram and neural network parameters are obtained, and the neural network structure diagram includes quantitative information; the corresponding neural network is simulated and constructed according to the neural network structure diagram; the data to be simulated is obtained, and the simulated data is quantified according to the quantitative information , To obtain the simulation input data, the simulation input data and the neural network parameters are the same hardware data type; input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain the convolution result; based on the convolution result, the simulation result is obtained. Output. Since the data to be simulated is quantified into the same hardware data type as the neural network parameters, when using software simulation, the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type. The calculation speed of neural network simulation can be improved. The entire calculation process is closer to the calculation mode of the hardware, reducing irrelevant content in floating-point calculations, and facilitating the hardware to be used for output verification. At the same time, because the calculation mode and operation mode are consistent with the hardware, the final calculation result of the hardware can be directly simulated, which can be used for algorithm testing of neural networks.
可选的,在根据神经网络结构图在软件中构建神经网络后,如图3所示,具体的步骤包括:Optionally, after constructing the neural network in the software according to the neural network structure diagram, as shown in Figure 3, the specific steps include:
S301,用户输入图片数据。S301: The user inputs picture data.
S302,对输入的图片数据进行量化,将Float32的图像数据量化为8bit单元长度的图片数据。S302: quantize the input picture data, and quantize the image data of Float32 into picture data with a unit length of 8 bits.
S303,将量化后的图片数据减去偏移值,变成int32的图片数据,用于输入到卷积层,进入步骤S306。S303: Subtract the offset value from the quantized picture data to become int32 picture data for input to the convolutional layer, and go to step S306.
S304,用户输入神经网络权重参数,神经网络权重参数为8bit单元长度的神经网络权重参数。S304, the user inputs a neural network weight parameter, and the neural network weight parameter is a neural network weight parameter with a unit length of 8 bits.
S305,将神经网络权重参数也减去偏移值,变成int32的神经网络权重参数,用于输入到卷积层,进入步骤S306。In S305, the neural network weight parameter is also subtracted from the offset value to become an int32 neural network weight parameter for input to the convolutional layer, and step S306 is entered.
S306,将处理后的图片数据与处理后的神经网络权重参数进行卷积计算, 得到卷积结果。S306: Perform convolution calculation on the processed image data and the processed neural network weight parameter to obtain a convolution result.
S307,将卷积结果加上偏置参数,得到特征图。S307: Add the offset parameter to the convolution result to obtain a feature map.
S308,判断是否存在激活层或激活函数,若存在,则对特征图进行反量化,输出给用户;若不存在,则进入步骤S309。S308: Determine whether there is an activation layer or an activation function. If it does, dequantize the feature map and output it to the user; if it does not exist, go to step S309.
S309,对特征图继续进行量化,作为下一计算层的输入。S309: Continue to quantize the feature map as an input to the next calculation layer.
本发明实施例中,获取神经网络结构图与神经网络参数,神经网络结构图包括量化信息;根据神经网络结构图模拟构建对应的神经网络;获取待仿真数据,并对待仿真数据按量化信息进行量化,得到仿真输入数据,仿真输入数据与神经网络参数为同一硬件数据类型;将神经网络参数与仿真输入数据输入到神经网络进行卷积计算,得到卷积结果;基于卷积结果,得到仿真结果进行输出。由于将待仿真数据量化为与神经网络参数相同的硬件数据类型,在使用软件仿真时,使得仿真计算更贴近硬件计算的结果,且硬件数据类型的数据计算量小于浮点类型的计算量,还可以提高神经网络仿真的计算速度。整个计算流程更贴近硬件的计算模式,减少浮点计算中的不相关内容,便于硬件用作输出校验。同时,由于计算模式和操作模式和硬件一致,所以可以直接模拟硬件的最终计算结果,可以用于神经网络的算法测试。In the embodiment of the present invention, the neural network structure diagram and neural network parameters are obtained, and the neural network structure diagram includes quantitative information; the corresponding neural network is simulated and constructed according to the neural network structure diagram; the data to be simulated is obtained, and the simulated data is quantified according to the quantitative information , To obtain the simulation input data, the simulation input data and the neural network parameters are the same hardware data type; input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain the convolution result; based on the convolution result, the simulation result is obtained. Output. Since the data to be simulated is quantified into the same hardware data type as the neural network parameters, when using software simulation, the simulation calculation is closer to the result of the hardware calculation, and the data calculation amount of the hardware data type is less than the calculation amount of the floating point type. The calculation speed of neural network simulation can be improved. The entire calculation process is closer to the calculation mode of the hardware, reducing irrelevant content in floating-point calculations, and facilitating the hardware to be used for output verification. At the same time, because the calculation mode and operation mode are consistent with the hardware, the final calculation result of the hardware can be directly simulated, which can be used for algorithm testing of neural networks.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,该计算机程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,前述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等非易失性存储介质,或随机存储记忆体(Random Access Memory,RAM)等。A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing relevant hardware through a computer program. The computer program can be stored in a computer readable storage medium, and the program can be stored in a computer readable storage medium. When executed, it may include the procedures of the above-mentioned method embodiments. Among them, the aforementioned storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.
应该理解的是,虽然附图的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,其可以以其他的顺序执行。而且,附图的流程图中的至少一部分步骤可以包括多个子步骤或者多个阶段,这 些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,其执行顺序也不必然是依次进行,而是可以与其他步骤或者其他步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that although the various steps in the flowchart of the drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless explicitly stated in this article, the execution of these steps is not strictly limited in order, and they can be executed in other orders. Moreover, at least part of the steps in the flowchart of the drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the order of execution is also It is not necessarily performed sequentially, but may be performed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
如图4所示,为本实施例所提供的一种运行时硬件模拟仿真装置的结构示意图,上述装置400包括:As shown in FIG. 4, which is a schematic structural diagram of a runtime hardware simulation device provided by this embodiment, the foregoing device 400 includes:
获取模块401,用于获取神经网络结构图与神经网络参数,所述神经网络结构图包括量化信息;The obtaining module 401 is configured to obtain a neural network structure diagram and neural network parameters, where the neural network structure diagram includes quantitative information;
构建模块402,用于根据所述神经网络结构图模拟构建对应的神经网络;The construction module 402 is used to simulate and construct a corresponding neural network according to the neural network structure diagram;
量化模块403,用于获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据,所述仿真输入数据与所述神经网络参数为同一数据类型;The quantization module 403 is configured to obtain the data to be simulated, and quantify the data to be simulated according to the quantization information to obtain simulation input data, and the simulation input data and the neural network parameters are of the same data type;
计算模块404,用于将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果;The calculation module 404 is configured to input the neural network parameters and the simulation input data into the neural network for convolution calculation, and obtain a convolution result;
输出模块405,用于基于所述卷积结果,得到仿真结果进行输出。The output module 405 is configured to obtain a simulation result for output based on the convolution result.
进一步地,如图4所示,所述量化模块还用于获取待仿真数据,并根据所述量化信息,将所述待仿真数据转换为8bit单元长度的待仿真数据,得到8bit单元长度的仿真输入数据。Further, as shown in FIG. 4, the quantization module is also used to obtain the data to be simulated, and according to the quantization information, convert the data to be simulated into the data to be simulated with a unit length of 8 bits to obtain a simulation with a unit length of 8 bits. Input data.
进一步地,如图4所示,所述待仿真数据为浮点类型数据,所述神经网络参数为8bit单元长度的神经网络参数,所述量化模块403还用于对所述8bit单元长度的神经网络数据与所述8bit单元长度的仿真输入数据分别减去自身的浮点偏移值,得到int32的整型数据;Further, as shown in FIG. 4, the data to be simulated is floating-point type data, the neural network parameter is a neural network parameter with a length of 8bit unit, and the quantization module 403 is also used to calculate the neural network with a length of 8bit unit. The network data and the simulation input data of the 8-bit unit length are respectively subtracted from their own floating-point offset values to obtain integer data of int32;
所述计算模块404还用于将int32的神经网络参数与仿真输入数据输入到神经网络中进行卷积计算,得到int32的卷积结果。The calculation module 404 is also used to input the neural network parameters of the int32 and the simulation input data into the neural network for convolution calculation to obtain the convolution result of the int32.
进一步地,如图5所示,所述神经网络参数包括偏置参数,所述输出模块405包括:Further, as shown in FIG. 5, the neural network parameters include bias parameters, and the output module 405 includes:
偏置单元4051,用于将所述int32的卷积结果加上偏置参数,得到int32的偏置结果;The bias unit 4051 is configured to add a bias parameter to the convolution result of the int32 to obtain the bias result of the int32;
第一输出单元4052,用于基于所述偏置结果,得到仿真结果进行输出。The first output unit 4052 is configured to obtain a simulation result for output based on the bias result.
进一步地,如图6所示,所述输出模块405包括:Further, as shown in FIG. 6, the output module 405 includes:
反量化单元4053,用于根据所述量化信息以及所述偏移值对所述卷积结果进行反量化,得到仿真结果;The dequantization unit 4053 is configured to dequantize the convolution result according to the quantization information and the offset value to obtain a simulation result;
第二输出单元4054,用于对所述仿真结果进行输出。The second output unit 4054 is configured to output the simulation result.
进一步地,如图6所示,所述量化信息包括缩放值,反量化单元4053还用于根据所述缩放值以及所述偏移值对所述卷积结果进行反量化,得到仿真结果。Further, as shown in FIG. 6, the quantization information includes a scaling value, and the inverse quantization unit 4053 is further configured to perform inverse quantization on the convolution result according to the scaling value and the offset value to obtain a simulation result.
本申请实施例提供的一种运行时硬件模拟仿真装置能够实现图1至图3的方法实施例中的各个实施方式,以及相应有益效果,为避免重复,这里不再赘述。The runtime hardware simulation device provided by the embodiment of the present application can realize the various implementation manners in the method embodiments of FIG. 1 to FIG. 3 and the corresponding beneficial effects. In order to avoid repetition, details are not described herein again.
为解决上述技术问题,本申请实施例还提供计算机设备。具体请参阅图7,图7为本实施例计算机设备基本结构框图。In order to solve the above technical problems, the embodiments of the present application also provide computer equipment. Please refer to FIG. 7 for details. FIG. 7 is a block diagram of the basic structure of the computer device in this embodiment.
计算机设备7包括通过系统总线相互通信连接存储器701、处理器702、网络接口703。需要指出的是,图中仅示出了具有组件701-703的计算机设备70,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。其中,本技术领域技术人员可以理解,这里的计算机设备是一种能够按照事先设定或存储的指令,自动进行数值计算和/或信息处理的设备,其硬件包括但不限于微处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程门阵列(Field-Programmable GateArray,FPGA)、数字处理器(Digital Signal Processor,DSP)、嵌入式设备等。The computer device 7 includes a memory 701, a processor 702, and a network interface 703 that are connected to each other in communication through a system bus. It should be pointed out that only the computer device 70 with components 701-703 is shown in the figure, but it should be understood that it is not required to implement all the illustrated components, and more or fewer components may be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculation and/or information processing in accordance with pre-set or stored instructions. Its hardware includes, but is not limited to, a microprocessor, a dedicated Integrated Circuit (Application Specific Integrated Circuit, ASIC), Programmable Gate Array (Field-Programmable GateArray, FPGA), Digital Processor (Digital Signal Processor, DSP), embedded equipment, etc.
计算机设备可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。计算机设备可以与客户通过键盘、鼠标、遥控器、触摸板或声控设备等方式进行人机交互。The computer equipment can be computing equipment such as desktop computers, notebooks, palmtop computers, and cloud servers. Computer equipment can interact with customers through keyboard, mouse, remote control, touchpad or voice control equipment.
存储器701至少包括一种类型的可读存储介质,可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。 在一些实施例中,存储器701可以是计算机设备7的内部存储单元,例如该计算机设备7的硬盘或内存。在另一些实施例中,存储器701也可以是计算机设备7的外部存储设备,例如该计算机设备7上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。当然,存储器701还可以既包括计算机设备7的内部存储单元也包括其外部存储设备。本实施例中,存储器701通常用于存储安装于计算机设备7的操作系统和各类应用软件,例如一种行时硬件模拟仿真方法的程序代码等。此外,存储器701还可以用于暂时地存储已经输出或者将要输出的各类数据。The memory 701 includes at least one type of readable storage medium. The readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory ( SRAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), magnetic memory, magnetic disks, optical disks, etc. In some embodiments, the memory 701 may be an internal storage unit of the computer device 7, such as a hard disk or a memory of the computer device 7. In other embodiments, the memory 701 may also be an external storage device of the computer device 7, such as a plug-in hard disk, a smart media card (SMC), and a secure digital (Secure Digital, SD) card, flash card (Flash Card), etc. Of course, the memory 701 may also include both the internal storage unit of the computer device 7 and its external storage device. In this embodiment, the memory 701 is generally used to store an operating system and various application software installed in the computer device 7, such as a program code of a real-time hardware simulation method. In addition, the memory 701 can also be used to temporarily store various types of data that have been output or will be output.
处理器702在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器702通常用于控制计算机设备7的总体操作。本实施例中,处理器702用于运行存储器701中存储的程序代码或者处理数据,例如运行一种行时硬件模拟仿真方法的程序代码。The processor 702 may be a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 702 is generally used to control the overall operation of the computer device 7. In this embodiment, the processor 702 is configured to run the program code stored in the memory 701 or process data, for example, run the program code of a real-time hardware simulation method.
网络接口703可包括无线网络接口或有线网络接口,该网络接口703通常用于在计算机设备7与其他电子设备之间建立通信连接。The network interface 703 may include a wireless network interface or a wired network interface, and the network interface 703 is generally used to establish a communication connection between the computer device 7 and other electronic devices.
本申请还提供了另一种实施方式,即提供一种计算机可读存储介质,计算机可读存储介质存储有一种行时硬件模拟仿真程序,上述一种行时硬件模拟仿真程序可被至少一个处理器执行,以使至少一个处理器执行如上述的一种行时硬件模拟仿真方法的步骤。This application also provides another implementation manner, that is, a computer-readable storage medium is provided. The computer-readable storage medium stores a runtime hardware simulation simulation program, and the aforementioned runtime hardware simulation simulation program can be processed by at least one The processor executes, so that at least one processor executes the steps of the above-mentioned runtime hardware simulation method.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本申请各个实施例的一种行时硬件模拟仿真方法。Through the description of the above implementation manners, those skilled in the art can clearly understand that the above-mentioned embodiment method can be implemented by means of software plus the necessary general hardware platform, of course, it can also be implemented by hardware, but in many cases the former is better.的实施方式。 Based on this understanding, the technical solution of this application essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM/RAM, magnetic disk, The optical disc) includes a number of instructions to make a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute a runtime hardware simulation method of each embodiment of the present application.
本申请的说明书和权利要求书及上述附图说明中的术语“包括”和“具有”以及它们的任何变形,意图在于覆盖不排他的包含。本申请的说明书和权利要求书或上述附图中的术语“第一”、“第二”等是用于区别不同对象,而不是用于描述特定顺序。在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。The terms "including" and "having" in the specification and claims of this application and the above description of the drawings and any variations thereof are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the application or the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific sequence. Reference to "embodiments" herein means that a specific feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art clearly and implicitly understand that the embodiments described herein can be combined with other embodiments.
以上仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modification, equivalent replacement and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention. Inside.

Claims (10)

  1. 一种运行时硬件模拟仿真方法,其特征在于,包括步骤:A runtime hardware simulation simulation method, which is characterized in that it comprises the steps:
    获取神经网络结构图与神经网络参数,所述神经网络结构图包括量化信息;Acquiring a neural network structure diagram and neural network parameters, where the neural network structure diagram includes quantitative information;
    根据所述神经网络结构图模拟构建对应的神经网络;Simulate and construct a corresponding neural network according to the neural network structure diagram;
    获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据,所述仿真输入数据与所述神经网络参数为同一硬件数据类型;Acquiring data to be simulated, and quantizing the data to be simulated according to the quantization information to obtain simulation input data, where the simulation input data and the neural network parameters are of the same hardware data type;
    将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果;Inputting the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain a convolution result;
    基于所述卷积结果,得到仿真结果进行输出。Based on the convolution result, the simulation result is obtained and output.
  2. 根据权利要求1所述的运行时硬件模拟仿真方法,其特征在于,所述获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据的步骤包括:The runtime hardware simulation simulation method according to claim 1, wherein the step of obtaining the data to be simulated and quantizing the data to be simulated according to the quantization information to obtain the simulation input data comprises:
    获取待仿真数据,并根据所述量化信息,将所述待仿真数据转换为8bit单元长度的待仿真数据,得到8bit单元长度的仿真输入数据。Obtain the data to be simulated, and according to the quantization information, convert the data to be simulated into data to be simulated with a unit length of 8 bits to obtain simulation input data with a unit length of 8 bits.
  3. 根据权利要求2所述的运行时硬件模拟仿真方法,其特征在于,所述待仿真数据为浮点类型数据,所述神经网络参数为8bit单元长度的神经网络参数,所述对所述待仿真数据按所述量化信息进行量化的步骤具体还包括:The runtime hardware simulation simulation method according to claim 2, wherein the data to be simulated is floating-point type data, the neural network parameter is a neural network parameter with a unit length of 8 bit, and the data to be simulated is The step of quantifying the data according to the quantified information specifically further includes:
    对所述8bit单元长度的神经网络数据与所述8bit单元长度的仿真输入数据分别减去自身的浮点偏移值,得到int32的整型数据;Subtracting the floating-point offset value of the neural network data of the 8-bit unit length and the simulation input data of the 8-bit unit length respectively to obtain the integer data of int32;
    所述将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果的步骤具体包括:The step of inputting the neural network parameters and the simulation input data to the neural network for convolution calculation, and obtaining the convolution result specifically includes:
    将int32的神经网络参数与仿真输入数据输入到神经网络中进行卷积计算,得到int32的卷积结果。Input the neural network parameters of int32 and the simulation input data into the neural network for convolution calculation, and get the convolution result of int32.
  4. 根据权利要求3所述的运行时硬件模拟仿真方法,其特征在于,所述神经网络参数包括偏置参数,所述基于所述卷积结果,得到仿真结果进行输出的步骤具体包括:The runtime hardware simulation simulation method according to claim 3, wherein the neural network parameters include bias parameters, and the step of obtaining a simulation result based on the convolution result and outputting it specifically comprises:
    将所述int32的卷积结果加上偏置参数,得到int32的偏置结果;Add the offset parameter to the convolution result of the int32 to obtain the offset result of the int32;
    基于所述偏置结果,得到仿真结果进行输出。Based on the offset result, the simulation result is obtained and output.
  5. 根据权利要求1所述的运行时硬件模拟仿真方法,其特征在于,所述基于所述卷积结果,得到仿真结果进行输出的步骤包括:The runtime hardware simulation simulation method according to claim 1, wherein the step of obtaining a simulation result based on the convolution result and outputting it comprises:
    根据所述量化信息以及所述偏移值对所述卷积结果进行反量化,得到仿真结果;Performing inverse quantization on the convolution result according to the quantization information and the offset value to obtain a simulation result;
    对所述仿真结果进行输出。Output the simulation result.
  6. 根据权利要求5所述的运行时硬件模拟仿真方法,其特征在于,所述量化信息包括缩放值,所述根据所述量化信息以及所述偏移值对所述卷积结果进行反量化,得到仿真结果的步骤包括:The runtime hardware simulation simulation method according to claim 5, wherein the quantization information includes a scaling value, and the convolution result is dequantized according to the quantization information and the offset value to obtain The steps of the simulation results include:
    根据所述缩放值以及所述偏移值对所述卷积结果进行反量化,得到仿真结果。Perform inverse quantization on the convolution result according to the scaling value and the offset value to obtain a simulation result.
  7. 一种运行时硬件模拟仿真装置,其特征在于,所述装置包括:A run-time hardware simulation simulation device, characterized in that the device includes:
    获取模块,用于获取神经网络结构图与神经网络参数,所述神经网络结构图包括量化信息;An obtaining module, used to obtain a neural network structure diagram and neural network parameters, the neural network structure diagram including quantitative information;
    构建模块,用于根据所述神经网络结构图模拟构建对应的神经网络;The construction module is used to simulate and construct a corresponding neural network according to the neural network structure diagram;
    量化模块,用于获取待仿真数据,并对所述待仿真数据按所述量化信息进行量化,得到仿真输入数据,所述仿真输入数据与所述神经网络参数为同一数据类型;The quantization module is used to obtain the data to be simulated, and quantify the data to be simulated according to the quantization information to obtain simulation input data, and the simulation input data and the neural network parameters are of the same data type;
    计算模块,用于将所述神经网络参数与所述仿真输入数据输入到所述神经网络进行卷积计算,得到卷积结果;A calculation module, configured to input the neural network parameters and the simulation input data to the neural network for convolution calculation to obtain a convolution result;
    输出模块,用于基于所述卷积结果,得到仿真结果进行输出。The output module is used to obtain a simulation result for output based on the convolution result.
  8. 根据权利要求7所述的运行时硬件模拟仿真装置,其特征在于,所述量化模块还用于获取待仿真数据,并根据所述量化信息,将所述待仿真数据转换为8bit单元长度的待仿真数据,得到8bit单元长度的仿真输入数据。The runtime hardware simulation simulation device according to claim 7, wherein the quantization module is also used to obtain the data to be simulated, and according to the quantization information, convert the data to be simulated into the data to be simulated with an 8-bit unit length. Simulation data, the simulation input data of 8bit unit length is obtained.
  9. 一种计算机设备,包括存储器和处理器,所述存储器中存储有计算机程 序,所述处理器执行所述计算机程序时实现如权利要求1至6中任一项所述的运行时硬件模拟仿真方法的步骤。A computer device, comprising a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the runtime hardware simulation method according to any one of claims 1 to 6 is implemented A step of.
  10. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至6中任一项所述的运行时硬件模拟仿真方法的步骤。A computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the runtime according to any one of claims 1 to 6 is realized. The steps of the hardware simulation method.
PCT/CN2019/110840 2019-10-12 2019-10-12 Method and apparatus for hardware simulation and emulation during running, and device and storage medium WO2021068249A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2019/110840 WO2021068249A1 (en) 2019-10-12 2019-10-12 Method and apparatus for hardware simulation and emulation during running, and device and storage medium
CN201980067042.8A CN113228056B (en) 2019-10-12 2019-10-12 Runtime hardware simulation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/110840 WO2021068249A1 (en) 2019-10-12 2019-10-12 Method and apparatus for hardware simulation and emulation during running, and device and storage medium

Publications (1)

Publication Number Publication Date
WO2021068249A1 true WO2021068249A1 (en) 2021-04-15

Family

ID=75437629

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/110840 WO2021068249A1 (en) 2019-10-12 2019-10-12 Method and apparatus for hardware simulation and emulation during running, and device and storage medium

Country Status (2)

Country Link
CN (1) CN113228056B (en)
WO (1) WO2021068249A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114707650B (en) * 2021-12-31 2024-06-14 浙江芯劢微电子股份有限公司 Simulation implementation method for improving simulation efficiency
CN115656747A (en) * 2022-12-26 2023-01-31 南方电网数字电网研究院有限公司 Transformer defect diagnosis method and device based on heterogeneous data and computer equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109002881A (en) * 2018-06-28 2018-12-14 郑州云海信息技术有限公司 The fixed point calculation method and device of deep neural network based on FPGA
CN109284761A (en) * 2018-09-04 2019-01-29 苏州科达科技股份有限公司 A kind of image characteristic extracting method, device, equipment and readable storage medium storing program for executing
EP3438890A1 (en) * 2017-08-04 2019-02-06 Samsung Electronics Co., Ltd. Method and apparatus for generating fixed-point quantized neural network
CN109753903A (en) * 2019-02-27 2019-05-14 北航(四川)西部国际创新港科技有限公司 A kind of unmanned plane detection method based on deep learning
CN110245741A (en) * 2018-03-09 2019-09-17 佳能株式会社 Optimization and methods for using them, device and the storage medium of multilayer neural network model

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3438890A1 (en) * 2017-08-04 2019-02-06 Samsung Electronics Co., Ltd. Method and apparatus for generating fixed-point quantized neural network
CN110245741A (en) * 2018-03-09 2019-09-17 佳能株式会社 Optimization and methods for using them, device and the storage medium of multilayer neural network model
CN109002881A (en) * 2018-06-28 2018-12-14 郑州云海信息技术有限公司 The fixed point calculation method and device of deep neural network based on FPGA
CN109284761A (en) * 2018-09-04 2019-01-29 苏州科达科技股份有限公司 A kind of image characteristic extracting method, device, equipment and readable storage medium storing program for executing
CN109753903A (en) * 2019-02-27 2019-05-14 北航(四川)西部国际创新港科技有限公司 A kind of unmanned plane detection method based on deep learning

Also Published As

Publication number Publication date
CN113228056A (en) 2021-08-06
CN113228056B (en) 2023-12-22

Similar Documents

Publication Publication Date Title
CN111523640B (en) Training method and device for neural network model
CN102099798B (en) For the method and system using native code module to perform application
CN108280757B (en) User credit evaluation method and device
CN110023963A (en) Use Processing with Neural Network text sequence
CN114048331A (en) Knowledge graph recommendation method and system based on improved KGAT model
CN111145076B (en) Data parallelization processing method, system, equipment and storage medium
CN112418292B (en) Image quality evaluation method, device, computer equipment and storage medium
WO2024001806A1 (en) Data valuation method based on federated learning and related device therefor
CN112488183A (en) Model optimization method and device, computer equipment and storage medium
WO2020030052A1 (en) Animal count identification method, device, medium, and electronic apparatus
WO2021068249A1 (en) Method and apparatus for hardware simulation and emulation during running, and device and storage medium
CN107437111A (en) Data processing method, medium, device and computing device based on neutral net
WO2022126902A1 (en) Model compression method and apparatus, electronic device, and medium
CN114970357A (en) Energy-saving effect evaluation method, system, device and storage medium
CN111652282B (en) Big data-based user preference analysis method and device and electronic equipment
CN111090740B (en) Knowledge graph generation method for dialogue system
CN116431807B (en) Text classification method and device, storage medium and electronic device
CN116168403A (en) Medical data classification model training method, classification method, device and related medium
WO2021068253A1 (en) Customized data stream hardware simulation method and apparatus, device, and storage medium
CN116306879A (en) Data processing method, device, electronic equipment and storage medium
CN113469237B (en) User intention recognition method, device, electronic equipment and storage medium
CN114897161A (en) Mask-based graph classification backdoor attack defense method and system, electronic equipment and storage medium
CN113762061A (en) Quantitative perception training method and device for neural network and electronic equipment
WO2020054402A1 (en) Neural network processing device, computer program, neural network manufacturing method, neural network data manufacturing method, neural network use device, and neural network downscaling method
WO2024045175A1 (en) Optimization of executable graph for artificial intelligence model inference

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: 19948842

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 21.09.2022)

122 Ep: pct application non-entry in european phase

Ref document number: 19948842

Country of ref document: EP

Kind code of ref document: A1