TWI767098B - Method for neural network forward computation and related product - Google Patents

Method for neural network forward computation and related product Download PDF

Info

Publication number
TWI767098B
TWI767098B TW107144040A TW107144040A TWI767098B TW I767098 B TWI767098 B TW I767098B TW 107144040 A TW107144040 A TW 107144040A TW 107144040 A TW107144040 A TW 107144040A TW I767098 B TWI767098 B TW I767098B
Authority
TW
Taiwan
Prior art keywords
data
matrix
floating
input data
type
Prior art date
Application number
TW107144040A
Other languages
Chinese (zh)
Other versions
TW201928793A (en
Inventor
發明人放棄姓名表示權
Original Assignee
大陸商中科寒武紀科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 大陸商中科寒武紀科技股份有限公司 filed Critical 大陸商中科寒武紀科技股份有限公司
Publication of TW201928793A publication Critical patent/TW201928793A/en
Application granted granted Critical
Publication of TWI767098B publication Critical patent/TWI767098B/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/30007Arrangements for executing specific machine instructions to perform operations on data operands
    • G06F9/3001Arithmetic instructions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/06Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons
    • G06N3/063Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons using electronic means
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/084Backpropagation, e.g. using gradient descent
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Artificial Intelligence (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Evolutionary Computation (AREA)
  • Data Mining & Analysis (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Computational Mathematics (AREA)
  • Neurology (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Advance Control (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Feedback Control In General (AREA)
  • Color Image Communication Systems (AREA)
  • Image Analysis (AREA)
  • Image Processing (AREA)

Abstract

本披露提供一種集成電路晶片裝置上執行的神經網絡正向運算方法,該神經網絡包含多層,其中,所述方法包括如下步驟:接收第一計算指令,解析第一計算指令得到所述第一計算指令在所述正向運算的第i層包含的第一運算以及第一計算指令對應的輸入數據以及權值數據;依據該輸入數據、權值數據以及第一運算確定第一運算的第一複雜度,依據所述第一複雜度確定該輸入數據以及權值數據在執行第一運算時的第一數據類型,所述第一數據類型包括:浮點類型或定點類型;將輸入數據以及權值數據以所述第一數據類型執行所述正向運算的第一層包含的第一運算。本披露提供的技術方案具有計算量小,功耗低的優點。 The present disclosure provides a neural network forward computing method executed on an integrated circuit chip device. The neural network includes multiple layers, wherein the method includes the following steps: receiving a first calculation instruction, parsing the first calculation instruction to obtain the first calculation the first operation included in the i-th layer of the forward operation and the input data and weight data corresponding to the first calculation instruction; determine the first complexity of the first operation according to the input data, weight data and the first operation degree, determine the first data type of the input data and the weight data when the first operation is performed according to the first complexity, the first data type includes: floating point type or fixed point type; The data performs the first operation included in the first layer of the forward operation in the first data type. The technical solution provided by the present disclosure has the advantages of small calculation amount and low power consumption.

Description

神經網絡正向運算方法及相關產品 Neural network forward operation method and related products

本披露涉及神經網絡領域,尤其涉及一種神經網絡正向運算方法及相關產品。 The present disclosure relates to the field of neural networks, and in particular, to a neural network forward computing method and related products.

人工神經網絡(Artificial Neural Network,ANN),是20世紀80年代以來人工智能領域興起的研究熱點。它從信息處理角度對人腦神經元網絡進行抽象,建立某種簡單模型,按不同的連接方式組成不同的網絡。在工程與學術界也常直接簡稱為神經網絡或類神經網絡。神經網絡是一種運算模型,由大量的節點(或稱神經元)之間相互聯接構成。現有的神經網絡的運算基於CPU(Central Processing Unit,中央處理器)或GPU(Graphics Processing Unit,圖形處理器)來實現神經網絡的正向運算,此種正向運算的計算量大,功耗高。 Artificial Neural Network (ANN) has been a research hotspot in the field of artificial intelligence since the 1980s. It abstracts the human brain neuron network from the perspective of information processing, establishes a certain simple model, and forms different networks according to different connection methods. In engineering and academia, it is often simply referred to as neural network or neural-like network. Neural network is an operation model, which is composed of a large number of nodes (or neurons) connected with each other. The operation of the existing neural network is based on a CPU (Central Processing Unit, central processing unit) or a GPU (Graphics Processing Unit, graphics processing unit) to realize the forward operation of the neural network, such a forward operation has a large amount of calculation and high power consumption .

本披露實施例提供了一種神經網絡正向運算方法及相關產品,可提升計算裝置的處理速度,提高效率。 Embodiments of the present disclosure provide a neural network forward computing method and related products, which can improve the processing speed and efficiency of a computing device.

第一方面,提供一種集成電路晶片裝置上執行的神經網絡正向運算方法,該神經網絡包含多層,所述方法包括如下步驟:接收第一計算指令,解析第一計算指令得到所述第一計算指令在所述正向運算的第i層包含的第一運算以及第一計算指令對應的輸入數據以及權值數據;,所述i的取值範圍為大於等於1的整數,如所述i大於等於2,所述輸入數據為第i-1層的輸出數據;依據該輸入數據、權值數據以及第一運算確定第一運算的第一複雜度,依據所述第一複雜度確定該輸入數據以及權值數據在執行第一運算時的第一數據類型,所述第一數據類型包括:浮點類型或定點類型;將輸入數據以及權值數據以所述第一數據類型執行所述正向運算的第一層包含的第一運算。 A first aspect provides a neural network forward computing method executed on an integrated circuit chip device, the neural network includes multiple layers, and the method includes the steps of: receiving a first calculation instruction, parsing the first calculation instruction to obtain the first calculation The first operation included in the i-th layer of the forward operation and the input data and weight data corresponding to the first calculation instruction; the value range of the i is an integer greater than or equal to 1, if the i is greater than or equal to 1 is equal to 2, the input data is the output data of the i-1th layer; the first complexity of the first operation is determined according to the input data, the weight data and the first operation, and the input data is determined according to the first complexity and the first data type of the weight data when the first operation is performed, the first data type includes: a floating point type or a fixed-point type; the input data and the weight data are executed in the forward direction with the first data type The first operation contained in the first layer of operations.

第二方面,提供一種集成電路晶片裝置,所述集成電路晶片裝置用於執行神經網絡的正向運算,所述神經網絡包含多層,所述裝置包括:處理電路以及外部介面;所述外部介面,用於接收第一計算指令;所述處理電路,用於解析第一計算指令得到所述第一計算指令在所述正向運算的第i層包含的第一運算、第一計算指令對應的輸入數據以及權值數據;,所述i的取值範圍為大於等於1的整數,如所述i大於等於2,所述輸入數據為第i-1層的輸出數據;所述處理電路,還用於依據該輸入數據、權值數據以及第一運算確定第一運算的第一複雜度,依據所述第一複雜度確定該輸入數據以及權值 數據在執行第一運算時的第一數據類型,所述第一數據類型包括:浮點類型或定點類型;所述處理電路,還用於將輸入數據以及權值數據以第一數據類型執行所述正向運算的第i層包含的第一運算。 In a second aspect, an integrated circuit chip device is provided, the integrated circuit chip device is used to perform forward operation of a neural network, the neural network includes multiple layers, and the device includes: a processing circuit and an external interface; the external interface, is used to receive a first calculation instruction; the processing circuit is used to parse the first calculation instruction to obtain the first calculation and the input corresponding to the first calculation instruction included in the i-th layer of the forward operation of the first calculation instruction data and weight data; the value range of the i is an integer greater than or equal to 1, if the i is greater than or equal to 2, the input data is the output data of the i-1th layer; the processing circuit also uses determining the first complexity of the first operation according to the input data, the weight data and the first operation, and determining the input data and the weight according to the first complexity The first data type of the data when the first operation is performed, the first data type includes: floating-point type or fixed-point type; the processing circuit is further configured to execute the input data and the weight data in the first data type. The first operation included in the i-th layer of the forward operation.

第三方面,提供一種神經網絡運算裝置,所述神經網絡運算裝置包括一個或多個第二方面提供的集成電路晶片裝置。 In a third aspect, a neural network computing device is provided, and the neural network computing device includes one or more integrated circuit chip devices provided in the second aspect.

第四方面,提供一種組合處理裝置,所述組合處理裝置包括:第三方面提供的神經網絡運算裝置、通用互聯介面和通用處理裝置;所述神經網絡運算裝置通過所述通用互聯介面與所述通用處理裝置連接。 In a fourth aspect, a combined processing device is provided, the combined processing device includes: the neural network computing device, the universal interconnection interface, and the universal processing device provided in the third aspect; the neural network computing device communicates with the neural network computing device through the universal interconnection interface. Universal processing unit connection.

第五方面,提供一種晶片,所述晶片集成第二方面的裝置、第三方面的裝置或第四方面的裝置。 A fifth aspect provides a wafer that integrates the device of the second aspect, the device of the third aspect, or the device of the fourth aspect.

第六方面,提供一種電子設備,所述電子設備包括第四方面的晶片。 In a sixth aspect, an electronic device is provided, the electronic device comprising the wafer of the fourth aspect.

可以看出,通過本披露實施例,提供數據轉換運算電路將數據塊的類型進行轉換後運算,節省了傳輸資源以及計算資源,所以其具有功耗低,計算量小的優點。 It can be seen that, through the embodiments of the present disclosure, a data conversion operation circuit is provided to perform operations after converting the types of data blocks, which saves transmission resources and computing resources, so it has the advantages of low power consumption and small calculation amount.

A、B、S:矩陣 A, B, S: Matrix

P:向量 P: vector

S401b、S402b、S403b、S401、S402、S403、S404:步驟 S401b, S402b, S403b, S401, S402, S403, S404: Steps

10:神經網絡處理器卡板 10: Neural network processor card board

11:神經網絡晶片封裝結構 11: Neural network chip package structure

12:第一電氣及非電氣連接裝置 12: First electrical and non-electrical connection device

13:第一基板 13: The first substrate

111:神經網絡晶片 111: Neural Network Chip

112:第二電氣及非電氣連接裝置 112: Second electrical and non-electrical connection device

113:第二基板 113: Second substrate

1111:存儲單元 1111: storage unit

1112:直接內存存取單元 1112: Direct Memory Access Unit

1113:指令緩存單元 1113: Instruction cache unit

1114:權緩存單元 1114: Weight cache unit

1115:輸入神經元緩存單元 1115: Input neuron buffer unit

1116:輸出神經元緩存單元 1116: output neuron buffer unit

1117:控制單元 1117: Control Unit

1118:運算單元 1118: arithmetic unit

21:神經網絡晶片 21: Neural Network Chip

22:焊盤 22: Pad

23:焊球 23: Solder Balls

24:第二基板 24: Second substrate

25:第二基板24上的連接點 25: Connection point on the second substrate 24

26:引腳 26: pin

27:絕緣填充物 27: Insulation filler

28:散熱膏 28: Thermal paste

29:金屬外殼散熱片 29: Metal shell heat sink

圖1是一種神經網絡的正向運算示意圖。 Figure 1 is a schematic diagram of the forward operation of a neural network.

圖1a為一種定點數據類型的示意結構圖。 FIG. 1a is a schematic structural diagram of a fixed-point data type.

圖2a為卷積輸入數據示意圖。 Figure 2a is a schematic diagram of convolution input data.

圖2b為卷積核示意圖。 Figure 2b is a schematic diagram of the convolution kernel.

圖2c為輸入數據的一個三維數據塊的運算窗口示意圖。 FIG. 2c is a schematic diagram of an operation window of a three-dimensional data block of input data.

圖2d為輸入數據的一個三維數據塊的另一運算窗口示意圖。 FIG. 2d is a schematic diagram of another operation window of a three-dimensional data block of input data.

圖2e為輸入數據的一個三維數據塊的又一運算窗口示意圖. Figure 2e is a schematic diagram of another operation window of a three-dimensional data block of input data.

圖3a是一種神經網絡晶片的結構示意圖。 Figure 3a is a schematic structural diagram of a neural network chip.

圖3b是另一種神經網絡晶片的結構示意圖。 Figure 3b is a schematic structural diagram of another neural network chip.

圖4a為矩陣乘以矩陣示意圖。 Figure 4a is a schematic diagram of matrix multiplication by matrix.

圖4b為矩陣乘以矩陣的方法流程圖。 Figure 4b is a flow chart of a method of multiplying a matrix by a matrix.

圖4c為矩陣乘以向量示意圖。 Figure 4c is a schematic diagram of multiplying a matrix by a vector.

圖4d為矩陣乘以向量的方法流程圖。 Figure 4d is a flow chart of a method of multiplying a matrix by a vector.

圖5a為本披露還揭露了一個組合處理裝置結構示意圖。 FIG. 5a also discloses a schematic structural diagram of a combined processing device for the present disclosure.

圖5b為本披露還揭露了一個組合處理裝置另一種結構示意圖。 FIG. 5b also discloses another structural schematic diagram of a combined processing device for the present disclosure.

圖5c為本披露實施例提供的一種神經網絡處理器板卡的結構示意圖;圖5d為本披露實施例流提供的一種神經網絡晶片封裝結構的結構示意圖;圖5e為本披露實施例流提供的一種神經網絡晶片的結構示意圖;圖6為本披露實施例流提供的一種神經網絡晶片封裝結構的示意圖;圖6a為本披露實施例流提供的另一種神經網絡晶片封裝結構的示意圖。 5c is a schematic structural diagram of a neural network processor board provided by an embodiment of the disclosure; FIG. 5d is a schematic structural diagram of a neural network chip packaging structure provided by an embodiment of the disclosure; A schematic diagram of the structure of a neural network chip; FIG. 6 is a schematic diagram of a neural network chip packaging structure provided by an embodiment of the disclosure; FIG. 6a is a schematic diagram of another neural network chip packaging structure provided by the embodiment of the disclosure.

為了使本技術領域的人員更好地理解本披露方案,下面將結合本披露實施例中的圖式,對本披露實施例中的技術方案進行清楚、完整地描述,顯然,所描述的實施例僅僅是本披露一部分實施例,而不是全部的實施例。基於本披露中的實施例,所屬技術領域中具有通常知識者在沒有作出創造性勞動前提下所獲得的所有其他實施例,都屬於本披露保護的範圍。 In order for those skilled in the art to better understand the disclosed solutions, the technical solutions in the disclosed embodiments will be clearly and completely described below with reference to the drawings in the disclosed embodiments. Obviously, the described embodiments are only These are some, but not all, embodiments of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by those with ordinary knowledge in the technical field without creative work shall fall within the protection scope of the present disclosure.

在第一方面提供的方法中,依據所述第一複雜度確定該輸入數據以及權值數據在執行第一運算時的第一數據類型,包括:將所述第一複雜度與預設閾值比較,如所述第一複雜度高於所述預設閾值,確定所述第一數據類型為定點類型,如所述第一複雜度低於或等於所述預設閾值,確定所述第一數據類型為浮點類型。 In the method provided by the first aspect, determining the first data type of the input data and the weight data when performing the first operation according to the first complexity includes: comparing the first complexity with a preset threshold , if the first complexity is higher than the preset threshold, determine that the first data type is a fixed-point type, and if the first complexity is lower than or equal to the preset threshold, determine the first data type The type is a floating point type.

在第一方面提供的方法中,所述方法在所述依據所述第一複雜度確定該輸入數據以及權值數據在執行第一運算時的第一數據類型之後還包括:確定所述輸入數據以及權值數據屬於第二數據類型,如所述第二數據類型與所述第一數據類型不同,將屬於第二數據類型的所述輸入數據以及屬於第二數據類型的所述權值數據轉換成屬於第一數據類型的所述輸入數據以及屬於第一數據類型的所述權值數據。 In the method provided in the first aspect, after determining the first data type of the input data and the weight data when the first operation is performed according to the first complexity, the method further includes: determining the input data and the weight data belongs to a second data type, if the second data type is different from the first data type, convert the input data belonging to the second data type and the weight data belonging to the second data type into the input data belonging to the first data type and the weight data belonging to the first data type.

在第一方面提供的方法中,如所述第一運算為卷積運算,所述輸入數據為卷積輸入數據,所述權值數據為卷積核,第一複雜度=α*C*kW*kH*M*N*W*C*H; 其中,α為卷積系數,取值範圍為大於1;C、kW、kH、M為卷積核四個維度的值,N、W、C、H為卷積輸入數據四個維度的值;如所述第一複雜度大於設定閾值,確定該卷積輸入數據以及卷積核是否為浮點數據,如該卷積輸入數據以及卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將卷積核轉換成浮點數據,然後將卷積輸入數據、卷積核以浮點數據類型執行卷積運算。 In the method provided in the first aspect, if the first operation is a convolution operation, the input data is convolution input data, the weight data is a convolution kernel, and the first complexity=α*C*kW *kH*M*N*W*C*H; Among them, α is the convolution coefficient, and the value range is greater than 1; C, kW, kH, and M are the values of the four dimensions of the convolution kernel, and N, W, C, and H are the values of the four dimensions of the convolution input data; If the first complexity is greater than the set threshold, determine whether the convolution input data and the convolution kernel are floating-point data, if the convolution input data and the convolution kernel are not floating-point data, the convolution input The data is converted to floating-point data, the convolution kernel is converted to floating-point data, and then the convolution input data and the convolution kernel are convolved with the floating-point data type.

在第一方面提供的方法中,如所述第一運算為:矩陣乘矩陣運算,所述輸入數據為所述矩陣乘矩陣運算的第一矩陣,所述權值為所述矩陣乘矩陣運算的第二矩陣;第一複雜度=β*F1*G*E*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為第一矩陣的行、列值,E、F2為第二矩陣的行、列值;如所述第一複雜度大於設定閾值,確定該第一矩陣以及第二矩陣是否為浮點數據,如該第一矩陣以及第二矩陣不為浮點數據,將該第一矩陣轉換成浮點數據,將第二矩陣轉換成浮點數據,然後將第一矩陣、第二矩陣以浮點數據類型執行矩陣乘矩陣運算。 In the method provided in the first aspect, if the first operation is a matrix multiplication matrix operation, the input data is the first matrix of the matrix multiplication matrix operation, and the weight value is the matrix multiplication matrix operation. The second matrix; the first complexity=β*F1*G*E*F2; where, β is the matrix coefficient, the value range is greater than or equal to 1, F1, G are the row and column values of the first matrix, E, F2 is the row and column values of the second matrix; if the first complexity is greater than the set threshold, determine whether the first matrix and the second matrix are floating point data, such as the first matrix and the second matrix are not floating point data data, convert the first matrix into floating-point data, convert the second matrix into floating-point data, and then perform a matrix-matrix-matrix operation on the first matrix and the second matrix in the floating-point data type.

在第一方面提供的方法中,如所述第一運算為:矩陣乘向量運算,所述輸入數據為所述矩陣乘向量運算的第一矩陣,所述權值為所述矩陣乘向量運算的向量;第一複雜度=β*F1*G*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為第一矩陣的行、列值,F2為向量的列值;如所述第一複雜度大於設定閾值,確定該第一矩陣以及向量是否為浮點數據,如該第一矩陣以及向量不為浮點數據,將該第一矩陣轉換成浮 點數據,將向量轉換成浮點數據,然後將第一矩陣、向量以浮點數據類型執行矩陣乘向量運算。 In the method provided in the first aspect, if the first operation is a matrix multiplication vector operation, the input data is the first matrix of the matrix multiplication vector operation, and the weight is the matrix multiplication vector operation. Vector; first complexity=β*F1*G*F2; where, β is the matrix coefficient, the value range is greater than or equal to 1, F1, G are the row and column values of the first matrix, and F2 is the column value of the vector; If the first complexity is greater than the set threshold, determine whether the first matrix and vector are floating-point data, and if the first matrix and vector are not floating-point data, convert the first matrix to floating-point data point data, convert the vector to floating point data, and then perform a matrix multiplication vector operation on the first matrix, vector with the floating point data type.

在第一方面提供的方法中,第i層還可以包括如下運算:偏置運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。 In the method provided in the first aspect, the i-th layer may further include one or any combination of the following operations: bias operation, fully connected operation, GEMM operation, GEMV operation, and activation operation.

在第二方面提供的裝置中,所述處理電路,具體用於將所述第一複雜度與預設閾值比較,如所述第一複雜度高於所述預設閾值,計算裝置確定所述第一數據類型為定點類型,如所述第一複雜度低於或等於所述預設閾值,計算裝置確定所述第一數據類型為浮點類型。 In the device provided in the second aspect, the processing circuit is specifically configured to compare the first complexity with a preset threshold, and if the first complexity is higher than the preset threshold, the computing device determines the The first data type is a fixed-point type, and if the first complexity is lower than or equal to the preset threshold, the computing device determines that the first data type is a floating-point type.

在第二方面提供的裝置中,所述集成電路晶片裝置還包括:數據類型轉換電路;所述處理電路,還用於確定所述輸入數據以及權值數據屬於的第二數據類型,如所述第二數據類型與所述第一數據類型不同,向所述數據類型轉換電路發送轉換命令,所述數據類型轉換電路,用於依據所述轉換命令將屬於第二數據類型的所述輸入數據以及屬於第二數據類型的所述權值數據轉換成屬於第一數據類型的所述輸入數據以及屬於第一數據類型的所述權值數據。 In the device provided in the second aspect, the integrated circuit chip device further includes: a data type conversion circuit; the processing circuit is further configured to determine the second data type to which the input data and the weight data belong, as described above The second data type is different from the first data type, and a conversion command is sent to the data type conversion circuit, and the data type conversion circuit is configured to convert the input data belonging to the second data type and The weight data belonging to the second data type is converted into the input data belonging to the first data type and the weight data belonging to the first data type.

在第二方面提供的裝置中,如所述第一運算為卷積運算,所述輸入數據為卷積輸入數據,所述權值數據為卷積核,所述處理電路,用於計算第一複雜度,第一複雜度=α*C*kW*kH*M*N*W*C*H;其中,α為卷積系數,取值範圍為大於1;C、kW、kH、M為卷積核四個維度的值,N、W、C、H為卷積輸入數據四個維度的值; 所述處理電路,還用於如所述第一複雜度大於設定閾值,確定該卷積輸入數據以及卷積核是否為浮點數據,如該卷積輸入數據以及卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將卷積核轉換成浮點數據,然後將卷積輸入數據、卷積核以浮點數據類型執行卷積運算。 In the device provided in the second aspect, if the first operation is a convolution operation, the input data is convolution input data, the weight data is a convolution kernel, and the processing circuit is configured to calculate the first Complexity, the first complexity = α*C*kW*kH*M*N*W*C*H; among them, α is the convolution coefficient, the value range is greater than 1; C, kW, kH, M are the volume The value of the four dimensions of the product kernel, N, W, C, and H are the values of the four dimensions of the convolution input data; The processing circuit is further configured to determine whether the convolution input data and the convolution kernel are floating-point data if the first complexity is greater than a set threshold, for example, the convolution input data and the convolution kernel are not floating-point data data, convert the convolution input data to floating point data, convert the convolution kernel to floating point data, and then perform the convolution operation on the convolution input data and the convolution kernel with the floating point data type.

在第二方面提供的裝置中,如所述第一運算為:矩陣乘矩陣運算,所述輸入數據為所述矩陣乘矩陣運算的第一矩陣,所述權值為所述矩陣乘矩陣運算的第二矩陣;所述處理電路,用於計算第一複雜度;第一複雜度=β*F1*G*E*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為第一矩陣的行、列值,E、F2為第二矩陣的行、列值;所述處理電路,還用於如所述第一複雜度大於設定閾值,確定該第一矩陣以及第二矩陣是否為浮點數據,如該第一矩陣以及第二矩陣不為浮點數據,將該第一矩陣轉換成浮點數據,將第二矩陣轉換成浮點數據,然後將第一矩陣、第二矩陣以浮點數據類型執行矩陣乘矩陣運算。 In the device provided in the second aspect, the first operation is: a matrix multiplication matrix operation, the input data is the first matrix of the matrix multiplication matrix operation, and the weight is the matrix multiplication matrix operation. The second matrix; the processing circuit is used to calculate the first complexity; the first complexity=β*F1*G*E*F2; wherein, β is the matrix coefficient, and the value range is greater than or equal to 1, F1, G are the row and column values of the first matrix, and E and F2 are the row and column values of the second matrix; the processing circuit is further configured to determine the first matrix and the second matrix if the first complexity is greater than the set threshold Whether the matrix is floating-point data, if the first matrix and the second matrix are not floating-point data, convert the first matrix to floating-point data, convert the second matrix to floating-point data, and then convert the first matrix to floating-point data. The first matrix and the second matrix perform matrix-by-matrix operations in floating point data types.

在第二方面提供的裝置中,如所述第一運算為:矩陣乘向量運算,所述輸入數據為所述矩陣乘向量運算的第一矩陣,所述權值為所述矩陣乘向量運算的向量;所述處理電路,用於計算第一複雜度;第一複雜度=β*F1*G*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為第一矩陣的行、列值,F2為向量的列值;所述處理電路,還用於如所述第一複雜度大於設定閾值,確定該第一矩陣以及向量是否為浮點數據,如該第一矩陣以及向量不為浮點數據, 將該第一矩陣轉換成浮點數據,將向量轉換成浮點數據,然後將第一矩陣、向量以浮點數據類型執行矩陣乘向量運算。 In the device provided in the second aspect, if the first operation is a matrix multiplication vector operation, the input data is the first matrix of the matrix multiplication vector operation, and the weight is the matrix multiplication vector operation. vector; the processing circuit is used to calculate the first complexity; the first complexity=β*F1*G*F2; wherein, β is the matrix coefficient, and the value range is greater than or equal to 1, and F1 and G are the first matrix The row and column values of , and F2 is the column value of the vector; the processing circuit is also used to determine whether the first matrix and the vector are floating-point data if the first complexity is greater than the set threshold, such as the first Matrices and vectors are not floating point data, The first matrix is converted into floating-point data, the vector is converted into floating-point data, and then a matrix-multiply-vector operation is performed on the first matrix and the vector in the floating-point data type.

在第二方面提供的裝置中,所述i層還可以包括如下運算:偏置運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。 In the apparatus provided in the second aspect, the i-layer may further include one or any combination of the following operations: a bias operation, a fully connected operation, a GEMM operation, a GEMV operation, and an activation operation.

如圖1所示,為本披露實施例提供的一種神經網絡的正向運算,每一層使用自己的輸入數據和權值按照層的類型所指定的運算規則計算得到相應的輸出數據;神經網絡的正向運算過程(也叫推理,inference)是逐層處理各層的輸入數據,經過一定的計算,得到輸出數據的過程,具有如下特徵:某一層的輸入:某一層的輸入可以是神經網絡的輸入數據;某一層的輸入可以是其他層的輸出;某一層的輸入可以是本層上一時刻的輸出(對應於循環神經網絡的情況);某一層可以同時從多個上述輸入源獲取輸入;某一層的輸出:某一層的輸出可以作為神經網絡的輸出結果;某一層的輸出可以是其它層的輸入;某一層的輸出可以是下一時刻本層的輸入(循環神經網絡的情況);某一層的輸出可以向上述多個輸出方向輸出結果; 具體地,所述神經網絡中的層的運算的類型包括但不限於以下幾種:卷積層(即執行卷積運算);全連接層(即執行全連接運算);歸一化(規則化)層:包括LRN(Local Response Normalization)層,BN(Batch Normalization)層等類型;池化層;激活層:包括但不限於以下類型Sigmoid層,ReLU層,PReLu層,LeakyReLu層,Tanh層;層的反向運算,每一層的反向運算需要執行兩部分運算:一部分是使用可能是稀疏表示的輸出數據梯度和可能是稀疏表示的輸入數據計算出權值的梯度(用於在「權值更新」步驟更新本層的權值),另一部分是使用可能是稀疏表示的輸出數據梯度和可能是稀疏表示的權值,計算出輸入數據梯度(用於作為反向運算中下一層的輸出數據梯度以供其進行反向運算);反向運算按照與正向運算相反的順序,從最後一層開始反向傳遞梯度。 As shown in FIG. 1 , in the forward operation of a neural network provided by the embodiment of the present disclosure, each layer uses its own input data and weights to calculate corresponding output data according to the operation rules specified by the type of the layer; The forward operation process (also called inference) is the process of processing the input data of each layer layer by layer, and obtaining the output data after a certain calculation. It has the following characteristics: the input of a certain layer: the input of a certain layer can be the input of the neural network data; the input of a certain layer can be the output of other layers; the input of a certain layer can be the output of this layer at the previous moment (corresponding to the case of a recurrent neural network); a certain layer can obtain input from multiple above-mentioned input sources at the same time; The output of one layer: the output of a certain layer can be used as the output of the neural network; the output of a certain layer can be the input of other layers; the output of a certain layer can be the input of this layer at the next moment (in the case of a recurrent neural network); a certain layer The output can output results to the above multiple output directions; Specifically, the types of operations of the layers in the neural network include but are not limited to the following: convolutional layers (that is, performing convolution operations); fully-connected layers (that is, performing fully-connected operations); normalization (regularization) Layer: including LRN (Local Response Normalization) layer, BN (Batch Normalization) layer and other types; pooling layer; activation layer: including but not limited to the following types of Sigmoid layer, ReLU layer, PReLu layer, LeakyReLu layer, Tanh layer; Reverse operation, the reverse operation of each layer needs to perform two parts of operation: one part is to use the gradient of the output data that may be sparsely represented and the input data that may be sparsely represented to calculate the gradient of the weights (used in "weight update" step to update the weights of this layer), and the other part is to use the output data gradient that may be sparsely represented and the weights that may be sparse representation to calculate the input data gradient (used as the output data gradient of the next layer in the reverse operation to for the reverse operation); the reverse operation follows the reverse order of the forward operation, starting from the last layer and passing the gradient backwards.

在一種可選方案中,某一層反向計算得到的輸出數據梯度可以來自:神經網絡最後的損失函數(lost function或者cost function)回傳的梯度;其它層的輸入數據梯度; 本層上一時刻的輸入數據梯度(對應於循環神經網絡的情況);某一層可以同時從多個上述源獲取輸出數據梯度;在執行完神經網絡的反向運算之後,就計算出了各層的權值的梯度,在這個步驟中,所述裝置的第一輸入緩存和第二輸入緩存分別用於存儲本層的權值和權值的梯度,然後在運算單元中使用權值梯度對權值進行更新;上文中提到的運算都是神經網絡中的一層的運算,對於多層神經網絡,其實現過程是,在正向運算中,當上一層人工神經網絡執行完成之後,下一層的運算指令會將運算單元中計算出的輸出數據作為下一層的輸入數據進行運算(或者是對該輸出數據進行某些操作再作為下一層的輸入數據),同時,將權值也替換為下一層的權值;在反向運算中,當上一層人工神經網絡的反向運算執行完成後,下一層運算指令會將運算單元中計算出的輸入數據梯度作為下一層的輸出數據梯度進行運算(或者是對該輸入數據梯度進行某些操作再作為下一層的輸出數據梯度),同時將權值替換為下一層的權值;(用以下的圖表示,以下圖中虛線的箭頭表示反向運算,實線的箭頭表示正向運算,各圖下面的標注表示圖的含義) In an optional solution, the gradient of the output data obtained by the reverse calculation of a certain layer can come from: the gradient returned by the final loss function (lost function or cost function) of the neural network; the input data gradient of other layers; The gradient of the input data at the previous moment of this layer (corresponding to the case of the recurrent neural network); a certain layer can obtain the gradient of the output data from multiple above-mentioned sources at the same time; after the reverse operation of the neural network is performed, the Gradient of the weight, in this step, the first input buffer and the second input buffer of the device are respectively used to store the weight of the layer and the gradient of the weight, and then use the gradient of the weight in the computing unit to measure the weight Update; the operations mentioned above are all operations of one layer in the neural network. For a multi-layer neural network, the implementation process is that in the forward operation, after the execution of the upper layer of artificial neural network is completed, the operation instructions of the next layer The output data calculated in the operation unit is used as the input data of the next layer for operation (or some operations are performed on the output data and then used as the input data of the next layer), and at the same time, the weights are also replaced with the weights of the next layer. value; in the reverse operation, when the reverse operation of the artificial neural network of the previous layer is executed, the operation instruction of the next layer will calculate the gradient of the input data calculated in the operation unit as the gradient of the output data of the next layer. The input data gradient performs some operations and then serves as the output data gradient of the next layer), and at the same time replaces the weights with the weights of the next layer; (represented by the following figure, the dotted arrow in the figure below represents the reverse operation, the solid line The arrows represent forward operations, and the labels below each figure represent the meaning of the figures)

定點化數據的表示方法 Representation of fixed-point data

定點化的方法是指將網絡中的某個數據塊的數據表示轉換成特定的某種固定小數點位置的數據表示方式(映射到電路裝置上數據的0/1比特位擺放方式); 在一種可選方案中,將多個數據組成個數據塊作為一個整體使用同樣的定點表示方法進行定點化表示;圖1a示出了根據本發明實施例的用於存儲數據的短位數定點數據結構的具體表示方法。其中,1Bit位用於表示符號,M位用於表示整數部分,N位用於表示小數部分;相比於32位浮點數據表示形式,本發明採用的短位定點數據表示形式除了佔用比特位數更少外,對於神經網絡中同一層、同一類型的數據,如第一個卷積層的所有權值數據,還另外設置了一個標誌位Point location記錄小數點的位置,這樣可以根據實際數據的分布調整數據表示的精度與可表示數據範圍。 The fixed-point method refers to converting the data representation of a data block in the network into a specific data representation with a fixed decimal point position (mapped to the 0/1 bit placement of the data on the circuit device); In an optional solution, multiple pieces of data are formed into a data block as a whole using the same fixed-point representation method for fixed-point representation; FIG. 1a shows fixed-point data with short bits for storing data according to an embodiment of the present invention A concrete representation of the structure. Among them, 1Bit is used to represent the symbol, M bits are used to represent the integer part, and N bits are used to represent the fractional part; compared with the 32-bit floating point data representation, the short-bit fixed-point data representation adopted in the present invention is used in addition to occupying bits In addition to fewer digits, for the same layer and the same type of data in the neural network, such as the ownership value data of the first convolutional layer, a flag bit Point location is additionally set to record the position of the decimal point, so that it can be used according to the actual data. The distribution adjusts the precision of the data representation and the range of representable data.

對於浮點數的表示即32bit來表示,但是對於此技術方案,其採用定點數可以減少一個數值的比特位的位數,從而降低傳輸的數據量以及運算的數據量。 The floating-point number is represented by 32 bits, but for this technical solution, the use of fixed-point numbers can reduce the number of bits of a numerical value, thereby reducing the amount of data transmitted and the amount of data calculated.

輸入數據用圖2a表示(N個樣本,每個樣本有C個通道,每個通道的特徵圖的高為H,寬為W),權值也即卷積核用圖2b表示(有M個卷積核,每個卷積核有C個通道,高和寬分別為KH和KW)。對於輸入數據的N個樣本,卷積運算的規則都是一樣的,下面解釋在一個樣本上進行卷積運算的過程,在一個樣本上,M個卷積核中的每一個都要進行同樣的運算,每個卷積核運算得到一張平面特徵圖,M個卷積核最終計算得到M個平面特徵圖,(對一個樣本,卷積的輸出是M個特徵圖),對於一個卷積核,要在一個樣本的每一個平面位置進行內積運算,然後沿著H和W方向進行滑動,例如,圖2c表示一個卷積核在輸入數據的一個樣本中右下角的位置進 行內積運算的對應圖;圖2d表示卷積的位置向左滑動一格和圖2e表示卷積的位置向上滑動一格。 The input data is represented by Figure 2a (N samples, each sample has C channels, the height of the feature map of each channel is H, and the width is W), and the weights, that is, the convolution kernel, are represented by Figure 2b (there are M Convolution kernel, each convolution kernel has C channels, the height and width are KH and KW respectively). For N samples of input data, the rules of the convolution operation are the same. The following explains the process of performing the convolution operation on a sample. On a sample, each of the M convolution kernels must perform the same Operation, each convolution kernel operation obtains a plane feature map, and M convolution kernels finally calculate M plane feature maps, (for a sample, the output of the convolution is M feature maps), for a convolution kernel , to perform the inner product operation at each plane position of a sample, and then slide along the H and W directions. For example, Figure 2c shows that a convolution kernel is processed at the lower right corner of a sample of the input data. Corresponding diagram of the in-line product operation; Figure 2d shows that the position of the convolution is slid one cell to the left and Figure 2e shows that the position of the convolution is slid one cell up.

當第一運算為卷積運算,所述輸入數據為卷積輸入數據,所述權值數據為卷積核,第一複雜度=α*C*kW*kH*M*N*W*C*H;其中,α為卷積系數,取值範圍為大於1;C、kW、kH、M為卷積核四個維度的值,N、W、C、H為卷積輸入數據四個維度的值;如所述第一複雜度大於設定閾值,確定該卷積輸入數據以及卷積核是否為浮點數據,如該卷積輸入數據以及卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將卷積核轉換成浮點數據,然後將卷積輸入數據、卷積核以浮點數據類型執行卷積運算。 When the first operation is a convolution operation, the input data is the convolution input data, the weight data is the convolution kernel, and the first complexity=α*C*kW*kH*M*N*W*C* H; among them, α is the convolution coefficient, and the value range is greater than 1; C, kW, kH, and M are the values of the four dimensions of the convolution kernel, and N, W, C, and H are the four dimensions of the convolution input data. value; if the first complexity is greater than the set threshold, determine whether the convolution input data and the convolution kernel are floating-point data, if the convolution input data and the convolution kernel are not floating-point data, the convolution input data and the convolution kernel are not floating-point data. Convert the convolution input data to floating point data, convert the convolution kernel to floating point data, and then perform the convolution operation on the convolution input data and the convolution kernel with the floating point data type.

具體的,該卷積處理的方式可以採用如圖3a所示的晶片結構處理,主處理電路(也可以稱為主單元)的數據轉換運算電路可以在第一複雜度大於設定閾值時,將權值的部分或全部卷積核中的數據轉換成定點類型的數據,主處理電路的控制電路將權值的部分或全部卷積核中的數據發送到通過橫向數據輸入介面直接與主處理電路相連的那些基礎處理電路(也可以稱為基礎單元)(例如,圖3b中最上方的灰色填充的竪向數據通路);在一種可選方案中,主處理電路的控制電路將權值中某個卷積核的數據每次發送一個數或者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3行第1個數,第2次發送第3行數據中的第2個數,第3次發送第3行的第3個數......,或者第1次發送第3行前兩個數,第二次發送第3行第3和第4個數,第三次發送第3行第5和第6個數......;) 在一種可選方案中另一種情況是,主處理電路的控制電路將權值中某幾個卷積核的數據每次各發送一個數者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3,4,5行每行的第1個數,第2次發送第3,4,5行每行的第2個數,第3次發送第3,4,5行每行的第3個數......,或者第1次發送第3,4,5行每行前兩個數,第二次發送第3,4,5行每行第3和第4個數,第三次發送第3,4,5行每行第5和第6個數......;)主處理電路的控制電路把輸入數據按照卷積的位置進行劃分,主處理電路的控制電路將輸入數據中的部分或全部卷積位置中的數據發送到通過竪向數據輸入介面直接與主處理電路相連的那些基礎處理電路(例如,圖3b中基礎處理電路陣列左側的灰色填充的橫向數據通路);在一種可選方案中,主處理電路的控制電路將輸入數據中某個卷積位置的數據每次發送一個數或者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3列第1個數,第2次發送第3列數據中的第2個數,第3次發送第3列的第3個數......,或者第1次發送第3列前兩個數,第二次發送第3列第3和第4個數,第三次發送第3列第5和第6個數......;)在一種可選方案中另一種情況是,主處理電路的控制電路將輸入數據中某幾個卷積位置的數據每次各發送一個數或者一部分數給某個基礎處理電路;(例如,對於某一個基礎處理電路,第1次發送第3,4,5列每列的第1個數,第2次發送第3,4,5列每列的第2個數,第3次發送第3,4,5列每列的第3個數......,或者第1次發送第3,4,5列每列前兩個數,第二次發送第3,4,5列每列第3和第4個數,第三次發送第3,4,5列每列第5和第6個數......;) 基礎處理電路接收到權值的數據之後,將該數據通過其橫向的數據輸出介面傳輸給其相連接下一個基礎處理電路(例如,圖3b中基礎處理電路陣列中間的白色填充的橫向的數據通路);基礎處理電路接收到輸入數據的數據後,將該數據通過其竪向的數據輸出介面傳輸給與其相連接的下一個基礎處理電路(例如,圖3b中基礎處理電路陣列中間的白色填充的竪向的數據通路);每一個基礎處理電路對接收到的數據進行運算;在一種可選方案中,基礎處理電路每次計算一組或多組兩個數據的乘法,然後將結果累加到寄存器和/或片上緩存上;在一種可選方案中,基礎處理電路每次計算一組或多組兩個向量的內積,然後將結果累加到寄存器和/或片上緩存上;基礎處理電路計算出結果後,可以將結果從數據輸出介面傳輸出去;在一種可選方案中,該計算結果可以是內積運算的最終結果或中間結果;具體地,如果該基礎處理電路有直接與主處理電路相連接的輸出介面則從該介面傳輸結果,如果沒有,則向著能夠直接向主處理電路輸出的基礎處理電路的方向輸出結果(例如,圖3b中,最下面一行基礎處理電路將其輸出結果直接輸出給主處理電路,其他基礎處理電路從竪向的輸出介面向下傳輸運算結果)。 Specifically, the convolution processing method can adopt the wafer structure processing as shown in FIG. 3a, and the data conversion operation circuit of the main processing circuit (also referred to as the main unit) can convert the weight of the weight when the first complexity is greater than the set threshold. Part or all of the data in the convolution kernel of the value is converted into fixed-point type data, and the control circuit of the main processing circuit sends part or all of the data in the convolution kernel of the weight to the main processing circuit through the horizontal data input interface. Those basic processing circuits (which may also be referred to as basic units) (for example, the uppermost gray-filled vertical data path in Figure 3b); in an alternative, the control circuit of the main processing circuit will The data of the convolution kernel is sent one number or part of the number to a certain basic processing circuit at a time; (for example, for a certain basic processing circuit, the first number of the third line is sent for the first time, and the data of the third line is sent for the second time. The 2nd number in the 3rd time, the 3rd number of the 3rd line..., or the 1st time to send the first two numbers of the 3rd line, the second time to send the 3rd and 3rd line of the 3rd line 4 numbers, 3rd time sending 3rd line 5th and 6th numbers... ;) In an alternative solution, another situation is that the control circuit of the main processing circuit sends the data of certain convolution kernels in the weights each time a number or a part of the number to a certain basic processing circuit; (for example, for a certain basic processing circuit; A basic processing circuit that sends the first number of lines 3, 4, and 5 for the first time, sends the second number of lines 3, 4, and 5 for the second time, and sends the third number for the third time. The 3rd number of each line of line 4,5..., or the first two numbers of lines 3,4,5 are sent for the first time, and the first two numbers of lines 3,4,5 are sent for the second time The 3rd and 4th numbers, the third time the 3rd, 4th, and 5th lines are sent. The 5th and 6th numbers in each line... ;) The control circuit of the main processing circuit arranges the input data according to the position of the convolution To divide, the control circuit of the main processing circuit sends the data in some or all of the convolution positions in the input data to those basic processing circuits that are directly connected to the main processing circuit through the vertical data input interface (for example, the basic processing circuit in Figure 3b). The gray-filled horizontal data path on the left side of the circuit array); in an alternative, the control circuit of the main processing circuit sends the data of a certain convolution position in the input data one number or part of the number at a time to a certain basic processing circuit ;(For example, for a certain basic processing circuit, the first number in the third column is sent for the first time, the second number in the third column is sent for the second time, and the third number in the third column is sent for the third time. ..., or the first two numbers of column 3 are sent for the first time, the third and fourth numbers of column 3 are sent for the second time, and the fifth and sixth numbers of column 3 are sent for the third time. .....;) In an alternative solution, another situation is that the control circuit of the main processing circuit sends a number or a part of the data at a certain convolution position in the input data to a certain basic processing. Circuit; (For example, for a certain basic processing circuit, the first number of columns 3, 4, and 5 is sent for the first time, and the second number of columns 3, 4, and 5 is sent for the second time. The 3rd time to send the 3rd number of each column of the 3rd, 4th, 5th column..., or the 1st time to send the first two numbers of each column of the 3rd, 4th, and 5th column, and the second time to send the 3rd number of each column ,4,5 columns 3rd and 4th numbers in each column, 3rd send 3rd,4,5th column 5th and 6th numbers in each column... ;) After the basic processing circuit receives the weight data, it transmits the data to the next basic processing circuit connected to it through its horizontal data output interface (for example, the white-filled horizontal data path in the middle of the basic processing circuit array in Figure 3b). ); after the basic processing circuit receives the data of the input data, it transmits the data to the next basic processing circuit connected to it through its vertical data output interface (for example, the white-filled ones in the middle of the basic processing circuit array in FIG. 3b vertical data path); each base processing circuit operates on the data received; in an alternative, the base processing circuit computes the multiplication of one or more sets of two data at a time, and then accumulates the results into a register and/or on-chip cache; in an alternative, the base processing circuit computes the inner product of one or more sets of two vectors at a time, and then accumulates the results into registers and/or on-chip cache; the base processing circuit calculates After the result, the result can be transmitted from the data output interface; in an optional solution, the calculation result can be the final result or the intermediate result of the inner product operation; The connected output interface transmits the result from this interface, if not, it outputs the result in the direction of the basic processing circuit that can output directly to the main processing circuit (for example, in Figure 3b, the basic processing circuit in the bottom row outputs its output result directly. To the main processing circuit, other basic processing circuits transmit the operation results downward from the vertical output interface).

基礎處理電路接收到來自其他基礎處理電路的計算結果之後,將該數據傳輸給與其相連接的其他基礎處理電路或者主處理電路; 向著能夠直接向主處理電路輸出的方向輸出結果(例如,最下面一行基礎處理電路將其輸出結果直接輸出給主處理電路,其他基礎處理電路從竪向的輸出介面向下傳輸運算結果);主處理電路接收到各個基礎處理電路內積運算的結果,即可得到輸出結果。 After the basic processing circuit receives the calculation results from other basic processing circuits, it transmits the data to other basic processing circuits or main processing circuits connected to it; Output the results in a direction that can be directly output to the main processing circuit (for example, the basic processing circuits in the bottom row directly output their output results to the main processing circuit, and other basic processing circuits transmit the operation results downward from the vertical output interface); The processing circuit receives the result of the inner product operation of each basic processing circuit, and then the output result can be obtained.

參閱圖4a,圖4a為一種矩陣乘以矩陣的運算,如所述第一運算為:矩陣乘矩陣運算,所述輸入數據為所述矩陣乘矩陣運算的第一矩陣,所述權值為所述矩陣乘矩陣運算的第二矩陣;第一複雜度=β*F1*G*E*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為第一矩陣的行、列值,E、F2為第二矩陣的行、列值;如所述第一複雜度大於設定閾值,確定該第一矩陣以及第二矩陣是否為浮點數據,如該第一矩陣以及第二矩陣不為浮點數據,將該第一矩陣轉換成浮點數據,將第二矩陣轉換成浮點數據,然後將第一矩陣、第二矩陣以浮點數據類型執行矩陣乘矩陣運算。 Referring to FIG. 4a, FIG. 4a is a matrix-by-matrix operation. For example, the first operation is: a matrix-by-matrix operation, the input data is the first matrix of the matrix-by-matrix operation, and the weight is The second matrix of the matrix multiplication matrix operation; the first complexity=β*F1*G*E*F2; wherein, β is the matrix coefficient, the value range is greater than or equal to 1, F1, G are the rows of the first matrix, Column value, E and F2 are the row and column values of the second matrix; if the first complexity is greater than the set threshold, determine whether the first matrix and the second matrix are floating-point data, such as the first matrix and the first matrix. The second matrix is not floating point data, convert the first matrix to floating point data, convert the second matrix to floating point data, and then perform matrix multiplication of the first matrix and the second matrix with floating point data type Matrix Operations.

參閱圖4b,使用如圖3b所示的裝置完成矩陣乘矩陣的運算;下面描述計算尺寸是M行L列的矩陣S和尺寸是L行N列的矩陣P的乘法的運算,(矩陣S中的每一行與矩陣P的每一列長度相同,如圖2d所示)所述神經網絡計算裝置擁有K個基礎處理電路: Referring to Figure 4b, use the device as shown in Figure 3b to complete the operation of matrix multiplication matrix; Describe below the calculation size is the operation of the multiplication of the matrix S of M rows and L columns and the size of the matrix P of L rows and N columns, (in the matrix S Each row of is the same length as each column of matrix P, as shown in Figure 2d) The neural network computing device has K basic processing circuits:

步驟S401b、主處理電路在如第一複雜度大於設定閾值時,將矩陣S和矩陣P轉換成定點類型數據,主處理電路的控制電路將矩陣S中的每一行數據分發到K個基礎處理電路中的某一個上,基礎處理電路將接收到的數 據保存在片上緩存和/或寄存器中;具體的,可以發送至K個基礎處理電路中與主處理電路連接的基礎處理電路。 Step S401b, the main processing circuit converts the matrix S and the matrix P into fixed-point type data when the first complexity is greater than the set threshold, and the control circuit of the main processing circuit distributes each row of data in the matrix S to K basic processing circuits On one of these, the underlying processing circuit will receive the number of The data is stored in the on-chip cache and/or register; specifically, it can be sent to the basic processing circuit connected to the main processing circuit among the K basic processing circuits.

在一種可選方案中,如果S的行數M<=K則,主處理電路的控制電路給M個基礎處理電路分別分發S矩陣的一行;在一種可選方案中,如果S的行數M>K,主處理電路的控制電路給每個基礎處理電路分別分發S矩陣中一行或多行的數據。 In an alternative solution, if the number of rows of S is M<=K, the control circuit of the main processing circuit distributes a row of the S matrix to the M basic processing circuits respectively; in an alternative solution, if the number of rows of S is M >K, the control circuit of the main processing circuit distributes data of one or more rows in the S matrix to each basic processing circuit.

S中有Mi行分發到第i個基礎處理電路,這Mi行的集合稱為Ai,如圖2e表示第i個基礎處理電路上將要執行的計算。 There are Mi rows in S that are distributed to the i-th basic processing circuit, and the set of Mi rows is called Ai. Figure 2e shows the computation to be performed on the i-th basic processing circuit.

在一種可選方案中,在每個基礎處理電路中,例如第i個基礎處理電路中:接收的由主處理電路分發的矩陣Ai,將矩陣Ai保存在第i個基礎處理電路寄存器和/或片上緩存中;優點是減少了之後的數據傳輸量,提高了計算效率,降低了功耗。 In an optional solution, in each basic processing circuit, such as the ith basic processing circuit: the received matrix Ai distributed by the main processing circuit is stored in the ith basic processing circuit register and/or In the on-chip cache; the advantage is that the amount of subsequent data transmission is reduced, the computing efficiency is improved, and the power consumption is reduced.

步驟S402b、主處理電路的控制電路將矩陣P中各部分以廣播的方式傳輸給各個基礎處理電路;在一種可選方案中,可以將矩陣P中各部分只廣播一次到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對這一次得到的矩陣P的數據進行充分地復用,完成對應與矩陣Ai中每一行的內積運算;本實施例中的復用具體可以為基礎處理電路在計算中重復使用,例如矩陣P的數據的復用,可以是對矩陣P的數據在多次使用。 In step S402b, the control circuit of the main processing circuit transmits each part in the matrix P to each basic processing circuit by broadcasting; in an optional solution, each part in the matrix P can be broadcast only once to the registers of each basic processing circuit Or in the on-chip cache, the i-th basic processing circuit fully multiplexes the data of the matrix P obtained this time, and completes the inner product operation corresponding to each row in the matrix Ai; the multiplexing in this embodiment can be based on The processing circuit is used repeatedly in the calculation, for example, the multiplexing of the data of the matrix P may be used for the data of the matrix P multiple times.

在一種可選方案中,主處理電路的控制電路可以將矩陣P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電 路對每次得到的矩陣P的數據不進行復用,分次完成對應於矩陣Ai中的每一行的內積運算;在一種可選方案中,主處理電路的控制電路可以將矩陣P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的矩陣P的數據進行部分復用,完成對應於矩陣Ai中的每一行的內積運算;在一種可選方案中,每個基礎處理電路,例如第i個基礎處理電路,計算矩陣Ai的數據和矩陣P的數據的內積; In an optional solution, the control circuit of the main processing circuit may broadcast each part of the matrix P to the registers or the on-chip cache of each basic processing circuit for many times, and the i-th basic processing circuit The data of the matrix P obtained each time is not multiplexed, and the inner product operation corresponding to each row in the matrix Ai is completed in stages; in an optional solution, the control circuit of the main processing circuit can The part is broadcast to the registers or on-chip cache of each basic processing circuit for many times, and the i-th basic processing circuit performs partial multiplexing on the data of the matrix P obtained each time, and completes the inner product operation corresponding to each row in the matrix Ai; In an optional solution, each basic processing circuit, such as the ith basic processing circuit, calculates the inner product of the data of the matrix Ai and the data of the matrix P;

步驟S403b、每個基礎處理電路的累加器電路將內積運算的結果進行累加並傳輸回主處理電路。 Step S403b, the accumulator circuit of each basic processing circuit accumulates the result of the inner product operation and transmits it back to the main processing circuit.

在一種可選方案中,基礎處理電路可以將每次執行內積運算得到的部分和傳輸回主處理電路進行累加;在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和保存在基礎處理電路的寄存器和/或片上緩存中,累加結束之後傳輸回主處理電路;在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和在部分情況下保存在基礎處理電路的寄存器和/或片上緩存中進行累加,部分情況下傳輸到主處理電路進行累加,累加結束之後傳輸回主處理電路。 In an optional solution, the basic processing circuit may transmit the partial sums obtained by performing the inner product operation each time back to the main processing circuit for accumulation; in an optional solution, the inner product operation performed by the basic processing circuit each time may also be The obtained partial sum is stored in the register and/or on-chip cache of the basic processing circuit, and is transmitted back to the main processing circuit after the accumulation; In some cases, the sum is stored in the register and/or on-chip cache of the basic processing circuit for accumulation, and in some cases, it is transmitted to the main processing circuit for accumulation, and is transmitted back to the main processing circuit after the accumulation is completed.

參閱圖4c,為一種矩陣乘以向量的運算示意圖。如所述第一運算為:矩陣乘向量運算,所述輸入數據為所述矩陣乘向量運算的第一矩陣,所述權值為所述矩陣乘向量運算的向量; 第一複雜度=β*F1*G*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為第一矩陣的行、列值,F2為向量的列值;如所述第一複雜度大於設定閾值,確定該第一矩陣以及向量是否為浮點數據,如該第一矩陣以及向量不為浮點數據,將該第一矩陣轉換成浮點數據,將向量轉換成浮點數據,然後將第一矩陣、向量以浮點數據類型執行矩陣乘向量運算。 Referring to FIG. 4c, it is a schematic diagram of an operation of multiplying a matrix by a vector. If the first operation is: matrix multiplication vector operation, the input data is the first matrix of the matrix multiplication vector operation, and the weight value is the vector of the matrix multiplication vector operation; The first complexity=β*F1*G*F2; where, β is the matrix coefficient, the value range is greater than or equal to 1, F1, G are the row and column values of the first matrix, and F2 is the column value of the vector; If the first complexity is greater than the set threshold, determine whether the first matrix and vector are floating-point data, if the first matrix and vector are not floating-point data, convert the first matrix into floating-point data, and convert The vector is converted into floating point data, and then a matrix multiplication vector operation is performed on the first matrix, the vector, with the floating point data type.

參閱圖4d,圖4d提供了了一種矩陣乘向量的實現方法,具體可以包括: Referring to Figure 4d, Figure 4d provides an implementation method of multiplying a matrix by a vector, which may specifically include:

步驟S401、主處理電路的數據轉換運算電路將矩陣S中的每一行數據轉換成定點類型的數據,主處理電路的控制電路分發到K個基礎處理電路中的某一個上,基礎處理電路將接收到的分發數據保存在基礎處理電路的片上緩存和/或寄存器中;在一種可選方案中,如果矩陣S的行數M<=K則,主處理電路的控制電路給K個基礎處理電路分別分發S矩陣的一行;在一種可選方案中,如果矩陣S的行數M>K,則主處理電路的控制電路給每個基礎處理電路分別分發S矩陣中一行或多行的數據。 Step S401, the data conversion operation circuit of the main processing circuit converts each row of data in the matrix S into fixed-point data, the control circuit of the main processing circuit distributes it to one of the K basic processing circuits, and the basic processing circuit will receive the data. The received distribution data is stored in the on-chip cache and/or register of the basic processing circuit; in an optional solution, if the number of rows M<=K of the matrix S, the control circuit of the main processing circuit gives the K basic processing circuits respectively. Distribute one row of the S matrix; in an optional solution, if the number of rows of the matrix S M>K, the control circuit of the main processing circuit distributes the data of one or more rows in the S matrix to each basic processing circuit.

分發到第i個基礎處理電路的S中的行的集合為Ai,共有Mi個行,如圖2c表示第i個基礎處理電路上將要執行的計算。 The set of rows in S distributed to the i-th basic processing circuit is Ai, and there are Mi rows in total. Figure 2c shows the computation to be performed on the i-th basic processing circuit.

在一種可選方案中,在每個基礎處理電路中,例如第i個基礎處理電路中,可以將接收到的分發數據例如矩陣Ai保存在第i個基礎處理電路的寄存器和/或片上緩存中;優點是減少了之後的分發數據的數據傳輸量,提高了計算效率,降低了功耗。 In an optional solution, in each basic processing circuit, such as the ith basic processing circuit, the received distribution data, such as the matrix Ai, may be stored in a register and/or an on-chip cache of the ith basic processing circuit ; The advantage is that the data transmission amount of the distributed data is reduced, the calculation efficiency is improved, and the power consumption is reduced.

步驟S402、主處理電路的數據類型運算電路將向量P轉換成定點類型的數據,主處理電路的控制電路將定點類型的向量P中各部分以廣播的方式傳輸給K個基礎處理電路;在一種可選方案中,主處理電路的控制電路可以將向量P中各部分只廣播一次到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對這一次得到的向量P的數據進行充分地復用,完成對應與矩陣Ai中每一行的內積運算。優點是,減少從主處理電路到基礎處理電路的向量P的重復傳輸的數據傳輸量,提高執行效率,降低傳輸功耗。 Step S402, the data type operation circuit of the main processing circuit converts the vector P into fixed-point type data, and the control circuit of the main processing circuit transmits each part of the fixed-point type vector P to K basic processing circuits by broadcasting; In an alternative solution, the control circuit of the main processing circuit can broadcast each part of the vector P only once to the registers or the on-chip cache of each basic processing circuit, and the i-th basic processing circuit can fully perform the data of the vector P obtained this time. Ground multiplexing to complete the inner product operation corresponding to each row in the matrix Ai. The advantage is that the data transmission amount of the repeated transmission of the vector P from the main processing circuit to the basic processing circuit is reduced, the execution efficiency is improved, and the transmission power consumption is reduced.

在一種可選方案中,主處理電路的控制電路可以將向量P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的向量P的數據不進行復用,分次完成對應於矩陣Ai中的每一行的內積運算;優點是,減少基礎處理電路內部的單次傳輸的向量P的數據傳輸量,並可以降低基礎處理電路緩存和/或寄存器的容量,提高執行效率,降低傳輸功耗,降低成本。 In an optional solution, the control circuit of the main processing circuit can broadcast each part of the vector P to the registers or the on-chip cache of each basic processing circuit for multiple times, and the i-th basic processing circuit can evaluate the data of the vector P obtained each time. No multiplexing is performed, and the inner product operation corresponding to each row in the matrix Ai is completed in stages; the advantage is that the data transmission amount of the vector P transmitted in a single transmission inside the basic processing circuit can be reduced, and the basic processing circuit cache and/or can be reduced. Or the capacity of the register, improve the execution efficiency, reduce the transmission power consumption, and reduce the cost.

在一種可選方案中,主處理電路的控制電路可以將向量P中各部分多次廣播到各個基礎處理電路的寄存器或者片上緩存中,第i個基礎處理電路對每次得到的向量P的數據進行部分復用,完成對應於矩陣Ai中的每一行的內積運算;優點是,減少從主處理電路到基礎處理電路的數據傳輸量,也減少基礎處理電路內部的數據傳輸量,提高執行效率,降低傳輸功耗。 In an optional solution, the control circuit of the main processing circuit can broadcast each part of the vector P to the registers or the on-chip cache of each basic processing circuit for multiple times, and the i-th basic processing circuit can evaluate the data of the vector P obtained each time. Partial multiplexing is performed to complete the inner product operation corresponding to each row in the matrix Ai; the advantage is that it reduces the amount of data transmission from the main processing circuit to the basic processing circuit, and also reduces the amount of data transmission inside the basic processing circuit, improving execution efficiency. , reduce the transmission power consumption.

步驟S403、K個基礎處理電路的內積運算器電路計算矩陣S和向量P的數據的內積,例如第i個基礎處理電路,計算矩陣Ai的數據和向量P的數據的內積; Step S403, the inner product operator circuit of the K basic processing circuits calculates the inner product of the data of the matrix S and the vector P, such as the i-th basic processing circuit, calculates the inner product of the data of the matrix Ai and the data of the vector P;

步驟S404、K個基礎處理電路的累加器電路將內積運算的結果進行累加得到累加結果,將累加結果以定點類型形式傳輸回主處理電路。 Step S404 , the accumulator circuits of the K basic processing circuits accumulate the results of the inner product operation to obtain an accumulation result, and transmit the accumulation result back to the main processing circuit in the form of a fixed-point type.

在一種可選方案中,可以將每次基礎處理電路執行內積運算得到的部分和(部分和即累加結果的一部分,例如累加結果為:F1*G1+F2*G2+F3*G3+F4*G4+F5*G5,那麼部分和可以為:F1*G1+F2*G2+F3*G3的值)傳輸回主處理電路進行累加;優點是,減少了基礎處理電路內部的運算量,提高基礎處理電路的運算效率。 In an optional solution, the partial sum (the partial sum is a part of the accumulated result) obtained by each time the basic processing circuit performs the inner product operation, for example, the accumulated result is: F1*G1+F2*G2+F3*G3+F4* G4+F5*G5, then the partial sum can be: the value of F1*G1+F2*G2+F3*G3) is transmitted back to the main processing circuit for accumulation; the advantage is that it reduces the amount of operations inside the basic processing circuit and improves the basic processing The operational efficiency of the circuit.

在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和保存在基礎處理電路的寄存器和/或片上緩存中,累加結束之後傳輸回主處理電路;優點是,減少了基礎處理電路和主處理電路之間的數據傳輸量,提高了運算效率,降低了數據傳輸功耗。 In an optional solution, the partial sum obtained by the inner product operation performed by the basic processing circuit each time can also be stored in the register and/or the on-chip cache of the basic processing circuit, and transferred back to the main processing circuit after the accumulation is completed; the advantage is that, The data transmission amount between the basic processing circuit and the main processing circuit is reduced, the operation efficiency is improved, and the power consumption of data transmission is reduced.

在一種可選方案中,也可以將每次基礎處理電路執行的內積運算得到的部分和在部分情況下保存在基礎處理電路的寄存器和/或片上緩存中進行累加,部分情況下傳輸到主處理電路進行累加,累加結束之後傳輸回主處理電路;優點是,減少了基礎處理電路和主處理電路之間的數據傳輸量,提高了運算效率,降低了數據傳輸功耗,減少了基礎處理電路內部的運算量,提高基礎處理電路的運算效率。 In an optional solution, the partial sum obtained by the inner product operation performed by the basic processing circuit each time can also be stored in the register and/or on-chip cache of the basic processing circuit for accumulation in some cases, and transferred to the main The processing circuit performs accumulation, and after the accumulation is completed, it is transmitted back to the main processing circuit; the advantage is that the amount of data transmission between the basic processing circuit and the main processing circuit is reduced, the operation efficiency is improved, the power consumption of data transmission is reduced, and the basic processing circuit is reduced. The amount of internal operation improves the operation efficiency of the basic processing circuit.

本披露還提供一種集成電路晶片裝置,所述集成電路晶片裝置用於執行神經網絡的正向運算,所述神經網絡包含多層,所述裝置包括:處理電路以及外部介面;所述外部介面,用於接收第一計算指令; 所述處理電路,用於解析第一計算指令得到所述第一計算指令在所述正向運算的第i層包含的第一運算、第一計算指令對應的輸入數據以及權值數據;上述i的取值可以為1,如為1時,其輸入數據可以為原始輸入數據,當i大於等於2時,該輸入數據可以為上一層的輸出數據,例如i-1層的輸出數據。 The present disclosure also provides an integrated circuit chip device, the integrated circuit chip device is used to perform forward operation of a neural network, the neural network includes multiple layers, and the device includes: a processing circuit and an external interface; upon receiving the first calculation instruction; The processing circuit is configured to parse the first calculation instruction to obtain the first calculation included in the i-th layer of the forward operation, the input data and weight data corresponding to the first calculation instruction; the i The value of can be 1. If it is 1, the input data can be the original input data. When i is greater than or equal to 2, the input data can be the output data of the previous layer, such as the output data of the i-1 layer.

所述處理電路,還用於依據該輸入數據、權值數據以及第一運算確定第一運算的第一複雜度,依據所述第一複雜度確定該輸入數據以及權值數據在執行第一運算時的第一數據類型,所述第一數據類型包括:浮點類型或定點類型;所述處理電路,還用於將輸入數據以及權值數據以第一數據類型執行所述正向運算的第i層包含的第一運算。 The processing circuit is further configured to determine the first complexity of the first operation according to the input data, the weight data and the first operation, and determine that the input data and the weight data are performing the first operation according to the first complexity The first data type at the time, the first data type includes: floating-point type or fixed-point type; the processing circuit is further configured to perform the first data type of the forward operation on the input data and the weight data in the first data type The first operation contained in layer i.

本披露還揭露了一個神經網絡運算裝置,其包括一個或多個在如圖3a或如圖3b所示的晶片,用於從其他處理裝置中獲取待運算數據和控制信息,執行指定的神經網絡運算,執行結果通過I/O介面傳遞給外圍設備。外圍設備譬如攝像頭,顯示器,鼠標,鍵盤,網卡,wifi介面,服務器。當包含一個以上神如圖3a或如圖3b所示的晶片時,如圖3a或如圖3b所示的晶片間可以通過特定的結構進行鏈接並傳輸數據,譬如,通過PCIE總線進行互聯並傳輸數據,以支持更大規模的神經網絡的運算。此時,可以共享同一控制系統,也可以有各自獨立的控制系統;可以共享內存,也可以每個加速器有各自的內存。此外,其互聯方式可以是任意互聯拓撲。 The present disclosure also discloses a neural network computing device, which includes one or more chips as shown in FIG. 3a or FIG. 3b, for obtaining data to be computed and control information from other processing devices, and executing a specified neural network Operation, the execution result is passed to the peripheral device through the I/O interface. Peripherals such as camera, monitor, mouse, keyboard, network card, wifi interface, server. When more than one chip as shown in Figure 3a or Figure 3b is included, the chips shown in Figure 3a or Figure 3b can be linked and transmitted through a specific structure, for example, interconnected and transmitted through the PCIE bus data to support larger-scale neural network operations. At this time, the same control system can be shared, or there can be independent control systems; memory can be shared, or each accelerator can have its own memory. In addition, the interconnection method can be any interconnection topology.

該神經網絡運算裝置具有較高的兼容性,可通過PCIE介面與各種類型的服務器相連接。 The neural network computing device has high compatibility and can be connected with various types of servers through the PCIE interface.

本披露還揭露了一個組合處理裝置,其包括上述的神經網絡運算裝置,通用互聯介面,和其他處理裝置(即通用處理裝置)。神經網絡運算裝置與其他處理裝置進行交互,共同完成用戶指定的操作。如5a為組合處理裝置的示意圖。 The present disclosure also discloses a combined processing device, which includes the above-mentioned neural network computing device, a universal interconnection interface, and other processing devices (ie, general-purpose processing devices). The neural network computing device interacts with other processing devices to jointly complete the operation specified by the user. Such as 5a is a schematic diagram of the combined treatment device.

其他處理裝置,包括中央處理器CPU、圖形處理器GPU、神經網絡處理器等通用/專用處理器中的一種或以上的處理器類型。其他處理裝置所包括的處理器數量不做限制。其他處理裝置作為神經網絡運算裝置與外部數據和控制的介面,包括數據搬運,完成對本神經網絡運算裝置的開啟、停止等基本控制;其他處理裝置也可以和神經網絡運算裝置協作共同完成運算任務。 Other processing devices include one or more processor types among general-purpose/special-purpose processors such as a central processing unit (CPU), a graphics processing unit (GPU), and a neural network processor. The number of processors included in other processing devices is not limited. Other processing devices serve as the interface between the neural network computing device and external data and control, including data transfer, to complete the basic control of starting and stopping the neural network computing device; other processing devices can also cooperate with the neural network computing device to complete computing tasks.

通用互聯介面,用於在所述神經網絡運算裝置與其他處理裝置間傳輸數據和控制指令。該神經網絡運算裝置從其他處理裝置中獲取所需的輸入數據,寫入神經網絡運算裝置片上的存儲裝置;可以從其他處理裝置中獲取控制指令,寫入神經網絡運算裝置片上的控制緩存;也可以讀取神經網絡運算裝置的存儲模塊中的數據並傳輸給其他處理裝置。 The universal interconnection interface is used to transmit data and control instructions between the neural network computing device and other processing devices. The neural network computing device obtains the required input data from other processing devices, and writes it into the memory device on-chip of the neural network computing device; it can obtain control instructions from other processing devices and write it into the control cache on the neural network computing device chip; The data in the memory module of the neural network computing device can be read and transmitted to other processing devices.

如圖5b所示,可選的,該結構還包括存儲裝置,用於保存在本運算單元/運算裝置或其他運算單元所需要的數據,尤其適用於所需要運算的數據在本神經網絡運算裝置或其他處理裝置的內部存儲中無法全部保存的數據。 As shown in Figure 5b, optionally, the structure further includes a storage device for storing the data required by the operation unit/operation device or other operation units, especially suitable for the data required for operation in the neural network operation device. or other data that cannot be fully stored in the internal storage of the processing device.

該組合處理裝置可以作為手機、機器人、無人機、視頻監控設備等設備的SOC片上系統,有效降低控制部分的核心面積,提高處理速度,降 低整體功耗。此情況時,該組合處理裝置的通用互聯介面與設備的某些部件相連接。某些部件譬如攝像頭,顯示器,鼠標,鍵盤,網卡,wifi介面。 The combined processing device can be used as a SOC system for mobile phones, robots, drones, video surveillance equipment and other equipment, effectively reducing the core area of the control part, improving processing speed, reducing Low overall power consumption. In this case, the general interconnection interface of the combined processing device is connected to some components of the device. Some components such as camera, monitor, mouse, keyboard, network card, wifi interface.

請參照圖5c,圖5c為本披露實施例提供的一種神經網絡處理器板卡的結構示意圖。如圖5c所示,上述神經網絡處理器板卡10包括神經網絡晶片封裝結構11、第一電氣及非電氣連接裝置12和第一基板(substrate)13。 Please refer to FIG. 5c, which is a schematic structural diagram of a neural network processor board according to an embodiment of the present disclosure. As shown in FIG. 5 c , the above-mentioned neural network processor board 10 includes a neural network chip package structure 11 , a first electrical and non-electrical connection device 12 and a first substrate 13 .

本披露對於神經網絡晶片封裝結構11的具體結構不作限定,可選的,如圖5d所示,上述神經網絡晶片封裝結構11包括:神經網絡晶片111、第二電氣及非電氣連接裝置112、第二基板113。 The present disclosure does not limit the specific structure of the neural network chip package structure 11. Optionally, as shown in FIG. 5d, the neural network chip package structure 11 includes: a neural network chip 111, a second electrical and non-electrical connection device 112, a first Two substrates 113 .

本披露所涉及的神經網絡晶片111的具體形式不作限定,上述的神經網絡晶片111包含但不限於將神經網絡處理器集成的神經網絡晶片,上述晶片可以由硅材料、鍺材料、量子材料或分子材料等製成。根據實際情況(例如:較嚴苛的環境)和不同的應用需求可將上述神經網絡晶片進行封裝,以使神經網絡晶片的大部分被包裹住,而將神經網絡晶片上的引腳通過金線等導體連到封裝結構的外邊,用於和更外層進行電路連接。 The specific form of the neural network chip 111 involved in the present disclosure is not limited. The above-mentioned neural network chip 111 includes but is not limited to a neural network chip that integrates a neural network processor. The above-mentioned chip can be made of silicon material, germanium material, quantum material or molecular material. materials etc. According to the actual situation (for example: harsh environment) and different application requirements, the above-mentioned neural network chip can be packaged, so that most of the neural network chip is wrapped, and the pins on the neural network chip are passed through gold wires. The other conductors are connected to the outside of the package structure for circuit connection with the outer layers.

本披露對於神經網絡晶片111的具體結構不作限定,可選的,請參照圖1a所示的裝置。 The present disclosure does not limit the specific structure of the neural network chip 111. Optionally, please refer to the device shown in FIG. 1a.

本披露對於第一基板13和第二基板113的類型不做限定,可以是印制電路板(printed circuit board,PCB)或(printed wiring board,PWB),還可能為其它電路板。對PCB的製作材料也不做限定。 The present disclosure does not limit the types of the first substrate 13 and the second substrate 113, which may be a printed circuit board (PCB) or a printed wiring board (PWB), and may also be other circuit boards. The material for making the PCB is also not limited.

本披露所涉及的第二基板113用於承載上述神經網絡晶片111,通過第二電氣及非電氣連接裝置112將上述的神經網絡晶片111和第二基板113進 行連接得到的神經網絡晶片封裝結構11,用於保護神經網絡晶片111,便於將神經網絡晶片封裝結構11與第一基板13進行進一步封裝。 The second substrate 113 involved in the present disclosure is used to carry the above-mentioned neural network chip 111 , and the above-mentioned neural network chip 111 and the second substrate 113 are connected to each other through the second electrical and non-electrical connection device 112 . The neural network chip package structure 11 obtained by row connection is used to protect the neural network chip 111 and facilitate further packaging of the neural network chip package structure 11 and the first substrate 13 .

對於上述具體的第二電氣及非電氣連接裝置112的封裝方式和封裝方式對應的結構不作限定,可根據實際情況和不同的應用需求選擇合適的封裝方式並進行簡單地改進,例如:倒裝晶片球柵陣列封裝(Flip Chip Ball Grid Array Package,FCBGAP),薄型四方扁平式封裝(Low-profile Quad Flat Package,LQFP)、帶散熱器的四方扁平封裝(Quad Flat Package with Heat sink,HQFP)、無引腳四方扁平封裝(Quad Flat Non-lead Package,QFN)或小間距四方扁平式封裝(Fine-pitch Ball Grid Package,FBGA)等封裝方式。 The packaging method and the structure corresponding to the packaging method of the above-mentioned specific second electrical and non-electrical connection device 112 are not limited, and an appropriate packaging method can be selected and simply improved according to the actual situation and different application requirements, for example: flip chip Ball Grid Array Package (Flip Chip Ball Grid Array Package, FCBGAP), Low-profile Quad Flat Package (LQFP), Quad Flat Package with Heat Sink (HQFP), None Pin quad flat package (Quad Flat Non-lead Package, QFN) or small pitch quad flat package (Fine-pitch Ball Grid Package, FBGA) and other packaging methods.

倒裝晶片(Flip Chip),適用於對封裝後的面積要求高或對導線的電感、信號的傳輸時間敏感的情況下。除此之外可以用引線鍵合(Wire Bonding)的封裝方式,減少成本,提高封裝結構的靈活性。 Flip Chip is suitable for situations where the area after packaging is high or is sensitive to the inductance of wires and the transmission time of signals. In addition, a wire bonding (Wire Bonding) packaging method can be used to reduce the cost and improve the flexibility of the packaging structure.

球柵陣列(Ball Grid Array),能夠提供更多引腳,且引腳的平均導線長度短,具備高速傳遞信號的作用,其中,封裝可以用引腳網格陣列封裝(Pin Grid Array,PGA)、零插拔力(Zero Insertion Force,ZIF)、單邊接觸連接(Single Edge Contact Connection,SECC)、觸點陣列(Land Grid Array,LGA)等來代替。 Ball Grid Array (Ball Grid Array) can provide more pins, and the average lead length of the pins is short, which has the function of high-speed signal transmission. Among them, the package can be packaged with Pin Grid Array (PGA) , zero insertion force (Zero Insertion Force, ZIF), single edge contact connection (Single Edge Contact Connection, SECC), contact array (Land Grid Array, LGA), etc. instead.

可選的,採用倒裝晶片球柵陣列(Flip Chip Ball Grid Array)的封裝方式對神經網絡晶片111和第二基板113進行封裝,具體的神經網絡晶片封裝結構的示意圖可參照圖6。如圖6所示,上述神經網絡晶片封裝結構包 括:神經網絡晶片21、焊盤22、焊球23、第二基板24、第二基板24上的連接點25、引腳26。 Optionally, the neural network chip 111 and the second substrate 113 are packaged by a flip chip ball grid array (Flip Chip Ball Grid Array). As shown in Figure 6, the above-mentioned neural network chip package structure package It includes: neural network chip 21 , pads 22 , solder balls 23 , second substrate 24 , connection points 25 and pins 26 on the second substrate 24 .

其中,焊盤22與神經網絡晶片21相連,通過在焊盤22和第二基板24上的連接點25之間焊接形成焊球23,將神經網絡晶片21和第二基板24連接,即實現了神經網絡晶片21的封裝。 Wherein, the pad 22 is connected to the neural network chip 21, and solder balls 23 are formed by welding between the pad 22 and the connection point 25 on the second substrate 24, and the neural network chip 21 and the second substrate 24 are connected. Packaging of the neural network chip 21 .

引腳26用於與封裝結構的外部電路(例如,神經網絡處理器板卡10上的第一基板13)相連,可實現外部數據和內部數據的傳輸,便於神經網絡晶片21或神經網絡晶片21對應的神經網絡處理器對數據進行處理。對於引腳的類型和數量本披露也不作限定,根據不同的封裝技術可選用不同的引腳形式,並遵從一定規則進行排列。 The pin 26 is used to connect with the external circuit of the package structure (for example, the first substrate 13 on the neural network processor board 10 ), which can realize the transmission of external data and internal data, and is convenient for the neural network chip 21 or the neural network chip 21 The corresponding neural network processor processes the data. The present disclosure also does not limit the type and quantity of pins, and different pin forms can be selected according to different packaging technologies, and are arranged in accordance with certain rules.

可選的,上述神經網絡晶片封裝結構還包括絕緣填充物,置於焊盤22、焊球23和連接點25之間的空隙中,用於防止焊球與焊球之間產生干擾。 Optionally, the above-mentioned neural network chip package structure further includes insulating fillers, which are placed in the gaps between the pads 22 , the solder balls 23 and the connection points 25 to prevent interference between the solder balls.

其中,絕緣填充物的材料可以是氮化硅、氧化硅或氧氮化硅;干擾包含電磁干擾、電感干擾等。 Wherein, the material of the insulating filler can be silicon nitride, silicon oxide or silicon oxynitride; the interference includes electromagnetic interference, inductive interference and the like.

可選的,上述神經網絡晶片封裝結構還包括散熱裝置,用於散髮神經網絡晶片21運行時的熱量。其中,散熱裝置可以是一塊導熱性良好的金屬片、散熱片或散熱器,例如,風扇。 Optionally, the above-mentioned neural network chip packaging structure further includes a heat dissipation device for dissipating heat during operation of the neural network chip 21 . Wherein, the heat dissipation device may be a metal sheet, a heat sink or a heat sink with good thermal conductivity, such as a fan.

舉例來說,如圖6a所示,神經網絡晶片封裝結構11包括:神經網絡晶片21、焊盤22、焊球23、第二基板24、第二基板24上的連接點25、引腳26、絕緣填充物27、散熱膏28和金屬外殼散熱片29。其中,散熱膏28和金屬外殼散熱片29用於散髮神經網絡晶片21運行時的熱量。 For example, as shown in FIG. 6a, the neural network chip package structure 11 includes: a neural network chip 21, pads 22, solder balls 23, a second substrate 24, connection points 25 on the second substrate 24, pins 26, Insulation filler 27, thermal paste 28 and metal shell heat sink 29. Among them, the heat dissipation paste 28 and the metal shell heat dissipation fins 29 are used to dissipate the heat of the neural network chip 21 during operation.

可選的,上述神經網絡晶片封裝結構11還包括補強結構,與焊盤22連接,且內埋於焊球23中,以增強焊球23與焊盤22之間的連接強度。 Optionally, the above-mentioned neural network chip package structure 11 further includes a reinforcing structure, which is connected to the pads 22 and embedded in the solder balls 23 to enhance the connection strength between the solder balls 23 and the pads 22 .

其中,補強結構可以是金屬線結構或柱狀結構,在此不做限定。 Wherein, the reinforcing structure may be a metal wire structure or a columnar structure, which is not limited herein.

本披露對於第一電氣及非電氣裝置12的具體形式也不作限定,可參照第二電氣及非電氣裝置112的描述,即通過焊接的方式將神經網絡晶片封裝結構11進行封裝,也可以採用連接線連接或插拔方式連接第二基板113和第一基板13的方式,便於後續更換第一基板13或神經網絡晶片封裝結構11。 The present disclosure does not limit the specific form of the first electrical and non-electrical device 12, and reference can be made to the description of the second electrical and non-electrical device 112, that is, the neural network chip package structure 11 is packaged by welding, or a connection can be used. The way of connecting the second substrate 113 and the first substrate 13 by wire connection or plugging is convenient for subsequent replacement of the first substrate 13 or the neural network chip package structure 11 .

可選的,第一基板13包括用於擴展存儲容量的內存單元的介面等,例如:同步動態隨機存儲器(Synchronous Dynamic Random Access Memory,SDRAM)、雙倍速率同步動態隨機存儲器(Double Date Rate SDRAM,DDR)等,通過擴展內存提高了神經網絡處理器的處理能力。 Optionally, the first substrate 13 includes an interface or the like for a memory unit used to expand the storage capacity, for example: a synchronous dynamic random access memory (Synchronous Dynamic Random Access Memory, SDRAM), a double-rate synchronous dynamic random access memory (Double Date Rate SDRAM, DDR), etc., the processing power of the neural network processor is improved by expanding the memory.

第一基板13上還可包括快速外部設備互連總線(Peripheral Component Interconnect-Express,PCI-E或PCIe)介面、小封裝可熱插拔(Small Form-factor Pluggable,SFP)介面、以太網介面、控制器局域網總線(Controller Area Network,CAN)介面等等,用於封裝結構和外部電路之間的數據傳輸,可提高運算速度和操作的便利性。 The first substrate 13 may further include a Peripheral Component Interconnect-Express (PCI-E or PCIe) interface, a Small Form-factor Pluggable (SFP) interface, an Ethernet interface, A controller area network bus (Controller Area Network, CAN) interface, etc., is used for data transmission between the package structure and the external circuit, which can improve the operation speed and the convenience of operation.

將神經網絡處理器封裝為神經網絡晶片111,將神經網絡晶片111封裝為神經網絡晶片封裝結構11,將神經網絡晶片封裝結構11封裝為神經網絡處理器板卡10,通過板卡上的介面(插槽或插芯)與外部電路(例如:計算機主板)進行數據交互,即直接通過使用神經網絡處理器板卡10實現 神經網絡處理器的功能,並保護神經網絡晶片111。且神經網絡處理器板卡10上還可添加其他模塊,提高了神經網絡處理器的應用範圍和運算效率。 The neural network processor is packaged as a neural network chip 111, the neural network chip 111 is packaged into a neural network chip package structure 11, and the neural network chip package structure 11 is packaged as a neural network processor board 10, through the interface ( socket or ferrule) for data interaction with external circuits (such as computer motherboards), that is, directly through the use of the neural network processor board 10 The function of the neural network processor and protect the neural network chip 111. In addition, other modules can be added to the neural network processor board 10, which improves the application scope and operation efficiency of the neural network processor.

在一個實施例里,本公開公開了一個電子裝置,其包括了上述神經網絡處理器板卡10或神經網絡晶片封裝結構11。 In one embodiment, the present disclosure discloses an electronic device including the above-mentioned neural network processor board 10 or neural network chip package structure 11 .

電子裝置包括數據處理裝置、機器人、電腦、打印機、掃描儀、平板電腦、智能終端、手機、行車記錄儀、導航儀、傳感器、攝像頭、服務器、相機、攝像機、投影儀、手錶、耳機、移動存儲、可穿戴設備、交通工具、家用電器、和/或醫療設備。 Electronic devices include data processing devices, robots, computers, printers, scanners, tablet computers, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, servers, cameras, video cameras, projectors, watches, headphones, mobile storage , wearable devices, vehicles, home appliances, and/or medical devices.

所述交通工具包括飛機、輪船和/或車輛;所述家用電器包括電視、空調、微波爐、冰箱、電飯煲、加濕器、洗衣機、電燈、燃氣灶、油煙機;所述醫療設備包括核磁共振儀、B超儀和/或心電圖儀。 The vehicles include airplanes, ships and/or vehicles; the household appliances include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, electric lamps, gas stoves, and range hoods; the medical equipment includes nuclear magnetic resonance device, B-ultrasound and/or electrocardiograph.

以上所述的具體實施例,對本披露的目的、技術方案和有益效果進行了進一步詳細說明,所應理解的是,以上所述僅為本披露的具體實施例而已,並不用於限制本披露,凡在本披露的精神和原則之內,所做的任何修改、等同替換、改進等,均應包含在本披露的保護範圍之內。 The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present disclosure in further detail. It should be understood that the above are only specific embodiments of the present disclosure, and are not intended to limit the present disclosure. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this disclosure shall be included within the protection scope of this disclosure.

Claims (18)

一種集成電路晶片裝置上執行的神經網絡正向運算方法,該神經網絡包含多層,其中,該方法包括如下步驟:接收第一計算指令,解析該第一計算指令得到該第一計算指令在正向運算的第i層包含的第一運算以及該第一計算指令對應的一輸入數據以及一權值數據,該i的取值範圍為大於等於1的整數,如該i大於等於2,該輸入數據為第i-1層的輸出數據;依據該輸入數據、該權值數據以及第一運算確定第一運算的第一複雜度,依據該第一複雜度確定該輸入數據以及該權值數據在執行第一運算時的第一數據類型,該第一數據類型包括:浮點類型或定點類型;將該輸入數據以及該權值數據以該第一數據類型執行該正向運算的第i層包含的第一運算。 A neural network forward computing method executed on an integrated circuit chip device, the neural network includes multiple layers, wherein the method includes the following steps: receiving a first calculation instruction, parsing the first calculation instruction to obtain that the first calculation instruction is in the forward direction The first operation included in the i-th layer of the operation and an input data and a weight data corresponding to the first calculation instruction, the value range of the i is an integer greater than or equal to 1, if the i is greater than or equal to 2, the input data is the output data of the i-1th layer; the first complexity of the first operation is determined according to the input data, the weight data and the first operation, and the input data and the weight data are determined according to the first complexity during execution The first data type during the first operation, the first data type includes: floating-point type or fixed-point type; the input data and the weight data are included in the i-th layer that performs the forward operation with the first data type first operation. 根據申請專利範圍第1項的方法,其中,依據該第一複雜度確定該輸入數據以及該權值數據在執行第一運算時的第一數據類型,包括:將該第一複雜度與一預設閾值比較,如該第一複雜度高於該預設閾值,確定該第一數據類型為定點類型,如該第一複雜度低於或等於該預設閾值,確定該第一數據類型為浮點類型。 The method according to claim 1, wherein determining the first data type of the input data and the weight data when performing the first operation according to the first complexity includes: combining the first complexity with a predetermined Set a threshold for comparison, if the first complexity is higher than the preset threshold, determine that the first data type is a fixed-point type, if the first complexity is lower than or equal to the preset threshold, determine that the first data type is floating point type. 根據申請專利範圍第2項的方法,其中,該方法在該依據該第一複雜度確定該輸入數據以及該權值數據在執行第一運算時的第一數據類型之後還包括:確定該輸入數據以及該權值數據屬於第二數據類型,如該第二數據類型與該第一數據類型不同,將屬於第二數據類型的該輸入數據以及屬於第二數據類 型的該權值數據轉換成屬於第一數據類型的該輸入數據以及屬於第一數據類型的該權值數據。 The method according to claim 2, wherein after determining the first data type of the input data and the weight data when the first operation is performed according to the first complexity, the method further comprises: determining the input data And the weight data belongs to a second data type, if the second data type is different from the first data type, the input data belonging to the second data type and the second data type The weight data of the type is converted into the input data of the first data type and the weight data of the first data type. 根據申請專利範圍第1項的方法,其中,如該第一運算為卷積運算,該輸入數據為一卷積輸入數據,該權值數據為一卷積核,第一複雜度=α*C*kW*kH*M*N*W*C*H;其中,α為卷積系數,取值範圍為大於1;C、kW、kH、M為該卷積核四個維度的值,N、W、C、H為該卷積輸入數據四個維度的值;如該第一複雜度大於一設定閾值,確定該卷積輸入數據以及該卷積核是否為浮點數據,如該卷積輸入數據以及該卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將該卷積核轉換成浮點數據,然後將該卷積輸入數據、該卷積核以浮點數據類型執行卷積運算。 The method according to claim 1, wherein, if the first operation is a convolution operation, the input data is a convolution input data, the weight data is a convolution kernel, and the first complexity=α*C *kW*kH*M*N*W*C*H; among them, α is the convolution coefficient, the value range is greater than 1; C, kW, kH, M are the values of the four dimensions of the convolution kernel, N, W, C, and H are the values of the four dimensions of the convolution input data; if the first complexity is greater than a set threshold, determine whether the convolution input data and the convolution kernel are floating-point data, such as the convolution The input data and the convolution kernel are not floating-point data, the convolution input data is converted into floating-point data, the convolution kernel is converted into floating-point data, and then the convolution input data, the convolution The kernel performs convolution operations with floating point data types. 根據申請專利範圍第1項的方法,其中,如該第一運算為一矩陣乘矩陣運算,該輸入數據為該矩陣乘矩陣運算的第一矩陣,該權值為該矩陣乘矩陣運算的第二矩陣;第一複雜度=β*F1*G*E*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為該第一矩陣的行、列值,E、F2為該第二矩陣的行、列值;如該第一複雜度大於一設定閾值,確定該第一矩陣以及第二矩陣是否為浮點數據,如該第一矩陣以及第二矩陣不為浮點數據,將該第一矩陣轉換成浮點數據,將該第二矩陣轉換成浮點數據,然後將該第一矩陣、該第二矩陣以浮點數據類型執行矩陣乘矩陣運算。 The method according to claim 1, wherein, if the first operation is a matrix-by-matrix operation, the input data is the first matrix of the matrix-by-matrix operation, and the weight is the second of the matrix-by-matrix operation. Matrix; first complexity=β*F1*G*E*F2; where, β is the matrix coefficient, the value range is greater than or equal to 1, F1, G are the row and column values of the first matrix, E, F2 are The row and column values of the second matrix; if the first complexity is greater than a preset threshold, determine whether the first matrix and the second matrix are floating point data, such as the first matrix and the second matrix are not floating point data data, convert the first matrix into floating-point data, convert the second matrix into floating-point data, and then perform a matrix-matrix-matrix operation on the first matrix and the second matrix in the floating-point data type. 根據申請專利範圍第1項的方法,其中,如該第一運算為一矩陣乘向量運算,該輸入數據為該矩陣乘向量運算的第一矩陣,該權值為該矩陣乘向量運算的向量;第一複雜度=β*F1*G*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為該第一矩陣的行、列值,F2為該向量的列值;如該第一複雜度大於一設定閾值,確定該第一矩陣以及該向量是否為浮點數據,如該第一矩陣以及該向量不為浮點數據,將該第一矩陣轉換成浮點數據,將該向量轉換成浮點數據,然後將該第一矩陣、該向量以浮點數據類型執行矩陣乘向量運算。 The method according to claim 1, wherein, if the first operation is a matrix multiplication vector operation, the input data is the first matrix of the matrix multiplication vector operation, and the weight value is the vector of the matrix multiplication vector operation; The first complexity=β*F1*G*F2; wherein, β is the matrix coefficient, the value range is greater than or equal to 1, F1, G are the row and column values of the first matrix, and F2 is the column value of the vector; If the first complexity is greater than a set threshold, determine whether the first matrix and the vector are floating-point data; if the first matrix and the vector are not floating-point data, convert the first matrix to floating-point data data, convert the vector to floating-point data, and then perform a matrix-multiply-vector operation on the first matrix, the vector, in the floating-point data type. 根據申請專利範圍第1-6項任意一項的方法,其中,該第i層還包括:偏置運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。 The method according to any one of items 1 to 6 in the scope of the patent application, wherein the i-th layer further includes one or any combination of bias operation, full connection operation, GEMM operation, GEMV operation, and activation operation. 一種集成電路晶片裝置,其中,該集成電路晶片裝置用於執行神經網絡的正向運算,該神經網絡包含多層,該裝置包括:處理電路以及外部介面;該外部介面,用於接收第一計算指令;該處理電路,用於解析該第一計算指令得到該第一計算指令在正向運算的第i層包含的第一運算、該第一計算指令對應的一輸入數據以及一權值數據,該i的取值範圍為大於等於1的整數,如該i大於等於2,該輸入數據為第i-1層的輸出數據; 該處理電路,還用於依據該輸入數據、該權值數據以及第一運算確定第一運算的第一複雜度,依據該第一複雜度確定該輸入數據以及該權值數據在執行第一運算時的第一數據類型,該第一數據類型包括:浮點類型或定點類型;該處理電路,還用於將該輸入數據以及該權值數據以該第一數據類型執行該正向運算的第一層包含的第一運算。 An integrated circuit chip device, wherein the integrated circuit chip device is used to perform forward operation of a neural network, the neural network includes multiple layers, the device includes: a processing circuit and an external interface; the external interface is used for receiving a first calculation instruction ; The processing circuit is used to analyze the first calculation instruction to obtain the first operation that the first calculation instruction includes in the i-th layer of the forward operation, an input data corresponding to the first calculation instruction and a weight data, the The value range of i is an integer greater than or equal to 1, if the i is greater than or equal to 2, the input data is the output data of the i-1th layer; The processing circuit is further configured to determine the first complexity of the first operation according to the input data, the weight data and the first operation, and determine that the input data and the weight data are performing the first operation according to the first complexity The first data type at the time, the first data type includes: floating-point type or fixed-point type; the processing circuit is further configured to perform the first data type of the forward operation on the input data and the weight data with the first data type The first operation that a layer contains. 根據申請專利範圍第8項的集成電路晶片裝置,其中,該處理電路,具體用於將該第一複雜度與一預設閾值比較,如該第一複雜度高於該預設閾值,計算裝置確定該第一數據類型為定點類型,如該第一複雜度低於或等於該預設閾值,計算裝置確定該第一數據類型為浮點類型。 The integrated circuit chip device according to claim 8, wherein the processing circuit is specifically configured to compare the first complexity with a preset threshold, and if the first complexity is higher than the preset threshold, the computing device It is determined that the first data type is a fixed-point type, and if the first complexity is lower than or equal to the preset threshold, the computing device determines that the first data type is a floating-point type. 根據申請專利範圍第9項的集成電路晶片裝置,其中,該集成電路晶片裝置還包括一數據類型轉換電路;該處理電路,還用於確定該輸入數據以及該權值數據屬於的第二數據類型,如該第二數據類型與該第一數據類型不同,向該數據類型轉換電路發送一轉換命令,該數據類型轉換電路,用於依據該轉換命令將屬於第二數據類型的該輸入數據以及屬於第二數據類型的該權值數據轉換成屬於第一數據類型的該輸入數據以及屬於第一數據類型的該權值數據。 The integrated circuit chip device according to claim 9, wherein the integrated circuit chip device further includes a data type conversion circuit; the processing circuit is further configured to determine the second data type to which the input data and the weight data belong , if the second data type is different from the first data type, send a conversion command to the data type conversion circuit, and the data type conversion circuit is used to convert the input data belonging to the second data type and the input data belonging to the second data type according to the conversion command to the data type conversion circuit. The weight data of the second data type is converted into the input data of the first data type and the weight data of the first data type. 根據申請專利範圍第8項的集成電路晶片裝置,其中,如該第一運算為卷積運算,該輸入數據為一卷積輸入數據,該權值數據為一卷積核,該處理電路,用於計算第一複雜度,該第一複雜度=α*C*kW*kH*M*N*W*C*H; 其中,α為卷積系數,取值範圍為大於1;C、kW、kH、M為該卷積核四個維度的值,N、W、C、H為該卷積輸入數據四個維度的值;該處理電路,還用於如該第一複雜度大於設定閾值,確定該卷積輸入數據以及該卷積核是否為浮點數據,如該卷積輸入數據以及該卷積核不為浮點數據,將該卷積輸入數據轉換成浮點數據,將該卷積核轉換成浮點數據,然後將該卷積輸入數據、該卷積核以浮點數據類型執行卷積運算。 The integrated circuit chip device according to claim 8, wherein, if the first operation is a convolution operation, the input data is a convolution input data, the weight data is a convolution kernel, and the processing circuit uses For calculating the first complexity, the first complexity=α*C*kW*kH*M*N*W*C*H; Among them, α is the convolution coefficient, and the value range is greater than 1; C, kW, kH, and M are the values of the four dimensions of the convolution kernel, and N, W, C, and H are the four dimensions of the convolution input data. value; the processing circuit is also used to determine whether the convolution input data and the convolution kernel are floating-point data if the first complexity is greater than a set threshold, if the convolution input data and the convolution kernel are not Floating point data, convert the convolution input data to floating point data, convert the convolution kernel to floating point data, then perform the convolution on the convolution input data, the convolution kernel with the floating point data type Product operation. 根據申請專利範圍第8項的集成電路晶片裝置,其中,如該第一運算為一矩陣乘矩陣運算,該輸入數據為該矩陣乘矩陣運算的第一矩陣,該權值為該矩陣乘矩陣運算的第二矩陣;該處理電路,用於計算第一複雜度;第一複雜度=β*F1*G*E*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為該第一矩陣的行、列值,E、F2為該第二矩陣的行、列值;該處理電路,還用於如該第一複雜度大於一設定閾值,確定該第一矩陣以及該第二矩陣是否為浮點數據,如該第一矩陣以及該第二矩陣不為浮點數據,將該第一矩陣轉換成浮點數據,將該第二矩陣轉換成浮點數據,然後將該第一矩陣、該第二矩陣以浮點數據類型執行矩陣乘矩陣運算。 The integrated circuit chip device according to claim 8, wherein, if the first operation is a matrix-by-matrix operation, the input data is a first matrix of the matrix-by-matrix operation, and the weight is the matrix-by-matrix operation the second matrix of are the row and column values of the first matrix, and E and F2 are the row and column values of the second matrix; the processing circuit is also used to determine the first matrix and the Whether the second matrix is floating-point data, if the first matrix and the second matrix are not floating-point data, convert the first matrix to floating-point data, and convert the second matrix to floating-point data , and then perform a matrix-matrix-matrix operation on the first matrix and the second matrix with floating-point data types. 根據申請專利範圍第8項的集成電路晶片裝置,其中,如該第一運算為一矩陣乘向量運算,該輸入數據為該矩陣乘向量運算的第一矩陣,該權值為該矩陣乘向量運算的向量;該處理電路,用於計算第一複雜度;該第一複雜度=β*F1*G*F2;其中,β為矩陣系數,取值範圍為大於等於1,F1、G為該第一矩陣的行、列值,F2為該向量的列值; 該處理電路,還用於如該第一複雜度大於一設定閾值,確定該第一矩陣以及該向量是否為浮點數據,如該第一矩陣以及該向量不為浮點數據,將該第一矩陣轉換成浮點數據,將該向量轉換成浮點數據,然後將該第一矩陣、該向量以浮點數據類型執行矩陣乘向量運算。 The integrated circuit chip device according to claim 8, wherein, if the first operation is a matrix multiplication vector operation, the input data is a first matrix of the matrix multiplication vector operation, and the weight is the matrix multiplication vector operation The processing circuit is used to calculate the first complexity; the first complexity=β*F1*G*F2; wherein, β is the matrix coefficient, and the value range is greater than or equal to 1, and F1 and G are the first The row and column values of a matrix, F2 is the column value of the vector; The processing circuit is further configured to determine whether the first matrix and the vector are floating-point data if the first complexity is greater than a set threshold, and if the first matrix and the vector are not floating-point data, determine whether the first matrix and the vector are floating-point data. Convert the first matrix to floating point data, convert the vector to floating point data, and then perform a matrix multiply-vector operation on the first matrix, the vector, in the floating point data type. 根據申請專利範圍第8-13項任意一項該的集成電路晶片裝置,其中,該第i層還包括:偏置運算、全連接運算、GEMM運算、GEMV運算、激活運算中的一種或任意組合。 The integrated circuit chip device according to any one of items 8 to 13 in the scope of the application, wherein the i-th layer further includes: one or any combination of bias operation, full connection operation, GEMM operation, GEMV operation, and activation operation . 一種神經網絡運算裝置,其中,該神經網絡運算裝置包括一個或多個如申請專利範圍第8-14項任意一項的集成電路晶片裝置。 A neural network computing device, wherein, the neural network computing device includes one or more integrated circuit chip devices according to any one of items 8 to 14 of the patent application scope. 一種組合處理裝置,其中,該組合處理裝置包括:如申請專利範圍第15項的一神經網絡運算裝置、一通用互聯介面和一通用處理裝置;該神經網絡運算裝置通過該通用互聯介面與該通用處理裝置連接。 A combined processing device, wherein the combined processing device includes: a neural network computing device, a general interconnection interface, and a general processing device as claimed in item 15 of the patent application scope; the neural network computing device communicates with the general purpose through the general interconnection interface Handling device connection. 一種晶片,其中,該晶片集成如申請專利範圍第8-14項任意一項的裝置。 A wafer, wherein the wafer integrates a device as in any one of claims 8-14 of the claimed scope. 一種電子設備,其中,該電子設備包括如申請專利範圍第17項的晶片。 An electronic device, wherein the electronic device includes a chip as claimed in claim 17 of the patented scope.
TW107144040A 2017-12-14 2018-12-07 Method for neural network forward computation and related product TWI767098B (en)

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
CN201711347407.1A CN109961131B (en) 2017-12-14 2017-12-14 Neural network forward operation method and related product
??201711347407.1 2017-12-14
CN201711347407.1 2017-12-14

Publications (2)

Publication Number Publication Date
TW201928793A TW201928793A (en) 2019-07-16
TWI767098B true TWI767098B (en) 2022-06-11

Family

ID=67018648

Family Applications (1)

Application Number Title Priority Date Filing Date
TW107144040A TWI767098B (en) 2017-12-14 2018-12-07 Method for neural network forward computation and related product

Country Status (2)

Country Link
CN (1) CN109961131B (en)
TW (1) TWI767098B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110490315B (en) * 2019-08-14 2023-05-23 中科寒武纪科技股份有限公司 Reverse operation sparse method of neural network and related products
TWI737228B (en) 2020-03-20 2021-08-21 國立清華大學 Quantization method based on hardware of in-memory computing and system thereof

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106126481A (en) * 2016-06-29 2016-11-16 华为技术有限公司 A kind of computing engines and electronic equipment
US20170061279A1 (en) * 2015-01-14 2017-03-02 Intel Corporation Updating an artificial neural network using flexible fixed point representation
WO2017124644A1 (en) * 2016-01-20 2017-07-27 北京中科寒武纪科技有限公司 Artificial neural network compression encoding device and method
CN107330515A (en) * 2016-04-29 2017-11-07 北京中科寒武纪科技有限公司 A kind of apparatus and method for performing artificial neural network forward operation

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170061279A1 (en) * 2015-01-14 2017-03-02 Intel Corporation Updating an artificial neural network using flexible fixed point representation
WO2017124644A1 (en) * 2016-01-20 2017-07-27 北京中科寒武纪科技有限公司 Artificial neural network compression encoding device and method
CN107330515A (en) * 2016-04-29 2017-11-07 北京中科寒武纪科技有限公司 A kind of apparatus and method for performing artificial neural network forward operation
CN106126481A (en) * 2016-06-29 2016-11-16 华为技术有限公司 A kind of computing engines and electronic equipment

Also Published As

Publication number Publication date
CN109961131B (en) 2020-05-08
TW201928793A (en) 2019-07-16
CN109961131A (en) 2019-07-02

Similar Documents

Publication Publication Date Title
TWI793225B (en) Method for neural network training and related product
US11748605B2 (en) Integrated circuit chip device
TWI791725B (en) Neural network operation method, integrated circuit chip device and related products
CN109961136B (en) Integrated circuit chip device and related product
TWI768159B (en) Integrated circuit chip apparatus and related product
TWI767098B (en) Method for neural network forward computation and related product
WO2019114842A1 (en) Integrated circuit chip apparatus
TWI793224B (en) Integrated circuit chip apparatus and related product
CN109977446B (en) Integrated circuit chip device and related product
TWI767097B (en) Integrated circuit chip apparatus and related product
CN109978157B (en) Integrated circuit chip device and related product
CN109978156B (en) Integrated circuit chip device and related product
CN109978148B (en) Integrated circuit chip device and related product
CN109978152B (en) Integrated circuit chip device and related product
TWI768160B (en) Integrated circuit chip apparatus and related product
CN109978158B (en) Integrated circuit chip device and related product
TWI795482B (en) Integrated circuit chip apparatus and related product