Method and computer system for real-time evaluation of matrix expressions of a code

The method addresses the challenge of ensuring bounded execution time in real-time systems by compiling source code into object code with explicit memory allocation and deallocation strategies, resulting in improved performance and compliance with time constraints.

FR3157613A1Active Publication Date: 2025-06-27COMMISSARIAT A LENERGIE ATOMIQUE ET AUX ENERGIES ALTERNATIVES
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
FR2023015076
Authority / Receiving Office
FR · FR
Patent Type
Applications
Current Assignee / Owner
Filing Date
2023-12-22
Publication Date
2025-06-27
Estimated Expiration
2043-12-22

AI Technical Summary

Technical Problem

Real-time systems that require the evaluation of matrix expressions face challenges in ensuring bounded execution time due to automatic and implicit dynamic memory allocation, which can lead to compliance issues with time constraints.

Method used

A method and system for compiling source code into object code that involves determining matrix operations from syntactic analysis, generating object code with instructions for pre-allocating temporary memory, and executing matrix operations with explicit allocation and deallocation of temporary memory subspaces.

Benefits of technology

This approach ensures bounded execution time by avoiding automatic dynamic memory allocation, reducing memory footprint, and improving computational performance, while also simplifying the writing and maintenance of complex matrix expressions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

A compilation method is proposed comprising the steps of: determining, for each matrix expression (E) of a source code, N ordered matrix operations (On), generating, from the matrix operations, an object code, delivering the object code to an execution device comprising a storage unit (240) capable of comprising at least one temporary memory space (241), each comprising temporary sub-spaces (241-n). The instructions of the object code comprise, for each thread of execution of the object code: the pre-allocation of a temporary space, for each expression of the thread of execution, the execution of N groups of instructions, each associated with one of the matrix operations and comprising: the allocation of a matrix (Tn) corresponding to the result of the evaluation of the operation, in a temporary sub-space, the evaluation of the operation and the storage of the matrix, the Nth matrix (TN) being the result of the execution of the expression of the thread.Figure for the abstract: [Fig.4].
Need to check novelty before this filing date? Find Prior Art

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 system for the real-time evaluation of matrix code expressions.

[0002] Systems under time constraints (called "real-time systems") operate under the control of one or more computer programs, and take into account execution time constraints to be respected. In particular, real-time systems use a computer device to execute an object code, comprising instructions to be executed, which governs the operation of the system under time constraints.

[0003] For some real-time systems, such as for example robotic control-command systems, the object code to be executed is derived from the compilation of a source code comprising one or more matrix expressions to be evaluated (i.e. to be calculated). In the case of such real-time systems, compliance with the time constraints of execution of the system is as important as the conformity of the results of the evaluation of the matrix expressions of the source code.

[0004] Computer devices for executing software code requiring the evaluation of dynamic matrix expressions generally use automatic and implicit instantiation of dynamic matrices to store the results of intermediate calculations of these matrix expressions. In particular, the implemented automatic instantiation induces dynamic memory allocation and deallocation operations. Such operations, when performed via the default allocator of the language, 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 time constraints essential to the proper functioning of such systems.

[0006] To enable the processing of a matrix expression according to a bounded execution time, a commonly used method consists of using a decomposition of complex matrix expressions into simple, unary or binary sub-expressions for the arithmetic operators, as well as an explicit pre-instantiation, outside of real-time context, of the dynamic matrices intended for the storage of the inter results mediators of decomposed subexpressions. However, such decomposition places a heavy burden on the programmer, making writing complex matrix expressions tedious, difficult to read, and prone to implementation errors. This also requires the definition of numerous intermediate matrices, thus increasing the memory footprint of the computer program at runtime.

[0007] There is thus 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] For this purpose, a method is proposed for compiling a source code into an object code, implemented in a compilation tool. The compilation method comprises the steps of: - receive a source code including at least one matrix expression, - determine, for each matrix expression of 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 an order relative to operational priority rules, - generating an object code from the matrix operations determined from the 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 among the at least one matrix expression, and - delivering 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 comprising at least one temporary memory space, each temporary memory space being capable of comprising temporary memory sub-spaces.

[0009] The instructions of the object code include, for each thread of execution: - instructions for pre-allocating temporary memory space in the storage unit of the execution device, and - for each matrix expression associated with the execution thread, instructions for 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 for allocating an intermediate result matrix corresponding to the result of the evaluation of the matrix operation, in a temporary memory subspace of the temporary memory space, and - an instruction for evaluating the matrix operation and storing the matrix of corresponding intermediate result, - an instruction to deliver the Nth intermediate result matrix as a result of the execution of the 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 a source code into an 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 a 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 priority rules, and - generating an object code from the 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 among the 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 storage unit of the execution device, and - for each matrix expression associated with the execution thread, successively executing the N matrix operations determined for the matrix expression, according to the order relative to operational priority rules, the execution of one of the matrix operations comprising the steps consisting of: - allocate an intermediate result matrix corresponding to the result of the evaluation of the matrix operation, 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, - output the Nth intermediate result matrix as a result of executing the at least one matrix expression associated with the thread of execution.

[0013] In embodiments, for each matrix expression associated with the thread of execution, the temporary memory subspaces, associated with the provided intermediate result matrices, may be allocated according to a dynamic allocation strategy of the "stack" type in the at least one temporary memory space pre-allocated in the unit storage and associated with the execution thread.

[0014] Advantageously, for each thread of execution, the 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 comprise, 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 comprise, in the execution phase, for each thread of execution, a step consisting of deallocating, for each matrix expression associated with the thread of execution, the N temporary memory subspaces of the temporary memory space associated with the thread of execution.

[0017] Advantageously, the method may comprise, 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 may be determined based on the number N of intermediate result matrices provided and the size of the intermediate result matrices associated with a matrix expression of the thread.

[0019] Also provided is a compilation tool configured to implement the compilation method.

[0020] In embodiments, the tool may comprise a computer library and a compiler, the source code being compiled by the compiler from a set of processing instructions predefined in the computer library.

[0021] Embodiments of the invention thus provide a computer system configured to implement the compilation method.

[0022] Advantageously, the code execution means 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 the computational performance and guaranteeing a bounded execution time.

[0024] They make it possible in particular to ensure the absence of automatic and implicit dynamic allocation of dynamic matrices by means of the default allocator of the language (i.e. in the Heap) to store the results of intermediate calculations of matrix expressions, and to guarantee a minimal memory footprint and performance optimal execution due to preserved co-locality of data via a specific allocation strategy. This results in a solution compatible with computing devices (or computer systems) subject to time constraints.

[0025] They also make it possible to ensure the use of a writing of so-called literal matrix expressions, in a conventional format (i.e. in a format conforming to the mathematical writing of the expression), readable and easy to maintain, whatever their complexity, without requiring the definition of intermediate matrices. The programmer's effort is greatly reduced, the associated computer code gains in readability, maintainability and is less subject to implementation error. Description of the figures

[0026] Other characteristics, details and advantages of the invention will emerge on reading the description given with reference to the appended drawings given by way of example.

[0027] [Fig-1] [Fig.l] is a diagram showing a system comprising a device compilation computer and an execution computer device, according to embodiments of the invention.

[0028] [Fig.2] [Fig.2] shows two diagrams (a) and (b) representing the states of a space so-called temporary memory respectively before and during the evaluation of a matrix expression by an executing computer device, according to embodiments of the invention.

[0029] [Fig.3] [Fig.3] is an example of the implementation of lines of code of a library computing computing used by a compiling computing device, according to embodiments of the invention.

[0030] [Fig.4] [Fig.4] is a flowchart representing a treatment method of matrix expressions, by a compilation computer device, according to embodiments of the invention.

[0031] [Fig.5] [Fig.5] is a flowchart representing a method of processing a code object resulting from the compilation of matrix expressions, by an executing computer device, according to embodiments of the invention.

[0032] Identical references are used in the figures to designate identical or similar elements. For reasons of clarity, the elements shown are not to scale. Detailed description

[0033] [Fig.l] schematically represents a system 1 comprising a compilation computing device 10 and an execution computing device 20, according to embodiments of the invention.

[0034] The compilation computing 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 executing computing device 20.

[0035] The execution computing 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-command device (or 'process control' according to the English expression). For example and without limitation, such a computing device can be a robotic control-command device, an aircraft navigation control-command device, a control-command device for a complex cyber-physical device, a device for digital simulation of complex devices, or even a signal processing device (in particular image processing).

[0036] As shown in [Fig. 1], the executing computing device 20 may be different from the compiling computing device 10. Alternatively, the compiling device 10 and the executing device 20 may be one and the same computing device.

[0037] The compilation computer device 10 (also called 'compilation tool' or 'source code compilation device') comprises a processor 160, the source code 121 to be compiled and a computer library 123. The computer device 10 further comprises a compilation computer program, also called compiler 125, intended to be loaded into a random access memory 141 of the compilation computer 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 and without limitation, the C++ language. The source code 121 comprises one or more matrix expressions E to be processed (i.e., to be evaluated, to be calculated). The computer library 123 comprises predefined processing instructions comprising definitions and declarations of properties in the form of source code. The computer library may also comprise executable machine code. The lines of source code 121 are intended to be compiled into an 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 embodiments, the source code 121, the computer library 123 and the compiler 125 may be included in the mass memory (not shown in the figures) of the computing device 10.

[0040] As used herein, the term "matrix expression" refers to a literal matrix algebraic expression of any form, composed of a finite combination of symbols and respecting the precedence rules 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 arithmetic operators of matrix composition (or multiplication, or product) and addition (or sum).

[0045] It should be noted that a matrix expression E is composed of N elementary matrix operations (also called 'elementary expressions'), noted 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 the source code 121 can be characterized by a number N of ordered matrix operations distinct and / or specific to the matrix expression E. The result of the execution (or evaluation) of a matrix operation O n of the matrix expression E produces an intermediate result matrix, noted Tn.

[0046] Each matrix operation On of a matrix expression E comprises a single operation symbol. A matrix operation may 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 may 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 the terms 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 classified according to an order defined from priority rules (corresponding to the priority rules of the operations and, in particular, of the arithmetic operators, i.e. the rules of order of processing of the operation symbols). In certain embodiments, a binary matrix operation can comprise a matrix operand and a scalar operand.

[0048] In the example represented in equation (01), the matrix expression E illustrated comprises three matrix operations Oi, O2 and O3 defined according to the following expressions (02), (03) and (04):

[0049] Oi: { U = A * X} (02)

[0050] O2: { T2 = B * Y} (03)

[0051] O3: {T3 = T1 + T2}(04)

[0052] The intermediate matrices (resulting from the evaluation of the intermediate matrix operations) are dynamic matrices. As used herein, the term "dynamic matrix" refers to a matrix of dimension unknown at the compilation of the source code 121. The input matrices of the matrix expression E and / or the result matrix R (resulting from the evaluation of E) may also be dynamic matrices.

[0053] The input matrices of the matrix expression E may be referred to as "persistent matrices". Advantageously, the intermediate result matrices Tn associated with the matrix operations On may be referred to as "temporary matrices". As used herein, the expression "temporary matrix" refers to a matrix created in a specific memory space of a computing device during the execution of software code, then deleted during or at the end of the execution time. Any matrix that is not a temporary matrix is ​​a persistent matrix. Thus, the expression "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 executing computing device 20 (also called 'code execution means', 'code execution device') may comprise a storage unit 240, as well as a processor 260 for executing the object code 221 generated by the compiling computing device 10, as shown in [Fig.l].

[0055] In embodiments, the storage unit 240 of the executing computing device 20 (also referred to as a 'backup unit' or 'storage module') may be the data segment.

[0056] As used herein, the term "data segment" may refer to a segment of RAM dedicated to the data of the object code execution method. The term "data segment" may therefore refer to a memory region that may include: the memory space used by the default dynamic memory allocator of the language, i.e. the "Heap" (or "stack memory" according to the corresponding English expression), the "Stack" (or "stack memory", according to the corresponding English expression), and / or the memory space reserved for so-called static data.

[0057] The object code 221 comprises instructions which, when executed by the processor 260, control the executing computing device 20, so that the latter performs the processing of the matrix expressions from the source code 121. In other words, the object code 221 comprises machine instructions executable by at least one processor. In particular, the object code 221 may comprise initialization instructions, processing instructions and ter instructions. mining. The computing device 20 for executing the object code 221 can thus be configured to process some or all of the matrix expressions E included in the source code 121.

[0058] Considering an execution computing 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 comprise for example up to 7 combined unary and / or binary elementary expressions, for linear Kalman filtering.

[0059] To compile the source code 121 and generate the object code 221, the compilation computer 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 matrix expression E detected (or found), the N associated matrix operations On, from a syntactic analysis of the matrix expression E considered. Advantageously, such a syntactic analysis of the matrix operations can be carried out from the computer library 123 and the rules of the computer language.

[0060] The object code 221 generated by the compilation computer device 10 comprises a set of at least M execution threads (or 'execution threacT in English), denoted F m, 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 among the set of matrix expressions E detected in the source code 121.

[0061] In 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 a parallel processing according to which several execution threads Fm are executed in parallel by the processor 260 of the execution computing device 20.

[0062] The initialization instructions of the object code 221 comprise, for each thread of execution Fm, the pre-allocation of a memory space reserved for the temporary matrices 241 (also called 'temporary space' or 'temporary memory space') in the storage unit 240. In other words, such a pre-allocation corresponds to the instruction of pre-allocation of a temporary space 241, for each thread of execution Fm, in the storage unit 240 of the executing computer 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 calculated, the initialization instructions comprise the pre-allocation of M distinct temporary spaces 241 in the storage unit 240.

[0063] The processing instructions of the object code 221 include, for each ex matrix pressure E associated with a thread of execution Fm, the execution of the N matrix operations On determined for this matrix expression E. In the object code 221, the N matrix operations On are ordered according to an order relative to the operational precedence rules.

[0064] The processing instructions of the object code 221 also comprise, for each execution (or evaluation, calculation) of a matrix operation On, the allocation of a temporary subspace 241-n (also called 'temporary memory subspace') included in the allocated temporary space 241, associated with the execution thread Fm. Such a temporary subspace 241-n constitutes the storage space of the intermediate result matrix Tn corresponding to the result of the execution of the matrix operation On considered.

[0065] In other words, for each matrix expression E associated with an execution thread Fm, the object code 221 may comprise a sequence of instructions grouped 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 an execution thread Fm, the groups of instructions Gn associated with a matrix expression E considered are ordered by the compiler in the object code generated according to the rules of priority of the operators.

[0066] A group of instructions Gn, relating to a matrix operation On, can comprise: - an instruction for allocating a storage space of the intermediate matrix Tn resulting from the evaluation of the matrix operation On, in a temporary memory subspace 241-n of the temporary memory space 241, - an instruction for evaluating the matrix operation On, and storing (i.e. providing) 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 comprise 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 the operations).

[0068] In embodiments, the temporary subspaces 241-n, relating to the intermediate result matrices Tn, can be allocated in the temporary space 241 according to a dynamic allocation strategy of the “stack” type. Such an allocation strategy can be based on a “last in, first out” (LIFO) processing of the dynamic matrices. A temporary space 241 therefore forms a data structure whose last added element is the first to leave it during deallocation.

[0069] In embodiments, the processing instructions of the object code 221 also comprise, for each matrix expression E associated with a thread of execution Fm, the transfer (i.e. the copy or the movement) of the last result matrix inter median 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), towards a result matrix R, temporary or persistent, corresponding to the result of the evaluation (i.e. of the execution) of the matrix expression E considered, associated with the execution 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 thread of execution Fm of the object code 221. The execution computing device 20 can be configured to further perform, for each matrix expression E associated with a thread of execution 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 considered (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 classification of the N matrix operations previously determined.

[0071] Advantageously, for a group of instructions Gn, the executing computing device 20 can be configured to allocate, to the intermediate result matrix T n> a temporary subspace 241-n in the temporary space 241, and to evaluate (i.e. execute or calculate) the matrix operation On, which provides a result stored in the intermediate result matrix Tn. The allocation operation corresponds to an operation of “reserving” a storage space (241-n) for the intermediate result matrix Tn. The evaluation operation produces the result of the evaluation and makes it possible to save the intermediate result matrix Tn in the allocated temporary subspace 241-n.

[0072] The executing computing device 20 may 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 matrix expression E considered.

[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 execution computing 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 Oi, O2 and O3 defined according to formulas (02), (03) and (04).

[0074] In 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 or each of the matrix expressions E associated with the execution thread Fm considered 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 embodiments, the size of a temporary space 241 may be predefined. For example and without limitation, the size of a temporary space 241 may 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. group of instructions Gn) associated with a matrix expression E, corresponds to the size of the intermediate result matrix Tn for the matrix operation On considered. The intermediate result matrices Tn can be stored in the pre-allocated temporary space 241 associated with an execution 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 T n are positioned in memory one after the other, contiguously, thus ensuring optimal co-locality of data storage in the storage unit 140. Such co-locality of the data guarantees a minimal memory footprint, allowing the use of a single temporary space 241 per execution thread Fm of the program. This co-locality of the data also makes it possible to ensure optimal execution performance during the evaluation of a matrix expression E.This structuring of the data in the temporary space 241 in fact ensures optimal use of the processor cache (or 'cache-friendly' according to the corresponding English expression), the execution times of the different operations of the execution computing device 20 then being optimal. 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 as matrix operands the intermediate matrices Ti and T2, and producing a result in the intermediate matrix T3, all three co-located as represented in [Fig.2](b).

[0078] Such a temporary space 241, pre-allocated associated with an execution thread Fm, also makes it possible to guarantee a storage area authorizing the allocation of matrices of size any, in a bounded allocation time of the intermediate result matrices T n, the temporary subspaces 241-n being positioned at each iteration at the level of the stack top pointer 241-i.

[0079] In embodiments, the processing instructions of the object code 221 generated by the compilation computing device 10 may comprise, for each matrix expression E associated with an execution thread Fm, the successive deallocation of all the temporary subspaces 241-n of the allocated temporary space 241 considered, 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 execution computing 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), a deallocation operation 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 leading to the deallocation of the temporary subspaces 241-n.The operation of deallocation of the N temporary subspaces 241-n is therefore carried out 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 matrix expression E processed associated with an execution thread Fm, the temporary space 241 allocated 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 limited deallocation time for each temporary subspace 241-n, this corresponding to the movement 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 computing device 10 may comprise, for each thread of execution Fm, the deallocation of the temporary space 241 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 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 'memory spaces persistent') in the storage unit 240. In this case, during the execution of the object code 221 by the processor 260, the executing computing device 20 can 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.l]. In particular, a pre-allocated persistent memory space 144 can correspond to a given memory segment, in which the allocation of the persistent matrices can be carried out according to a dynamic allocation strategy of the "pool" type.

[0084] The execution computing device 20 may further be configured to perform an operation of storing 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 may for example be predetermined as a function of the sizes and number of input matrices of the matrix expression(s) to be processed. A persistent memory space 243 may 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 processing instructions of the object code 221 may comprise, for each matrix expression E associated with an execution thread Fm, 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 may further be configured to carry out 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 persistent memory space 243 pre-allocated 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 (or assignment) operation may be included in the processing instructions of the object code 221 when compiling 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 from a temporary matrix to a persistent matrix.

[0088] [Fig. 3] illustrates an example of possible implementation of lines of code written, in the C++ computer language in the form of 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 comprising declarations and definitions of properties, used by the compiler 125 to compile the source code 121 into an object code 221.

[0089] In particular, [Fig.3](a) illustrates an example of a template class definition of the various data used during the execution of the 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 class 'HeapAlloc' (i.e. implementing the allocation and deallocation functions, for example, in the "Heap" of the storage unit 240), and the possible implementation of an allocator for temporary matrices corresponds to the class 'StackAlloc' (i.e. implementing the allocation and deallocation functions in the memory space reserved for temporary matrices 241).

[0090] [Fig.3](b) illustrates an example of implementation of a matrix operation using the operation symbol “*” corresponding to the arithmetic operator of matrix composition (or product, or multiplication), taking as parameters two operands of persistent matrix type and / or temporary matrix, and returning a result of temporary matrix type. Any other matrix operation using another arithmetic operator or even a function, in any complex matrix expression E, can be implemented in a manner similar to the example of implementation represented in [Fig.3](b). Advantageously, the computer library 123 can comprise all the lines of code making it possible 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 persistent matrix type, temporary matrix, or scalar, and returning a temporary matrix.It is 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 implementation of an assignment operation ensuring the copying or moving (or more generally the transfer) of the content 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 compilation computer device 10 is further configured to identify typical mathematical expressions, so as to generate an optimized matrix expression, prior to the determination of 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 the system 1, according to embodiments of the invention.

[0096] The method comprises a phase PI of compiling the source code 121 implemented by the compilation computer device 10 (i.e. the compilation tool).

[0097] Advantageously, the compilation phase PI (or compilation method) may comprise a step consisting of receiving the source code 121 comprising one or more matrix expressions E, and of identifying these matrix expressions by analyzing the source code 121.

[0098] The compilation phase PI further comprises, 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 operational priority rules.

[0099] The compilation phase PI further comprises a step 440 consisting of generating the executable object code 221, by the execution computer device 20 (i.e. the code execution means), from the determined elementary matrix operations On and the processing instructions, predefined in particular in the computer library 123.

[0100] Advantageously, the compilation phase PI may comprise a step consisting 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 comprising at least one temporary memory space 241, each temporary memory space 241 being capable to understand temporary memory subspaces 241-n.

[0101] The method may further comprise a phase P2 of execution of the object code 221 implemented by the execution computing device 20. The execution phase P2 comprises, 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 comprise, 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 may correspond for example to a copy or to a displacement) 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 execution computer device 20 (which can be for example and without limitations a robotic system).

[0104] The execution phase P2 may further comprise 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 the “pool” type).

[0105] The execution phase P2 can also comprise, for each matrix expression E associated with the execution thread Fm, a step 564 consisting of deallocating all of the 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 comprise, 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] Those skilled in the art will easily understand that certain steps of the method of [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 executing computer 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 may be implemented as a computer program having instructions for its execution. The computer program may be recorded on a recording medium readable by a processor. 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 (e.g., application software, firmware, microcode, or any other form of computer instruction) that may be used to program one or more processors to implement aspects of the techniques described herein.The computing means or resources may in particular be distributed ("Cloud computing"), possibly using peer-to-peer technologies. The software code may be executed on any suitable processor (e.g., a microprocessor) or processor core or a set of processors, whether provided in a single computing device or distributed among several computing devices (e.g., as may be accessible in the device environment). The executable code of each program enabling the programmable device to implement the processes according to the invention may be stored, for example, in the hard disk or in read-only memory. Generally, the program(s) may be loaded into one of the storage means of the device before being executed.A central unit can control 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 disk or in the read-only memory or in the other aforementioned storage elements.

[0110] The invention is not limited to the embodiments described above as a non-limiting example. It encompasses all the variant embodiments that may be envisaged by those skilled in the art. In particular, those skilled in the art will understand that the invention is not limited to the different computer units of the device described as a non-limiting example. In particular, certain embodiments of the invention may be combined.

Claims

Claims

1. Method for compiling (PI) a source code (121) into an 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), - determining, 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, - generating an 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 of execution (Fm) associated with one or more matrix expressions (E) among said at least one matrix expression, and - delivering 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 sub-spaces (241-n); the object code instructions including, for each thread of execution (Fm): - pre-allocation instructions (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 thread of execution (Fm), instructions for successive execution of N groups of instructions (Gn) according to said order, each group of instructions (Gn) being associated with one of said N matrix operations (On) and comprising: • an instruction for allocating 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), 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.

2. Computer method comprising a compilation phase (PI) of a source code (121) into an 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 consisting 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 priority rules, and - generating an object code (221) from said N matrix operations (On), 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 method comprising, in said execution phase (P2) of said code object (221), for each thread of execution (Fm), the steps consisting in: - pre-allocating (520) a temporary memory space (241) in said storage unit (240) of the execution device, and - for each matrix expression (E) associated with said thread of execution (Fm), successively executing the N matrix operations (On) determined for the matrix expression (E), according to said order, the execution of one of said matrix operations (On) comprising the steps consisting in: • allocating 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 • evaluating said matrix operation (On), and storing said intermediate result matrix (Tn) in said temporary memory subspace (241-n),- 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.,

3. Method, according to claim 2, in which, for each matrix expression (E) associated with said thread of execution (Fm), said temporary memory sub-spaces (241-n), associated with said intermediate result matrices (Tn) provided, are allocated according to a dynamic allocation strategy of the "stack" type in said at least one temporary memory space (241) pre-allocated in said storage unit (240) and associated with said thread of execution (Fm).

4. Method according to one of claims 2 or 3, in which, for each thread of execution (Fm), said temporary memory space (241) is pre-allocated (520) in a “Heap” memory segment, said storage unit (240) corresponding to the default dynamic memory allocator.

5. Method according to one of claims 2 to 4, wherein the method comprises, in said execution phase (P2), a step of pre-allocating at least one persistent memory space (243) in said storage unit (240), and for each thread of execution (Fm), a step of assigning (562), for each matrix expression (E) associated with said thread of execution (Fm), said Nth result matrix in- intermediate (TN) of the Nth temporary memory subspace (241-N) to a matrix of said persistent memory space (243).

6. Method according to one of claims 2 to 5, in which the method comprises, in said execution phase (P2), for each thread of execution (Fm), a step consisting of deallocating (564), for each matrix expression (E) associated with said thread of execution (Fm), said N temporary memory sub-spaces (241-n) of said temporary memory space (241) associated with said thread of execution (Fm).

7. Method according to one of claims 2 to 6, in which the method comprises, in said execution phase (P2), for each thread of execution (Fm), a step consisting of deallocating (580) said temporary memory space (241) from said storage unit (240).

8. Method according to one of claims 2 to 7, in which the size of said temporary memory space (241) pre-allocated 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).

9. Compilation tool configured to implement the compilation method (PI) according to claim 1.

10. A compilation tool, according to claim 9, 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 processing instructions predefined in said computer library (123).

11. Computer system configured to implement the compilation method (PI) according to one of claims 2 to 8.

12. A system according to claim 11, wherein the code execution means are subject to real-time constraints.

Citation Information

Patent Citations

  • Method of compilation, computer program and computing system

    FR2986343A1