Calculation device, calculation method, and program
Patent Information
- Application Number
- JP2024524114
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2042-06-02
AI Technical Summary
Existing methods for executing source programs are inefficient when partially converting them into intermediate representation, as they do not effectively utilize existing libraries for both source and intermediate representations, leading to suboptimal execution and data format compatibility issues.
An arithmetic device and method that determine which parts of a source program to convert into intermediate representation, generating intermediate representations with data conversion instructions to ensure compatibility, allowing for execution using existing libraries and optimizing program execution by leveraging both source and intermediate representations.
Enables efficient execution of source programs by utilizing existing libraries for both source and intermediate representations, facilitating data format conversion and optimizing program execution, thereby increasing the number of executable program parts and ensuring data compatibility.
Abstract
Description
Calculation device, calculation method, and recording medium
[0001] The present invention relates to a computing device, a computing method, and a recording medium.
[0002] There are cases where a source program is partially converted and executed, such as when compiling a program at runtime. For example, Non-Patent Document 1 describes a technique in which a graph called an IR graph is generated for a portion of a program, and the portion corresponding to the IR graph calls a compiled program to execute an operation sequence.
[0003] Alex Suhan, 6 others, "LazyTensor: combining eager execution with domain-specific compilers", arXiv:2102.13267, 2021
[0004] When a source program is partially converted into an intermediate representation (IR) and then executed, the load on system development is expected to be relatively small by using existing libraries for both the execution of the source program and the execution of the converted intermediate representation. In this case, it is considered preferable to have as many portions of the source program as possible that can be converted into an intermediate representation and executed.
[0005] An example of an object of the present invention is to provide a computing device, a computing method, and a recording medium that can solve the above-mentioned problems.
[0006] According to a first aspect of the present invention, a computing device comprises: intermediate representation determination means for determining, for each portion of a source program that is a program to be executed, whether to convert that portion into an intermediate representation or execute the program without converting it into an intermediate representation; intermediate representation generation means for generating an intermediate representation of the portion of the source program that has been determined to be converted into an intermediate representation, the intermediate representation generation means determining whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program, and if it is determined that such data exists, generating the intermediate representation including an instruction to convert the data representation format of that data; source program execution means for instructing the execution of the intermediate representation by executing the portion of the source program that has been determined not to be converted into an intermediate representation; and intermediate representation execution means for executing the intermediate representation that has been instructed to be executed.
[0007] According to a second aspect of the present invention, a calculation method includes a computer determining, for each portion of a source program that is a program to be executed, whether to convert that portion into an intermediate representation or to execute the program without converting it into an intermediate representation, generating an intermediate representation for the portion of the source program that has been determined to be converted into an intermediate representation, determining whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program, and if it is determined that such data exists, generating the intermediate representation including an instruction to convert the data representation format of that data, executing the portion of the source program that has been determined not to be converted into an intermediate representation, thereby instructing the execution of the intermediate representation, and executing the intermediate representation that has been instructed to be executed.
[0008] According to a third aspect of the present invention, a recording medium is a recording medium having recorded thereon a program for causing a computer to determine, for each portion of a source program that is a program to be executed, whether to convert that portion into an intermediate representation or to execute the program without converting it into an intermediate representation; generating an intermediate representation for the portion of the source program that has been determined to be converted into an intermediate representation; determining whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program; and, if it is determined that such data exists, generating the intermediate representation including an instruction to convert the data representation format of that data; executing the portion of the source program that has been determined not to be converted into an intermediate representation, thereby instructing the execution of the intermediate representation; and executing the intermediate representation that has been instructed to be executed.
[0009] According to the present invention, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and there are relatively many portions of the source program that can be converted into an intermediate representation and executed.
[0010] 1 is a diagram illustrating an example of the configuration of a computing device according to an embodiment; FIG. 2 is a diagram illustrating an example of components of an intermediate representation generated by an intermediate representation generation unit according to an embodiment; FIG. 3 is a diagram illustrating an example of a representation format of matrix data in a parent library according to an embodiment; FIG. 4 is a diagram illustrating an example of a representation format of matrix data in a child library according to an embodiment; FIG. 5 is a diagram illustrating an example of an intermediate representation including a data conversion instruction generated by an intermediate data conversion instruction generation unit according to an embodiment; FIG. 6 is a diagram illustrating an example of intermediate code including a data conversion instruction generated by an intermediate data conversion instruction generation unit according to an embodiment; FIG. 7 is a diagram illustrating an example of a source program including a portion converted into an intermediate representation according to an embodiment and a portion executed in a source program; FIG. 8 is a diagram illustrating an example of intermediate code including a data conversion instruction generated by an intermediate data conversion instruction generation unit according to an embodiment; FIG. 9 is a diagram illustrating an example of data flow in a control unit according to an embodiment; FIG. 10 is another example of the configuration of a computing device according to an embodiment; FIG. 11 is a diagram illustrating an example of a processing procedure in a computing method according to an embodiment; FIG. 12 is a schematic block diagram illustrating the configuration of a computer according to at least one embodiment.
[0011] Embodiments of the present invention will be described below, but the following embodiments do not limit the scope of the invention. Furthermore, not all of the combinations of features described in the embodiments are necessarily essential to the solution of the invention. FIG. 1 is a diagram illustrating an example of the configuration of a computing device according to an embodiment. In the configuration shown in FIG. 1, the computing device 100 includes a communication unit 110, a display unit 120, an operation input unit 130, a storage unit 180, and a control unit 190. The control unit 190 includes a front-end unit 210, a parent library 220, a back-end unit 230, and a child library 240. The front-end unit 210 includes an intermediate representation determination unit 211, an intermediate representation generation unit 212, an intermediate data conversion instruction generation unit 213, a source data conversion instruction generation unit 214, and a source program execution unit 215. The back-end unit 230 includes a data conversion unit 231.
[0012] The arithmetic device 100 partially converts a source program, which is a program to be executed, such as a user program, into an intermediate representation and executes it. The arithmetic device 100 may operate as a just-in-time compiler and partially convert the source program into an intermediate representation and execute it. Converting a source program into an intermediate representation is also referred to as creating an intermediate representation or generating an intermediate representation. Generally, a program is not deleted when it is executed. It is also possible for the arithmetic device 100 to leave the portion of the original source program converted into an intermediate representation intact. However, the arithmetic device 100 may also delete the portion of the original source program converted into an intermediate representation. The arithmetic device 100 is configured using a computer, such as a personal computer (PC).
[0013] The communication unit 110 communicates with other devices. For example, the communication unit 110 may communicate with another computer, such as a user's terminal device, to receive the source program. However, the method by which the arithmetic device 100 acquires the source program is not limited to a specific method.
[0014] The display unit 120 has a display screen such as a liquid crystal panel or an LED (Light Emitting Diode) panel, and acquires various images. For example, the display unit 120 displays data and the like in accordance with display commands in a source program. The operation input unit 130 includes input devices such as a keyboard and a mouse, and accepts user operations. For example, the operation input unit 130 may accept user operations to instruct execution of a source program. Alternatively, the display unit 120 may display an editor screen for inputting and editing a source program, and the operation input unit 130 may accept user operations for programming the source program.
[0015] The storage unit 180 stores various data. For example, the storage unit 180 may store a source program acquired by the communication unit 110 or the operation input unit 130. The storage unit 180 is configured using a storage device included in the arithmetic device 100.
[0016] The control unit 190 controls each unit of the arithmetic device 100 to perform various processes. In particular, the control unit 190 executes a source program. As described above with respect to the arithmetic device 100, the control unit 190 partially converts the source program into an intermediate representation and executes it. The functions of the control unit 190 are performed, for example, by a CPU (Central Processing Unit) included in the arithmetic device 100 reading and executing a program from the storage unit 180.
[0017] The arithmetic device 100 may include an accelerator such as a GPU (Graphics Processing Unit) in addition to a CPU, and the functions of the control unit 190 may be executed using the accelerator in addition to the CPU. For example, the control unit 190 may convert a portion of the source program that can be executed by a GPU into an intermediate representation for a GPU and execute it on the GPU, and the remaining portion may be executed by the CPU when executing the source program.
[0018] The computing device 100 executes both the source program and the intermediate representation using libraries. Executing the intermediate representation here means executing operations and the like indicated in the intermediate representation format. In the configuration of FIG. 1 , the parent library 220 is an example of a library used to execute the source program, and the child library 240 is an example of a library used to execute the intermediate representation.
[0019] The programming languages of the parent library and the source program are not limited to any particular one. The programming languages of the child library and the intermediate representation are also not limited to any particular one. For example, the programming languages of the parent library and the source program may be ones that provide a relatively wide variety of operations, etc., to make it easier for users to write programs. Furthermore, the programming languages of the child library and the intermediate representation may be ones that provide fewer operations, etc., compared to the execution of the source program, but have some advantage, such as high-speed execution. Furthermore, for example, the programming languages of the child library and the intermediate representation may be domain-specific languages (DSLs) specialized for devices that execute the intermediate representation, such as GPUs.
[0020] The front-end unit 210 converts part of the source program into an intermediate representation and causes the obtained intermediate representation to be executed by the back-end unit 230. Furthermore, the front-end unit 210 executes the part of the source program that is not converted into the intermediate representation by executing the source program.
[0021] The intermediate representation conversion determination unit 211 determines, for each portion of the source program, whether or not to convert that portion into an intermediate representation. For example, the intermediate representation conversion determination unit 211 determines, for each portion of the source program, whether or not that portion satisfies predetermined criteria for conversion to an intermediate representation. The intermediate representation conversion determination unit 211 determines to convert a portion determined to satisfy the criteria to an intermediate representation. On the other hand, the intermediate representation conversion determination unit 211 determines to execute a portion determined not to satisfy the criteria by executing the source program without converting it to an intermediate representation. The intermediate representation conversion determination unit 211 corresponds to an example of an intermediate representation conversion determination means. The criteria for determining whether or not to convert a portion of the source program to an intermediate representation are also referred to as intermediate representation conversion criteria.
[0022] In the following, an example will be described in which the intermediate representation determination unit 211 determines, for each instruction or operation in a source program, whether or not to convert that instruction or operation into an intermediate representation. However, the unit in which the intermediate representation determination unit 211 determines whether or not to convert a portion of a source program into an intermediate representation is not limited to a specific unit such as each instruction or operation. In the following, there may be cases in which no distinction is made between instructions and operations.
[0023] The intermediate representation conversion determination criterion used by the intermediate representation conversion determination unit 211 may include a criterion as to whether the instruction or operation to be determined is supported by a library used to execute the intermediate representation. For example, consider a case where the library used to execute the source program allows the operations of addition, subtraction, multiplication, and division, but the library used to execute the intermediate representation does not allow division. In this case, the intermediate representation conversion determination criterion may include a criterion as to whether the operation to be determined is division. The intermediate representation conversion determination unit 211 may determine, in accordance with this criterion, that a division included in the source program should be executed in the source program without being converted to an intermediate representation.
[0024] The intermediate representation conversion determination criterion used by the intermediate representation conversion determination unit 211 may include a criterion as to whether or not the data type used in the target of determination is supported by the library used to execute the intermediate representation. For example, consider a case where the library used to execute the source program can define complex number type data, but the library used to execute the intermediate representation cannot handle complex number type data. In this case, the intermediate representation conversion determination criterion may include a criterion as to whether or not the target of determination handles complex number type data. In accordance with this criterion, the intermediate representation conversion determination unit 211 may determine that the part of the source program that handles complex number type data is to be executed as the source program without being converted to an intermediate representation.
[0025] Furthermore, the intermediate representation determination unit 211 determines that, among the instructions included in the source program, a predetermined instruction that is scheduled to be executed in the source program is to be executed in the source program. For example, the intermediate representation determination unit 211 determines that a display instruction (e.g., a "print" statement) included in the source program is to be executed in the source program. The intermediate representation determination criteria may include a criterion that a predetermined instruction that is scheduled to be executed in the source program is to be executed in the source program.
[0026] The intermediate representation generation unit 212 generates an intermediate representation of the portion of the source program that the intermediate representation generation determination unit 211 has determined should be generated as an intermediate representation. The intermediate representation generation unit 212 is an example of an intermediate representation generation means. The intermediate representation generated by the intermediate representation generation unit 212 is not executed immediately upon generation, but rather when the need for execution arises. Execution of the intermediate representation in this case is also referred to as delayed execution.
[0027] For example, consider a case where a source program includes a sequence (a series of instructions) for calculating the value of a variable f and an instruction "print(f)" for displaying the value of the variable f. In this case, the intermediate representation generation unit 212 generates an intermediate representation of the sequence for calculating the value of the variable f, but the intermediate representation is not executed when the intermediate representation is generated. Then, during execution of the source program, at the timing when the instruction for displaying the value of the variable f is executed, the back-end unit 230 executes the intermediate representation of the sequence for calculating the value of the variable f using the child library 240.
[0028] Determining the value of a variable, an operation, etc. is called evaluating the variable, the operation, etc. The intermediate representation may be generated in a representation format that indicates the reference relationship of the operation so that the intermediate representation generation unit 212 can select an intermediate representation for calculating the value to be evaluated.
[0029] FIG. 2 is a diagram showing examples of components of an intermediate representation generated by the intermediate representation generation unit 212. The components of the intermediate representation shown in FIG. 2 are also referred to as operation information. FIG. 2 shows an example of operation information generated by the intermediate representation generation unit 212 for the operation "c = mat_mul(a, b)" in the source program. "mat_mul(a, b)" is a matrix operation that multiplies matrix a by matrix b, and the operation "mat_mul" corresponds to the operation "mul" in the intermediate representation.
[0030] Information d11 is information indicating an instruction code that indicates the type of instruction. In the example of FIG. 2, an operation name "mul" is shown as the instruction code. Information d12 indicates an input data reference, which is information indicating the reference destination of input data given to the instruction. FIG. 2 shows an example in which both input data "a" and "b" are calculated by an operation, and as input data references, a link to operation information for "a" and a link to operation information for "b" are shown.
[0031] A combination of an instruction code and an input data reference corresponds to an example of operation information. In the example of FIG. 2, information d10, which is a combination of information d11 and information d12, corresponds to an example of operation information for "c". In FIG. 2, a link is established from the operation information for "c" to the operation information for "a" and the operation information for "b", and information in which operation information is linked corresponds to an example of an intermediate representation. An intermediate representation can also be expressed as a sequence (a sequence of instructions). An intermediate representation expressed as a sequence is also called an intermediate code or an intermediate program.
[0032] Based on the example of FIG. 2 , the intermediate representation generation unit 212 can generate intermediate code for calculating "c" that calculates "a" and "b" and then multiplies "a" and "b" to calculate "c." An instruction for multiplying "a" and "b" to calculate "c" is expressed as, for example, "%c = mul(%a, %b)." "%a" corresponds to "a" in the source program. "%b" corresponds to "b" in the source program. "%c" corresponds to "c" in the source program.
[0033] The intermediate data conversion instruction generation unit 213 determines whether or not there is data that needs to be converted into a data representation format in the intermediate representation among the data referenced by the part of the source program that the intermediate representation conversion determination unit 211 has determined to convert into an intermediate representation. Here, cases may arise where the data representation formats of the parent library 220 and the child library 240 differ, such as when both the parent library 220 and the child library 240 use existing libraries.
[0034] Fig. 3 is a diagram showing an example of a representation format for matrix data in the parent library 220. In the example of Fig. 3, the matrix data is configured in the order of the number of rows, the number of columns, the data type, and the actual data from the top of the diagram.
[0035] Fig. 4 is a diagram showing an example of a representation format for matrix data in the child library 240. In the example of Fig. 4, the matrix data is configured in the following order from the top of the diagram: data type, number of rows, number of columns, and actual data. Comparing the example of Fig. 3 with the example of Fig. 4, in Fig. 3, the data type is shown after the number of rows and columns, whereas in Fig. 4, the data type is shown first, followed by the number of rows and columns.
[0036] In this way, if the data representation formats differ between the parent library 220 and the child library 240, it is possible that the data obtained by executing the source program will not operate correctly even if it is directly applied to the intermediate representation. Therefore, the intermediate data conversion instruction generation unit 213 generates a data conversion instruction for converting the data representation format and includes it in the intermediate representation.
[0037] The intermediate data conversion instruction generation unit 213 determines whether any data referenced during execution of the intermediate representation needs to be converted into the data representation format in the intermediate representation (the data representation format in the child library 240). If it determines that such data exists, the intermediate data conversion instruction generation unit 213 generates a conversion instruction for changing the data representation format of the data and includes it in the intermediate representation. Specifically, the intermediate data conversion instruction generation unit 213 generates a data conversion instruction for converting from the data representation format in the parent library 220 to the data representation format in the child library 240 and includes it in the intermediate representation.
[0038] For example, when matrix data in the data representation format of Fig. 3 is obtained by executing a source program, the intermediate data conversion instruction generation unit 213 generates a data conversion instruction to convert that data into matrix data in the data representation format of Fig. 4 and includes it in the intermediate representation. As a result, even if the source program includes data in a data representation format different from the data representation format of the child library 240, it is expected that the arithmetic device 100 will be able to execute the part of the program included in that data in the intermediate representation.
[0039] The intermediate data conversion instruction generation unit 213 makes such determinations, creates data conversion instructions, and inserts them into the intermediate representation at any timing between the time when the intermediate representation generation unit 212 converts a portion of the source program into the intermediate representation and before the execution of "evaluation" by the source program execution unit 215. The timing when the source program execution unit 215 executes "evaluation" is the timing when the execution result of the intermediate representation is requested.
[0040] FIG. 5 is a diagram showing an example of an intermediate representation including a data conversion instruction generated by the intermediate data conversion instruction generator 213. FIG. 5 shows an example of an intermediate representation generated by the intermediate representation generator 212 for the operation "c = mat_mul(a, b)" in the source program. As in the example of FIG. 2, in the example of FIG. 5, "mat_mul(a, b)" is a matrix operation that multiplies matrix a by matrix b, and this operation "mat_mul" corresponds to the operation "mul" in the intermediate representation. Also, as in the example of FIG. 2, in the example of FIG. 5, input data "a" is calculated by an operation. However, unlike the example of FIG. 2, in the example of FIG. 5, input data "b" is actual data represented in the data representation format of the parent library 220.
[0041] 5, the intermediate data conversion instruction generator 213 generates a data conversion instruction by the operation "convert" and includes it in the intermediate representation. In the example of Fig. 5, the operation "convert" receives input of actual data "b" and converts it into data in the data representation format of the child library 240.
[0042] FIG. 6 is a diagram showing an example of intermediate code including a data conversion instruction generated by the intermediate data conversion instruction generation unit 213. In FIG. 6, the intermediate representation shown in FIG. 5 is shown in the form of a sequence (a series of instructions). In the example of FIG. 6, "%a" corresponds to "a" in the source program. "%b" corresponds to "b" in the source program. "%t" indicates the execution result of "convert." In the intermediate code shown in FIG. 6, after calculating "a," the actual data of "b" is converted by "convert," and the calculated "a" is multiplied by the data ("%t") obtained by data conversion of "b" to calculate "c."
[0043] When it is necessary to convert the data representation format of data obtained as a result of executing the intermediate representation, the source-oriented data conversion instruction generator 214 generates a data conversion instruction for converting the data representation format and includes it in the intermediate representation. In the examples of Figures 3 and 4, if matrix data in the data representation format of Figure 4 is obtained by executing the intermediate representation, this data cannot be used as is for executing the source program. Therefore, the source-oriented data conversion instruction generator 214 generates a data conversion instruction for converting the matrix data in the data representation format of Figure 4 into matrix data in the data representation format of Figure 3 and includes it in the intermediate representation. As a result, it is expected that the matrix data in the data representation format of Figure 4 obtained by executing the intermediate representation will be converted into matrix data in the data representation format of Figure 3, and the converted data will be usable for executing the source program.
[0044] The source-oriented data conversion instruction generator 214 determines whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program (the data representation format of the parent library 220). If it determines that such data exists, the source-oriented data conversion instruction generator 214 generates a conversion instruction for the data representation format of the data and includes it in the intermediate representation. Specifically, the source-oriented data conversion instruction generator 214 generates a data conversion instruction for converting from the data representation format of the child library 240 to the data representation format of the parent library 220 and includes it in the intermediate representation.
[0045] The source-oriented data conversion instruction generation unit 214 makes such determinations, creates data conversion instructions, and inserts them into the intermediate representation at any time from the time the intermediate representation generation unit 212 converts a portion of the source program into the intermediate representation to before the source program execution unit 215 executes "evaluation." The source program execution unit 215 executes "evaluation" when the execution result of the intermediate representation is requested.
[0046] 7 is a diagram showing an example of a source program including a portion converted into an intermediate representation and a portion executed by the source program. In the example of FIG. 7, "mat_add" indicates matrix addition, "mat_mul" indicates matrix multiplication, and "mat_div" indicates matrix division. Furthermore, "a," "b," "c," and "d" are all assumed to be actual data in the data representation format of the parent library 220.
[0047] Here, it is assumed that matrix division is defined in the parent library 220, but is not defined in the child library 240. The intermediate representation determination unit 211 decides to convert "x = mat_add(a, b)" and "y = mat_mul(x, c)" into an intermediate representation and execute them, and decides to execute "z = mat_div(y, d)" in the source program (without converting it into an intermediate representation).
[0048] FIG. 8 is a diagram showing an example of intermediate code including a data conversion instruction generated by the intermediate data conversion instruction generation unit 213. FIG. 8 shows an example of intermediate code for executing "x = mat_add(a, b)" and "y = mat_mul(x, c)" from the source program shown in FIG. 7. As described above, "convert" is an operation indicating a data conversion instruction generated by the intermediate data conversion instruction generation unit 213. "add" corresponds to "mat_add" in the source program. "mul" corresponds to "mat_mul" in the source program.
[0049] "%a" corresponds to "a" in the source program. "%b" corresponds to "b" in the source program. "%c" corresponds to "c" in the source program. "%x" corresponds to "x" in the source program. "%y" corresponds to "y" in the source program. "%aa" indicates the execution result of "convert(%a)". "%bb" indicates the execution result of "convert(%b)". "%cc" indicates the execution result of "convert(%c)".
[0050] For example, the intermediate representation generation unit 212 may generate the intermediate code shown in FIG. 8 or an intermediate representation equivalent to this intermediate code in a format that uses operation information by the time the intermediate representation determination unit 211 decides to execute "z = mat_div(y, d)" in the source program.
[0051] The intermediate code shown in Figure 8 includes a data conversion instruction that converts data in the data representation format of the parent library 220 into data in the data representation format of the child library 240, and the back-end unit 230 can execute this intermediate code. However, the matrix data resulting from the execution of the intermediate code shown in Figure 8 is represented in the data representation format of the child library 240, which is different from the data representation format of the parent library 220. For this reason, the execution result of the intermediate code shown in Figure 8 cannot be used as is to execute "z = mat_div(y, d)" in the source program.
[0052] FIG. 9 is a diagram showing an example of intermediate code including a data conversion instruction generated by the source-oriented data conversion instruction generation unit 214. FIG. 9 shows an example of intermediate code in which a data conversion instruction generated by the source-oriented data conversion instruction generation unit 214 is added to the intermediate code shown in FIG. 9. In the example of FIG. 9, the source-oriented data conversion instruction generation unit 214 generates a data conversion instruction by the operation "rev_convert" and includes it in the intermediate representation. In the example of FIG. 9, the operation "rev_convert" converts matrix data in the data representation format of the child library 240, obtained as a result of executing the intermediate representation, into data in the data representation format of the parent library 220. As a result, the execution result of the intermediate representation is obtained in a format that can be used to execute the source program.
[0053] For example, the source-oriented data conversion instruction generation unit 214 may generate the data conversion instruction shown in FIG. 9 and include it in the intermediate representation at a timing between when the intermediate representation determination unit 211 decides to execute "z = mat_div(y, d)" in the source program and before the source program execution unit 215 executes "evaluation."
[0054] The source program execution unit 215 executes the source program as a source program (without converting it to an intermediate representation). Execution of the source program by the source program execution unit 215 without converting it to an intermediate representation is also referred to as fallback (degenerate operation). The source program execution unit 215 is an example of a source program execution means. The parent library 220 is a library corresponding to the programming language of the source program. The source program execution unit 215 performs fallback using the parent library 220. For example, the computing device 100 accepts a source program that uses operations provided by the parent library 220. The source program execution unit 215 then executes the source program by calling the operations of the parent library 220. It is also assumed that instructions that involve evaluation, such as the "print" instruction, are not converted into an intermediate representation but are instead executed by the source program execution unit 215 in the source program.
[0055] The backend unit 230 executes the intermediate representation. The intermediate representation generation unit 212 may output the intermediate representation to the backend unit 230 in the form of intermediate code, and the backend unit 230 may execute the intermediate code. The data conversion unit 231 of the backend unit 230 executes the data conversion instructions generated by the intermediate-directed data conversion instruction generation unit 213 and the data conversion instructions generated by the source-directed data conversion instruction generation unit 214, out of the intermediate representation generated by the intermediate representation generation unit 212. These data conversion instructions correspond to the parts of the intermediate representation generated by the intermediate representation generation unit 212 other than those supported by the child library 240.
[0056] Of the intermediate representation generated by the intermediate representation generation unit 212, the backend unit 230 executes the portion other than the data conversion instructions executed by the data conversion unit 231. In other words, of the intermediate representation generated by the intermediate representation generation unit 212, the backend unit 230 executes the portion supported by the child library 240. The backend unit 230 corresponds to an example of intermediate representation execution means. The child library 240 is a library that corresponds to the programming language of the intermediate representation. Of the intermediate representation generated by the intermediate representation generation unit 212, the backend unit 230 executes the portion other than the data conversion instructions executed by the data conversion unit 231, using the child library 240. For example, the backend unit 230 executes the operations indicated in the intermediate representation by calling the operations of the child library 240.
[0057] The combination of the front-end unit 210 and the back-end unit 230 is also referred to as an intermediate representation library. The intermediate representation library provides an execution environment for the calculations provided by the parent library 220. The intermediate representation library converts part of a source program into an intermediate representation and executes it, thereby executing the source program, for example, faster than when the parent library 220 is used.
[0058] The intermediate representation library may further have a function for optimizing the intermediate representation. For example, when the intermediate representation generation unit 212 generates an intermediate representation specialized for a specific domain such as matrix operations, the intermediate representation library may optimize the intermediate representation based on knowledge specific to that domain.
[0059] Fig. 10 is a diagram showing an example of the flow of data in the control unit 190. In the example of Fig. 10, the intermediate representation determination unit 211 acquires a source program and determines, for each part of the acquired source program, whether to convert it into an intermediate representation or to execute it as a source program without converting it into an intermediate representation.
[0060] For example, the intermediate representation generation determination unit 211 analyzes the source program in the order in which it is written and extracts portions of the source program, such as instructions or operations. Then, for each extracted portion of the source program, the intermediate representation generation determination unit 211 determines whether or not to convert that portion into an intermediate representation. The intermediate representation generation determination unit 211 outputs the portion of the source program that it has determined should be converted into an intermediate representation to the intermediate representation generation unit 212. Furthermore, the intermediate representation generation determination unit 211 outputs the portion of the source program that it has determined should be executed as a source program without converting it into an intermediate representation to the source program execution unit 215.
[0061] The intermediate representation generation unit 212 converts the part of the source program acquired from the intermediate representation determination unit 211 into an intermediate representation. For example, the intermediate representation generation unit 212 generates operation information such as those exemplified in Figures 2 and 5 based on the source program acquired from the intermediate representation determination unit 211. As described above, the intermediate representation generated by the intermediate representation generation unit 212 is not executed immediately, but is executed when the need arises during the execution of the source program.
[0062] As described above, when both the parent library 220 and the child library 240 use existing libraries, the data representation format in the parent library 220 may differ from the data representation format in the child library 240. Therefore, the intermediate data conversion instruction generator 213 and the source data conversion instruction generator 214 each generate data conversion instructions and include them in the intermediate representation.
[0063] The source program execution unit 215 executes the part of the source program acquired from the intermediate representation determination unit 211. As described above, the source program execution unit 215 executes the source program using the parent library 220, such as by calling operations provided by the parent library 220.
[0064] Furthermore, the source program execution unit 215 executes an instruction that involves evaluation, such as a "print" instruction, in the source program. If execution of an intermediate representation becomes necessary when executing an instruction that involves evaluation, the source program execution unit 215 presents data whose value is required to the intermediate representation generation unit 212 and requests that the intermediate representation be executed.
[0065] When the intermediate representation generation unit 212 receives an execution request for an intermediate representation from the source program execution unit 215, it selects an intermediate representation for calculating the value of the requested data. Then, the intermediate representation generation unit 212 outputs the selected intermediate representation to the back-end unit 230 in the form of intermediate code as exemplified in FIG. 6 for execution.
[0066] The backend unit 230 executes the intermediate representation obtained from the intermediate representation generation unit 212. Specifically, the data conversion unit 231 executes, from the intermediate representation, the data conversion instructions generated by the intermediate-directed data conversion instruction generation unit 213 and the data conversion instructions generated by the source-directed data conversion instruction generation unit 214. The backend unit 230 executes, using the child library 240, the parts of the intermediate representation other than the data conversion instructions executed by the data conversion unit 231.
[0067] It is conceivable that the data conversion instructions generated by the intermediate data conversion instruction generation unit 213 and the data conversion instructions generated by the source data conversion instruction generation unit 214 are not included in the child library 240. Therefore, the back-end unit 230 includes a data conversion unit 231 as a functional unit that executes these data conversion instructions.
[0068] The back-end unit 230 outputs data obtained as a result of executing the intermediate representation to the source program execution unit 215. As described above, when it is necessary to convert the data representation format of the data obtained as a result of executing the intermediate result, the data conversion unit 231 converts the data representation format in accordance with a data conversion command included in the intermediate representation. The back-end unit 230 then outputs the data converted by the data conversion unit 231 to the source program execution unit 215.
[0069] As described above, the intermediate representation determination unit 211 determines, for each portion of the source program that is the program to be executed, whether to convert that portion into an intermediate representation or execute the program without converting it into an intermediate representation. The intermediate representation generation unit 212 generates an intermediate representation for the portion of the source program that has been determined to be converted into an intermediate representation. The intermediate representation generation unit 212 determines whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program, and if it determines that such data exists, generates the intermediate representation that includes an instruction to convert the data representation format of that data. The source program execution unit 215 instructs the execution of the intermediate representation by executing the portion of the source program that has been determined not to be converted into an intermediate representation. The back-end unit 230 executes the intermediate representation that has been instructed to be executed.
[0070] According to the computing device 100, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and there are relatively many portions of the source program that can be converted into an intermediate representation and executed.
[0071] In particular, even if the data representation format of the data obtained as a result of executing the intermediate representation cannot be used in the execution of the source program as is, the intermediate representation can be converted into a data representation format that can be used in the source program by the data conversion instructions included in the intermediate representation by the intermediate representation generation unit 212. In this respect, according to the computing device 100, a relatively large portion of the source program can be converted into an intermediate representation and executed, and the execution results can be used in the execution of the source program.
[0072] In addition, the intermediate representation determination unit 211 decides to execute a part of the source program that it determines contains data of a data type that is not supported by the child library 240, which is the library used to execute the intermediate representation, without converting it into an intermediate representation.
[0073] According to the computing device 100, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and it is also possible to execute a source program that includes data of a data type that is not supported by the library used to execute the intermediate representation.
[0074] In addition, the intermediate representation generation unit 212 determines whether or not there is any data that needs to be converted into a data representation format in the intermediate representation among the data referenced by the part of the source program that has been decided to be converted into an intermediate representation, and if it determines that such data exists, it generates an intermediate representation that includes a conversion instruction for the data representation format of that data.
[0075] According to the computing device 100, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and there are relatively many portions of the source program that can be converted into an intermediate representation and executed.
[0076] In particular, even if a portion of the source program references data in a data representation format that cannot be used in execution of the intermediate representation as is, the data representation format of that data can be converted into a data representation format that can be used in execution of the intermediate representation by the data conversion instructions included in the intermediate representation by the intermediate representation generation unit 212. In this respect, according to the computing device 100, there are relatively many portions of the source program that can be converted into an intermediate representation and executed, and the execution results can be used in execution of the source program.
[0077] In addition, the intermediate representation determination unit 211 decides to execute a part of the source program that is determined to include an operation that is not supported by the child library 240, which is the library used to execute the intermediate representation, without converting it into an intermediate representation.
[0078] According to the computing device 100, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and it is also possible to execute a source program that includes operations that are not supported by the libraries used to execute the intermediate representation.
[0079] 11 is a diagram showing another example of the configuration of a computing device according to an embodiment. In the configuration shown in Fig. 11, a computing device 610 includes an intermediate representation determination unit 611, an intermediate representation generation unit 612, a source program execution unit 613, and an intermediate representation execution unit 614.
[0080] With this configuration, the intermediate representation determination unit 611 determines, for each portion of the source program to be executed, whether to convert that portion into an intermediate representation or execute the program without converting it into an intermediate representation. The intermediate representation generation unit 612 generates an intermediate representation for the portion of the source program determined to be converted into an intermediate representation. The intermediate representation generation unit 612 determines whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program, and if it determines that such data exists, generates an intermediate representation including an instruction to convert the data representation format of that data. The source program execution unit 613 instructs the execution of the intermediate representation by executing the portion of the source program determined not to be converted into an intermediate representation. The intermediate representation execution unit 614 executes the intermediate representation instructed to be executed.
[0081] The intermediate representation determination unit 611 corresponds to an example of an intermediate representation determination means. The intermediate representation generation unit 612 corresponds to an example of an intermediate representation generation means. The source program execution unit 613 corresponds to an example of a source program execution means. The intermediate representation execution unit 614 corresponds to an example of an intermediate representation execution means.
[0082] According to the computing device 610, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and there are relatively many portions of the source program that can be converted into an intermediate representation and executed.
[0083] In particular, even if the data representation format of the data obtained as a result of executing the intermediate representation cannot be used in the execution of the source program as is, the intermediate representation generation unit 612 can use the data conversion instructions included in the intermediate representation to convert the data into a data representation format that can be used in the execution of the source program. In this respect, the arithmetic unit 610 allows a relatively large portion of the source program to be converted into an intermediate representation and executed, with the execution results being usable in the execution of the source program.
[0084] 12 is a diagram showing an example of a processing procedure in a calculation method according to an embodiment. The calculation method shown in FIG. 12 includes determining whether to generate an intermediate representation (step S611), generating an intermediate representation (step S612), executing a source program (step S613), and executing the intermediate representation (step S614).
[0085] In determining whether to convert to an intermediate representation (step S611), the computer determines, for each portion of the source program that is the program to be executed, whether to convert that portion to an intermediate representation or execute the program without converting it to an intermediate representation. In generating an intermediate representation (step S612), the computer generates an intermediate representation for the portion of the source program that was determined to be converted to an intermediate representation, determines whether any data obtained as a result of executing the intermediate representation needs to be converted to the data representation format of the source program, and if it determines that such data exists, generates an intermediate representation that includes an instruction to convert the data representation format of that data.
[0086] In the step of executing the source program (step S613), the computer executes the portion of the source program that has been determined not to be converted into an intermediate representation, thereby instructing execution of the intermediate representation. In the step of executing the intermediate representation (step S614), the computer executes the intermediate representation that has been instructed to be executed.
[0087] According to the calculation method shown in FIG. 12, when a source program is partially converted into an intermediate representation and then executed, existing libraries can be used for both the execution of the source program and the execution of the converted intermediate representation, and there are relatively many portions of the source program that can be converted into an intermediate representation and executed.
[0088] In particular, even if the data representation format of the data obtained as a result of executing the intermediate representation cannot be used in the execution of the source program as is, the data conversion instructions included in the intermediate representation can be used to convert the data into a data representation format that can be used in the execution of the source program. In this respect, according to the calculation method shown in Figure 12, a relatively large portion of the source program can be converted into an intermediate representation and executed, and the execution results can be used in the execution of the source program.
[0089] 13 is a schematic block diagram illustrating the configuration of a computer according to at least one embodiment. In the configuration shown in FIG. 13, a computer 700 includes a CPU 710, a main memory device 720, an auxiliary memory device 730, an interface 740, a non-volatile recording medium 750, and an accelerator 760.
[0090] One or more of the above-described arithmetic device 100 and arithmetic device 610, or a part thereof, may be implemented in the computer 700. In this case, the operation of each of the above-described processing units is stored in the auxiliary storage device 730 in the form of a program. The CPU 710 and accelerator 760 read the program from the auxiliary storage device 730, load it into the main storage device 720, and execute the above-described processing in accordance with the program. The CPU 710 also allocates storage areas in the main storage device 720 corresponding to each of the above-described storage units in accordance with the program. Communication between each device and other devices is performed by the interface 740, which has a communication function, and performs communication under the control of the CPU 710.
[0091] When the arithmetic device 100 is implemented in a computer 700, the operations of the control unit 190 and each of its units are stored in the form of a program in the auxiliary storage device 730. The CPU 710 and the accelerator 760 read the program from the auxiliary storage device 730, load it into the main storage device 720, and execute the above-described processing in accordance with the program.
[0092] Furthermore, the CPU 710 allocates a storage area for the storage unit 180 in the main storage device 720 in accordance with the program. Communication between the arithmetic device 100 and other devices is performed by the interface 740, which has a communication function and operates under the control of the CPU 710. Interaction between the arithmetic device 100 and a user is performed by the interface 740, which has a display device and an input device, displaying various images under the control of the CPU 710 and accepting user operations.
[0093] When the arithmetic unit 610 is implemented in the computer 700, the operations of the intermediate representation determination unit 611, the intermediate representation generation unit 612, the source program execution unit 613, and the intermediate representation execution unit 614 are stored in the form of a program in the auxiliary storage device 730. The CPU 710 and the accelerator 760 read the program from the auxiliary storage device 730, load it into the main storage device 720, and execute the above-described processing in accordance with the program.
[0094] Furthermore, the CPU 710 allocates a storage area in the main memory device 720 for the arithmetic device 610 to perform processing in accordance with the program. Communication between the arithmetic device 610 and other devices is performed by the interface 740, which has a communication function and operates under the control of the CPU 710. Interaction between the arithmetic device 610 and a user is performed by the interface 740, which has a display device and an input device, displaying various images under the control of the CPU 710 and accepting user operations.
[0095] One or more of the above-described programs may be recorded on the nonvolatile recording medium 750. In this case, the interface 740 may read the programs from the nonvolatile recording medium 750. The CPU 710 and the accelerator 760 may then directly execute the programs read by the interface 740, or may temporarily store the programs in the main storage device 720 or the auxiliary storage device 730 and then execute them.
[0096] Alternatively, a program for executing all or part of the processing performed by the arithmetic unit 100 and the arithmetic unit 610 may be recorded on a computer-readable recording medium, and the program may be loaded into a computer system and executed to perform the processing of each unit. The term "computer system" as used herein includes hardware such as an operating system (OS) and peripheral devices. The term "computer-readable recording medium" refers to portable media such as flexible disks, optical magnetic disks, read-only memories (ROMs), and compact disc read-only memories (CD-ROMs), as well as storage devices such as hard disks built into computer systems. The program may be designed to implement part of the aforementioned functions, or may be capable of implementing the aforementioned functions in combination with a program already stored in the computer system.
[0097] Although an embodiment of the present invention has been described above in detail with reference to the drawings, the specific configuration is not limited to this embodiment, and includes designs within the scope of the gist of the present invention.
[0098] A part or all of the above-described embodiments can be described as, but not limited to, the following supplementary notes.
[0099] (Supplementary Note 1) An arithmetic device comprising: intermediate representation determination means for determining, for each portion of a source program that is a program to be executed, whether to convert that portion into an intermediate representation or execute that portion without converting it into an intermediate representation; intermediate representation generation means for generating an intermediate representation of the portion of the source program that has been determined to be converted into an intermediate representation, the intermediate representation generation means determining whether any data obtained as a result of executing the intermediate representation needs to be converted into a data representation format in the source program, and if it is determined that such data exists, generating the intermediate representation including an instruction to convert the data representation format of that data; source program execution means for instructing the execution of the intermediate representation by executing the portion of the source program that has been determined not to be converted into an intermediate representation; and intermediate representation execution means for executing the intermediate representation that has been instructed to be executed.
[0100] (Supplementary Note 2) The arithmetic device according to Supplementary Note 1, wherein the intermediate representation determination means determines that a portion of the source program that is determined to include data of a data type that is not supported by a library used to execute the intermediate representation is to be executed without being converted into an intermediate representation.
[0101] (Supplementary Note 3) The arithmetic device according to Supplementary Note 1 or Supplementary Note 2, wherein the intermediate representation generation means determines whether or not there is data that needs to be converted into a data representation format in the intermediate representation among the data referenced by the part of the source program that has been decided to be converted into an intermediate representation, and if it determines that such data exists, generates the intermediate representation including a conversion instruction for the data representation format of that data.
[0102] (Supplementary Note 4) The arithmetic device according to any one of Supplementary Notes 1 to 3, wherein the intermediate representation determination means determines that a portion of the source program that is determined to include an operation that is not supported by a library used to execute the intermediate representation is to be executed without being converted into an intermediate representation.
[0103] (Supplementary Note 5) A computing method including: a computer determining, for each part of a source program that is a program to be executed, whether to convert that part into an intermediate representation or execute the program without converting it into an intermediate representation; generating an intermediate representation for the part of the source program that has been determined to be converted into an intermediate representation; determining whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program; and if it is determined that such data exists, generating the intermediate representation including an instruction to convert the data representation format of that data; executing the part of the source program that has been determined not to be converted into an intermediate representation, thereby instructing the execution of the intermediate representation; and executing the intermediate representation that has been instructed to be executed.
[0104] (Supplementary Note 6) A recording medium having recorded thereon a program to cause a computer to: determine, for each portion of a source program that is a program to be executed, whether to convert that portion into an intermediate representation or to execute the program without converting it into an intermediate representation; generate an intermediate representation for the portion of the source program that has been determined to be converted into an intermediate representation, determine whether any data obtained as a result of executing the intermediate representation needs to be converted into the data representation format of the source program, and if it is determined that such data exists, generate the intermediate representation including an instruction to convert the data representation format of the data; execute the portion of the source program that has been determined not to be converted into an intermediate representation, thereby instructing the execution of the intermediate representation; and execute the intermediate representation that has been instructed to be executed.
[0105] The present invention may be applied to a computing device, a computing method, and a recording medium.
[0106] 100, 610 arithmetic unit 110 communication unit 120 display unit 130 operation input unit 180 storage unit 190 control unit 210 front end unit 211, 611 intermediate representation determination unit 212, 612 intermediate representation generation unit 213 intermediate data conversion instruction generation unit 214 source data conversion instruction generation unit 215, 613 source program execution unit 220 parent library 230 back end unit 231 data conversion unit 240 child library 614 intermediate representation execution unit
Claims
1. an intermediate representation determination means for determining, for each portion of a source program to be executed, whether that portion is to be converted into an intermediate representation or to be executed without being converted into an intermediate representation; an intermediate representation generating means for generating an intermediate representation of a portion of the source program that has been determined to be converted into an intermediate representation, the intermediate representation generating means determining whether or not there is data obtained as a result of executing the intermediate representation that needs to be converted into a data representation format in the source program, and when it is determined that such data exists, generating the intermediate representation including a conversion command for the data representation format of the data; a source program execution means for executing a portion of the source program that has been determined not to be converted into an intermediate representation, thereby instructing execution of the intermediate representation; an intermediate representation execution means for executing the intermediate representation instructed to be executed; A computing device comprising:
2. The intermediate representation determination means determines that a portion of the source program that is determined to include data of a data type that is not supported by a library used to execute the intermediate representation is to be executed without being converted into an intermediate representation. The computing device of claim 1 .
3. the intermediate representation generating means determines whether or not there is data that needs to be converted into a data representation format in the intermediate representation among data referenced by the part of the source program that has been decided to be converted into an intermediate representation, and when it is determined that such data exists, generates the intermediate representation including a conversion instruction for the data representation format of the data. The computing device of claim 1 .
4. The intermediate representation determination means determines that a portion of the source program that is determined to include an operation that is not supported by a library used to execute the intermediate representation is to be executed without being converted into an intermediate representation. The computing device of claim 1 .
5. The computer determining, for each portion of a source program to be executed, whether to intermediateize that portion or execute it without intermediateizing it; generating an intermediate representation of a portion of the source program that has been determined to be converted into an intermediate representation, determining whether or not any data obtained as a result of executing the intermediate representation includes data that needs to be converted into a data representation format in the source program, and if it is determined that such data exists, generating the intermediate representation including a conversion instruction for the data representation format of the data; instructing execution of the intermediate representation by executing a portion of the source program that has been determined not to be converted into an intermediate representation; Execute the intermediate representation that is instructed to be executed. A calculation method including the steps of:
6. On the computer, determining, for each portion of a source program to be executed, whether to convert that portion into an intermediate representation or to execute that portion without converting it into an intermediate representation; generating an intermediate representation of a portion of said source program that has been determined to be converted into an intermediate representation, determining whether or not any data obtained as a result of executing said intermediate representation has data that needs to be converted into a data representation format in the source program, and if it is determined that such data exists, generating said intermediate representation including a conversion instruction for the data representation format of that data; directing execution of the intermediate representation by executing a portion of the source program that has been determined not to be converted into an intermediate representation; executing the intermediate representation as instructed to be executed; A program for executing the above.