CUDA backend separation and transplantation method, device and storage medium of deep learning framework

By decoupling the CUDA backend and frontend CPU code, the problem of poor code portability in the PyTorch framework is solved, and a simplified GPU replacement process and efficient code migration are achieved.

CN121541925BActive Publication Date: 2026-05-19ZHEJIANG LAB
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ZHEJIANG LAB
Filing Date
2026-01-16
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

In the existing PyTorch framework, the CUDA backend code and the frontend CPU code are tightly coupled, which requires large-scale modifications and adaptations when changing GPUs, resulting in poor code portability.

Method used

By determining the location of the target file corresponding to CUDA in the deep learning code project, extracting and migrating it to the CUDA backend repository, decoupling the target code of the CPU and CUDA mixed files, and migrating the build script in the build configuration file, the decoupling of the CUDA backend code and the frontend CPU code is achieved.

Benefits of technology

It improves code portability, simplifies the GPU replacement process, provides a replaceable backend access foundation, and reduces the risk of modification and errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121541925B_ABST
    Figure CN121541925B_ABST
Patent Text Reader

Abstract

The application provides a CUDA backend separation transplantation method, device and storage medium of a deep learning framework, wherein the CUDA backend separation transplantation method of the deep learning framework comprises the following steps: determining the file position of a target file corresponding to CUDA in a deep learning code project, extracting the target file from the deep learning code project according to the file position, and migrating the target file to a CUDA backend repository in the same file hierarchical structure; extracting a target code corresponding to CUDA from a CPU and CUDA mixed file, and migrating the target code to a corresponding target file in the CUDA backend repository according to the implementation function of the target code; extracting a build script corresponding to CUDA from a build configuration file, and migrating the build script to a configuration file in the CUDA backend repository. Through the application, the problem of poor code portability is solved, and a replacement type backend access basis is provided for a GPU.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of deep learning frameworks, and in particular to methods, apparatus and storage media for the separate porting of CUDA backends for deep learning frameworks. Background Technology

[0002] With the rapid development of deep learning technology, the deep learning framework PyTorch has been widely used in the field of artificial intelligence. It adopts a heterogeneous computing model of CPU+GPU, in which the Compute Unified Device Architecture (CUDA) serves as the parallel computing platform and programming model for NVIDIA GPUs, and is a key technology for achieving GPU-accelerated computing.

[0003] In the existing PyTorch framework, the CUDA backend code is tightly coupled with the frontend CPU code. When it is necessary to replace the NVIDIA GPU with a domestic or third-party GPU, the entire framework needs to be modified and adapted on a large scale, which is labor-intensive and prone to errors, and has poor code portability.

[0004] There is currently no effective solution to the problem of poor code portability in related technologies. Summary of the Invention

[0005] This embodiment provides a method, apparatus, and storage medium for separating and porting the CUDA backend of a deep learning framework, in order to solve the problem of poor code portability in related technologies.

[0006] Firstly, this embodiment provides a method for separating and porting the CUDA backend of a deep learning framework, including:

[0007] Determine the file location of the target file corresponding to CUDA in the deep learning code project, extract the target file from the deep learning code project according to the file location, and migrate the target file to the CUDA backend repository with the same file hierarchy structure;

[0008] Identify the files in the deep learning code project that combine CPU and CUDA, extract the target code corresponding to CUDA from the files that combine CPU and CUDA, and migrate the target code to the corresponding target file in the CUDA backend repository according to the implementation function of the target code.

[0009] The build configuration file in the deep learning code project is determined, the CUDA corresponding build script is extracted from the build configuration file, and the build script is migrated to the configuration file in the CUDA backend repository.

[0010] In some embodiments, extracting the target file from the deep learning code project based on the file location includes:

[0011] Based on the file location, extract the corresponding target file of the CUDA backend implementation from the deep learning code project;

[0012] Based on the file location, extract the corresponding target file recorded in the build configuration file for compiling and generating the CUDA dynamic library from the deep learning code project.

[0013] In some embodiments, extracting the CUDA-corresponding target code from the CPU and CUDA-mixed file includes:

[0014] Extract the CUDA-corresponding target code from the CUDA conditional compilation macro paragraph within the file containing the CPU and CUDA mixture.

[0015] In some embodiments, the method further includes:

[0016] Configure a compiler control switch, which is used to independently compile and generate CUDA dynamic libraries.

[0017] In some embodiments, a compiler control switch is set to independently compile and generate a CUDA dynamic library, including:

[0018] When the compilation control switch is set to the on state, the CUDA backend repository is compiled and the CUDA dynamic library is generated.

[0019] When the compilation control switch is set to the off state, only the CPU front-end code is compiled to generate the CPU dynamic library.

[0020] Secondly, this embodiment provides a CUDA backend separation and porting device for a deep learning framework, including an inter-file decoupling module, an intra-file decoupling module, and a compilation and build decoupling module, wherein:

[0021] The file decoupling module is used to determine the file location of the target file corresponding to CUDA in the deep learning code project, extract the target file from the deep learning code project according to the file location, and migrate the target file to the CUDA backend repository with the same file hierarchy structure.

[0022] The file decoupling module is used to identify files in the deep learning code project that combine CPU and CUDA, extract the target code corresponding to CUDA from the files that combine CPU and CUDA, and migrate the target code to the corresponding target file in the CUDA backend repository according to the implementation function of the target code.

[0023] The compilation and build decoupling module is used to determine the build configuration file in the deep learning code project, extract the CUDA-corresponding build script from the build configuration file, and migrate the build script to the configuration file in the CUDA backend repository.

[0024] In some embodiments, the file decoupling module includes a file determination module and a file migration module, wherein:

[0025] The file determination module is used to determine the file location of the target file corresponding to CUDA in the deep learning code project;

[0026] The file migration module is used to extract the target file from the deep learning code project according to the file location, and migrate the target file to the CUDA backend repository with the same file hierarchy structure.

[0027] In some embodiments, the file determination module is implemented through a file scanning command; the file migration module is implemented through a file migration command.

[0028] Thirdly, this embodiment provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to execute the CUDA backend decoupling porting method for the deep learning framework described in the first aspect above.

[0029] Fourthly, this embodiment provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the CUDA backend separation and porting method for the deep learning framework described in the first aspect above.

[0030] Compared with related technologies, the CUDA backend separation and porting method for deep learning frameworks provided in this embodiment decouples the CUDA backend code from the frontend CPU code in the deep learning code project. It determines the file location of the target file corresponding to CUDA in the deep learning code project, extracts the target file from the deep learning code project based on the file location, and migrates the target file to the CUDA backend repository with the same file hierarchy. It also determines files in the deep learning code project that combine CPU and CUDA, extracts the target code corresponding to CUDA from these files, and migrates the target code to the corresponding target file in the CUDA backend repository based on its functionality. Finally, it determines the build configuration file in the deep learning code project, extracts the build script corresponding to CUDA from the build configuration file, and migrates the build script to the configuration file in the CUDA backend repository. This decouples the CUDA backend code from the frontend CPU code, improves code portability, solves the problem of poor code portability, and provides a replaceable backend access foundation for GPUs.

[0031] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description

[0032] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0033] Figure 1 This is a hardware structure block diagram of the terminal for the CUDA backend separation and porting method of the deep learning framework in this embodiment.

[0034] Figure 2 This is a flowchart of the CUDA backend separation and porting method of the deep learning framework in this embodiment;

[0035] Figure 3 This is a flowchart of the CUDA backend separation and porting method of the deep learning framework in this embodiment;

[0036] Figure 4 This is a structural block diagram of the CUDA backend separation and porting device for the deep learning framework in this embodiment;

[0037] Figure 5 This is a structural block diagram of the CUDA backend separation and porting device for the deep learning framework in this embodiment. Detailed Implementation

[0038] To better understand the purpose, technical solution, and advantages of this application, the application is described and explained below in conjunction with the accompanying drawings and embodiments.

[0039] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these” used in this application do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to these processes, methods, products, or devices. Words such as “connected,” “linked,” and “coupled” used in this application are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. “Multiple” used in this application refers to two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, and B alone. Normally, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," "third," etc., used in this application are merely to distinguish similar objects and do not represent a specific order of objects.

[0040] The method embodiments provided in this example can be executed on a terminal, computer, or similar computing device. For example, it can run on a terminal. Figure 1 This is a hardware structure block diagram of the terminal for the CUDA backend separation and porting method of the deep learning framework in this embodiment. For example... Figure 1 As shown, a terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 and a memory 104 for storing data are also included. The processor 102 may be, but is not limited to, a microprocessor (MCU) or a programmable logic device (FPGA). The terminal may also include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that… Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the terminal described above. For example, the terminal may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown are illustrated.

[0041] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the CUDA backend separation and porting method of the deep learning framework in this embodiment. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0042] The transmission device 106 is used to receive or send data via a network. This network includes a wireless network provided by the terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 can be a Radio Frequency (RF) module used for wireless communication with the Internet.

[0043] This embodiment provides a method for separating and porting the CUDA backend of a deep learning framework. Figure 2 This is a flowchart of the CUDA backend separation and porting method of the deep learning framework in this embodiment, as shown below. Figure 2 As shown, the process includes the following steps:

[0044] Step S201: Determine the file location of the target file corresponding to CUDA in the deep learning code project. Based on the file location, extract the target file from the deep learning code project and migrate the target file to the CUDA backend repository with the same file hierarchy structure.

[0045] This deep learning code project can be a code project written based on the PyTorch deep learning framework; the target file can be the code files that use CUDA to implement the corresponding functions in the deep learning code project and the resource files used to compile and generate CUDA dynamic libraries. For example, it can be a file that implements data augmentation functions, a file that implements loss function calculations, or a file that implements evaluation metric calculations. The CUDA backend repository can be customized to store the code files that use CUDA to implement the corresponding functions, the resource files used to compile and generate CUDA dynamic libraries, and the configuration files used to compile and generate CUDA dynamic libraries.

[0046] Specifically, based on the source code tree of the PyTorch deep learning framework, the file location of the CUDA target file in the deep learning code project can be determined. This target file includes code files that utilize CUDA to implement the corresponding functions and resource files used to compile and generate CUDA dynamic libraries. Based on this file location, the CUDA target file can be extracted from the deep learning code project. A CUDA backend repository is created with the same file hierarchy, and the target file is migrated to the file location corresponding to that CUDA backend repository.

[0047] Step S202: Identify the files in the deep learning code project that combine CPU and CUDA, extract the target code corresponding to CUDA from the files that combine CPU and CUDA, and migrate the target code to the corresponding target file in the CUDA backend repository according to the implementation function of the target code.

[0048] The CPU and CUDA hybrid file can be a code file that uses both CPU and CUDA to implement the corresponding function; the target code can be code that uses CUDA to implement the corresponding function. For example, the target code can be code that implements data augmentation functions, code that calculates loss functions, etc. The target file can be a code file that uses CUDA to implement the corresponding function.

[0049] Specifically, the conditional macro "#ifdef USE_CUDA" identifies files in the deep learning code project that combine CPU and CUDA implementations. This macro controls whether to compile the CUDA implementation code. These mixed CPU / CUDA files are code files that utilize both CPU and CUDA to implement corresponding functionalities. The corresponding CUDA target code is extracted from these mixed files, and based on the functionality implemented by this target code, it is migrated to the corresponding target file in the CUDA backend repository. This target file is the code file that utilizes CUDA to implement the corresponding functionality. If the corresponding target file exists in the CUDA backend repository, the target code is directly migrated to that file; if the corresponding target file does not exist in the CUDA backend repository, a new file is created in the CUDA backend repository first, and then the target code is migrated to the new file.

[0050] Step S203: Determine the build configuration file in the deep learning code project, extract the CUDA corresponding build script from the build configuration file, and migrate the build script to the configuration file in the CUDA backend repository.

[0051] The build configuration file can be a file used to compile and generate CPU dynamic libraries and CUDA dynamic libraries; the build script can be a script used to compile and generate CUDA dynamic libraries; the configuration file can be customized and used to compile and generate CUDA dynamic libraries.

[0052] Specifically, based on the source code tree of the PyTorch deep learning framework, the build configuration file in the deep learning code project can be identified. This build configuration file is used to compile and generate CPU dynamic libraries and CUDA dynamic libraries. The build script used to compile and generate the CUDA dynamic libraries is extracted from this build configuration file. A configuration file is created in the CUDA backend repository at the same file location, and the build script is migrated to the configuration file in the CUDA backend repository. This configuration file is used to compile and generate the CUDA dynamic libraries. For example, taking the source code tree of the PyTorch v2.6.0 deep learning framework as an example, the build configuration files in the deep learning code project can be identified as "CMakeLists.txt", "build_variables.bzl", and files containing the filename or suffix "cmake"; these "CMakeLists.txt", "build_variables.bzl", and files containing the filename or suffix "cmake" are used to compile and generate CPU dynamic libraries and CUDA dynamic libraries. Extract the build script used to compile and generate the CUDA dynamic library from the build configuration file; create the configuration file "CMakeLists.txt" in the CUDA backend repository with the same file location, and migrate the build script to the configuration file "CMakeLists.txt" in the CUDA backend repository.

[0053] In this embodiment, by determining the file location of the CUDA-corresponding target file in the deep learning code project, the target file is extracted from the deep learning code project based on the file location, and migrated to the CUDA backend repository with the same file hierarchy structure. Furthermore, by determining the files in the deep learning code project that combine CPU and CUDA, the target code corresponding to CUDA is extracted from these files, and migrated to the corresponding target file in the CUDA backend repository based on the implemented function of the target code. Finally, by determining the build configuration file in the deep learning code project, the build script corresponding to CUDA is extracted from the build configuration file, and the build script is migrated to the configuration file in the CUDA backend repository. This decouples the CUDA backend code from the frontend CPU code, improves code portability, solves the problem of poor code portability, and provides a replaceable backend access foundation for GPUs.

[0054] In some embodiments, the target file is extracted from the deep learning code project based on the file location, including: extracting the target file corresponding to the CUDA backend implementation from the deep learning code project based on the file location; and extracting the target file corresponding to the CUDA dynamic library recorded in the build configuration file from the deep learning code project based on the file location.

[0055] The target file can be the code file that uses CUDA to implement the corresponding functions in the deep learning code project, and the resource file used to compile and generate the CUDA dynamic library.

[0056] Specifically, based on the source code tree of the PyTorch deep learning framework, the file location of the CUDA target file in the deep learning code project can be determined. This target file consists of the code files that utilize CUDA to implement the corresponding functions and the resource files used to compile and generate the CUDA dynamic library. Based on this file location, the code files that utilize CUDA to implement the corresponding functions can be extracted from the deep learning code project. Based on this file location, the resource files recorded in the build configuration file for compiling and generating the CUDA dynamic library can also be extracted from the deep learning code project. For example, taking the source code tree of the PyTorch v2.6.0 deep learning framework as an example, the file location of the CUDA target file in the deep learning code project can be determined. The file location of the code files that utilize CUDA to implement the corresponding functions is the directory of the "cuda", "cudnn", and "THC" folders. The build configuration files are "CMakeLists.txt" and "build_variables.bzl". The file locations of the resource files used to compile and generate the CUDA dynamic library are obtained from the directories other than the "cuda", "cudnn", and "THC" folders recorded in the "ATen_CUDA_CPP_SRCS" list in "CMakeLists.txt" and the file directories recorded in the "libtorch_cuda_distributed_extra_sources" and "libtorch_cuda_core_source" lists in "build_variables.bzl".

[0057] In some embodiments, extracting CUDA-corresponding target code from a file that is a mixture of CPU and CUDA includes: extracting CUDA-corresponding target code within CUDA conditional compilation macro paragraphs from a file that is a mixture of CPU and CUDA.

[0058] Specifically, the target code corresponding to CUDA is extracted from the CUDA conditional compilation macro section within the mixed CPU and CUDA file. The mixed CPU and CUDA file is the code file that implements the corresponding function using CPU and CUDA; the target code is the code that implements the corresponding function using CUDA; the CUDA conditional compilation macro is USE_CUDA, and the code that implements the corresponding function using CUDA is extracted from the section within this conditional compilation macro.

[0059] In some embodiments, the method further includes setting a compilation control switch for independently compiling and generating a CUDA dynamic library.

[0060] Specifically, the compiler control switch can be defined as "USE_CUDA". Setting this compiler control switch can decouple the front-end CPU code building and CUDA back-end code building into a two-stage build process. The "USE_CUDA" compiler control switch is used to independently compile and generate CUDA dynamic libraries.

[0061] In some of these embodiments, Figure 3 This is a flowchart of the CUDA backend separation and porting method of the deep learning framework in this embodiment, as shown below. Figure 3 As shown, the CUDA backend separation and porting method of this deep learning framework includes the following steps:

[0062] Step S301: Set the “USE_CUDA” compilation control switch; specifically, setting the “USE_CUDA” compilation control switch can decouple the front-end CPU code building and CUDA back-end code building into a two-stage build process.

[0063] Step S302: When the "USE_CUDA" compilation control switch is enabled, the CUDA backend repository is compiled and a CUDA dynamic library is generated. Specifically, when the "USE_CUDA" compilation control switch is enabled, the CUDA backend repository can be compiled independently and a CUDA dynamic library can be generated. For example, taking the source code tree of the deep learning framework PyTorch v2.6.0 as an example, when the "USE_CUDA" compilation control switch is enabled, the CUDA backend repository is compiled and the CUDA dynamic library "libtorch_cuda.so" is generated.

[0064] Step S303: When the "USE_CUDA" compilation control switch is set to the off state, only the CPU front-end code is compiled to generate the CPU dynamic library. Specifically, when the "USE_CUDA" compilation control switch is set to the off state, only the CPU front-end code in the deep learning code project is compiled to generate the CPU dynamic library. For example, taking the source code tree of the deep learning framework PyTorch v2.6.0 as an example, when the "USE_CUDA" compilation control switch is set to the off state, only the CPU front-end code is compiled to generate the CPU dynamic library "libtorch_cpu.so".

[0065] This embodiment also provides a CUDA backend separation and porting device for a deep learning framework. This device is used to implement the above embodiments and preferred embodiments, and details already described will not be repeated. The terms "module," "unit," "subunit," etc., used below can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0066] Figure 4 This is a structural block diagram of the CUDA backend separate porting device for the deep learning framework in this embodiment, as shown below. Figure 4 As shown, the CUDA backend decoupling and porting device 40 of this deep learning framework includes: an inter-file decoupling module 401, an intra-file decoupling module 402, and a compilation and build decoupling module 403, wherein:

[0067] The inter-file decoupling module 401 is used to determine the file location of the target file corresponding to CUDA in the deep learning code project. Based on the file location, it extracts the target file from the deep learning code project and migrates the target file to the CUDA backend repository with the same file hierarchy structure. This inter-file decoupling module 401 identifies and separates CUDA backend-related files, aggregating CUDA files scattered in various locations of the deep learning code project into independent project levels, achieving file-level module separation.

[0068] The file-level decoupling module 402 is used to identify files in the deep learning code project that combine CPU and CUDA implementations. It extracts the corresponding CUDA target code from these files and, based on the functionality of the target code, migrates it to the corresponding target file in the CUDA backend repository. This file-level decoupling module 402 performs internal file migration, achieving CUDA code decoupling at the file-level granularity for mixed logic containing both CPU and CUDA implementations.

[0069] The build decoupling module 403 is used to determine the build configuration file in the deep learning code project, extract the corresponding CUDA build script from the build configuration file, and migrate the build script to the configuration file in the CUDA backend repository. This build decoupling module 403 enables independent compilation and loading of the CUDA backend repository.

[0070] In some of these embodiments, Figure 5 This is a structural block diagram of the CUDA backend separate porting device for the deep learning framework in this embodiment, as shown below. Figure 5 As shown, the file decoupling module 401 includes a file determination module 501 and a file migration module 502, wherein: the file determination module 501 is used to determine the file location of the target file corresponding to CUDA in the deep learning code project; the file migration module 502 is used to extract the target file from the deep learning code project according to the file location, and migrate the target file to the CUDA backend repository with the same file hierarchy structure.

[0071] In some embodiments, the file determination module 501 is implemented through a file scanning command; the file migration module 502 is implemented through a file migration command.

[0072] Specifically, the file identification module 501 can be implemented through a file scanning command. This file scanning command can recursively scan the deep learning code project, identify folders containing "cuda", "cudnn", or "THC", and record their relative paths; it also obtains the file paths recorded in the "ATen_CUDA_CPP_SRCS" list in "CMakeLists.txt" (excluding the paths to the "cuda", "cudnn", and "THC" folders) and the file paths recorded in the "libtorch_cuda_distributed_extra_sources" and "libtorch_cuda_core_source" lists in "build_variables.bzl", generating a list of CUDA files to be migrated. For example, taking the source code tree of the deep learning framework PyTorch v2.6.0 as an example, the generated list of CUDA files to be migrated, "cuda_list.json", has the following format:

[0073] {

[0074] "dirs": [

[0075] "c10 / cuda",

[0076] "aten / src / THC",

[0077] "aten / src / ATen / cuda",

[0078] "aten / src / ATen / cudnn",

[0079] "aten / src / ATen / native / miopen", ...

[0081] ],

[0082] "files": [

[0083] "torch / csrc / CudaIPCTypes.cpp",

[0084] "torch / csrc / distributed / c10d / reducer_cuda.cpp",

[0085] "torch / csrc / distributed / c10d / CudaDMAConnectivity.cpp",

[0086] "torch / csrc / distributed / c10d / NCCLUtils.cpp",

[0087] "torch / csrc / distributed / c10d / FlightRecorder.cpp",

[0088] "torch / csrc / distributed / c10d / ProcessGroupNCCL.cpp", ... ]

[0091] };

[0092] The file migration module 502 can be implemented through file migration commands. These commands can create a CUDA backend repository based on the list of CUDA files to be migrated generated by the file determination module 501, and then batch migrate the corresponding files from the CUDA file list to the corresponding file locations in the CUDA backend repository. For example, if the original file location is "pytorch-official / aten / src / ATen / cuda", the corresponding file location in the CUDA backend repository is "torch_cuda / aten / src / ATen / cuda", maintaining consistent relative paths. File scanning and file migration commands can significantly reduce the time consumption and error probability of manual splitting and manual migration.

[0093] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can reside in the same processor; or the above modules can be located in different processors in any combination.

[0094] This embodiment also provides an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.

[0095] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0096] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated in this embodiment.

[0097] Furthermore, in conjunction with the CUDA backend separation and porting method for deep learning frameworks provided in the above embodiments, this embodiment can also provide a storage medium for implementation. This storage medium stores a computer program; when executed by a processor, this computer program implements any of the CUDA backend separation and porting methods for deep learning frameworks in the above embodiments.

[0098] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.

[0099] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0100] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.

[0101] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0102] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.

Claims

1. A method for separating and porting the CUDA backend of a deep learning framework, characterized in that, include: Based on the source code tree of the deep learning framework PyTorch, the file location of the target file corresponding to CUDA in the deep learning code project is determined. Based on the file location, the target file is extracted from the deep learning code project and migrated to the CUDA backend repository with the same file hierarchy structure. Identify the files in the deep learning code project that combine CPU and CUDA, extract the target code corresponding to CUDA from the files that combine CPU and CUDA, and migrate the target code to the corresponding target file in the CUDA backend repository according to the implementation function of the target code. Based on the source code tree of the deep learning framework PyTorch, the build configuration file in the deep learning code project is determined, the CUDA corresponding build script is extracted from the build configuration file, and the build script is migrated to the configuration file in the CUDA backend repository.

2. The CUDA backend separation and porting method for deep learning frameworks according to claim 1, characterized in that, Based on the file location, the target file is extracted from the deep learning code project, including: Based on the file location, extract the corresponding target file of the CUDA backend implementation from the deep learning code project; Based on the file location, extract the corresponding target file recorded in the build configuration file for compiling and generating the CUDA dynamic library from the deep learning code project.

3. The CUDA backend separation and porting method for deep learning frameworks according to claim 1, characterized in that, Extracting the target code corresponding to CUDA from the file containing the CPU and CUDA mixture includes: Extract the CUDA-corresponding target code from the CUDA conditional compilation macro paragraph within the file containing the CPU and CUDA mixture.

4. The CUDA backend separation and porting method for deep learning frameworks according to claim 1, characterized in that, The method further includes: Configure a compiler control switch, which is used to independently compile and generate CUDA dynamic libraries.

5. The CUDA backend separation and porting method for deep learning frameworks according to claim 4, characterized in that, Configure compilation control switches, which are used to independently compile and generate CUDA dynamic libraries, including: When the compilation control switch is set to the on state, the CUDA backend repository is compiled and the CUDA dynamic library is generated. When the compilation control switch is set to the off state, only the CPU front-end code is compiled to generate the CPU dynamic library.

6. A CUDA backend decoupling and porting device for a deep learning framework, characterized in that, This includes inter-file decoupling modules, intra-file decoupling modules, and compilation / build decoupling modules, among which: The file decoupling module is used to determine the file location of the target file corresponding to CUDA in the deep learning code project according to the source code tree of the deep learning framework PyTorch, extract the target file from the deep learning code project according to the file location, and migrate the target file to the CUDA backend repository with the same file hierarchy structure. The file decoupling module is used to identify files in the deep learning code project that combine CPU and CUDA, extract the target code corresponding to CUDA from the files that combine CPU and CUDA, and migrate the target code to the corresponding target file in the CUDA backend repository according to the implementation function of the target code. The compilation and build decoupling module is used to determine the build configuration file in the deep learning code project based on the source code tree of the deep learning framework PyTorch, extract the CUDA-corresponding build script from the build configuration file, and migrate the build script to the configuration file in the CUDA backend repository.

7. The CUDA backend separation and porting device for the deep learning framework according to claim 6, characterized in that, The file decoupling module includes a file determination module and a file migration module, wherein: The file determination module is used to determine the file location of the target file corresponding to CUDA in the deep learning code project based on the source code tree of the deep learning framework PyTorch. The file migration module is used to extract the target file from the deep learning code project according to the file location, and migrate the target file to the CUDA backend repository with the same file hierarchy structure.

8. The CUDA backend separation and porting device for the deep learning framework according to claim 7, characterized in that, The file determination module is implemented through a file scanning command; the file migration module is implemented through a file migration command.

9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the CUDA backend separation porting method of the deep learning framework according to any one of claims 1 to 5.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the CUDA backend separation and porting method of the deep learning framework according to any one of claims 1 to 5.