Operator test method, device and equipment, readable storage medium and program product

By updating and testing the original neural network operators, using the interpreter of the target software language to run the neural network operator described in the field-specific language, the problems of high difficulty in development and debugging of neural network operators and low testing efficiency in the existing technology are solved, and rapid debugging and efficient testing are achieved.

CN119576788AActive Publication Date: 2025-03-07ARM TECH CHINA CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411758978.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-03-07
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

In the prior art, when deploying neural network operators on NPUs, development and debugging are difficult, testing efficiency is low, and threshold is high.

Method used

By obtaining the original neural network operator and the target software language description, the decorator of the objective function is determined, and the original neural network operator is updated based on the target software language description, decorator and target class, the updated neural network operator is obtained, and the test is carried out in the target software language test.

Benefits of technology

It realizes the updated neural network operator described in the domain-specific language using the interpreter of the target software language (such as python), and quickly adjusts the correctness of the operator, reduces the difficulty of development and debugging, and improves testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576788A_ABST
    Figure CN119576788A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an operator testing method, device and equipment, a readable storage medium and a program product, and relates to the field of software testing and the like, and application scenes include but are not limited to operator testing scenes. The method comprises the steps that an original neural network operator and target software language description are obtained, the original neural network operator comprises a target function, and the target software language description is obtained by conducting language conversion on hardware primitives in the target function through a target software language; a decorator of the target function is determined, the decorator of the target function comprises a target object of a preset target class, and the target object of the target class is obtained by packaging the target function through the target class; updating the original neural network operator based on the target software language description, the decorator of the target function and the target class to obtain an updated neural network operator; and testing the updated neural network operator in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to an operator testing method, device, equipment, readable storage medium, and program product. Background Art

[0002] In the existing technology, when deploying deep learning models on NPU (Neural Network Processing Unit), neural network operator development and debugging are very important tasks. Usually, developing a neural network operator requires the cooperation of the entire compilation and deployment software stack, using low-level languages ​​such as C or OpenCL to describe the neural network operator, and using the tool chain to deploy the neural network operator to the NPU. Using low-level languages ​​such as C or OpenCL to describe neural network operators is a very difficult method, and requires developers to have a deep understanding of the software and hardware of the NPU.

[0003] As a programming language, Python has the advantages of low learning threshold. In order to lower the threshold for developing neural network operators, many manufacturers provide Python-like DSL (Domain-Specific Language) to describe neural network operators. Generally, the syntax of this DSL is a subset of Python syntax, and the DSL includes primitives related to various hardware.

[0004] The user completes the DSL description of the neural network operator, converts the DSL description into a low-level language description such as C, OpenCL or hardware instructions through the tool chain provided by the manufacturer, and deploys the low-level language description to the device. The user tests whether the DSL is correct by observing the generated low-level language description such as C, OpenCL or hardware instructions; or the user tests the low-level language description by deploying the low-level language description; this makes the testing of the neural network operator more difficult, the testing process is longer, and the testing efficiency of the neural network operator is lower. Summary of the invention

[0005] In view of the shortcomings of existing methods, the present disclosure proposes an operator testing method, device, equipment, computer-readable storage medium and computer program product to solve the problem of how to improve the testing efficiency of neural network operators.

[0006] In a first aspect, the present disclosure provides an operator testing method, comprising: Obtaining an original neural network operator and a target software language description, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by converting a hardware primitive in the target function into a language using the target software language, and the hardware primitive is used to represent a primitive related to a hardware device; Determine a decorator of the target function, the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; Based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator; The updated neural network operator is tested in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator.

[0007] In one embodiment, before determining the decorator of the original neural network operator, the method further includes: Construct a target class, the target class includes a calling method, and the calling method is used for the interpreter of the target software language to call the object of the target class and run the function corresponding to the object of the target class in multiple threads.

[0008] In one embodiment, based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator, including: Writing the target software language description, the decorator of the target function, and the target class into the original neural network operator to obtain an updated neural network operator; Among them, the decorator of the objective function also includes the label of the object of the target class, and the label is used to represent that if the objective function is called in the neural network operator after the objective function is updated and the called function is language converted to obtain the underlying language description corresponding to the called function, then the objective function is language converted to obtain the underlying language description corresponding to the objective function.

[0009] In one embodiment, the updated neural network operator is tested in a test mode of the target software language to determine the test result corresponding to the updated neural network operator, including: Through the interpreter of the target software language, the target object of the target class is called based on the calling method, and the target function and the target software language description are run in multiple threads to obtain the test results corresponding to the target function. The test results corresponding to the updated neural network operator include the test results corresponding to the target function.

[0010] In one embodiment, after determining the test result corresponding to the updated neural network operator, the method further includes: If the test result corresponding to the updated neural network operator is the same as the preset standard result, the target function, the target software language description, the decorator of the target function and the target class are converted into an abstract syntax tree description through the interpreter of the target software language; Convert the abstract syntax tree description into the underlying language description through the interpreter of the target software language; Write the low-level language description into the hardware device.

[0011] In one embodiment, the hardware device is a neural network processor, the domain-specific language includes hardware primitives, the syntax of the domain-specific language is a subset of the syntax of the target software language, and the target software language is Python.

[0012] In a second aspect, the present disclosure provides an operator testing device, comprising: A first processing module is used to obtain an original neural network operator and a target software language description, wherein the original neural network operator is described by a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by language conversion of hardware primitives in the target function using the target software language, and the hardware primitives are used to represent primitives related to hardware devices; The second processing module is used to determine a decorator of the target function, where the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; The third processing module is used to update the original neural network operator based on the target software language description, the decorator of the target function and the target class to obtain an updated neural network operator; The fourth processing module is used to test the updated neural network operator in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator.

[0013] In a third aspect, the present disclosure provides an electronic device, including: a processor, a memory, and a bus; A bus, used to connect the processor and memory; A memory, used for storing operation instructions; The processor is used to execute the operator testing method of the first aspect of the present disclosure by calling an operation instruction.

[0014] In a fourth aspect, the present disclosure provides a computer-readable storage medium storing a computer program, wherein the computer program is used to execute the operator testing method of the first aspect of the present disclosure.

[0015] In a fifth aspect, the present disclosure provides a computer program product, including a computer program, which implements the steps of the operator testing method in the first aspect of the present disclosure when the computer program is executed by a processor.

[0016] The technical solution provided by the embodiments of the present disclosure has at least the following beneficial effects: The original neural network operator and the target software language description are obtained, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, the target software language description is obtained by language conversion of the hardware primitives in the target function using the target software language, and the hardware primitives are used to represent primitives related to the hardware device; the decorator of the target function is determined, the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator; the updated neural network operator is tested in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator; thus, by obtaining the updated neural network operator, the updated neural network operator described in the domain-specific language can be run using an interpreter of the target software language (such as Python), and the correctness of the updated neural network operator can be quickly debugged and verified, thus significantly reducing the development difficulty and debugging difficulty of the neural network operator, improving the testing efficiency of the neural network operator, and enabling users to use the target software language to develop a neural network operator that can be deployed on a hardware device. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for describing the embodiments of the present disclosure are briefly introduced below.

[0018] Figure 1 A schematic diagram of the architecture of an operator testing system provided in an embodiment of the present disclosure; Figure 2 A flowchart of an operator testing method provided in an embodiment of the present disclosure; Figure 3 A flowchart of an operator testing method provided in an embodiment of the present disclosure; Figure 4 A schematic diagram of the structure of an operator testing device provided in an embodiment of the present disclosure; Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0019] The embodiments of the present disclosure are described below in conjunction with the drawings in the present disclosure. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present disclosure and do not constitute a limitation on the technical solutions of the embodiments of the present disclosure.

[0020] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present disclosure refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" indicates that it is implemented as "A", or implemented as "B", or implemented as "A and B".

[0021] It is understandable that in the specific implementation of the present disclosure, data related to operator testing is involved. When the above embodiments of the present disclosure are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0022] In order to make the objectives, technical solutions and advantages of the present disclosure more clear, the embodiments of the present disclosure will be further described in detail below with reference to the accompanying drawings.

[0023] The embodiment of the present disclosure is an operator testing method provided by an operator testing system, and the operator testing method relates to fields such as software testing.

[0024] In order to better understand and illustrate the solutions of the embodiments of the present disclosure, some technical terms involved in the embodiments of the present disclosure are briefly explained below.

[0025] Neural network operators: Deep learning algorithms are composed of multiple computing units, each of which is a neural network operator. Neural network operators correspond to the computing logic of the layers in a neural network. For example, the convolutional layer in a neural network is a neural network, and the weight summation process of the fully connected layer in a neural network is a neural network. For example, tanh, ReLU, etc. are neural network operators used as activation functions in neural networks.

[0026] Decorator: A decorator is used to modify or enhance the behavior of a function or class. A decorator is essentially a function that accepts another function or class as a parameter and returns a new function or class. Decorators are often used to add additional functionality without modifying the original code.

[0027] Python: Python provides efficient high-level data structures and simple and effective object-oriented programming; Python syntax, dynamic typing, and the nature of an interpreted language make Python a programming language for writing scripts and rapidly developing applications on most platforms.

[0028] OpenCL: OpenCL (Open Computing Language) is an open, royalty-free standard for cross-platform parallel programming of a variety of accelerators in supercomputers, cloud servers, personal computers, mobile devices, and embedded platforms.

[0029] C: C language is a process-oriented computer programming language. The design goal of C language is to provide a programming language that can be compiled in an easy way, process low-level memory, generate only a small amount of machine code, and can run without any operating environment support.

[0030] NPU: NPU (Neural network Processing Unit) is an embedded neural network processor.

[0031] pdb: Python debugging module pdb (python debugger) is a standard library that comes with Python. pdb can be used to debug programs.

[0032] The reasons why existing technologies cannot run DSL descriptions of neural network operators through Python interpreters include: (1) In general, when using DSL to describe function calls in neural network operators, it is difficult to determine whether the called function needs to be converted into hardware device-side code (underlying language description) or just run on the host side (server); (2) The DSL description of neural network operators will inevitably use a large number of hardware primitives, and the Python interpreter cannot know the specific implementation of these hardware primitives; (3) For a GPGPU (General-Purpose computing on Graphics Processing Units)-like NPU, there will be multiple threads executing kernel functions. Each thread in the multiple threads runs different data through threadIdx (a built-in index). The Python interpreter directly calls and runs the DSL description only once, so the execution results of the Python interpreter are inconsistent with the execution results of the NPU's multiple threads.

[0033] Based on this, the embodiments of the present disclosure provide an operator testing method, apparatus, device, computer-readable storage medium, and program product. The specific technical solution will be described below.

[0034] The solution provided by the embodiments of the present disclosure relates to operator testing technology. The technical solution of the present disclosure is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present disclosure will be described below in conjunction with the accompanying drawings.

[0035] In order to better understand the solution provided by the embodiment of the present disclosure, the solution is described below in conjunction with a specific application scenario.

[0036] In one embodiment, Figure 1 FIG. 1 shows a schematic diagram of the architecture of an operator testing system applicable to an embodiment of the present disclosure. It can be understood that the operator testing method provided by the embodiment of the present disclosure can be applied to, but not limited to, Figure 1 In the application scenario shown.

[0037] In this example, Figure 1 As shown, the architecture of the operator testing system in this example may include but is not limited to a server 10, a terminal 20 and a database 30. The server 10, the terminal 20 and the database 30 may interact with each other through a network 40.

[0038] The server 10 obtains the original neural network operator and the target software language description, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by converting the hardware primitives in the target function into a language using the target software language, and the hardware primitives are used to represent primitives related to hardware devices; the server 10 determines the decorator of the target function, and the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; the server 10 updates the original neural network operator based on the target software language description, the decorator of the target function, and the target class to obtain an updated neural network operator; the server 10 tests the updated neural network operator in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator. The server 10 sends the test result corresponding to the updated neural network operator to the terminal 20 for progress display, and the server 10 sends the test result corresponding to the updated neural network operator to the database 30 for storage.

[0039] It is understandable that the above is only an example and this embodiment is not limited here.

[0040] Among them, terminals include but are not limited to smart phones (such as Android phones, iOS phones, etc.), mobile phone simulators, tablet computers, laptops, digital broadcast receivers, MIDs (Mobile Internet Devices), PDAs (Personal Digital Assistants), intelligent voice interaction devices, smart home appliances, car terminals, etc.

[0041] The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server or server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms.

[0042] The above network may include but is not limited to: wired network, wireless network, wherein the wired network includes: local area network, metropolitan area network and wide area network, and the wireless network includes: Bluetooth, Wi-Fi and other networks that realize wireless communication. The specific can also be determined based on the actual application scenario requirements and is not limited here.

[0043] See also Figure 2 , Figure 2 The flowchart of an operator testing method provided by an embodiment of the present disclosure is shown, wherein the method can be executed by any electronic device, such as a server, etc.; as an optional implementation, the method can be executed by a server. For the convenience of description, in the description of some optional embodiments below, the method will be executed by a server as an example of the execution subject of the method. Figure 2 As shown, the operator testing method provided by the embodiment of the present disclosure includes the following steps: S201, obtaining an original neural network operator and a target software language description, wherein the original neural network operator is described by a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by converting the hardware primitives in the target function into the target software language, and the hardware primitives are used to represent primitives related to hardware devices.

[0044] Specifically, the domain-specific language includes hardware primitives, and the syntax of the domain-specific language is a subset of the syntax of the target software language, such as Python. The original neural network operator may include multiple target functions, and each of the multiple target functions includes a hardware primitive. For example, the hardware device manufacturer provides a target software language description corresponding to the hardware primitive in each target function, and the target software language description is, for example, a Python description, and the Python description is a software implementation of the hardware primitive that can be run by the Python interpreter; the hardware device manufacturer uses Python to convert the hardware primitive in the target function into a corresponding Python description, and the Python description can be a piece of Python code.

[0045] Hardware primitives such as S.dma_copy, S.alloc_buffer, etc.; among them, S.dma_copy is used to copy data in global memory to the local SRAM buffer, and S.alloc_buffer is used to allocate the local SRAM buffer.

[0046] S202, determining a decorator of the target function, the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class.

[0047] Specifically, the decorator of the target function includes the target object of the target class, the label of the object of the target class, etc. For example, the decorator prim_func is as follows: def prim_func(func=None): obj = PyPrimFunc(func) obj.hw_flag=True ... return obj It should be noted that the target function is such as func, the decorator is such as prim_func, the target class is such as PyPrimFunc, the target object of the target class is such as obj=PyPrimFunc(func), and the label of the object of the target class is such as obj.hw_flag=True.

[0048] For example, the target class PyPrimFunc looks like this: class PyPrimFunc: def __init__(self, py_func): #The target function py_func described by the incoming DSL; self.py_func = py_func def __call__(self, *args): #The __call__ method needs to be implemented so that the Python interpreter can directly execute the target class; #In order to simulate GPGPU, multiple instances need to be run in multiple threads; with context: threads=[Thread(targets=self.py_func, args=args)for_in range(threads_size)] It should be noted that, the target function is such as py_func, and the calling method is such as the __call__ method. If the multi-threaded operation of the target function py_func of GPGPU is to be simulated, the __call__ method can start multiple threads, and the multiple threads simultaneously run the target function py_func described by the DSL, so as to simulate the multi-threaded operation of the target function py_func of GPGPU, that is, the calling method __call__ method is used by the interpreter of the target software language python to call the object obj=PyPrimFunc(func) of the target class, and run the function func corresponding to the object obj=PyPrimFunc(func) of the target class in multi-threaded operation, where func is py_func; threads represents threads, and threads-size represents the number of threads. For example, the number of threads is 10, that is, the multi-threading is 10 threads.

[0049] S203, based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator.

[0050] Specifically, for example, the target software language description, the decorator of the objective function, and the target class are written into the original neural network operator to obtain an updated neural network operator, which includes the original neural network operator, the target software language description, the decorator of the objective function, and the target class.

[0051] S204, testing the updated neural network operator in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator.

[0052] Specifically, the target software language is, for example, python; for example, the updated neural network operator is tested in a python test mode, that is, the updated neural network operator is run through a python interpreter to obtain a test result corresponding to the updated neural network operator.

[0053] In an embodiment of the present disclosure, an original neural network operator and a target software language description are obtained, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, the target software language description is obtained by language conversion of hardware primitives in the target function using the target software language, and the hardware primitives are used to characterize primitives related to hardware devices; a decorator of the target function is determined, the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator; the updated neural network operator is tested in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator; in this way, by obtaining the updated neural network operator, it is realized that the updated neural network operator described in the domain-specific language is run by an interpreter of the target software language (such as Python), and the correctness of the updated neural network operator can be quickly debugged and verified, so that the development difficulty and debugging difficulty of the neural network operator are significantly reduced, and the testing efficiency of the neural network operator is improved, so that users can use the target software language to develop a neural network operator that can be deployed on a hardware device.

[0054] In one embodiment, before determining the decorator of the original neural network operator, the method further includes: Construct a target class, the target class includes a calling method, and the calling method is used for the interpreter of the target software language to call the object of the target class and run the function corresponding to the object of the target class in multiple threads.

[0055] Specifically, for example, the target class PyPrimFunc looks like this: class PyPrimFunc: def __init__(self, py_func): #The target function py_func described by the incoming DSL; self.py_func = py_func def __call__(self, *args): #The __call__ method needs to be implemented so that the Python interpreter can directly execute the target class; #In order to simulate GPGPU, multiple instances need to be run in multiple threads; with context: threads=[Thread(targets=self.py_func, args=args)for_in range(threads_size)] For example, the decorator prim_func looks like this: def prim_func(func=None): obj = PyPrimFunc(func) obj.hw_flag=True return obj It should be noted that, the target function is, for example, py_func, and the calling method is, for example, the __call__ method. If the multi-threaded operation of the target function py_func of GPGPU is to be simulated, the __call__ method can start multiple threads, and the multiple threads simultaneously run the target function py_func described by the DSL, so as to simulate the multi-threaded operation of the target function py_func of GPGPU, that is, the calling method __call__ method is used by the interpreter of the target software language python to call the object obj=PyPrimFunc(func) of the target class, and run the function func corresponding to the object obj=PyPrimFunc(func) of the target class in multi-threaded operation, where func is py_func; threads represents threads, and threads-size represents the number of threads, for example, the number of threads is 10, that is, the multi-threading is 10 threads; in the prior art, the python interpreter cannot directly call the object obj=PyPrimFunc(func) of the target class generated after the decorator prim_func is decorated, so the embodiment of the present disclosure implements the __call__ method in the target class PyPrimFunc, thereby enabling the python interpreter to call the target function func.

[0056] In one embodiment, based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator, including: Writing the target software language description, the decorator of the target function, and the target class into the original neural network operator to obtain an updated neural network operator; Among them, the decorator of the objective function also includes the label of the object of the target class, and the label is used to represent that if the objective function is called in the neural network operator after the objective function is updated and the called function is language converted to obtain the underlying language description corresponding to the called function, then the objective function is language converted to obtain the underlying language description corresponding to the objective function.

[0057] Specifically, for example, the target software language description, the decorator of the objective function, and the target class are written into the original neural network operator to obtain an updated neural network operator, which includes the original neural network operator, the target software language description, the decorator of the objective function, and the target class.

[0058] For example, the decorator prim_func looks like this: def prim_func(func=None): obj = PyPrimFunc(func) obj.hw_flag=True return obj It should be noted that the target function is such as func, the decorator is such as prim_func, the target class is such as PyPrimFunc, the target object of the target class is such as obj=PyPrimFunc(func), and the label of the object of the target class is such as obj.hw_flag=True; the decorator prim_func of the target function func also includes the label obj.hw_flag=True of the object of the target class obj=PyPrimFunc(func), and the label obj.hw_flag=True is used to represent that if the target function func is called in the updated neural network operator and the calling function performs language conversion to obtain the underlying language description corresponding to the calling function, then the target function func is subjected to language conversion to obtain the underlying language description corresponding to the target function.

[0059] For example, a decorator prim_func is used to decorate the target function func described by the DSL. The decorator’s function includes tagging the target function func with obj.hw_flag=True, that is, the label obj.hw_flag=True of the target class object obj=PyPrimFunc(func). The label obj.hw_flag=True indicates that the target function func is called by the called function and the calling function performs language conversion to obtain the underlying language description corresponding to the calling function. The target function func is converted to the underlying language description corresponding to the target function, that is, the target function func will be converted to the underlying language description executed on the NPU. The low-level language description of the line, in this way, it is possible to distinguish through labels that some called functions (such as the target function func) need to be converted into C or hardware instructions, and other functions (such as ordinary Python functions, ordinary Python functions do not have hardware primitives, ordinary Python functions such as helper functions) only need to be evaluated on the host side (server) and do not need to be converted into C or hardware instructions; the role of the decorator also includes encapsulating the target function func into an object of a class obj=PyPrimFunc(func), and the object of this class obj=PyPrimFunc(func) serves as the context for subsequent multi-threaded parallel execution of the target function func.

[0060] In one embodiment, the updated neural network operator is tested in a test mode of the target software language to determine the test result corresponding to the updated neural network operator, including: Through the interpreter of the target software language, the target object of the target class is called based on the calling method, the target function and the target software language description are run in multiple threads, and the test results corresponding to the target function are obtained. The test results corresponding to the updated neural network operator include the test results corresponding to the target function.

[0061] Specifically, for example, for some hardware primitives, such as S.alloc_buffer, S.dma_copy, etc., these hardware primitives do not have software implementations. When the Python interpreter runs the statements of these hardware primitives without software implementations, an error will be reported; therefore, it is necessary to register the software implementation corresponding to the hardware primitives, and the software implementation of the hardware primitives needs to ensure that the behavior of the software implementation is consistent with the behavior of the hardware primitives. The software implementation of the hardware primitives is described in the target software language; in this way, it is guaranteed that the Python description corresponding to the hardware primitives used in the target function described by the DSL and the Python description corresponding to the hardware primitives can be run on the Python interpreter.

[0062] For example, the software implementation of the registered hardware primitive S.dma_copy (target software language description, i.e., Python description) adds assertion to the software implementation of the registered hardware primitive S.dma_copy, and debugs in the software implementation of the hardware primitive to ensure that the hardware specification limits will still report errors when the software is running. For example, illegal input will report errors when the Python interpreter is running. In this way, corresponding checks can be added to the software implementation of the registered hardware primitive S.dma_copy, which can not only ensure the correctness of the parameters, but also eliminate the need for corresponding checks during the operation of the hardware device (such as NPU), thereby improving the testing efficiency of the neural network operator.

[0063] For example, registering the software implementation of the hardware primitive S.dma_copy is as follows: @register_ir_api Def _py_dma_copy(dst, src, width, src_stride=None, times=1, dst_stride=None): assert src_stride>=width, "Stride need greater equal than width" It should be noted that dst: target memory address or array, data will be copied here; src: source memory address or array, data will be copied from here; width: data width of each copy (unit: number of elements); src_stride: stride of source data (that is, the number of elements the source pointer moves after each copy), if not specified, the default is width; times: number of copies; dst_stride: stride of target data (that is, the number of elements the target pointer moves after each copy), if not specified, the default is width; assertion is added in the software implementation of the registered hardware primitive S.dma_copy to debug in the software implementation of the hardware primitive.

[0064] For example, before compiling the updated neural network operator into the underlying language, the updated neural network operator is run through the Python interpreter. Since the updated neural network operator can be run directly on Python, various debugging libraries on Python can be reused, such as pdb (python debugger, Python debugging module), etc., and Python breakpoints and other means can be used to debug the correct neural network operator on Python and deploy the correct neural network operator to the NPU. Because the entire debugging process is implemented on Python, it can greatly reduce the threshold and difficulty of developing and debugging neural network operators, thereby improving the testing efficiency of neural network operators.

[0065] In one embodiment, after determining the test result corresponding to the updated neural network operator, the method further includes: If the test result corresponding to the updated neural network operator is the same as the preset standard result, the target function, the target software language description, the decorator of the target function and the target class are converted into an abstract syntax tree description through the interpreter of the target software language; Convert the abstract syntax tree description into the underlying language description through the interpreter of the target software language; Write the low-level language description into the hardware device.

[0066] Specifically, the target software language is such as Python, the underlying language is such as C or OpenCL, and the hardware device is such as NPU.

[0067] For example, a python interpreter can directly run the updated neural network operator and ensure that the software behavior or test result of each line of python code is consistent with the hardware device; in this way, the user can directly debug the updated neural network operator as an ordinary python program without debugging C code or hardware instructions; because the software behavior is consistent with the corresponding hardware behavior, the running result of the debugged software is correct, that is, the test result corresponding to the updated neural network operator is the same as the preset standard result, which means that the running result of the updated neural network operator on the hardware device is correct.

[0068] In one embodiment, the hardware device is a neural network processor, the domain-specific language includes hardware primitives, the syntax of the domain-specific language is a subset of the syntax of the target software language, and the target software language is Python.

[0069] The application of the embodiments of the present disclosure has at least the following beneficial effects: By obtaining the updated neural network operator, it is possible to use the interpreter of the target software language (such as Python) to run the updated neural network operator described in the domain-specific language, and quickly debug and verify the correctness of the updated neural network operator. This significantly reduces the difficulty of developing and debugging the neural network operator, improves the testing efficiency of the neural network operator, and enables users to use the target software language to develop a neural network operator that can be deployed on hardware devices.

[0070] In order to better understand the method provided by the embodiment of the present disclosure, the solution of the embodiment of the present disclosure is further described below with reference to examples of specific application scenarios.

[0071] The method provided in the embodiment of the present disclosure implements a domain-specific language similar to Python to quickly implement neural network operators. At the same time, the neural network operators described by DSL can be run through the Python interpreter to quickly debug or verify the correctness of the neural network operators; the method can be used in all application fields of NPU, such as IoT devices (Internet of Things devices), mobile (mobile devices), automotive (autonomous driving systems), wearable devices, etc.; the method can significantly reduce the development difficulty and debugging difficulty of neural network operators, and users can develop neural network operators that can be deployed on NPU through Python; during debugging, the neural network operators described by DSL can be run through the Python interpreter to debug or verify the results of the operators, thereby improving the development efficiency of neural network operators.

[0072] In a specific application scenario embodiment, such as a neural network operator testing scenario, see Figure 3 , shows a processing flow of an operator testing method, such as Figure 3 As shown, the processing flow of the operator testing method provided by the embodiment of the present disclosure includes the following steps: S301, the server obtains the original neural network operator described in a domain-specific language.

[0073] Specifically, for example, the original neural network operator includes an objective function, and the objective function includes hardware primitives.

[0074] S302, the server builds a target class, the target class includes a calling method, and the calling method is used for the Python interpreter to call the object of the target class and run the function corresponding to the object of the target class in multi-threaded manner.

[0075] Specifically, for example, by implementing the __call__ method (calling method) in the target class PyPrimFunc, the Python interpreter can call the function func (the object of the target class PyPrimFunc).

[0076] S303, the server determines a decorator of the target function, where the decorator of the target function includes a target object of the target class and a label of the object of the target class.

[0077] Specifically, for example, the decorator prim_func of the target function func includes the target object obj=PyPrimFunc(func) of the target class, the label obj.hw_flag=True of the object of the target class, and the like.

[0078] S304, the server obtains the software implementation of the hardware primitives in the target function.

[0079] Specifically, for example, the hardware device manufacturer provides the server with a Python description (target software language description) corresponding to the hardware primitives in the target function. The Python description is a software implementation of the hardware primitives that can be run by the Python interpreter. The Python description can be a piece of Python code.

[0080] S305, the server updates the original neural network operator based on the software implementation of the hardware primitives in the objective function, the decorator of the objective function and the target class to obtain an updated neural network operator.

[0081] Specifically, for example, the software implementation of the hardware primitives in the objective function, the decorator of the objective function, and the target class are written into the original neural network operator to obtain an updated neural network operator. The updated neural network operator includes the original neural network operator, the software implementation of the hardware primitives in the objective function, the decorator of the objective function, the target class, etc.

[0082] S306, the server tests the updated neural network operator through the Python interpreter to determine the test result corresponding to the updated neural network operator.

[0083] Specifically, through the interpreter of the target software language, the target object of the target class is called based on the calling method, the target function and the target software language description are run in multiple threads, and the test results corresponding to the target function are obtained. The test results corresponding to the updated neural network operator include the test results corresponding to the target function.

[0084] S307: If the test result corresponding to the updated neural network operator is the same as the standard result, the server writes the underlying language description corresponding to the updated neural network operator into the hardware device.

[0085] Specifically, if the test result corresponding to the updated neural network operator is the same as the preset standard result, the target function, the target software language description, the decorator of the target function and the target class are converted into an abstract syntax tree description through the interpreter of the target software language; the abstract syntax tree description is converted into a low-level language description through the interpreter of the target software language; and the low-level language description is written into the hardware device.

[0086] The application of the embodiments of the present disclosure has at least the following beneficial effects: By obtaining the updated neural network operator, it is possible to use the interpreter of the target software language (such as Python) to run the updated neural network operator described in the domain-specific language, and quickly debug and verify the correctness of the updated neural network operator. This significantly reduces the difficulty of developing and debugging the neural network operator, improves the testing efficiency of the neural network operator, and enables users to use the target software language to develop a neural network operator that can be deployed on hardware devices.

[0087] The present disclosure also provides an operator testing device. The structural diagram of the operator testing device is as follows: Figure 4 As shown, the operator testing device 60 includes a first processing module 601 , a second processing module 602 , a third processing module 603 and a fourth processing module 604 .

[0088] The first processing module 601 is used to obtain an original neural network operator and a target software language description, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by converting the hardware primitives in the target function into a language using the target software language, and the hardware primitives are used to represent primitives related to hardware devices; The second processing module 602 is used to determine a decorator of the target function, where the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; The third processing module 603 is used to update the original neural network operator based on the target software language description, the decorator of the target function and the target class to obtain an updated neural network operator; The fourth processing module 604 is used to test the updated neural network operator in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator.

[0089] In one embodiment, the second processing module 602 is further configured to: Construct a target class, the target class includes a calling method, and the calling method is used for the interpreter of the target software language to call the object of the target class and run the function corresponding to the object of the target class in multiple threads.

[0090] In one embodiment, the third processing module 603 is specifically configured to: Writing the target software language description, the decorator of the target function, and the target class into the original neural network operator to obtain an updated neural network operator; Among them, the decorator of the objective function also includes the label of the object of the target class, and the label is used to represent that if the objective function is called in the neural network operator after the objective function is updated and the called function is language converted to obtain the underlying language description corresponding to the called function, then the objective function is language converted to obtain the underlying language description corresponding to the objective function.

[0091] In one embodiment, the fourth processing module 604 is specifically configured to: Through the interpreter of the target software language, the target object of the target class is called based on the calling method, the target function and the target software language description are run in multiple threads, and the test results corresponding to the target function are obtained. The test results corresponding to the updated neural network operator include the test results corresponding to the target function.

[0092] In one embodiment, the fourth processing module 604 is further configured to: If the test result corresponding to the updated neural network operator is the same as the preset standard result, the target function, the target software language description, the decorator of the target function and the target class are converted into an abstract syntax tree description through the interpreter of the target software language; Convert the abstract syntax tree description into the underlying language description through the interpreter of the target software language; Write the low-level language description into the hardware device.

[0093] In one embodiment, the hardware device is a neural network processor, the domain-specific language includes hardware primitives, the syntax of the domain-specific language is a subset of the syntax of the target software language, and the target software language is Python.

[0094] The application of the embodiments of the present disclosure has at least the following beneficial effects: The original neural network operator and the target software language description are obtained, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, the target software language description is obtained by language conversion of the hardware primitives in the target function using the target software language, and the hardware primitives are used to represent primitives related to the hardware device; the decorator of the target function is determined, the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator; the updated neural network operator is tested in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator; thus, by obtaining the updated neural network operator, the updated neural network operator described in the domain-specific language can be run using an interpreter of the target software language (such as Python), and the correctness of the updated neural network operator can be quickly debugged and verified, thus significantly reducing the development difficulty and debugging difficulty of the neural network operator, improving the testing efficiency of the neural network operator, and enabling users to use the target software language to develop a neural network operator that can be deployed on a hardware device.

[0095] The present disclosure also provides an electronic device. The structural diagram of the electronic device is as follows: Figure 5 As shown, Figure 5 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present disclosure.

[0096] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of the present invention. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0097] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0098] The memory 4003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation herein.

[0099] The memory 4003 is used to store the computer program for executing the embodiment of the present disclosure, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the above method embodiment.

[0100] Among them, electronic equipment includes but is not limited to: servers, etc.

[0101] The application of the embodiments of the present disclosure has at least the following beneficial effects: The original neural network operator and the target software language description are obtained, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, the target software language description is obtained by language conversion of the hardware primitives in the target function using the target software language, and the hardware primitives are used to represent primitives related to the hardware device; the decorator of the target function is determined, the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function through the target class; based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator; the updated neural network operator is tested in a test mode of the target software language to obtain a test result corresponding to the updated neural network operator; thus, by obtaining the updated neural network operator, the updated neural network operator described in the domain-specific language can be run using an interpreter of the target software language (such as Python), and the correctness of the updated neural network operator can be quickly debugged and verified, thus significantly reducing the development difficulty and debugging difficulty of the neural network operator, improving the testing efficiency of the neural network operator, and enabling users to use the target software language to develop a neural network operator that can be deployed on a hardware device.

[0102] An embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.

[0103] The embodiments of the present disclosure also provide a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiments when executed by a processor.

[0104] It should be understood that, although the flowchart of the embodiment of the present disclosure indicates each operation step by arrows, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present disclosure, the implementation steps in each flowchart can be executed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage in these sub-steps or stages can also be executed at different times. In scenarios with different execution times, the execution order of these sub-steps or stages can be flexibly configured according to demand, and the embodiment of the present disclosure does not limit this.

[0105] The above is only an optional implementation method for some implementation scenarios of the present disclosure. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the scheme of the present disclosure, other similar implementation methods based on the technical ideas of the present disclosure are also within the protection scope of the embodiments of the present disclosure.

Claims

1. An operator testing method, characterized in that: include: Obtaining an original neural network operator and a target software language description, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by converting a hardware primitive in the target function into a language using the target software language, and the hardware primitive is used to represent a primitive related to a hardware device; Determine a decorator of the objective function, wherein the decorator of the objective function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the objective function by the target class; Based on the target software language description, the decorator of the target function and the target class, the original neural network operator is updated to obtain an updated neural network operator; The updated neural network operator is tested in a test mode of a target software language to obtain a test result corresponding to the updated neural network operator.

2. The method according to claim 1, characterized in that Before determining the decorator of the original neural network operator, the method further includes: The target class is constructed, and the target class includes a calling method, and the calling method is used by the interpreter of the target software language to call the object of the target class and run the function corresponding to the object of the target class in multi-threaded manner.

3. The method according to claim 1, characterized in that The updating of the original neural network operator based on the target software language description, the decorator of the target function and the target class to obtain an updated neural network operator includes: Writing the target software language description, the decorator of the target function and the target class into the original neural network operator to obtain an updated neural network operator; Among them, the decorator of the objective function also includes the label of the object of the target class, and the label is used to represent that if the objective function is called by the calling function in the updated neural network operator and the calling function performs language conversion to obtain the underlying language description corresponding to the calling function, then the objective function is language converted to obtain the underlying language description corresponding to the objective function.

4. The method according to claim 2, characterized in that: The step of testing the updated neural network operator in a test mode of a target software language to determine a test result corresponding to the updated neural network operator includes: Through the interpreter of the target software language, the target object of the target class is called based on the calling method, and the target function and the target software language description are run in multiple threads to obtain the test results corresponding to the target function, and the test results corresponding to the updated neural network operator include the test results corresponding to the target function.

5. The method according to claim 1, characterized in that After determining the test result corresponding to the updated neural network operator, the method further includes: If the test result corresponding to the updated neural network operator is the same as the preset standard result, converting the target function, the target software language description, the decorator of the target function and the target class into an abstract syntax tree description through the interpreter of the target software language; Converting the abstract syntax tree description into an underlying language description by an interpreter of the target software language; The low-level language description is written into the hardware device.

6. The method according to any one of claims 1 to 5, characterized in that The hardware device is a neural network processor, the domain-specific language includes the hardware primitives, the syntax of the domain-specific language is a subset of the syntax of the target software language, and the target software language is Python.

7. An operator testing device, characterized in that: include: A first processing module is used to obtain an original neural network operator and a target software language description, wherein the original neural network operator is described in a domain-specific language, the original neural network operator includes a target function, and the target software language description is obtained by converting a hardware primitive in the target function into a language using the target software language, and the hardware primitive is used to represent a primitive related to a hardware device; A second processing module is used to determine a decorator of the target function, wherein the decorator of the target function includes a target object of a preset target class, and the target object of the target class is obtained by encapsulating the target function by the target class; A third processing module is used to update the original neural network operator based on the target software language description, the decorator of the target function and the target class to obtain an updated neural network operator; The fourth processing module is used to test the updated neural network operator in a test mode of a target software language to obtain a test result corresponding to the updated neural network operator.

8. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 6.

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

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Operator unloading and registering method and device, storage medium and electronic device

    CN114398095A

  • Platform framework extension method and device and storage medium

    CN116360712A

  • Operator testing method and device, nonvolatile storage medium and electronic equipment

    CN116501642A

  • Lightweight image quality evaluation method and system based on convolutional neural network pruning

    CN117372387A