OpenCL configuration methods, usage methods and related products

By converting OpenCL kernel files into CUDA binary files and configuring the target OpenCL interface, the problem of CUDA architecture processors not supporting OpenCL is solved, the ability to run OpenCL programs on these processors is realized, and the application scenarios are expanded.

CN120371425BActive Publication Date: 2025-09-30北京天数智芯半导体科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510875153.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-09-30
Estimated Expiration
2045-06-27

AI Technical Summary

Technical Problem

CUDA architecture processors do not support OpenCL technology, which limits their application scenarios.

Method used

By converting the OpenCL kernel file into a CUDA binary file and configuring the target OpenCL interface, the OpenCL function can be deployed and called.

Benefits of technology

This enables processors that do not support OpenCL to run OpenCL-related programs, improving the applicability of the processor in different application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371425B_ABST
    Figure CN120371425B_ABST
Patent Text Reader

Abstract

This application provides a method for configuring and using OpenCL, as well as related products. The configuration method includes: obtaining an OpenCL kernel file; generating a CUDA binary file based on the kernel file; and configuring a target OpenCL interface; wherein the target OpenCL interface is used to call the CUDA binary file to execute on a processor core. This application enables processors that do not support OpenCL to implement OpenCL functionality by running a CUDA binary file generated from the OpenCL kernel file. This allows processors that do not support OpenCL to run OpenCL-related programs, improving the processor's applicability to different application scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of processor technology, and more specifically, to an OpenCL configuration method, a usage method, and related products. Background Art

[0002] Currently, some CUDA (Compute Unified Device Architecture) processors do not support OpenCL (Open Computing Language). However, in practice, many business areas require OpenCL technology, such as graphics processing, scientific computing, artificial intelligence, encryption processing, and finance. This limits the application scenarios of CUDA processors that do not support OpenCL. Summary of the Invention

[0003] The purpose of the embodiments of the present application is to provide an OpenCL configuration method, usage method, device, processor, electronic device and electronic device, so as to enable a processor using the CUDA architecture that does not support OpenCL to run OpenCL-related programs, thereby improving the applicability of the processor for different application scenarios.

[0004] An embodiment of the present application provides an OpenCL configuration method, comprising: obtaining an OpenCL kernel file; generating a CUDA binary file based on the kernel file; configuring a target OpenCL interface; and using the target OpenCL interface to call the CUDA binary file to run on a processor core.

[0005] In the above implementation, an OpenCL kernel file is used to generate a CUDA binary file, and a target OpenCL interface that can call the CUDA binary file is configured. This allows the processor to call the CUDA binary file through the target OpenCL interface and execute it on the processor core. Since the CUDA binary file is generated based on the OpenCL kernel file, when running on the processor core, the CUDA binary file implements the functionality of the OpenCL kernel file, effectively launching and running the OpenCL kernel. This allows processors that don't support OpenCL to implement OpenCL functionality by running the CUDA binary file generated from the OpenCL kernel file. This allows processors that don't support OpenCL to run OpenCL-related programs, improving the processor's suitability for various application scenarios.

[0006] Furthermore, generating a CUDA binary file based on the kernel file includes: converting the kernel file into a CUDA source code file; and compiling the CUDA source code file to generate the CUDA binary file.

[0007] In the above implementation, the OpenCL kernel file is first converted into a CUDA source code file and then compiled to produce a CUDA binary file. Since the conversion of the OpenCL kernel file into the CUDA source code file primarily involves converting the source code, minimal information loss occurs after the conversion, allowing for better expression of OpenCL functions. Consequently, the compiled CUDA binary file more closely matches the OpenCL function expression, resulting in better conversion performance and smoother use of OpenCL.

[0008] Furthermore, the kernel file is converted into a CUDA source code file, including: converting a target built-in function in the kernel file into a CUDA built-in function; the target built-in function is a built-in function supported by both OpenCL and CUDA; converting other built-in functions in the kernel file except the target built-in function into a CUDA header file; converting a vector in the kernel file into a CUDA vector; the CUDA source code file includes the CUDA built-in function, the CUDA vector and the CUDA header file.

[0009] Some of OpenCL's built-in functions may not be supported by CUDA. Therefore, in the above implementation, built-in functions supported by both OpenCL and CUDA are converted to CUDA built-in functions, while built-in functions supported by OpenCL but not CUDA are replaced with CUDA header files. This way, the resulting CUDA source code file, which includes vector and CUDA header files, can fully include all OpenCL source code functions while meeting CUDA architecture requirements. This makes the compiled CUDA binary file more consistent with OpenCL functional expression, making OpenCL usage smoother.

[0010] Furthermore, converting the target built-in function in the kernel file into a built-in function of CUDA includes: based on a preset built-in function mapping relationship, converting the target built-in function in the kernel file into a built-in function of CUDA.

[0011] In the above implementation, by pre-building the built-in function mapping relationship, the conversion accuracy of the target built-in function to the vector can be improved.

[0012] Furthermore, converting the target built-in function in the kernel file into a built-in function of CUDA, and converting the vector in the kernel file into a vector of CUDA, includes: in a target compiler, mapping the target built-in function in the kernel file into a built-in function of CUDA through a TranslationUnit class, and converting the vector in the kernel file into a vector of CUDA through a TranslationUnit class; the target compiler is: a compiler having a TranslationUnit class that supports mapping the target built-in function in the kernel file into a built-in function of CUDA, and supports converting the vector in the kernel file into a vector of CUDA.

[0013] In the above implementation, by using the TranslationUnit class in the target compiler to map the target built-in functions and vectors, the CUDA backend can be directly reused to convert CUDA binary files, greatly reducing the difficulty and workload of developers.

[0014] Furthermore, the kernel file is converted into a CUDA source code file, including: converting the built-in functions and vectors in the kernel file into LLVM IR (Intermediate Representation) according to a conversion relationship between preset built-in functions, vectors and LLVM (Low Level Virtual Machine) IR; and converting the LLVM IR into the CUDA source code file.

[0015] Furthermore, configuring the target OpenCL interface includes: calling a preset software development kit to implement the clBuildProgram interface of OpenCL; the clBuildProgram interface is the target interface.

[0016] The clBuildProgram interface is a key function in OpenCL, used to build (compile and link) program executables for all devices or for a specific device within the OpenCL context associated with the program. In the above implementation, the clBuildProgram interface is implemented using an existing software development kit and used to call CUDA binaries. This eliminates the need for specialized interface configuration and maintains the OpenCL architecture.

[0017] An embodiment of the present application also provides a method for using OpenCL, which is applied to a processor that has executed the above-mentioned OpenCL configuration method; the method for using OpenCL includes: responding to a startup instruction of the OpenCL kernel, calling the CUDA binary file through the target OpenCL interface to run on the processor core of the processor.

[0018] Based on this implementation, the processor can call the CUDA binary file through the target OpenCL interface to execute on the processor core. Since the CUDA binary file is generated based on the OpenCL kernel file, the CUDA binary file implements the functions of the OpenCL kernel file when running on the processor core. This allows processors that do not support OpenCL to implement OpenCL functions by running the CUDA binary file generated based on the OpenCL kernel file, allowing even processors that do not support OpenCL to run OpenCL-related programs, thereby improving the processor's applicability to different application scenarios.

[0019] An embodiment of the present application also provides an OpenCL configuration device, including: an acquisition module for acquiring an OpenCL kernel file; a generation module for generating a CUDA binary file based on the kernel file; a configuration module for configuring a target OpenCL interface; the target OpenCL interface is used to call the CUDA binary file to run on a processor core.

[0020] Furthermore, the generating module is specifically configured to: convert the kernel file into a CUDA source code file; and compile the CUDA source code file to generate the CUDA binary file.

[0021] An embodiment of the present application also provides an OpenCL usage device, which is applied to a processor that has executed the above-mentioned OpenCL configuration method; the device includes: a calling module, which is used to respond to the startup instruction of the OpenCL kernel and call the CUDA binary file through the target OpenCL interface to run on the processor core of the processor.

[0022] An embodiment of the present application further provides a processor, including a processor core, wherein the processor core is configured to execute one or more programs to implement any of the above-mentioned OpenCL configuration methods or the above-mentioned OpenCL usage methods.

[0023] An embodiment of the present application also provides an electronic device including the above-mentioned processor.

[0024] An embodiment of the present application also provides an electronic device, including the above-mentioned electronic device.

[0025] An embodiment of the present application further provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement any of the above-mentioned OpenCL configuration methods or the above-mentioned OpenCL usage methods.

[0026] An embodiment of the present application further provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement any of the above-mentioned OpenCL configuration methods or the above-mentioned OpenCL usage methods.

[0027] An embodiment of the present application further provides a computer program product, which includes computer program code. When the computer program code runs on a processor, the processor executes any one of the above-mentioned OpenCL configuration methods or the above-mentioned OpenCL usage method. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.

[0029] Figure 1 A flowchart of an OpenCL configuration method provided in an embodiment of the present application;

[0030] Figure 2 A flowchart of a method for using OpenCL provided in an embodiment of the present application;

[0031] Figure 3 An exemplary specific implementation process provided for the embodiments of the present application;

[0032] Figure 4 A schematic diagram of the structure of an OpenCL configuration device provided in an embodiment of the present application;

[0033] Figure 5 A schematic diagram of the structure of an OpenCL usage device provided in an embodiment of the present application;

[0034] Figure 6 A schematic diagram of the basic structure of a processor provided in an embodiment of the present application. DETAILED DESCRIPTION

[0035] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments.

[0036] In the following, the terms "first," "second," etc., are used for descriptive convenience only and should not be understood to indicate or imply relative importance or implicitly specify the number of the technical features indicated. Therefore, a feature defined as "first," "second," etc. may explicitly or implicitly include one or more of the features.

[0037] In the embodiments of this application, unless otherwise specified or limited, the term "connection" should be understood in a broad sense. For example, "connection" can mean fixed connection, detachable connection, or integration; it can mean direct connection or indirect connection through an intermediate medium. In addition, the term "coupling" can mean direct electrical connection or indirect electrical connection through an intermediate medium. The term "contact" can mean direct contact or indirect contact through an intermediate medium.

[0038] Currently, the software stacks for some CUDA-based processors don't support OpenCL. However, OpenCL is often required in fields like graphics processing, scientific computing, artificial intelligence, encryption, and finance. This limits the application scenarios for CUDA-based processors that don't support OpenCL.

[0039] To solve this technical problem, in the embodiments of the present application, the deployment of OpenCL functions is achieved by converting OpenCL kernel files into CUDA binary files supported by the processor, and by configuring the target OpenCL interface for calling the CUDA binary file, users can call the CUDA binary file through OpenCL, thereby realizing the use of OpenCL functions.

[0040] For this, see Figure 1 As shown, Figure 1 The following is a basic flow chart of the OpenCL configuration method provided in the embodiments of the present application, including:

[0041] S101: Obtain an OpenCL kernel file.

[0042] OpenCL typically consists of .cl files and .cpp files. The .cl file primarily contains the OpenCL kernel and, when executed, is used to launch the OpenCL kernel and implement its functionality. The .cpp file is primarily used to compile and generate the executable bin file, which must be linked with the OpenCL library. Furthermore, when running an OpenCL program, the kernel is loaded to implement OpenCL functionality.

[0043] Therefore, in the embodiment of the present application, a .cl file can be identified from OpenCL and the .cl file can be obtained as the kernel file of OpenCL.

[0044] S102: Generate a CUDA binary file based on the kernel file.

[0045] In an optional implementation of the present application, an OpenCL kernel file can be converted into a CUDA source code file (generally a .cu file), and then the CUDA source code file is compiled to generate a CUDA binary file (cubin). In this way, since the conversion of the OpenCL kernel file into the CUDA source code file mainly involves the conversion of the source code form, there is little information loss after the conversion, which can better realize the expression of the OpenCL function, thereby making the compiled CUDA binary file more consistent with the OpenCL function expression, having a better conversion effect, and thus making the use of OpenCL smoother.

[0046] Considering the differences in the format requirements for built-in functions and vectors between CUDA source code files and OpenCL kernel files, in order to convert an OpenCL kernel file into a CUDA source code file, in the above optional implementation, the target built-in function (built-in functions are also referred to as builtin in some files) in the kernel file can be converted into a CUDA built-in function, and all built-in functions in the kernel file other than the target built-in function can be converted into CUDA header files, and the vectors in the kernel file can be converted into CUDA vectors. The target built-in function is a built-in function supported by both OpenCL and CUDA. In this way, a CUDA source code file including vectors and CUDA header files can be obtained.

[0047] Through the above method, for the built-in functions supported by both OpenCL and CUDA, they are converted into CUDA built-in functions, and the built-in functions supported by OpenCL but not CUDA are replaced with CUDA header files. In this way, the CUDA source code file containing vector and CUDA header files can fully include all the source code functions of OpenCL while meeting the requirements of the CUDA architecture, so that the compiled CUDA binary file is more in line with the OpenCL function expression, and the use of OpenCL can be smoother.

[0048] In one possible embodiment of the above optional implementation, a built-in function mapping relationship can be pre-established and saved. Thus, when converting a target built-in function in a kernel file to a CUDA built-in function, the target built-in function in the kernel file can be converted to a CUDA built-in function based on the pre-established built-in function mapping relationship. In other words, the target built-in function in the kernel file can be matched against the pre-established built-in function mapping relationship to find the CUDA built-in function corresponding to the target built-in function.

[0049] In the above feasible embodiment, when building built-in function mappings, engineers can only build mappings for built-in functions supported by both OpenCL and CUDA (i.e., target built-in functions). The mappings include the correspondence between the representations of built-in functions in OpenCL and those in CUDA.

[0050] Similarly, in one possible embodiment of the aforementioned optional implementation, a vector mapping relationship can be pre-established and saved, so that when converting vectors in a kernel file to CUDA vectors, the vectors in the kernel file can be converted to CUDA vectors based on the pre-established vector mapping relationship. In other words, the vectors in the kernel file can be matched against the pre-established vector mapping relationship to find the CUDA vector corresponding to the vector in the kernel file. The vector mapping relationship includes the correspondence between the representation of vectors in OpenCL and the representation of vectors in CUDA.

[0051] In another feasible embodiment of the above optional implementation, some existing tools can also be used to realize the conversion of target built-in functions to CUDA built-in functions, and the conversion of vectors in kernel files to CUDA vectors. For example, in the target compiler, the target built-in functions in the kernel file can be mapped to CUDA built-in functions through the TranslationUnit class, and the vectors in the kernel file can be converted to CUDA vectors through the TranslationUnit class. Among them, the target compiler is: a compiler with a TranslationUnit class that supports mapping the target built-in functions in the kernel file to CUDA built-in functions, and supports converting the vectors in the kernel file to CUDA vectors. For example, the target compiler can be the clang front-end compiler of llvm, but this is not a limitation. In this way, by using the TranslationUnit class in the target compiler to map the target built-in function to the vector, the back end of CUDA can be directly reused to perform the conversion of CUDA binary files, which can greatly reduce the difficulty and workload of the developer.

[0052] In the above feasible embodiment, FrontendPluginRegistry (part of the Clang plug-in system, used to register and manage Clang plug-ins) can be registered for the clang front-end compiler of llvm, and then the target built-in functions in the kernel file can be mapped to CUDA built-in functions through the TranslationUnit class in FrontendPluginRegistry, thereby converting the vectors in the kernel file into CUDA vectors.

[0053] In another optional implementation of the present application, the built-in functions and vectors in the kernel file can be converted into LLVM IR according to the preset conversion relationship between built-in functions and vectors and LLVM IR, and then the LLVM IR is converted into CUDA source code files, and finally the CUDA source code files are compiled to generate CUDA binary files. This can achieve closer hardware alignment and higher efficiency.

[0054] In the above optional implementation manner, the conversion relationship between the preset built-in functions, vectors and LLVM IR can be written by engineers according to the respective architectural requirements of OpenCL and LLVM.

[0055] S103: Configure the target OpenCL interface.

[0056] The target OpenCL interface is used to call the CUDA binary file to run on the processor core.

[0057] In an optional implementation of the embodiment of the present application, a preset software development kit can be called to implement the clBuildProgram interface of OpenCL, wherein the clBuildProgram interface is the target interface.

[0058] The clBuildProgram interface is a key function in OpenCL, used to build (compile and link) a program executable for all devices or for a specific device within the OpenCL context associated with the program. In this optional implementation, the clBuildProgram interface is implemented using an existing software development kit and used to call the CUDA binary. This eliminates the need for specialized interface configuration and maintains no modifications to the OpenCL architecture.

[0059] In the embodiment of the present application, the above implementation method can be applied to a processor adopting the CUDA architecture.

[0060] In an embodiment of the present application, a method for using OpenCL is also provided, which is applied to the aforementioned processor using the CUDA architecture, and requires that the processor has executed the aforementioned OpenCL configuration method.

[0061] See also Figure 2 As shown, the usage of OpenCL includes:

[0062] S201: In response to a start instruction of an OpenCL kernel, calling a CUDA binary file through a target OpenCL interface to execute the file on a processor core of a processor.

[0063] As mentioned above, OpenCL generally includes .cpp files. In the embodiments of this application, to ensure that the processor can properly use OpenCL-related programs when it is delivered to the customer, the OpenCL .cpp files are also compiled to generate an executable program and link the OpenCL library. When the OpenCL executable program is run, the kernel is loaded to meet the requirements of OpenCL. The .cpp files can be written by the customer.

[0064] The method provided in the embodiments of the present application allows a processor to call a CUDA binary file to run on the processor core through the target OpenCL interface. Since the CUDA binary file is generated based on the OpenCL kernel file, the CUDA binary file implements the functions of the OpenCL kernel file when it runs on the processor core. In this way, even processors that do not support OpenCL can implement OpenCL functions by running the CUDA binary file generated based on the OpenCL kernel file, allowing processors that do not support OpenCL to run OpenCL-related programs, thereby improving the processor's applicability to different application scenarios.

[0065] Example 2:

[0066] This embodiment, based on the first embodiment, takes a specific implementation process as an example to further illustrate this application. The whole process can be found in Figure 3 shown.

[0067] First, the processor uses the clang front-end compiler of the open source project llvm to convert the OpenCL .cl file into a .cu file (CUDA source code file) through the mapping of builtin (built-in function).

[0068] Specifically, you can register the FrontendPluginRegistry plug-in for the clang front-end compiler of llvm, and complete the mapping between the target builtin and vector by registering the TranslationUnit class in clangFrontendPluginRegistry.

[0069] The target builtins are those supported by both OpenCL and CUDA, such as work_group and block.

[0070] For builtins that are supported by OpenCL but not by CUDA, such as rotate and as_uint, convert them to the CUDA header file cuh.

[0071] The above operations result in a .cu file.

[0072] Next, compile the .cu file to generate cubin.

[0073] Next, call the SDK (software development kit) to implement the opencl interface, including the clBuildProgram interface.

[0074] Finally, the kernel is loaded through the load cubin method in the clBuildProgram interface of opencl (cubin can be loaded through Culoadmodule (a CUDA interface)).

[0075] In the embodiments of this application, Figure 3 As shown, before starting the kernel, you can also compile the OpenCL .cpp file to obtain the binary execution file bin of the OpenCL .cpp file and link it to the OpenCL library.

[0076] Through the above solution, users can run OpenCL related programs seamlessly when using the processor, thereby achieving the purpose of supporting users to use OpenCL.

[0077] Example 3:

[0078] Based on the same inventive concept, the present application also provides an OpenCL configuration device 400 and an OpenCL use device 500. Figure 4 and Figure 5 As shown, Figure 4 Shows the use of Figure 1 The OpenCL configuration device shown in the method, Figure 5 Shows the use of Figure 2 The OpenCL configuration device 400 and the OpenCL usage device 500 are described in detail above. To avoid repetition, the detailed description is omitted here. The OpenCL configuration device 400 and the OpenCL usage device 500 include at least one software function module that can be stored in a memory in the form of software or firmware or fixed in the operating system of the OpenCL configuration device 400 and the OpenCL usage device 500. Specifically:

[0079] See also Figure 4 As shown, the OpenCL configuration device 400 includes: an acquisition module 401, a generation module 402 and a configuration module 403.

[0080] An acquisition module 401 is used to acquire an OpenCL kernel file;

[0081] A generating module 402 is configured to generate a CUDA binary file based on the kernel file;

[0082] The configuration module 403 is used to configure a target OpenCL interface; the target OpenCL interface is used to call the CUDA binary file to run on the processor core.

[0083] In a feasible implementation of the embodiment of the present application, the generating module 402 is specifically configured to:

[0084] Converting the kernel file into a CUDA source code file;

[0085] Compile the CUDA source code file to generate the CUDA binary file.

[0086] In a feasible implementation of the embodiment of the present application, the generating module 402 is specifically configured to:

[0087] Converting the target built-in function in the kernel file into a built-in function of CUDA; the target built-in function is a built-in function supported by both OpenCL and CUDA;

[0088] Converting other built-in functions in the kernel file except the target built-in function into CUDA header files;

[0089] Convert the vector in the kernel file into a CUDA vector;

[0090] The CUDA source code file includes the CUDA built-in functions, the CUDA vectors and the CUDA header file.

[0091] In a feasible implementation of the embodiment of the present application, the generating module 402 is specifically configured to convert the target built-in function in the kernel file into a CUDA built-in function based on a preset built-in function mapping relationship.

[0092] In a feasible implementation manner of an embodiment of the present application, the generation module 402 is specifically used to: in a target compiler, map the target built-in function in the kernel file to a built-in function of CUDA through the TranslationUnit class, and convert the vector in the kernel file to a vector of CUDA through the TranslationUnit class; the target compiler is: a compiler having a TranslationUnit class that supports mapping the target built-in function in the kernel file to a built-in function of CUDA, and supports converting the vector in the kernel file to a vector of CUDA.

[0093] In a feasible implementation of an embodiment of the present application, the generation module 402 is specifically used to: convert the built-in functions and vectors in the kernel file into LLVM IR according to the preset conversion relationship between the built-in functions, vectors and LLVM intermediate expression IR; and convert the LLVM IR into the CUDA binary file.

[0094] In a feasible implementation of the embodiment of the present application, the configuration module 403 is specifically used to call a preset software development kit to implement the clBuildProgram interface of OpenCL; the clBuildProgram interface is the target interface.

[0095] See also Figure 5 As shown, an OpenCL usage device 500 is applied to a processor that has executed the OpenCL configuration method described in Example 1. The device 500 includes:

[0096] The calling module 501 is configured to respond to a start instruction of the OpenCL kernel and call the CUDA binary file through the target OpenCL interface to execute the file on the processor core of the processor.

[0097] It should be understood that, for the sake of brevity, some of the contents described in the first embodiment will not be repeated in this embodiment.

[0098] Example 4:

[0099] Based on the same inventive concept, the embodiment of the present application provides a processor, see Figure 6 As shown, it includes a processor core 601. Among them:

[0100] The processor core 601 is configured to execute one or more programs to implement the aforementioned OpenCL configuration method or the aforementioned OpenCL usage method.

[0101] In the embodiment of the present application, the processor may be, but is not limited to, a GPU (Graphics Processing Unit), a GPGPU (General-purpose computing on graphics processing units), an AI (Artificial Intelligence) processor, an NPU (Neural Network Processing Unit), an ISP (Image Signal Processor), a DPU (Display Processing Unit), a VPU (Video Processing Unit), or the like, which may adopt a CUDA architecture.

[0102] In an embodiment of the present application, the program executed by the processor core 601 can be obtained and executed from a memory outside the processor, such as a memory. In addition, the program executed by the processor core 601 can also be obtained and executed from an on-chip memory within the processor.

[0103] In the embodiment of the present application, in addition to the aforementioned processor core 601 and on-chip memory, the processor may also have other components, such as a task distribution circuit.

[0104] Based on the same inventive concept, an embodiment of the present application provides an electronic device comprising the aforementioned processor.

[0105] In the embodiments of the present application, the electronic device may be, but is not limited to, a graphics card, a processor board, a processor mainboard, a GPGPU product card, a data processing module, or the like, which can be produced or sold separately but still require cooperation with other components to fully provide services.

[0106] In the embodiment of the present application, the electronic device may include not only a processor but also other components, such as a heat sink, a power supply, and peripheral circuits that cooperate with the power supply or the processor.

[0107] Based on the same inventive concept, an embodiment of the present application provides an electronic device, which includes the aforementioned electronic device.

[0108] In the embodiments of the present application, the electronic device may be, but is not limited to, a smart phone, a smart wearable device, a vehicle-mounted terminal, a laptop computer, a desktop computer, a server, etc.

[0109] In an embodiment of the present application, in addition to the aforementioned electronic devices, the electronic device may also include other devices, for example, it may also include an internal communication bus for realizing communication between the processor and the memory; for example, it may also have an external communication interface, such as a USB (Universal Serial Bus) interface, a CAN (Controller Area Network) bus interface, etc.; for example, it may also have an information display component such as a display screen, but this is not a limitation.

[0110] Based on the same inventive concept, this embodiment further provides a computer-readable storage medium, such as a floppy disk, an optical disk, a hard disk, a flash memory, a USB flash drive, an SD (Secure Digital Memory Card), or an MMC (Multimedia Card). The computer-readable storage medium stores one or more programs that implement the aforementioned steps. These one or more programs can be executed by one or more processors to implement the aforementioned OpenCL configuration method or the aforementioned OpenCL usage method. This description is omitted here.

[0111] Embodiments of the present application also provide a computer program product, comprising computer program code that, when executed on a processor, causes the processor to execute the steps of the aforementioned OpenCL configuration method or the aforementioned OpenCL usage method. The computer program product may be, but is not limited to, an installation package, a software package, a firmware package, or the like.

[0112] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interface, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0113] In addition, the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0114] Furthermore, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0115] As used herein, a plurality refers to two or more than two.

[0116] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, various modifications and variations of the present application are possible. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. A configuration method for OpenCL, characterized in that: include: Get the OpenCL kernel file; Generate a CUDA binary file based on the kernel file; Configure the target OpenCL interface; The target OpenCL interface is used to call the CUDA binary file to run on the processor core; Generate a CUDA binary file based on the kernel file, including: Converting the kernel file into a CUDA source code file; Compile the CUDA source code file to generate the CUDA binary file; Convert the kernel file into a CUDA source code file, including: Converting the target built-in function in the kernel file into a built-in function of CUDA; the target built-in function is a built-in function supported by both OpenCL and CUDA; Converting other built-in functions in the kernel file except the target built-in function into CUDA header files; Convert the vector in the kernel file into a CUDA vector; The CUDA source code file includes the CUDA built-in functions, the CUDA vectors and the CUDA header file.

2. The OpenCL configuration method according to claim 1, wherein: Converting the target built-in functions in the kernel file into CUDA built-in functions includes: Based on a preset built-in function mapping relationship, the target built-in function in the kernel file is converted into a CUDA built-in function.

3. The OpenCL configuration method according to claim 1, wherein: Converting the target built-in function in the kernel file into a built-in function of CUDA, and converting the vector in the kernel file into a vector of CUDA, including: In the target compiler, mapping the target built-in functions in the kernel file to built-in functions of CUDA through the TranslationUnit class, and converting the vectors in the kernel file to vectors of CUDA through the TranslationUnit class; The target compiler is a compiler having a TranslationUnit class that supports mapping target built-in functions in the kernel file into CUDA built-in functions and supports converting vectors in the kernel file into CUDA vectors.

4. The OpenCL configuration method according to any one of claims 1 to 3, wherein: Configure the target OpenCL interface, including: Calling a preset software development kit to implement the clBuildProgram interface of OpenCL; the clBuildProgram interface is the target interface.

5. A method for using OpenCL, characterized in that: applied to a processor, the processor having executed the method according to any one of claims 1 to 4; The method of using OpenCL includes: In response to a start instruction of the OpenCL kernel, the CUDA binary file is called through the target OpenCL interface to execute on a processor core of the processor.

6. An OpenCL configuration device, characterized in that: include: Get module, used to get OpenCL kernel file; A generation module, configured to generate a CUDA binary file based on the kernel file; A configuration module, configured to configure a target OpenCL interface; the target OpenCL interface is used to call the CUDA binary file to run on the processor core; The generating module is specifically used to: convert the kernel file into a CUDA source code file; compile the CUDA source code file to generate the CUDA binary file; The generation module is specifically used to: convert the target built-in function in the kernel file into a CUDA built-in function; the target built-in function is a built-in function supported by both OpenCL and CUDA; convert other built-in functions in the kernel file except the target built-in function into a CUDA header file; convert the vector in the kernel file into a CUDA vector; the CUDA source code file includes the CUDA built-in function, the CUDA vector and the CUDA header file.

7. A device for using OpenCL, characterized in that: Applied in a processor, the processor having executed the method according to any one of claims 1 to 4; the apparatus comprising: The calling module is used for calling the CUDA binary file to run on the processor core of the processor through the target OpenCL interface in response to a start instruction of the OpenCL kernel.

8. A processor, characterized in that: The system comprises a processor core configured to execute one or more programs to implement the OpenCL configuration method according to any one of claims 1 to 4, or to implement the OpenCL usage method according to claim 5.

9. An electronic device, characterized in that: comprising the processor of claim 8.

10. An electronic device, characterized in that: Comprising the electronic device according to claim 9.