Method and computer system for the real-time evaluation of matrix expressions of a code
The method compiles source code into object code with pre-allocated memory spaces and stack-based allocation to address execution time challenges in real-time systems, enhancing matrix expression processing efficiency and reducing errors.
Patent Information
- Application Number
- FR2023015076
- Authority / Receiving Office
- FR · FR
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2026-02-20
- Estimated Expiration
- 2043-12-22
AI Technical Summary
Existing real-time systems face challenges in processing complex matrix expressions due to unbounded execution times caused by dynamic memory allocation, leading to implementation errors and increased memory footprint, which complicates programming and hinders compliance with timing constraints.
A method and system that compiles source code into object code, using pre-allocation of temporary memory spaces and explicit instantiation of dynamic matrices, ensuring bounded execution times and optimal memory usage through a stack-based allocation strategy, allowing for readable and maintainable code without intermediate matrix definitions.
Ensures efficient processing of complex matrix expressions within bounded execution times, minimizing memory footprint, reducing implementation errors, and maintaining optimal computational performance in real-time systems.
Smart Images

Figure 00000024_0000 
Figure 00000025_0000 
Figure 00000025_0001
Abstract
Description
Title of the invention: Method and computer system for the real-time evaluation of matrix expressions of a code. Technical field
[0001] The present invention relates generally to computer systems, and in particular to a method and a system for the real-time evaluation of matrix code expressions.
[0002] Time-constrained systems (also called "real-time systems") operate under the control of one or more computer programs and take into account execution time constraints that must be respected. In particular, real-time systems use a computer device to execute object code, comprising instructions to be executed, which governs the operation of the system under time constraints.
[0003] For certain real-time systems, such as robotic control systems, the object code to be executed is compiled from source code comprising one or more matrix expressions to be evaluated (i.e., calculated). In the case of such real-time systems, compliance with the system's execution timing constraints is as important as the conformity of the results of the evaluation of the matrix expressions in the source code.
[0004] Computer devices for executing software code that require the evaluation of dynamic matrix expressions generally use the automatic and implicit instantiation of dynamic matrices to store the results of intermediate calculations of these matrix expressions. In particular, the automatic instantiation implemented induces dynamic memory allocation and deallocation operations. Such operations, when performed through the language's default allocator, generally take place in the "Heap".
[0005] However, in systems subject to real-time constraints, such automatic instantiation, inducing a dynamic allocation of memory via the default allocator of the language, cannot generally guarantee a bounded execution time, and therefore cannot guarantee compliance with the temporal constraints essential to the proper functioning of such systems.
[0006] To enable the processing of a matrix expression within a bounded execution time, a commonly used method consists of using a decomposition of complex matrix expressions into simple sub-expressions, unary or binary for the arithmetic operators, as well as an explicit pre-instantiation, outside of a real-time context, of the dynamic matrices intended for storing the Intermediate results of the decomposed sub-expressions. However, such decomposition places a heavy burden on the programmer, making the writing of complex matrix expressions tedious, difficult to read, and prone to implementation errors. Furthermore, this necessitates the definition of numerous intermediate matrices, thus increasing the memory footprint of the computer program at runtime.
[0007] There is therefore a need for a system and a method capable of improving the processing of complex matrix expressions using dynamic matrices, in particular in real time. Summary of the invention
[0008] To this end, a method for compiling source code into object code is proposed, implemented in a compilation tool. The compilation method comprises the steps of: - receive source code including at least one matrix expression, - determine, for each matrix expression in the source code, N matrix operations, N being an integer greater than or equal to 1, from a syntactic analysis of the matrix expression, the matrix operations being ordered according to a relative order of operational precedence rules, - generate object code from matrix operations determined from at least one matrix expression, the object code comprising machine instructions executable by at least one processor, the object code comprising at least one thread of execution associated with one or more matrix expressions from among at least one matrix expression, and - deliver the object code to an object code execution device capable of executing the object code, and comprising a storage unit, the storage unit being capable of including at least one temporary memory space, each temporary memory space being capable of including temporary memory subspaces.
[0009] The object code instructions include, for each thread of execution: - instructions for pre-allocating temporary memory space in the execution device's storage unit, and - for each matrix expression associated with the execution thread, instructions for the successive execution of N groups of instructions according to the order relative to operational priority rules, each group of instructions being associated with one of the N matrix operations and comprising: - an instruction to allocate an intermediate result matrix corresponding to the result of the matrix operation evaluation, in a temporary memory subspace of the temporary memory space, and - an instruction for evaluating the matrix operation and storing the corresponding intermediate result matrix, - an instruction to deliver the Nth intermediate result matrix as a result of the execution of at least one matrix expression associated with the thread of execution.
[0010] The present invention further proposes a computer method comprising a phase of compiling source code into object code and a phase of executing the object code, the method being implemented in a computer system comprising a compilation tool and code execution means, the code execution means comprising a storage unit.
[0011] The method comprises, in the compilation phase, the steps of: - receiving source code comprising at least one matrix expression, - determining, from a syntactic analysis of the at least one matrix expression, N matrix operations, N being an integer greater than or equal to 1, the matrix operations being ordered according to an order relative to operational precedence rules, and - generate object code from N matrix operations, comprising machine instructions executable by at least one processor, the object code comprising at least one thread of execution associated with one or more matrix expressions from among at least one matrix expression,
[0012] The method comprises, in the execution phase of the object code, for each thread of execution, the steps consisting of: - pre-allocate temporary memory space in the execution device's storage unit, and - For each matrix expression associated with the execution thread, successively execute the N matrix operations determined for the matrix expression, according to the order related to operational precedence rules, the execution of one of the matrix operations comprising the steps of: - allocate an intermediate result matrix corresponding to the result of the matrix operation evaluation, in a temporary memory subspace of the temporary memory space, and - evaluate the matrix operation and store the intermediate result matrix in the temporary memory subspace, - deliver the Nth intermediate result matrix as a result of the execution of at least one matrix expression associated with the execution thread.
[0013] In embodiments, for each matrix expression associated with the thread of execution, the temporary memory subspaces, associated with the provided intermediate result matrices, can be allocated according to a dynamic allocation strategy. of the "stack" type in at least one pre-allocated temporary memory space in the storage unit and associated with the thread of execution.
[0014] Advantageously, for each thread of execution, temporary memory space can be pre-allocated in a "Heap" memory segment, the storage unit corresponding to the default dynamic memory allocator.
[0015] In some embodiments, the method may include, in the execution phase, a step of pre-allocating at least one persistent memory space in the storage unit, and for each thread of execution, a step of assigning, for each matrix expression associated with the thread of execution, the Nth intermediate result matrix of the Nth temporary memory subspace to a matrix of the persistent memory space.
[0016] The method may include, in the execution phase, for each thread, a step consisting of deallocating, for each matrix expression associated with the thread, the N temporary memory subspaces of the temporary memory space associated with the thread.
[0017] Advantageously, the method may include, in the execution phase, for each thread of execution, a step consisting of deallocating the temporary memory space of the storage unit.
[0018] The size of the pre-allocated temporary memory space for each thread of execution can be determined as a function of the number N of intermediate result matrices provided and the size of the intermediate result matrices associated with a matrix expression of the thread of execution.
[0019] A compilation tool configured to implement the compilation process is also proposed.
[0020] In some embodiments, the tool may include a computer library and a compiler, the source code being compiled by the compiler from a set of predefined processing instructions in the computer library.
[0021] The embodiments of the invention thus provide a computer system configured to implement the compilation process.
[0022] Advantageously, the means of code execution can be subject to real-time constraints.
[0023] The embodiments of the invention thus provide a system and a method capable of improving the processing of matrix expressions using dynamic matrices, by optimizing computational performance and guaranteeing a bounded execution time.
[0024] In particular, they ensure the absence of automatic and implicit dynamic allocation of dynamic matrices via the language's default allocator (i.e., in the Heap) to store the results of intermediate expression calculations. matrix-based architectures ensure minimal memory footprint and optimal execution performance through preserved data co-locality via a specific allocation strategy. This results in a solution compatible with computing devices (or computer systems) subject to time constraints.
[0025] They also allow the use of a notation for so-called literal matrix expressions, in a conventional format (that is, in a format conforming to the mathematical notation of the expression), which is readable and easy to maintain, regardless of their complexity, without requiring the definition of intermediate matrices. The programmer's effort is thus greatly reduced, the associated computer code gains in readability and maintainability, and is less prone to implementation errors. Description of the figures
[0026] Other features, details and advantages of the invention will become apparent from the description made with reference to the accompanying drawings given by way of example.
[0027] [Fig-1] Fig. 1 is a diagram representing a system comprising a device a computer compilation and a computer execution device, according to embodiments of the invention.
[0028] [Fig.2] Fig.2 shows two diagrams (a) and (b) representing the states of a temporary memory space respectively before and during the evaluation of a matrix expression by a computer execution device, according to embodiments of the invention.
[0029] [Fig.3] Fig.3 is an example of the implementation of lines of code from a library computing computing used by a computer compilation device, according to embodiments of the invention.
[0030] [Fig.4] Fig.4 is a flowchart representing a processing method matrix expressions, by a computer compilation device, according to embodiments of the invention.
[0031] [Fig. 5] Fig. 5 is a flowchart representing a code processing method object resulting from the compilation of matrix expressions, by a computer execution device, according to embodiments of the invention.
[0032] Identical reference numerals are used in the figures to designate identical or analogous elements. For clarity, the elements shown are not to scale. Detailed description
[0033] Fig. 1 schematically represents a system 1 comprising a computer compilation device 10 and a computer execution device 20, according to embodiments of the invention.
[0034] The computer compilation device 10 is configured to compile a source code 121 into an object code 221 intended to be executed (i.e. the object code is executable) by the computer execution device 20.
[0035] The computing execution device 20 can be used in numerous applications requiring calculations on dynamic matrices and subject to real-time constraints. The computing device can, in particular, be a control device (or 'process control' device). For example, and without limitation, such a computing device can be a robotic control device, an aircraft navigation control device, a control device for a complex cyber-physical device, a numerical simulation device for complex devices, or a signal processing device (in particular, an image processing device).
[0036] As shown in [Fig. 1], the computer execution device 20 may be different from the computer compilation device 10. Alternatively, the compilation device 10 and the execution device 20 may be one and the same computer device.
[0037] The computer compilation device 10 (also called 'compilation tool' or 'source code compilation device') includes a processor 160, the source code 121 to be compiled and a computer library 123. The computer device 10 further includes a computer compilation program, also called compiler 125, intended to be loaded into a RAM 141 of the computer compilation device 10 in order to be executed by the processor 160.
[0038] The source code 121 and the computer library 123 comprise lines of code written in a computer language. The computer language may be a compilable object-oriented computer language, such as, for example, but without limitation, C++. The source code 121 comprises one or more matrix expressions E to be processed (i.e., evaluated, computed). The computer library 123 comprises predefined processing instructions including definitions and declarations of properties in source code form. The computer library may also include executable machine code. The lines of source code 121 are intended to be compiled into object code 221 by the compiler 125 from the compilation rules of the language and the predefined processing instructions of the computer library 123.
[0039] In some embodiments, the source code 121, the computer library 123 and the compiler 125 can be contained in the mass memory (not shown in the figures) of the computer device 10.
[0040] As used here, the term "matrix expression" refers to a literal matrix algebraic expression of any form, composed of a finite combination of symbols and respecting the order of precedence of arithmetic operators.
[0041] For example, and without limitation, a matrix expression, denoted E, can be defined as the following equation (01):
[0042] E: {R = A * X + B * Y} (01)
[0043] In equation (01), the terms R, A, X, B, and Y are symbols representing matrices. The matrices A, X, B, and Y correspond to the input matrices from which the matrix expression E is evaluated (i.e., calculated, determined). The matrix R is the result matrix resulting from the evaluation of the matrix expression E.
[0044] In equation (01) also, the terms “*” and “+” are operator symbols, representing respectively the matrix composition (or multiplication, or product) and addition (or sum) arithmetic operators.
[0045] It should be noted that a matrix expression E is composed of N elementary matrix operations (also called 'elementary expressions'), denoted On, associated with an index 'n' which is an integer between 1 and N and corresponds to the nth matrix operation. The value of N is an integer greater than or equal to 1. Each matrix expression E from source code 121 can be characterized by a number N of distinct ordered matrix operations and / or specific to the matrix expression E. The result of the execution (or evaluation) of a matrix operation On of the matrix expression E produces an intermediate result matrix, denoted Tn.
[0046] Each matrix operation On of a matrix expression E comprises a unique operation symbol. A matrix operation can be a unary operator (relating to the processing of a single matrix operand), a binary operator (relating to the processing of two operands), or a function of any number of operands. For example, and without limitation, such a function can be a unary function, such as the 'determinant' function det(A) or the trace function tr(B), or a binary function, such as the 'Kronecker product' function kron(C, D), where A, B, C, and D represent matrices.
[0047] A matrix operand of matrix operation On can be an input matrix of the matrix expression E, or an intermediate result matrix Th associated with another matrix operation of the matrix expression E, denoted Oh, whose index 'h' is an integer between 1 and n. The N matrix operations of a matrix expression E can be ranked according to an order defined from priority rules (corresponding to the priority rules of operations and, in particular, of arithmetic operators, i.e. the rules of order of processing of operation symbols). In some embodiments, a binary matrix operation may include a matrix operand and a scalar operand.
[0048] In the example represented in equation (01), the matrix expression E illustrated comprises three matrix operations Ob O2 and O3 defined according to the following expressions (02), (03) and (04):
[0049] Oi: { Tj = A * X} (02)
[0050] O2: { T2 = B * Y} (03)
[0051] O3: {T3 = T1 + T2}(04)
[0052] The intermediate matrices (resulting from the evaluation of matrix operations) Intermediate matrices) are dynamic matrices. As used here, the term "dynamic matrix" refers to a matrix of unknown dimension at the compilation of source code 121. The input matrices of the matrix expression E and / or the result matrix R (resulting from the evaluation of E) can also be dynamic matrices.
[0053] The input matrices of the matrix expression E can be described as "persistent matrices." Advantageously, the intermediate result matrices Tn associated with the matrix operations On can be described as "temporary matrices." As used here, the term "temporary matrix" refers to a matrix created in a specific memory space of a computing device during the execution of software code and then deleted during or at the end of execution time. Any matrix that is not a temporary matrix is a persistent matrix. Thus, the term "persistent matrix" refers to a matrix that remains (i.e., persists) in memory in the computing device beyond the local scope of the software code that created it.
[0054] The computer execution device 20 (also called 'code execution means', 'code execution device') may include a storage unit 240, as well as a processor 260 for executing the object code 221 generated by the computer compilation device 10, as shown in [Fig.1].
[0055] In some embodiments, the storage unit 240 of the computing execution device 20 (also called 'backup unit' or 'storage module') can be the data segment.
[0056] As used here, the term "data segment" can refer to a segment of RAM dedicated to the data of the object code execution process. The term "data segment" can therefore refer to a memory region that may include: the memory space used by the language's default dynamic memory allocator, i.e., the "Heap" (or "heap memory" in English). corresponding), the "Stack" (or 'stock memory' according to the corresponding Anglo-Saxon expression), and / or the memory space reserved for so-called static data.
[0057] Object code 221 comprises instructions which, when executed by processor 260, command the execution computer 20 to process the matrix expressions from source code 121. In other words, object code 221 comprises machine instructions executable by at least one processor. In particular, object code 221 may include initialization instructions, processing instructions, and termination instructions. The execution computer 20 for object code 221 can thus be configured to process some or all of the matrix expressions E contained in source code 121.
[0058] Considering a computer execution device 20 of the robotic system type, by way of non-limiting example, the estimation of the state of such a robotic system can be carried out by Kalman filtering, an algorithm requiring the evaluation of complex matrix expressions. In such a case, a complex matrix expression to be processed by the robotic system can include, for example, up to 7 combined unary and / or binary elementary expressions, for a linear Kalman filter.
[0059] To compile the source code 121 and generate the object code 221, the computer compilation device 10 can be configured to identify (or detect) one or more matrix expressions E in the source code 121 and to determine, for each detected (or found) matrix expression E, the N associated matrix operations On, based on a syntactic analysis of the matrix expression E under consideration. Advantageously, such a syntactic analysis of the matrix operations can be performed using the computer library 123 and the rules of the computer language.
[0060] The object code 221 generated by the computer compilation device 10 comprises a set of at least M execution threads (or 'execution threads'), denoted Fm, whose index 'm' is an integer between 1 and M corresponding to the m-th execution thread, the value of M being an integer greater than or equal to 1. Each execution thread Fm is associated with one or more matrix expressions determined from the set of matrix expressions E detected in the source code 121.
[0061] Within the same execution thread Fm, the associated matrix expressions E can be processed, for example, sequentially. Advantageously, it should be noted that execution threads Fm of an object code 221 can be executed according to parallel processing whereby several execution threads Fm are executed in parallel by the processor 260 of the execution computing device 20.
[0062] The object code initialization instructions 221 include, for each thread Fm, the pre-allocation of memory space reserved for matrices temporary spaces 241 (also called 'temporary space' or 'temporary memory space') in the storage unit 240. In other words, such pre-allocation corresponds to the instruction to pre-allocate a temporary space 241, for each thread of execution Fm, in the storage unit 240 of the execution computing device 20 when the initialization instructions are executed by the processor 260 of the system 20. Thus, for an object code 221 comprising M threads of execution associated with matrix expressions to be computed, the initialization instructions include the pre-allocation of M distinct temporary spaces 241 in the storage unit 240.
[0063] The processing instructions of object code 221 include, for each matrix expression E associated with an execution thread Fm, the execution of the N matrix operations On determined for this matrix expression E. In object code 221, the N matrix operations On are ordered according to an order relative to the rules of operational precedence.
[0064] The object code processing instructions 221 also include, for each execution (or evaluation, calculation) of a matrix operation On, the allocation of a temporary subspace 241-n (also called a 'temporary memory subspace') contained within the allocated temporary space 241, associated with the execution thread Fm. Such a temporary subspace 241-n constitutes the storage space for the intermediate result matrix Tn corresponding to the result of the execution of the matrix operation On under consideration.
[0065] In other words, for each matrix expression E associated with a thread Fm, the object code 221 can comprise a sequence of grouped instructions for each matrix operation On. Each group of instructions, denoted Gn, thus corresponds to one of the matrix operations On of a matrix expression E. Furthermore, in a thread Fm, the groups of instructions Gn associated with a given matrix expression E are ordered by the compiler in the generated object code according to the operator precedence rules.
[0066] A group of instructions Gn, relating to a matrix operation On, may include: - an instruction allocating a storage space of the intermediate matrix T n resulting from the evaluation of the matrix operation On, in a temporary memory subspace 241-n of the temporary memory space 241, - an instruction to evaluate the matrix operation On, and to store (i.e. supply) the result in the form of the intermediate result matrix Tn.
[0067] Thus, in an execution thread Fm, the evaluation of a matrix expression E can include the successive execution of the N groups of instructions Gn (the order of execution of the groups of instructions, from Gi to GN, having been determined by the compiler, according to the priority of operations).
[0068] In some embodiments, the temporary subspaces 241-n, related to the intermediate result matrices Tn, can be allocated in the temporary space 241 according to a dynamic "stack" allocation strategy. Such an allocation strategy can be based on a "last in, first out" (LIFO) approach to the dynamic matrices. A temporary space 241 thus forms a data structure in which the last element added is the first to be removed during deallocation.
[0069] In embodiments, the object code processing instructions 221 also include, for each matrix expression E associated with a thread Fm, the transfer (i.e. the copy or the move) of the last intermediate result matrix TN determined at the end of the execution of the N matrix operations On (i.e. the Nth intermediate result matrix TN stored in the temporary subspace 241-n associated with the matrix operation ON), to a result matrix R, temporary or persistent, corresponding to the result of the evaluation (i.e. the execution) of the matrix expression E under consideration, associated with the thread Fm.
[0070] Advantageously, during the execution of the object code 221 by the processor 260, the execution computing device 20 can be configured to perform a pre-allocation operation of a temporary space 241 in the storage unit 240, for each execution thread Fm of the object code 221. The execution computing device 20 can also be configured to perform, for each matrix expression E associated with an execution thread Fm, the successive execution of the N groups of instructions Gn. Each group of instructions Gn is associated with one of the N matrix operations On of the matrix expression E. For each group of instructions Gn (corresponding, for example, to an iteration), the execution computing device 20 can be configured to determine the intermediate result matrix Tn corresponding to the result of the execution of the matrix operation On under consideration (i.e., the matrix resulting from the calculation of the intermediate matrix operation).The N successive iterations associated with the same matrix expression E can be implemented according to the order of the ranking of the N matrix operations previously determined.
[0071] Advantageously, for a group of instructions Gn, the executing computer device 20 can be configured to allocate, to the intermediate result matrix Tn, a temporary subspace 241-n in the temporary space 241, and to evaluate (i.e., execute or compute) the matrix operation On, which provides a result stored in the intermediate result matrix Tn. The allocation operation corresponds to a "reservation" operation of a storage space (241-n) for the matrix of intermediate result Tn. The evaluation operation produces the result of the evaluation and allows saving the intermediate result matrix Tn in the allocated temporary subspace 241-n.
[0072] The computer execution device 20 can further be configured to return the Nth intermediate result matrix TN of the temporary subspace 241-n as a result of the execution of the considered matrix expression E.
[0073] Fig. 2 schematically illustrates the states of a temporary space 241 before or after (Fig. 2(a)), and during (Fig. 2(b)) the evaluation of a matrix expression of an execution thread Fm, by the computer execution device 20. In particular, Fig. 2(b) illustrates the states of a temporary memory space 241 following the application of successive iterations associated with the example of the matrix expression E represented in equation (01) comprising three matrix operations Ob O2 and O3 defined according to formulas (02), (03) and (04).
[0074] In some embodiments, the size of a pre-allocated temporary space 241, associated with an execution thread Fm, can be determined as a function of the maximum number N of intermediate matrices Tn to be evaluated (denoted Nmax) for the matrix expression(s) E associated with the execution thread Fm under consideration, and the size of the intermediate matrices Tn to be evaluated (denoted by Size(Tn)). In particular, the size of a pre-allocated temporary space 241 can be determined by the product of the numbers Nmax and Size(Tn). For example, the number Size(Tn) can correspond to the maximum size of the intermediate matrices Tn to be evaluated.
[0075] In some embodiments, the size of a temporary space 241 can be predefined. For example, and without limitations, the size of a temporary space 241 can be equal to a few kilobytes.
[0076] Advantageously, the size of a temporary subspace 241-n allocated during the execution of an nth iteration (i.e., instruction group Gn) associated with a matrix expression E corresponds to the size of the intermediate result matrix Tn for the matrix operation On under consideration. The intermediate result matrices Tn can be stored in the pre-allocated temporary space 241 associated with a thread Fm from a stack top pointer 241-i, as shown in [Fig. 2].
[0077] The use of a pre-allocated temporary space 241 associated with an execution thread Fm, using a dynamic allocation strategy of the "stack" type, makes it possible to generate a storage area in the 'Heap' in which the stored intermediate result matrices Tn are positioned in memory one after the other, contiguously, thus ensuring optimal co-locality of data storage in the storage unit 140. Such data co-locality guarantees a footprint Minimal memory allows the use of a single temporary space 241 per execution thread Fm of the program. This data co-locality also ensures optimal execution performance during the evaluation of a matrix expression E. This data structuring in the temporary space 241 ensures optimal use of the processor cache (or 'cache-friendly' according to the corresponding Anglo-Saxon expression), thus optimizing the execution times of the various operations of the computer execution device 20. This optimized execution performance can be illustrated with the matrix expression E represented in equation (01) generating a matrix operation O3 to be determined and defined according to the preceding expression (04), using the intermediate matrices Ti and T2 as matrix operands, and producing a result in the intermediate matrix T3, all three co-localized as shown in [Fig.2](b).
[0078] Such a temporary space 241, pre-allocated associated with an execution thread Fm, makes it possible to guarantee a storage area allowing the allocation of matrices of any size, in a bounded allocation time of the intermediate result matrices Tn, the temporary subspaces 241-n being positioned at each iteration at the level of the stack top pointer 241-i.
[0079] In embodiments, the instructions for processing the object code 221 generated by the computer compilation device 10 may include, for each matrix expression E associated with an execution thread Fm, the successive deallocation of the set of temporary subspaces 241-n of the considered allocated temporary space 241, in response to the determination of the result matrix R, obtained at the end of the evaluation of the matrix expression E.
[0080] Thus, during the execution of the object code 221 by the processor 260, the computer execution device 20 can be configured to perform, for each matrix expression E associated with an execution thread Fm, after the implementation of the N iterations (i.e., instruction groups Gi to GN), an operation of deallocation of the N temporary subspaces 241-n of the temporary space 241. Such a deallocation operation corresponds to a consequence of the destruction of the set of intermediate result matrices Tn evaluated for the matrix expression E. Such destructions take place implicitly and in the reverse order of construction, by operating principle of the language, the destructions entailing the deallocation of the temporary subspaces 241-n.The operation of deallocation of the N temporary subspaces 241-n is therefore performed in the reverse order of the allocations of the temporary subspaces 241-n (thus respecting the order of construction of the temporary matrices Tn instantiated during the N iterations). Thus, for each expression . matrix E processed associated with an execution thread Fm, the allocated temporary space 241 considered is empty (i.e. free) at the end of the processing.
[0081] Advantageously, the use of the temporary space 241 with a dynamic allocation strategy of the "stack" type makes it possible to guarantee a bounded deallocation time of each temporary subspace 241-n, the latter corresponding to the displacement of the stack top pointer 241-i of the allocated temporary subspaces.
[0082] In embodiments, the termination instructions of the object code 221 generated by the compilation computer device 10 may include, for each execution thread Fm, the deallocation of the temporary space 241 in the storage unit 240. In this case, when the object code 221 is executed by the processor 260, the execution computer device 20 may be configured to perform a deallocation operation of the temporary space(s) 241 in the storage unit 240.
[0083] In some embodiments, the initialization instructions of the object code 221 may include a pre-allocation of one or more spaces reserved for persistent matrices 243 (also called 'persistent spaces' or 'persistent memory spaces') in the storage unit 240. In this case, when the object code 221 is executed by the processor 260, the execution computing device 20 may be configured to perform a pre-allocation operation of one or more persistent memory spaces 243 in the storage unit 140, as shown in [Fig. 1]. In particular, a pre-allocated persistent memory space 144 may correspond to a given memory segment, in which the allocation of persistent matrices may be carried out according to a dynamic allocation strategy of the 'pool' type.
[0084] The execution computer device 20 can further be configured to perform a storage operation of some or all of the input matrices of the matrix expression(s) to be processed, in the persistent memory space(s) 243. The dimensions and number of persistent memory spaces 243 to be pre-allocated can, for example, be predetermined according to the sizes and number of input matrices of the matrix expression(s) to be processed. A persistent memory space 243 can also be pre-allocated and adapted to contain the result matrix R corresponding to the result of the evaluation of a matrix expression E.
[0085] The use of such persistent memory spaces 243 can make it possible to instantiate a persistent matrix both in the real-time context of a specific application and outside of such a context, when the allocation strategy guarantees a bounded-time allocation, as in the case of a dynamic allocation strategy of the "pool" type.
[0086] Advantageously, the object code processing instructions 221 can include, for each matrix expression E associated with a thread of execution F m, the assignment of the Nth intermediate result matrix TN of the temporary subspace 241-n to a matrix corresponding to the result matrix R (providing the result of the evaluation of the matrix expression E), the latter being able to be allocated in the storage unit 240. In this case, during the execution of the object code 221 by the processor 260, the execution computing device 20 can further be configured to perform an assignment operation consisting of assigning the Nth intermediate result matrix TN of the temporary space 241 associated with the execution thread Fm to the matrix R of this subspace of the storage unit 240. Such a subspace can be included directly in the "Heap", the "Stack" or the static data area of the storage unit 240, or alternatively in a pre-allocated persistent memory space 243 in this same storage unit.Such a memory subspace can be allocated prior to the implementation of the iterations associated with one or more matrix expressions E of an execution thread Fm, for example.
[0087] Such an assignment operation can be included in the object code processing instructions 221 during the compilation of the source code 121, and determined during the parsing of the matrix expression E, in response to the detection of the operation symbol “=", as illustrated by equation (01). The symbol “=" represents the operator associated with this matrix assignment operation. Thus, the assignment operation can correspond to a copy of a temporary matrix to a persistent matrix.
[0088] Fig. 3 illustrates an example of a possible implementation of lines of code written in the C++ computer language as a class model in the computer library 123 used by the computer device 10 to compile the source code 121. This example of implementation corresponds to predefined processing instructions including declarations and property definitions, used by the compiler 125 to compile the source code 121 into object code 221.
[0089] In particular, [Fig. 3](a) illustrates an example of a template class definition for the various data used during the execution of object code 221. In this [Fig. 3], the template parameters 'S', P, and 'T' represent, respectively, a scalar data type, a class implementing an allocator for persistent matrices, and a class implementing an allocator for temporary matrices. In [Fig. 3](a), the possible implementation of an allocator for persistent matrices corresponds to the 'HcapAlloc' class (i.e., implementing the allocation and deallocation functions, for example, in the 'Heap' of storage unit 240), and the possible implementation of an allocator for temporary matrices corresponds to the 'StackAlloc' class (i.e., implementing the allocation and deallocation functions, for example, in the 'Heap' of storage unit 240). implementing the allocation and deallocation functions in the memory space reserved for temporary matrices 241).
[0090] Figure 3(b) illustrates an example of an implementation of a matrix operation using the operation symbol "*" corresponding to the matrix composition (or product, or multiplication) arithmetic operator, taking as parameters two operands of type persistent matrix and / or temporary matrix, and returning a result of type temporary matrix. Any other matrix operation using another arithmetic operator or a function, in any complex matrix expression E, can be implemented similarly to the example implementation shown in Figure 3(b). Advantageously, the 123 computer library can include all the lines of code necessary to declare and define the properties relating to any other matrix operation associated with an operation symbol, taking as parameters one or more operands of type persistent matrix, temporary matrix, or scalar, and returning a temporary matrix.It should be noted that, in [Fig.3](b), the instantiation of the temporary matrix, resulting from the evaluation of the matrix operation using the operator symbol "*", is ensured via the allocator for temporary matrices according to the use of the template parameter 'T'.
[0091] Fig. 3(c) illustrates an example of an implementation of an assignment operation ensuring the copying or moving (or more generally the transfer) of the contents of a source matrix of any type (i.e. persistent or temporary) to a destination matrix of any type (i.e. persistent or temporary).
[0092] In certain embodiments, the computer library 123 can be adapted so that, during the syntactic analysis of a matrix expression E of the source code 121, the computer compilation device 10 is further configured to identify typical mathematical expressions, so as to generate an optimized matrix expression prior to determining the N matrix operations On. For example, and without limitation, a mathematical expression of the type to be identified can be defined according to equation (05):
[0093] F += u * C * D (05)
[0094] In equation (05), the terms C, D, F are symbols representing matrices, the term u is a symbol representing a scalar, and the term "+=" represents the addition-assignment operator.
[0095] Figures 4 and 5 represent the method for the real-time evaluation (or calculation) of matrix code expressions, (or method for processing matrix expressions), implemented by system 1, according to embodiments of the invention.
[0096] The process includes a PI phase of compiling the source code 121 implemented by the computer compilation device 10 (i.e. the compilation tool).
[0097] Advantageously, the PI compilation phase (or compilation process) may include a step of receiving the source code 121 comprising one or more matrix expressions E, and identifying these matrix expressions by analyzing the source code 121.
[0098] The PI compilation phase further includes, for each matrix expression E identified in the source code 121, a step 420 consisting of applying a syntactic analysis to determine N elementary matrix operations On, which can be classified according to the rules of operational precedence.
[0099] The PI compilation phase further includes a step 440 consisting of generating the executable object code 221, by the computer execution device 20 (i.e. the means of code execution), from the determined elementary matrix operations On and the processing instructions, predefined in particular in the computer library 123.
[0100] Advantageously, the PI compilation phase may include a step of delivering the object code 221 to an object code execution device capable of executing the object code 221, and comprising a storage unit 240 capable of including at least one temporary memory space 241, each temporary memory space 241 being capable of including temporary memory subspaces 241-n.
[0101] The method may further include a phase P2 of execution of the object code 221 implemented by the computer execution device 20. The execution phase P2 includes, for each execution thread Fm relating to the object code 221, a step 406 of pre-allocation of a temporary memory space 241 in the storage unit 140, implemented so that the allocations which will take place in this temporary space are implemented according to a dynamic allocation strategy of the “stack” type.
[0102] The execution phase P2 may further include, for each elementary matrix operation On, determined for a matrix expression E associated with the execution thread Fm, a step 542 consisting of allocating a temporary subspace 241-n, in the associated temporary memory space 241, to the intermediate result matrix Tn, resulting from the execution (i.e. evaluation or calculation) of the matrix operation On, and a step 544 consisting of evaluating the matrix operation On and thus determining the intermediate result matrix Tn.
[0103] The last (i.e. N-th) intermediate result matrix TN, obtained at the end of the N matrix operations On, is transferred (a transfer can correspond for example to a copy or a move) into the result matrix R providing the result of the evaluation of the matrix expression E. The result matrix R can be used by the computer execution device 20 (which can be for example and without limitation a robotic system).
[0104] The execution phase P2 may further include a step 562 consisting of assigning the Nth intermediate result matrix TN of the temporary subspace 241-N to a result matrix R, such a result matrix R being allocated in the storage unit 240 (for example, in the "Heap" memory segment of the storage unit 240, or a persistent space 243 of type "pool").
[0105] The execution phase P2 can also include, for each matrix expression E associated with the execution thread Fm, a step 564 consisting of deallocating the set of temporary subspaces 241-n allocated, associated with the evaluation of the N elementary matrix operations On determined for the matrix expression E.
[0106] The execution phase P2 may further include, for each execution thread Fm, a step 580 consisting of deallocating the associated temporary memory space 241 after the evaluation of the matrix expression(s) E associated with the execution thread Fm.
[0107] A person skilled in the art will readily understand that certain steps of the process in [Fig.4] can be carried out simultaneously, sequentially, independently or not, and / or in a different order, for example in an order defined by the computer execution device.
[0108] It should be noted that certain features of the invention may have advantages when considered separately.
[0109] Those skilled in the art will understand that the invention can be implemented as a computer program comprising instructions for its execution. The computer program can be stored on a processor-readable storage medium. The reference to a computer program that, when executed, performs any of the functions described above, is not limited to an application program running on a single host computer. Rather, the terms computer program and software are used herein in a general sense to refer to any type of computer code (for example, application software, firmware, microcode, or any other form of computer instruction) that can be used to program one or more processors to implement aspects of the techniques described herein.Computing resources can be distributed ("cloud computing"), possibly using peer-to-peer technologies. The software code can be executed on any suitable processor (e.g., a microprocessor) or processor core, or a set of processors, whether located in a single computing device or distributed across multiple computing devices (e.g., as potentially accessible within the device's environment). The executable code for each program enabling the programmable device to implement the processes according to the invention can be stored, for example, on the hard drive or in memory. dead. Generally, the program(s) can be loaded into one of the device's storage means before being executed. A central processing unit can command and direct the execution of the instructions or portions of software code of the program(s) according to the invention, instructions which are stored in the hard drive or in read-only memory or in the other aforementioned storage elements.
[0110] The invention is not limited to the embodiments described above by way of non-limiting example. It encompasses all possible embodiments that can be envisioned by a person skilled in the art. In particular, a person skilled in the art will understand that the invention is not limited to the various computer units of the device described by way of non-limiting example. In particular, certain embodiments of the invention can be combined.
Claims
1. Demands A compilation method (PI) for converting source code (121) into object code (221), implemented in a compilation tool, the compilation method comprising the steps of: - receive a source code (121) comprising at least one matrix expression (E), - determine, for each matrix expression (E) of said source code (121), N matrix operations (On), N being an integer greater than or equal to 1, from a syntactic analysis of said matrix expression (E), said matrix operations (On) being ordered according to an order relative to operational priority rules, - to compile said source code (121) and generate object code (221) from said matrix operations (On) determined from said at least one matrix expression (E), said object code (221) comprising machine instructions executable by at least one processor, said object code (221) comprising at least one thread (Fm) associated with one or more matrix expressions (E) from said at least one matrix expression, and - deliver said object code (221) to an object code execution device capable of executing the object code (221), and comprising a storage unit (240), the storage unit (240) being capable of comprising at least one temporary memory space (241), each temporary memory space (241) being capable of comprising temporary memory subspaces (241-n); the object code instructions including, for each thread of execution (Fm): - instructions for pre-allocation (520) of a temporary memory space (241) in said storage unit (240) of the execution device, and - for each matrix expression (E) associated with said execution thread (Fm), instructions for the successive execution of N groups of instructions (Gn) according to said order, each
2. group of instructions (Gn) being associated with one of said N matrix operations (On) and comprising: • an instruction to allocate an intermediate result matrix (Tn) corresponding to the result of the evaluation of said matrix operation (On), in a temporary memory subspace (241-n) of said temporary memory space (241), and • an instruction for evaluating said matrix operation (On) and storing said corresponding intermediate result matrix (Tn), said temporary memory subspaces (241-n), associated with said intermediate result matrices (Tn) provided, being allocated according to a dynamic "stack" type allocation strategy in said pre-allocated temporary memory space (241), - an instruction to deliver the Nth intermediate result matrix (TN) as a result of the execution of said at least one matrix expression (E) associated with the thread of execution. A computer method comprising a compilation phase (PI) of source code (121) into object code (221) and an execution phase (P2) of said object code (221), the method being implemented in a computer system comprising a compilation tool and code execution means, the code execution means comprising a storage unit (240), the method comprising, in said compilation phase (PI), the steps of: - receive a source code (121) comprising at least one matrix expression (E), - determine, from a syntactic analysis of said at least one matrix expression (E), N matrix operations (On), N being an integer greater than or equal to 1, said matrix operations (On) being ordered according to an order relative to operational precedence rules, and - compile said source code (121) and generate an object code (221) from said N matrix operations (On),
3.
4. comprising machine instructions executable by at least one processor, said object code (221) comprising at least one thread of execution (Fm) associated with one or more matrix expressions (E) among said at least one matrix expression, the process comprising, in said execution phase (P2) of said object code (221), for each execution thread (Fm), the steps consisting of: - pre-allocate (520) a temporary memory space (241) in said storage unit (240) of the execution device, and - for each matrix expression (E) associated with said execution thread (Fm), successively execute the N matrix operations (On) determined for the matrix expression (E), in said order, the execution of one of said matrix operations (On) comprising the steps consisting of: • allocate an intermediate result matrix (Tn) corresponding to the result of the evaluation of said matrix operation (On), in a temporary memory subspace (241-n) of said temporary memory space (241), and • evaluate said matrix operation (On), and store said intermediate result matrix (Tn) in said temporary memory subspace (241-n), said temporary memory subspaces (241-n), associated with said intermediate result matrices (Tn) provided, being allocated according to a dynamic "stack" type allocation strategy in said pre-allocated temporary memory space (241), - deliver the Nth intermediate result matrix (TN) as a result of the execution of said at least one matrix expression (E) associated with the execution thread. Method, according to claim 2, wherein, for each thread of execution (Fm), said temporary memory space (241) is pre-allocated (520) in a memory segment "Heap", said storage unit (240) corresponding to the default dynamic memory allocator. A method, according to any one of claims 2 to 3, wherein the method comprises, in said execution phase (P2), a step consisting to pre-allocate at least one persistent memory space (243) in said storage unit (240), and for each thread (Fm), a step consisting of assigning (562), for each matrix expression (E) associated with said thread (Fm), said Nth intermediate result matrix (TN) of the Nth temporary memory subspace (241-N) to a matrix of said persistent memory space (243).
5. A method, according to any one of claims 2 to 4, wherein the method comprises, in said execution phase (P2), for each execution thread (Fm), a step consisting of deallocating (564), for each matrix expression (E) associated with said execution thread (Fm), said N temporary memory subspaces (241-n) of said temporary memory space (241) associated with said execution thread (Fm).
6. A method, according to any one of claims 2 to 5, wherein the method comprises, in said execution phase (P2), for each execution thread (Fm), a step consisting of deallocating (580) said temporary memory space (241) of said storage unit (240).
7. A method, according to any one of claims 2 to 6, wherein the size of said pre-allocated temporary memory space (241) for each thread of execution (Fm) is determined as a function of the number N of intermediate result matrices (Tn) provided and the size of said intermediate result matrices (Tn) associated with a matrix expression (E) of said thread of execution (Fm).
8. Compilation tool configured to implement the compilation process (PI) according to claim 1.
9. Compilation tool, according to claim 8, wherein the tool comprises a computer library (123) and a compiler (125), said source code (121) being compiled by the compiler (125) from a set of predefined processing instructions in said computer library (123).
10. Computer system configured to implement the compilation process (PI) according to any one of claims 2 to 9.
11. System, according to claim 10, wherein the code execution means are subject to real-time constraints.