TWI798976B - Direct memory access circuit, operation method thereof, and method of generating memory access command - Google Patents

Direct memory access circuit, operation method thereof, and method of generating memory access command Download PDF

Info

Publication number
TWI798976B
TWI798976B TW110145104A TW110145104A TWI798976B TW I798976 B TWI798976 B TW I798976B TW 110145104 A TW110145104 A TW 110145104A TW 110145104 A TW110145104 A TW 110145104A TW I798976 B TWI798976 B TW I798976B
Authority
TW
Taiwan
Prior art keywords
channel
command
memory
controller
channel controller
Prior art date
Application number
TW110145104A
Other languages
Chinese (zh)
Other versions
TW202324117A (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 大陸商星宸科技股份有限公司
Priority to TW110145104A priority Critical patent/TWI798976B/en
Application granted granted Critical
Publication of TWI798976B publication Critical patent/TWI798976B/en
Publication of TW202324117A publication Critical patent/TW202324117A/en

Links

Images

Landscapes

  • Dram (AREA)
  • Bus Control (AREA)

Abstract

A direct memory access (DMA) circuit, its operation method, and a method of generating memory access commands are provided. The DMA circuit is used to access a memory according to a command and includes a first-in first-out (FIFO) register, a first channel controller, and a second channel controller. The operation method of the DMA circuit includes: decoding the command to obtain a first channel code and a second channel code, the first channel code corresponding to the first channel controller, and the second channel code corresponding to the second channel controller; obtaining a state of the first channel controller from the FIFO register according to the first channel code; selecting the second channel controller according to the second channel code; and controlling the second channel controller according to the state.

Description

直接記憶體存取電路、其操作方法,以及記憶體存取指令的產生方法Direct memory access circuit, its operating method, and method for generating memory access instructions

本發明是關於記憶體存取,尤其是關於直接記憶體存取電路、其操作方法,以及記憶體存取指令的產生方法。The present invention relates to memory access, in particular to a direct memory access circuit, its operating method, and a method for generating memory access instructions.

當電子裝置計算下方的算式(1)時,詳細步驟是:(i)計算C11(即,算式(1a));(ii)將資料C11存入記憶體的目標位置;(iii)從記憶體的目標位置讀出資料C11;以及(iv)計算E11(即,算式(1b))。When the electronic device calculates the formula (1) below, the detailed steps are: (i) calculate C11 (that is, formula (1a)); (ii) store the data C11 into the target location of the memory; (iii) from the memory Read data C11 at the target position of ; and (iv) calculate E11 (ie, formula (1b)).

Figure 02_image001
(1)
Figure 02_image001
(1)

Figure 02_image003
(1a)
Figure 02_image003
(1a)

Figure 02_image005
(1b)
Figure 02_image005
(1b)

Figure 02_image007
(2)
Figure 02_image007
(2)

當習知的計算機或電子裝置計算算式(1)及算式(2)時,是採用算子(operator)整體同步的方法來進行運算,以確保結果正確。算子整體同步是指計算機或電子裝置會先完成算式(1)的計算(即,得到結果E11之後),才進行算式(2)的計算。然而,算式(2)的乘法運算(即,「

Figure 02_image009
」)不需要等到算式(1)完成後才開始進行。更明確地說,因為讀取資料A12不影響算式(1)的計算,所以計算機或電子裝置較佳地可以於執行算式(1)的乘法運算(即,「
Figure 02_image011
」)時便同時從記憶體讀取資料A12,以提高運算效能。 When the conventional computer or electronic device calculates the formula (1) and the formula (2), it adopts the method of synchronizing the operators as a whole to ensure the correct result. The overall synchronization of operators means that the computer or electronic device will first complete the calculation of formula (1) (that is, after obtaining the result E11), and then perform the calculation of formula (2). However, the multiplication operation of equation (2) (ie, "
Figure 02_image009
”) does not need to wait until formula (1) is completed before starting. More specifically, since the reading data A12 does not affect the calculation of formula (1), the computer or electronic device is preferably able to perform the multiplication operation of formula (1) (ie, "
Figure 02_image011
”), the data A12 is read from the memory at the same time to improve the computing performance.

然而,有些資料(例如算式(1a)及(1b)中的資料C11)無法在任意時間被取用或修改(即,資料C11必須先被儲存後,才能被讀出),否則會導致錯誤的計算結果。換言之,儲存該資料的記憶體空間不能在任意時間被讀取或寫入。因此,需要一種記憶體存取指令的產生方法及相關的直接記憶體存取(direct memory access, DMA)電路及其操作方法,來提升計算機或電子裝置的效能。However, some data (such as the data C11 in formulas (1a) and (1b)) cannot be accessed or modified at any time (that is, the data C11 must be stored before it can be read), otherwise it will lead to erroneous Calculation results. In other words, the memory space storing the data cannot be read or written at any time. Therefore, there is a need for a method for generating a memory access command, a related direct memory access (DMA) circuit and an operation method thereof, so as to improve the performance of a computer or an electronic device.

鑑於先前技術之不足,本發明之一目的在於提供一種直接記憶體存取電路、其操作方法,以及記憶體存取指令的產生方法,以改善先前技術的不足。In view of the deficiencies of the prior art, an object of the present invention is to provide a direct memory access circuit, its operating method, and a method for generating memory access instructions, so as to improve the deficiencies of the prior art.

本發明之一實施例提供一種直接記憶體存取電路,用來根據一指令存取一記憶體,包含:一第一通道控制器、一第二通道控制器、一解碼器、一先進先出暫存器以及一控制器。第一及第二通道控制器用來存取該記憶體。解碼器用來解碼該指令以得到一第一通道代碼及一第二通道代碼,該第一通道代碼對應於該第一通道控制器,且該第二通道代碼對應於該第二通道控制器。先進先出暫存器用來儲存該第一通道控制器之一狀態。控制器耦接該解碼器及該先進先出暫存器,用來執行以下步驟:根據該第一通道代碼從該先進先出暫存器取得該狀態;根據該第二通道代碼選擇該第二通道控制器;以及根據該狀態控制該第二通道控制器。One embodiment of the present invention provides a direct memory access circuit for accessing a memory according to an instruction, including: a first channel controller, a second channel controller, a decoder, a first-in-first-out register and a controller. The first and second channel controllers are used to access the memory. The decoder is used to decode the instruction to obtain a first channel code and a second channel code, the first channel code corresponds to the first channel controller, and the second channel code corresponds to the second channel controller. The FIFO register is used to store a state of the first channel controller. The controller is coupled to the decoder and the FIFO register, and is used to perform the following steps: obtain the state from the FIFO register according to the first channel code; select the second channel code according to the second channel code. a channel controller; and controlling the second channel controller according to the state.

本發明之另一實施例提供一種直接記憶體存取電路的操作方法,該直接記憶體存取電路用來根據一指令存取一記憶體,該直接記憶體存取電路包含一先進先出暫存器、一第一通道控制器及一第二通道控制器,該方法包含:解碼該指令以得到一第一通道代碼及一第二通道代碼,其中,該第一通道代碼對應於該第一通道控制器,且該第二通道代碼對應於該第二通道控制器;根據該第一通道代碼從該先進先出暫存器取得該第一通道控制器之一狀態;根據該第二通道代碼選擇該第二通道控制器;以及,根據該狀態控制該第二通道控制器。Another embodiment of the present invention provides a method of operating a direct memory access circuit for accessing a memory according to a command, the direct memory access circuit includes a first-in-first-out buffer memory, a first channel controller and a second channel controller, the method includes: decoding the instruction to obtain a first channel code and a second channel code, wherein the first channel code corresponds to the first channel code a channel controller, and the second channel code corresponds to the second channel controller; obtain a state of the first channel controller from the FIFO register according to the first channel code; according to the second channel code selecting the second channel controller; and controlling the second channel controller according to the state.

本發明之另一實施例提供一種記憶體存取指令的產生方法,其中,一記憶體區塊係被連續之一第一指令及一第二指令存取,該第二指令緊接於該第一指令之後,該方法包含:當該第一指令及該第二指令的其中一者為一讀取指令,另一者為一寫入指令時,將該第一指令之一自身通道代碼作為該第二指令的一參數。該自身通道代碼係對應到一直接記憶體存取電路的一通道控制器,且該通道控制器係用來執行該第一指令。Another embodiment of the present invention provides a method for generating a memory access command, wherein a memory block is accessed by a continuous first command and a second command, and the second command follows the second command. After a command, the method includes: when one of the first command and the second command is a read command and the other is a write command, using a channel code of the first command itself as the A parameter for the second command. The own channel code corresponds to a channel controller of a direct memory access circuit, and the channel controller is used to execute the first instruction.

本發明根據連續的記憶體存取指令的相依性來控制記憶體的存取。相較於先前技術,使用本發明之直接記憶體存取電路的電子裝置或晶片可以以更有效率的方式進行計算,提升運算效能。The invention controls the memory access according to the dependency of consecutive memory access instructions. Compared with the prior art, the electronic device or the chip using the direct memory access circuit of the present invention can perform calculation in a more efficient manner and improve the calculation performance.

有關本發明的特徵、實作與功效,茲配合圖式作實施例詳細說明如下。The characteristics, implementation and effects of the present invention are described in detail as follows with reference to the drawings.

以下說明內容之技術用語係參照本技術領域之習慣用語,如本說明書對部分用語有加以說明或定義,該部分用語之解釋係以本說明書之說明或定義為準。The technical terms in the following explanations refer to the customary terms in this technical field. If some terms are explained or defined in this specification, the explanations of these terms shall be based on the descriptions or definitions in this specification.

本發明之揭露內容包含直接記憶體存取電路、其操作方法,以及記憶體存取指令的產生方法。由於本發明之直接記憶體存取電路所包含之部分元件單獨而言可能為已知元件,因此在不影響該裝置發明之充分揭露及可實施性的前提下,以下說明對於已知元件的細節將予以節略。The disclosure of the present invention includes a direct memory access circuit, its operating method, and a method for generating memory access instructions. Since some of the components included in the direct memory access circuit of the present invention may be known components individually, on the premise of not affecting the full disclosure and implementability of the device invention, the details of the known components are described below will be omitted.

在產品的開發過程中,產品開發工具(例如電腦)針對某個運算模型(例如神經網路模型)及智能處理器(intelligent processing unit, IPU)或直接記憶體存取等硬體,分析資料的相依性,再根據資料的相依性產生記憶體存取指令。該產品例如是電子裝置、晶片等具有運算能力的硬體,且該產品使用直接記憶體存取電路來控制記憶體(包含但不限於快取記憶體或隨機存取記憶體)的存取(讀取或寫入)。更明確地說,利用軟體將運算模型欲進行運算的資料分成多個資料頁,每個資料頁的大小例如為4KB,並對應地將一記憶體(快取記憶體或隨機存取記憶體)分成多個記憶體區塊,每個記憶體區塊的大小對應資料頁的大小,利用產品開發工具追踪每個資料頁的資料相依性。在一實施例中,各資料頁透過對應的存取指令被寫入某一記憶體區塊或自某一記憶體區塊讀出,產品開發工具可藉由分析對某一記憶體區塊(以下稱為目標記憶體區塊,用來儲存一目標資料頁)的多個存取指令來追踪一資料頁的資料相依性。產品開發工具藉由分析對目標記憶體區塊所進行操作的連續兩個指令(第一指令與第二指令,第二指令緊接於第一指令之後,第一指令是第二指令的先前指令)來判斷是否加入資料相依性的訊息(或資料同步訊息),並據以產生該目標資料頁的記憶體存取指令,詳細的流程如圖1所示,包含以下的步驟。In the product development process, product development tools (such as computers) analyze data for a computing model (such as a neural network model) and hardware such as an intelligent processing unit (IPU) or direct memory access. Dependencies, and then generate memory access instructions according to the dependencies of the data. The product is, for example, hardware with computing capabilities such as electronic devices and chips, and the product uses direct memory access circuits to control access to memory (including but not limited to cache memory or random access memory) ( read or write). More specifically, software is used to divide the data to be calculated by the calculation model into multiple data pages, each data page is, for example, 4KB in size, and a memory (cache memory or random access memory) is correspondingly allocated Divide into multiple memory blocks, the size of each memory block corresponds to the size of the data page, and use product development tools to track the data dependencies of each data page. In one embodiment, each data page is written into or read from a certain memory block through a corresponding access command, and the product development tool can analyze a certain memory block ( Hereinafter referred to as a target memory block, it is used to store a plurality of access commands of a target data page) to track data dependencies of a data page. The product development tool analyzes two consecutive instructions (the first instruction and the second instruction) that operate on the target memory block, the second instruction is immediately after the first instruction, and the first instruction is the previous instruction of the second instruction ) to determine whether to add a data dependency message (or a data synchronization message), and generate a memory access command for the target data page accordingly. The detailed process is shown in FIG. 1 and includes the following steps.

步驟S110:取得連續的第一指令及第二指令,第一指令及第二指令存取目標記憶體區塊(即,第一指令及第二指令從目標記憶體區塊讀取目標資料頁、將目標資料頁寫入目標記憶體區塊,或是更新目標記憶體區塊中的目標資料頁(相當於寫入操作))。詳言之,產品開發工具可以針對該產品的某一項操作中對一目標資料頁的存取操作取得連續的第一指令及第二指令,該項操作先以第一指令存取目標記憶體區塊,再以第二指令存取該目標記憶體區塊,且第一指令與第二指令中間不包含存取該目標記憶體區塊的其他指令。Step S110: Obtain consecutive first instructions and second instructions, the first instruction and the second instruction access the target memory block (that is, the first instruction and the second instruction read the target data page from the target memory block, Write the target data page into the target memory block, or update the target data page in the target memory block (equivalent to a write operation)). Specifically, the product development tool can obtain consecutive first instructions and second instructions for an access operation to a target data page in a certain operation of the product, and the operation first uses the first instruction to access the target memory block, and then use the second instruction to access the target memory block, and the first instruction and the second instruction do not contain other instructions for accessing the target memory block.

需注意的是,一個指令(即上述之第一指令或第二指令)包含或攜帶一個自身通道代碼,該自身通道代碼對應到一個直接記憶體存取電路的一個通道控制器。換言之,當直接記憶體存取電路執行一個讀取(或寫入)指令時,會以該讀取(或寫入)指令的自身通道代碼指定一個通道控制器進行讀取(或寫入)操作。It should be noted that a command (ie, the above-mentioned first command or second command) contains or carries a self-channel code, and the self-channel code corresponds to a channel controller of a direct memory access circuit. In other words, when the direct memory access circuit executes a read (or write) command, it will use the read (or write) command's own channel code to designate a channel controller to perform the read (or write) operation .

步驟S120:產品開發工具判斷該第一指令及該第二指令是否包含一讀取指令及一寫入指令。如果為是(即,該第一指令及該第二指令的其中一者是讀取指令而另一者是寫入指令),代表第一指令與第二指令存在資料相依性,產品開發工具執行步驟S130;否則(即,該第一指令及該第二指令皆為讀取指令或皆為寫入指令),產品開發工具執行步驟S140。Step S120: The product development tool determines whether the first command and the second command include a read command and a write command. If yes (that is, one of the first command and the second command is a read command and the other is a write command), it means that there is a data dependency between the first command and the second command, and the product development tool executes Step S130; otherwise (ie, the first command and the second command are both read commands or both are write commands), the product development tool executes step S140.

步驟S130:產品開發工具將該第一指令的自身通道代碼作為該第二指令的一參數(即,下面所述的相依通道代碼),此參數即為資料相依訊息。請參閱圖2,圖2顯示本發明之指令格式的一實施例。圖2之格式僅用於示例,非用以限定本發明。在圖2的例子中,一個指令可以包含五個參數:「讀/寫」、「自身通道代碼」、「相依通道代碼」、「地址」及「寫入內容」,第一指令是寫(以「W」表示)指令,第二指令是讀(以「R」表示)指令,第一指令的相依通道代碼「FF」是一個預設值(也可以是「0」或其他數值)。如圖2所示,第一指令的「自身通道代碼」參數與第二指令的「相依通道代碼」參數都是「ID1」,表示第二指令相依於第一指令。而「FF」代表第一指令不相依於其前一個指令。Step S130: The product development tool uses the own channel code of the first command as a parameter of the second command (ie, the dependent channel code described below), and this parameter is the data dependency message. Please refer to FIG. 2, which shows an embodiment of the command format of the present invention. The format of FIG. 2 is for example only, and is not intended to limit the present invention. In the example in Figure 2, a command can contain five parameters: "read/write", "own channel code", "dependent channel code", "address" and "write content", the first command is write (with "W" indicates) command, the second command is a read (indicated by "R") command, and the dependent channel code "FF" of the first command is a default value (it can also be "0" or other values). As shown in FIG. 2 , both the "self channel code" parameter of the first command and the "dependent channel code" parameter of the second command are "ID1", indicating that the second command is dependent on the first command. And "FF" means that the first command does not depend on its previous command.

步驟S140:產品開發工具將該第二指令的相依通道代碼設為預設值。請參閱圖3,圖3顯示本發明之指令格式的另一實施例。圖3之格式僅用於示例,非用以限定本發明。因為在圖3的例子中第一指令及第二指令都是讀取指令,所以產品開發工具將第二指令的相依通道代碼設為預設值「FF」,代表第二指令不相依於第一指令。請注意,當第一指令及第二指令都是寫入指令時,第二指令的相依通道代碼亦為預設值「FF」。Step S140: The product development tool sets the dependent channel code of the second command as a default value. Please refer to FIG. 3, which shows another embodiment of the command format of the present invention. The format of FIG. 3 is for example only, and is not intended to limit the present invention. Because the first command and the second command are both read commands in the example in FIG. instruction. Please note that when both the first command and the second command are write commands, the dependent channel code of the second command is also the default value “FF”.

產品開發工具持續進行圖1的流程來掃描該項操作對各個資料頁的存取指令,以確定每一指令是否相依於其先前指令。在一些實施例中,圖1的流程是以軟體實作;換言之,產品開發工具藉由執行程式碼或程式指令來完成圖1的流程。The product development tool continues the process of FIG. 1 to scan the operation's access commands to each data page to determine whether each command is dependent on its previous command. In some embodiments, the process of FIG. 1 is implemented by software; in other words, the product development tool completes the process of FIG. 1 by executing program codes or program instructions.

以下將說明直接記憶體存取電路如何根據「自身通道代碼」及「相依通道代碼」操作。The following will explain how the DMA circuit operates according to the "own channel code" and the "dependent channel code".

圖4為本發明直接記憶體存取電路之一實施例的功能方塊圖。圖4的元件是前述之產品的一部分,包含處理器10、直接記憶體存取電路20及記憶體25(包含但不限於快取記憶體30及隨機存取記憶體40)。處理器10透過直接記憶體存取電路20來存取快取記憶體30及隨機存取記憶體40。直接記憶體存取電路20包含解碼器210、先進先出暫存器220、控制器230、匯流排250、m個通道控制器260(260_1、260_2、…、260_m,m為大於1之整數)及匯流排270。該m個通道控制器260的通道代碼分別是ID1、ID2、…及IDm。FIG. 4 is a functional block diagram of an embodiment of the direct memory access circuit of the present invention. The components of FIG. 4 are part of the aforementioned product, including processor 10, direct memory access circuit 20, and memory 25 (including but not limited to cache memory 30 and random access memory 40). The processor 10 accesses the cache memory 30 and the random access memory 40 through the direct memory access circuit 20 . The direct memory access circuit 20 includes a decoder 210, a FIFO register 220, a controller 230, a bus 250, and m channel controllers 260 (260_1, 260_2, ..., 260_m, m is an integer greater than 1) and busbar 270 . The channel codes of the m channel controllers 260 are ID1, ID2, . . . and IDm, respectively.

當處理器10欲將一目標資料頁寫入記憶體25或自記憶體25讀出時,處理器10發送一目標指令至直接記憶體存取電路20。解碼器210解碼處理器10所發送的目標指令以取得目標指令的所有參數,並將該些參數傳送給控制器230。先進先出暫存器220儲存該m個通道控制器260的狀態。控制器230耦接解碼器210及先進先出暫存器220,用來根據目標指令的自身通道代碼控制對應的通道控制器260執行該目標指令之任務。通道控制器260除了存取快取記憶體30或隨機存取記憶體40之外,還會更新先進先出暫存器220中的自身狀態。請參閱圖5,圖5是通道控制器260的狀態表500的一個例子,狀態表500儲存於先進先出暫存器220中。「BUSY」代表通道控制器是忙碌狀態(例如正在存取快取記憶體30或隨機存取記憶體40),而「IDLE」代表通道控制器是閒置狀態。When the processor 10 intends to write a target data page into the memory 25 or read it from the memory 25 , the processor 10 sends a target command to the DMA circuit 20 . The decoder 210 decodes the target command sent by the processor 10 to obtain all parameters of the target command, and transmits the parameters to the controller 230 . The FIFO register 220 stores the states of the m channel controllers 260 . The controller 230 is coupled to the decoder 210 and the FIFO register 220, and is used for controlling the corresponding channel controller 260 to execute the task of the target command according to its own channel code of the target command. In addition to accessing the cache memory 30 or the random access memory 40 , the channel controller 260 also updates its own state in the FIFO register 220 . Please refer to FIG. 5 . FIG. 5 is an example of a state table 500 of the channel controller 260 , and the state table 500 is stored in the FIFO register 220 . "BUSY" means that the channel controller is in a busy state (such as accessing the cache memory 30 or the random access memory 40 ), and "IDLE" means that the channel controller is in an idle state.

圖6為直接記憶體存取電路的操作方法之一實施例的流程圖。以下配合圖6說明直接記憶體存取電路20的操作。FIG. 6 is a flowchart of an embodiment of an operating method of a direct memory access circuit. The operation of the DMA circuit 20 will be described below with reference to FIG. 6 .

步驟S610:直接記憶體存取電路20從處理器10接收目標指令,目標指令攜帶一第一通道代碼(即相依通道代碼)及一第二通道代碼(即自身通道代碼)。舉例來說,當目標指令是圖2的第二指令時,第一通道代碼是「ID1」,而第二通道代碼是「ID2」。Step S610: The DMA circuit 20 receives the target command from the processor 10, and the target command carries a first channel code (ie, the dependent channel code) and a second channel code (ie, its own channel code). For example, when the target command is the second command in FIG. 2 , the first channel code is "ID1", and the second channel code is "ID2".

步驟S620:解碼器210解碼該目標指令以得到該第一通道代碼、該第二通道代碼及該目標指令的其他參數。處理器10以某一編碼方式編碼目標指令,而解碼器210以相對於該編碼方式之解碼方式解碼目標指令。解碼操作為本技術領域具有通常知識者所熟知,故不再贅述。Step S620: The decoder 210 decodes the target command to obtain the first channel code, the second channel code and other parameters of the target command. The processor 10 encodes the target instruction in an encoding manner, and the decoder 210 decodes the target instruction in a decoding manner corresponding to the encoding manner. The decoding operation is well known to those skilled in the art, so details will not be repeated here.

步驟S630:控制器230根據該第二通道代碼選擇一第二通道控制器。承上例(即,目標指令是圖2的第二指令),控制器230選擇對應於第二通道代碼「ID2」的第二通道控制器260_2。Step S630: The controller 230 selects a second channel controller according to the second channel code. Continuing from the above example (that is, the target command is the second command in FIG. 2 ), the controller 230 selects the second channel controller 260_2 corresponding to the second channel code “ID2”.

步驟S640:控制器230判斷該第一通道代碼是否為預設值。如果該第一通道代碼是預設值(代表目標指令不相依於先前指令,也就是目標指令跟先前指令是同一種操作(皆為讀取操作或皆為寫入操作)),則控制器230執行步驟S650。如果該第一通道代碼不是預設值(代表目標指令相依於先前指令,也就是目標指令跟先前指令不是同一種操作(一者為讀取操作,另一者為寫入操作)),則控制器230執行步驟S660及S670。在這裡,先前指令與目標指令是操作目標記憶體區塊的連續指令,也就是說,對目標記憶體區塊而言,目標指令緊接於該先前指令之後。然而,對處理器10及控制器230而言,先前指令與目標指令之間可能有其他的指令,該或該些其他的指令不存取目標記憶體區塊。Step S640: The controller 230 determines whether the first channel code is a preset value. If the first channel code is a preset value (representing that the target command is not dependent on the previous command, that is, the target command and the previous command are the same operation (both are read operations or both are write operations)), then the controller 230 Execute step S650. If the first channel code is not a preset value (representing that the target instruction is dependent on the previous instruction, that is, the target instruction is not the same operation as the previous instruction (one is a read operation, the other is a write operation)), then the control The controller 230 executes steps S660 and S670. Here, the previous instruction and the target instruction are consecutive instructions for operating the target memory block, that is, for the target memory block, the target instruction is immediately after the previous instruction. However, for the processor 10 and the controller 230, there may be other instructions between the previous instruction and the target instruction, and the or these other instructions do not access the target memory block.

步驟S650:控制器230控制第二通道控制器260_2存取記憶體25,即,通道控制器260_2執行目標指令的任務。Step S650: The controller 230 controls the second channel controller 260_2 to access the memory 25, that is, the channel controller 260_2 executes the task of the target instruction.

步驟S660:控制器230根據該第一通道代碼從先進先出暫存器220取得一第一通道控制器之狀態。承上例(即,目標指令是圖2的第二指令,且通道控制器260的狀態如圖5所示),控制器230以第一通道代碼「ID1」作為索引,在狀態表500中查詢到對應「ID1」的第一通道控制器260_1的狀態為忙碌。Step S660: The controller 230 acquires a state of the first channel controller from the FIFO register 220 according to the first channel code. Continuing from the above example (that is, the target command is the second command in FIG. 2 , and the state of the channel controller 260 is shown in FIG. 5 ), the controller 230 uses the first channel code "ID1" as an index to query in the state table 500 The status of the first channel controller 260_1 corresponding to “ID1” is busy.

步驟S670:控制器230根據該第一通道控制器260_1之狀態控制該第二通道控制器260_2。步驟S670的細節於下方配合圖7詳述。Step S670: The controller 230 controls the second channel controller 260_2 according to the state of the first channel controller 260_1. Details of step S670 are described in detail below with FIG. 7 .

請參閱圖7,圖7顯示步驟S670之一實施例的流程圖,包含以下步驟。Please refer to FIG. 7 . FIG. 7 shows a flowchart of an embodiment of step S670 , including the following steps.

步驟S710:控制器230判斷該第一通道控制器260_1之狀態是否為閒置狀態。如果否,則執行步驟S720、步驟S730及步驟S740;如果是,則執行步驟S750及步驟S740。Step S710: The controller 230 determines whether the state of the first channel controller 260_1 is an idle state. If not, execute step S720, step S730 and step S740; if yes, execute step S750 and step S740.

步驟S720:控制器230等待該第一通道控制器260_1之狀態變為閒置狀態。任一個通道控制器260在完成任務後(例如完成讀取操作或寫入操作),會將狀態表500中的自身狀態改為閒置。反之,任一個通道控制器260在收到任務後,會將狀態表500中的自身狀態改為忙碌。換言之,在步驟S720中,控制器230等待該第一通道控制器260_1完成目前的任務,以確保資料正確。Step S720: The controller 230 waits for the state of the first channel controller 260_1 to become idle. After any channel controller 260 completes a task (for example, completes a read operation or a write operation), it will change its state in the state table 500 to idle. Conversely, any channel controller 260 will change its status in the status table 500 to busy after receiving the task. In other words, in step S720, the controller 230 waits for the first channel controller 260_1 to complete the current task to ensure that the data is correct.

步驟S730:在該第一通道控制器260_1之狀態變為閒置狀態後,控制器230控制該第二通道控制器260_2存取該記憶體25。步驟S730與步驟S650相同。Step S730 : After the state of the first channel controller 260_1 becomes idle, the controller 230 controls the second channel controller 260_2 to access the memory 25 . Step S730 is the same as step S650.

步驟S740:該第二通道控制器260_2在收到任務後,將狀態表500中的自身狀態改為非閒置狀態(即,忙碌狀態)。Step S740: After receiving the task, the second channel controller 260_2 changes its state in the state table 500 to a non-idle state (ie, busy state).

步驟S750:控制器230控制該第二通道控制器260_2存取該記憶體25。步驟S750與步驟S730及S650相同。Step S750 : the controller 230 controls the second channel controller 260_2 to access the memory 25 . Step S750 is the same as steps S730 and S650.

圖8顯示本發明通道控制器260之一實施例的功能方塊圖。通道控制器260包含有限狀態機262、讀寫控制器264及暫存器組266。暫存器組266儲存系統參數(包含但不限於匯流排250及匯流排270的資訊、每筆讀/寫資料的寬度、直接記憶體存取電路20的參數、隨機存取記憶體40的參數等)。有限狀態機262控制讀寫控制器264根據暫存器組266所儲存的系統參數及目標指令的各項參數來進行讀取操作及寫入操作。此外,有限狀態機262還根據該通道控制器260是否正在執行任務來切換狀態(閒置或忙碌),並且更新儲存於先進先出暫存器220中的狀態表500的對應欄位。FIG. 8 shows a functional block diagram of an embodiment of the channel controller 260 of the present invention. The channel controller 260 includes a finite state machine 262 , a read/write controller 264 and a register set 266 . The register group 266 stores system parameters (including but not limited to bus 250 and bus 270 information, the width of each read/write data, the parameters of the direct memory access circuit 20, the parameters of the random access memory 40 wait). The finite state machine 262 controls the read-write controller 264 to perform read and write operations according to the system parameters and various parameters of the target command stored in the register set 266 . In addition, the finite state machine 262 also switches the state (idle or busy) according to whether the channel controller 260 is executing a task, and updates the corresponding column of the state table 500 stored in the FIFO register 220 .

本技術領域具有通常知識者可以根據以上的揭露內容來設計控制器230。在一些實施例中,控制器230可以是由可程式化邏輯裝置(Programmable Logic Device, PLD)等電路或硬體實作;在另一些實施例中,控制器230可以藉由執行程式碼或程式指令來完成上述之操作。Those skilled in the art can design the controller 230 according to the above disclosure. In some embodiments, the controller 230 can be realized by circuits or hardware such as a programmable logic device (Programmable Logic Device, PLD); in other embodiments, the controller 230 can execute codes or programs command to complete the above operations.

綜上所述,本發明的直接記憶體存取電路20及其操作方法根據每個資料頁連續的指令來追踪其相依性,並據以控制通道控制器,可以確保緊接於寫入操作後的讀取操作以及緊接於讀取操作後的寫入操作都不會造成資料錯誤。如此一來,使用直接記憶體存取電路20的電子裝置或晶片可以以更有效率的方式進行計算。以前述之算式(1)及算式(2)為例,藉由找出資料C11在算式(1a)及算式(1b)中的相依性(即,藉由指定相依通道代碼),本發明可以確保計算算式(1b)時取得正確的資料C11;如此一來,相較於先前技術之算子整體同步,本發明可以提前運算算式(2)。換言之,本發明可以更精細地安排資料的運算,因此運算效能可以獲得提升。To sum up, the direct memory access circuit 20 and its operating method of the present invention track its dependencies according to the continuous instructions of each data page, and control the channel controller accordingly, so as to ensure that the direct memory access circuit 20 immediately after the write operation A read operation and a write operation immediately following a read operation will not cause data errors. In this way, electronic devices or chips using the DMA circuit 20 can perform calculations in a more efficient manner. Taking the aforementioned formula (1) and formula (2) as an example, by finding out the dependence of data C11 in formula (1a) and formula (1b) (that is, by specifying the dependent channel code), the present invention can ensure The correct data C11 is obtained when calculating the formula (1b); in this way, compared with the prior art, the operators are synchronized as a whole, and the present invention can calculate the formula (2) in advance. In other words, the present invention can more finely arrange data calculation, so the calculation performance can be improved.

雖然本發明之實施例如上所述,然而該些實施例並非用來限定本發明,本技術領域具有通常知識者可依據本發明之明示或隱含之內容對本發明之技術特徵施以變化,凡此種種變化均可能屬於本發明所尋求之專利保護範疇,換言之,本發明之專利保護範圍須視本說明書之申請專利範圍所界定者為準。Although the embodiments of the present invention are as described above, these embodiments are not intended to limit the present invention, and those skilled in the art can make changes to the technical characteristics of the present invention according to the explicit or implicit contents of the present invention. All these changes may belong to the scope of patent protection sought by the present invention. In other words, the scope of patent protection of the present invention must be defined by the scope of patent application in this specification.

10:處理器 20:直接記憶體存取電路 25:記憶體 30:快取記憶體 40:隨機存取記憶體 210:解碼器 220:先進先出暫存器 230:控制器 250,270:匯流排 260,260_2,260_1,260_m:通道控制器 ID1,ID2,IDm:通道代碼 500:狀態表 262:有限狀態機 264:讀寫控制器 266:暫存器組 S110,S120,S130,S140,S610,S620,S630,S640,S650,S660,S670,S710,S720,S730,S740,S750:步驟 10: Processor 20: Direct memory access circuit 25: memory 30: Cache memory 40: Random Access Memory 210: decoder 220: FIFO register 230: controller 250,270: busbar 260, 260_2, 260_1, 260_m: channel controller ID1, ID2, IDm: channel code 500: status table 262: Finite state machine 264: read and write controller 266: Register group S110, S120, S130, S140, S610, S620, S630, S640, S650, S660, S670, S710, S720, S730, S740, S750: steps

圖1是本發明記憶體存取指令的產生方法之一實施例的流程圖; 圖2顯示本發明之指令格式的一實施例; 圖3顯示本發明之指令格式的另一實施例; 圖4為本發明直接記憶體存取電路之一實施例的功能方塊圖; 圖5顯示通道控制器的狀態表的一個例子; 圖6為直接記憶體存取電路的操作方法之一實施例的流程圖; 圖7顯示步驟S670之一實施例的流程圖;以及 圖8顯示本發明通道控制器之一實施例的功能方塊圖。 Fig. 1 is the flowchart of one embodiment of the generation method of memory access instruction of the present invention; Fig. 2 shows an embodiment of the instruction format of the present invention; Fig. 3 shows another embodiment of the instruction format of the present invention; FIG. 4 is a functional block diagram of an embodiment of the direct memory access circuit of the present invention; Figure 5 shows an example of a state table of a channel controller; 6 is a flowchart of an embodiment of an operating method of a direct memory access circuit; Fig. 7 shows the flowchart of one embodiment of step S670; And FIG. 8 shows a functional block diagram of an embodiment of the channel controller of the present invention.

S610,S620,S630,S640,S650,S660,S670:步驟 S610, S620, S630, S640, S650, S660, S670: steps

Claims (9)

一種直接記憶體存取電路,用來根據一指令存取一記憶體,包含:一第一通道控制器,用來存取該記憶體;一第二通道控制器,用來存取該記憶體;一解碼器,用來解碼該指令以得到一第一通道代碼及一第二通道代碼,該第一通道代碼對應於該第一通道控制器,且該第二通道代碼對應於該第二通道控制器;一先進先出暫存器,用來儲存該第一通道控制器之一狀態;以及一控制器,耦接該解碼器及該先進先出暫存器,用來執行以下步驟:根據該第一通道代碼從該先進先出暫存器取得該狀態;根據該第二通道代碼選擇該第二通道控制器;當該狀態指示該第一通道控制器非為閒置狀態時,等待該第一通道控制器為閒置狀態,然後控制該第二通道控制器存取該記憶體;以及當該狀態指示該第一通道控制器為閒置狀態時,控制該第二通道控制器存取該記憶體。 A direct memory access circuit for accessing a memory according to an instruction, comprising: a first channel controller for accessing the memory; a second channel controller for accessing the memory ; A decoder for decoding the instruction to obtain a first channel code and a second channel code, the first channel code corresponds to the first channel controller, and the second channel code corresponds to the second channel a controller; a FIFO register for storing a state of the first channel controller; and a controller coupled to the decoder and the FIFO register for performing the following steps: according to The first channel code obtains the status from the first-in first-out register; selects the second channel controller according to the second channel code; when the status indicates that the first channel controller is not idle, waits for the second channel controller A channel controller is in an idle state, then controlling the second channel controller to access the memory; and when the status indicates that the first channel controller is in an idle state, controlling the second channel controller to access the memory . 如請求項1之直接記憶體存取電路,其中,該狀態係一第一狀態,該先進先出暫存器更儲存該第二通道控制器之一第二狀態,以及當該第二通道控制器開始存取該記憶體時,該第二通道控制器改變該第二狀態為非閒置狀態。 The direct memory access circuit of claim 1, wherein the state is a first state, and the first-in-first-out register further stores a second state of the second channel controller, and when the second channel control When the device starts to access the memory, the second channel controller changes the second state to a non-idle state. 如請求項1之直接記憶體存取電路,其中,該狀態係一第一狀態,該先進先出暫存器更儲存該第二通道控制器之一第二狀態,以及當該第二通道控制器開始存取該記憶體時,該第二通道控制器改變該第二狀態為非閒置狀態。 The direct memory access circuit of claim 1, wherein the state is a first state, and the first-in-first-out register further stores a second state of the second channel controller, and when the second channel control When the device starts to access the memory, the second channel controller changes the second state to a non-idle state. 如請求項1之直接記憶體存取電路,其中,於收到該指令之前,該直接記憶體存取電路係收到一先前指令,該先前指令係控制該第一通道控制器對該記憶體之一記憶體區塊進行一讀取操作,且該指令係控制該第二通道控制器對該記憶體之該記憶體區塊進行一寫入操作。 The direct memory access circuit of claim 1, wherein, before receiving the command, the direct memory access circuit receives a previous command, and the previous command is to control the first channel controller to the memory A memory block performs a read operation, and the instruction controls the second channel controller to perform a write operation on the memory block of the memory. 一種直接記憶體存取電路的操作方法,該直接記憶體存取電路用來根據一指令存取一記憶體,該直接記憶體存取電路包含一先進先出暫存器、一第一通道控制器及一第二通道控制器,該方法包含:解碼該指令以得到一第一通道代碼及一第二通道代碼,其中,該第一通道代碼對應於該第一通道控制器,且該第二通道代碼對應於該第二通道控制器;根據該第一通道代碼從該先進先出暫存器取得該第一通道控制器之一狀態;根據該第二通道代碼選擇該第二通道控制器;當該狀態指示該第一通道控制器非為閒置狀態時,等待該第一通道控制器為閒置狀態,然後控制該第二通道控制器存取該記憶體;以及當該狀態指示該第一通道控制器為閒置狀態時,控制該第二通道控制器存取該記憶體。 An operation method of a direct memory access circuit, the direct memory access circuit is used to access a memory according to an instruction, the direct memory access circuit includes a first-in-first-out temporary register, a first channel control device and a second channel controller, the method includes: decoding the instruction to obtain a first channel code and a second channel code, wherein the first channel code corresponds to the first channel controller, and the second The channel code corresponds to the second channel controller; obtain a state of the first channel controller from the FIFO register according to the first channel code; select the second channel controller according to the second channel code; When the status indicates that the first channel controller is not idle, waiting for the first channel controller to be idle, and then controlling the second channel controller to access the memory; and when the status indicates the first channel When the controller is in an idle state, the second channel controller is controlled to access the memory. 如請求項5之操作方法,其中,該狀態係一第一狀態,該先進先出暫存器更儲存該第二通道控制器之一第二狀態,該方法更包含:當該第二通道控制器開始存取該記憶體時,改變該第二狀態為非閒置狀態。 As the operation method of claim item 5, wherein, the state is a first state, and the first-in-first-out register further stores a second state of the second channel controller, and the method further includes: when the second channel control When the device starts to access the memory, the second state is changed to a non-idle state. 如請求項5之操作方法,其中,於收到該指令之前,該直接記憶體存取電路係收到一先前指令,該先前指令係控制該第一通道控制器對該記憶體之一記憶體區塊進行一讀取操作,且該指令係控制該第二通道控制器對該記憶體之該記憶體區塊進行一寫入操作。 The operation method according to claim 5, wherein, before receiving the command, the direct memory access circuit receives a previous command, and the previous command controls the first channel controller to a memory of the memory The block performs a read operation, and the instruction controls the second channel controller to perform a write operation on the memory block of the memory. 一種記憶體存取指令的產生方法,其中,一記憶體區塊係被連續之一第一指令及一第二指令存取,該第二指令緊接於該第一指令之後,該方法包含:當該第一指令及該第二指令的其中一者為一讀取指令,另一者為一寫入指令時,將該第一指令之一自身通道代碼作為該第二指令的一參數;其中,該自身通道代碼係對應到一直接記憶體存取電路的一通道控制器,且該通道控制器係用來執行該第一指令。 A method for generating a memory access instruction, wherein a memory block is accessed by a continuous first instruction and a second instruction, the second instruction immediately following the first instruction, the method comprising: When one of the first command and the second command is a read command and the other is a write command, a channel code of the first command is used as a parameter of the second command; , the own channel code is corresponding to a channel controller of a direct memory access circuit, and the channel controller is used to execute the first instruction. 如請求項8之產生方法,更包含:當該第一指令及該第二指令皆為該讀取指令或該寫入指令時,將該第二指令的該參數設為一預設值。 The generating method of claim 8 further includes: when both the first command and the second command are the read command or the write command, setting the parameter of the second command to a default value.
TW110145104A 2021-12-02 2021-12-02 Direct memory access circuit, operation method thereof, and method of generating memory access command TWI798976B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW110145104A TWI798976B (en) 2021-12-02 2021-12-02 Direct memory access circuit, operation method thereof, and method of generating memory access command

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW110145104A TWI798976B (en) 2021-12-02 2021-12-02 Direct memory access circuit, operation method thereof, and method of generating memory access command

Publications (2)

Publication Number Publication Date
TWI798976B true TWI798976B (en) 2023-04-11
TW202324117A TW202324117A (en) 2023-06-16

Family

ID=86948708

Family Applications (1)

Application Number Title Priority Date Filing Date
TW110145104A TWI798976B (en) 2021-12-02 2021-12-02 Direct memory access circuit, operation method thereof, and method of generating memory access command

Country Status (1)

Country Link
TW (1) TWI798976B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5506970A (en) * 1991-04-15 1996-04-09 Bull S.A. Bus arbitrator circuit
CN1991810A (en) * 2005-12-19 2007-07-04 威盛电子股份有限公司 A dma controller with multiple intra-channel software request support
CN103064807A (en) * 2012-12-17 2013-04-24 福建星网锐捷网络有限公司 Multi-channel direct memory access controller
CN103793342A (en) * 2012-11-02 2014-05-14 中兴通讯股份有限公司 Multichannel direct memory access (DMA) controller
US9684615B1 (en) * 2015-01-08 2017-06-20 Altera Corporation Apparatus and methods for multiple-channel direct memory access

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5506970A (en) * 1991-04-15 1996-04-09 Bull S.A. Bus arbitrator circuit
CN1991810A (en) * 2005-12-19 2007-07-04 威盛电子股份有限公司 A dma controller with multiple intra-channel software request support
CN103793342A (en) * 2012-11-02 2014-05-14 中兴通讯股份有限公司 Multichannel direct memory access (DMA) controller
CN103064807A (en) * 2012-12-17 2013-04-24 福建星网锐捷网络有限公司 Multi-channel direct memory access controller
US9684615B1 (en) * 2015-01-08 2017-06-20 Altera Corporation Apparatus and methods for multiple-channel direct memory access

Also Published As

Publication number Publication date
TW202324117A (en) 2023-06-16

Similar Documents

Publication Publication Date Title
CN110609730B (en) Method and equipment for realizing interrupt transparent transmission between virtual processors
US10209922B2 (en) Communication via a memory interface
US20080155167A1 (en) Handling access requests in a data processing apparatus
JPWO2004079583A1 (en) Data transfer control device and DMA data transfer control method
JP6069031B2 (en) Computer and memory management method
JP2013522748A (en) Hierarchical translation table control
JP2016513846A (en) Memory sharing over the network
JP2008047116A (en) Flexible control for data transfer between input/output device and memory
JPH0863354A (en) Equipment and method for execution of computer processing
US20090164749A1 (en) Coupled symbiotic operating systems
WO2014100954A1 (en) Method and system for data controlling
CN114207596A (en) Providing interrupts from an input-output memory management unit to a guest operating system
US20200371827A1 (en) Method, Apparatus, Device and Medium for Processing Data
TWI798976B (en) Direct memory access circuit, operation method thereof, and method of generating memory access command
CN111177027A (en) Dynamic random access memory, memory management method, system and storage medium
EP4170538A1 (en) Chip simulation method, apparatus and system, and device and storage medium
CN114116555A (en) Direct memory access circuit, operation method and access instruction generation method
JPH10240546A (en) Execution time program translation method
JP2003202999A (en) Virtual computer system
JP2011175666A (en) Semiconductor storage device, and method for controlling the same
TW202418076A (en) Computing system for memory management opportunities and memory swapping tasks and method of managing the same
CN117389685B (en) Virtual machine thermal migration dirty marking method and device, back-end equipment and chip thereof
KR102254101B1 (en) Data processing system and operating method of the same
JP2024072010A (en) Program, instruction execution controller, and instruction execution control method
JPH07109589B2 (en) Instruction processing method