Method and device for transplanting mathematical calculation library and storage medium

By analyzing and optimizing the architecture and instruction set of domestic processors, the SLEEF library's performance inadequate and adaptation difficulties on domestic processors is solved, efficient mathematical computing performance is achieved, and domestic processors are promoted to high performance Applications in the fields of computing and artificial intelligence.

CN119225804APending Publication Date: 2024-12-31WUXI ADVANCED TECH RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411435244.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The unique architecture of domestic processors and SIMD instruction sets lead to insufficient direct portability and difficulty in adapting the SLEEF mathematical computing library, and the ability to fully utilize parallel computing capabilities.

Method used

By analyzing the architecture and instruction set characteristics of the migration target, architecture migration and instruction set optimization are carried out, including designing processor architecture recognition, enabling instruction set, header file configuration, compiling condition configuration, and adding SIMD instruction set extension function library, adjusting compilation options to Reduce compilation error rate and improve computing performance.

Benefits of technology

It has realized the smooth porting and optimization of the SLEEF library on domestic processors, improved mathematical computing performance, solved compatibility problems, and improved the efficiency of high-performance computing and artificial intelligence applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225804A_ABST
    Figure CN119225804A_ABST
Patent Text Reader

Abstract

The invention discloses a method and device for transplanting a mathematical calculation library and a storage medium, and the method comprises the steps: determining a transplantation target and a transplanted mathematical calculation library, and building a development environment needed by transplantation; the transplantation target is a carrier for receiving a transplanted mathematical calculation library; analyzing a source code structure, an instruction set support condition, a compiling method and a test case for the source code of the mathematical calculation library needing to be transplanted; performing architecture transplantation on the mathematical calculation library according to the architecture characteristics of the transplantation target and the source code analysis result; optimizing the mathematical calculation library according to the characteristics of the instruction set of the transplantation target; the mathematical calculation library optimization comprises compilation optimization and code optimization, the compilation optimization reduces the error rate of the compilation process by adjusting compilation constraints, and the code optimization optimizes the mathematical calculation library through an instruction set of a transplantation target; and compiling the modified mathematical calculation library source code. The method can solve the problem that the operation performance of the mathematical calculation library is affected by errors in the process of transplanting the mathematical calculation library.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method, a device and a storage medium for transplanting a mathematical calculation library, and belongs to the field of computers. Background Art

[0002] Mathematical computing libraries are basic software components that support scientific computing, image processing, artificial intelligence, and other high-performance computing fields. In recent years, with the development of hardware, processor architecture has gradually evolved towards quantization, and modern processors are usually equipped with SIMD instruction sets to improve performance in vectorized computing. In order to fully utilize the parallel computing capabilities of hardware, the development and optimization of mathematical computing libraries has gradually shifted to supporting these instruction sets, thereby improving the efficiency of data parallel computing.

[0003] SLEEF is an open source mathematical computing library that is specifically designed to efficiently calculate basic mathematical functions such as trigonometric functions, exponential functions, logarithmic functions, etc. through the SIMD instruction set. In international mainstream processors, SLEEF is widely used in various high-performance computing scenarios. SLEEF significantly improves the efficiency of these basic mathematical operations by utilizing vectorized computing and parallel execution.

[0004] However, due to the unique instruction set and architecture design of domestic processors, directly porting the SLEEF library often faces problems of insufficient performance and difficult adaptation. Especially when it comes to the SIMD instruction set of the processor, the porting process not only needs to consider the correctness of the code, but also needs to deeply optimize the hardware architecture of the target processor to give full play to the parallel computing capabilities of the processor. Therefore, porting and optimizing the SLEEF library has become an urgent issue to be solved. For domestic processors, developing a set of SLEEF versions specifically adapted to their architecture can effectively improve the performance of mathematical calculations, thereby improving the execution efficiency of application scenarios such as high-performance computing and artificial intelligence.

[0005] At present, there are several defects in the transplantation of SLEEF library for domestic processors:

[0006] Hardware architecture differences: The architectural design of domestic processors is significantly different from that of X86 and ARM. These hardware differences make SLEEF difficult to adapt when ported to domestic processors. Direct porting may lead to a decrease in computing performance and even compatibility issues.

[0007] SIMD instruction set is not supported: The core of the SLEEF library is to use the SIMD instruction set for efficient parallel computing, but the existing version of SLEEF is mainly optimized for the SIMD extension of the international mainstream architecture. The SIMD instruction set of domestic processors lacks special support in SLEEF, resulting in the inability to fully utilize the computing performance. Summary of the invention

[0008] The purpose of the present invention is to overcome the deficiencies in the prior art and provide a method, device and storage medium for transplanting a mathematical calculation library to solve the problem that errors in the process of transplanting a mathematical calculation library affect the computing performance of the mathematical calculation library.

[0009] In order to solve the above technical problems, the present invention is implemented by adopting the following technical solutions:

[0010] In a first aspect, the present invention provides a method for transplanting a mathematical calculation library, comprising:

[0011] S1: Determine the transplantation target and the transplanted mathematical calculation library, and build the development environment required for the transplantation; the transplantation target is a carrier that receives the transplanted mathematical calculation library;

[0012] S2: Analyze the source code of the mathematical calculation library in step S1; the analysis includes: analyzing the source code structure of the mathematical calculation library, the support status of the data calculation library instruction set, the mathematical calculation library compilation method and test cases.

[0013] S3: Performing architecture transplantation on the mathematical calculation library according to the architecture characteristics of the transplantation target in step S1 and the analysis result of step S2;

[0014] S4: Optimizing the mathematical calculation library according to the instruction set characteristics of the transplant target in step S1; the mathematical calculation library optimization includes compilation optimization and code optimization, wherein the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, and the code optimization optimizes the mathematical calculation library by the instruction set of the transplant target;

[0015] S5: Compile the modified mathematical calculation library source code.

[0016] In the above method for transplanting mathematical calculation library, the transplantation target in step S1 is a processor, and the construction of the development environment required for transplantation includes installing the system library and development library required for transplantation, and the system library and development library include a compiler, a standard C library and a cmake tool.

[0017] In the above method for transplanting a mathematical computing library, in step S3, the architecture transplantation includes performing the following steps in the source code of the mathematical computing library:

[0018] S31: Design a processor architecture identification method;

[0019] S32: compiles code for compiler verification and enabling instruction sets;

[0020] S33: Perform header file configuration of the processor and set parameters of the required instruction set;

[0021] S34: Performing compilation condition configuration to enable an instruction set of a processor.

[0022] The above method of transplanting the mathematical calculation library, when the mathematical calculation library is the SLEEF library and the processor is the Shenwei processor,

[0023] Step S31 includes: in the configuration file Configure.cmake of the SLEEF library source code, detecting the processor architecture through the CMAKE_SYSTEM_PROCESSOR variable, and when it is detected that the system processor is sw_64, setting the SLEEF_ARCH_SW64 flag;

[0024] Step S32 includes: in the configuration file Configure.cmake of the SLEEF library source code, using the CHECK_C_SOURCE_COMPILES command to compile the C code to confirm whether the compiler of the Shenwei platform supports the verified instruction set;

[0025] Step S33 includes: defining the header file SLEEF_HEADER_LIST of the Shenwei processor architecture in the configuration files CMakeLists.txt files in the libm and quad directories of the SLEEF library source code, and setting the parameters of each required instruction set respectively;

[0026] Step S34 includes: adding a #if defined(__sw_64__) compilation option in the header file under the arch directory of the SLEEF library source code to enable the instruction set under the Shenwei architecture.

[0027] In the aforementioned method for transplanting a mathematical calculation library, in step S4, the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, including: adding a -fno-strict-aliasing compilation option in the configuration file Configure.cmake of the SLEEF library source code.

[0028] In the aforementioned method for transplanting a mathematical computing library, in step S4, the compilation optimization further includes adding a -D_SIMD_ compilation option for enabling a supported SIMD instruction set for the Shenwei processor.

[0029] In the above-mentioned method of transplanting mathematical computing library, in step S4, the code optimization optimizes the mathematical computing library by the instruction set of the transplant target, including: adding the SIMD instruction set extension function library avx2sw64.h of the Shenwei platform to the transplanted mathematical computing library, so as to optimize the operation processing capability of the transplanted mathematical computing library.

[0030] In the above-mentioned method of transplanting a mathematical calculation library, step S5 also includes obtaining an executable program of a test case. When the mathematical calculation library is a SLEEF library, the executable program includes an executable program of an avx instruction set and / or an avx2 instruction set and / or an avx2128 instruction set and / or an sse2 instruction set and / or an sse4 instruction set.

[0031] In a second aspect, the present invention provides a device for transplanting a mathematical computing library, including an environment building module, an analysis module, an architecture transplantation module, an optimization module, and a compilation module;

[0032] The environment building module is used to: determine the transplantation target and the transplanted mathematical calculation library, and build the development environment required for the transplantation; the transplantation target is a carrier that receives the transplanted mathematical calculation library;

[0033] The analysis module is used to analyze the source code of the mathematical calculation library; the analysis includes: analyzing the source code structure of the mathematical calculation library, the support of the data calculation library instruction set, the compilation method of the mathematical calculation library and the test cases;

[0034] The architecture transplantation module is used to: perform architecture transplantation of the mathematical calculation library according to the architecture characteristics of the transplantation target and the analysis results of the analysis module;

[0035] The optimization module is used to optimize the mathematical calculation library according to the instruction set characteristics of the transplant target; the mathematical calculation library optimization includes compilation optimization and code optimization, the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, and the code optimization optimizes the mathematical calculation library through the instruction set of the transplant target;

[0036] The compilation module is used to compile the modified mathematical calculation library source code.

[0037] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any one of the methods described in the first aspect.

[0038] Compared with the prior art, the present invention has the following beneficial effects:

[0039] The present invention analyzes the characteristics of the transplantation target and the transplanted mathematical calculation library. On the one hand, it adjusts the compilation constraints to reduce the error rate of the compilation process and improve the accuracy of the calculation results and the transplantation efficiency; on the other hand, it optimizes the mathematical calculation library through the instruction set of the transplantation target, and further improves the computing power of the transplanted mathematical calculation library in combination with the characteristics of the transplantation target itself, thereby realizing the optimization of the method of transplanting the mathematical calculation library and solving the problem that the transplanted mathematical calculation library affects the computing performance of the mathematical calculation library.

[0040] When the transplantation target is a processor, the present invention analyzes the source code structure of the mathematical calculation library and the architectural characteristics of the processor, adds steps such as architecture detection, instruction set enabling and header file configuration, so that the mathematical calculation library SLEEF library can adapt to the characteristics of domestic processors, thereby achieving its smooth transplantation on the domestic processor platform and solving the compatibility problem between the mathematical calculation library and the processor architecture.

[0041] By optimizing the instruction set of the mathematical computing library, the mathematical computing performance of domestic processors has been improved. Specifically, the -D_SIMD_ and -fno-strict-aliasing compilation options are enabled, the SIMD extension library that comes with the domestic processor is added to the mathematical computing library SLEEF library, and the relevant code is modified to reduce the error rate of the compilation process while improving the parallel processing capability of the transplanted mathematical computing library operations.

[0042] The method of transplanting a mathematical computing library of the present invention effectively improves the mathematical computing performance of domestic processors and promotes the widespread application of domestic processors in the fields of high-performance computing, artificial intelligence, etc. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 This is a schematic flow chart of a method for transplanting a mathematical calculation library according to Embodiment 1 of the present invention;

[0044] Figure 2 It is a schematic diagram of the transplantation of the SLEEF library architecture of Example 1 of the present invention. DETAILED DESCRIPTION

[0045] The technical solution of the present invention is described in detail below through the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present application and the specific features in the embodiments are detailed descriptions of the technical solution of the present application, rather than limitations on the technical solution of the present application. In the absence of conflict, the embodiments of the present application and the technical features in the embodiments can be combined with each other.

[0046] The term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0047] Embodiment 1:

[0048] This embodiment 1 provides a method for transplanting a mathematical calculation library, including:

[0049] S1: Determine the transplantation target and the transplanted mathematical calculation library, and build the development environment required for the transplantation; the transplantation target is a carrier that receives the transplanted mathematical calculation library;

[0050] S2: Analyze the source code of the mathematical calculation library in step S1; the analysis includes: analyzing the source code structure of the mathematical calculation library, the support of the data calculation library instruction set, the compilation method of the mathematical calculation library and the test cases;

[0051] S3: Performing architecture transplantation on the mathematical calculation library according to the architecture characteristics of the transplantation target in step S1 and the analysis result of step S2;

[0052] S4: Optimizing the mathematical calculation library according to the instruction set characteristics of the transplant target in step S1; the mathematical calculation library optimization includes compilation optimization and code optimization, wherein the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, and the code optimization optimizes the mathematical calculation library by the instruction set of the transplant target;

[0053] S5: Compile the modified mathematical calculation library source code.

[0054] In step S1, a development environment is built including a hardware environment and a software environment.

[0055] Hardware environment: Build the development environment of Shenwei processor.

[0056] Software environment: Install necessary system libraries and development libraries, including the gcc compiler, standard c library, and cmake tool, to support the compilation and operation of the mathematical calculation library SLEEF.

[0057] In step S2, the source code of the SLEEF library is analyzed, including analyzing the source code structure of the SLEEF library, the support of the instruction set of the SLEEF library, the compilation method of the SLEEF library, and the libm-tester test case;

[0058] Analyze the source code structure of the SLEEF library, including SIMD vectorization codes for different architectures, specific implementations of mathematical functions, and codes related to mathematical library testing;

[0059] refer to Figure 2 It can be seen that the main structure of the SLEEF library source code is as follows:

[0060] CMakeLists.txt: The main configuration file of CMake, which defines the settings and rules for building the project.

[0061] Configure.cmake: CMake file used to configure the project, including custom options or modules.

[0062] doc: Document directory, including project documentation, user manuals, etc.

[0063] src: Source code directory, containing the main implementation code of the project.

[0064] travis: Contains build and test configuration files related to Travis.

[0065] Include: header file.

[0066] Among them, src includes arch (code or configuration related to a specific architecture), common (common code or library), libm (implementation of various mathematical functions), libm-tester (code for testing libm library functions), and other key parts, which are described in detail as follows:

[0067] helperavx.h: provides functions or macros based on AVX instructions.

[0068] helperavx2.h: Contains functions or macros that use AVX2 instructions.

[0069] helperpower_128.h: Functions to support 128-bit vector operations.

[0070] helpersse2.h: Contains functions or macros that use SSE instructions.

[0071] dispsse.c.org: Function implementations with architecture identifiers (such as sse).

[0072] sleefsimdsp.c: Single-precision SIMD implementation.

[0073] sleefinline_header.h.org: Definition of inline functions.

[0074] tester3.c: Functional test implementation, benchmarking to evaluate performance.

[0075] iutsimd.c: Implementation or test of SIMD instruction set, verification of SIMD related functions.

[0076] Analyze the instruction set support of the SLEEF library, including instruction set support on different platforms, instruction set selection, and optimization methods;

[0077] Analyze the SLEEF library compilation method, including how the SLEEF library adapts to different processor architectures through conditional compilation, macro definition, etc.

[0078] Analyze the libm-tester test cases in the SLEEF library source code, including the test range of mathematical functions, special values ​​(such as 0, infinity, NaN) and boundary conditions, measurement accuracy, etc.

[0079] In step S3, the source code of the mathematical calculation library is transplanted, such as Figure 2 shown.

[0080] S31: Design a processor architecture identification method;

[0081] S32: compiles code for compiler verification and enabling instruction sets;

[0082] S33: Perform header file configuration of the processor and set parameters of the required instruction set;

[0083] S34: Performing compilation condition configuration to enable an instruction set of a processor.

[0084] When the math library is the SLEEF library and the processor is the Shenwei processor:

[0085] Step S31 includes: in the configuration file Configure.cmake of the SLEEF library source code, detecting the processor architecture through the CMAKE_SYSTEM_PROCESSOR variable, and when it is detected that the system processor is sw_64, setting the SLEEF_ARCH_SW64 flag;

[0086] Architecture macro definition: By introducing architecture-related macro definitions in the code, it ensures that it can be compiled correctly under different processor architectures. You can define the SLEEF_ARCH_SW64 macro to distinguish different processor architectures.

[0087] Among them, the SLEEF_ARCH_SW64 macro is defined as follows:

[0088]

[0089] Step S32 includes: in the configuration file Configure.cmake of the SLEEF library source code, using the CHECK_C_SOURCE_COMPILES command to compile a section of C code that verifies and enables the instruction set to confirm whether the compiler of the Shenwei platform supports the verified instruction set. The Configure.cmake file is usually used to configure the parameters or options of the project, and contains some presets or settings for use by other CMake files.

[0090] When the instruction set being verified is the AVX instruction set, the AVX instruction set verification and enabling code is as follows:

[0091]

[0092] The AVX instruction set is mainly used to improve the floating-point computing capability and integer computing performance of the processor. The AVX instruction set accelerates vector computing by adding new instructions to the processor, allowing multiple data elements to be processed at a time. This computing method is particularly suitable for tasks that require processing large amounts of data, such as multimedia processing, scientific computing, and server fields.

[0093] Step S33 includes: defining the header file SLEEF_HEADER_LIST of the Shenwei processor architecture in the configuration files CMakeLists.txt files in the libm and quad directories of the SLEEF library source code respectively, and setting the parameters of each required instruction set.

[0094] The CMakeLists.txt file is the main configuration file of CMake, which is used to define the project's build process. The CMakeLists.txt file contains information such as source files, compilation options, link libraries, and dependencies.

[0095] SLEEF_HEADER_LIST is defined as follows:

[0096]

[0097] The parameter settings corresponding to each instruction set are defined as follows:

[0098]

[0099] Step S34 includes: adding a #if defined(__sw_64__) compilation option in the header file under the arch directory of the SLEEF library source code to enable the instruction set under the Shenwei architecture.

[0100] In step S4, the SLEEF library is optimized according to the instruction set characteristics of the Shenwei processor, and the optimization process includes compilation optimization and code optimization.

[0101] In step S4, the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, including: adding a -fno-strict-aliasing compilation option in the CMake tool configuration file Configure.cmake file.

[0102] During the porting process, in order to ensure the correctness and stability of the SLEEF library on domestic processors, the -fno-strict-aliasing option was enabled during compilation. This option disables the compiler's assumption of strict aliasing rules, making the compiler more conservative during optimization, thereby avoiding runtime errors caused by aliasing problems. In the specific implementation process, especially in vectorized optimized code snippets, this option ensures that pointers of different types can be safely converted and access the same memory address, ensuring the accuracy of calculation results and the stability of the program.

[0103] In step S4, the compilation optimization also includes adding a -D_SIMD_ compilation option in the Configure.cmake file of the SLEEF library source code to enable the supported SIMD instruction set for the Shenwei processor.

[0104] The supported SIMD instruction sets include AVX, AVX2, SSE and other instruction sets of the SLEEF library.

[0105] The SSE instruction set significantly improves data processing throughput and efficiency by allowing the processor to perform the same operation on multiple data elements in a single instruction cycle.

[0106] In step S4, code optimization optimizes the mathematical computing library by optimizing the instruction set of the transplant target, including: adding the SIMD instruction set extension function library avx2sw64.h of the Shenwei platform to the transplanted mathematical computing library to optimize the floating-point operation processing capability of the transplanted mathematical computing library.

[0107] The optimized code is as follows:

[0108]

[0109] It can be further seen that the cpuSupportsSIMD() function detects whether the current processor supports the SIMD instruction set. The specific implementation of the cpuSupportsSIMD() function is as follows:

[0110]

[0111] In step 5, compile the modified SLEEF source code

[0112] Compile the SLEEF library source code using the following command:

[0113]

[0114] Step S5 also includes obtaining an executable program of the test case. When the mathematical calculation library is the SLEEF library, the executable program includes an executable program of the avx instruction set and / or the avx2 instruction set and / or the avx2128 instruction set and / or the sse2 instruction set and / or the sse4 instruction set, corresponding to the executable program: tester3avx and / or tester3avx2 and / or tester3avx2128 and / or tester3sse2 and / or tester3sse4. At this point, the transplantation of the SLEEF library is completed. The entire transplantation process is as follows: Figure 1 shown.

[0115] Embodiment 2:

[0116] Based on the same inventive concept as the first embodiment, this embodiment introduces a device for transplanting a mathematical computing library, including an environment building module, an analysis module, an architecture transplantation module, an optimization module and a compilation module;

[0117] The environment building module is used to: determine the transplantation target and the transplanted mathematical calculation library, and build the development environment required for the transplantation; the transplantation target is a carrier that receives the transplanted mathematical calculation library;

[0118] The analysis module is used to analyze the source code of the mathematical calculation library; the analysis includes: analyzing the source code structure of the mathematical calculation library, the support of the data calculation library instruction set, the compilation method of the mathematical calculation library and the test cases;

[0119] The architecture transplantation module is used to: perform architecture transplantation of the mathematical calculation library according to the architecture characteristics of the transplantation target and the analysis results of the analysis module;

[0120] The optimization module is used to optimize the mathematical calculation library according to the instruction set characteristics of the transplant target; the mathematical calculation library optimization includes compilation optimization and code optimization, the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, and the code optimization optimizes the mathematical calculation library through the instruction set of the transplant target;

[0121] The compilation module is used to compile the modified mathematical calculation library source code.

[0122] Embodiment three:

[0123] Based on the same inventive concept as the first embodiment, this embodiment introduces a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of any method described in the first embodiment are implemented.

[0124] This embodiment and the first embodiment are based on the same inventive concept and have the same technical effects.

[0125] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0126] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0127] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0128] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0129] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for transplanting a mathematical computing library, characterized in that: include: S1: Determine the transplantation target and the transplanted mathematical calculation library, and build the development environment required for the transplantation; The transplantation target is a carrier that receives the transplanted mathematical calculation library; S2: Analyze the source code of the mathematical calculation library in step S1; the analysis includes: analyzing the source code structure of the mathematical calculation library, the support of the data calculation library instruction set, the mathematical calculation library compilation method and test cases; S3: Performing architecture transplantation on the mathematical calculation library according to the architecture characteristics of the transplantation target in step S1 and the analysis result of step S2; S4: Optimizing the mathematical calculation library according to the instruction set characteristics of the transplant target in step S1; the mathematical calculation library optimization includes compilation optimization and code optimization, wherein the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, and the code optimization optimizes the mathematical calculation library by the instruction set of the transplant target; S5: Compile the modified mathematical calculation library source code.

2. The method for transplanting a mathematical calculation library according to claim 1, characterized in that: The transplantation target in step S1 is a processor, and the construction of the development environment required for transplantation includes installing system libraries and development libraries required for transplantation, and the system libraries and development libraries include a compiler, a standard C library and a CMake tool.

3. The method for transplanting a mathematical calculation library according to claim 1, characterized in that: In step S3, the architecture transplantation includes performing the following steps in the source code of the mathematical calculation library: S31: Design a processor architecture identification method; S32: compiles code for compiler verification and enabling instruction sets; S33: Perform header file configuration of the processor and set parameters of the required instruction set; S34: Performing compilation condition configuration to enable an instruction set of a processor.

4. The method for transplanting a mathematical calculation library according to claim 3, characterized in that: When the math library is the SLEEF library and the processor is the Shenwei processor, Step S31 includes: in the configuration file Configure.cmake of the SLEEF library source code, detecting the processor architecture through the CMAKE_SYSTEM_PROCESSOR variable, and when it is detected that the system processor is sw_64, setting the SLEEF_ARCH_SW64 flag; Step S32 includes: in the configuration file Configure.cmake of the SLEEF library source code, using the CHECK_C_SOURCE_COMPILES command to compile the C code to confirm whether the compiler of the Shenwei platform supports the verified instruction set; Step S33 includes: defining the header file SLEEF_HEADER_LIST of the Shenwei processor architecture in the configuration files CMakeLists.txt files in the libm and quad directories of the SLEEF library source code, and setting the parameters of each required instruction set respectively; Step S34 includes: adding a #if defined(__sw_64__) compilation option in the header file under the arch directory of the SLEEF library source code to enable the instruction set under the Shenwei architecture.

5. The method for transplanting a mathematical calculation library according to claim 4, characterized in that: In step S4, the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, including: adding a -fno-strict-aliasing compilation option in the Configure.cmake file of the SLEEF library source code.

6. The method according to claim 4, characterized in that In step S4, the compilation optimization also includes adding a -D_SIMD_ compilation option in the Configure.cmake file of the SLEEF library source code to enable the supported SIMD instruction set of the Shenwei processor.

7. The method for transplanting a mathematical calculation library according to claim 6, characterized in that: In step S4, the code optimization includes optimizing the mathematical computing library by the instruction set of the transplant target: adding the SIMD instruction set extension function library avx2sw64.h of the Shenwei platform to the transplanted mathematical computing library to optimize the operation processing capability of the transplanted mathematical computing library.

8. The method for transplanting a mathematical calculation library according to claim 1, characterized in that: Step S5 also includes obtaining an executable program of the test case. When the mathematical calculation library is the SLEEF library, the executable program includes an executable program of the avx instruction set and / or the avx2 instruction set and / or the avx2128 instruction set and / or the sse2 instruction set and / or the sse4 instruction set.

9. A device for transplanting a mathematical calculation library, characterized in that: It includes environment building module, analysis module, architecture transplantation module, optimization module and compilation module; The environment building module is used to: determine the transplantation target and the transplanted mathematical calculation library, and build the development environment required for the transplantation; the transplantation target is a carrier that receives the transplanted mathematical calculation library; The analysis module is used to analyze the source code of the mathematical calculation library; the analysis includes: analyzing the source code structure of the mathematical calculation library, the support of the instruction set of the data calculation library, the compilation method of the mathematical calculation library and the test cases; The architecture transplantation module is used to: perform architecture transplantation on the mathematical calculation library according to the architecture characteristics of the transplantation target and the analysis result of the analysis module; The optimization module is used to optimize the mathematical calculation library according to the instruction set characteristics of the transplant target; the mathematical calculation library optimization includes compilation optimization and code optimization, the compilation optimization reduces the error rate of the compilation process by adjusting the compilation constraints, and the code optimization optimizes the mathematical calculation library through the instruction set of the transplant target; The compiling module is used to compile the modified mathematical calculation library source code.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.