A general-purpose processor that supports accelerated vector operations
By introducing a vector operation module into a general-purpose processor, the configuration of data bit width and vector dimension can be achieved, enabling parallel operation. This solves the problem of non-dedicated processors being unable to efficiently process matrix operations, improving computational efficiency and reducing costs.
Patent Information
- Application Number
- CN202310219286.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-07
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2043-03-07
AI Technical Summary
In the existing technology, non-dedicated neural network processors have difficulty efficiently processing a large number of matrix operations, and dedicated neural network accelerators are expensive and have poor scalability.
A vector operation module is introduced into a general-purpose processor. By configuring the data bit width and vector dimension, parallel operation of the vector operation module is achieved, including parallel operation of the data reading control unit, the vector calculation control unit, the multiplier, and the adder.
It improves the computational efficiency of vector operations, is applicable to neural network algorithms in different scenarios, accelerates tasks, and reduces costs.
Smart Images

Figure CN116225532B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of general-purpose processors, specifically to hardware acceleration of vector operations by general-purpose processors, and more specifically, to a general-purpose processor that supports accelerated vector operations. Background Technology
[0002] With the widespread adoption of neural network models in the field of artificial intelligence, various prediction tasks have seen significant improvements compared to traditional prediction methods. However, in areas such as image processing that require extensive matrix operations, neural network algorithms can impose excessive computational load on terminal processors.
[0003] As the complexity of neural network algorithms and tasks increases, non-dedicated neural network processors struggle to handle such a large number of matrix operations, resulting in low computational efficiency. Existing technologies include solutions that directly offload neural network tasks to dedicated neural network accelerators defined for those tasks. However, these dedicated accelerators require customization, leading to high costs, and are difficult to use for different neural network tasks, exhibiting limited scalability. Summary of the Invention
[0004] Therefore, the purpose of this invention is to overcome the shortcomings of the prior art and provide a general-purpose processor that supports accelerated vector operations.
[0005] The objective of this invention is achieved through the following technical solution:
[0006] According to a first aspect of the present invention, a general-purpose processor supporting accelerated vector operations is provided. The general-purpose processor includes a CPU and further includes one or more vector operation modules. Each vector operation module is configured to: obtain instruction information for a vector operation to be processed from the CPU, the instruction information including a data bit width and a vector dimension; and adjust the reading and calculation method of data in the vector operation to be processed by the vector operation module according to the data bit width and vector dimension in the instruction information, so as to complete the vector operation using the vector operation module while supporting configurable data bit width and vector dimension.
[0007] In some embodiments of the present invention, each vector operation module includes a data reading control unit, a vector calculation control unit, multiple multipliers, and at least one adder. The vector operation to be processed is a dot product of a first vector and a second vector. The data reading control unit includes multiple storage registers of a predetermined size for retrieving data of at least a portion of the dimensions of the first and second vectors from the CPU's storage area and temporarily storing it in the storage registers. The vector calculation control unit controls the multipliers and adders to receive data from the storage registers and controls the multipliers to perform multiplication operations on the corresponding dimensions of the first and second vectors to obtain intermediate products, and controls the adders to sum the intermediate products of each dimension to obtain the vector operation result. The multipliers and adders are configured to perform parallel operations in a preset manner.
[0008] In some embodiments of the present invention, the data reading control unit reads the data contained in the vector to be processed multiple times. In each data reading, the data of a specified dimension of the first vector and the corresponding dimension of the second vector are read from the storage area of the CPU by means of cross-data retrieval and stored in the storage register to reduce data preparation time.
[0009] Preferably, when the data bit width of the vector to be processed is greater than the data bit width of a single storage register, the data of each dimension of the vector to be processed is split into at least two storage registers for storage, and the vector computation control unit controls the corresponding multiplier to obtain the corresponding data from the at least two storage registers as the multiplication operation input; when the data bit width of the vector to be processed is less than the data bit width of the storage register, each storage register stores multiple data of the vector to be processed, and the vector computation control unit controls multiple multipliers to obtain the corresponding data from the corresponding bit position of the storage register as the multiplication operation input to achieve parallel multiplication operation; when the data bit width of the vector to be processed is equal to the data bit width of the storage register, each storage register stores one number, and the vector computation control unit controls multiple multipliers to obtain the corresponding data from the corresponding bit position of the storage register as the multiplication operation input.
[0010] In some embodiments of the present invention, each vector operation module is configured to perform parallel operations of the multiplier and adder in the following preset manner: the vector calculation control unit controls the multiplier to read data from the storage register to perform multiplication operations; the data reading control unit reads the next data from the CPU's storage area and stores it in the storage register while the multiplier is performing multiplication operations; the adder receives the operation result of the multiplier and performs addition operations, while the vector calculation control unit controls the multiplier to read the next data from the storage register to perform multiplication operations; the above steps are repeated until the vector operation to be processed is completed.
[0011] In some embodiments of the present invention, the indication information is configured to be obtained by accessing a designated register group on the CPU, the designated register group on the CPU including: an operation status register, used to indicate whether the current vector operation module has completed the operation of the current vector to be processed; a data bit width control status register, used to configure the data bit width of the vector to be processed; a vector dimension control status register, used to configure the vector dimension of the vector to be processed; and a starting address control status register, used to configure the starting address of the vector data to be processed in the CPU's memory area.
[0012] Preferably, the adder is provided with a counter, and the counter controls the operation status register to indicate whether the calculation of the currently processed vector is complete by calculating a counting threshold based on the currently configured vector dimension.
[0013] Preferably, each vector operation module further includes a write-back control unit, which is used to control each vector operation module to write back the vector operation result to the CPU's memory area according to the starting address in the starting address control status register.
[0014] In some embodiments of the present invention, each vector operation module corresponds to multiple working states throughout the entire working process, including an idle state, a data reading state, a calculation waiting state, and a result write-back state. Specifically: the idle state is the state when the vector operation module has not completed the configuration of the configuration register; when the configuration register is configured, it jumps to the data reading state. The data reading state is the state when the vector operation module reads data from the CPU's storage area; after reading all the data contained in the vector to be processed, it jumps to the calculation waiting state; when accessing the CPU's storage area for data reading fails, it jumps back to the idle state. The calculation waiting state is the state before the vector to be processed by the vector operation module completes all operations; after completing all operations on the vector to be processed, it jumps to the result write-back state. The result write-back state is the state when the vector operation module writes the result back to the CPU's storage area after completing all operations on the current vector; after writing back the operation result of the vector to be processed, it jumps back to the idle state.
[0015] According to a second aspect of the present invention, a vector operation method is provided, the method comprising: S1, performing vector operation using a vector operation module of a general-purpose processor based on the first aspect of the present invention to obtain a vector operation result, and writing the vector operation result back to the storage area of the CPU; S2, the CPU of the general-purpose processor reading the vector operation result from the storage area.
[0016] Preferably, in step S1, the CPU of the general-purpose processor decomposes the convolution operation in the neural network task into multiple vector operations to be processed, sets instruction information for each vector operation to be processed, and calls the corresponding vector operation module to perform the vector operation according to the instruction information. Compared with the prior art, the advantages of the present invention are: it can improve the computational efficiency of vector operations, and it is also applicable to the acceleration tasks of neural network algorithms in different scenarios. It not only has strong scalability, but also reduces costs. Attached Figure Description
[0017] The embodiments of the present invention will be further described below with reference to the accompanying drawings, wherein:
[0018] Figure 1 This is a schematic diagram of the structure of a general-purpose processor that supports accelerated vector operations according to an embodiment of the present invention;
[0019] Figure 2 This is a schematic diagram of the structure of a vector operation module in a general-purpose processor that supports accelerated vector operations according to an embodiment of the present invention;
[0020] Figure 3 This is a schematic diagram of the state transition of the vector operation module according to an embodiment of the present invention;
[0021] Figure 4 A schematic diagram illustrating the reading of 32-bit vector data by the vector operation module according to an embodiment of the present invention;
[0022] Figure 5 This is a schematic diagram of the calculation process control logic of the vector operation module according to an embodiment of the present invention;
[0023] Figure 6 A schematic diagram illustrating the reading of 64-bit vector data by the vector operation module according to an embodiment of the present invention;
[0024] Figure 7 This is a schematic diagram of the overall workflow of the vector operation module according to an embodiment of the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the invention.
[0026] As mentioned in the background section, non-dedicated neural network processors struggle to handle neural network algorithms involving numerous matrix operations, such as image processing and object detection. While there are solutions that directly offload neural network tasks to dedicated neural network accelerators defined for those tasks, these accelerators require customization, leading to high costs, and are difficult to use for different neural network tasks, resulting in limited scalability. Therefore, the inventors have proposed a general-purpose processor that supports accelerated vector operations. This processor adds one or more vector operation modules to an existing general-purpose processor. Each module can be configured based on the data width and dimension of the vectors to be processed, and can be invoked via simple software instructions to achieve parallel operation of multiple vector operation modules.
[0027] To better understand the present invention, each step will be described in detail below with reference to specific embodiments.
[0028] According to one embodiment of the present invention, as shown in the appendix Figure 1 As shown, this invention provides a general-purpose processor that supports accelerated vector operations. The general-purpose processor includes a CPU and one or more vector operation modules (multiple vector operation modules can independently and in parallel perform vector operations). Each vector operation module is configured to: obtain instruction information from the CPU regarding the vector operation to be processed, the instruction information including data bit width and vector dimension; and adjust the data reading and calculation method of the vector operation module in the vector operation to be processed according to the data bit width and vector dimension in the instruction information, so as to complete the vector operation using the vector operation module while supporting configurable data bit width and vector dimension. It should be understood that the vector to be processed is the vector that needs to be processed, usually an operation between two vectors. Operations between more than two vectors also need to be converted into multiple operations between two vectors. It should also be noted that the vector operation module can be in the form of ASIC chips, FPGAs, and other forms of integrated circuits or chips, etc., and this invention does not limit this. Furthermore, the CPU calls the vector operation module through a software platform that can run on the general-purpose processor, for example, using C programs, assembly instructions, etc., and this invention also does not limit this. In the general-purpose processor provided by this invention, multiple parallel vector operation modules are set up to improve computational efficiency.
[0029] According to one embodiment of the present invention, each vector operation module is connected to the CPU through a memory read / write interface to realize data reading and writing. Since the memory read / write interface is a well-known technology in the field of general-purpose processors, it will not be described in detail here.
[0030] According to one embodiment of the present invention, the indication information is configured to be obtained by accessing a specified register group on the CPU. The specified register group on the CPU includes an operation status register, a data bit width control status register, a vector dimension control status register, and a starting address control status register (for simplicity, the latter three control status registers will be collectively referred to as configuration registers below). Each register is described below.
[0031] According to one embodiment of the present invention, the operation status register is used to indicate whether the current vector operation module has completed the operation of the current vector to be processed. For example, when the operation of the vector to be processed is completed, the operation status register is set to 1; otherwise, it remains at 0. The CPU will continuously query the operation status register until it finds the status of completion (i.e., 1).
[0032] According to one embodiment of the present invention, a data bit width control status register is used to configure the data bit width of the vector to be processed. For example, for the data of the vector to be processed, 1 indicates a data bit width of 8 bits, 2 indicates a data bit width of 16 bits, 3 indicates a data bit width of 32 bits, and 4 indicates a data bit width of 64 bits. The CPU can perform dot product of vectors with different data bit widths by modifying the parameters of the data bit width control status register.
[0033] According to one embodiment of the present invention, the vector dimension control status register is used to configure the vector dimension (or simply dimension) of the vector to be processed. The dimension is determined by the data bit width of the vector to be processed. For example, for the data of the vector to be processed to be operated on, 8 bits can be configured to configure a vector with a vector dimension that is a multiple of 4, 16 bits can be configured to configure a vector with a vector dimension that is a multiple of 2, and 32 bits and 64 bits can be configured to configure a vector with a vector dimension that is a natural number (the maximum supported dimension is 2^32).
[0034] According to one embodiment of the present invention, the first address control status register is used to configure the storage first address of the vector data to be processed in the storage area of the CPU. For two vectors to be processed, the first vector is usually stored first, followed by the second vector (for ease of understanding, the first vector will be referred to as vector A and the second vector as vector B in some parts of the following text).
[0035] It should be noted that the control of the register group over the vector operation module can be adjusted according to the actual situation. For example, multiple vector operation modules can be controlled by a single register group in a time-division multiplexing manner, allowing multiple vector operation modules to perform calculations in parallel; alternatively, a register group can be configured for each vector operation module, so that the parameters of each register group do not need to be adjusted frequently. This invention uses the CPU to generate indication information corresponding to the data bit width and vector dimension of the vector to be calculated, thereby controlling a corresponding vector operation module to perform vector operations, so as to realize vector operations with configurable data bit widths and vector dimensions.
[0036] According to one embodiment of the present invention, as shown in the appendix Figure 2 As shown, each vector operation module includes a data reading control unit, a vector calculation control unit, a write-back control unit, multiple multipliers, and at least one adder. The vector operation to be processed is a dot product of the first vector and the second vector. Each unit is described below.
[0037] According to one embodiment of the present invention, the data reading control unit includes a plurality of storage registers of predetermined size, used to obtain data of at least a portion of the dimensions of a first vector and a second vector from the CPU's storage area and temporarily store them in the storage registers. Preferably, the data reading control unit reads the data contained in the vector to be processed in multiple steps, wherein, during each data reading, data of a specified dimension of the first vector and data of the corresponding dimension of the second vector are read from the CPU's storage area in an interleaved manner and stored in the storage registers to reduce data preparation time. It should be noted that interleaved data reading means that each time data is read from the CPU's storage area and stored in the storage register, the read address of the CPU's storage area is controlled to interleave the reading of n numbers of the first vector and n numbers of the second vector and store them in the storage registers. Preferably, after the vector calculation control unit reads data from the storage registers, the data reading control unit reads the next set of data from the CPU's storage area and stores it in the storage registers according to a preset period, wherein the preset period is a number of cycles determined according to the number of storage registers, wherein the time required for each storage register to store the maximum amount of data is one cycle.
[0038] According to one embodiment of the present invention, the vector calculation control unit is used to control the multiplier and adder to receive data from the storage register and to control the multiplier and adder to perform multiplication operations on the data of the corresponding dimensions of the first vector and the second vector respectively to obtain intermediate products, and to control the adder to sum the intermediate products of each dimension to obtain the vector operation result, wherein the multiplier and adder are configured to perform parallel operations in a preset manner.
[0039] According to one embodiment of the present invention, a multiplier is used to perform multiplication operations, and the result of the multiplication operation is used as the input of an adder for addition operations. The dot product operation of vectors is completed through the combination of multipliers and adders. Preferably, for each vector operation module, multiple multipliers and at least one adder can be configured. The number of multipliers can be adjusted according to the actual situation corresponding to the number of storage registers to ensure that the data read from the storage registers can be multiplied in parallel each time. Preferably, the adder in the vector operation module of the present invention is also provided with a counter. The counter controls the operation status register to indicate whether the calculation of the currently processed vector is completed based on a counting threshold calculated according to the currently configured vector dimension. According to one embodiment of the present invention, a counting threshold is set according to the vector dimension. Each time an addition operation in the vector operation to be processed is completed, the count value is incremented by 1, and the completion of the calculation is determined based on whether the count value reaches the counting threshold. For example, the counting threshold is set to the vector dimension minus 1, the count value is initially 0, each time an addition operation in the vector operation to be processed is completed, the count value is incremented by 1, and the calculation is considered complete when the count value reaches the counting threshold. It should be understood that there may be other ways, such as setting the counting threshold to the value of the vector dimension, and initializing the count value to 1.
[0040] According to one embodiment of the present invention, the multiplier and adder are configured to perform parallel operations in a preset manner, the preset manner being as follows: the vector computation control unit controls the multiplier to read data from the storage register and perform multiplication operations; the data reading control unit reads the next data from the CPU's storage area and stores it in the storage register while the multiplier is performing multiplication operations; the adder receives the operation result from the multiplier and performs addition operations, while the vector computation control unit controls the multiplier to read the next data from the storage register and perform multiplication operations; the above steps are repeated until the operation of the vector to be processed is completed.
[0041] According to one embodiment of the present invention, for each vector operation module, when the data bit width of the vector to be processed is greater than the data bit width of a single storage register, each number of the vector to be processed is split into at least two storage registers for storage, and the vector calculation control unit controls the corresponding multiplier to obtain the corresponding data from the at least two storage registers as multiplication operation input; when the data bit width of the vector to be processed is less than the data bit width of the storage register, each storage register stores multiple data of the vector to be processed, and the vector calculation control unit controls multiple multipliers to obtain the corresponding data from the corresponding bit positions of the storage registers as multiplication operation input to achieve parallel multiplication operation; when the data bit width of the vector to be processed is equal to the data bit width of the storage register, each storage register stores one number, and the vector calculation control unit controls multiple multipliers to obtain the corresponding data from the corresponding bit positions of the storage registers as multiplication operation input. It should be understood that the number of storage registers and the data bit width that can be stored are manually set and can be adjusted according to the actual application scenario. For example, if the data width of the vector to be processed is 32 bits, and the data width of the storage register is 16 bits, a 32-bit number needs to be split into high 16 bits and low 16 bits. In this case, each number in the vector requires two storage registers, and at least four storage registers are needed to read one number from each vector at a time. However, when the data width of the vector to be processed is equal to the data width of the storage register, each storage register can store one number. For example, if both the data width of the vector to be processed and the data width of the storage register are 16 bits, the number of registers can be set to 2 or 4. Alternatively, six storage registers can be used, allowing for the simultaneous retrieval of one, two, or three numbers from two vectors. Simultaneously, the number of multipliers can be set to one, two, or three, enabling parallel multiplication operations. When the data width of the vector to be processed is 8 bits, and the data width of the storage registers is 32 bits, each storage register can store four numbers at a time. Therefore, if two storage registers are configured, four numbers from two vectors can be read at a time. In this case, eight multipliers can be set simultaneously, performing parallel multiplication of eight numbers from two vectors in a single retrieval. It should be noted that when the vectors to be processed (i.e., vectors A and B to be operated on) have different dimensions, the lower-dimensional vector is padded with zeros by software to make its dimension the same as the higher-dimensional vector.
[0042] According to one embodiment of the present invention, the write-back control unit is used to write back the operation result of the vector to be processed to the memory area of the CPU, wherein the write-back address is determined by the starting address of the vector to be processed in the memory area of the CPU before the vector operation is performed.
[0043] According to an embodiment of the present invention, refer to the appendix Figure 3As shown, each vector operation module corresponds to multiple working states throughout the entire process, including idle state, data reading state, calculation waiting state, and result writing back state. Each state is described in detail below.
[0044] The idle state is the state when the vector operation module has not completed the configuration of the configuration register. When the configuration register is completed, it jumps to the data reading state. However, when the configuration register in the register group has not been completed, the vector operation module remains in the idle state.
[0045] The data read state refers to the state of the vector processing module when reading data from the CPU's memory area. After reading all the data contained in the vector to be processed, it jumps to a computation waiting state. If accessing the CPU's memory area fails, it jumps to an idle state. For each vector processing module, its data read control unit needs to be configured according to the CPU's register set based on the data bit width, vector dimension, and memory address of the vector to be processed.
[0046] The calculation waiting state is the state before the vector operation module completes all operations on the vector to be processed. After all operations on the vector to be processed are completed, it jumps to the write-back result state.
[0047] The write-back result state is the state of the vector operation module when it writes back the result to the CPU's storage area after completing all operations on the current vector. After writing back the operation result of the vector to be processed, it jumps to the idle state.
[0048] To facilitate understanding, the following concrete example illustrates the entire vector operation process. In this example, the vectors to be processed are two vectors, vector A and vector B, each with a data width of 32 bits. The data read control unit has four 32-bit storage registers. During data retrieval, the data read control unit first reads the first number (32-bit data width) of vector A and vector B from the corresponding address in the CPU's memory area according to the address control status register in the CPU's register set and stores it in the first and second storage registers, respectively. Then, it reads the second number of vector A and vector B and stores it in the third and fourth storage registers, respectively. This entire process takes four steps (one step corresponds to storing data in one storage register). Finally, the four numbers in the storage registers (i.e., the first and second numbers of vector A and vector B) are input... The data is fed into the multiplier for multiplication. While the multiplier performs the multiplication of these four numbers, the data read control unit reads the third and fourth numbers of vectors A and B and stores them in the storage register. After the multiplier completes the multiplication, it inputs the result into the adder for addition. While the adder performs the addition, it inputs the four numbers from the storage register into the multiplier for multiplication. At the same time, the data read control unit reads the fifth and sixth numbers of vectors A and B and stores them in the storage register. This process is repeated continuously. Finally, when the CPU finds a 1 in the operation status register (which means that the operation of all data of the vector to be processed has been completed), the CPU reads the calculation result from the corresponding address in the storage area according to the starting address stored in the starting address control status register. By adopting the above method, time-sharing multiplexing of multipliers and adders can be achieved, which greatly improves the computational efficiency. At the same time, the existence of storage registers can greatly reduce the storage space required in the vector operation module, and only a small amount of data needs to be read each time. In contrast, the existing technology requires reading all the numbers contained in two vectors at once. In addition, multipliers and adders cannot operate in parallel. Therefore, the method provided by this invention can accelerate vector operations.
[0049] For vector data with a data width of 32 bits, append Figure 4 This diagram illustrates the vector operation module reading vector data. At this point, the storage registers are two 32-bit registers. Therefore, each time data is retrieved, one number from vector A and one number from vector B are read separately. For example, the first time data is retrieved, the first numbers from vector A and vector B are read separately. (See attached diagram.) Figure 5 The control logic diagram of the entire calculation process is shown.
[0050] For vector data with a data width of 64 bits, append Figure 6The diagram illustrates the vector operation module reading vector data. At this time, the storage registers are four 32-bit storage registers. Therefore, a 64-bit number needs to be split into two 32-bit storage registers, with the lower 32 bits and the higher 32 bits stored separately. That is, the first number (64 bits) of vector A and the first number (64 bits) of vector B are stored in the four 32-bit storage registers.
[0051] For vector calculations with other data bit widths, refer to the above illustration. It can be achieved by simply changing the indication information of the register group on the CPU (i.e., the data bit width, vector dimension, and storage starting address of the vector to be processed) as well as the data bit width and number of storage registers. It will not be elaborated here.
[0052] Appendix Figure 7 This invention illustrates the entire process by which each vector operation module in a general-purpose processor supporting accelerated vector operations completes one operation on a vector to be processed. This process mainly includes two aspects: software and hardware. The software mainly refers to writing data to the CPU's memory area through the CPU, configuring parameters in the CPU's register group, querying the operation status register, and reading the final completed vector operation result. The hardware mainly refers to starting the vector operation module, reading the data of the vector to be processed from the CPU's memory area for calculation, writing back the final operation result, updating the operation status register, and clearing the configuration register.
[0053] According to an embodiment of the present invention, the present invention also provides a vector operation method, the method comprising: S1, performing vector operations using a vector operation module based on the aforementioned general-purpose processor to obtain vector operation results, and writing the vector operation results back to the CPU's storage area; S2, the CPU of the general-purpose processor reading the vector operation results from the storage area. Preferably, in step S1, the CPU of the general-purpose processor decomposes the convolution operation in the neural network task into multiple vector operations to be processed, sets instruction information for each vector operation to be processed, and calls the corresponding vector operation module to perform vector operations according to the instruction information. It should be understood that, in addition to the vector operations corresponding to the neural network task, the CPU may also process vector operations corresponding to other tasks. According to the rules set by the implementer, the CPU may also call the vector operation module to complete the vector operations corresponding to other tasks.
[0054] Compared with existing technologies, the advantages of this invention are: it can improve the computational efficiency of vector operations, and it is also applicable to the acceleration of neural network algorithms in different scenarios. It is not only highly scalable, but also reduces costs.
[0055] It should be noted that although the steps are described in a specific order above, it does not mean that the steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently, or even in a different order, as long as the required function can be achieved.
[0056] This invention can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of the invention.
[0057] Computer-readable storage media can be tangible devices that hold and store instructions for use by an instruction execution device. Computer-readable storage media can be, for example, including but not limited to, electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination thereof.
[0058] The various embodiments of the present invention have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A general-purpose processor supporting accelerated vector operations, the general-purpose processor comprising a CPU, characterized in that, The general-purpose processor also includes one or more vector operation modules, each of which is configured as follows: The instruction information for the vector operation to be processed is obtained from the CPU. This instruction information includes the data bit width and vector dimension. The instruction information is configured to be obtained by accessing a designated register set on the CPU. This designated register set includes: an operation status register, used to indicate whether the current vector operation module has completed the operation on the vector to be processed; a data bit width control status register, used to configure the data bit width of the vector to be processed; a vector dimension control status register, used to configure the vector dimension of the vector to be processed; and a starting address control status register, used to configure the starting address of the vector data to be processed in the CPU's memory area. The vector operation module adjusts the reading and calculation method of data in the vector operation to be processed according to the data bit width and vector dimension in the instruction information, so as to complete the vector operation using the vector operation module while supporting configurable data bit width and vector dimension.
2. The general-purpose processor according to claim 1, characterized in that, Each vector operation module includes a data reading control unit, a vector calculation control unit, multiple multipliers, and at least one adder. The vector operation to be processed involves the dot product of a first vector and a second vector, wherein: The data reading control unit includes multiple storage registers of predetermined size, used to obtain data of at least a portion of the dimensions of the first vector and the second vector from the CPU's storage area and temporarily store them in the storage registers; The vector calculation control unit is used to control the multiplier and adder to receive data from the storage register, and to control the multiplier to perform multiplication operations on the data of the corresponding dimensions of the first vector and the second vector respectively to obtain intermediate products, and to control the adder to sum the intermediate products of each dimension to obtain the vector operation result. The multiplier and adder are configured to perform parallel operations in a preset manner.
3. The general-purpose processor according to claim 2, characterized in that, The data reading control unit reads the data contained in the vector to be processed in multiple steps. During each data reading, the data of a specified dimension of the first vector and the corresponding dimension of the second vector are read from the CPU's storage area by means of cross-data retrieval and stored in the storage register to reduce data preparation time.
4. The general-purpose processor according to claim 2, characterized in that, When the data bit width of the vector to be processed is greater than the data bit width of a single storage register, the data of each dimension of the vector to be processed is split into at least two storage registers for storage, and the vector calculation control unit controls the corresponding multiplier to obtain the corresponding data from at least two storage registers as the input for multiplication operation.
5. The general-purpose processor according to claim 2, characterized in that, When the data bit width of the vector to be processed is smaller than the data bit width of the storage register, each storage register stores multiple data of the vector to be processed, and the vector calculation control unit controls multiple multipliers to obtain the corresponding data from the corresponding bit position of the storage register as the input for multiplication operation to realize parallel multiplication operation.
6. The general-purpose processor according to claim 2, characterized in that, When the data bit width of the vector to be processed is equal to the data bit width of the storage register, each storage register stores one number, and the vector computation control unit controls multiple multipliers to obtain the corresponding data from the corresponding bit position of the storage register as the input for the multiplication operation.
7. The general-purpose processor according to claim 2, characterized in that, Each vector operation module is configured to implement parallel operations of the multiplier and adder in the following preset manner: The vector computation control unit controls the multiplier to read data from the storage register and perform multiplication operations; The data read control unit reads the next data from the CPU's memory area and stores it in the memory register while the multiplier is performing the multiplication operation; The adder receives the result of the multiplier's operation and performs the addition operation, while the vector calculation control unit controls the multiplier to read the next data from the storage register and perform the multiplication operation. Repeat the above steps until the vector operation to be processed is completed.
8. The general-purpose processor according to any one of claims 2-7, characterized in that, The adder is equipped with a counter, and the counter controls the operation status register to indicate whether the calculation of the currently processed vector is complete based on a counting threshold calculated based on the currently configured vector dimension.
9. The general-purpose processor according to claim 8, characterized in that, Each vector operation module also includes a write-back control unit, which controls each vector operation module to write back the vector operation result to the CPU's memory area according to the starting address in the starting address control status register.
10. The general-purpose processor according to claim 9, characterized in that, Each vector operation module corresponds to multiple working states throughout the entire process, including idle state, data reading state, computation waiting state, and result write-back state, among which: The idle state is the state when the vector operation module has not completed the configuration of the configuration register. When the configuration register is completed, it jumps to the data reading state. The data reading state is the state of the vector operation module when it reads data from the CPU's storage area. After reading all the data contained in the vector to be processed, it jumps to the calculation waiting state. When reading data fails to access the CPU's storage area, it jumps to the idle state. The calculation waiting state is the state before the vector operation module completes all operations on the vector to be processed. After all operations on the vector to be processed are completed, the module jumps to the write-back result state. The write-back result state is the state of the vector operation module when it writes back the result to the CPU's storage area after completing all operations on the current vector. After writing back the operation result of the vector to be processed, it jumps to the idle state.
11. A vector operation method, characterized in that, The method includes: S1. Perform vector operations using the vector operation module of the general-purpose processor according to any one of claims 1-10 to obtain the vector operation result, and write the vector operation result back to the CPU's storage area; S2. The CPU of the general-purpose processor reads the vector operation results from the storage area.
12. The vector operation method according to claim 11, characterized in that, In step S1, the CPU of the general-purpose processor decomposes the convolution operation in the neural network task into multiple vector operations to be processed, sets instruction information for each vector operation to be processed, and calls the corresponding vector operation module to perform vector operations according to the instruction information.
