Function library linking method and device, equipment, storage medium and program product

By dividing the function library into groups and static and dynamic linking, the problem of failure of function library call in the shared instruction space accelerator is solved, and the effect of reducing the jump distance of the function library and avoiding failure of program operation is achieved.

CN119440672AActive Publication Date: 2025-02-14BEIJING QINGCHENG JIZHI TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411470314.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2025-02-14
Estimated Expiration
2044-10-21

AI Technical Summary

Technical Problem

The shared instruction space accelerator may cause link failure when calling the function library, resulting in program failure. This is mainly because the function jump range on the accelerator is limited, resulting in the address jump distance between libraries being too far.

Method used

By dividing multiple function libraries into multiple function library groups, the call distance between function libraries in the same function library group is limited, and static linking is performed to merge library files, and dynamic linking is formed to reduce the number of function libraries between them. jump distance.

Benefits of technology

By dividing the function library into groups and statically linking, the jump distance between the function library is limited, the call failure of the shared instruction space accelerator is avoided, and the stable operation of large programs on the accelerator is achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440672A_ABST
    Figure CN119440672A_ABST
Patent Text Reader

Abstract

The invention discloses a function library linking method and device, equipment, a storage medium and a program product, and relates to the technical field of artificial intelligence, and the method comprises the steps that multiple function libraries are divided into multiple function library groups, the calling distance between a first function library and at least one second function library in the same function library group is limited, and the calling distance between the first function library and the at least one second function library in the same function library group is limited; the calling distance between the function libraries of different function library groups is not limited, the first function library is any function library in the function libraries of the same function library group, and the second function library is the function library except the first function library in the function libraries of the same function library group; performing static linking on the function libraries in the plurality of function library groups to obtain respective static link files of the plurality of function libraries; and dynamically linking each static link file to obtain a dynamic link library. According to the method, the jump distance between the function libraries can be reduced, and the condition of calling failure of the shared instruction space accelerator is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a function library linking method, apparatus, device, storage medium and program product. Background Art

[0002] An artificial intelligence tensor accelerator is a hardware device that can be installed in a computer and used in combination with the computer's CPU (Central Processing Unit). When the CPU and accelerator are used in combination, the CPU reads CPU-specific instructions and performs various general-purpose calculations according to the instructions, while the accelerator reads accelerator-specific instructions and processes tensor calculations in artificial intelligence programs according to the instructions. According to the different ways of reading instructions, accelerators can be divided into accelerators with private instruction memory and accelerators with shared instruction memory. Accelerators with shared instruction memory can directly read instructions from the memory space that stores CPU instructions. Therefore, users can store CPU instructions and accelerator instructions in the same memory space. When executing an artificial intelligence program, the library containing the instructions corresponding to the artificial intelligence program and the program will be linked together. Due to the limited function jump range on the accelerator, the mixed storage of CPU instructions and accelerator instructions may cause the addresses between accelerator instructions to be too far apart, resulting in a link failure and program failure.

[0003] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0004] The main purpose of the present application is to provide a function library linking method, device, equipment, storage medium and program product, aiming to solve the technical problem of failure in calling a shared instruction space accelerator.

[0005] To achieve the above purpose, the present application proposes a function library linking method, the method comprising:

[0006] Divide a plurality of function libraries into a plurality of function library groups, wherein a calling distance between a first function library and at least one second function library in the same function library group is limited, and a calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library among the function libraries in the same function library group except the first function library;

[0007] Static linking the function libraries in the multiple function library groups respectively to obtain static link files of the multiple function libraries;

[0008] The static link files are dynamically linked to obtain a dynamic link library.

[0009] In one embodiment, the step of dividing the plurality of function libraries into a plurality of function library groups comprises:

[0010] For any target function library among the multiple function libraries, if there is a call class instruction in the target function library, traverse each of the call class instructions in the target function library to determine a call start function and a call destination function of the call class instruction, wherein the call start function is a function where the call class instruction calls and a function where the call destination of the call class instruction calls;

[0011] If the function types of the calling start function and the calling target function are both accelerator functions, the target function library and the function library where the calling target function is located are divided into the same function library group.

[0012] In one embodiment, the step of statically linking the function libraries within the multiple function library groups to obtain the static link files of the multiple function libraries includes:

[0013] For any target function library group among the plurality of function library groups, library files of each function library in the target function library group are input into a static linker, multiple segments with the same attributes in each library file are merged into a target segment through the static linker, and each target segment is copied to a preset target file to obtain a merged file;

[0014] Parsing each of the library files by the static linker to obtain each of the symbols in the library files, searching for each of the actual memory addresses of the symbols in the target end by the static linker, and constructing a static symbol table by the static linker based on each of the actual memory addresses of the symbols and the symbols;

[0015] The merged file and the static symbol table are packaged into an executable file through the static linker, and the packaged executable file is used as the static link file corresponding to the target function library group.

[0016] In one embodiment, before the step of statically linking the function libraries within the multiple function library groups to obtain the static link files of the multiple function libraries, the method further includes:

[0017] Creating an empty source file, and using the empty source file as a statically linked main program;

[0018] The step of copying each of the target segments to a preset target file to obtain a merged file comprises:

[0019] Copy each of the target segments to the statically linked main program to obtain a merged file.

[0020] In one embodiment, the step of dynamically linking each of the static link files to obtain a dynamic link library includes:

[0021] Inputting each of the static link files into a dynamic linker, and allocating a space address to each of the static link files through the dynamic linker;

[0022] Reading each symbol in each of the static link files through the dynamic linker, and relocating each symbol based on the spatial address of each of the static link files to obtain dynamic address information of each symbol;

[0023] A dynamic symbol table is generated based on the various symbols and the dynamic address information of the various symbols, and the dynamic symbol table is added to a preset shared library to obtain a dynamic link library.

[0024] In one embodiment, if there is a function library from the packaged compiler, the step of dynamically linking each of the static link files to obtain a dynamic link library further includes:

[0025] Dynamically linking each of the static link files through a non-encapsulated compiler to obtain a basic link library;

[0026] The function library from the packaged compiler is linked to the basic link library to obtain a dynamic link library.

[0027] In addition, to achieve the above purpose, the present application also proposes a function library linking method, the method comprising:

[0028] a grouping module, used for dividing a plurality of function libraries into a plurality of function library groups, wherein a calling distance between a first function library and at least one second function library in the same function library group is limited, and a calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library among the function libraries in the same function library group except the first function library;

[0029] A static link module, used for statically linking the function libraries in the multiple function library groups to obtain respective static link files of the multiple function libraries;

[0030] The dynamic link module is used to dynamically link each of the static link files to obtain a dynamic link library.

[0031] In addition, to achieve the above purpose, the present application also proposes a function library linking device, the function library linking device comprising:

[0032] In addition, to achieve the above-mentioned purpose, the present application also proposes a function library linking device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the function library linking method described above.

[0033] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the function library linking method described above are implemented.

[0034] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the function library linking method described above are implemented.

[0035] In the present application, multiple function libraries are divided into multiple function library groups, wherein the calling distance between a first function library and at least one second function library in the same function library group is limited, and the calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library other than the first function library among the function libraries in the same function library group; the function libraries within the multiple function library groups are statically linked to obtain the static link files of the multiple function libraries; and the static link files are dynamically linked to obtain dynamic link libraries.

[0036] The present application divides each function library with limited calling distance into the same group, and statically links the function libraries in the same group. Static linking can merge these libraries into a single static link file. The libraries inside each static link file have been closely combined through static linking. The jump distance between libraries in the same function library group is limited to a smaller range, thereby reducing the jump distance between function libraries and avoiding the situation where the shared instruction space accelerator fails to call. At the same time, each static link file is dynamically linked to form a dynamic link library. Since these static link files have merged the codes of the function libraries in the group, the calls between static link files can be realized by jumping inside the dynamic link library without crossing the entire address space, thereby reducing the jump distance between function libraries and avoiding the situation where the shared instruction space accelerator fails to call. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0039] Figure 1 A schematic diagram of a scenario of a general function library linking method provided in an embodiment of the present application;

[0040] Figure 2 A flowchart of the first embodiment of the method for linking a function library of the present application is provided;

[0041] Figure 3 A schematic diagram of a function library grouping scenario of a function library linking method provided in an embodiment of the present application;

[0042] Figure 4 A schematic diagram of a function library merging scenario of a function library linking method provided in an embodiment of the present application;

[0043] Figure 5 A schematic diagram of a static linking scenario of a function library linking method provided in an embodiment of the present application;

[0044] Figure 6 This is a schematic diagram of the module structure of the function library linking device according to an embodiment of the present application;

[0045] Figure 7 Schematic diagram of the device structure of the hardware operating environment involved in the function library linking method in the embodiment of the present application.

[0046] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0048] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0049] The main solution of the embodiment of the present application is: by dividing multiple function libraries into multiple function library groups, wherein the calling distance between a first function library and at least one second function library in the same function library group is limited, and the calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the various function libraries in the same function library group, and the second function library is a function library other than the first function library among the various function libraries in the same function library group; statically linking the function libraries within the multiple function library groups respectively to obtain static link files of the multiple function libraries; and dynamically linking each of the static link files to obtain a dynamic link library.

[0050] In this embodiment, for ease of description, the following description is based on the function library link device as the execution subject. The artificial intelligence tensor accelerator is a hardware device installed in the computer, and is the same as the CPU as the computing unit of the computer. Among them, the CPU can perform various general-purpose calculations, but the performance is relatively low; the accelerator has limited functions and can only process tensor calculations in artificial intelligence programs, but the performance is relatively high. By mixing the CPU and the artificial intelligence accelerator, a complete artificial intelligence program with both tensor calculations and peripheral general-purpose calculations can be efficiently executed.

[0051] To mix the CPU and the accelerator, the CPU needs to read the CPU-specific instructions, and the accelerator reads the accelerator-specific instructions, and these instructions together constitute a complete program. According to the different ways of reading instructions, the accelerator can be divided into an accelerator with a private instruction memory and an accelerator with a shared instruction memory. The embodiment of the present application is applied to an accelerator with a shared instruction memory. This type of accelerator can read instructions directly from the memory space storing the CPU instructions without using a dedicated memory to store the accelerator instructions, which simplifies the steps of reading instructions. When using this type of accelerator, the user only needs to store the CPU instructions and the accelerator instructions in the same memory space.

[0052] Different AI programs need to perform the same or similar calculations. These same or similar calculations can be summarized into multiple functions and written in various function libraries (hereinafter referred to as libraries). The same library can be used by multiple AI programs, and each AI program may also use multiple libraries at the same time. Some libraries contain accelerator instructions executed on the accelerator, and some libraries contain CPU instructions executed on the CPU. To use multiple libraries in an AI program, you need to link this program with these libraries. Please refer to Figure 1 In the scenario diagram shown, during the linking process, the program (main program), library A and library B are linked to the instructions in the program and library and they will be encoded in a unified address space, where each instruction is assigned a unique address. During the linking process, the call address of each function in the program and library is rewritten to the unique address, so that the functions in the program and library can call each other.

[0053] Linking can be divided into static linking and dynamic linking. When static linking is used, the order of libraries in the address space is determined immediately. When dynamic linking is used, the order of libraries in the address space is postponed to the program runtime and is determined on demand. The specific order varies depending on the actual execution of the program. Python is the mainstream programming language for artificial intelligence development. To use libraries in Python, dynamic linking is required between the Python interpreter (that is, the main Python program) and the library.

[0054] Linking can be done in stages. For example, if you want to link library A, library B, and library C together, you can first link library A and library B into library X, and then link library X and library C together. When linking in stages, you can use only static linking, only dynamic linking, or first use static linking and then dynamic linking, but you cannot use dynamic linking first and then static linking.

[0055] Since accelerators sacrifice functionality to improve performance, the range of function jumps on many accelerators is limited, that is, if you want to call the instruction at address Y from the instruction at address X, the distance between X and Y cannot be too far. If there are many libraries to be linked, and the mutually called libraries A and B are distributed at both ends of the address space, the jump distance is likely to be too far, resulting in a link failure, which in turn causes the program to fail to run. Since accelerators with shared instruction memory do not distinguish between libraries executed on the accelerator and libraries executed on the CPU, after using a general method to link, many CPU libraries will be inserted between multiple accelerator libraries, further increasing the distance between accelerator libraries and exacerbating this problem.

[0056] Due to this problem, the general linking method can only be used for small programs that use only a small number of libraries. However, the embodiment of the present application can avoid the problem of too long jump distance by reasonably adjusting the order of the linked libraries, so that large programs that need to link a large number of libraries can be run on the accelerator.

[0057] A solution is provided in the embodiment of the present application, by dividing each function library with limited calling distance into the same group, statically linking the function libraries in the same group, and statically linking these libraries into a single static link file, the libraries inside each static link file have been tightly combined together through static linking, and the jump distance between libraries in the same function library group is limited to a smaller range, thereby reducing the jump distance between function libraries and avoiding the situation where the shared instruction space accelerator fails to call. At the same time, each static link file is dynamically linked to form a dynamic link library. Since these static link files have merged the codes of the function libraries in the group, the calls between static link files can be realized by jumping inside the dynamic link library without crossing the entire address space, thereby reducing the jump distance between function libraries and avoiding the situation where the shared instruction space accelerator fails to call.

[0058] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, a server, etc., or an electronic device capable of realizing the above functions, a function library linking device, etc. The following takes the function library linking device as an example to illustrate this embodiment and the following embodiments.

[0059] Based on this, the embodiment of the present application provides a function library linking method, referring to Figure 2 , Figure 2 This is a flowchart of the first embodiment of the function library linking method of the present application.

[0060] In this embodiment, the function library linking method includes steps S10 to S30:

[0061] Step S10, dividing the multiple function libraries into multiple function library groups, wherein the calling distance between a first function library and at least one second function library in the same function library group is limited, and the calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library among the function libraries in the same function library group except the first function library.

[0062] It should be noted that a function library is a set of pre-written functions for programs to call to achieve specific functions. A function library group is a grouping of multiple function libraries according to certain rules or standards for easy management and optimization. Call distance usually refers to the dependency between functions or modules. Limited call distance means that calls between functions need to meet specific conditions or rules.

[0063] In this embodiment, the calling relationship between function libraries is analyzed, and function libraries with close calling relationship are divided into the same group, while ensuring that the calling distance within the group is limited, while the calling distance between groups is not limited. In a specific implementation, the process of dividing multiple function libraries into multiple function library groups may include:

[0064] Step S101, for any target function library among the multiple function libraries, if there is a calling class instruction in the target function library, traverse each of the calling class instructions in the target function library to determine the calling start function and the calling destination function of the calling class instruction, wherein the calling start function is the function where the calling class instruction calls and the function where the calling class instruction calls.

[0065] It should be noted that the calling class instruction is an instruction or statement used to call other functions in the program. The calling start function is the function that executes the calling class instruction, that is, the function that initiates the call, and the calling target function is the function called by the calling class instruction, that is, the target function that receives the call.

[0066] Functions can be classified into different function types according to their functions or uses. In this embodiment, they can be divided into accelerator functions and processor functions, where accelerator functions refer to functions executed by accelerators to process tensor calculations in artificial intelligence programs, and processor functions refer to functions executed by central processing units to process routine computing tasks.

[0067] In this implementation, a compiler or static analysis tool is used to scan the source code of the target function library, identify all call instructions, and record their call start function and call destination function. By accurately identifying the call relationship between functions, the grouping of the function library can be organized more reasonably, ensuring that the locality of function calls is optimized, thereby possibly reducing the execution time and memory usage of the program.

[0068] Step S102: If the function types of the calling start function and the calling target function are both accelerator functions, the target function library and the function library where the calling target function is located are divided into the same function library group.

[0069] After identifying the call start function and the call destination function, check the metadata or annotations of the call start function and the call destination function to determine whether the call start function and the call destination function are both accelerator functions. If so, group the function libraries where they are located into the same group. By grouping accelerator functions with the same functions into the same group, these function libraries can more effectively utilize hardware acceleration or other optimization measures when compiling or linking, improving the overall performance of the program. Through reasonable grouping, the jump distance between function libraries can be reduced, avoiding call failures in shared instruction space accelerators.

[0070] Step S20, statically linking the function libraries within the multiple function library groups to obtain respective static link files of the multiple function libraries.

[0071] When the program is compiled, the required library files are directly embedded into the final executable file, so that the final executable file contains all the necessary code.

[0072] The process of using a static linker to link all function libraries in the same function library group into a static link file is not limited here and can be set according to actual needs and system architecture. For example, you can use the static link option of the compiler, such as using gcc (a compiler) in the Linux system to compile the function library and the main program into a single executable file; or set the project properties in the IDE (Integrated Development Environment) to specify the library that needs to be statically linked, so that the IDE automatically handles the static link during the build process.

[0073] Static linking can reduce runtime loading time because all necessary code is already included in the executable file, and it can also avoid version conflict problems.

[0074] Step S30, dynamically linking each of the static link files to obtain a dynamic link library.

[0075] Dynamic linking: Library files are dynamically loaded and linked as needed when the program is running, rather than being statically embedded at compile time.

[0076] Use a dynamic linker to convert the generated static link files into dynamic link libraries, which are loaded and linked when the program is running. Dynamic linking provides greater flexibility, allowing individual modules to be updated without recompiling the entire program, while also supporting a plug-in architecture that facilitates functional expansion and customization. The flexibility of dynamic linking is critical to the Python language, especially when it is necessary to call libraries running on accelerators. Python is an interpreted language that does not usually interact directly with hardware accelerators. However, through dynamic link libraries, Python can communicate with these accelerators efficiently. Dynamic link libraries allow Python to dynamically load and link to code on the accelerator at runtime, which means that Python programs can take advantage of the computing power provided by the accelerator without stopping or restarting. This instant loading and linking mechanism allows Python to easily integrate and utilize the latest algorithms and functions on the accelerator without recompiling the entire program. In addition, the use of dynamic link libraries also simplifies the interface design between Python and accelerators. Developers can call complex accelerator functions by writing concise Python code, thereby improving development efficiency and program maintainability. This flexibility and ease of use make Python one of the preferred languages ​​for interacting with hardware accelerators in fields such as scientific computing, data analysis, and machine learning.

[0077] In the present embodiment, by dividing each function library with limited calling distance into the same group, statically linking the function libraries in the same group, the static linking can merge these libraries into a single static link file, and the libraries inside each static link file have been closely combined together through static linking, and the jump distance between libraries in the same function library group is limited to a smaller range, thereby reducing the jump distance between function libraries and avoiding the situation of call failure in the shared instruction space accelerator. At the same time, each static link file is dynamically linked to form a dynamic link library. Since these static link files have merged the codes of the function libraries in the group, the call between the static link files can be realized by the jump inside the dynamic link library without crossing the entire address space, thereby reducing the jump distance between function libraries and avoiding the situation of call failure in the shared instruction space accelerator.

[0078] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the first embodiment can be referred to the above description, and will not be described in detail later. On this basis, the step S20: statically linking the function libraries within the multiple function library groups to obtain the static link files of the multiple function libraries includes steps S201 to S203:

[0079] Step S201, for any target function library group among the multiple function library groups, input the library files of each function library in the target function library group into a static linker, merge multiple segments with the same attributes in each of the library files into a target segment through the static linker, and copy each of the target segments to a preset target file to obtain a merged file.

[0080] It should be noted that the static linker is a linker tool used to link multiple target files or library files into a single executable file or library file. Library files are files containing compiled code that can be called by other programs. In executable files, segments are areas in memory allocated to specific types of data, such as code segments, data segments, etc. The target segment is a single memory area formed by merging multiple segments with the same attributes during the linking process.

[0081] The preset target file is a binary file used to store the merged target segments during the linking process. It can be understood that the target file can be used as the main program used during the linking process, and the file does not contain any content. The merged file is a file containing all target segments and is an intermediate product of the linking process.

[0082] The static linker first allocates contiguous memory space for the merged segments. For example, all .text code segments will be merged into a new larger .text segment, and similarly, all .data data segments will be merged into a new .data segment.

[0083] In a feasible implementation manner, before the step of statically linking the function libraries within the multiple function library groups to obtain the static link files of the multiple function libraries, the following may also be included:

[0084] Step A01, creating an empty source file, and using the empty source file as a statically linked main program;

[0085] It should be noted that in the static linking process, a main program or main file is usually required as the starting point or container for the link. The main program itself may not contain any actual code or data, but it provides a framework or structure that allows the linker to merge the code and data in other target files or library files into this framework. It can be understood that by creating an empty source file and using it as the static link main program, unnecessary code and data interference in the linking process is avoided, making the linking process more efficient.

[0086] In this implementation manner, the step of copying each of the target segments to a preset target file to obtain a merged file includes:

[0087] Step S2011, copy each of the target segments to the statically linked main program to obtain a merged file.

[0088] After the static linker merges the same attribute segments in the library files of multiple function libraries into target segments, these target segments need to be copied to the blank static link main program to form the final static link file. By copying these target segments to the static link main program, a new file (i.e., the merged file) containing all necessary code and data is constructed. The merged file is an intermediate product of the static link process and the basis for subsequent steps (such as generating the final executable file or library file).

[0089] Step S202, parsing each of the library files through the static linker to obtain each of the symbols in the library files, searching for each of the actual memory addresses of the symbols in the target end through the static linker, and constructing a static symbol table based on each of the actual memory addresses of the symbols and the symbols through the static linker.

[0090] In programming, symbols usually refer to the names of variables, functions, etc., which are used to refer to them in the code. The static symbol table refers to a table containing all symbols and their memory addresses during the static linking process.

[0091] The static linker first reads the metadata in the library file and identifies all symbol definitions and references. Then the static linker assigns a memory address to each symbol in the merged library file. The static linker creates a table based on the memory address of each symbol. This table will be used to quickly find the address of the symbol when the program is executed.

[0092] Step S203, packaging the merged file and the static symbol table into an executable file through the static linker, and using the packaged executable file as the static link file corresponding to the target function library group.

[0093] It should be noted that the code and data in all library files are merged into one file in a certain format, and this file is called the merged file.

[0094] The static linker uses the merged file and the static symbol table to generate the final executable file. During this process, the linker ensures that all symbol references are correctly resolved and point to the correct memory address. The final executable file contains all the necessary code and resources as a static link file. The static link file can run independently without the need for additional library files.

[0095] It should be noted that the generated executable file does not depend on external library files and can run on a system that does not have the corresponding library installed. Developers only need to distribute a single executable file without worrying about library version issues in the user's system. Static linking reduces exposure to external dependencies and helps protect the security of the program.

[0096] In a feasible implementation, the step S30: dynamically linking each of the static link files to obtain a dynamic link library, includes steps S301 to S303:

[0097] Step S301, input each of the static link files into a dynamic linker, and allocate a space address to each of the static link files through the dynamic linker.

[0098] It should be noted that the dynamic linker is part of the operating system and is responsible for linking dynamic libraries to the program when the program is running. The space address is the location allocated to the program or library in the memory, which is used to store the code and data in the static link file.

[0099] The dynamic linker allocates an address space in memory for each statically linked file. This address space is the base address when the program is running.

[0100] Step S302: read each symbol in each static link file through the dynamic linker, and relocate each symbol based on the spatial address of each static link file to obtain dynamic address information of each symbol.

[0101] Address relocation refers to the process of converting symbolic references in the code to actual memory addresses when the program is loaded into memory. Dynamic address information is the actual address information of the symbol in memory, which is determined by the dynamic linker when the program is running. The dynamic linker reads the symbol information in the static link file and relocates the symbol according to the assigned memory address to ensure that the symbolic references in the program point to the correct memory location.

[0102] Step S303: Generate a dynamic symbol table based on the symbols and the dynamic address information of the symbols, and add the dynamic symbol table to a preset shared library to obtain a dynamic link library.

[0103] The dynamic symbol table is a table containing all dynamic address information, which is used to resolve symbol references at runtime. A shared library is a library file that can be shared between multiple dynamically linked programs.

[0104] The dynamic linker generates a dynamic symbol table based on the dynamic address information of the symbol. This table records the runtime addresses of all symbols. The dynamic symbol table is added to the shared library to create a dynamic link library, which can be loaded and linked when the program is running.

[0105] It is understandable that the addresses assigned by the dynamic linker allow the same library to be used in different programs without being unable to use it due to address conflicts. Multiple programs can share the same memory copy of the library file, reducing memory usage.

[0106] In a feasible implementation, if there is a function library from the packaged compiler, the step S30: dynamically linking each of the static link files to obtain a dynamic link library, further includes:

[0107] Step S304, dynamically linking each of the static link files using a non-encapsulated compiler to obtain a basic link library.

[0108] The packaged compiler refers to the compiler and its related toolchain, which are packaged together for easy distribution and use. The basic link library is an intermediate library formed by linking multiple static link files during the dynamic link process, which serves as the basis for further linking.

[0109] The code and data in the static link file are merged through the non-encapsulated compiler to generate a basic link library to facilitate the subsequent dynamic link process.

[0110] Step S305, linking the function library from the packaged compiler to the basic link library to obtain a dynamic link library.

[0111] The packaged compiler will link additional libraries. In this implementation, the additional function library linked by the packaged compiler is linked with the basic link library, which may include address relocation, symbol resolution and other steps, and finally generate a dynamic link library that can be loaded by the program at runtime.

[0112] In this implementation, the process of dynamically linking the static link file and dynamically linking the function library from the packaged compiler and the basic link library can refer to the specific implementation process of steps S301 to S303, which will not be described in detail here.

[0113] It is understandable that by creating a basic link library and then linking the encapsulated compiler-linked function library with the basic link library, it is possible to prevent linking these additional linked function libraries from interfering with the static link process, thereby improving the correctness of the static link process.

[0114] For example, in order to help understand the present embodiment obtained by combining the above-mentioned embodiment 1 and embodiment 2, in the present embodiment, the function library linking process is generally divided into three steps:

[0115] 1. Group the linked libraries (that is, divide multiple function libraries into multiple function library groups, wherein the calling distance between the first function library and at least one second function library in the same function library group is limited, and the calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is the function library other than the first function library among the function libraries in the same function library group). This embodiment first finds out the libraries whose jump distance is limited when calling each other, and divides these libraries into groups. For example, if the calling between library A and library B is limited, and the calling between library C and library D is limited, then A and B are grouped into one group, and C and D are grouped into another group. Grouping is performed according to the following principles: a. Restricted calls should not cross groups; b. The libraries included in each group should be as small as possible. Please refer to Figure 3 As shown in the schematic diagram of the grouping scenario, this embodiment automatically traverses the instructions of all calling classes in the linked library, analyzes the function signatures of the calling function and the calling destination function, and analyzes from the function signatures whether the calling function and the destination function are CPU functions or accelerator functions, respectively. If both the calling function and the destination function are accelerator functions, the jump of this call is restricted. This embodiment marks the library where the calling function is located and the library where the destination function is located as a group. If at least one of the calling function or the destination function is a CPU function, the jump distance of this call is not restricted and the library is not marked. This embodiment uses a union-find algorithm to merge the above-mentioned marked libraries. Please refer to Figure 4In the schematic diagram of the merge scenario shown, if there are library A, library B, and library C, where library A and library B have been marked as a group, and library B and library C have also been marked as a group, then the marks are merged into library A, library B, and library C are all in one group. The merge is automatically repeated until no new merge can be performed.

[0116] 2. Link the libraries in each group in a static linking manner (that is, statically link the function libraries within the multiple function library groups to obtain the static link files of the multiple function libraries). After grouping, this embodiment links the libraries in each group together in a static linking manner. The specific method is: first create an empty source file as the main program used for linking. The file does not contain any content and is only used to meet the requirement that the compiler must have a main program when linking. Subsequently, call the compiler to statically link each library in the group to the main program. Please refer to Figure 5 The static link diagram shown in FIG. 1 shows that when statically linking, the encapsulated compiler (compiler wrapper) needs to be specially processed. When developing an artificial intelligence program, in addition to using the compiler directly, the encapsulated compiler is also used to automatically set related functions during compilation. For example, the encapsulated compiler mpicc is used to automatically enable the MPI communication library function during compilation. However, the encapsulated compiler will additionally link some libraries during linking, for example, mpicc will automatically link libmpi. When linking the libraries in each group, this embodiment will turn off this function to avoid introducing libraries that are not desired to be introduced into the group. These libraries will be postponed until the last dynamic link to be linked.

[0117] 3. Link each group in a dynamic linking manner (that is, dynamically link each of the static link files to obtain a dynamic link library). In this embodiment, the linking results of each group are linked together in the form of dynamic linking to meet the Python language's requirements for dynamic linking. When performing dynamic linking, the library from the packaged compiler that is disabled during static linking will be supplemented.

[0118] This embodiment avoids long call jump distances between libraries on the accelerator through group linking; automatically selects appropriate groups by analyzing the call relationships in the linked libraries; implements group linking by establishing an empty main program and performing special processing on the packaged compiler; combines static linking with dynamic linking to implement group linking while meeting the Python language's requirements for dynamic linking.

[0119] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the function library linking method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.

[0120] This application also provides a function library linking device, please refer to Figure 6 , the function library linking device comprises:

[0121] A grouping module 10 is used to divide a plurality of function libraries into a plurality of function library groups, wherein a calling distance between a first function library and at least one second function library in the same function library group is limited, and a calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library other than the first function library among the function libraries in the same function library group;

[0122] A static link module 20, used for statically linking the function libraries in the plurality of function library groups to obtain respective static link files of the plurality of function libraries;

[0123] The dynamic link module 30 is used to dynamically link each of the static link files to obtain a dynamic link library.

[0124] Optionally, the grouping module 10 is further configured to:

[0125] For any target function library among the multiple function libraries, if there is a call class instruction in the target function library, traverse each of the call class instructions in the target function library to determine a call start function and a call destination function of the call class instruction, wherein the call start function is a function where the call class instruction calls and a function where the call destination of the call class instruction calls;

[0126] If the function types of the calling start function and the calling target function are both accelerator functions, the target function library and the function library where the calling target function is located are divided into the same function library group.

[0127] Optionally, the static link module 20 is further used for:

[0128] For any target function library group among the plurality of function library groups, library files of each function library in the target function library group are input into a static linker, multiple segments with the same attributes in each library file are merged into a target segment through the static linker, and each target segment is copied to a preset target file to obtain a merged file;

[0129] Parsing each of the library files by the static linker to obtain each of the symbols in the library files, searching for each of the actual memory addresses of the symbols in the target end by the static linker, and constructing a static symbol table by the static linker based on each of the actual memory addresses of the symbols and the symbols;

[0130] The merged file and the static symbol table are packaged into an executable file through the static linker, and the packaged executable file is used as the static link file corresponding to the target function library group.

[0131] Optionally, the device is also used for:

[0132] Creating an empty source file, and using the empty source file as a statically linked main program;

[0133] The static link module 20 is also used for:

[0134] Copy each of the target segments to the statically linked main program to obtain a merged file.

[0135] Optionally, the dynamic link module 30 is further used for:

[0136] Inputting each of the static link files into a dynamic linker, and allocating a space address to each of the static link files through the dynamic linker;

[0137] Reading each symbol in each of the static link files through the dynamic linker, and relocating each symbol based on the spatial address of each of the static link files to obtain dynamic address information of each symbol;

[0138] A dynamic symbol table is generated based on the various symbols and the dynamic address information of the various symbols, and the dynamic symbol table is added to a preset shared library to obtain a dynamic link library.

[0139] Optionally, the dynamic link module 30 is further used for:

[0140] Dynamically linking each of the static link files through a non-encapsulated compiler to obtain a basic link library;

[0141] The function library from the packaged compiler is linked to the basic link library to obtain a dynamic link library.

[0142] The function library linking device provided by the present application adopts the function library linking method in the above embodiment, which can solve the technical problem of the failure of the shared instruction space accelerator call. Compared with the prior art, the beneficial effects of the function library linking device provided by the present application are the same as the beneficial effects of the function library linking method provided by the above embodiment, and other technical features in the function library linking device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0143] The present application provides a function library linking device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the function library linking method in the above-mentioned embodiment.

[0144] Reference below Figure 7 , which shows a schematic diagram of the structure of a function library linking device suitable for implementing the embodiment of the present application. The function library linking device in the embodiment of the present application may include but is not limited to mobile terminals such as servers, mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The function library linking device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0145] like Figure 7As shown, the function library linking device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the function library linking device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. Communication device 1009 can allow the library linking device to communicate wirelessly or wired with other devices to exchange data. Although the library linking device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or less systems can be implemented or have alternatively.

[0146] It should be noted that the function library linking device may include an artificial intelligence tensor accelerator or may not include an artificial intelligence tensor accelerator, and this is not limited here. When the function library linking device includes an artificial intelligence tensor accelerator, after the function library linking device executes the function library linking method in the above embodiment, the program obtained by executing the function library linking method can be directly run on the artificial intelligence tensor accelerator; when the function library linking device does not include an artificial intelligence tensor accelerator, the program obtained by executing the function library linking method can be sent to a device deployed with an artificial intelligence tensor accelerator, and the program obtained by executing the function library linking method can be run on the device deployed with the artificial intelligence tensor accelerator.

[0147] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0148] The function library linking device provided by the present application adopts the function library linking method in the above embodiment, which can solve the technical problem of the failure of the shared instruction space accelerator call. Compared with the prior art, the beneficial effects of the function library linking device provided by the present application are the same as the beneficial effects of the function library linking method provided by the above embodiment, and the other technical features in the function library linking device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0149] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0150] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0151] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the function library linking method in the above-mentioned embodiment.

[0152] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0153] The computer-readable storage medium may be included in the function library linking device; or may exist independently without being assembled into the function library linking device.

[0154] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by a library linking device, the library linking device: divides multiple function libraries into multiple library groups, wherein the calling distance between a first function library and at least one second function library in the same library group is limited, and the calling distance between function libraries in different library groups is not limited, the first function library is any one of the function libraries in the same library group, and the second function library is a function library other than the first function library in the function libraries in the same library group; statically links the function libraries in the multiple library groups to obtain static link files of the multiple library groups; and dynamically links the static link files to obtain dynamic link libraries.

[0155] Computer program codes for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, conventional procedural programming languages, such as "C" or similar programming languages, special programming languages ​​required for writing programs running on artificial intelligence tensor accelerators, special variants of mainstream programming languages ​​for artificial intelligence tensor accelerators, etc. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0156] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0157] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0158] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned function library linking method, and can solve the technical problem of failure to call the shared instruction space accelerator. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the function library linking method provided by the above-mentioned embodiment, and will not be repeated here.

[0159] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned function library linking method when executed by a processor.

[0160] The computer program product provided by the present application can solve the technical problem of failure to call a shared instruction space accelerator. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the function library linking method provided by the above embodiment, which will not be repeated here.

[0161] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A function library linking method, characterized in that: The function library linking method comprises: Divide a plurality of function libraries into a plurality of function library groups, wherein a calling distance between a first function library and at least one second function library in the same function library group is limited, and a calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library among the function libraries in the same function library group except the first function library; Static linking the function libraries in the multiple function library groups respectively to obtain static link files of the multiple function libraries; The static link files are dynamically linked to obtain a dynamic link library.

2. The function library linking method according to claim 1, characterized in that: The step of dividing the multiple function libraries into multiple function library groups includes: For any target function library among the multiple function libraries, if there is a call class instruction in the target function library, traverse each of the call class instructions in the target function library to determine a call start function and a call destination function of the call class instruction, wherein the call start function is a function where the call class instruction calls and a function where the call destination of the call class instruction calls; If the function types of the calling start function and the calling target function are both accelerator functions, the target function library and the function library where the calling target function is located are divided into the same function library group.

3. The function library linking method according to claim 1, characterized in that: The step of statically linking the function libraries within the multiple function library groups to obtain the static link files of the multiple function libraries respectively comprises: For any target function library group among the plurality of function library groups, library files of each function library in the target function library group are input into a static linker, multiple segments with the same attributes in each library file are merged into a target segment through the static linker, and each target segment is copied to a preset target file to obtain a merged file; Parsing each of the library files by the static linker to obtain each of the symbols in the library files, searching for each of the actual memory addresses of the symbols in the target end by the static linker, and constructing a static symbol table by the static linker based on each of the actual memory addresses of the symbols and the symbols; The merged file and the static symbol table are packaged into an executable file through the static linker, and the packaged executable file is used as the static link file corresponding to the target function library group.

4. The function library linking method according to claim 3, characterized in that: Before the step of statically linking the function libraries within the plurality of function library groups to obtain the respective static link files of the plurality of function libraries, the method further comprises: Creating an empty source file, and using the empty source file as a statically linked main program; The step of copying each of the target segments to a preset target file to obtain a merged file comprises: Copy each of the target segments to the statically linked main program to obtain a merged file.

5. The function library linking method according to claim 1, characterized in that: The step of dynamically linking each of the static link files to obtain a dynamic link library comprises: Inputting each of the static link files into a dynamic linker, and allocating a space address to each of the static link files through the dynamic linker; Reading each symbol in each of the static link files through the dynamic linker, and relocating each symbol based on the spatial address of each of the static link files to obtain dynamic address information of each symbol; A dynamic symbol table is generated based on the various symbols and the dynamic address information of the various symbols, and the dynamic symbol table is added to a preset shared library to obtain a dynamic link library.

6. The function library linking method according to any one of claims 1 to 5, characterized in that: If there is a function library from the packaged compiler, the step of dynamically linking each of the static link files to obtain a dynamic link library also includes: Dynamically linking each of the static link files through a non-encapsulated compiler to obtain a basic link library; The function library from the packaged compiler is linked to the basic link library to obtain a dynamic link library.

7. A function library linking device, characterized in that: The function library linking device comprises: a grouping module, used for dividing a plurality of function libraries into a plurality of function library groups, wherein a calling distance between a first function library and at least one second function library in the same function library group is limited, and a calling distance between function libraries in different function library groups is not limited, the first function library is any function library among the function libraries in the same function library group, and the second function library is a function library among the function libraries in the same function library group except the first function library; A static link module, used for statically linking the function libraries in the multiple function library groups to obtain respective static link files of the multiple function libraries; The dynamic link module is used to dynamically link each of the static link files to obtain a dynamic link library.

8. A function library linking device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the function library linking method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the function library linking method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the function library linking method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Performance detection method and device for heterogeneous acceleration program and storage medium

    CN116126669A

  • Data processing method, scanner, electronic equipment and storage medium

    CN118484179A

  • Method for managing programmable logic circuits for applications invoking dynamic libraries

    US20190286779A1

  • Dynamically overriding a function based on a capability set during load time

    WO2023154092A1

Cited By

  • Dynamic link call conversion method and device

    CN120123023A