Method for generating target code, method and device for displaying NPU instructions

By analyzing and mapping the field properties and initial code functions of NPU instructions, the object code is generated, and the problem of large workload of NPU instruction code development and maintenance in the existing technology is solved, and the convenient generation and efficient maintenance of code are achieved.

CN116028062BActive Publication Date: 2025-05-30YAOYAO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310043431.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2022-10-25
Filing Date
2023-01-26
Publication Date
2025-05-30
Estimated Expiration
2043-01-26

AI Technical Summary

Technical Problem

The existing code development and maintenance workload for assembling NPU instructions is large, and the response speed to instruction set changes is slow, resulting in inconvenient development and maintenance.

Method used

By obtaining the target NPU instructions, the target description data and the initial code, parsing the instruction fields and field properties, establishing a mapping relationship between the instruction fields and the initial code function, receiving the target value input by the user, and writing the initial code to generate the target code.

Benefits of technology

It realizes automatic generation of code for assembling and parsing NPU instructions, reducing the workload of manual development, improving the convenience and maintenance efficiency of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116028062B_ABST
    Figure CN116028062B_ABST
Patent Text Reader

Abstract

The present application provides a method for generating target code, a method and device for displaying NPU instructions. The method for generating target code includes: parsing target NPU instructions based on target description data to obtain at least one instruction field and multiple preset type field attributes in each instruction field, establishing a first type of mapping relationship between each instruction field and a function in the initial code in a first preset order, and receiving first type of target values corresponding to each instruction field input by a user, and writing the first type of target values into the initial code based on the first type of mapping relationship and the preset type field attributes to obtain target code. The present application abstractly represents NPU instructions to obtain target NPU instructions. Through the above method for generating target code, code for assembling and parsing instructions can be automatically generated, eliminating the need for manual development of code for assembling and parsing instructions. Code development and maintenance are convenient and the workload is small.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a method for generating target code, a method and device for displaying NPU instructions. Background Art

[0002] A neural network processor instruction (Neural network Processing Unit, abbreviated as NPU) is code for performing a specific operation within an NPU chip. There are several instruction fields in an NPU instruction to respectively represent the function of the instruction and the corresponding parameters. The position, length, and possible fixed values of the instruction fields in the instruction vary depending on the instruction format. The NPU instruction set is a set of all instruction formats supported by an NPU.

[0003] Regarding the generation method of NPU instructions, currently, mainly a supporting instruction generation tool is developed for each NPU instruction set. In the instruction generation tool, corresponding program code is developed according to the format of each instruction to assemble the instruction fields to generate specific NPU instruction code, resulting in a large amount of code development and maintenance work. In the initial stage of instruction set design, the instruction set is updated and iterated frequently, and the corresponding instruction generation tool has a slow response speed to such changes in the instruction set.

[0004] Therefore, the existing code for assembling instructions has technical problems such as inconvenient development and maintenance and a large amount of work. Summary of the Invention

[0005] To solve the above technical problems, this application provides a method for generating target code, a method and device for displaying NPU instructions. The specific solutions are as follows:

[0006] In a first aspect, an embodiment of this application provides a method for generating target code. The method for generating target code includes:

[0007] Obtain a target NPU instruction, target description data corresponding to the target NPU instruction, and an initial code, where the target NPU instruction includes at least one instruction field, each instruction field includes multiple preset types of field attributes, the preset types include a field name, a field start bit, and a number of bits corresponding to the field, and the initial code includes at least one callable function;

[0008] Parse the target NPU instruction based on the target description data to obtain at least one instruction field and multiple preset types of field attributes in each instruction field;

[0009] Establish a first type of mapping relationship between each instruction field and the functions in the initial code in a first preset order;

[0010] Receive the first type of target values corresponding to each of the instruction fields input by the user, and write the first type of target values into the initial code based on the first type of mapping relationship and the field attributes of a preset type to obtain the target code.

[0011] According to a specific implementation manner disclosed in the present application, before the steps of obtaining the target NPU instruction, the target description data corresponding to the target NPU instruction, and the initial code, the method for generating the target code further includes:

[0012] Receive the target NPU instruction input by the user and the initial description data corresponding to the target NPU instruction;

[0013] If the initial format corresponding to the initial description data is different from the preset format, convert the initial description data into target description data in the preset format.

[0014] According to a specific implementation manner disclosed in the present application, the step of establishing the first type of mapping relationship between each of the instruction fields and the functions in the initial code in the first preset order includes:

[0015] Obtain the field names of each instruction field in the first order;

[0016] For any instruction field, convert the field name of the instruction field into the function name in the initial code according to the preset conversion type to obtain the first type of mapping relationship corresponding to the field name and the function name, where the preset conversion type includes copy, mapping, and expansion.

[0017] In a second aspect, an embodiment of the present application provides a method for displaying an NPU instruction, and the method for displaying the NPU instruction includes:

[0018] Obtain a target NPU instruction and target description data corresponding to the target NPU instruction, where the target NPU instruction includes at least one instruction field, and each instruction field includes multiple field attributes of a preset type, and the preset type includes a field start bit and the number of bits corresponding to the field;

[0019] Parse the target NPU instruction based on the target description data to obtain at least one instruction field and multiple field attributes of a preset type in each instruction field;

[0020] Select display elements of a second type from a preset database according to the user input, where the second type includes text, icons, and colors, and each display element of the second type includes an attribute type and an initial attribute value corresponding to the attribute type;

[0021] Establish a second type of mapping relationship between each of the instruction fields and the display elements in the second preset order;

[0022] Receive the second type of target values corresponding to each of the instruction fields input by the user, and update the initial attribute values of the display elements corresponding to each of the instruction fields to the second type of target values based on the second type of mapping relationship, so as to obtain a target NPU instruction with custom display;

[0023] Wherein, the target NPU instruction and the target description data corresponding to the target NPU instruction are obtained according to the method for generating the target code described in any one of claims 1 to 2.

[0024] In a third aspect, an embodiment of the present application provides a device for generating a target code, and the device for generating the target code includes:

[0025] An acquisition module, configured to acquire a target NPU instruction, target description data corresponding to the target NPU instruction, and an initial code corresponding to the target NPU instruction, wherein the target NPU instruction includes at least one instruction field, each of the instruction fields includes a plurality of field attributes of a preset type, the preset type includes a field name, a field start bit, and a number of bits corresponding to the field, and the initial code includes at least one callable function;

[0026] An analysis module, configured to analyze the target NPU instruction based on the target description data to obtain at least one instruction field and a plurality of field attributes of a preset type in each of the instruction fields;

[0027] A mapping module, configured to establish a first type of mapping relationship between each of the instruction fields and the functions in the initial code in a first preset order;

[0028] A writing module, configured to receive the first type of target values corresponding to each of the instruction fields input by the user, and write the first type of target values into the initial code based on the first type of mapping relationship and the field attributes of the preset type to obtain a target code.

[0029] According to a specific implementation manner disclosed in the present application, the device for generating the target code further includes:

[0030] A receiving module, configured to receive a target NPU instruction input by the user and initial description data corresponding to the target NPU instruction;

[0031] A conversion module, configured to convert the initial description data into target description data in a preset format if the initial format corresponding to the initial description data is different from the preset format.

[0032] According to a specific implementation manner disclosed in the present application, the mapping module is specifically configured to:

[0033] Obtain the field names of each instruction field in the first order;

[0034] For any instruction field, convert the field name of the instruction field into the function name in the initial code according to a preset conversion type, to obtain a first type of mapping relationship between the field name and the function name, where the preset conversion type includes copy, mapping, and expansion.

[0035] Fourthly, an embodiment of the present application provides a display device for NPU instructions, and the display device for NPU instructions includes:

[0036] An acquisition module, configured to acquire a target NPU instruction and target description data corresponding to the target NPU instruction, where the target NPU instruction includes at least one instruction field, and each instruction field includes a plurality of field attributes of a preset type, and the preset type includes a field start bit and the number of bits corresponding to the field;

[0037] An analysis module, configured to analyze the target NPU instruction based on the target description data to obtain at least one instruction field and a plurality of field attributes of a preset type in each instruction field;

[0038] A selection module, configured to select display elements of a second type from a preset database according to user input, where the second type includes text, icons, and colors, and each display element of the second type includes an attribute type and an initial attribute value corresponding to the attribute type;

[0039] A mapping module, configured to establish a second type of mapping relationship between each instruction field and the display element in a second preset order;

[0040] An update module, configured to receive second type of target values corresponding to each instruction field input by a user, and update the initial attribute values of the display elements corresponding to each instruction field to the second type of target values based on the second type of mapping relationship, to obtain a target NPU instruction with custom display;

[0041] Wherein, the target NPU instruction and the target description data corresponding to the target NPU instruction are obtained according to the target code generation method described in any one of claims 1 to 2.

[0042] Fifthly, an embodiment of the present application provides a computer device, and the computer device includes a processor and a memory, and the memory stores a computer program, and when the computer program is executed on the processor, it implements the target code generation method described in any one of the first aspects and the NPU instruction display method described in the second aspect.

[0043] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which when executed on a processor implements the method for generating the target code according to any one of the first aspect and the method for displaying NPU instructions according to the second aspect.

[0044] Compared with the prior art, the present application has the following beneficial effects:

[0045] The method for generating the target code provided by the present application parses the target NPU instruction based on the target description data to obtain at least one instruction field and multiple preset type field attributes in each instruction field, establishes a first type of mapping relationship between each instruction field and the function in the initial code in a first preset order, and receives the first type of target value corresponding to each instruction field input by the user. Based on the first type of mapping relationship and the preset type of field attributes, the first type of target value is written into the initial code to obtain the target code. The present application abstractly represents the NPU instruction to obtain the target NPU instruction. Through the above method for generating the target code, the code for assembling and parsing the NPU instruction can be automatically generated, eliminating the need for manual development of the code for assembling and parsing the NPU instruction. The code development and maintenance are convenient and the workload is small. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions of the embodiments disclosed in the present application, the following will briefly introduce the drawings required for the embodiments. Obviously, the drawings in the following description are only some embodiments disclosed in the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0047] Figure 1 It is a schematic flowchart of a method for generating a target code provided by an embodiment of the present application;

[0048] Figure 2 It is a schematic data structure diagram of instructions and instruction sets involved in a method for generating a target code provided by an embodiment of the present application;

[0049] Figure 3 It is a schematic flowchart of a method for displaying NPU instructions provided by an embodiment of the present application;

[0050] Figure 4 It is a block diagram of modules of a device for generating a target code provided by an embodiment of the present application;

[0051] Figure 5 It is a block diagram of modules of a device for displaying NPU instructions provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0052] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments.

[0053] Generally, the components of the embodiments of the present invention described and illustrated herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts belong to the scope of protection of the present invention.

[0054] In the following, the terms "including", "having" and their cognates that can be used in various embodiments of the present invention are only intended to represent specific features, numbers, steps, operations, elements, components or combinations of the foregoing items, and should not be construed as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or combinations of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or combinations of the foregoing items.

[0055] In addition, the terms "first", "second", "third", etc. are only used for descriptive distinction and cannot be understood as indicating or implying relative importance.

[0056] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art to which the various embodiments of the present invention belong. The terms (such as those defined in a general-use dictionary) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized meaning or being overly formal, unless clearly defined in the various embodiments of the present invention.

[0057] Next, some embodiments of the present application will be described in detail in conjunction with the accompanying drawings. Without conflict, the following embodiments and the features in the embodiments can be combined with each other.

[0058] See Figure 1 , Figure 1 which is a schematic flowchart of a method for generating an object code provided by an embodiment of the present application. As Figure 1 shown, the method for generating an object code mainly includes:

[0059] Step S101, obtain a target NPU instruction, target description data corresponding to the target NPU instruction, and initial code, where the target NPU instruction includes at least one instruction field, and each instruction field includes multiple field attributes of a preset type. The preset type includes a field name, a field start bit, and a number of bits corresponding to the field. The initial code includes at least one callable function.

[0060] It should be noted that the "target NPU instruction and the initial code corresponding to the target NPU instruction" refers to the code that can be executed as an instruction by the NPU, generally in the form of binary data. The target description data refers to the "data describing the format of the NPU instruction". In other words, these description data are used to describe the NPU instruction and are generally stored in a text file. These description data cannot be executed as an instruction by the NPU.

[0061] An example is given to illustrate the difference between the two:

[0062] In the NPU instruction, the value in the instruction field is determined. For example, in a subtraction instruction, the instruction content contains the specific values of the minuend and the subtrahend, or the positions of these values in the memory. For example, the subtraction instruction can be: 0b00011000000010000000000000000000;

[0063] In the description data of the NPU instruction, it only describes what fields a certain instruction has, and where the values of each instruction field are stored in the content of an NPU instruction, without caring about the specific values of the instruction fields. Taking the subtraction instruction as an example again, the NPU instruction description data will state that there are two fields, the minuend and the subtrahend, in the subtraction instruction, where the values of these fields start at which bit in the content of the subtraction instruction, and what the lengths of the fields are in bits. For example, the target description data corresponding to the above subtraction instruction can be:

[0064]

[0065]

[0066] The NPU instructions or NPU instruction sets used by users are all designed according to the user's needs or specific application scenarios, and the formats of the description data corresponding to the NPU instructions used by different users are different. Therefore, before generating the target code according to the instructions, it is necessary to unify the formats of the description data of each instruction.

[0067] Specifically, before the step of obtaining the target NPU instruction, the target description data corresponding to the target NPU instruction, and the initial code, the method for generating the target code further includes:

[0068] Receive the target NPU instruction input by the user and the initial description data corresponding to the target NPU instruction;

[0069] If the initial format corresponding to the initial description data is different from the preset format, convert the initial description data into target description data in the preset format.

[0070] Specifically, the process of converting the initial description data into target description data in the preset format is the abstract representation of the instruction, which can be described and stored in any existing structured file format, such as XML, JSON, YAML format, etc., or other custom file formats that can express structured information regularly. The data content for expressing the instruction set can be stored independently in a single file or as a part of the content of other files.

[0071] See Figure 2 , Figure 2 FIG.

[0072] The first layer is the outermost layer of the abstract representation of the instruction set, and the data structure type it adopts should be able to describe the attributes of an object, and common data types such as structures. The first layer is used to represent the instruction set itself. Among them, there should be at least one data member used to describe the second layer in the abstract representation of the instruction set.

[0073] The second layer is a child of the aforementioned first layer and is used to represent the content part of the instruction set. Logically, it is included by the first layer, and the data structure type it adopts should be a data structure that can express clustering, and common data structures such as arrays. The second layer is used to represent the clustering of instruction formats. Each element in the instruction format clustering is used to represent an instruction format, that is, the aforementioned target NPU instruction. The data type it adopts should be able to describe the attributes of an object, and common data types such as structures. Among them, there should be at least several data members used to describe some information of an instruction format, such as instruction name, instruction length, etc. and a data member used to describe the third layer in the abstract representation of the instruction set.

[0074] The third layer is a child of the aforementioned second layer and is used to represent the content part of the instruction. Logically, it is included by the second layer. The data type it adopts should be a data structure that can express clustering, and common data types such as arrays. The third layer is used to represent the clustering of instruction fields. Each element in the instruction field clustering is used to represent an instruction field, and the data type it adopts should be able to describe the attributes of an object, and common data structures such as structures. Among its data members, there should be several data members used to describe the starting bit position of the instruction field, the number of bits occupied by the instruction field, etc. Figure 2 The instruction fields 1, 2,... N shown in Figure 2 correspond to different instruction fields in the aforementioned target NPU instruction. Each instruction field includes multiple field attributes of a preset type, and the preset type includes a field name, a field start bit, and the number of bits corresponding to the field.

[0075] Step S102: Parse the target NPU instruction based on the target description data to obtain at least one instruction field and multiple field attributes of each instruction field of a preset type.

[0076] In specific implementation, after obtaining the target NPU instruction, the data content of the instruction set described by the abstract representation of the aforementioned instruction set can be read first, and the instruction format clustering can be parsed from it. Then, according to the actual usage requirements of the user or the specific application scenario, an element can be randomly or taken out from the instruction format clustering in a custom order, and the instruction name and the instruction field clustering can be obtained from it.

[0077] Step S103: Establish a first type of mapping relationship between each of the instruction fields and the functions in the initial code in a first preset order.

[0078] Among them, the first preset order can also be customized according to the actual usage requirements of the user or the specific application scenario.

[0079] In specific implementation, for the entire NPU instruction set, the name of the initial code used to assemble the corresponding instruction can be pieced together with the instruction name as the keyword to establish a mapping relationship between the target NPU instruction and the initial code, which is convenient for querying in the subsequent usage process. In addition, to further improve the convenience in the subsequent usage process, the order in which the instruction format appears in the instruction format clustering can also be used as the index identifier of the instruction format. In the actual usage process, the initial code can be understood as a class, a code module, or other equivalent code organization units.

[0080] For a single target NPU instruction, an element can be taken out from the instruction field clustering, and preset type of field attributes such as the name of each instruction field, the starting bit position of the instruction field, and the number of bits occupied by the instruction field can be obtained therefrom. Then, a first type of mapping relationship between each instruction field and the functions in the initial code is established in accordance with a first preset order. Specifically, the name of a member method for obtaining and setting the content of the instruction field, or the name of a function in other equivalent code organization units such as a code module can be pieced together with the instruction field name as the keyword. The step of establishing a first type of mapping relationship between each of the instruction fields and the functions in the initial code in accordance with a first preset order includes:

[0081] Obtain the field names of each instruction field in accordance with the first order;

[0082] For any instruction field, convert the field name of the instruction field into the function name in the initial code according to a preset conversion type, to obtain a first type of mapping relationship corresponding to the field name and the function name, where the preset conversion type includes copy, mapping, and expansion.

[0083] For example, in an actual application scenario, the above "conversion" process includes but is not limited to:

[0084] op_code is directly used;

[0085] op_code is converted to opcode

[0086] op_code is converted to opCode

[0087] op_code is converted to OP_CODE

[0088] op_code is converted to getOpCode

[0089] Similarly, for the convenience of query in the subsequent usage process, the order in which the instruction field appears in the instruction field clustering can be used as the index identifier of the instruction field. In a member method or function, the starting bit position and the number of bits of the instruction field are used as the basis for assembling the instruction field; or the starting bit position of the current instruction field and the starting bit position of the next instruction field are used as the basis for assembling the current instruction field. For example, for the instruction "a + b = c" corresponding to 32 bits, excluding the fixed high 4 bits, the first 7 bits in the remaining 28 bits can be defined as the address corresponding to the addend a, the second 7 bits can be defined as the address corresponding to the addend b, the third 7 bits can be defined as the address corresponding to the result c, and the last 7 bits can be defined as the data type, etc.

[0090] In specific implementation, for a certain NPU instruction or NPU instruction set, repeat the above steps until all instruction fields of the current target NPU instruction are traversed or each target NPU instruction in the current instruction set is traversed.

[0091] Step S104: Receive the first type of target values corresponding to each of the instruction fields input by the user, and write the first type of target values into the initial code based on the first type of mapping relationship and the field attributes of the preset type to obtain the target code.

[0092] It should be noted that the target NPU instruction and the target description data corresponding to the target NPU instruction described above can be understood as a general model or formula. In the subsequent usage process, by inputting the corresponding specific values, the interface of the class can be called to write the specific values, that is, "writing the first type of target values into the initial code", so as to meet the user's usage requirements and obtain the target code in a specific application scenario.

[0093] Taking the subtraction instruction as an example, the overall process of the above target code generation method is as follows:

[0094] The most primitive input is the instruction set description document prepared by the NPU chip designer, and part of its content can be:

[0095] Subtraction instruction: Instruction length is 32bit, instruction identification code is 0x1. The minuend position is 21, with a length of 7bit; the subtrahend position is 14, with a length of 7bit; the result address position is 0, with a length of 14bit; Addition instruction: Instruction length is 32bit, instruction identification code is 0x2...

[0096] Through the above target code generation method of the present application, the instructions in the instruction set are abstractly modeled to obtain an instruction set description document in a target format, that is, the target description data. Then, the target description data is used as the input of the code generation tool, which can be described in file formats such as XML, JSON, YAML, etc. Part of its content can be:

[0097]

[0098] Then the automatically generated code can be:

[0099] class SubtractInstructionHelper{ ...

[0101] / / Set the values of the instruction fields

[0102] void setMinuend(uint32_t);

[0103] void setSubtrahend(uint32_t);

[0104] void setResult(uint32_t);

[0105] uint32_t generate(); / / Generate NPU instructions

[0106] void parse(uint32_t); / / Parse NPU instructions

[0107] / / Obtain the value of the instruction field

[0108] uint32_t getInstructionId();

[0109] uint32_t getMinuend();

[0110] uint32_t getSubtrahend();

[0111] uint32_t getResult(); ...

[0113] }; ...

[0115] The method for generating the target code provided by this application structures and models the NPU instructions, enabling the NPU instructions to be described and stored in a structured data format. Codes for assembling and parsing NPU instructions can be automatically generated from the instruction set description file using generalized tools, without being restricted by the NPU chip to which the NPU instructions belong, the attributes and number of the instructions, or the attributes and number of the instruction fields in the instructions. Code development and maintenance are convenient and require less effort.

[0116] Corresponding to the above method for generating the target code, see Figure 3 , Figure 3 is a schematic flowchart of a method for displaying NPU instructions provided by an embodiment of this application. As Figure 3 shown, the method for displaying NPU instructions includes:

[0117] Step S301: Obtain the target NPU instruction and the target description data corresponding to the target NPU instruction, where the target NPU instruction includes at least one instruction field, and each instruction field includes multiple preset types of field attributes. The preset types include the starting bit of the field and the number of bits corresponding to the field.

[0118] Step S302: Parse the target NPU instruction based on the target description data to obtain at least one instruction field and multiple preset type field attributes in each of the instruction fields.

[0119] Step S303: Select display elements of a second type from a preset database according to user input. The second type includes text, icons, and colors. Each display element of the second type includes an attribute type and an initial attribute value corresponding to the attribute type.

[0120] Step S304: Establish a second type of mapping relationship between each of the instruction fields and the display elements in a second preset order.

[0121] Step S305: Receive second type target values corresponding to each of the instruction fields input by the user, and update the initial attribute values of the display elements corresponding to each of the instruction fields to the second type target values based on the second type mapping relationship to obtain a target NPU instruction for custom display.

[0122] Through the foregoing method for generating target code, structural modeling is performed on the NPU instruction, enabling the NPU instruction to be described and stored in a structured data format, and a generalized tool can be designed to visually read the instruction set. The overall process is similar to the method for generating target code. Only the differences between the display method of the NPU instruction and the method for generating target code described above are introduced below. For other specific implementation processes, reference can be made to the specific implementation processes of the method for generating target code provided in the foregoing embodiments, which will not be elaborated herein one by one.

[0123] The display method of the NPU instruction is essentially a method of displaying the abstract representation of the foregoing instruction set in various ways. It should be noted that if the instruction is described in a text format such as JSON, XML, or YAML, it already has readability and can be displayed using the method described below or directly used for reading.

[0124] For a certain instruction set, its personalized display workflow is as follows:

[0125] 1) First, read in the data content of the instruction set described by the abstract representation method of the foregoing instruction set, and parse out the instruction format clustering from it;

[0126] 2) Take out an element from the instruction format clustering, that is, the target NPU instruction, and obtain the attributes of the instruction such as the instruction name and the instruction field clustering from it;

[0127] 3) Then select or design custom display elements of the second type, such as text, icons, colors, etc., for displaying the instruction format, and customize the layout order and position. Each display element of the second type includes an attribute type and an initial attribute value corresponding to the attribute type. For example, the current target NPU instruction actually corresponds to a chart, and the background color of the chart can be changed by setting the attribute type and the initial attribute value corresponding to the attribute type;

[0128] 4) Take out an element from the instruction field clustering, and obtain the attributes of the instruction field, such as the instruction field name, the starting bit position of the instruction field, the number of bits occupied by the instruction field, etc.

[0129] 5) Similarly, custom display elements of the second type, such as text, icons, colors, etc., can also be selected or designed for displaying the instruction fields, and the layout order and position can be customized.

[0130] 6) Repeat steps 4) to 5) until all the instruction fields of the current target NPU instruction are traversed.

[0131] 7) Repeat steps 2) to 6) until each target NPU instruction in the current instruction set is traversed.

[0132] The display method of the NPU instruction provided by this application performs a structured modeling on the NPU instruction through the target code generation method described above, enabling the NPU instruction to be described and stored in a structured data format, realizing document content in any layout and corresponding reading methods, such as local reading or web reading, visual difference comparison reading between different versions of instruction formats, etc. It can also display the instruction set in various forms, such as charts, graphs, icons, etc., to realize the visual reading of the target NPU instruction or instruction set.

[0133] Corresponding to the above method embodiment, refer to Figure 4 In addition, the present invention also provides a target code generation device 400, and the target code generation device 400 includes:

[0134] An acquisition module 401, configured to acquire a target NPU instruction and an initial code corresponding to the target NPU instruction, where the target NPU instruction includes at least one instruction field, each instruction field includes multiple field attributes of a preset type, the preset type includes a field name, a field start bit, and a number of bits corresponding to the field, and the initial code includes at least one callable function;

[0135] An analysis module 402, configured to analyze the target NPU instruction to obtain at least one instruction field and multiple field attributes of a preset type in each instruction field;

[0136] A mapping module 403, configured to establish a first type of mapping relationship between each of the instruction fields and functions in the initial code in a first preset order;

[0137] A writing module 404, configured to receive first type of target values corresponding to each of the instruction fields input by a user, and write the first type of target values into the initial code based on the first type of mapping relationship and field attributes of a preset type to obtain a target code.

[0138] Specifically in implementation, the target code generation device further includes:

[0139] A receiving module, configured to receive an initial NPU instruction input by a user;

[0140] A conversion module, configured to convert the initial NPU instruction into a target NPU instruction if an initial format of the initial NPU instruction is different from a preset format.

[0141] Specifically in implementation, the mapping module is specifically configured to:

[0142] Obtain field names of each instruction field in a first order;

[0143] For any instruction field, convert the field name of the instruction field into a function name in the initial code according to a preset conversion type to obtain a first type of mapping relationship corresponding to the field name and the function name, where the preset conversion type includes copying, mapping, and expansion.

[0144] Corresponding to the above method embodiments, refer to Figure 5 , the present invention further provides an NPU instruction display device 500, and the NPU instruction display device 500 includes:

[0145] An obtaining module 501, configured to obtain a target NPU instruction, where the target NPU instruction includes at least one instruction field, and each of the instruction fields includes a plurality of field attributes of a preset type, and the preset type includes a field start bit and a number of bits corresponding to the field;

[0146] An analysis module 502, configured to analyze the target NPU instruction to obtain at least one instruction field and a plurality of field attributes of a preset type in each of the instruction fields;

[0147] A selection module 503, configured to select a second type of display element from a preset database according to user input, where the second type includes text, icons, and colors, and each second type of display element includes an attribute type and an initial attribute value corresponding to the attribute type;

[0148] A mapping module 504, configured to establish a second type of mapping relationship between each of the instruction fields and the display elements in a second preset order;

[0149] An update module 505, configured to receive second type target values corresponding to each of the instruction fields input by a user, and update initial attribute values of the display elements corresponding to each of the instruction fields to the second type target values based on the second type of mapping relationship, so as to obtain a target NPU instruction for custom display.

[0150] In addition, a computer device is further provided. The computer device includes a processor and a memory. The memory stores a computer program. When the computer program is executed on the processor, the above-mentioned method for generating target code and the method for displaying NPU instructions are implemented.

[0151] In addition, a computer-readable storage medium is further provided. The computer-readable storage medium stores a computer program. When the computer program is executed on the processor, the method for generating target code and the method for displaying NPU instructions are implemented.

[0152] For the specific implementation processes of the target code generation device, the NPU instruction display device, the computer device, and the computer-readable storage medium provided in this application, reference may be made to the specific implementation processes of the target code generation method or the NPU instruction display provided in the above embodiments, which will not be elaborated herein one by one.

[0153] The target code generation device, the NPU instruction display device, the computer device, and the computer-readable storage medium provided in this application perform structured modeling on NPU instructions, so that NPU instructions can be described and stored in a structured data format, and code for assembling and parsing NPU instructions can be automatically generated from an instruction set description file using a generalization tool, without being restricted by the NPU chip to which the NPU instruction belongs, without being restricted by the attributes and numbers of the instructions, and without being restricted by the attributes and numbers of the instruction fields in the instructions. Code development and maintenance are convenient and the workload is small. Moreover, it can implement document content in any layout and corresponding reading methods, such as local reading or web page reading, visual difference comparison reading between different versions of instruction formats, etc., and the instruction set can also be displayed in various forms, such as charts, graphs, icons, etc., to achieve visual reading of target NPU instructions or instruction sets.

[0154] It should be noted that the computer-readable medium disclosed in this application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the disclosure of this application, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device. In the disclosure of this application, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable signal medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0155] The above computer-readable medium can be included in the above computer device; or it can exist separately without being assembled into the computer device.

[0156] The above computer-readable medium carries one or more programs. When the above one or more programs are executed by the computer device, the computer device is caused to: obtain at least two Internet protocol addresses; send a node evaluation request including the at least two Internet protocol addresses to a node evaluation device, where the node evaluation device selects an Internet protocol address from the at least two Internet protocol addresses and returns it; receive the Internet protocol address returned by the node evaluation device; where the obtained Internet protocol address indicates an edge node in a content delivery network.

[0157] Alternatively, the above computer-readable medium carries one or more programs which, when executed by the computer device, cause the computer device to: receive a node evaluation request including at least two Internet Protocol addresses; select an Internet Protocol address from the at least two Internet Protocol addresses; return the selected Internet Protocol address; wherein the received Internet Protocol address indicates an edge node in a content delivery network.

[0158] Computer program code for carrying out operations disclosed in this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can execute entirely on the user's computer, partially on the user's computer, execute as a stand-alone software package, execute partially on the user's computer and partially on a remote computer, or execute entirely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).

[0159] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments disclosed in this application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0160] The units involved in the embodiments disclosed in this application can be implemented in software or in hardware. Among them, the name of the unit does not constitute a limitation to the unit itself in some cases. For example, the first acquisition unit can also be described as "the unit for acquiring at least two Internet Protocol addresses".

[0161] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof.

[0162] As described above, it is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed in this application should be covered within the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

Claims

1. A method for generating target code, characterized in that, the method for generating target code includes: obtaining a target NPU instruction, target description data corresponding to the target NPU instruction, and initial code, wherein the target NPU instruction includes at least one instruction field, each instruction field includes multiple field attributes of a preset type, the preset type includes a field name, a field start bit, and the number of bits corresponding to the field, and the initial code includes at least one callable function; parsing the target NPU instruction based on the target description data to obtain at least one instruction field and multiple field attributes of a preset type in each instruction field; establishing a first type of mapping relationship between each instruction field and a function in the initial code in a first preset order; receiving first type of target values corresponding to each instruction field input by a user, and writing the first type of target values into the initial code based on the first type of mapping relationship and the field attributes of the preset type to obtain target code.

2. The method for generating target code according to claim 1, characterized in that, before the step of obtaining a target NPU instruction, target description data corresponding to the target NPU instruction, and initial code, the method for generating target code further includes: receiving a target NPU instruction input by a user and initial description data corresponding to the target NPU instruction; if the initial format corresponding to the initial description data is different from a preset format, converting the initial description data into target description data in the preset format.

3. The method for generating target code according to claim 1, characterized in that, the step of establishing a first type of mapping relationship between each instruction field and a function in the initial code in a first preset order includes: obtaining the field names of each instruction field in a first order; for any instruction field, converting the field name of the instruction field into a function name in the initial code according to a preset conversion type to obtain a first type of mapping relationship between the field name and the function name, wherein the preset conversion type includes copy, mapping, and expansion.

4. A method for displaying an NPU instruction, characterized in that, the method for displaying an NPU instruction includes: obtaining a target NPU instruction and target description data corresponding to the target NPU instruction, wherein the target NPU instruction includes at least one instruction field, each instruction field includes multiple field attributes of a preset type, the preset type includes a field start bit and the number of bits corresponding to the field; parsing the target NPU instruction based on the target description data to obtain at least one instruction field and multiple field attributes of a preset type in each instruction field; selecting second type of display elements from a preset database according to user input, the second type includes text, icons, and colors, and each second type of display element includes an attribute type and an initial attribute value corresponding to the attribute type; establishing a second type of mapping relationship between each instruction field and the display elements in a second preset order; Receive the second type of target values corresponding to each of the instruction fields input by the user, and update the initial attribute values of the display elements corresponding to each of the instruction fields to the second type of target values based on the second type of mapping relationship, so as to obtain a target NPU instruction for custom display; Wherein, the target NPU instruction and the target description data corresponding to the target NPU instruction are obtained according to the method for generating the target code described in any one of claims 1 to 2.

5. A device for generating a target code, Characterized in that, The device for generating the target code includes: An acquisition module, configured to acquire a target NPU instruction, target description data corresponding to the target NPU instruction, and an initial code corresponding to the target NPU instruction, wherein the target NPU instruction includes at least one instruction field, and each instruction field includes multiple field attributes of a preset type, and the preset type includes a field name, a field start bit, and the number of bits corresponding to the field, and the initial code includes at least one callable function; An analysis module, configured to analyze the target NPU instruction based on the target description data to obtain at least one instruction field and multiple field attributes of a preset type in each instruction field; A mapping module, configured to establish a first type of mapping relationship between each of the instruction fields and the functions in the initial code in a first preset order; A writing module, configured to receive the first type of target values corresponding to each of the instruction fields input by the user, and write the first type of target values into the initial code based on the first type of mapping relationship and the field attributes of the preset type, so as to obtain a target code.

6. The device for generating a target code according to claim 5, Characterized in that, The device for generating the target code further includes: A receiving module, configured to receive a target NPU instruction input by the user and initial description data corresponding to the target NPU instruction; A conversion module, configured to convert the initial description data into target description data in a preset format if the initial format corresponding to the initial description data is different from the preset format.

7. The device for generating a target code according to claim 5, Characterized in that, The mapping module is specifically configured to: Obtain the field names of each instruction field in the first order; For any instruction field, convert the field name of the instruction field into the function name in the initial code according to a preset conversion type to obtain a first type of mapping relationship between the field name and the function name, wherein the preset conversion type includes copy, mapping, and expansion.

8. A display device for NPU instructions, Characterized in that, The display device for NPU instructions includes: An acquisition module, configured to acquire a target NPU instruction and target description data corresponding to the target NPU instruction, wherein the target NPU instruction includes at least one instruction field, and each instruction field includes multiple field attributes of a preset type, and the preset type includes a field start bit and the number of bits corresponding to the field; An analysis module, configured to analyze the target NPU instruction based on the target description data to obtain at least one instruction field and multiple field attributes of a preset type in each instruction field; A selection module, configured to select display elements of a second type from a preset database according to user input, where the second type includes text, icons, and colors, and each display element of the second type includes an attribute type and an initial attribute value corresponding to the attribute type; A mapping module, configured to establish a second type of mapping relationship between each of the instruction fields and the display elements in a second preset order; An update module, configured to receive second type of target values corresponding to each of the instruction fields input by a user, and update the initial attribute values of the display elements corresponding to each of the instruction fields to the second type of target values based on the second type of mapping relationship, so as to obtain a target NPU instruction for custom display; Wherein, the target NPU instruction and the target description data corresponding to the target NPU instruction are obtained according to the method for generating a target code described in any one of claims 1 to 2.

9. A computer device, characterized in that, the computer device includes a processor and a memory, the memory stores a computer program, and when the computer program is executed on the processor, it implements the method for generating a target code described in any one of claims 1-3 and the method for displaying an NPU instruction described in claim 4.

10. A computer-readable storage medium, characterized in that, the computer-readable storage medium stores a computer program, and when the computer program is executed on a processor, it implements the method for generating a target code described in any one of claims 1-3 and the method for displaying an NPU instruction described in claim 4.

Citation Information

Patent Citations

  • Method and device for generating custom code based on sql and electronic device

    CN112346720A

  • Field assignment code generation method and device, equipment and storage medium

    CN114625348A