Searching apparatus utilizing sub-word finite state machines
11586956 · 2023-02-21
Assignee
Inventors
Cpc classification
International classification
Abstract
An apparatus that searches an input stream having a sequence of N-bit wide data words for a pattern using a plurality of small FSMs is disclosed. The apparatus includes a plurality of sub-word FSMs and a combiner. Each sub-word FSM has an input word size less than N-bits. Each FSM processes a corresponding segment of the N-bit words and generates a match output indicative of a possible match to the pattern when one of the input words to that FSM is received and that FSM moves to a predetermined match state. The combiner receives the match outputs from all of the sub-word FSMs and generates a pattern match output if all of the sub-word FSMs indicate a match to the pattern. The pattern is a variable pattern. In one embodiment, the FSMs are single bit FSMs.
Claims
1. An apparatus that searches an input stream comprising a sequence of data words in order to identify a pattern in the input stream, each data word being N-bits wide, said apparatus comprising: a processor adapted to receive a collection of match outputs from single bit FSMs; and a non-tangible memory that stores instructions executable by the processor, wherein the instructions comprise a plurality of sub-word finite state machines (FSMs), each sub-word FSM having a word size less than N-bits, wherein when executed, the instructions cause the processor to: execute the sub-word FSMs to process corresponding segments of said data words in parallel, respectively; generate a match output for each sub-word FSM that transitions to a match state based on a corresponding segment of said data words matching said pattern; generate a combined pattern match output when all of the FSMs generate the match outputs, indicating a match of said data words to said pattern; and determine when there is a common state reported by all of the single bit FSMs, wherein: said pattern is a variable pattern specifying a string that cannot be predicted in advance in terms of length; and the input stream comprises a series of measurements produced by a digital oscilloscope data.
2. The apparatus of claim 1, wherein said apparatus emulates a single FSM operating on said data words to match said pattern, and wherein said match output corresponds to different possible match states in said single FSM.
3. The apparatus of claim 1, wherein said apparatus emulates a single FSM operating simultaneously on a plurality of said data words.
4. The apparatus of claim 1, wherein said pattern does not have a predetermined fixed length.
5. The apparatus of claim 1, wherein said pattern corresponds to an FSM having multiple tokens on an edge that needs to be distinguished.
6. The apparatus of claim 1, wherein one bit of said data words is not processed by any of said sub-word FSMs.
7. The apparatus of claim 1, wherein each sub-word FSM is configured to transition to the match state without regard to transitions being made in other sub-word FSMs.
8. The apparatus of claim 1, wherein the input stream comprises a series of measurements produced by a digital oscilloscope data.
9. A method for operating a computer to identify a variable pattern in an input data stream comprising a sequence of input words, wherein the variable pattern specifies a string that cannot be predicted in advance in terms of length, each input word comprising a plurality of sub-words having fewer bits than said input words, said method comprising: receiving a collection of match outputs from single bit FSMs; operating a plurality of sub-word finite state machines (FSMs) in parallel on different sub-words, respectively, of each of said input words; providing a matched output indicative of a possible pattern match for each sub-word FSM that transitions to a matched state based on the respective sub-word of said input words matching the variable pattern; determining when all of said matched outputs of said sub-word FSMs of each of said input words are provided, indicating a common matched state of said input words to said variable pattern; determining when there is a common state reported by all single bit FSMs; and outputting that common matched state wherein the input data stream comprises a series of measurements produced by a digital oscilloscope data.
10. The method of claim 9, wherein said plurality of sub-word FSMs emulate a single FSM operating simultaneously on said input words.
11. The method of claim 9, wherein said variable pattern does not have a predetermined fixed length.
12. The method of claim 9, wherein said variable pattern corresponds to an FSM having multiple tokens on an edge that needs to be distinguished.
13. The method of claim 9, wherein one bit of said input words is not processed by any of said sub-word FSMs.
14. The method of claim 9, wherein each sub-word FSM is configured to transition to the matched state without regard to transitions being made in other sub-word FSMs.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
DETAILED DESCRIPTION
(10) The present invention provides a parallel search engine utilizing FSMs that have a word size significantly smaller than the word size of the input data and that can operate in parallel to search for a variable pattern. To simplify the following discussion, the word size utilized by an FSM will be referred to as the FSM word size. This word size could be larger or smaller than the word size of the input string being searched. The word size of the string being searched will be referred to as the input word size. In the cases of interest here, the FSM word size is significantly less than the input word size. An FSM that operates on a FSM word size that is less than that of the input word size will be referred to as a sub-word FSM. The smallest sub-word FSM has an FSM word size of 1 bit.
(11) The manner in which the present invention provides its advantages can be more easily understood in terms of a search engine that includes a plurality of single bit FSMs operating in parallel to emulate a larger FSM that searches for a pattern in an input data sequence. The larger FSM will be referred to as the one word FSM in the following discussion. Assume that a one word wide search engine has already been designed for a pattern of interest. Methods for generating an FSM for a pattern that is represented by a regular expression are known to the art, and hence, will not be discussed in detail here.
(12) The input words for the sequence are N-bits wide and the number of states in the one word FSM will be denoted by M. The one word FSM is typically represented by a state diagram in which the various states are connected by a plurality of “edges” that represent transitions between the states. Each edge has a starting state and an ending state and one or more “tokens”. The ending state is the next state for the FSM when the current state is the starting state and a word having the value of one of the tokens is received. In principle, there are 2.sup.N possible token values for each state, since each N-bit input word has 2.sup.N possible values. Hence, the FSM can be operated by a simple table lookup operation in a table having 2.sup.N rows and M columns that gives the next state for each of the M possible current states and the current input word. Hence, the time to make a transition is essentially independent of the number of states in the FSM.
(13) For large values of N, the memory required by this table makes this simple approach impractical. N values of 32 or 64 bits are often needed for applications in which the input data stream is a series of measurements from an instrument such as a digital oscilloscope. In such applications, the FSM is used to parse the waveform measured by the instrument to identify features of interest. Hence, a mechanism for reducing the amount of memory required to implement a large word FSM is needed.
(14) In one embodiment of the present invention, N single bit FSMs are used in parallel to search the input stream. As will be discussed in more detail below, one or more of the single bit FSMs may have a larger number of states than the N-bit word FSM. Denote this maximum number of states by M′. The single bit FSMs require tables that have only two rows by M′ columns at most. There are now N such FSMs operating in parallel. In the case of a one byte search word, N=8 and the memory requirement is less than or equal to 16 rows by M columns as compared to 256 rows by M states. Even if the number of states is significantly higher in the 1-bit FSMs, there is still a significant memory savings.
(15) In general, the N single bit FSMs working in parallel will require approximately the same time to complete the search. Hence, the major savings in this approach is one of cost, since the cost is a direct function of the memory requirement. However, the smaller size of the FSMs may also result in some speed improvement due to using a simpler circuit. In addition, this approach makes large input word FSMs practical.
(16) To obtain a significant speed improvement over the one word FSM, an FSM that operates on two words at a time can be derived from the original one word FSM. This new two word FSM is then implemented as 2N single bit FSMs working in parallel. In this case, a speed factor of two is provided by the parallel processing as the length of the input stream is effectively halved. Additional improvements can be realized by using an FSM having a search word that is a higher multiple of N and then implementing a corresponding collection of single bit FSMs. In this case memory savings can become significant.
(17) To simplify the following discussion, it will be assumed that the sub-word FSMs are single bit FSMs. The manner in which other size sub-word FSMs can be utilized will then be discussed in more detail. In general, the N-bit FSM has at least one state that is a “matched” state. When the FSM enters this state, a signal is generated to the processing hardware attached to the FSM indicating that a match has been found for one of the target patterns for which the FSM was created. There may be multiple such match states within an FSM.
(18) Each single bit FSM operates on a corresponding bit of the input words to the N-bit FSM. Each single bit FSM must make its transitions without regard to the transitions being made in the other single bit FSMs. When an input word to the N-bit FSM would trigger a match in that FSM because the target pattern had been found, each single bit FSM must likewise report a match. It should be noted that the single bit matches may specify a plurality of possible match states in the larger FSM. A combining processor receives the collection of match outputs from the single bit FSMs and determines if there is a common state reported by all of the single bit FSMs. That common state is then reported out as the matched state.
(19) Given a search pattern consisting of a regular expression, there is a minimal FSM that implements that regular search pattern. The minimal FSM is the FSM with the minimum number of states that implements the search pattern. The minimum FSM has a unique topology. Given any FSM for a particular pattern, the minimal pattern can be derived by removing or merging states. Any state that is unreachable from the initial state for any input can be removed. Any two states that cannot be distinguished from one another for any input can be merged together. When the FSM no longer has any unreachable states or indistinguishable states, it is the minimal FSM.
(20) An FSM that implements a search for a variable pattern has a minimal FSM in which there are multiple tokens on at least one edge or one that contains direct loops created by wildcards such as “*”. That is, there will be two states in the minimal FSM that have the property that a transition from the first state to the second state will occur for multiple different input values, or repeating input values or, possibly, no input value at all. In contrast, an FSM that searches for a fixed pattern has a minimal FSM that has only one single token on all edges to a given state.
(21) Prior art techniques for deriving a plurality of single bit FSMs from a one word FSM only work reliably if the one word FSM has a corresponding search pattern that is a fixed pattern. In addition, FSMs that include multiple tokens on an edge but have a fixed length pattern also present challenges when attempting to implement such FSMs as a plurality of sub-word FSMs.
(22) The manner in which the present invention provides its advantages can be more easily understood with reference to a simple example. Consider a stream of data words that is to be checked for correct parity. Each data word has either even or odd parity. The regular expression for a parity calculator is as follows
({even}*{odd}{even}*{odd})*{even}*
(23) Here “even” stands for a word in the stream having even parity and “odd” stands for a word in the stream having odd parity. The regular expression is satisfied by any number (zero or more) words with even parity followed by a word with odd parity, followed by any number of words with even parity followed by a word with odd parity repeated any number of times followed by any number of words with even parity. This pattern has a variable and unknown length, since “*” means zero or more of the preceding value. In addition, the minimal FSM for finding this pattern has multiple tokens on an edge between two states that are indistinguishable at the bit level for all known inputs.
(24) To simplify the example, the data stream will be assumed to be 3-bit words. i.e., the integer values from 0 to 7. It should be noted that 0, 3, 5, and 6 have even parity and 1, 2, 4, and 7 have odd parity. Hence, for this 3-bit word case, the regular expression is as follows:
({0,3,5,6}*{1,2,4,7}{0,3,5,6}*{1,2,4.7})*{0,3.5,6}*
(25) To improve legibility, commas have been used to separate the integer tokens and braces ‘{’ and ‘}’ are used to group the tokens together.
(26) The minimal FSM for implementing this pattern is shown in
(27) Refer now to
(28) Since each of the FSMs only operates on a single bit stream, that FSM must make state changes based solely on that bit value and those state changes must correspond to state changes in the FSM that would be operating on the whole words for the matched states of the one word FSM. However, as will be explained in more detail below, a state of a one-bit FSM may correspond to multiple states in the one-word FSM. The bit values for the eight states in this example are shown below, the least significant bit is b.sub.0:
(29) TABLE-US-00001 Word Value b.sub.0 b.sub.1 b.sub.2 0 0 0 0 1 1 0 0 2 0 1 0 3 1 1 0 4 0 0 1 5 1 0 1 6 0 1 1 7 1 1 1
(30) The FSM in
(31) A similar problem occurs when an “*” is in the pattern even if the edges have only one token. Consider the simple pattern “za*” that is to be searched in an input string of ASCII characters. The pattern is satisfied by z followed by any number, including 0, of a's. That is, a match corresponds to ‘z’, “za”, “zaa”, and so on. The word wise FSM for this pattern is shown in
(32) The problem with implementing this FSM in eight single bit FSMs can be most easily appreciated for the FSM dealing with the least significant bit. In ASCII, the least significant bit of a ‘z’ is 0, while that of an ‘a’ is 1. Assume that the FSM has transitioned from state 0 to state 1 because it received a 0. If the next bit received is not an ‘a’, the FSM is to return to state 1. If the next bit is from an ‘a’, the FSM remains in the current state and reports another match. The problem again lies in the FSM's inability to determine whether a 1 that is received next corresponds to an ‘a’ or some other character that has a 1 in its least significant bit. For example, an ‘s’ also has a one in its least significant bit. Hence, the single bit FSM for implementing the FSM shown in
(33) The present invention avoids this problem by expanding the one word FSM for which the sub-word FSMs fail to a new FSM in which the sub-word FSMs operate correctly. Refer again to
(34) The state numbers in
(35) The remaining edges can be understood by following a sequence of input values and comparing the results to those obtained with the FSM of
(36) While the FSM shown in
(37) Refer now to
(38) The process is now repeated for each of the new states and the possible input values to FSM.sub.0 of 0 and 1. Assume that FSM.sub.0 is in A1 and a 1 arrives as the next input to FSM.sub.0. This situation can occur if FSM.sub.w was in any of states 1, 3, 5, or 7 and the next input word was a 1, 3, 5, or 7. Hence, the next state, denoted as B1, corresponds to all of those states in FSM.sub.w that could be the end point if one of the potential input words was received by one of the possible states in the list in A1. These are summarized in the following table:
(39) TABLE-US-00002 input value of starting state of FSM.sub.w for b.sub.0 = 1 FSM.sub.w 1 3 5 7 1 0 2 4 6 3 2 0 6 4 5 4 6 0 2 7 6 4 2 0
(40) Hence, the possible states for B1 are 0, 2, 4, and 6: however, these are exactly the same states as state A0. Hence, states A0 and B1 are the same. Accordingly, the partially finished FSM.sub.0 is now as shown in
(41) TABLE-US-00003 input value of starting state of FSM.sub.w for b.sub.0 = 0 FSM.sub.w 0 2 4 6 1 1 3 5 7 3 3 1 7 5 5 5 7 1 3 7 7 5 3 1
(42) Hence, the possible FSM.sub.w states corresponding to B0 are 1, 3, 5, and 7. However, these are the same states as A1; hence A1 and B0 are the same state. Accordingly, the partially finished FSM.sub.0 is now as shown in
(43) This procedure is now repeated starting from the states in A0 and assuming that an input word having b.sub.0=1 is received by FSM. The results are summarized in the following table.
(44) TABLE-US-00004 input value of starting state of FSM.sub.w for b.sub.0 = 1 FSM.sub.w 1 3 5 7 0 1 3 5 7 2 3 1 7 5 4 5 7 1 3 6 7 5 3 1
(45) Hence, the states that result from a bit value of 1 being input to state A0 are again 1, 3, 5, and 7. These are the same states that corresponded to state A1; hence, no new state is created. That is, A0 transitions to A1 when a 1 is received. Repeating this procedure for A0 and an input bit of 0 results in a state that corresponds to FSM.sub.w states of 0, 2, 4, and 6. This is just A0 again. Accordingly, the final FSM.sub.0 is as shown in
(46) In practice, a match corresponding to state x is reported by combiner 14 when each single bit FSM reports out a match on receiving an input bit from the current input word and the lists of states reported by each single bit FSM contain state x.
(47) In the above examples, an N-bit word FSM was replaced by N 1-bit wide FSMs. For large values of N, this strategy provides reduced memory requirements and a potential for some increase in speed due to the use of many simple small circuits rather than one large complex one. To provide additional speed improvements, a multi-word FSM can first be created from the original N-bit word FSM. For example, a two word wide FSM could be created from the one word wide FSM and then 2N single bit FSMs would be used to implement the two word wide FSM. In this case, an increase of up to a factor of two could be realized over the one-word FSM. Hence, the present invention has the potential to significantly reduce the time needed to scan a large data set for a variable pattern.
(48) In some cases, larger sub-word FSMs may be more efficient depending on the specific search pattern being implemented. For the purposes of the present discussion, a sub-word FSM is defined to be an FSM that operates on less than all of the bits of the words in the input data sequence. For example, a 64-bit word FSM could be implemented as 32 2-bit FSMs or 16 4-bit FSMs. In addition, not all of the sub-word FSMs need be the same size. In the above-described procedure, the one word wide variable pattern FSM was first expanded to provide an FSM with one token on each edge to arrive at an FSM that could be reliably implemented as a plurality of sub-word FSMs. However, other strategies could be utilized.
(49) The problems encountered in finding a single bit FSM version of the FSM in
(50) Refer now to
(51) The ASCII values for ‘z’, ‘a’ and ‘b’ are given in the following table:
(52) TABLE-US-00005 Token bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 z 0 1 1 1 1 0 1 0 a 0 1 1 0 0 0 0 1 b 0 1 1 0 0 0 1 0
The problem with implementing this FSM in eight single bit FSMs can be most easily appreciated for the FSM dealing with the least significant bit. In ASCII, the least significant bit of a ‘z’ is 0, while that of an ‘a’ is 1. Assume that the FSM has transitioned from state 0 to state 1 because it received a 0. If the next bit received is not an ‘a’, the FSM is to return to state 0. If the next bit is from an ‘a’, the FSM remains in the current state and reports another match. The problem again lies in the FSM's inability to determine whether a 1 that is received next corresponds to an ‘a’ or some other character that has a 1 in its least significant bit. For example, an ‘s’ also has a one in its least significant bit and needs the FSM to transition to state 0 not state 1.
(53) Refer now to
(54) Hence, the FSM in
(55) In general, the process of expanding an arbitrary one word FSM to remove edges with multiple tokens that cannot be resolved at the sub-word level proceeds in an analogous manner. An edge that cannot be resolved at the desired sub-word level will be referred to as an ambiguous edge. The ambiguous edge is split into two or more edges such that each edge is now resolvable at the desired sub-word level. That is, the new edges are all not ambiguous. New states are introduced to receive the new edges. The one word pattern being matched is then used to examine each possible input for each of the new states. If an input returns to a known state, that edge is directed to that state and no further actions are needed for that edge. If the input causes the FSM to move to a state that is not already known, that new state is introduced and connected by the edge in question. For each new state, all of the possible inputs are explored and edges to corresponding states are created, either a new state or a previously known state. When all inputs to all new states have been explored and no new states are needed, the process terminates.
(56) Refer now to
(57) The manner in which FSM.sub.0 is obtained from
(58) Next, all possible edges from this new state “0,1” in the word wise FSM in
(59) The process must now be repeated for the two new compound states “0,2” and “0,1,2” by exploring the possible transitions for the various inputs when the one word FSM is in these states. For state “0,1,2” inputs 0 and 3 decimal are a fail and return to state 0. However, for input 1, the FSM goes to state 0 on fail and 2 on ‘a’. The compound state “0.2” already exists, so no new state is needed. For input 2, the one word FSM goes to state 0 on ‘a’ (fail), state 1 on ‘z’ and state 2 on a ‘b’. Again, the compound state “0,1,2”, has already been defined, and hence, the result of this expansion is shown in
(60) Finally, the transitions corresponding to the various inputs to the compound state “0,2” must be explored. Inputs 0 and 3 decimal are a fail and return the one word FSM to state 0. However, for input 1, the one word FSM goes to state 0 on a fail and state 2 on ‘a’. The compound state “0,2” already exists. For input 2, the one word FSM goes to state 0 on ‘a’ (fail), state 1 on ‘z’, and state 2 on a ‘b’. This compound state “0,1,2” already exists and hence, the state diagram is left as in
(61) Refer now to
(62) Refer now to
(63) In the above-described embodiments, a one word FSM was emulated using a plurality of sub-word FSMs working in parallel. In these embodiments, each bit of the one word FSM was processed in at least one of the sub-word FSMs. However, there are cases in which not all of the sub-word FSMs are required. That is, one or more of the one word FSMs is redundant. Consider the case in which the one word FSM searches an ASCII string for a specific sequence of characters and in which the case of the characters does not matter. For example, the FSM could search for the sequence “mad” in which each character could be upper or lower case. That is, the sequences Mad, mad, MAd, etc. satisfy the target sequence. If this FSM is replaced by seven single-bit FSMs, the FSM that operates on the fifth most significant bit is redundant, since this bit merely distinguishes between a lower case letter and an upper case letter.
(64) In another aspect of the present invention, each FSM in the set of sub-word FSMs is tested for redundancy. If the candidate FSM is redundant, the candidate can be eliminated from the set of sub-word FSMs with a corresponding reduction in computational workload and memory. Consider all possible inputs to the one word FSM. Suppose the one word FSM reports out a match at state K in the one-word FSM for one of the inputs to that FSM. All of the sub-word FSMs must report out a match in which the intersection of the lists reported by each sub-word FSM is “K”. The candidate sub-word FSM is redundant if:
(65) (1) the remaining sub-word FSMs report matches and the intersection of the match lists is the state K.
(66) (2) the candidate sub-word FSM also reports out a match state with a list containing K.
(67) (3) For any non-match state in the one word FSM, at least one of the remaining sub-word FSMs is in a non-match state or the intersection of the match state lists reported by the remaining sub-word FSMs is null.
(68) The computational workload to test a candidate FSM can be reduced significantly by altering the manner in which the sub-word FSMs are generated from the one word FSM. In the above-described procedure, each state in a sub-word FSM that reports a match has a list of reporting states in the one word FSM that could correspond to that state in the sub-word FSM. In the modified procedure, the list associated with each state in the sub-word FSM contains all states in the one-word FSM that could correspond to that state in the sub-word FSM. In addition, all states in the one word FSM, not just the reporting states, are included in this list. Finally, each state in the sub-word FSM includes a corresponding list of possible states in the one word FSM whether or not that state in the sub-word FSM is a reporting state.
(69) Assume each sub-word FSM reports at each state with the list of possible states in the one word FSM that correspond to that state. This report occurs whether or not the sub-word FSM is in a match reporting state. Hence, for any state in the one-word FSM, all possible sub-word FSM states in each sub-word FSM are known. In particular, denote the sub-word FSMs other than the candidate FSM by the “remaining sub-word FSMs”.
(70) Consider a state, Q, in the one word FSM. Q will appear in one or more of the lists of the sub-word FSMs. To simplify the following discussion, assume that the candidate FSM is sub-word FSM.sub.0. The remaining sub-word FSMs will be labeled FSM.sub.1, FSM.sub.2, . . . FSM.sub.N. Consider FSM.sub.1. Each state has a list of one-word FSM states associates with that state. Define a vector S[s.sub.1, . . . , S.sub.N], where s.sub.1 is a state of sub-word FSM.sub.1, s.sub.2 is a state of FSM.sub.2, etc. Each of these states has a corresponding list that provides the possible lists in the one word FSM. Define S[s.sub.1, . . . , s.sub.N]=Q if all of the lists in the states contain state Q in the one word FSM. The vector [s.sub.1, . . . , s.sub.N] will be referred to as the sub-word state vector in the following discussion.
(71) Consider the case in which Q is a reporting state. Then there is at least one state vector for which the remaining FSMs report a match. Consider all possible state vectors for which S=Q. For each state vector, each sub-word FSM will report out a list that includes Q and possibly other states. Compute the intersection of the lists for each of these states. There are two cases of interest, either the intersection includes only reporting state Q or there are multiple reporting states. If the intersection includes multiple reporting states, then FSM.sub.0 is needed to resolve the ambiguity, and hence, FSM.sub.0 is not redundant. If the reporting state is uniquely Q then FSM.sub.0 is not needed to resolve any ambiguity corresponding to Q, and hence, FSM.sub.0 is possibly redundant.
(72) If FSM.sub.0 is possibly redundant, then the above test must be repeated for each value of Q in which Q is a reporting state in the one word FSM. Assume that the results are the same, i.e., FSM.sub.0 is possibly redundant. Then the remaining sub-word FSMs can uniquely identify each reporting state in the one-word FSM.
(73) Hence, in this case FSM.sub.0 is not needed to identify a match. FSM.sub.0 could be needed, however, to defeat a false positive. Consider the case in which Q is not a reporting state in the one word FSM, and there is a state vector corresponding to Q in which the intersection of the states happens to include a reporting state K. While this is expected to be a rare occurrence, it could occur. In this case FSM.sub.0 is needed to eliminate the false positive, and hence, is not redundant.
(74) The above-described embodiments of the present invention have been provided to illustrate various aspects of the invention. However, it is to be understood that different aspects of the present invention that are shown in different specific embodiments can be combined to provide other embodiments of the present invention. In addition, various modifications to the present invention will become apparent from the foregoing description and accompanying drawings. Accordingly, the present invention is to be limited solely by the scope of the following claims.