Hardware device and method for realizing neural network activation function

By using the preconfiguration of the input cache module and the data configuration module and the efficient index of the data mapping module in the hardware device of the neural network activation function, the flexibility, complexity and resource consumption problems in the implementation of the activation function in the prior art are solved. It realizes fast and efficient activation function calculation and diversified support.

CN119089957APending Publication Date: 2024-12-06NANJING UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411310737.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-20
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

When implementing neural network activation functions, the prior art is difficult to take into account high flexibility, low hardware design complexity and low hardware resource consumption, and at the same time supports a diverse type of activation function, resulting in limited computing efficiency and real-time performance.

Method used

Design a hardware device, including an input cache module, a data configuration module and a data mapping module, through the pre-configuration of the data configuration module and the efficient indexing operation of the data mapping module, the rapid mapping and output of the activation function is achieved, avoiding complex calculations and duplications. Computation, supports multiple activation function types.

Benefits of technology

It realizes fast and efficient processing when data activation at the neural network layer is activated, reduces computing resources and power consumption, improves processing efficiency and real-time performance, and is suitable for application requirements of multiple activation functions and different data bit widths.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119089957A_ABST
    Figure CN119089957A_ABST
Patent Text Reader

Abstract

The invention discloses a hardware device and method for realizing a neural network activation function. The device comprises an input cache module, a data configuration module and a data mapping module, the input cache module is connected with the data mapping module, and the data configuration module is connected with the data mapping module; the input cache module is used for receiving the input data of the neural network layer, performing grouping storage on the input data, and converting an effective signal of the input data into a mapping enable signal; the data configuration module is used for storing a series of mapping values of the activation function; and the data mapping module is used for performing data mapping and outputting the mapped data to the next layer of the neural network. According to the method, diversified neural network activation functions can be supported, and compared with a traditional scheme, higher flexibility can be achieved, and meanwhile computing resources and power consumption are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention proposes a hardware device and method for realizing a neural network activation function, belonging to the field of digital integrated circuits. Background Art

[0002] The performance of neural networks depends largely on the choice and implementation efficiency of activation functions, which affects the training speed of the model, the overall computational overhead, and the performance of image classification, object detection, speech recognition, etc. when applied.

[0003] There are two main activation function implementation schemes. The first is the traditional software implementation scheme. The implementation of the activation function mainly depends on the software level, usually executed on the central processing unit (CPU) or graphics processing unit (GPU) through various advanced computing libraries. This scheme has high flexibility and good versatility, and can quickly adapt to changes in various neural network architectures and application requirements. The disadvantage is that the computing efficiency is low and the scalability is limited. If the neural network is large in scale, the processing speed will be slow, the response time will be extremely long, and a large amount of computing resources will be consumed.

[0004] The second solution is to use a hardware accelerator to achieve fast calculation of the activation function, and to implement the calculation formula of the activation function through a hardware circuit. Specifically, this solution includes designing dedicated hardware circuits, such as operational amplifiers, multipliers, adders, etc. These circuits are configured to perform specific mathematical operations to process input signals and output predetermined results. This solution has high-speed processing capabilities and excellent real-time performance, and can achieve efficient use of computing resources. It is particularly suitable for applications that are sensitive to delays. The disadvantage is that the circuit design is complex, the hardware resource consumption is large, and it may not be able to flexibly support multiple activation function types when processing complex application scenarios, which limits its scope of application. Summary of the invention

[0005] In order to ensure that a variety of activation functions can be supported and high flexibility can be maintained while reducing the complexity of hardware design and reducing hardware resource consumption, the present invention proposes a hardware device and method for implementing a neural network activation function.

[0006] The technical solution adopted by the device of the present invention is as follows:

[0007] A hardware device for implementing a neural network activation function, the device comprising an input buffer module, a data configuration module and a data mapping module, the input buffer module and the data mapping module are connected, and the data configuration module is connected to the data mapping module;

[0008] The input cache module is used to receive input data of the neural network layer, group and store the input data, and convert the input data valid signal into a mapping enable signal; the data configuration module is used to store a series of mapping values ​​of the activation function; the data mapping module is used to perform data mapping and output the mapped data to the next layer of the neural network.

[0009] Furthermore, the input cache module includes two digital input signals and digital output signals, wherein the two digital input signals are input data datain and input data valid signal datain_vld, respectively, and the digital output signal includes a two-dimensional array data_temp storing multiple groups of input data and an enable signal datain_vld_d1 for data mapping operation.

[0010] Furthermore, the input processing module specifically includes GROUP_NUM data registers and an enable signal register, which are respectively used to receive input data datain and input data valid signal datain_vld, the input data datain is a combination of data of the GROUP_NUM group that needs to be activated, wherein GROUP_NUM is the number of groups of input data in one clock cycle, and the GROUP_NUM data registers implement grouped storage of the input data in sequence; the enable signal register is used to delay the input data valid signal datain_vld by one clock cycle to obtain the enable signal datain_vld_d1 as a trigger signal for the data mapping operation.

[0011] Furthermore, the data configuration module includes a memory unit for storing the mapping value of the activation function, the effective depth of the memory unit is the second power of the bit width DATA_WIDTH of each group of data in the input data, representing the output function value mapped to different input values ​​under the bit width DATA_WIDTH, and the memory unit width is the bit width DATA_WIDTH.

[0012] Furthermore, the activation function includes a Sigmoid function, a Tanh function, a ReLU function, a Leaky Relu function or other activation functions.

[0013] Furthermore, the data configuration module includes 4 digital input signals and 2 digital output signals, wherein the 4 digital input signals are respectively a write enable signal wr_en, a read enable signal rd_en, a read / write address signal addr and a write data signal wr_data of the memory unit, and the 2 digital output signals are respectively a read data rd_data and a read data valid signal rd_data_vld.

[0014] Furthermore, the data mapping module includes two digital input signals and digital output signals, wherein the two digital input signals are respectively a two-dimensional array data_temp of input data stored in the input cache module and a data mapping enable signal data_vld_d1, and the digital output signal includes multiple groups of one-dimensional arrays data_out composed of activation function values ​​corresponding to the input data and an output data valid signal dataout_vld.

[0015] Furthermore, the data mapping module includes an output data register and an output data validity register, wherein the output data register is used to store the one-dimensional array data_out after the data mapping is completed, and the output data validity register is used to delay the data mapping enable signal datain_vld_d1 by one clock cycle to achieve synchronization between the output mapping data and the output data validity signal dataout_vld.

[0016] The present invention also provides a method for a hardware device for implementing a neural network activation function, the method comprising the following steps:

[0017] S1, according to the data activation requirements, select the data activation function and the corresponding number of bits for each group of data;

[0018] S2, the working modes of the data configuration module include reset mode, write mode and read mode. The data configuration module first selects to enter the reset mode to ensure that the memory unit inside the data configuration module is initialized to the default value; after the reset is completed, according to the activation function input variable and the corresponding activation function value, the data configuration module selects to enter the write mode, and uses the activation function input variable as the write address and the corresponding activation function value as the write data to realize the configuration of the data configuration module; after the configuration is completed, the data configuration module enters the read mode to confirm that the data configuration module is correctly configured;

[0019] S3, according to the input data validity signal datain_vld, the input cache module groups and stores the neural network layer input data datain as the address information data_temp[k] of the data mapping, where k=0, 1, 2, 3...GROUP_NUM-1, and GROUP_NUM is the number of groups of input data in one clock cycle;

[0020] S4, according to the data mapping enable signal datain_vld_d1 and the data mapping address information data_temp[k], the data mapping module indexes the corresponding mapping function value from the data configuration module configured in step S2, and finally in each clock cycle, according to the output data valid signal dataout_vld output by the data mapping module, realizes the activation output of the GROUP_NUM group data.

[0021] Furthermore, when the data configuration module enters the reset mode, all the data in the data configuration module are initialized to zero; when entering the write mode, the write function value and the write address of the data configuration module are determined according to the three write operation related signals, namely the write enable signal wr_en, the write address signal addr and the write data signal wr_data, corresponding to the function value of the activation function and the input variable of the activation function; when entering the read mode, the data stored at the specified address in the data configuration module is determined to be read correctly and effectively according to the four read operation related signals, namely the read enable signal rd_en, the read address signal addr, the read data signal rd_data and the read data valid signal rd_data_vld.

[0022] The advantages of the present invention compared to the prior art are:

[0023] (1) The hardware device of the present invention can perform data mapping on the input data according to the input data and output data requirements without recalculating the function value each time, thereby avoiding the complex calculations that may exist in the traditional hardware circuit calculation method, thereby reducing the complexity of hardware design.

[0024] (2) The present invention pre-configures the activation function value through the data configuration module, and performs efficient data mapping operations through the data mapping module. This method reduces repeated calculations of data and only requires simple indexing operations, saving computing resources and power consumption.

[0025] (3) The data configuration module can realize the mapping relationship of all types of activation functions of the neural network, support a variety of activation functions, and achieve high flexibility. Therefore, when performing data activation of the neural network layer, the present invention can quickly and effectively implement the activation function based on the input data under the condition of data pre-configuration. Compared with traditional software and hardware implementation solutions, the present invention can support a variety of activation functions, while reducing computing resources and power consumption, and improving processing efficiency and real-time performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 is a block diagram of a hardware device in Embodiment 1 of the present invention;

[0027] Figure 2 is a data flow diagram of an activation device in Embodiment 2 of the present invention;

[0028] Figure 3 is a data activation timing diagram of the activation device in Embodiment 2 of the present invention;

[0029] Figure 4 is a timing diagram of a write command of a data configuration module in Embodiment 2 of the present invention;

[0030] Figure 5 This is a read command timing diagram of the data configuration module in Example 2 of the present invention. DETAILED DESCRIPTION

[0031] Example 1

[0032] This embodiment provides a hardware device for implementing a neural network activation function, and its circuit block diagram is as follows: Figure 1 As shown, it includes an input cache module, a data configuration module and a data mapping module, the input cache module is connected to the data mapping module, and the data configuration module is connected to the data mapping module. Among them, the input cache module is used to receive the input data of the neural network layer, group and store the input data, and convert the input data valid signal into a mapping enable signal; the data configuration module is used to store a series of mapping values ​​of the activation function, allowing the internal storage unit to be dynamically updated in the write mode to adapt to different neural network architectures and requirements; the data mapping module is used to perform data mapping operations and output the mapped data to the next network layer.

[0033] In this embodiment, the input cache module includes two digital input signals and a digital output signal, wherein the two digital input signals are input data datain and input data valid signal datain_vld, respectively, and the digital output signal includes a two-dimensional array data_temp of multiple sets of stored input data and an enable signal datain_vld_d1 for data mapping operation. The input cache module specifically includes GROUP_NUM data registers and an enable signal register, which are respectively used to receive input data datain and input data valid signal datain_vld. The input data datain is a combination of data of the GROUP_NUM group that needs to be activated, wherein GROUP_NUM is the number of groups of input data in one clock cycle, the bit width of each group of data is DATA_WIDTH, and the bit width of the input data datain is determined by the product value of GROUP_NUM and DATA_WIDTH; the number of data bits of each data register is determined by the bit width DATA_WIDTH of each group of data, and the GROUP_NUM data registers realize the grouped storage of the input data in turn; the enable signal register is used to delay the input data valid signal datain_vld by one clock cycle to obtain the enable signal datain_vld_d1 as the trigger signal for the data mapping operation.

[0034] The data configuration module specifically includes a memory unit to realize the pre-storage of the mapping value of the activation function, wherein the effective depth of the memory unit is determined by the power of the bit width DATA_WIDTH of each group of data in the input data, representing the output function value mapped by different input values ​​under the bit width DATA_WIDTH, and the width of the memory unit is determined by the bit width DATA_WIDTH of a group of data. Among them, the activation function can be selected as Sigmoid function, Tanh function, ReLU function, Leaky Relu function or other activation functions, and the memory unit pre-stores the mapping value corresponding to the selected activation function.

[0035] The data configuration module includes 4 digital input signals and 2 digital output signals. The 4 digital input signals are a write enable signal wr_en, a read enable signal rd_en, a read / write address signal addr and a write data signal wr_data for the memory cell, and the 2 digital output signals are a read data signal rd_data and a read data valid signal rd_data_vld.

[0036] The working modes of the data configuration module include reset mode, write mode and read mode, which realize the correct initialization and update of the data in the memory unit. When entering the reset mode, all the data in the memory unit are initialized to zero; when entering the write mode, the write function value and write address of the memory unit are determined according to the three write operation related signals of the write enable signal wr_en, the write address signal addr and the write data signal wr_data, which correspond to the function value of the activation function and the input variable of the activation function; when entering the read mode, according to the four read operation related signals of the read enable signal rd_en, the read address signal addr, the read data signal rd_data and the read data valid signal rd_data_vld, it is determined that the reading of the data stored at the specified address in the memory unit is correct and valid.

[0037] The data mapping module includes two digital input signals and a digital output signal, wherein the two digital input signals are respectively a two-dimensional array data_temp of stored input data and a data mapping enable signal datain_vld_d1, and the digital output signal includes multiple groups of one-dimensional arrays data_out composed of activation function values ​​corresponding to the input data and an output data valid signal dataout_vld. The data mapping module specifically includes an output data register and an output data validity register, wherein the output data register is used to store the one-dimensional array data_out after data mapping is completed, and its data bit width is determined by the product value of the number of input data groups GROUP_NUM and the bit width DATA_WIDTH of each group of input data, and the data value is composed of the data of the GROUP_NUM group of input data corresponding to the memory unit address in the data configuration module, and the output data validity register delays the data mapping enable signal datain_vld_d1 by one clock cycle to achieve synchronization of the output mapping data and the output data valid signal dataout_vld. When the data mapping enable signal datain_vld_d1 is valid, the data mapping module uses data_temp[k] (k=0, 1, 2, 3...GROUP_NUM-1) as the index address of the memory unit of the data configuration module to perform a data indexing operation; obtains the stored GROUP_NUM data from the GROUP_NUM memory unit addresses, and sequentially combines the GROUP_NUM data from the low bit according to the address position k in data_temp, and further obtains multiple groups of one-dimensional arrays data_out composed of activation function values ​​corresponding to the input data, thereby realizing the mapping function of the data mapping module.

[0038] This embodiment also provides a method for implementing the above hardware device, which includes the following steps:

[0039] S1, according to the data activation requirements, select the data activation function and the corresponding number of bits for each group of data;

[0040] S2, the data configuration module first selects to enter the reset mode to ensure that the memory unit inside the data configuration module is initialized to the default value; after the reset is completed, according to the activation function input variable and the corresponding activation function value, the data configuration module selects to enter the write mode, and uses the activation function input variable as the write address and the corresponding activation function value as the write data to realize the configuration of the memory unit in the data configuration module; after the configuration is completed, the data configuration module enters the read mode to confirm that the memory unit is correctly configured;

[0041] S3, according to the input data valid signal datain_vld, the input cache module groups and stores the neural network layer input data datain as the address information data_temp[k] (k=0, 1, 2, 3...GROUP_NUM-1) of the data mapping;

[0042] S4, according to the data mapping enable signal datain_vld_d1 and the data mapping address information data_temp[k], the data mapping module indexes the corresponding mapping function value from the memory cell configured in step S2, and finally in each clock cycle, according to the output data valid signal dataout_vld output by the data mapping module, realizes the activation output of the GROUP_NUM group data.

[0043] Example 2

[0044] The hardware device of Example 1 is designed as an efficient data activation device that can activate a large amount of ADC data in real time. First, the input cache module is designed with the input signal requirements and output requirements of the device as the design starting point, and the valid input data of the neural network layer is temporarily stored in the data register of the input cache module. The delayed data valid signal datain_vld_d1 is used as the data mapping enable signal of the data mapping module. This embodiment gives examples of relevant parameters and indicators as follows: the input data is 512 bits, the minimum unit of each group of ADC data is 8 bits, and there are 64 groups in total. It is necessary to output the activated data stream at a clock frequency of 100hz and 512 bits per beat. The data mapping function is to realize the ReLU activation of ADC data, convert all negative ADC data to 0, and convert all positive ADC data to linear input. The output data requirement is 64 groups of activated 8-bit data, a total of 512 bits.

[0045] The specific block diagram of the data activation device provided in this embodiment is as follows Figure 2 As shown, Figure 2 Among them, wr_en, wr_data, rd_en, and addr are off-chip configuration parameters; adc_vld is the external trigger signal; datain is the external input data signal; data_temp is the two-dimensional array for temporarily storing input data; adc_vld_d1 is the delay register; Memory is the memory unit in the data configuration module to be configured; dataout is the output data signal after the data activation device is activated for the input data.

[0046] First, according to the functional requirements of data activation, the data configuration step of the memory unit is performed. This step requires the memory unit (Memory), that is, receiving three write operation signals wr_en, wdata and addr. When the write enable wr_en is pulled high, the mapping data corresponding to the input data is written to the same address as the input data. For example, in this embodiment, the data mapping function is to realize the ReLU activation of ADC data, such as Figure 5 As shown, the data to be written to address 0000 is 00, the data to be written to address 0001 is 01, and the data to be written to address 0002 is 02. When the highest bit in the 8-bit data is 1, that is, the address is greater than 0080, the data written is all 00.

[0047] When the data in the memory unit of the data configuration module is ready, the input cache module receives the input data signal datain and the input valid signal adc_vld from the neural network layer and temporarily caches them. When the input signal is valid, that is, the adc_vld signal is pulled high, each group of cached input data is used as the index memory unit address, and the corresponding mapping function value is retrieved from the pre-configured memory unit, and the corresponding n groups of activation function values ​​are simultaneously used as the valid output dataout, thereby forming a pipelined data activation process.

[0048] The data activation device in this embodiment can efficiently cope with the real-time processing requirements of large-scale data, and is particularly suitable for application scenarios that require rapid processing of large amounts of data and real-time response, such as autonomous driving systems, high-speed signal processing, real-time video analysis, and deep learning accelerators.

[0049] Compared with the prior art, the present invention significantly reduces the time required for data processing through parallel activation processing of multiple groups of data and the pipeline process of data activation, achieves a significant increase in data processing speed, and effectively reduces processing delay. At the same time, the data configuration module of the present invention supports the configuration of multiple activation functions and different data bit widths. For any one-to-one or many-to-one mapping relationship, it can output an output value that conforms to the corresponding mapping relationship, so that it can flexibly adapt to different neural network models and a wide range of application requirements. In addition, the direct mapping of multiple activation functions is realized through hardware, which avoids complex mathematical calculations, thereby reducing the consumption of computing resources and improving processing speed and efficiency.

Claims

1. A hardware device for implementing a neural network activation function, It is characterized in that The device comprises an input buffer module, a data configuration module and a data mapping module, wherein the input buffer module is connected to the data mapping module, and the data configuration module is connected to the data mapping module; The input buffer module is used to receive input data of the neural network layer, group and store the input data, and convert the input data valid signal into a mapping enable signal; The data configuration module is used to store a series of mapping values ​​of the activation function; The data mapping module is used to perform data mapping and output the mapped data to the next layer of the neural network.

2. A hardware device for implementing a neural network activation function according to claim 1, It is characterized in that The input buffer module includes two digital input signals and a digital output signal, wherein the two digital input signals are input data datain and input data valid signal datain_vld, respectively, and the digital output signal includes a two-dimensional array data_temp of storing multiple groups of input data and an enable signal datain_vld_d1 for data mapping operation.

3. A hardware device for implementing a neural network activation function according to claim 2, It is characterized in that The input processing module specifically includes GROUP_NUM data registers and an enable signal register, which are respectively used to receive input data datain and input data valid signal datain_vld, where the input data datain is a combination of data of the GROUP_NUM group that needs to be activated, wherein GROUP_NUM is the number of groups of input data in one clock cycle, and the GROUP_NUM data registers sequentially implement grouped storage of the input data; the enable signal register is used to delay the input data valid signal datain_vld by one clock cycle to obtain the enable signal datain_vld_d1 as a trigger signal for the data mapping operation.

4. A hardware device for implementing a neural network activation function according to claim 1, It is characterized in that The data configuration module includes a memory unit for storing the mapping value of the activation function. The effective depth of the memory unit is the second power of the bit width DATA_WIDTH of each group of data in the input data, representing the output function value mapped to different input values ​​under the bit width DATA_WIDTH, and the memory unit width is the bit width DATA_WIDTH.

5. A hardware device for implementing a neural network activation function according to claim 4, It is characterized in that The activation function includes a Sigmoid function, a Tanh function, a ReLU function, a Leaky Relu function or other activation functions.

6. A hardware device for implementing a neural network activation function according to claim 4, It is characterized in that The data configuration module includes 4 digital input signals and 2 digital output signals, wherein the 4 digital input signals are respectively a write enable signal wr_en, a read enable signal rd_en, a read / write address signal addr and a write data signal wr_data of the memory unit, and the 2 digital output signals are respectively a read data rd_data and a read data valid signal rd_data_vld.

7. A hardware device for implementing a neural network activation function according to claim 1, It is characterized in that The data mapping module includes two digital input signals and a digital output signal, wherein the two digital input signals are respectively a two-dimensional array data_temp of input data stored in the input cache module and a data mapping enable signal data_vld_d1, and the digital output signal includes multiple groups of one-dimensional arrays data_out composed of activation function values ​​corresponding to the input data and an output data valid signal dataout_vld.

8. A hardware device for implementing a neural network activation function according to claim 7, It is characterized in that The data mapping module includes an output data register and an output data validity register, wherein the output data register is used to store the one-dimensional array data_out after data mapping is completed, and the output data validity register is used to delay the data mapping enable signal datain_vld_d1 by one clock cycle to achieve synchronization between the output mapping data and the output data valid signal dataout_vld.

9. A method of using a hardware device for implementing a neural network activation function as claimed in claim 1, It is characterized in that The method comprises the following steps: S1, according to the data activation requirements, select the data activation function and the corresponding number of bits for each group of data; S2, the working modes of the data configuration module include reset mode, write mode and read mode. The data configuration module first selects to enter the reset mode to ensure that the memory unit inside the data configuration module is initialized to the default value; after the reset is completed, according to the activation function input variable and the corresponding activation function value, the data configuration module selects to enter the write mode, and uses the activation function input variable as the write address and the corresponding activation function value as the write data to realize the configuration of the data configuration module; after the configuration is completed, the data configuration module enters the read mode to confirm that the data configuration module is correctly configured; S3, according to the input data validity signal datain_vld, the input cache module groups and stores the neural network layer input data datain as the address information data_temp[k] of the data mapping, where k=0, 1, 2, 3...GROUP_NUM-1, and GROUP_NUM is the number of groups of input data in one clock cycle; S4, according to the data mapping enable signal datain_vld_d1 and the data mapping address information data_temp[k], the data mapping module indexes the corresponding mapping function value from the data configuration module configured in step S2, and finally in each clock cycle, according to the output data valid signal dataout_vld output by the data mapping module, realizes the activation output of the GROUP_NUM group data.

10. The method according to claim 9, It is characterized in that When the data configuration module enters the reset mode, all the data in the data configuration module are initialized to zero; when entering the write mode, the write function value and the write address of the data configuration module are determined according to the three write operation related signals, namely the write enable signal wr_en, the write address signal addr and the write data signal wr_data, corresponding to the function value of the activation function and the input variable of the activation function; when entering the read mode, the data stored at the specified address in the data configuration module is determined to be read correctly and effectively according to the four read operation related signals, namely the read enable signal rd_en, the read address signal addr, the read data signal rd_data and the read data valid signal rd_data_vld.