Mapping method and device for converting Fortran90 to Cuda programming language

Through the mapping method from Fortran90 to Cuda, the problems of low conversion efficiency and untimely error detection are solved, and efficient and accurate programming language conversion is achieved.

CN120406952APending Publication Date: 2025-08-01COMP NETWORK INFORMATION CENT CHINESE ACADEMY OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510477381.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-16
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In the prior art, the conversion efficiency is not high during the transplantation process of Fortran to Cuda, and the programming language conversion errors cannot be discovered and corrected in time.

Method used

A mapping method for converting from Fortran90 to the Cuda programming language is adopted, including preprocessing, syntax mapping, error determination and the use of language converters, to ensure that the Cuda programming language is error-free after conversion.

Benefits of technology

Improve the conversion efficiency of Fortran to Cuda, and can promptly detect and correct errors in programming languages, ensuring that the converted Cuda programming language is correct.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406952A_ABST
    Figure CN120406952A_ABST
Patent Text Reader

Abstract

The invention discloses a mapping method and device for converting a Fortran90 programming language into a Cuda programming language, and relates to the technical field of computers. Comprising the following steps: acquiring an initial Fortran90 programming language, preprocessing the Fortran90 programming language, and standardizing code lines; according to the specific syntax tree, establishing a syntax mapping relation between a Fortran90 programming language and a Cuda programming language; the Cuda programming language is converted into a target declaration file conforming to the Fortran90 programming language; whether errors exist in the Cuda programming language or not is judged, if errors do not exist, direct output is carried out, and otherwise, modification is carried out through the language converter till the Cuda programming language without errors is generated. According to the method, the problems that the conversion efficiency is not high in the process of transplanting from Fortran to Cuda, and errors cannot be found and corrected in time after programming language conversion occurs are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and particularly to a mapping method and device for converting from Fortran90 to the Cuda programming language. Background Art

[0002] Fortran language is a widely popular programming language suitable for scientific computing internationally and is also the world's earliest high-level programming language. Fortran is an abbreviation of Formula Translation, that is, a mathematical formula translator. After the Fortran 77 standard, the brand-new Fortran 90 standard was announced. In addition to introducing a free code style, the Fortran 90 standard also introduced important syntactic features such as modules, interface blocks, freely defined (derived) data types and operators, arrays that can be dynamically allocated and participate in complex operations, routine overloading, pointers, and recursion. This not only makes the structured language more perfect but also endows it with a small number of object-oriented language features.

[0003] With the development of graphics cards, GPUs are becoming more and more powerful, and GPUs are optimized for displaying images. They have surpassed general CPUs in computing. Such a powerful chip would be a waste if only used as a graphics card. Therefore, NVIDIA launched Cuda to enable graphics cards to be used for purposes other than image computing.

[0004] Cuda (Compute Unified Device Architecture) is a new infrastructure that can use GPUs to solve complex computing problems in business, industry, and science. It is a complete GPU solution that provides a direct access interface to the hardware, rather than relying on the graphics API interface in the traditional way to access the GPU. It adopts a brand-new computing architecture in the architecture to use the hardware resources provided by the GPU, thus providing a more powerful computing ability than the CPU for large-scale data computing applications. Cuda uses the C language as the programming language to provide a large number of high-performance computing instruction development capabilities, enabling developers to build a more efficient dense data computing solution based on the powerful computing ability of the GPU.

[0005] The existing programming language Fortran is suitable for large-scale matrix operations, while Cuda is suitable for parallel computing. However, in the prior art, during the transplantation process from Fortran to Cuda, there are problems such as low conversion efficiency and inability to detect and correct errors in programming language conversion in a timely manner. [[ID=......]]

[0006] Therefore, it is an urgent problem for those skilled in the art to propose a mapping method and device for converting from Fortran90 to the Cuda programming language to solve the difficulties existing in the prior art. Summary of the Invention

[0007] In view of this, the present invention provides a mapping method and device for converting from Fortran90 to the Cuda programming language, which solves the problems of low conversion efficiency during the transplantation process from Fortran to Cuda and the inability to promptly detect and correct errors in programming language conversion.

[0008] To achieve the above object, the present invention adopts the following technical solutions:

[0009] A mapping method for converting from Fortran90 to the Cuda programming language includes the following steps:

[0010] Obtain the initial Fortran90 programming language, preprocess the Fortran90 programming language, and standardize the code lines;

[0011] Establish a syntax mapping relationship between the Fortran90 programming language and the Cuda programming language according to the specific syntax tree;

[0012] Convert the Cuda programming language into a target declaration file that conforms to the Fortran90 programming language according to the syntax mapping relationship;

[0013] After the conversion is completed, determine whether there are errors in the Cuda programming language. If there are no errors, output directly; otherwise, use a language converter to modify until a Cuda programming language without errors is generated.

[0014] Optionally, the specific content of establishing a syntax mapping relationship between the Fortran90 programming language and the Cuda programming language according to the specific syntax tree is as follows:

[0015] Read the Fortran90 programming language according to the specific syntax tree, merge it into identification tokens according to a predetermined rule, and at the same time remove whitespace and comments, and divide the Fortran90 programming language into a one-dimensional array;

[0016] Convert the separated one-dimensional array into a tree form, and at the same time verify the syntax. If the syntax is incorrect, throw a syntax error;

[0017] Extract the global variable names in the Fortran90 programming language, find the corresponding mod files according to the use statement, and establish a mapping between the variables of the external array type and the mod file names;

[0018] Replace the internal array variables of the Fortran90 programming language with variables of the Cuda programming language, and replace the external array variables of the Fortran90 programming language with variables of the Cuda programming language;

[0019] Replace the keywords and statements in the Fortran90 programming language that are incompatible with Cuda with the correct format, and comment out the statements that are not required in Cuda;

[0020] Convert the corresponding array formats and subscript indices in the Fortran90 programming language to the Cuda programming language;

[0021] Retain the original.h files in the Fortran90 programming language, find the mod files according to the use statement, extract the variables and related definitions therein, and generate new Cuda programming language header files.

[0022] Optionally, according to the syntax mapping relationship, the specific content of converting the Cuda programming language to a target declaration file that conforms to the Fortran90 programming language is as follows:

[0023] Obtain the syntax mapping relationship, where the syntax mapping relationship includes the conversion rules for converting the syntax structure of the Fortran90 programming language to the syntax structure of the Cuda programming language;

[0024] Traverse each first node in the specific syntax tree and record the node type of each first node;

[0025] Find the conversion rules corresponding to the node type of each first node and the syntax element names of the Cuda programming language in the syntax mapping relationship;

[0026] Determine the Cuda programming language code template corresponding to each first node according to the conversion rules and the syntax element names of the Cuda programming language, where the Cuda programming language code template includes: placeholders;

[0027] Extract the target information from each first node and use the target information to replace the placeholders in the Cuda programming language code template to determine the code segment corresponding to each first node;

[0028] Concatenate the code segments corresponding to each first node to obtain the Cuda programming language code, and write the Cuda programming language code into a preset file to obtain a Cuda programming language declaration file that conforms to the Fortran90 programming language.

[0029] Optionally, after the conversion is completed, determine whether there is an error in the Cuda programming language. If there is no error, output directly; otherwise, use the language converter to modify it until the specific content of the error-free Cuda programming language is generated, which is as follows:

[0030] Start triggering from the first Fortran90 specified programming language, verify that the platform pushes out the corresponding Cuda programming language paragraph, that is, the converted Cuda programming language is correct, and then trigger the next Fortran90 specified programming language until the end, confirm and store the converted Cuda programming language;

[0031] If there is no corresponding Cuda programming language paragraph, adjust the adapter, modify the Fortran90 specified programming language, and then return to the previous step to verify again.

[0032] Optionally, the verification platform records the content and related times of adapter adjustment. When the content of the same adjustment reaches the specified number of times, relevant rectification is carried out on the adapter through the technical background.

[0033] A mapping device for converting from Fortran90 to Cuda programming language, applying a mapping method for converting from Fortran90 to Cuda programming language according to any one of the above, including a preprocessing module, a processing module, an adapter, a verification platform, a memory, and a compiler connected in sequence;

[0034] The preprocessing module is used to preprocess the Fortran90 programming language and standardize the code lines;

[0035] The processing module is used to store and send the initial Fortran90 specified programming language;

[0036] The adapter is used to compile the initial Fortran90 specified programming language into Cuda programming language;

[0037] The verification platform is used to determine whether the Cuda programming language is converted into a compliant Fortran90 programming language;

[0038] The memory is used to convert the correct Cuda programming language;

[0039] The compiler is used to generate an executable program from the Cuda programming language.

[0040] From the above technical solutions, it can be seen that compared with the prior art, the present invention provides a mapping method and device for converting from Fortran90 to Cuda programming language, and has the following beneficial effects:

[0041] (1) The present invention solves the problems existing in the process of porting from Fortran to Cuda, such as low conversion efficiency and the inability to detect and correct errors in programming language conversion in a timely manner.

[0042] (2) The present invention can quickly and accurately convert the initial text language of a program, and determine whether there are errors in the Cuda programming language after the conversion is completed, and run on systems using different programming languages. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to the provided drawings.

[0044] Figure 1 It is a flowchart of a mapping method for converting from Fortran90 to the Cuda programming language provided by the present invention;

[0045] Figure 2 It is a structural block diagram of a mapping device for converting from Fortran90 to the Cuda programming language provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0046] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.

[0047] Refer to Figure 1 As shown, the present invention discloses a mapping method for converting from Fortran90 to the Cuda programming language, including the following steps:

[0048] Obtain the initial Fortran90 program language, preprocess the Fortran90 program language, and standardize the code lines;

[0049] Establish a syntax mapping relationship between the Fortran90 program language and the Cuda programming language according to the specific syntax tree;

[0050] Convert the Cuda programming language into a target declaration file that conforms to the Fortran90 program language according to the syntax mapping relationship;

[0051] After the conversion is completed, it is determined whether there are errors in the Cuda programming language. If there are no errors, it is directly output; otherwise, the language converter is used to modify it until a Cuda programming language without errors is generated.

[0052] Furthermore, the specific content of establishing the syntax mapping relationship between the Fortran90 programming language and the Cuda programming language according to the specific syntax tree is as follows:

[0053] Read the Fortran90 programming language according to the specific syntax tree, merge it into identification tokens according to the predetermined rules, and at the same time remove whitespace and comments. The Fortran90 programming language is split into a one-dimensional array.

[0054] Convert the split one-dimensional array into a tree form, and at the same time verify the syntax. If the syntax is incorrect, a syntax error is thrown.

[0055] Extract the global variable names in the Fortran90 programming language, find the corresponding mod files according to the use statement, and establish the mapping between the variables of the external array type and the mod file names.

[0056] Replace the internal array variables of the Fortran90 programming language with variables of the Cuda programming language, and replace the external array variables of the Fortran90 programming language with variables of the Cuda programming language.

[0057] Replace the keywords and statements in the Fortran90 programming language that are incompatible with Cuda with the correct format, and comment out the statements that are not required in Cuda.

[0058] Convert the corresponding array formats and subscript indexes in the Fortran90 programming language into the Cuda programming language.

[0059] Retain the.h files in the original Fortran90 programming language, find the mod files according to the use statement, extract the variables and related definitions in them, and generate new Cuda programming language header files.

[0060] Furthermore, the specific content of converting the Cuda programming language into a target declaration file that conforms to the Fortran90 programming language according to the syntax mapping relationship is as follows:

[0061] Obtain the syntax mapping relationship, where the syntax mapping relationship includes the conversion rules for converting the syntax structure of the Fortran90 programming language to the syntax structure of the Cuda programming language.

[0062] Traverse each first node in the specific syntax tree and record the node type of each first node.

[0063] Find the conversion rules corresponding to the node types of each first node and the syntax element names of the Cuda programming language in the syntax mapping relationship;

[0064] Determine the Cuda programming language code template corresponding to each first node according to the conversion rules and the syntax element names of the Cuda programming language, where the Cuda programming language code template includes: placeholders;

[0065] Extract the target information from each first node, and use the target information to replace the placeholders in the Cuda programming language code template to determine the code segment corresponding to each first node;

[0066] Concatenate the code segments corresponding to each first node to obtain the Cuda programming language code, and write the Cuda programming language code into a preset file to obtain a Cuda programming language declaration file that conforms to the Fortran90 programming language.

[0067] Further, after the conversion is completed, determine whether there are errors in the Cuda programming language. If there are no errors, output directly; otherwise, use a language converter to modify until the specific content of the Cuda programming language without errors is generated:

[0068] Start triggering from the first Fortran90 specified programming language, verify that the platform pushes out the corresponding Cuda programming language paragraph, that is, the converted Cuda programming language is correct, and then trigger the next Fortran90 specified programming language until the end, and confirm and store the converted Cuda programming language;

[0069] If there is no corresponding Cuda programming language paragraph, adjust the adapter, modify the Fortran90 specified programming language, and then return to the previous step to verify again.

[0070] Further, the verification platform records the content and related times of adapter adjustment. When the same adjusted content reaches the specified number of times, the adapter is rectified through the technical background.

[0071] In a specific embodiment, it includes the following content:

[0072] (1) Obtain the initial Fortran90 programming language, preprocess the Fortran90 programming language, retain the comments of the original program code, merge the multi-line program code, and remove the multi-line symbols; perform normalization preprocessing on the Fortran90 program code "!casein point" and rewrite it into the Cuda program code " / / !case inpoint".

[0073] (2) Read the Fortran90 programming language according to the specific syntax tree, merge it into identifying tokens according to the predetermined rules, and remove whitespace and comments at the same time. The Fortran90 programming language is split into a one-dimensional array;

[0074] Convert the split one-dimensional array into a tree form and verify the syntax at the same time. If there is a syntax error, throw a syntax error;

[0075] For variables of real and dimension types in the Fortran90 programming language, extract the internal variable names and the corresponding dimension information; extract all array-type variables according to the subscript operator "()"; remove keywords, internal variables, and function names to obtain all external array variable names;

[0076] Find the corresponding mod file according to the use statement and establish a mapping between variables of external array types and mod file names;

[0077] Replace variable names according to different compilers. For example, for ifort, replace the internal array variables of the Fortran90 programming language with variables of the Cuda programming language, and replace the external array variables of the Fortran90 programming language with variables of the Cuda programming language; for example, replace the internal array variable a of the Fortran90 programming language with the variable a_ of the Cuda programming language, and replace the external array variable b of the Fortran90 programming language with the external array variable fun_mod_mp_b of the Cuda programming language;

[0078] Replace keywords and statements in the Fortran90 programming language that are incompatible with Cuda with the correct format, comment out statements that are not required in Cuda, and replace the Fortran90 program code "integer::i,j,k" with the Cuda program code "int i,j,k";

[0079] Convert the corresponding array format and subscript index in the Fortran90 program code into Cuda program code; specifically, when processing a do loop, convert the corresponding array format A[i][j] in the Fortran90 program code into the corresponding array format A[i*n+j] in the Cuda program code, where n is the second dimension of a. In an example, replace the Fortran90 program code "doj=1,m;c(j,i)=0" with the Cuda program code "if(j>=0&&j<=m){param_mp_c[i*m+j]=0}";

[0080] Retain the.h files in the original Fortran90 program code, search for mod files according to the use statement, extract the variables and related definitions therein, and generate a new header file for the Cuda program code.

[0081] (3) After the conversion is completed, determine whether there are errors in the Cuda programming language. If there are no errors, output directly; otherwise, use the language converter to modify until a Cuda programming language without errors is generated. Specifically, start triggering from the first Fortran90 specified programming language, verify that the platform pushes out the corresponding Cuda programming language paragraph, that is, the converted Cuda programming language is correct, and then trigger the next Fortran90 specified programming language until the end, and confirm and store the converted Cuda programming language;

[0082] If there is no corresponding Cuda programming language paragraph, adjust the adapter, modify the Fortran90 specified programming language, and return to the previous step to verify again;

[0083] The verification platform records the content and related times of adapter adjustment. When the same adjusted content reaches the specified number of times, relevant rectification is carried out on the adapter through the technical background.

[0084] And Figure 1 Corresponding to the method described above, an embodiment of the present invention also provides a mapping device for converting from Fortran90 to Cuda programming language, and its structural schematic diagram is as Figure 2 shown, including a preprocessing module, a processing module, an adapter, a verification platform, a memory, and a compiler connected in sequence;

[0085] The preprocessing module is used to preprocess the Fortran90 programming language and standardize the code lines;

[0086] The processing module is used to store and send the initial Fortran90 specified programming language;

[0087] The adapter is used to compile the initial Fortran90 specified programming language into a Cuda programming language;

[0088] The verification platform is used to determine whether the Cuda programming language is converted into a compliant Fortran90 programming language;

[0089] The memory is used to convert the correct Cuda programming language;

[0090] The compiler is used to generate an executable program from the Cuda programming language.

[0091] In the present specification, the various embodiments are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple. For the relevant parts, reference can be made to the description in the method section.

[0092] The foregoing description of the disclosed embodiments enables those skilled in the art to practice or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A mapping method for converting from Fortran90 to the Cuda programming language, characterized in that, Including the following steps: Obtain the initial Fortran90 programming language, preprocess the Fortran90 programming language, and standardize the code lines; Establish a syntax mapping relationship between the Fortran90 programming language and the Cuda programming language according to the specific syntax tree; Convert the Cuda programming language into a target declaration file that conforms to the Fortran90 programming language according to the syntax mapping relationship; After the conversion is completed, determine whether there are errors in the Cuda programming language. If there are no errors, output directly. Otherwise, use the language converter to modify until a Cuda programming language without errors is generated.

2. A mapping method from Fortran90 to Cuda programming language according to claim 1, characterized in that The specific content of establishing a syntax mapping relationship between the Fortran90 programming language and the Cuda programming language according to the specific syntax tree is: Read the Fortran90 programming language according to the specific syntax tree, merge it into identifier tokens according to the predetermined rules, and remove whitespace and comments at the same time. The Fortran90 programming language is split into a one-dimensional array; Convert the split one-dimensional array into a tree form and verify the syntax at the same time. If the syntax is incorrect, throw a syntax error; Extract the global variable names in the Fortran90 programming language, find the corresponding mod files according to the use statement, and establish a mapping between the variables of the external array type and the mod file names; Replace the internal array variables of the Fortran90 programming language with variables of the Cuda programming language, and replace the external array variables of the Fortran90 programming language with variables of the Cuda programming language; Replace the keywords and statements in the Fortran90 programming language that are incompatible with Cuda with the correct format, and comment out the statements that are not required in Cuda; Convert the corresponding array formats and subscript indices in the Fortran90 programming language into the Cuda programming language; Retain the.h files in the original Fortran90 programming language, find the mod files according to the use statement, extract the variables and related definitions therein, and generate a new Cuda programming language header file.

3. A mapping method from Fortran90 to Cuda programming language according to claim 1, characterized in that The specific content of converting the Cuda programming language into a target declaration file that conforms to the Fortran90 programming language according to the syntax mapping relationship is: Obtain the syntax mapping relationship, where the syntax mapping relationship includes the conversion rules for converting the syntax structure of the Fortran90 programming language to the syntax structure of the Cuda programming language; Traverse each first node in the specific syntax tree and record the node type of each first node; Find the conversion rules corresponding to the node type of each first node and the syntax element names of the Cuda programming language in the syntax mapping relationship; According to the conversion rules and the syntax element names of the Cuda programming language, determine the Cuda programming language code template corresponding to each first node. The Cuda programming language code template includes: placeholders; Extract the target information in each first node, and use the target information to replace the placeholders in the Cuda programming language code template to determine the code segment corresponding to each first node; Perform splicing processing on the code segments corresponding to each first node to obtain the Cuda programming language code, and write the Cuda programming language code into a preset file to obtain a Cuda programming language declaration file that conforms to the Fortran90 programming language.

4. The mapping method from Fortran90 to Cuda programming language according to claim 1, characterized in that After the conversion is completed, determine whether there are errors in the Cuda programming language. If there are no errors, output directly; otherwise, use a language converter to modify until the specific content of the Cuda programming language without errors is generated: Start triggering from the first Fortran90 specified programming language, verify that the platform pushes out the corresponding Cuda programming language paragraph, that is, the converted Cuda programming language is correct, and then trigger the next Fortran90 specified programming language until the end, confirm and store the converted Cuda programming language; If there is no corresponding Cuda programming language paragraph, adjust the adapter, modify the Fortran90 specified programming language, and then return to the previous step to verify again.

5. The mapping method from Fortran90 to Cuda programming language according to claim 4, characterized in that The verification platform records the content and related times of adapter adjustment. When the same adjusted content reaches the specified number of times, relevant rectification of the adapter is carried out through the technical background.

6. A mapping device for converting from Fortran90 to the Cuda programming language, characterized in that, Applying the mapping method from Fortran90 to Cuda programming language according to any one of claims 1-5, including a preprocessing module, a processing module, an adapter, a verification platform, a memory, and a compiler connected in sequence; The preprocessing module is used to preprocess the Fortran90 programming language and standardize the code lines; The processing module is used to store and send the initial Fortran90 specified programming language; The adapter is used to compile the initial Fortran90 specified programming language into the Cuda programming language; The verification platform is used to judge whether the Cuda programming language is converted into a conforming Fortran90 programming language; The memory is used to convert the correct Cuda programming language; The compiler is used to generate an executable program from the Cuda programming language.