Neural network processing device and method for executing vector outer product instruction

By realizing the analysis and execution of vector outer product instructions in the neural network processing device, it supports multiple operations of sparse vectors and matrices, solves the problem of insufficient support for sparse neural network operations in the existing technology, and reduces operation overhead and energy consumption.

CN109117186BActive Publication Date: 2024-09-13SHANGHAI CAMBRICON INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201810914419.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-08-08
Publication Date
2024-09-13
Estimated Expiration
2038-08-08

AI Technical Summary

Technical Problem

Existing vector operation instructions cannot support sparse vector or sparse matrix operations in sparse neural networks, and cannot implement variable-scale sparse vector or matrix operations, resulting in high computational overhead and high energy consumption.

Method used

Provide a neural network processing device and a method for executing vector outer product instructions, which realize the analysis and execution of vector outer product instructions through a memory, arithmetic unit and a control unit, support multiple operations of sparse vectors and matrices, reduce the number of instructions, and simplify instructions to use.

Benefits of technology

A single vector outer product instruction is used to realize multiple operations, reduce operation overhead, reduce module power consumption, and support the operation of larger-scale neural networks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN109117186B
    Figure CN109117186B
Patent Text Reader

Abstract

The present invention provides a processing device, comprising: a memory, a register unit, an operation unit and a control unit; the memory stores vectors; the register unit stores vector outer product instructions, the control unit obtains the vector outer product instructions, parses the vector outer product instructions to obtain an operation code and an operation domain; according to the operation code, data participating in the vector outer product operation are obtained from the memory; the operation unit performs a vector outer product operation on the data participating in the vector outer product operation. The technical solution provided by the present invention has the advantages of low power consumption and low calculation overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a neural network processing device and a method for executing a vector outer product instruction thereof. Background Art

[0002] In modern general-purpose and special-purpose processors, more and more computing instructions (such as vector instructions) are introduced for operations. Vector instructions are instructions that enable the processor to perform vector or matrix operations, such as vector addition and subtraction, vector inner product, matrix multiplication, matrix convolution, etc. In a vector instruction, at least one input is a vector or matrix or the operation result is a vector or matrix. Vector instructions can perform parallel calculations by calling the vector processing components inside the processor to increase the operation speed. In existing vector instructions, the vectors or matrices in their operands or results are generally of fixed size. For example, the vector instructions in the vector extension structure Neon in the ARM processor can process a 32-bit floating-point vector of length 4 or a 16-bit fixed-point vector of length 8 at a time. Therefore, existing vector operation instructions cannot implement operations on vectors or matrices of variable size.

[0003] On the other hand, as a high-computation and high-memory algorithm, the more weights a neural network has, the more computation and memory it will require. In order to reduce the amount of computation and the number of weights, and thus the amount of memory required, a sparse neural network is proposed. A sparse neural network is defined as follows: In a neural network, if there are many weights with a value of 0 and there is no regular distribution of weights with a value other than 0, then the neural network is called a sparse neural network. The ratio of the number of elements with a weight of 0 to the number of all weighted elements in the neural network is defined as the sparsity of the neural network, such as Figure 1a shown.

[0004] However, the existing vector operation instructions cannot support the operations of sparse vectors or sparse matrices in sparse neural networks, let alone the operations of sparse vectors or sparse matrices of variable scale. In addition, the current vector operation instructions can only implement one operation. For example, a vector instruction can only implement one operation of multiplication or addition. A vector instruction cannot implement more than two operations. Therefore, the existing vector operations have high computational overhead and high energy consumption. Summary of the invention

[0005] The embodiment of the present invention provides a neural network processing device and a method for executing a vector outer product instruction, which can achieve the purpose of implementing multiple operations with a single vector outer product instruction, which is beneficial to reducing computing overhead and lowering the power consumption of the module.

[0006] In a first aspect, an embodiment of the present invention provides a processing device, the processing device is used to perform operations according to a vector outer product instruction, the processing device comprising: a memory, an operation unit, a control unit and a register unit;

[0007] The register unit is used to store a vector outer product instruction; the vector outer product instruction includes an operation code and an operation field, the operation code is used to instruct to perform a vector outer product operation; the operation field includes the first address of the data participating in the vector outer product operation and the address of the index of part of the data or all of the data participating in the vector outer product operation;

[0008] The memory is used to store data involved in the vector outer product operation;

[0009] The control unit is used to obtain the vector outer product instruction from the register unit, parse the vector outer product instruction to obtain the operation code and the operation domain; obtain the data participating in the vector outer product operation and the index of part of the data or all of the data participating in the vector outer product operation from the memory according to the operation domain; and transmit the data participating in the vector outer product operation to the operation unit;

[0010] The operation unit is used to perform a vector outer product operation on the data participating in the vector outer product operation.

[0011] In a possible embodiment, when the vector outer product instruction is a first vector outer product instruction, the operation code is used to indicate the first vector outer product operation, and the operation domain includes: the index representation of the sparse vector X12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector X12, the first address of the index of the sparse vector X12, the first address of the element in the vector Y1, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors;

[0012] The control unit is specifically used for:

[0013] Obtain the matrix A1 from the memory according to the first address of the matrix A1, the storage format of the matrix A1 and the low-dimensional length of the matrix A1, the number of elements in the matrix A1 being the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; obtain the sparse vector X12 from the memory according to the first address of the element in the sparse vector X12; obtain the index of the sparse vector X12 from the memory according to the first address of the index of the sparse vector X12; obtain the vector Y1 from the memory according to the first address of the element in the vector Y1; filter the elements in the vector Y1 according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y12; obtain the tenth scalar from the memory according to the first address of the tenth scalar; transmit the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar to the operation unit;

[0014] The computing unit is specifically used for:

[0015] A first vector outer product operation is performed on the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar.

[0016] Further, the operation domain also includes: the number of elements in the sparse vector X12, the number of elements in the vector Y1, and the address interval between the elements in the vector Y1;

[0017] The control unit obtains the sparse vector X12 from the memory according to the first address of the element in the sparse vector X12, including:

[0018] Obtaining the sparse vector X12 from the memory according to the first address of the element in the sparse vector X12 and the number of elements in the sparse vector X12;

[0019] The control unit obtains the vector Y1 from the memory according to the first address of the element in the vector Y1, including:

[0020] The vector Y1 is obtained from the memory according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1.

[0021] In a possible embodiment, when the vector outer product instruction is a second vector outer product instruction, the operation code is used to indicate the second vector outer product operation, and the operation domain includes: the index representation of the sparse vector sX12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector sX12, the first address of the index of the sparse vector sX12, the first address of the element in the sparse vector sY12, the first address of the index of the sparse vector sY12, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the control unit is specifically used to:

[0022] The matrix A1 is obtained from the memory according to the first address of the matrix A1, the storage format of the matrix and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector sX12 and the sparse vector sY12 are respectively obtained from the memory according to the first address of the elements in the sparse vector sX12 and the first address of the elements in the sparse vector sY12; the index of the sparse vector sX12 and the sparse vector sY12 are respectively obtained from the memory according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12 The index of the sparse vector sY12; obtaining a first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12; filtering the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; obtaining the tenth scalar from the memory according to the first address of the tenth scalar; transmitting the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12 and the tenth scalar to the operation unit;

[0023] The computing unit is specifically used for:

[0024] A second vector outer product operation is performed on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12, and the tenth scalar.

[0025] Furthermore, the operation domain also includes an index representation of the sparse vector sY12; and the control unit is further used for:

[0026] After obtaining the sparse vector sX12 and its index and the sparse vector sY12 and its index, obtaining a second intermediate index according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12;

[0027] The elements in the sparse vector sX12 and the sparse vector sY12 are filtered according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; and the filtered sparse vector sX12 and the filtered sparse vector sY12 are transmitted to the operation unit.

[0028] Further, the operation domain also includes: the number of elements in the sparse vector sX12 and the number of elements in the sparse vector sY12;

[0029] The control unit obtains the sparse vector sX12 and the sparse vector sY12 from the memory according to the first address of the element in the sparse vector sX12 and the first address of the element in the sparse vector sY12, respectively, including:

[0030] Obtaining the sparse vector sX12 from the memory according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12;

[0031] The sparse vector sY12 is obtained from the memory according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12.

[0032] In a possible embodiment, the index representation of the input data includes: a direct index representation or a step index representation; wherein the input data includes: a sparse vector X12, a sparse vector sX12 or a sparse vector sY12.

[0033] Further, when the index representation of the input data is a direct index representation, the index of the input data is a string consisting of 0 and 1, 0 indicates that the element in the input data does not meet the preset condition, and 1 indicates that the element in the input data meets the preset condition, or;

[0034] When the index representation of the input data is a step index representation, the index of the input data is a character string consisting of the distance value between the element in the input data that meets the preset condition and the previous element that meets the preset condition;

[0035] The preset condition is that the absolute value of the element in the input data is greater than or less than a preset threshold.

[0036] In a possible embodiment, the operation unit further includes a vector addition circuit, a vector multiplication circuit, a size comparison circuit, a nonlinear operation circuit and a vector scalar multiplication circuit; the operation unit is a multi-pipelined structure;

[0037] Among them, the vector multiplication circuit and the vector scalar multiplication circuit are in the first pipeline stage, the size comparison circuit and the vector addition circuit are in the second pipeline stage, and the nonlinear operation component is in the third pipeline stage, wherein the output data of the first pipeline stage is the input data of the second pipeline stage, and the output data of the second pipeline stage is the input data of the third pipeline stage.

[0038] In a possible embodiment, the control unit further includes:

[0039] An instruction storage unit, used for storing the vector outer product instruction;

[0040] An instruction processing unit, used for parsing the vector outer product instruction to obtain the operation code and operation domain;

[0041] The storage queue unit is used to store an instruction queue, which includes: a plurality of vector outer product instructions to be executed in a front-to-back order of the queue.

[0042] In a possible embodiment, the processing device further includes:

[0043] a dependency processing unit, configured to determine whether an s-th vector outer product instruction has an association relationship with an s-1th vector outer product instruction before the s-th vector outer product instruction, and if the s-th vector outer product instruction has an association relationship with the s-1th vector outer product instruction, cache the s-th vector outer product instruction in the instruction storage unit, and extract the s-th vector outer product instruction from the instruction storage unit and transmit it to the operation unit after the s-1th vector outer product instruction is executed;

[0044] The determining whether there is an association relationship between the s-th vector outer product instruction and the s-1-th vector outer product instruction before the s-th vector outer product instruction comprises:

[0045] The first storage address interval of the data required in the s-th vector outer product instruction is extracted based on the s-th vector outer product instruction, and the zeroth storage address interval of the data required in the s-1th vector outer product instruction is extracted based on the s-1th vector outer product instruction. If the first storage address interval and the zeroth storage address interval have an overlapping area, it is determined that the s-th vector outer product instruction has an associated relationship with the s-1th vector outer product instruction; if the first storage address interval and the zeroth storage address interval do not have an overlapping area, it is determined that the s-th vector outer product instruction has no associated relationship with the s-1th vector outer product instruction.

[0046] In a second aspect, an embodiment of the present invention provides a computing device, which includes one or more processing devices as described in the first aspect, and is used to obtain data to be calculated and control information from other processing devices, and perform specified operations, and transmit the execution results to other processing devices through an I / O interface;

[0047] When the computing device includes a plurality of processing devices, the plurality of processing devices may be connected and transmit data through a specific structure;

[0048] Among them, multiple processing devices are interconnected and transmit data through a fast external device interconnect bus or a PCIE bus to support larger-scale neural network operations; multiple processing devices share the same control system or have their own control systems; multiple processing devices share memory or have their own memory; the interconnection method of multiple processing devices is any interconnection topology.

[0049] In a third aspect, an embodiment of the present invention provides a combined processing device, which includes the computing device, the universal interconnection interface and other processing devices as described in the second aspect;

[0050] The computing device interacts with the other processing devices to jointly complete the operation specified by the user.

[0051] In a fourth aspect, an embodiment of the present invention provides a neural network chip, which includes the processing device described in the first aspect, the computing device described in the second aspect, or the combined processing device described in the third aspect.

[0052] In a fifth aspect, an embodiment of the present invention provides a neural network chip packaging structure, wherein the neural network chip packaging structure includes the neural network chip described in the fourth aspect;

[0053] In a sixth aspect, an embodiment of the present invention provides an electronic device, which includes the neural network chip described in the fourth aspect or the neural network chip packaging structure described in the fifth aspect.

[0054] In a seventh aspect, an embodiment of the present invention provides a method for executing a vector outer product instruction, comprising:

[0055] Obtaining a vector outer product instruction, and parsing the vector outer product instruction to obtain an operation code and an operation domain of the vector outer product instruction;

[0056] Acquire data involved in vector outer product operation according to the operation domain;

[0057] A vector outer product operation is performed on the data participating in the vector outer product operation.

[0058] In a possible embodiment, when the vector outer product instruction is a first vector outer product instruction, the operation code is used to indicate the first vector outer product operation, and the operation domain includes: the index representation of the sparse vector X12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector X12, the first address of the index of the sparse vector X12, the first address of the element in the vector Y1, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors;

[0059] The step of acquiring data participating in the vector outer product operation according to the operation domain includes:

[0060] The matrix A1 is obtained according to the first address of the matrix A1, the storage format of the matrix A1 and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector X12 is obtained according to the first address of the element in the sparse vector X12; the index of the sparse vector X12 is obtained according to the first address of the index of the sparse vector X12; the vector Y1 is obtained according to the first address of the element in the vector Y1; the elements in the vector Y1 are screened according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y1; the tenth scalar is obtained according to the first address of the tenth scalar;

[0061] The performing a vector outer product operation on the data participating in the vector outer product operation includes:

[0062] A first vector outer product operation is performed on the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar.

[0063] Further, the operation domain also includes: the number of elements in the sparse vector X12, the number of elements in the vector Y1, and the address interval between the elements in the vector Y1;

[0064] The step of obtaining the sparse vector X12 according to the first address of the element in the sparse vector X12 comprises:

[0065] Obtain the sparse vector X12 according to the first address of the element in the sparse vector X12 and the number of elements in the sparse vector X12;

[0066] The obtaining the vector Y1 according to the first address of the element in the vector Y1 comprises:

[0067] The vector Y1 is obtained according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1.

[0068] In a possible embodiment, when the vector outer product instruction is a second vector outer product instruction, the operation code is used to indicate a second vector outer product operation, and the operation domain includes: the index representation of the sparse vector sX12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector sX12, the first address of the index of the sparse vector sX12, the first address of the element in the sparse vector sY12, the first address of the index of the sparse vector sY12, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the obtaining of data participating in the vector outer product operation according to the operation domain includes:

[0069] The matrix A1 is obtained according to the first address of the matrix A1, the storage format of the matrix and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector sX12 and the sparse vector sY12 are obtained according to the first address of the element in the sparse vector sX12 and the first address of the element in the sparse vector sY12 respectively; the sparse vector sX12 and the sparse vector sY12 are obtained according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12 respectively. Respectively obtain the index of the sparse vector sX12 and the index of the sparse vector sY12; obtain a first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12; filter the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; obtain the tenth scalar according to the first address of the tenth scalar;

[0070] Performing a vector outer product operation on the data participating in the vector outer product operation includes:

[0071] A second vector outer product operation is performed on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12, and the tenth scalar.

[0072] Furthermore, the operation domain also includes an index representation of the sparse vector sY12; and the step of obtaining data participating in the vector outer product operation according to the operation domain also includes:

[0073] After obtaining the sparse vector sX12 and its index and the sparse vector sY12 and its index, obtaining a second intermediate index according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12;

[0074] The elements in the sparse vector sX12 and the sparse vector sY12 are filtered according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12.

[0075] Further, the operation domain also includes: the number of elements in the sparse vector sX12 and the number of elements in the sparse vector sY12;

[0076] The step of obtaining the sparse vector sX12 and the sparse vector sY12 according to the first addresses of the elements in the sparse vector sX12 and the first addresses of the elements in the sparse vector sY12 respectively comprises:

[0077] Obtain the sparse vector sX12 according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12;

[0078] The sparse vector sY12 is obtained according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12.

[0079] In a possible embodiment, the index representation of the input data is a direct index representation or a step index representation; the input data includes: the sparse vector X12, the sparse vector sX12 or the sparse vector sY12;

[0080] When the index representation of the input data is a direct index representation, the index of the input data is a string consisting of 0 and 1, 0 indicates that the element in the input data does not meet the preset condition, and 1 indicates that the element in the input data meets the preset condition, or;

[0081] When the index representation of the input data is a step index representation, the index of the input data is a character string consisting of the distance value between the element in the input data that meets the preset condition and the previous element that meets the preset condition;

[0082] The preset condition is that the absolute value of the element in the input data is greater than or less than a preset threshold.

[0083] It can be seen that the vector outer product instruction provided by the embodiment of the present invention strengthens the function of the instruction and replaces the original multiple instructions with one instruction. This reduces the number of instructions required for complex vector and matrix operations and simplifies the use of vector instructions; compared with multiple instructions, there is no need to store intermediate results, which saves storage space and avoids additional reading and writing overhead. BRIEF DESCRIPTION OF THE DRAWINGS

[0084] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0085] Figure 1a A schematic diagram of the structure of a sparse neural network provided by an embodiment of the present invention;

[0086] Figure 1b A schematic diagram of the structure of a processing device provided for the implementation of the present invention;

[0087] Figure 2A schematic diagram of a partial structure of a processing device provided by an embodiment of the present invention;

[0088] Figure 3 A schematic diagram of a partial structure of another processing device provided by an embodiment of the present invention;

[0089] Figure 4 A schematic diagram of a pipeline stage of a computing unit in a processing device provided by an embodiment of the present invention;

[0090] Figure 5a A schematic diagram of the structure of a computing device provided by an embodiment of the present invention;

[0091] Figure 5b A schematic diagram of the structure of another computing device provided by an embodiment of the present invention;

[0092] Figure 6 A flow chart of a method for executing a vector outer product instruction provided by an embodiment of the present invention.

[0093] The dashed components in the figures are optional. DETAILED DESCRIPTION

[0094] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0095] The terms "first", "second", "third" and "fourth" etc. in the specification and claims of the present invention and the drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices. The " / " in the text may represent "or".

[0096] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. 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 that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0097] See also Figure 1b , Figure 1b 1 is a schematic diagram of a processing device according to an embodiment of the present invention. The processing device 100 is used to perform operations according to a vector outer product instruction. Figure 1b As shown, the processing device 100 includes: a memory 101 , a register unit 102 (optionally), an operation unit 104 and a control unit 103 .

[0098] The register unit 102 is used to store a vector outer product instruction; the vector outer product instruction includes an operation code and an operation field, and the operation code is used to instruct to perform a vector outer product operation;

[0099] The memory 101 is used to store data involved in the vector outer product operation;

[0100] The control unit 103 is configured to obtain the vector outer product instruction from the register unit 102, and parse the vector outer product instruction to obtain the operation code and operation domain; the operation domain includes the first address of the data participating in the vector outer product operation and the address of the index of part or all of the data in the data participating in the vector outer product operation; obtain the data participating in the vector outer product operation and the index of part or all of the data in the data participating in the vector outer product operation from the memory 101 according to the operation domain; and transmit the data participating in the vector outer product operation to the operation unit 104;

[0101] The operation unit 104 is used to perform a vector outer product operation on the data participating in the vector outer product operation.

[0102] In a possible embodiment, when the vector outer product instruction is a first vector outer product instruction, the operation code is used to indicate the first vector outer product operation, and the operation domain includes: the index representation of the sparse vector X12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector X12, the first address of the index of the sparse vector X12, the first address of the element in the vector Y1, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the control unit 103 is specifically used to:

[0103] The matrix A1 is obtained from the memory according to the first address of the matrix A1, the storage format of the matrix A1 and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector X12 is obtained from the memory according to the first address of the element in the sparse vector X12; the index of the sparse vector X12 is obtained from the memory 101 according to the first address of the index of the sparse vector X12; the vector Y1 is obtained from the memory 101 according to the first address of the element in the vector Y1; the elements in the vector Y1 are screened according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y12 of the vector Y1; the tenth scalar is obtained from the memory 101 according to the first address of the tenth scalar; the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar are transmitted to the operation unit 104;

[0104] The computing unit 104 is specifically used for:

[0105] A first vector outer product operation is performed on the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar.

[0106] Specifically, the first vector outer product instruction is used to calculate the outer product (i.e., tensor product) of one or two vectors. The first vector outer product instruction can be expressed as: SGER1 (I_TYPE12, LAYOUT1, R1, R2, C10, ValX12, InX12, y1, D1, LDA1), wherein the operation code of the vector outer product instruction is SGER1, which is used to indicate the vector outer product operation; the operation domain of the vector outer product instruction includes: I_TYPE12, LAYOUT1, R1, R2, C10, ValX12, InX12, y1, D1 and LDA1, and the corresponding meanings are described in Table 1 below.

[0107]

[0108] Table 1

[0109] After obtaining the vector outer product instruction, the control unit 103 parses the vector outer product instruction to obtain the operation domain and operation code of the vector outer product instruction. The control unit 103 obtains R1*R2 elements from the memory 101 according to the first address D1 of the matrix A1, the storage format of the matrix A1 and the low-dimensional length LDA1 of the matrix A1.

[0110] When the storage format of the above-mentioned matrix A1 is row-major order, the low-dimensional length of the above-mentioned matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the above-mentioned matrix A1 is column-major order, the low-dimensional length of the above-mentioned matrix A1 is the first address interval between two adjacent column vectors.

[0111] The control unit 103 obtains the sparse vector X12 from the memory 101 according to the first address of the element in the sparse vector X12; obtains the index of the sparse vector X12 from the memory 101 according to the first address of the index of the sparse vector X12; obtains the vector Y1 from the memory 101 according to the first address of the element in the vector Y1; and filters the elements in the vector Y1 according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y12.

[0112] It should be pointed out that a sparse vector is a vector composed of elements that meet preset conditions selected from a dense vector corresponding to the sparse vector; or in other words, the elements in the above dense vector that do not meet the preset conditions are removed and do not participate in subsequent operations.

[0113] Since the operation between the two vectors is an operation between the elements in the same position in the two vectors, it is necessary to filter the elements in the above-mentioned vector Y1 through the index representation of the above-mentioned sparse vector X12 and the index of the sparse vector X12, and obtain the elements in the above-mentioned vector Y1 whose positions are the same as the elements in the above-mentioned sparse vector X12 in their corresponding dense vectors to obtain the sparse vector Y12.

[0114] It should be noted here that the above-mentioned sparse vector X12 and vector Y1 are stored in the above-mentioned memory 101 according to the default length. Therefore, the above-mentioned control unit 103 can obtain the above-mentioned sparse vector X12 and vector Y1 respectively from the above-mentioned memory 101 only according to the first address of the elements in the above-mentioned sparse vector X12 and the first address of the elements in the vector Y1.

[0115] The control unit 103 filters the elements in the vector Y1 according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y12, including:

[0116] When the index representation of the sparse vector X12 is a direct index representation, the index of the sparse vector X12 is a string composed of 0 and 1, 0 indicates that the element in the dense vector corresponding to the sparse vector X12 does not meet the preset conditions, and 1 indicates that the element in the dense vector corresponding to the sparse vector X12 meets the preset conditions. For example, if the index is "101101", it means that each of the 1st element, 3rd element, 4th element and 6th element in the dense vector corresponding to the sparse vector X12 meets the preset conditions, and the 2nd element and the 5th element do not meet the preset conditions, and the elements that do not meet the preset conditions do not participate in subsequent operations. The control unit 103 selects the 1st element, the 3rd element, the 4th element and the 6th element from the vector Y1 according to the index "101101" to obtain the sparse vector Y12. For example, if the vector Y1=(2, 3, 5, 2.3, 4, 1.4), then the sparse vector Y12=(2, 5, 2.3, 1.4) obtained after filtering according to the above index "101101" is obtained.

[0117] When the index representation of the sparse vector X12 is a step index representation, the index of the sparse vector X12 is a character string consisting of the distance values ​​between the element in the dense vector corresponding to the sparse vector X12 that satisfies the preset condition and the last element that satisfies the preset condition. For example, the index of the sparse vector X12 is "0212", which means that each of the first element, the third element, the fourth element and the sixth element in the dense vector corresponding to the sparse vector X12 satisfies the preset condition, and the other elements do not satisfy the preset condition. The control unit 103 selects the first element, the third element, the fourth element and the sixth element from the vector Y1 according to the index "0212" to obtain the sparse vector Y12. For example, if the vector Y1 = (2, 3, 7, 2.3, 4, 1.4), the sparse vector Y12 obtained after screening according to the index "0212" = (2, 7, 2.3, 1.4).

[0118] The control unit 103 obtains the tenth scalar c10 from the controller 101 according to the first address C10 of the tenth scalar, and transmits the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar c10 to the operation unit 104.

[0119] The operation unit 104 performs a vector outer product operation on the sparse vector X12, the sparse vector Y12, the tenth scalar c10 and the matrix A1 according to the following formula (1).

[0120] A1:=c10*X12*Y12 T +A1 (1)

[0121] It should be noted that the above-mentioned operation unit 104 is based on the formula c10*X12*Y12 T The calculated result is matrix A', and the form of the matrix A' is consistent with the form of the above matrix A1. The result of adding the i-th element in the matrix A' and the i-th element in the above matrix A1 is stored in the storage space corresponding to the first address of the i-th element of the matrix A1.

[0122] Further, the operation domain also includes: the number of elements in the sparse vector X12, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1;

[0123] The control unit 103 obtains the sparse vector X12 from the memory 101 according to the first address of the element in the sparse vector X12, including:

[0124] Obtaining the sparse vector X12 from the memory 101 according to the first address of the element in the sparse vector X12 and the number of elements in the sparse vector X12;

[0125] The control unit 103 obtains the vector Y1 from the memory 101 according to the first address of the element in the vector Y1, including:

[0126] The vector Y1 is obtained from the memory 101 according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1.

[0127] Specifically, the above-mentioned first vector outer product instruction can also be expressed as: SGER1 (D_TYPE12, I_TYPE12, LAYOUT1, R1, R2, C10, Nnz12, ValX12, InX12, M5, y1, INCY1, D1, LDA1), wherein the operation code of the vector outer product instruction is SGER1, which is used to indicate a vector outer product operation; the operation domain of the vector outer product instruction includes: D_TYPE12, I_TYPE12, LAYOUT1, R1, R2, C10, Nnz12, ValX12, InX12, M5, y1, INCY1, D1 and LDA1, and the corresponding meanings are described in Table 2 below.

[0128]

[0129] Table 2

[0130] It should be noted that the above operation field D_TYPE12 represents the type of data involved in the above vector outer product operation.

[0131] The control unit 103 obtains the sparse vector X12 from the memory 101 according to the first address of the elements in the sparse vector X12 and the number of elements in the sparse vector X12; and obtains the vector Y1 from the memory according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1. After obtaining the sparse vector X12 and the vector Y1, the control unit 103 performs subsequent processing on the sparse vectors X12 and Y1 according to the relevant description of Table 1, which will not be described here.

[0132] In a possible embodiment, when the vector outer product instruction is a second vector outer product instruction, the operation code is used to indicate the second vector outer product operation, and the operation domain includes: the index representation of the sparse vector sX12, the storage format of the matrix, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector sX12, the first address of the index of the sparse vector sX12, the first address of the element in the sparse vector sY12, the first address of the index of the sparse vector sY12, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the control unit 103 is specifically used to:

[0133] The matrix A1 is obtained from the memory 101 according to the first address of the matrix A1, the storage format of the matrix and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector sX12 and the sparse vector sY12 are respectively obtained from the memory 101 according to the first address of the elements in the sparse vector sX12 and the first address of the elements in the sparse vector sY12; the index and the index of the sparse vector sX12 are respectively obtained from the memory 101 according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12 The index of the sparse vector sY12; obtaining a first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12; filtering the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; obtaining the tenth scalar from the memory 101 according to the first address of the tenth scalar; transmitting the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12 and the tenth scalar to the operation unit 104;

[0134] The computing unit 104 is specifically used for:

[0135] A second vector outer product operation is performed on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12, and the tenth scalar.

[0136] Specifically, the second vector outer product instruction can be expressed as: SGER2 (I_TYPEsX12, LAYOUT1, R1, R2, C10, ValsX12, InsX12, ValsY12, InsY12, D1, LDA1), wherein the operation code of the vector outer product instruction is SGER2, which is used to indicate a vector outer product operation; the operation domain of the vector outer product instruction includes: I_TYPE12, LAYOUT1, R1, R2, C10, ValsX12, InsX12, ValsY12, InsY12, D1 and LDA1, and the corresponding meanings are described in Table 3 below.

[0137]

[0138] Table 3

[0139] The control unit 103 obtains R1*R2 elements from the memory 101 according to the first address D1 of the matrix A1, the storage format of the matrix A1 and the low-dimensional length LDA1 of the matrix A1. When the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors.

[0140] The control unit 103 obtains the sparse vector sX12 and the sparse vector sY12 from the memory according to the first address of the elements in the sparse vector sX12 and the first address of the elements in the sparse vector sY12 respectively; obtains the index of the sparse vector sX12 and the index of the sparse vector sY12 from the memory 101 according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12.

[0141] It should be noted here that the above-mentioned sparse vector sX12 and sparse vector sY12 are stored in the above-mentioned memory 101 according to the default length. Therefore, the above-mentioned control unit 103 can obtain the above-mentioned sparse vector sX12 and sparse vector sY12 from the above-mentioned memory 101 respectively only according to the first address of the elements in the above-mentioned sparse vector sX12 and the first address of the elements in the sparse vector sY12.

[0142] The control unit 103 obtains the first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12, including:

[0143] When the index representation of the sparse vector sX12 is a direct index representation, the index of the sparse vector sX12 and the index of the sparse vector sY12 are both strings composed of 0 and 1. The specific meanings of 0 and 1 can be found in the above description of Table 1, which will not be described here. The control unit 103 performs an AND operation on the index of the sparse vector sX12 and the index of the sparse vector sY12 to obtain the first intermediate index. Then the control unit 103 filters the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sX12 and the filtered sparse vector sY12.

[0144] For example, the above-mentioned sparse vector sX12=(2,5,1,3), and the index of the sparse vector sX12 is "101101"; the above-mentioned sparse vector sY12=(1.2,8,5), and the index of the sparse vector sY12 is "110100", then the above-mentioned first intermediate index is "100100", and the above-mentioned control unit 103 filters the elements in the above-mentioned sparse vector sX12 and the sparse vector sY12 according to the above-mentioned first intermediate index "100100", and the obtained filtered sparse vector sX12=(2,1), and the obtained filtered sparse vector sY12=(1.2,5).

[0145] When the index representation of the above-mentioned sparse vector sX12 is a step index representation, the index of the above-mentioned sparse vector sX12 and the index of the sparse vector sY12 are both strings composed of the distance values ​​between the elements in the corresponding dense vectors that meet the above-mentioned preset conditions and the previous elements that meet the above-mentioned preset conditions, and the strings representing the index of the above-mentioned sparse vector sX12 and the index of the sparse vector sY12 are stored in order from low to high according to the physical address.

[0146] The control unit 103 accumulates each element in the index of the sparse vector sX12 and the element whose physical address is lower than the physical address where the element is stored, and the results constitute the first string; similarly, the index of the sparse vector sY12 is processed in the same way to obtain the second string; the same elements are selected from the first string and the second string, and are sorted in ascending order of element value to obtain the third string; each element in the third string is subtracted from the element adjacent to it and whose value is smaller than the element value, and the obtained elements constitute the first intermediate index.

[0147] For example, the index of the sparse vector sX12 is "01111", the index of the sparse vector sY12 is "022", and the control unit 103 adds each element in the index of the sparse vector sX12 to its adjacent previous element to obtain the first character string "01234"; similarly, the control unit 103 performs the same processing on the index of the sparse vector sY12 to obtain the second character string "024". The control unit 103 selects the same elements from the first character string "01234" and the second character string "024" to obtain the third character string "024". The control unit 103 subtracts each element in the third character string from its adjacent previous element, i.e., 0, (2-0), (4-2), to obtain the first intermediate index "022". Then the control unit 103 filters the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sX12 and the filtered sparse vector sY12. Then the control unit 103 obtains the tenth scalar c10 from the controller 101 according to the first address C10 of the tenth scalar, and transmits the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12 and the tenth scalar c10 to the operation unit 104.

[0148] The operation unit 104 performs a vector outer product operation on the above-mentioned filtered sparse vector sX12 and the filtered sparse vector sY12, the tenth scalar c10 and the matrix A1 according to the following formula (2).

[0149] A1:=c10*sX12*sY12 T +A1 (2)

[0150] It should be noted that the above-mentioned operation unit 104 is based on the formula c10*sX12*sY12 T The calculated result is matrix A', and the form of the matrix A' is consistent with the form of the above matrix A1. The result of adding the i-th element in the matrix A' and the i-th element in the above matrix A1 is stored in the storage space corresponding to the first address of the i-th element of the matrix A1.

[0151] Furthermore, the operation domain also includes an index representation of the sparse vector sY12; and the control unit is further used for:

[0152] After obtaining the sparse vector sX12 and its index and the sparse vector sY12 and its index, obtaining a second intermediate index according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12;

[0153] The elements in the sparse vector sX12 and the sparse vector sY12 are filtered according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; and the filtered sparse vector sX12 and the filtered sparse vector sY12 are transmitted to the operation unit 104.

[0154] Specifically, the second vector outer product instruction can also be expressed as: SGER2(I_TYPEsX12, I_TYPEsY12,

[0155] LAYOUT1,R1,R2,C10,ValsX12,InsX12,ValsY12,InsY12,D1,LDA1), wherein the operation code of the second vector outer product instruction is SGER2, which is used to indicate the vector outer product operation; the operation domain of the second vector outer product instruction includes: I_TYPEsX12,I_TYPEsY12,LAYOUT1,R1,R2,C10,ValsX12,InsX12,ValsY12,

[0156] InsY12, D1 and LDA1, their corresponding meanings are described in Table 4 below.

[0157]

[0158] Table 4

[0159] The control unit 103 obtains R1*R2 elements from the memory 101 according to the first address D1 of the matrix A1, the storage format of the matrix A1 and the low-dimensional length LDA1 of the matrix A1. When the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors.

[0160] After the control unit 103 obtains the index of the sparse vector sX12 and the index of the sparse vector sY12 from the memory 101 according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12, respectively, the second intermediate index is obtained according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12, including:

[0161] When the index representation of the sparse vector sX12 and the index representation of the sparse vector sY12 are both direct index representations, the control unit 103 performs an AND operation on the index of the sparse vector sX12 and the index of the sparse vector sY12 to obtain the second intermediate index;

[0162] When the index representation of the sparse vector sX12 and the index representation of the sparse vector sY12 are both step index representation, the control unit 103 accumulates each element in the index of the sparse vector sX12 and the element whose storage physical address is lower than the physical address where the element is stored, and the result constitutes the first string; similarly, the index of the sparse vector sY12 is processed in the same way to obtain the second string; the same elements are selected from the first string and the second string, and are sorted in ascending order of element value to obtain the third string; each element in the third string is subtracted from the element adjacent to the element whose value is smaller than the element value, and the obtained elements constitute the second intermediate index;

[0163] When one of the index representation modes of the sparse vector sX12 and the index representation mode of the sparse vector sY12 is a direct index representation mode and the other is a step index representation mode, the control unit 103 converts the index of the sparse vector sX12 and the index of the sparse vector sY12 represented by the step index representation mode into an index represented by the direct index representation mode, and then performs an AND operation on the index and the index of the sparse vector sX12 and the index of the sparse vector sY1 represented by the direct index representation mode to obtain the second intermediate index, or;

[0164] The control unit 103 converts the index of the sparse vector sX12 and the index of the sparse vector sY12 represented by direct index representation into an index represented by step index representation, and then processes the index and the index of the sparse vector sX12 and the index of the sparse vector sY12 represented by step index representation according to the method to obtain the second intermediate index.

[0165] Then the control unit 103 filters the elements in the sparse vector sX12 and the sparse vector sY12 according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; then the control unit 103 obtains the tenth scalar c10 from the controller 101 according to the first address C10 of the tenth scalar, and transmits the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12 and the tenth scalar c10 to the operation unit 104. The specific process of the operation unit 104 performing the vector outer product conversion operation on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12 and the tenth scalar c10 can be referred to the above description of Table 3, which will not be described here.

[0166] Further, the operation domain also includes: the number of elements in the sparse vector sX12 and the number of elements in the sparse vector sY12;

[0167] The control unit obtains the sparse vector sX12 and the sparse vector sY12 from the memory according to the first address of the element in the sparse vector sX12 and the first address of the element in the sparse vector sY12, respectively, including:

[0168] Obtaining the sparse vector sX12 from the memory according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12;

[0169] The sparse vector sY12 is obtained from the memory according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12.

[0170] Optionally, the second vector outer product instruction can also be expressed as: SGER2 (D_TYPE12, I_TYPEsX12, LAYOUT1, R1, R2, C10, Nnz12, ValsX12, InsX12, Mnz12, ValsY12, InsY12, D1, LDA1), wherein the operation code of the vector outer product instruction is SGER2, which is used to indicate a vector outer product operation; the operation domain of the vector outer product instruction includes: D_TYPE12, I_TYPEsX12, LAYOUT1, R1, R2, C10, Nnz12, ValsX12, InsX12, Mnz12, ValsY12, InsY12, D1 and LDA1, and the corresponding meanings are described in Table 5 below.

[0171]

[0172] Table 5

[0173] It should be noted that the operation field D_TYPE12 in the above Table 5 represents the type of data involved in the above vector outer product operation.

[0174] The control unit 103 obtains the sparse vector sX12 from the memory 101 according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12; and obtains the sparse vector sY12 from the memory 101 according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12. After obtaining the sparse vector sX12 and the sparse vector sY12, the control unit 103 performs subsequent processing and calculation on the sparse vector sX12 and the sparse vector sY12 according to the relevant description of Table 3, which will not be described here.

[0175] Optionally, the second vector outer product instruction can also be expressed as: SGER2(D_TYPE12, I_TYPEsX12, I_TYPEsY12, LAYOUT1, R1, R2, C10, Nnz12, ValsX12, InsX12, Mnz12, ValsY12, InsY12, D1, LDA1), wherein the operation code of the vector outer product instruction is SGER2, which is used to indicate the second vector outer product operation; the operation domain of the vector outer product instruction includes: D_TYPE12, I_TYPEsX12, I_TYPEsY12, LAYOUT1, R1, R2, C10, Nnz12, ValsX12, InsX12, Mnz12, ValsY12, InsY12, D1 and LDA1, and the corresponding meanings are described in Table 6 below.

[0176]

[0177]

[0178] Table 6

[0179] It should be noted that the operation field D_TYPE12 in the above Table 6 represents the type of data involved in the above vector outer product operation.

[0180] The control unit 103 obtains the sparse vector sX12 from the memory 101 according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12; and obtains the sparse vector sY12 from the memory 101 according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12. After obtaining the sparse vector sX12 and the sparse vector sY12, the control unit 103 performs subsequent processing and calculation on the sparse vector sX12 and the sparse vector sY12 according to the relevant description of Table 4, which will not be described here.

[0181] In the instruction formats shown in Tables 1 to 6 above, the tenth scalar c10 scales the result matrix, which increases the flexibility of the instructions and avoids the extra overhead of scaling using scaling instructions. The scale of vectors and matrices is variable, which can reduce the number of instructions and simplify the use of instructions. It can process matrices of different storage formats (row-major and column-major), avoid the overhead of transforming the matrix, and support vector formats stored at certain intervals, avoiding the execution overhead of transforming the vector format and the space occupied by storing intermediate results, and supports multiple sparse vector index representation methods, with higher compatibility. It helps to expand the scope of application of its instructions.

[0182] In a possible implementation, when the index representation of the input data is a direct index representation, the index of the input data is a string consisting of 0 and 1, 0 indicates that the element in the input data does not meet the preset condition, and 1 indicates that the element in the input data meets the preset condition, or;

[0183] When the index representation of the input data is a step index representation, the index of the input data is a character string consisting of the distance value between the element in the input data that meets the preset condition and the previous element that meets the preset condition;

[0184] Among them, the above-mentioned preset conditions are: the absolute value of the elements in the above-mentioned input data is greater than (>) or less than or equal to (≤) the preset threshold, and the above-mentioned input data may be the above-mentioned sparse vector X12, sparse vector sX12 or sparse vector sY12.

[0185] For example, assuming that the above input data is a vector (3, 0, 6, 4, 0.1, 0.9), the preset threshold is 0.5. Since the absolute values ​​of element 0 and element 0.1 in the vector are both less than the preset threshold, the index of the input data represented by direct index representation is 101101.

[0186] For example, assuming that the above input data is a vector (3, 0, 6, 4, 0.1, 0.9), the preset threshold is 0.5. Since the absolute values ​​of element 0 and element 0.1 in the vector are both less than the above preset threshold, the index of the input data represented by the step index representation is 0212.

[0187] Optionally, the index of the input data may be represented in a coordinate list (COO) representation or a compressed sparse row (CSR) representation.

[0188] Specifically, the above-mentioned input data is sparse data, and the input data is represented in matrix form. When the index of the above-mentioned input data is represented in COO form, the index of the input data is composed of at least one tuple, and the tuple includes the row number, column number and value of the element whose absolute value is greater than the preset threshold in the input data matrix.

[0189] For example, assuming the above input data is The above preset threshold is 0.5, so the index of the input data represented by COO is ((1,1,2), (1,2,3.5), (2,2,8), (3,1,5.8), (3,2,6)).

[0190] Specifically, the above-mentioned input data is sparse data, and the input data is represented in matrix form. When the index representation of the above-mentioned input data is CSR representation, the index of the input data includes three arrays, namely a first array, a second array and a third array. The first array stores the values ​​of elements in the above-mentioned input data matrix whose absolute values ​​are greater than a preset threshold, the above-mentioned second array stores the column indexes of the elements in the input data matrix whose absolute values ​​are greater than the preset threshold in the input data matrix, and the above-mentioned third array is used to cumulatively store the number of elements in each row of the above-mentioned input data matrix whose absolute values ​​are greater than the preset threshold, and the last element in the third array stores the number of elements in the above-mentioned input data matrix whose absolute values ​​are greater than the preset threshold.

[0191] The CSR representation method compresses and stores the information of the rows of the above input data matrix, and only explicitly retains the position of the first element in each row whose absolute value is greater than the above preset threshold. The index of the above input data is represented by three arrays:

[0192] The first array stores the values ​​of all elements in the input data matrix whose absolute values ​​are greater than the preset threshold, and the elements are arranged in a row traversal manner from left to right and from top to bottom. The first array is denoted as A. The length of the first array is the number of elements in the input data matrix whose absolute values ​​are greater than the preset threshold;

[0193] The second array stores the column index (ie, column number) of each element in the first array A in the input data matrix, so the length of the second array is the same as that of array A. This array is denoted as JA.

[0194] The third array is denoted as IA, and the length of the array IA is the number of rows of the input data matrix plus 1. The elements in the array IA are accumulated to store the number of elements in each row of the input data matrix whose absolute value is greater than the preset threshold, which can be obtained by the following recursive method, and the number of elements in the entire input data matrix whose absolute value is greater than the preset threshold is saved in the last element of the array IA.

[0195] If the sequence numbers of the above three arrays and the sequence number of the input data matrix start from 0, the array IA can be defined recursively as follows:

[0196] IA[0]=0

[0197] IA[i]=IA[i-1]+the number of elements whose absolute values ​​in the i-1th row of the input data matrix are greater than the above preset threshold (i>0). For example, assuming that the above input data is The above preset threshold is 0.5, and CSR is used to represent the

[0198] The formula represents the index of the input data: Since the first array A stores the values ​​of all elements in the matrix whose absolute values ​​are greater than 0.5, the order of the elements is arranged in a row traversal manner from left to right and from top to bottom, so the first array A = [5, 8, 3, 6]; the second array JA stores the column index (i.e., column number) of each element in the array A in the matrix, then the array JA = [0, 1, 2, 1]. The i-th element in the third array IA is the sum of the i-1-th element in the third array I and the number of elements in the i-1-th row in the matrix whose absolute values ​​are greater than 0.5, i = 1, 2, 3, 4, 5, and the array IA = [0, 0, 2, 3, 4] is determined according to the above recursive method.

[0199] Furthermore, the control unit 103 may convert the sparse vector index or the row index or column index of the sparse matrix according to a conversion instruction, which includes a first conversion instruction, a second conversion instruction, and a third conversion instruction.

[0200] The first conversion instruction is used to convert an index represented by a direct index representation to an index represented by a step index representation. Specifically, the first conversion instruction is: DIRECT2STTP (InX, InY). The operation code of the first conversion instruction is DIRECT2STTP, and the operation domain includes: InX and InY. The functional description of each operation domain in the instruction is shown in Table 7 below.

[0201] variable Functional Description InX The first address of the direct index of the data to be converted InY The first address of the step index of the converted data

[0202] Table 7

[0203] After parsing the first conversion instruction, the control unit 103 obtains the operation code and operation domain of the instruction; obtains the direct index of the data to be converted from the memory 101 according to the first address of the direct index of the data to be converted; then converts the direct index of the data to be converted into a step index, and then stores the step index in the storage space corresponding to the first address of the step index of the converted data.

[0204] For example, if the direct index above is "100101", the corresponding step index is "032".

[0205] Specifically, the first conversion instruction may also be: DIRECT2STTP (D_TYPE, Nnz, InX, ValX, InY, ValY). The operation code of the first conversion instruction is DIRECT2STTP, and the operation fields include: D_TYPE, Nnz, InX, ValX, InY and ValY. The functional description of each operation field in the instruction is shown in Table 8 below.

[0206] Operational Domain Functional Description D_TYPE The data type to be operated on supports real and complex numbers NZ The number of elements in the data to be converted InX The first address of the direct index of the data to be converted ValX The first address of the element in the data to be converted InY The first address of the step index of the converted data VY The first address of the element in the converted data

[0207] Table 8

[0208] It should be noted that D_TYPE in the above Table 8 is used to represent the type of data to be indexed.

[0209] After parsing the first conversion instruction, the control unit 103 obtains the operation code and operation domain of the instruction; obtains the direct index of the data to be converted from the memory 101 according to the first address of the direct index of the data to be converted; obtains the data to be converted from the memory 101 according to the number of elements in the data to be converted and the first address of the data to be converted.

[0210] The control unit 103 converts the direct index of the data to be converted into a step index; screens the elements in the data to be converted according to the step index to obtain the converted data, and stores the converted data in the storage space corresponding to the first address of the element in the converted data; stores the step index in the storage space corresponding to the first address of the step index of the converted data.

[0211] For example, the data to be converted is a vector Mx1 = (3, 7, 5, 9, 0.4, 2.3), and the direct index of the data to be converted is "101101". The control unit 103 converts the direct index into a step index of "0212", and filters the elements in the vector Mx1 according to the step index "0212" to obtain the converted data as a vector (3, 5, 9, 2.3).

[0212] The second conversion instruction is used to convert the index of the matrix represented by the COO index representation into the index represented by the step index representation. Specifically, the second conversion instruction is: COO2STTP (D_TYPE, LAYOUT, Nnz, InXi, InYi, ValX, InY, ValY). The operation code of the second conversion instruction is: COO2STTP, and the operation domain includes: D_TYPE, LAYOUT, Nnz, InXi, InYi, ValX, InY and ValY. The functional description of each operation domain in the instruction is shown in Table 9 below.

[0213] Operational Domain Functional Description D_TYPE The data type to be operated on supports real and complex numbers LAYOUT Indicates the matrix storage format (including row-major or column-major) NZ The number of data whose absolute value is greater than the preset threshold in the data to be converted InXi The first address of the row coordinates of the data to be converted Yj Y The first address of the column coordinates of the data to be converted ValX The first address of the element in the data to be converted InY The first address of the step index of the converted data VY The first address of the element in the converted data

[0214] Table 9

[0215] It should be noted that D_TYPE in the above Table 9 is used to represent the type of data to be indexed.

[0216] The third conversion instruction is used to convert the index of the matrix represented by the CSR index representation to the index represented by the step index representation. Specifically, the third conversion instruction is: CSR2STTP (D_TYPE, Nnz, InXr, InYc, ValX, InY, ValY). The operation code of the second conversion instruction is: COO2STTP, and the operation domain includes: D_TYPE, Nnz, InXr, InYc, ValX, InY and ValY. The functional description of each operation domain in the instruction is shown in Table 10 below.

[0217] variable Functional Description D_TYPE The data type to be operated on supports real and complex numbers NZ The number of data whose absolute value is greater than the preset threshold in the data to be converted iX The first address of the row index of the data to be converted iY The first address of the column index of the data to be converted ValX The first address of the element in the data to be converted InY The first address of the step index of the converted data VY The first address of the element in the converted data

[0218] Table 10

[0219] It should be noted that D_TYPE in the above Table 10 is used to represent the type of data to be indexed.

[0220] Optionally, the computing unit 104 executing the instruction to perform computing operations on the input data may include: directly computing the sparse input data, or processing another data to be computed according to the index of the sparse input data before computing, etc.

[0221] Specifically, when the input data of the vector outer product instruction includes a scalar and a vector / matrix, that is, the vector outer product instruction is used to perform operations between scalars and vectors / matrices, the above-mentioned operation unit 104 directly operates on the scalar and the vector / matrix; when the vector outer product instruction is an instruction for operating on at least two vectors / matrices, and at least one of the at least two vectors / matrices is a sparse vector / matrix, the above-mentioned operation unit 104 performs data screening on the non-sparse matrix / vector according to the index of the sparse matrix / vector before performing the operation; when the representation method of the index of the sparse vector / matrix is ​​not the representation method of the index corresponding to the hardware operation part (that is, the representation method of the index of the sparse vector / matrix is ​​not the default index representation method), the above-mentioned operation unit 104 converts the index of the sparse vector / matrix represented by the non-default index representation method into an index represented by the default index representation method, and then performs the corresponding operation operation.

[0222] For example, for a scalar and a sparse matrix, such as F=αA, where α is a scalar and A is a sparse matrix, the operation unit 104 can directly operate on the elements of the sparse data A. For another example, F=AB, where A is a sparse matrix and B is a dense matrix, the operation unit 104 screens the elements of the dense matrix B according to the index of the sparse matrix A to screen out the elements to be operated with the sparse matrix A, and then perform subsequent operations.

[0223] In a feasible embodiment, the memory 101 is a high-speed temporary storage memory.

[0224] In a possible embodiment, Figure 2 As shown, the control unit 103 includes:

[0225] An instruction storage unit 1031, used for storing the vector outer product instruction;

[0226] An instruction processing unit 1032, configured to parse the vector outer product instruction to obtain the operation code and operation domain;

[0227] The storage queue unit 1033 is used to store an instruction queue, which includes: a plurality of vector outer product instructions to be executed in the order of the queue.

[0228] In a possible embodiment, Figure 3 As shown, the operation unit 104 includes: a vector addition circuit 1041, a vector multiplication circuit 1042, a size comparison circuit 1043, a nonlinear operation circuit 1044 and a vector scalar multiplication circuit 1045. The circuit unit inside the operation unit 104 can be a multi-pipeline structure, specifically as follows Figure 4 As shown, the circuit units inside the operation unit 104 can be divided into three pipeline stages.

[0229] The first pipeline stage includes but is not limited to: vector multiplication circuit 1042 and vector scalar multiplication circuit 1045, etc.; the second pipeline stage includes but is not limited to: size comparison circuit 1043 (such as a comparator) and vector addition circuit 1041, etc.; the third pipeline stage includes but is not limited to: nonlinear operation circuit 1044 (such as an activation circuit or a transcendental function calculation circuit, etc.), etc. The output data of the first pipeline stage is the input data of the second pipeline stage, and the output data of the second pipeline stage is the input data of the third pipeline stage.

[0230] In a feasible embodiment, the above-mentioned operation unit 104 may include but is not limited to three parts, namely a multiplier, one or more adders (optionally, multiple adders form an addition tree) and an activation function unit / activation function operator. The above-mentioned multiplier multiplies the first input data (in1) and the second input data (in2) to obtain the first output data (out1), and the process is: out1 = in1*in2; the above-mentioned addition tree adds the third input data (in3) step by step through the addition tree to obtain the second output data (out2), where in3 is a vector with a length of N, N is greater than 1, and is called: out2 = in3[1]+in3[2]+...+in3[N], and / or the result obtained by accumulating the third input data (in3) through the addition tree and the fourth input data (in4) are added to obtain the second output data (out2), and the process is: out2 = in3[1]+in3[2]+...+in3[N]+ in4, or the third input data (in3) and the fourth input data (in4) are added to obtain the second output data (out2), which is called: out2=in3+in4; the above-mentioned activation function unit obtains the third output data (out3) by the activation function (active) on the fifth input data (in5), and the process is: out3=active(in5). The activation function active can be a function such as sigmoid, tanh, relu, softmax, etc. In addition to the activation operation, the activation function unit can realize other nonlinear function operations, and can obtain the output data (out) by the function (f) operation on the input data (in), and the process is: out=f(in).

[0231] The above-mentioned operation unit 104 may also include a pooling unit, which performs a pooling operation on the input data (in) to obtain output data (out) after the pooling operation. The process is out=pool(in), where pool is a pooling operation, and the pooling operation includes but is not limited to: average pooling, maximum pooling, median pooling, and the input data in is the data in a pooling core related to the output out.

[0232] In a feasible embodiment, the processing device 100 further includes:

[0233] A dependency processing unit 105 is used to determine whether the s-th vector outer product instruction has an association relationship with the s-1-th vector outer product instruction before the s-th vector outer product instruction. If the s-th vector outer product instruction has an association relationship with the s-1-th vector outer product instruction, cache the s-th vector outer product instruction in the instruction storage unit, and after the s-1-th vector outer product instruction is executed, extract the s-th vector outer product instruction from the instruction storage unit and transmit it to the operation unit;

[0234] The determining whether there is an association relationship between the s-th vector outer product instruction and the s-1-th vector outer product instruction before the s-th vector outer product instruction comprises:

[0235] The first storage address interval of the data required in the s-th vector outer product instruction is extracted based on the s-th vector outer product instruction, and the zeroth storage address interval of the data required in the s-1th vector outer product instruction is extracted based on the s-1th vector outer product instruction. If the first storage address interval and the zeroth storage address interval have an overlapping area, it is determined that the s-th vector outer product instruction has an associated relationship with the s-1th vector outer product instruction; if the first storage address interval and the zeroth storage address interval do not have an overlapping area, it is determined that the s-th vector outer product instruction has no associated relationship with the s-1th vector outer product instruction.

[0236] It should be noted that the vectors or matrices in the same instruction in any of the above tables can be of different data types, including floating point, fixed point, bit width, complex number, etc. In addition to transposition and complex number conjugation, the transformation in the instruction can also include other operations such as inverse matrix, and these transformations can be combined with each other. For vector operations, the operator can be replaced with other operation types, such as vector addition replaced by multiplication, division, etc., and MAX replaced by intermediate value, etc.

[0237] For Figure 1b The processing device shown calculates the specific structure of the vector outer product instruction when implementing the vector outer product instruction operation, that is, a combination of multiple calculation instructions is implemented through the execution of one vector outer product instruction. It should be noted that when the processing device executes the vector outer product instruction, the vector outer product instruction is not split into multiple calculation instructions.

[0238] It should be pointed out that when the above processing device is applied to the neural network operation, the matrix or vector mentioned in the embodiment of the present invention can be regarded as input neurons and output neurons, and the input neurons and output neurons do not refer to the neurons in the input layer and the neurons in the output layer of the entire neural network, but for any two adjacent layers of neurons in the neural network, the neurons in the lower layer of the network feedforward operation are input neurons, and the neurons in the upper layer of the network feedforward operation are output neurons. Taking a convolutional neural network as an example, assuming that a convolutional neural network has L layers, K = 1, 2, 3...L-1, for the Kth layer and the K+1th layer, the Kth layer is called the input layer, and the neurons in this layer are the above-mentioned input neurons, and the K+1th layer is called the input layer, and the neurons in this layer are the above-mentioned output neurons, that is, except for the top layer, each layer can be used as an input layer, and the next layer is the corresponding output layer.

[0239] Each unit in the above processing device can be a hardware circuit including a digital circuit, an analog circuit, etc. The physical implementation of the hardware circuit includes but is not limited to physical devices, and the physical devices include but are not limited to transistors, memristors, etc. The computing unit in the above processing device can be any appropriate hardware processor, such as CPU, GPU, FPGA, DSP and ASIC, etc. The above memory can be any appropriate magnetic storage medium or magneto-optical storage medium, such as RRAM, DRAM, SRAM, EDRAM, HBM, HMC, etc.

[0240] In a feasible embodiment, the present invention provides a computing device, which includes one or more Figure 1b The processing device described in the illustrated embodiment is used to obtain data to be calculated and control information from other processing devices, and to perform specified neural network operations, and to transmit the execution results to other processing devices through the I / O interface;

[0241] When the computing device includes a plurality of the processing devices, the plurality of the processing devices may be connected and transmit data through a specific structure;

[0242] Among them, multiple processing devices are interconnected and transmit data through a PCIE bus to support larger-scale operations; multiple processing devices share the same control system or have their own control systems; multiple processing devices share memory or have their own memory; the interconnection method of multiple processing devices is any interconnection topology.

[0243] The computing device has high compatibility and can be connected to various types of servers through a PCIE interface.

[0244] In a feasible embodiment, the embodiment of the present invention provides a combined processing device, which includes the above-mentioned computing device, a universal interconnection interface and other processing devices.

[0245] The computing device interacts with the other processing devices to jointly complete the operation specified by the user. Figure 5a , Figure 5a A schematic diagram of the structure of a combined processing device provided by an embodiment of the present invention. Figure 5a As shown, the combined processing device includes the above-mentioned computing device 501 , a universal interconnection interface 502 and other processing devices 503 .

[0246] Among them, the above-mentioned other processing devices 503 include one or more processor types of general / special processors such as central processing unit (Central Processing Unit), graphics processing unit (Graphics Processing Unit, GPU), processor, etc. There is no limit on the number of processors included in other processing devices 503. Other processing devices 503 serve as interfaces between the computing device 501 and external data and control, including data handling, and complete basic control of the computing device such as starting and stopping; other processing devices 503 can also cooperate with the computing device 501 to complete computing tasks together.

[0247] The universal interconnection interface 502 is used to transmit data and control instructions between the computing device 501 and other processing devices 503. The computing device 501 obtains the required input data from other processing devices 503 and writes it into the storage device on the computing device 501 chip; it can obtain control instructions from other processing devices 503 and write them into the control cache on the computing device 501 chip; it can also read the data in the storage module of the computing device 501 and transmit it to other processing devices 503.

[0248] Optional, such as Figure 5b As shown, the above-mentioned combined processing device also includes a storage device 504, which is used to store data required by this operation unit / operation device or other operation units, and is particularly suitable for data that cannot be fully stored in the internal storage of this operation device 501 or other processing devices 503.

[0249] The above-mentioned combined device can be used as a system-on-chip for smart devices such as mobile phones, robots, and drones, effectively reducing the core area of ​​the control part, increasing the processing speed, and reducing the overall power consumption.

[0250] In a feasible embodiment, the present invention provides a neural network chip, which includes: Figure 1b The processing device described in the illustrated embodiment, or the above-mentioned computing device or the above-mentioned combined processing device.

[0251] In a feasible embodiment, an embodiment of the present invention provides a neural network chip packaging structure, which includes the above-mentioned neural network chip.

[0252] In a feasible embodiment, an embodiment of the present invention provides a board card, which includes the above-mentioned neural network chip packaging structure. The board card can be used in many general or special computing system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, smart homes, home appliances, multi-processor systems, microprocessor-based systems, robots, programmable consumer electronic devices, network personal computers (personal computers, PCs), minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.

[0253] In one embodiment, the present disclosure discloses an electronic device, which includes the above-mentioned board or neural network chip packaging structure 11.

[0254] Electronic devices include data processing devices, robots, computers, printers, scanners, tablet computers, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, servers, cameras, camcorders, projectors, watches, headphones, mobile storage, wearable devices, vehicles, household appliances, and / or medical devices.

[0255] The transportation means include airplanes, ships and / or vehicles; the household appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, electric lights, gas stoves, and range hoods; the medical equipment includes magnetic resonance imaging, ultrasound machines and / or electrocardiographs.

[0256] See also Figure 6 , Figure 6 A flowchart of a computing method provided by an embodiment of the present invention is shown in FIG. Figure 6 As shown, the method includes:

[0257] S601. A processing device obtains a vector outer product instruction, and parses the vector outer product instruction to obtain an operation code and an operation domain of the vector outer product instruction.

[0258] S602: The processing device obtains data participating in the vector outer product operation according to the operation domain.

[0259] S603: The processing device performs a vector outer product operation on the data participating in the vector outer product operation.

[0260] In a possible embodiment, when the vector outer product instruction is a first vector outer product instruction, the operation code is used to indicate the first vector outer product operation, and the operation domain includes: the index representation of the sparse vector X12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector X12, the first address of the index of the sparse vector X12, the first address of the element in the vector Y1, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors;

[0261] The step of acquiring data participating in the vector outer product operation according to the operation domain includes:

[0262] The matrix A1 is obtained according to the first address of the matrix A1, the storage format of the matrix A1 and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector X12 is obtained according to the first address of the element in the sparse vector X12; the index of the sparse vector X12 is obtained according to the first address of the index of the sparse vector X12; the vector Y1 is obtained according to the first address of the element in the vector Y1; the elements in the vector Y1 are screened according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y12; the tenth scalar is obtained according to the first address of the tenth scalar;

[0263] The performing a vector outer product operation on the data participating in the vector outer product operation includes:

[0264] A first vector outer product operation is performed on the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar.

[0265] Further, the operation domain also includes: the number of elements in the sparse vector X12, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1;

[0266] The step of obtaining the sparse vector X12 according to the first address of the element in the sparse vector X12 comprises:

[0267] Obtain the sparse vector X12 according to the first address of the element in the sparse vector X12 and the number of elements in the sparse vector X12;

[0268] The obtaining the vector Y1 according to the first address of the element in the vector Y1 comprises:

[0269] The vector Y1 is obtained according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1.

[0270] In a possible embodiment, when the vector outer product instruction is a second vector outer product instruction, the operation code is used to indicate a second vector outer product operation, and the operation domain includes: the index representation of the sparse vector sX12, the storage format of the matrix, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector sX12, the first address of the index of the sparse vector sX12, the first address of the element in the sparse vector sY12, the first address of the index of the sparse vector sY12, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the obtaining of data participating in the vector outer product operation according to the operation domain includes:

[0271] The matrix A1 is obtained according to the first address of the matrix A1, the storage format of the matrix and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector sX12 and the sparse vector sY12 are obtained according to the first address of the element in the sparse vector sX12 and the first address of the element in the sparse vector sY12 respectively; the sparse vector sX12 and the sparse vector sY12 are obtained according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12 respectively. Respectively obtain the index of the sparse vector sX12 and the index of the sparse vector sY12; obtain a first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12; filter the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; obtain the tenth scalar according to the first address of the tenth scalar;

[0272] Performing a vector outer product operation on the data participating in the vector outer product operation includes:

[0273] A second vector outer product operation is performed on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12, and the tenth scalar.

[0274] Furthermore, the operation domain also includes an index representation of the sparse vector sY12; and the step of obtaining data participating in the vector outer product operation according to the operation domain also includes:

[0275] After obtaining the sparse vector sX12 and its index and the sparse vector sY12 and its index, obtaining a second intermediate index according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12;

[0276] The elements in the sparse vector sX12 and the sparse vector sY12 are filtered according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12.

[0277] Further, the operation domain also includes: the number of elements in the sparse vector sX12 and the number of elements in the sparse vector sY12;

[0278] The step of obtaining the sparse vector sX12 and the sparse vector sY12 according to the first addresses of the elements in the sparse vector sX12 and the first addresses of the elements in the sparse vector sY12 respectively comprises:

[0279] Obtain the sparse vector sX12 according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12;

[0280] The sparse vector sY12 is obtained according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12.

[0281] In a possible embodiment, the index representation of the input data is a direct index representation or a step index representation; the input data includes: the sparse vector X12, the sparse vector sX12 or the sparse vector sY12;

[0282] When the index representation of the input data is a direct index representation, the index of the input data is a string consisting of 0 and 1, 0 indicates that the element in the input data does not meet the preset condition, and 1 indicates that the element in the input data meets the preset condition, or;

[0283] When the index representation of the input data is a step index representation, the index of the input data is a character string consisting of the distance values ​​between the element in the input data that meets the preset condition and the previous element that meets the preset condition; wherein the preset condition is: the absolute value of the element in the input data is greater than or less than a preset threshold.

[0284] It should be noted that the specific description of the above method embodiment can be found in Figure 1b The relevant description of the illustrated embodiment will not be repeated here.

[0285] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described order of actions, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present invention.

[0286] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0287] In the several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be electrical or other forms.

[0288] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0289] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0290] The embodiments of the present invention are described in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A processing device for performing an operation according to a vector outer product instruction, characterized in that: The processing device comprises: a memory, an operation unit, a control unit and a register unit; The register unit is used to store a vector outer product instruction; the vector outer product instruction includes an operation code and an operation field, the operation code is used to instruct to perform a vector outer product operation; the operation field includes a first address of data participating in the vector outer product operation, an address of an index of part of the data or all of the data participating in the vector outer product operation, and an index representation method, the index representation method is used to instruct to filter the vectors in the data participating in the vector outer product operation; The memory is used to store data involved in the vector outer product operation, or indexes of part of the data involved in the vector outer product operation, or all of the data; The control unit is used to obtain the vector outer product instruction from the register unit, parse the vector outer product instruction to obtain the operation code and the operation domain; obtain the data participating in the vector outer product operation and the index of part of the data or all of the data participating in the vector outer product operation from the memory according to the operation domain, wherein the index is used to indicate the screening of elements in the vector; Screening the vectors in the data participating in the vector outer product operation according to the index and the index representation to obtain a sparse vector, and transmitting the data participating in the vector outer product operation including the sparse vector to the operation unit; The operation unit is used to perform a vector outer product operation on the data participating in the vector outer product operation; Wherein, when the vector outer product instruction is the first vector outer product instruction, the operation code is used to indicate the first vector outer product operation, and the operation domain includes: the index representation of the sparse vector X12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector X12, the first address of the index of the sparse vector X12, the first address of the element in the vector Y1, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; The control unit is specifically used for: Obtaining the matrix A1 from the memory according to the first address of the matrix A1, the storage format of the matrix A1 and the low-dimensional length of the matrix A1, wherein the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; Obtaining the sparse vector X12 from the memory according to the first address of the element in the sparse vector X12; Obtaining the index of the sparse vector X12 from the memory according to the first address of the index of the sparse vector X12; Obtaining the vector Y1 from the memory according to the first address of the element in the vector Y1; Filtering the elements in the vector Y1 according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain a sparse vector Y12; Retrieving the tenth scalar from the memory according to the first address of the tenth scalar; Transmitting the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar to the operation unit; The computing unit is specifically used for: A first vector outer product operation is performed on the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar.

2. The processing device according to claim 1, characterized in that The operation domain also includes: the number of elements in the sparse vector X12, the number of elements in the vector Y1, and the address interval between the elements in the vector Y1; The control unit obtains the sparse vector X12 from the memory according to the first address of the element in the sparse vector X12, including: Obtaining the sparse vector X12 from the memory according to the first address of the element in the sparse vector X12 and the number of elements in the sparse vector X12; The control unit obtains the vector Y1 from the memory according to the first address of the element in the vector Y1, including: The vector Y1 is obtained from the memory according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1.

3. The processing device according to claim 1, characterized in that When the vector outer product instruction is a second vector outer product instruction, the operation code is used to instruct to perform a second vector outer product operation, and the operation domain includes: the index representation of the sparse vector sX12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector sX12, the first address of the index of the sparse vector sX12, the first address of the element in the sparse vector sY12, the first address of the index of the sparse vector sY12, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the control unit is specifically used to: The matrix A1 is obtained from the memory according to the first address of the matrix A1, the storage format of the matrix and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector sX12 and the sparse vector sY12 are respectively obtained from the memory according to the first address of the elements in the sparse vector sX12 and the first address of the elements in the sparse vector sY12; the index of the sparse vector sX12 and the sparse vector sY12 are respectively obtained from the memory according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12 The index of the sparse vector sY12; obtaining a first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12; filtering the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; obtaining the tenth scalar from the memory according to the first address of the tenth scalar; transmitting the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12 and the tenth scalar to the operation unit; The computing unit is specifically used for: A second vector outer product operation is performed on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12, and the tenth scalar.

4. The processing device according to claim 3, characterized in that The operation domain also includes an index representation of the sparse vector sY12; the control unit is also used for: After obtaining the sparse vector sX12 and its index and the sparse vector sY12 and its index, obtaining a second intermediate index according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12; The elements in the sparse vector sX12 and the sparse vector sY12 are filtered according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; and the filtered sparse vector sX12 and the filtered sparse vector sY12 are transmitted to the operation unit.

5. The processing device according to claim 3 or 4, characterized in that: The operation domain also includes: the number of elements in the sparse vector sX12 and the number of elements in the sparse vector sY12; The control unit obtains the sparse vector sX12 and the sparse vector sY12 from the memory according to the first address of the element in the sparse vector sX12 and the first address of the element in the sparse vector sY12, respectively, including: Obtaining the sparse vector sX12 from the memory according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12; The sparse vector sY12 is obtained from the memory according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12.

6. The processing device according to any one of claims 1 to 4, characterized in that: The operation unit further includes a vector addition circuit, a vector multiplication circuit, a size comparison circuit, a nonlinear operation circuit and a vector scalar multiplication circuit; the operation unit is a multi-pipeline structure; Among them, the vector multiplication circuit and the vector scalar multiplication circuit are in the first pipeline stage, the size comparison circuit and the vector addition circuit are in the second pipeline stage, and the nonlinear operation component is in the third pipeline stage, wherein the output data of the first pipeline stage is the input data of the second pipeline stage, and the output data of the second pipeline stage is the input data of the third pipeline stage.

7. The processing device according to any one of claims 1 to 4, characterized in that: The control unit also includes: An instruction storage unit, used for storing the vector outer product instruction; An instruction processing unit, used for parsing the vector outer product instruction to obtain the operation code and operation domain; The storage queue unit is used to store an instruction queue, which includes: a plurality of vector outer product instructions to be executed in a front-to-back order of the queue.

8. The processing device according to claim 7, characterized in that The processing device also includes: a dependency processing unit, configured to determine whether an s-th vector outer product instruction has an association relationship with an s-1th vector outer product instruction before the s-th vector outer product instruction, and if the s-th vector outer product instruction has an association relationship with the s-1th vector outer product instruction, cache the s-th vector outer product instruction in the instruction storage unit, and extract the s-th vector outer product instruction from the instruction storage unit and transmit it to the operation unit after the s-1th vector outer product instruction is executed; The determining whether there is an association relationship between the s-th vector outer product instruction and the s-1-th vector outer product instruction before the s-th vector outer product instruction comprises: The first storage address interval of the data required in the s-th vector outer product instruction is extracted based on the s-th vector outer product instruction, and the zeroth storage address interval of the data required in the s-1th vector outer product instruction is extracted based on the s-1th vector outer product instruction. If the first storage address interval and the zeroth storage address interval have an overlapping area, it is determined that the s-th vector outer product instruction has an associated relationship with the s-1th vector outer product instruction; if the first storage address interval and the zeroth storage address interval do not have an overlapping area, it is determined that the s-th vector outer product instruction has no associated relationship with the s-1th vector outer product instruction.

9. The processing device according to any one of claims 2 to 4, characterized in that: The index representation of the input data includes: a direct index representation or a step index representation, wherein the input data includes a sparse vector X12, a sparse vector sX12 and a sparse vector sY12; When the index representation of the input data is a direct index representation, the index of the input data is a string consisting of 0 and 1, 0 indicates that the element in the input data does not meet the preset condition, and 1 indicates that the element in the input data meets the preset condition, or; When the index representation of the input data is a step index representation, the index of the input data is a character string consisting of the distance value between the element in the input data that meets the preset condition and the previous element that meets the preset condition; The preset condition is that the absolute value of the element in the input data is greater than or less than a preset threshold.

10. A computing device, characterized in that: The computing device comprises one or more processing devices according to any one of claims 1 to 9, which are used to obtain data to be computed and control information from other processing devices, and to perform specified operations, and to transmit the execution results to other processing devices through an I / O interface; When the computing device includes a plurality of processing devices, the plurality of processing devices may be connected and transmit data through a specific structure; Among them, multiple processing devices are interconnected and transmit data through a fast external device interconnect bus or a PCIE bus to support larger-scale neural network operations; multiple processing devices share the same control system or have their own control systems; multiple processing devices share memory or have their own memory; the interconnection method of multiple processing devices is any interconnection topology.

11. A combined processing device, characterized in that: The combined processing device comprises the computing device as claimed in claim 10, a universal interconnection interface and other processing devices; The computing device interacts with the other processing devices to jointly complete the operation specified by the user.

12. A neural network chip, characterized in that: The neural network chip includes the computing device as described in claim 10 or the combined processing device as described in claim 11.

13. An electronic device, characterized in that: The electronic device includes a neural network chip as described in claim 12.

14. A method for executing a vector outer product instruction, characterized in that: include: Obtaining a vector outer product instruction, and parsing the vector outer product instruction to obtain an operation code and an operation domain of the vector outer product instruction; the vector outer product instruction includes an operation code and an operation domain, the operation code is used to indicate to perform a vector outer product operation; the operation domain includes a first address of data participating in the vector outer product operation, an address and an index representation of an index of part or all of the data in the data participating in the vector outer product operation, and the index representation is used to indicate the screening of vectors in the data participating in the vector outer product operation; Acquire data participating in the vector outer product operation and indexes of part or all of the data in the data participating in the vector outer product operation according to the operation domain, wherein the indexes are used to indicate the screening of elements in the vector; Screening the vectors in the data participating in the vector outer product operation according to the index and the index representation to obtain a sparse vector, and transmitting the data participating in the vector outer product operation including the sparse vector to a computing unit; Performing a vector outer product operation on the data participating in the vector outer product operation; Wherein, when the vector outer product instruction is the first vector outer product instruction, the operation code is used to indicate the first vector outer product operation, and the operation domain includes: the index representation of the sparse vector X12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector X12, the first address of the index of the sparse vector X12, the first address of the element in the vector Y1, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major order, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; The step of screening the vectors in the data participating in the vector outer product operation according to the index and the index representation to obtain a sparse vector, and transmitting the data participating in the vector outer product operation including the sparse vector to the operation unit includes: Acquire the matrix A1 according to the first address of the matrix A1, the storage format of the matrix A1 and the low-dimensional length of the matrix A1, wherein the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; Obtain the sparse vector X12 according to the first address of the element in the sparse vector X12; Obtaining the index of the sparse vector X12 according to the first address of the index of the sparse vector X12; Obtain the vector Y1 according to the first address of the element in the vector Y1; filter the elements in the vector Y1 according to the index representation of the sparse vector X12 and the index of the sparse vector X12 to obtain the sparse vector Y12; Obtain the tenth scalar according to the first address of the tenth scalar; Transmitting the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar to the operation unit; The performing a vector outer product operation on the data participating in the vector outer product operation includes: A first vector outer product operation is performed on the matrix A1, the sparse vector X12, the sparse vector Y12 and the tenth scalar.

15. The method according to claim 14, characterized in that The operation domain also includes: the number of elements in the sparse vector X12, the number of elements in the vector Y1, and the address interval between the elements in the vector Y1; The step of obtaining the sparse vector X12 according to the first address of the element in the sparse vector X12 comprises: Obtain the sparse vector X12 according to the first address of the element in the sparse vector X12 and the number of elements in the sparse vector X12; The obtaining the vector Y1 according to the first address of the element in the vector Y1 comprises: The vector Y1 is obtained according to the first address of the elements in the vector Y1, the number of elements in the vector Y1 and the address interval between the elements in the vector Y1.

16. The method according to claim 14, characterized in that When the vector outer product instruction is a second vector outer product instruction, the operation code is used to instruct to perform a second vector outer product operation, and the operation domain includes: the index representation of the sparse vector sX12, the storage format of the matrix A1, the number of rows of the matrix A1, the number of columns of the matrix A1, the first address of the tenth scalar, the first address of the element in the sparse vector sX12, the first address of the index of the sparse vector sX12, the first address of the element in the sparse vector sY12, the first address of the index of the sparse vector sY12, the first address of the matrix A1 and the low-dimensional length of the matrix A1; wherein, when the storage format of the matrix A1 is row-major sequence, the low-dimensional length of the matrix A1 is the first address interval between two adjacent row vectors; when the storage format of the matrix A1 is column-major sequence, the low-dimensional length of the matrix A1 is the first address interval between two adjacent column vectors; the obtaining of data participating in the vector outer product operation according to the operation domain includes: The matrix A1 is obtained according to the first address of the matrix A1, the storage format of the matrix and the low-dimensional length of the matrix A1, and the number of elements in the matrix A1 is the product of the number of rows of the matrix A1 and the number of columns of the matrix A1; the sparse vector sX12 and the sparse vector sY12 are obtained according to the first address of the element in the sparse vector sX12 and the first address of the element in the sparse vector sY12 respectively; the sparse vector sX12 and the sparse vector sY12 are obtained according to the first address of the index of the sparse vector sX12 and the first address of the index of the sparse vector sY12 respectively. Respectively obtain the index of the sparse vector sX12 and the index of the sparse vector sY12; obtain a first intermediate index according to the index representation of the sparse vector sX12, the index of the sparse vector sX12 and the index of the sparse vector sY12; filter the elements in the sparse vector sX12 and the sparse vector sY12 according to the first intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12; obtain the tenth scalar according to the first address of the tenth scalar; Performing a vector outer product operation on the data participating in the vector outer product operation includes: A second vector outer product operation is performed on the matrix A1, the filtered sparse vector sX12, the filtered sparse vector sY12, and the tenth scalar.

17. The method according to claim 16, characterized in that The operation domain also includes the index representation of the sparse vector sY12; the obtaining of data participating in the vector outer product operation according to the operation domain also includes: After obtaining the sparse vector sX12 and its index and the sparse vector sY12 and its index, obtaining a second intermediate index according to the index of the sparse vector sX12, the index representation of the sparse vector sX12, the index of the sparse vector sY12, and the index representation of the sparse vector sY12; The elements in the sparse vector sX12 and the sparse vector sY12 are filtered according to the second intermediate index to obtain the filtered sparse vector sX12 and the filtered sparse vector sY12.

18. The method according to claim 16 or 17, characterized in that The operation domain also includes: the number of elements in the sparse vector sX12 and the number of elements in the sparse vector sY12; The step of obtaining the sparse vector sX12 and the sparse vector sY12 according to the first addresses of the elements in the sparse vector sX12 and the first addresses of the elements in the sparse vector sY12 respectively comprises: Obtain the sparse vector sX12 according to the first address of the element in the sparse vector sX12 and the number of elements in the sparse vector sX12; The sparse vector sY12 is obtained according to the first address of the element in the sparse vector sY12 and the number of elements in the sparse vector sY12.

19. The method according to any one of claims 14 to 17, characterized in that: The index representation of the input data is a direct index representation or a step index representation; the input data includes: the sparse vector X12, the sparse vector sX12 or the sparse vector sY12; When the index representation of the input data is a direct index representation, the index of the input data is a string consisting of 0 and 1, 0 indicates that the element in the input data does not meet the preset condition, and 1 indicates that the element in the input data meets the preset condition, or; When the index representation of the input data is a step index representation, the index of the input data is a character string consisting of the distance value between the element in the input data that meets the preset condition and the previous element that meets the preset condition; The preset condition is that the absolute value of the element in the input data is greater than or less than a preset threshold.