Code library packaging method and device, program compiling method and device, equipment and medium

By compiling the library functions of each interface in the code base of heterogeneous computing devices into intermediate representations and encrypting, the problem of the inability to meet the development efficiency and security in the prior art is solved, and the security and efficiency of the code base are achieved.

CN120122953APending Publication Date: 2025-06-10KUNLUNXIN TECHNOLOGY (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510186248.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-19
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

The existing heterogeneous computing device code library packaging method cannot meet the efficiency and security of development at the same time.

Method used

By compiling the library functions of each interface in the code library of heterogeneous computing devices into intermediate representation forms and encrypting the intermediate representation files, an encrypted library is obtained, and each interface in the code library is encapsulated based on the encryption library.

Benefits of technology

It realizes the security of the code base, while retaining the original optimization attributes and information of the interface file, taking into account efficiency, and achieving the goal of being both easy to develop and safe and efficient.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120122953A_ABST
    Figure CN120122953A_ABST
Patent Text Reader

Abstract

The invention provides a code library packaging method and device, a program compiling method and device, equipment and a medium, and relates to the technical field of heterogeneous computing, in particular to artificial intelligence and chip technologies. The code library packaging method comprises the steps that library functions of all interfaces in a code library of heterogeneous computing equipment are compiled into an intermediate representation form, an intermediate representation file is obtained, and the intermediate representation file is used for recording optimization attributes and algorithm logic of the library functions; encrypting the intermediate representation file to obtain an encrypted library; and packaging each interface in the code library based on the encryption library. The program compiling method comprises the following steps: reading an encryption library into a memory, and decrypting the encryption library in the memory to obtain an intermediate representation file of a library function of each interface; and compiling a device code of a user and the intermediate representation file of the library function of each interface to obtain a heterogeneous execution program, the device code including calling of the library function of each interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of heterogeneous computing technologies, particularly to artificial intelligence and chip technologies, and specifically to a method for encapsulating a code library, a method for program compilation, a device, a device, and a medium. Background Art

[0002] With the rise of modern computing tasks such as artificial intelligence and deep learning, the demand for computing performance has also become increasingly high. Heterogeneous computing has significant advantages in energy efficiency optimization, development flexibility, and scalability, and has been widely promoted and used. In order to utilize the advantages of different hardware units of heterogeneous computing, it is necessary to develop the code of heterogeneous computing devices and build a code library for heterogeneous computing devices.

[0003] During the process of building a code library for heterogeneous computing devices, the encapsulation method of device interfaces is involved. However, the existing encapsulation methods cannot simultaneously meet the requirements of development efficiency and security. Summary of the Invention

[0004] The present disclosure provides a method for encapsulating a code library, a method for program compilation, a device, a device, and a medium.

[0005] According to one aspect of the present disclosure, there is provided a method for encapsulating a code library for a heterogeneous computing device, including:

[0006] Compiling library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, where the intermediate representation file is used to record optimization attributes and algorithm logics of the library functions;

[0007] Encrypting the intermediate representation file to obtain an encrypted library;

[0008] Encapsulating each interface in the code library based on the encrypted library.

[0009] According to another aspect of the present disclosure, there is provided a method for compiling a program for a heterogeneous computing device, including:

[0010] Reading an encrypted library into a memory, where the encrypted library is obtained by compiling library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file and encrypting the intermediate representation file; each interface in the code library is encapsulated based on the encrypted library;

[0011] Decrypting the encrypted library in the memory to obtain the intermediate representation file of the library functions of each interface;

[0012] Compile the device code of the user and the intermediate representation files of the library functions of the respective interfaces to obtain a heterogeneous execution program, where the device code includes calls to the library functions of the respective interfaces.

[0013] According to another aspect of the present disclosure, there is provided a code library encapsulation device for a heterogeneous computing device, including:

[0014] An intermediate representation compilation module, configured to compile the library functions of the respective interfaces in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, where the intermediate representation file is used to record the optimization attributes and algorithm logic of the library functions;

[0015] An encryption module, configured to encrypt the intermediate representation file to obtain an encrypted library;

[0016] An encapsulation module, configured to encapsulate the respective interfaces in the code library based on the encrypted library.

[0017] According to another aspect of the present disclosure, there is provided a program compilation device for a heterogeneous computing device, including:

[0018] A reading module, configured to read the encrypted library into the memory, where the encrypted library is obtained by compiling the library functions of the respective interfaces in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file and encrypting the intermediate representation file; the respective interfaces in the code library are encapsulated based on the encrypted library;

[0019] A decryption module, configured to decrypt the encrypted library in the memory to obtain the intermediate representation file of the library functions of the respective interfaces;

[0020] An execution program compilation module, configured to compile the device code of the user and the intermediate representation file of the library functions of the respective interfaces to obtain a heterogeneous execution program, where the device code includes calls to the library functions of the respective interfaces.

[0021] According to another aspect of the present disclosure, there is provided an electronic device, including:

[0022] At least one processor; and

[0023] A memory communicatively connected to the at least one processor; where

[0024] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the code library encapsulation method for a heterogeneous computing device and the program compilation method for a heterogeneous computing device according to any embodiment of the present disclosure.

[0025] According to another aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the code library encapsulation method for heterogeneous computing devices and the program compilation method for heterogeneous computing devices described in any embodiment of the present disclosure.

[0026] According to another aspect of the present disclosure, there is provided a computer program product including a computer program which, when executed by a processor, implements the code library encapsulation method for heterogeneous computing devices and the program compilation method for heterogeneous computing devices described in any embodiment of the present disclosure.

[0027] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it used to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The drawings are used to better understand the solution and do not constitute a limitation to the present disclosure. Among them:

[0029] Figure 1 is a schematic diagram of a code library encapsulation method for heterogeneous computing devices according to an embodiment of the present disclosure;

[0030] Figure 2 is a schematic diagram of a program compilation method for heterogeneous computing devices according to an embodiment of the present disclosure;

[0031] Figure 3 is a flowchart of code library encapsulation and usage processing for heterogeneous computing devices according to an embodiment of the present disclosure;

[0032] Figure 4 is a schematic diagram of a code library encapsulation device for heterogeneous computing devices according to an embodiment of the present disclosure;

[0033] Figure 5 is a schematic diagram of a program compilation device for heterogeneous computing devices according to an embodiment of the present disclosure;

[0034] Figure 6 is a block diagram of an electronic device for implementing the code library encapsulation method for heterogeneous computing devices according to an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0035] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0036] In the process of building a heterogeneous computing device code library, there are usually two processing methods in the prior art to encapsulate the device interface: the first method is to provide a builtin built-in function interface in the compiler, by adding additional builtin functions in the compiler, and lowering these functions to the underlying hardware instructions during the compilation process, that is, converting these functions into underlying machine instructions or assembly code. However, this builtin encapsulation method requires the complete definition of all interfaces and the above-mentioned lowering process to be implemented inside the compiler, which requires a large amount of compiler development. When the number of interfaces is large, this method has a large time cost; the second method is device library encapsulation, including encapsulation and provision to users in two specific ways: binary library or source code library. Among them, the binary device library provides the interface in the form of binary function, cannot perform compilation optimization such as inlining, and has function call overhead; while the source code library is directly provided to the user in the form of source code, directly exposing the specific implementation of the interface internally, and there is no guarantee in terms of security. It can be seen that the existing encapsulation methods cannot simultaneously meet the efficiency and security of development.

[0037] The present disclosure aims to solve the problem that the current heterogeneous computing device code library cannot have both efficiency and security, and proposes a code library encapsulation method, program compilation method, device, equipment and medium. The method compiles the library functions of the device code library into an intermediate representation, encrypts the obtained intermediate representation file, and encapsulates each interface in the code library based on the encryption library, that is, the encryption library is used as an interface library for users. In this way, not only the security of the library is guaranteed, but also the original optimization properties and information of the interface file are retained, taking into account efficiency, thereby achieving the goal of being easy to develop, safe and efficient.

[0038] Figure 1 The present invention is a schematic diagram of a code base packaging method for heterogeneous computing devices according to an embodiment of the present invention. This embodiment can be applied to the case of packaging the code base of heterogeneous computing devices, and relates to the field of heterogeneous computing technology, especially artificial intelligence and chip technology. The method can be executed by a code base packaging device for heterogeneous computing devices, which is implemented in software and / or hardware, and is preferably configured in an electronic device, such as a computer device or a server. Figure 1 As shown, the method specifically includes the following:

[0039] S101. Compile the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, where the intermediate representation file is used to record the optimization attributes and algorithm logic of the library functions.

[0040] S102. Encrypt the intermediate representation file to obtain an encrypted library.

[0041] S103. Package each interface in the code library based on the encrypted library.

[0042] Among them, the code library is pre-developed and built by developers. The way to develop the code library is the same as that of developing ordinary device operators, and each interface corresponds to a library function.

[0043] Specifically, the writing method of the library function can be determined by the programming model and syntax provided by the compiler. For example, in most heterogeneous computing compilers, usually the extended C / C++ language is used as the development language. In this case, only the actual logic of implementing the interface according to C / C++ needs to be followed. Therefore, from the perspective of development, it is very easy for interface writers to get started, ensuring high development efficiency.

[0044] At the same time, inside the interface library function, the optimal implementation algorithm and strategy can also be selected according to the characteristics of the running device to implement the interface. For example, the interface can be implemented and optimized from the perspectives of task division, memory storage hierarchy selection, and computing memory access parallelism, so as to improve the interface performance. When the performance requirement of the interface is relatively high, inline assembly control instructions can also be directly written for optimization, and this is more flexible and simpler than the above Builtin packaging method.

[0045] In addition, in order to avoid the call overhead of the interface function and perform specific optimizations for specific interfaces, various compilation optimization attributes can also be added when implementing the interface library function. For example, when the interface function is simple, __attribute__((always_inline)) can be used to tell the compiler to perform inlining for this interface, effectively avoiding the function call overhead compared with the above binary library packaging method.

[0046] After the code base is built, it needs to be compiled, that is, the library functions of each interface in the code base are compiled into an intermediate representation to obtain an intermediate representation file. Among them, the intermediate representation file is used to record the optimization properties and algorithm logic of the library function. Intermediate Representation (IR) is an abstract representation that can record the optimization properties and algorithm logic of the library function, which is easy to parse and optimize. The optimization properties of the library function include at least the optimization properties of inlining the interface and the compilation optimization properties. Therefore, compared with the encapsulation method of the binary library, compilation optimizations such as inlining can be performed, thereby reducing the function call overhead.

[0047] In one embodiment, the library functions of each interface in the code library of the heterogeneous computing device are compiled into an intermediate representation to obtain an intermediate representation file, including: separately compiling the library functions of each interface in the code library of the heterogeneous computing device to obtain the intermediate representation of the library functions of each interface; merging the intermediate representations of the library functions of each interface to obtain the intermediate representation file.

[0048] Specifically, for device library files developed using modularization, each file can be independently compiled into an intermediate representation file, and then these files can be aggregated into a single file using a specific tool. The library function can be compiled into an intermediate representation using an encoder, or other conversion tools can be used.

[0049] In addition, during the compilation process, you can also perform compilation optimization on the device library file as needed to reduce redundant code.

[0050] The compiled intermediate representation file is an unencrypted file. In order to prevent users from using tools to convert it and thus expose the internal implementation of the interface function code, the intermediate representation file is further encrypted in the disclosed embodiment to obtain an encryption library, and then the interfaces in the code library are encapsulated based on the encryption library. In other words, the device library provided to external users is a library processed by an encryption algorithm, so that users cannot parse its real content, which ensures the security of the device library and avoids the leakage of important parameters or instructions of the chip. Among them, the disclosed embodiment does not impose any restrictions on the encryption algorithm.

[0051] The technical solution of the disclosed embodiment aims at the problem that the current heterogeneous computing device code library cannot have both efficiency and security. By developing in the form of a device code library, the library functions in the code library are compiled into an intermediate representation, ensuring the efficiency of programming interface development. At the same time, the intermediate representation file is encrypted and used as an interface library for users, ensuring the security of the library, and retaining the original optimization properties and information of the interface file, taking into account efficiency, thereby achieving the goal of being easy to develop, safe and efficient.

[0052] Figure 2 It is a schematic diagram of a program compilation method for heterogeneous computing devices according to an embodiment of the present disclosure. This embodiment is applicable to the situation of compiling heterogeneous execution programs for heterogeneous computing devices. Among them, the code library of the heterogeneous computing device is encapsulated according to the method described in the above embodiment, which relates to the field of heterogeneous computing technology, especially artificial intelligence and chip technology. This method can be executed by a program compilation device for heterogeneous computing devices, and this device is implemented in a software and / or hardware manner, preferably configured in an electronic device, such as a computer device or a server equipped with a compiler. As Figure 2 shown, this method specifically includes the following:

[0053] S201. Read the encrypted library into the memory. Among them, the encrypted library is obtained by compiling the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, and then encrypting the intermediate representation file; each interface in the code library is encapsulated based on the encrypted library.

[0054] S202. Decrypt the encrypted library in the memory to obtain the intermediate representation file of the library functions of each interface.

[0055] S203. Compile the user's device code and the intermediate representation file of the library functions of each interface to obtain a heterogeneous execution program, where the device code includes calls to the library functions of each interface.

[0056] Among them, the encrypted library is obtained by compiling the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, and then encrypting the intermediate representation file according to the code library encapsulation method provided by the embodiment of the present disclosure. And the encrypted library is provided to the user as the encapsulation interface of the heterogeneous device code library. When the user writes their own device code, they only need to include the appropriate header files to directly use / call the library functions of each interface in the encrypted library. Then use the compiler to compile the encrypted library and the device code developed by the user together.

[0057] During the compilation process, the compiler first obtains the path of the file system where the encrypted library is located, and reads the encrypted library into the memory according to this path. Then, decrypt the encrypted library in the memory to obtain the intermediate representation file of the library functions of each interface. That is to say, all decryption processes are carried out inside the compiler to prevent the decrypted code library from being captured by the user.

[0058] After decryption, the compiler can compile the user's device code and the intermediate representation files of the library functions of each interface to obtain a heterogeneous execution program. Since the device library code carries optimization information such as inlining, the compiler can perform cross-function optimizations, generate the overall code for the optimized code, and finally compile an efficient heterogeneous execution program.

[0059] In one implementation, compiling the user's device code and the intermediate representation files of the library functions of each interface to obtain a heterogeneous execution program includes: parsing the intermediate representation files of the library functions of each interface to obtain the first intermediate representation in the memory form of the library functions of each interface; compiling the device code into the second intermediate representation in the memory form; and compiling the first intermediate representation and the second intermediate representation to obtain a heterogeneous execution program.

[0060] Specifically, the compiler converts the intermediate representation file and the device code into the intermediate representation in the memory form, that is, in memory IR, and then performs overall program analysis and compilation optimization on the IR of the decrypted library function and the device code IR, and finally generates a heterogeneous execution program.

[0061] In the technical solution of the embodiments of the present disclosure, the compiler decrypts the encrypted library in the memory, compiles the intermediate representations of the library functions and the device code in their respective memory forms to obtain a heterogeneous execution program, introduces the decryption and parsing processes into the memory of the compiler, hides the decryption process, and is transparent to the user, which can not only optimize the program during compilation, but also ensure the security of the code library.

[0062] Figure 3 It is a flowchart of the code library encapsulation and usage processing of a heterogeneous computing device according to the embodiments of the present disclosure. In this embodiment, LLVM bitcode (an intermediate representation form independent of the target hardware platform and operating system) is used as the intermediate representation form of the code library. LLVM bitcode belongs to a higher-level intermediate representation, carries a large amount of optimization and debugging information of the source code, and is convenient for subsequent overall optimization with the user's device code. In addition, LLVM bitcode is also a compact intermediate representation. Compared with the text form of LLVM IR, bitcode occupies less storage space and is also easier to parse.

[0063] Such as Figure 3As shown, a.cpp, b.cpp, and c.cpp represent different library functions in the code library. First, compile them into bitcode files to obtain a.bc, b.bc, and c.bc, and then use the tool llvm-link to merge them to obtain the merged bitcode file lib.bc. In order to avoid users converting the file into LLVM IR, thereby exposing its internal implementation, in particular, if the implementation involves some non-public parameters or instructions of the chip, it will directly lead to information leakage, and the attacker can also spy on the architecture information of the chip, which may lead to attacks on the device, causing greater risks. Therefore, the embodiment of the present disclosure further uses any encryption algorithm to encrypt it, obtain the encrypted bitcode, that is, the encryption library lib.enc, and encapsulate the interface in the form of an encryption library. Afterwards, the encryption library is provided to the user as an interface and a compiler. When in use, the encryption library is first read by the compiler and decrypted in the memory to obtain the decrypted bitcode. Among them, it can be implemented specifically using the clang compiler which is also based on the LLVM architecture. Then, the compiler compiles and optimizes the decrypted bitcode together with the device code developed by the user to obtain the final heterogeneous execution program.

[0064] Therefore, the technical solution of the disclosed embodiment is based on the encryption and decryption strategy of the device code library, which encapsulates the user interface in the form of the LLVM bitcode library, retains optimization opportunities such as function inlining, and facilitates developers to develop interfaces. At the same time, performing encryption and decryption operations on the bitcode library ensures the security of the library and does not expose internal details to users. Compared with the existing technology, it has both efficiency and security.

[0065] Figure 4 The present invention is a schematic diagram of a code base packaging device for heterogeneous computing devices according to an embodiment of the present invention. The present invention can be applied to packaging code bases of heterogeneous computing devices, and relates to the field of heterogeneous computing technology, especially artificial intelligence and chip technology. The device can implement the code base packaging method for heterogeneous computing devices described in any embodiment of the present invention. Figure 4 As shown, the device 400 specifically includes:

[0066] An intermediate representation compiling module 401 is used to compile the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, wherein the intermediate representation file is used to record the optimization properties and algorithm logic of the library function;

[0067] An encryption module 402, used to encrypt the intermediate representation file to obtain an encryption library;

[0068] The encapsulation module 403 is used to encapsulate each interface in the code library based on the encryption library.

[0069] Optionally, the intermediate representation compilation module 401 includes:

[0070] The first compilation unit is used to separately compile the library functions of each interface in the code library of the heterogeneous computing device to obtain the intermediate representation form of the library functions of each interface;

[0071] The merging unit is used to merge the intermediate representation forms of the library functions of each interface to obtain the intermediate representation file.

[0072] Optionally, the optimization attributes of the library functions at least include the optimization attribute of performing inlining on the interface and the compilation optimization attribute.

[0073] Figure 5 FIG. is a schematic diagram of a program compilation device for a heterogeneous computing device according to an embodiment of the present disclosure. This embodiment is applicable to the case of compiling a heterogeneous execution program for a heterogeneous computing device, and among them, the code library of the heterogeneous computing device is encapsulated according to the method described in the above embodiment, relating to the field of heterogeneous computing technology, especially artificial intelligence and chip technology. This device can implement the program compilation method for a heterogeneous computing device described in any embodiment of the present disclosure. As Figure 5 shown, the device 500 specifically includes:

[0074] The reading module 501 is used to read the encryption library into the memory, where the encryption library is obtained by compiling the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file and encrypting the intermediate representation file; each interface in the code library is encapsulated based on the encryption library;

[0075] The decryption module 502 is used to decrypt the encryption library in the memory to obtain the intermediate representation file of the library functions of each interface;

[0076] The execution program compilation module 503 is used to compile the device code of the user and the intermediate representation file of the library functions of each interface to obtain a heterogeneous execution program, where the device code includes calls to the library functions of each interface.

[0077] Optionally, the execution program compilation module 503 includes:

[0078] The parsing unit is used to parse the intermediate representation file of the library functions of each interface to obtain the first intermediate representation in the memory form of the library functions of each interface;

[0079] A second compilation unit, configured to compile the device code into a second intermediate representation in the memory form;

[0080] A third compilation unit, configured to compile the first intermediate representation and the second intermediate representation to obtain the heterogeneous execution program.

[0081] Optionally, the reading module 501 includes:

[0082] A path acquisition unit, configured to acquire the path of the file system where the encryption library is located;

[0083] A reading unit, configured to read the encryption library into the memory according to the path.

[0084] The above product can execute the method provided in any embodiment of the present disclosure, and has corresponding functional modules and beneficial effects for executing the method.

[0085] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved all comply with the provisions of relevant laws and regulations and do not violate public order and good customs.

[0086] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0087] Figure 6 FIG. shows a schematic block diagram of an exemplary electronic device 600 that can be used to implement embodiments of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0088] As Figure 6 shown, the device 600 includes a computing unit 601, which can execute various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0089] Multiple components in device 600 are connected to I / O interface 605, including: input unit 606, such as a keyboard, mouse, etc.; output unit 607, such as various types of displays, speakers, etc.; storage unit 608, such as a disk, optical disc, etc.; and communication unit 609, such as a network card, modem, wireless communication transceiver, etc. Communication unit 609 allows device 600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0090] Computing unit 601 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Computing unit 601 executes the various methods and processes described above, such as the code library encapsulation method for heterogeneous computing devices. For example, in some embodiments, the code library encapsulation method for heterogeneous computing devices can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed onto device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by computing unit 601, one or more steps of the code library encapsulation method for heterogeneous computing devices described above can be executed. Alternatively, in other embodiments, computing unit 601 can be configured to execute the code library encapsulation method for heterogeneous computing devices in any other suitable manner (e.g., by means of firmware).

[0091] Various embodiments of the systems and techniques described above in this document can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor, and can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit the data and instructions to the storage system, the at least one input device, and the at least one output device.

[0092] The program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, a special purpose computer, or other programmable data processing device, such that the program codes, when executed by the processor or controller, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine, or entirely on the remote machine or server.

[0093] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0094] In order to provide interaction with a user, the systems and techniques described herein may be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0095] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.

[0096] A computer system can include a client and a server. The client and the server are generally far from each other and usually interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system, solving the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services. The server can also be a server of a distributed system, or a server combined with blockchain.

[0097] Artificial intelligence is a discipline that studies to make a computer simulate certain thinking processes and intelligent behaviors of humans (such as learning, reasoning, thinking, planning, etc.), and it has both hardware-level technologies and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include several major directions such as computer vision technology, speech recognition technology, natural language processing technology, machine learning / deep learning technology, big data processing technology, and knowledge graph technology.

[0098] Cloud computing refers to a technical system that accesses an elastic and scalable shared physical or virtual resource pool through a network. The resources can include servers, operating systems, networks, software, applications, and storage devices, etc., and the resources can be deployed and managed in a demand-based and self-service manner. Through cloud computing technology, it can provide efficient and powerful data processing capabilities for the application and model training of technologies such as artificial intelligence and blockchain.

[0099] In addition, according to the embodiments of the present disclosure, the present disclosure also provides another electronic device, another readable storage medium, and another computer program product for performing one or more steps of the program compilation method for heterogeneous computing devices described in any embodiment of the present disclosure. The specific structure and program code can be referred to asFigure 6 The content description of the illustrated embodiment will not be elaborated here.

[0100] It should be understood that various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution provided in this disclosure can be achieved, and no limitations are imposed herein.

[0101] The above specific embodiments do not constitute a limitation on the protection scope of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub - combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the protection scope of this disclosure.

Claims

1. A code base packaging method for a heterogeneous computing device, comprising: Compile the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, wherein the intermediate representation file is used to record the optimization properties and algorithm logic of the library function; Encrypting the intermediate representation file to obtain an encryption library; Each interface in the code library is encapsulated based on the encryption library.

2. The method according to claim 1, wherein: The step of compiling the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file includes: Compiling library functions of each interface in a code library of the heterogeneous computing device respectively to obtain an intermediate representation of the library functions of each interface; The intermediate representation forms of the library functions of the interfaces are merged to obtain the intermediate representation file.

3. The method according to claim 1, wherein: The optimization attributes of the library function at least include an optimization attribute for performing inlining on an interface and a compilation optimization attribute.

4. A program compiling method for a heterogeneous computing device, comprising: Reading the encryption library into the memory, wherein the encryption library is obtained by compiling the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form, obtaining an intermediate representation file, and encrypting the intermediate representation file; each interface in the code library is encapsulated based on the encryption library; Decrypting the encrypted library in the memory to obtain an intermediate representation file of the library function of each interface; The user's device code and the intermediate representation files of the library functions of the interfaces are compiled to obtain a heterogeneous execution program, wherein the device code includes calls to the library functions of the interfaces.

5. The method according to claim 4, wherein: The process of compiling the user's device code and the intermediate representation files of the library functions of the interfaces to obtain a heterogeneous execution program includes: Parsing the intermediate representation files of the library functions of the interfaces to obtain the first intermediate representations of the library functions of the interfaces in memory format; Compiling the device code into a second intermediate representation in the memory form; The first intermediate representation and the second intermediate representation are compiled to obtain the heterogeneous execution program.

6. The method according to claim 4, wherein: The step of reading the encryption library into the memory includes: Obtain the path of the file system where the encryption library is located; The encryption library is read into the memory according to the path.

7. A code library packaging device for a heterogeneous computing device, comprising: An intermediate representation compilation module is used to compile the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form to obtain an intermediate representation file, wherein the intermediate representation file is used to record the optimization properties and algorithm logic of the library function; An encryption module, used for encrypting the intermediate representation file to obtain an encryption library; The encapsulation module is used to encapsulate each interface in the code library based on the encryption library.

8. A program compiling apparatus for a heterogeneous computing device, comprising: A reading module, used to read the encryption library into the memory, wherein the encryption library is obtained by compiling the library functions of each interface in the code library of the heterogeneous computing device into an intermediate representation form, obtaining an intermediate representation file, and encrypting the intermediate representation file; each interface in the code library is encapsulated based on the encryption library; A decryption module, used for decrypting the encryption library in the memory to obtain an intermediate representation file of the library function of each interface; The execution program compiling module is used to compile the user's device code and the intermediate representation files of the library functions of the interfaces to obtain a heterogeneous execution program, wherein the device code includes calls to the library functions of the interfaces.

9. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed 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 code library encapsulation method for heterogeneous computing devices described in any one of claims 1-3, and the program compilation method for heterogeneous computing devices described in any one of claims 4-6.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable a computer to execute the code library packaging method for heterogeneous computing devices according to any one of claims 1-3, and the program compilation method for heterogeneous computing devices according to any one of claims 4-6.

11. A computer program product, comprising a computer program, which, when executed by a processor, implements the code library packaging method for heterogeneous computing devices according to any one of claims 1 to 3, and the program compilation method for heterogeneous computing devices according to any one of claims 4 to 6.