Hardware acceleration instruction determination method and system, and electronic device and storage medium

By obtaining the code to be converted and writing extended compilation control instructions, the hardware circuit design and verification process is simplified, the problem of low hardware circuit development efficiency is solved, and the flexibility and development efficiency of the hardware processor are improved.

WO2024222455A1PCT designated stage expired Publication Date: 2024-10-31CHIPEASY TECHNOLOGY (SHANGHAI) LTD

Patent Information

Application Number
PCT/CN2024/086961
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-28
Filing Date
2024-04-10
Publication Date
2024-10-31

AI Technical Summary

Technical Problem

Hardware circuit design is difficult, the verification process is complex, and development efficiency is low, resulting in increased hardware acceleration circuit development costs.

Method used

By obtaining the code to be converted, preprocessing it into an algorithm function, determining the register file, status register and operands, writing extended compilation control instructions, compiling and generating hardware acceleration instructions, using C language and extended compilation control instructions to unify the software and hardware design languages ​​and simplify Design and verification process.

Benefits of technology

It improves the flexibility and development efficiency of hardware processors, reduces the difficulty of debugging and verification, simplifies instruction set design, and improves development efficiency and reuse.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024086961_31102024_PF_FP_ABST
    Figure CN2024086961_31102024_PF_FP_ABST
Patent Text Reader

Abstract

The present invention relates to the field of computers. Disclosed are a hardware acceleration instruction determination method and system, and an electronic device and a storage medium. The method comprises: acquiring a code to be converted; performing pre-processing on said code, so as to obtain an algorithm function; according to the algorithm function, determining a register file, a state register, a register operand and an immediate operand; adding the register file, the state register, the register operand and the immediate operand into a new file, so as to obtain an instruction; according to an actual requirement, determining an instruction slot, which is occupied by the instruction in a very-long instruction word coding format, and a coding method, and writing an extended compilation control instruction; and compiling the extended compilation control instruction, so as to obtain a processor file, wherein the processor file is used for generating a hardware acceleration instruction. By means of the present invention, the flexibility and development efficiency of a hardware processor can be improved, thereby reducing the difficulty of debugging and verification.
Need to check novelty before this filing date? Find Prior Art

Description

A method, system, electronic device and storage medium for determining hardware acceleration instructions Technical Field The present invention relates to the field of computers, and in particular to a method, system, electronic device and storage medium for determining hardware acceleration instructions. Background Art With the extensive application of chips in various industries (such as engineering control, autonomous driving, and consumer electronics), a large number of algorithms need to be accelerated through hardware circuits. However, the high difficulty of hardware circuit design, complex verification process, and long generation cycle make the development efficiency of hardware acceleration circuits low, debugging complex, and the iteration cycle long, resulting in increased development costs. Summary of the invention The purpose of the present invention is to provide a hardware acceleration instruction determination method, system, electronic device and storage medium, which can improve the flexibility and development efficiency of hardware processors and reduce the difficulty of debugging and verification. To achieve the above object, the present invention provides the following solutions: A method for determining a hardware accelerated instruction, comprising: Get the code to be converted; Preprocessing the code to be converted to obtain an algorithm function; Determine a register file, a status register, a register operand, and an immediate operand according to the algorithm function; Add the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction; Determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and write an extended compilation control instruction; The extended compilation control instruction is compiled to obtain a processor file; the processor file is used to generate a hardware acceleration instruction. Optionally, the code to be converted is preprocessed to obtain an algorithm function, specifically including: Compiling and executing the code to be converted on a host platform to obtain a correct code program; The code fragments that need to be converted in the correct code program are extracted from the source code into an algorithm function; the algorithm function is a function of the C language. Optionally, determining a register file, a status register, a register operand, and an immediate operand according to the algorithm function specifically includes: Determine a register file according to a function parameter of the algorithm function; Determining a status register based on a global variable accessed in the algorithm function; Register operands and immediate operands are determined based on all function parameters and return values ​​in the algorithm function. Optionally, adding the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction specifically includes: Storing the algorithm function in a source file; adding the register file, the status register, the register operand and the immediate operand to a new file; the register file and the status register both including a vector type tag; Add the directive name in said new file; A directive is determined from the source file and a new file to which the directive name is added. Optionally, according to actual needs, the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method are determined and the extended compilation control instruction is written, specifically including: Determine the encoding format of the very long instruction word according to actual needs and add the very long instruction word encoding format to the new file; According to actual needs, the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method are determined and the extended compilation control instruction is written. Optionally, compiling the extended compilation control instruction to obtain a processor file specifically includes: Compiling the extended compilation control instructions to obtain an instruction set library; The instruction set libraries having different functions are linked to generate processor files. Optionally, compiling the extended compilation control instruction to obtain an instruction set library specifically includes: Preprocessing the source files of the instructions in sequence to generate an intermediate expression file; the preprocessing includes calling clang compilation, static single assignment conversion, vector scalar conversion and adding a pipeline termination signal; the vector scalar conversion is to perform scalar conversion according to the vector type tag; The intermediate expression file and the extended compilation control instructions are stored and packaged to obtain an instruction set library. The present invention also provides a hardware acceleration instruction determination system, comprising: An acquisition module is used to obtain the code to be converted; A preprocessing module, used for preprocessing the code to be converted to obtain an algorithm function; A register file, status register, register operand and immediate operand determination module, used to determine the register file, status register, register operand and immediate operand according to the algorithm function; An adding module, used for adding the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction; An encoding module, used to determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and to write an extended compilation control instruction; The compiling module is used to compile the extended compiling control instruction to obtain a processor file; the processor file is used to generate a hardware acceleration instruction. The present invention also provides an electronic device, comprising: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the above-mentioned method. The present invention also provides a storage medium having a computer program stored thereon, wherein the computer program When the machine program is executed by a processor, the above method is implemented. According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects: The present invention preprocesses the code to be converted to obtain an algorithm function; determines a register file, a status register, a register operand and an immediate operand according to the algorithm function; adds the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction; determines the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and writes an extended compilation control instruction; compiles the extended compilation control instruction to obtain a processor file; the processor file is used to generate a hardware acceleration instruction. The present invention can improve the flexibility and development efficiency of the hardware processor and reduce the difficulty of debugging and verification. BRIEF DESCRIPTION OF THE DRAWINGS In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work. FIG1 is a flow chart of a method for determining hardware accelerated instructions. DETAILED DESCRIPTION The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. The purpose of the present invention is to provide a hardware acceleration instruction determination method, system, electronic device and storage medium, which can improve the flexibility and development efficiency of hardware processors and reduce the difficulty of debugging and verification. In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments. The present invention uses C language and its extended compilation control instructions (pragma) as the design language of the instruction, unifies the design language of software and hardware, and thus accelerates the collaborative design and verification of software and hardware. Modify the compiler front end. Similar methods can be applied to other software design languages ​​(such as Fortran and Java). Use C language and some syntax extensions to describe the instruction set, and use a general C language compiler on the host platform to compile and execute the source file to complete the correctness verification of the function verification. Then compile the source file with a proprietary compiler to generate a specific instruction set library. Linking multiple instruction set libraries can generate a processor description file, which can be used to generate hardware RTL code, simulators, compilers, operating systems and other software and hardware. The description of the instruction set includes the following points: the register file and status register contained in the instruction set, the encoding and decoding method of each instruction in the instruction set for immediate operands and register operands, the behavior of each instruction in the instruction set, the VLIW format of the instruction set, and the encoding format of each instruction in the instruction set. As shown in FIG1 , a method for determining a hardware acceleration instruction provided by the present invention includes: Step 101: Obtain the code to be converted. Step 102: pre-process the code to be converted to obtain an algorithm function. Step 102 specifically includes: compiling and executing the code to be converted on the host platform to obtain a correct code program; extracting the code fragments to be converted in the correct code program from the source code into an algorithm function; the algorithm function is a function of the C language. Taking C language code as an example, the preprocessing of C language code to be converted into processor instructions specifically includes: 1.1 Prepare C language code Use C language to implement a software program with specific functions, and use a general C language compiler (such as GCC or clang, etc.) to compile and execute the program on the host platform (such as X86_64) to verify the correctness of the program. In other words, to implement a specific function, first prepare the corresponding C language code program, and then verify the correctness of the C language code program. 1.2 Extract key algorithms from C language code programs to form C language functions In the software program that has been verified to be correct, the code snippets that need to be converted into processor instructions are extracted from the source code into a C language function. The function contains the algorithm code snippets that need to be converted into instructions and is saved separately as a source code file inst.c. Specifically, the code snippets that need to be converted into processor instructions are copied and pasted, and a function header is added. Finally, the corresponding variable names are modified. Step 103: Determine the register file, status register, register operands and immediate operands according to the algorithm function. Step 103 specifically includes: determining a register file according to function parameters of the algorithm function; determining a status register according to global variables accessed in the algorithm function; and determining register operands and immediate operands according to all function parameters and return values ​​in the algorithm function. Step 104: Add the register file, the status register, the register operands and the immediate operands to a new file to obtain instructions. Step 104 specifically includes: storing the algorithm function into a source file; adding the register file, the status register, the register operand and the immediate operand to a new file; adding an instruction name to the new file; and determining an instruction according to the source file and the new file with the instruction name added. The register file and the status register both include a vector type tag. In addition, the register file and the status register can be added before the type by adding __attribute__((vector_size(<num_bytes> ))) attribute marks it as a vector type, which is supported by the common compilers clang and gcc, where<num_bytes> Indicates the total number of bytes of the vector type. Vector operations can be used directly in design instructions. For the specific syntax of this attribute, please refer to the gcc document (https: / / gcc.gnu.org / onlinedocs / gcc / Vector-Extensions.html). In step 20103, the vector operation will be automatically converted into multiple scalar operations. Write a code file that describes the instruction set. Add additional C language code and use the pragma (extended compilation control instructions) in the C language compiler to describe other information about the processor instructions (referred to as "instructions" in subsequent steps) that need to be generated, including: Step 2.1: Determine the register file and status register required by the function to be converted into instructions (a). The register file contains a set of registers with three attributes: name, number, and width. The register width is determined by the function parameters and needs to be consistent with the width of the function parameters, while the number is determined based on the actual algorithm requirements and chip costs. The status register corresponds one-to-one to the global variables accessed in the function. Declare the above register files and status registers as global primitive data type arrays variables and primitive data types global variables, Write the corresponding pragmaREGFILE to the register file <name> <id>,in <name>and <id>Respectively represent the name and number of the register, Write the corresponding pragmaSTATE to the status register <name>instruction, <name>Indicates the name of the status register. Save the above written content into a new file inst.h. For example, inst.h may contain the following code, which declares a register file XR with 16 32-bit wide registers and a 32-bit wide status register S. #pragmaREGFILEXRx externuint32_tXR

[0016] ; #pragmaSTATES externuint32_tS; Step 2.2: Based on all the parameters and return values ​​of the algorithm function that need to be converted into instructions obtained in step 1.2, determine the register operands and immediate operands (b) required for the instruction. The specific determination method is described as follows. Instructions need operands to access registers, so each parameter of a function corresponds to a register operand or an immediate operand. If the content of a function parameter is statically determined during compilation, the parameter can be encoded in the instruction and the parameter corresponds to an immediate operand. If the content of a function parameter can only be determined at runtime, the content of this parameter is usually stored in a register, and the parameter corresponds to a register operand. Register operands are divided into input operands and register operands. An input operand corresponds to an input parameter of a function, and an output operand corresponds to an output parameter of a function or the return value of a function. For each operand, write a corresponding operand decoding function. The first parameter of the encoding function of the immediate operand, input operand, and output operand represents the encoding of the operand in the instruction. The decoding function of the immediate operand has a return value, which returns its decoded value. Decoding of input operands The function has a return value, which returns a specific register in the register file after decoding. The output operand has no return value, but has an additional parameter, which represents the data to be stored in the register. Write corresponding pragmaOPERAND for all operands <name> <id> , <name>and <id>Mark the name and number of the operands respectively, and add the written pragma to the inst.h file to form a new inst.h. For example, the following codes are added to inst.h and opreand.c, respectively, describing an operand xs that can access the XR register file. Step 2.3: Add pragmaINST in the new inst.h <name> <operands>…, indicating the algorithm function that needs to be converted into instructions, where <name>is the name of the instruction and also the name of the function to be converted into the instruction. <operands>...are the names of all operands accessed by this instruction. <name>, functions and instructions are associated, and the function determines the behavior of each instruction (c). For example, the newly added code in inst.h and the original inst.c code are as follows. The code indicates that the algorithm function FUNC is an instruction, its operand is xs, and the status register S is overwritten. Step 105: Determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and write an extended compilation control instruction. Step 105 specifically includes: determining the very long instruction word encoding format according to actual needs and adding the very long instruction word encoding format to the new file; determining the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and writing an extended compilation control instruction. Designed Very Long Instruction Word (VLIW) encoding format (d). According to actual application requirements, determine the total length of the VLIW encoding format, the number of instruction slots, the length of each instruction slot, and the fixed bits in the encoding, and write pragmaFORMAT <name> <fmt>,in <name>Marks the name of a VLIW encoding format, <fmt>Is a string of length equal to the length of the VLIW encoding format. <fmt>The fixed bits in are represented by 0 and 1. <fmt>Each instruction slot is determined by a substring composed of the same characters, the length of the substring is the length of the instruction slot, and the characters are the number of the instruction slot. Add the pragmaFORMAT written above to the inst.h file. For example, the following code describes a VLIW format fmt2 with a length of 32 and two instruction slots a and b of length 14 and 16 respectively, and the lowest two bits are fixed to 01. #pragmaFORMATfmt2aaaa,aaaa,aaaa,aa,bbbb,bbbb,bbbb,bbbb,01 Determine the instruction slots occupied by instructions in each VLIW format and the corresponding encoding method (e) according to actual application requirements, and write the corresponding pragmaOPCODE <id> <name> <code>,in <id>is the instruction slot number, <name>Corresponding to the name of the instruction added in step 2.3, <code>The length of the instruction slot is the same as the length of the instruction slot. The entire pragma is named <name>The instruction number is <id>The encoding of the instruction slot. <code>The fixed bits in are represented by 0 and 1, and each string composed of the same characters other than 0 and 1 represents the bit occupied by an operand in the encoding. The characters that make up the string are the numbers of the operands described in step 2.2. Add the pragmaOPCODE written above to the inst.h file. For example, the following code describes the encoding of instruction FUNC in instruction slots a and b, where s represents the operand xs of FUNC. #pragmaOPCODEaFUNC0000,ssss,0001,00 #pragmaOPCODEbFUNCss00,0101,00ss,0000 Step 106: Compile the extended compilation control instruction to obtain a processor file; the processor file is used to generate hardware acceleration instructions. Step 106 specifically includes: compiling the extended compilation control instructions to obtain an instruction set library; linking the instruction set libraries with different functions to generate processor files. Compiling the extended compilation control instructions to obtain an instruction set library specifically includes: preprocessing the source files of the instructions in sequence to generate an intermediate expression file; the preprocessing includes calling clang compilation, static single assignment conversion, vector scalar conversion and adding pipeline termination signals; the vector scalar conversion is scalar conversion according to the vector type tag; the intermediate expression file and the extended compilation control instructions are stored and packaged to obtain an instruction set library. Generate instruction set library using proprietary compiler. By using the fcc compiler of Xinyihui Company to compile the source files describing the above instruction set, the corresponding instruction set library can be generated. The specific working steps of the proprietary compiler fcc are as follows: Step 201: Compile the source files saved in step 104 in sequence (eg, compile inst.c and operand.c obtained in step 104 in sequence) to generate an intermediate expression file. When fcc is specified with the -c parameter, fcc works in compilation mode. At this time, fcc uses the clang compiler to generate LLVM's IR (Intermediate Representation) for the instruction functions and operand functions defined in the source file, performs preprocessing, and converts LLVM's IR into an intermediate expression suitable for generating hardware circuits (the preprocessing and conversion process is described in steps 20102 to 20106), and saves it as an intermediate expression file together with the VLIW format, instruction encoding, status register, register file and other information of the instruction set described by the extended compilation control instructions (pragma). For example, the following command uses fcc to compile the inst.c and operand.c files containing the above instructions and their operand descriptions, and generates intermediate expression files inst.o and operand.o. fcc-cinst.c-oinst.o fcc-coperand.c-ooperand.o Steps 20101 to 20107 describe the specific execution process of fcc. Since LLVM's IR only describes the execution logic of the software, it is not suitable for generating hardware RTL. It needs to be preprocessed and converted into an intermediate expression suitable for generating hardware RTL (hereinafter referred to as "RTL IR"). The following steps describe the preprocessing process of LLVMIR (step 20102 to step 20105) and the process of converting LLVMIR into RTLIR (step 20106). Step 20101: Call clang to compile the source file to generate LLVM's IR. Step 20102: Convert the above LLVMIR into LLVMIR that conforms to the SSA (Static Single Assignment) format. By using the existing algorithms mem2reg (Promote Memory to Register) and sroa (Scalar Replacement of Aggregates) in LLVM, LLVM IR can be directly converted into LLVM IR that conforms to SSA form. Step 20103: Convert all vector operations in LLVMIR to scalar operations. In step 104, the declared data type supports vector type and the calculation also supports vector operation. However, since the description language of the hardware RTL (such as Verilog or VHDL, etc.) does not support vector type operations, all vector operations need to be converted into scalar operations in advance. The specific method is to traverse all vector operations in all functions of the LLVMIR output in step 20102, and replace all vector type calculations containing n elements with n scalar type calculations. Step 20104: Add corresponding pipeline termination signals to all memory reads and writes, status register reads and writes, and register file reads and writes in LLVMIR. Since there is no control flow in the hardware logic, for access operations with execution conditions, the pipeline termination signal needs to be explicitly indicated. If the pipeline termination signal is 0, it means that the access operation is valid. If the pipeline termination signal is 1, it indicates that the access operation is invalid. The specific method is to add a new global variable to represent the pipeline termination state of the corresponding state register or register file (corresponding to the global variables in LLVMIR) for each state register and register file output by step 202103. For memory access, only one global variable needs to be added to mark the pipeline termination state of memory access. In the control flow of LLVMIR, the corresponding pipeline termination global variable is set to 0 at the location of accessing the state register, register file or memory, and set to 1 elsewhere. For example, in the following example, the instruction FUNC described in C language in step 104 is rewritten so that the status register S is written only when the condition xs>10 is satisfied. #pragmaSTATES intS; #pragmaINSTFUNCxs voidFUNC(intxs){if(xs>10)S=xs;} At this time, the LLVM IR fragment corresponding to the FUNC code is (see https: / / llvm.org / docs / LangRef.html for LLVMIR syntax), At this point, it is necessary to add a pipeline termination signal to S, indicating that S is written only when xs>10. The LLVMIR of FUNC after adding pipeline termination (KILL) is as follows, and the added content is marked in bold. For ease of understanding, the pseudo code corresponding to the above IR is shown here as follows: Step 20105: Eliminate all control flows. Since there is no control flow in the hardware logic (i.e., no branch jump statements), all jump instructions in LLVM IR need to be eliminated. The specific method is, for each function of the LLVMIR output in step 20104, all basic blocks are traversed in sequence according to topological sorting, and all operations traversed into the basic blocks are arranged in sequence. During the traversal, if you encounter phi(<true_val> ,<false_val> ) node, then modify the phi node to a select operation. The select operation has three operands, in the form of select <cond>,<true_val> ,<false_val> ,in, <cond>For a condition,<true_val> and<false_val> The conditions are <cond>The values ​​selected when it is true and false correspond to the values ​​in the phi node one by one, and <cond>It is determined according to the conditions of all conditional branch jump instructions that reach the phi node. Step 20106: Convert the preprocessed LLVM IR into RTLIR suitable for generating hardware, and save the information described in the compilation extension control instruction (pragma) into the RTLIR. After the preprocessing from step 20102 to step 20105, the IR of LLVM has been compared with the hard The converted RTLIR, as well as the VLIW format, instruction encoding, status register, register file and other information of the instruction set described in the compiled extended control instruction (pragma), can be saved as the RTLIR file of the instruction. For example, the following RTLIR file describes a simple instruction set, which describes the information of the examples contained in all the above steps, namely, a register file XR containing 16 registers with a width of 32, a status register S with a width of 32, an operand xs encoded with 4 bits that can read the register file XR, an instruction FUNC that writes xs to S when xs>10, a VILW format fmt2 containing two instruction slots a and b, and the encoding method of the instruction FUNC in the instruction slots a and b. Step 202: Use the ar tool in the binutils toolkit to package the intermediate expression file into an instruction set library file. For example, the following instructions package two intermediate expression files and generate the instruction set library func1.a. arrcsfunc1.ainst.ooperand.o Step 203: Link multiple instruction set libraries with different functions to generate a processor file. When fcc is not specified with the -c parameter, fcc works in link mode. When linking, fcc will automatically merge multiple intermediate expression files and generate a processor description file. The information contained in the processor description file is consistent with that in the instruction set description file. For example, the following command uses the fcc compiler to link two instruction set libraries func1.a and func2.a to generate a processor description file dsa.so. fccfunc1.afunc2.a-odsa.so uses the generated processor description file to generate hardware RTL code, simulators, compilers, operating system and other software and hardware through other tools (such as FARMStudio of Xinyihui). By using the generated hardware and supporting software adapted to various fields, a complete hardware and software system can be built to accelerate applications in specific fields. The instruction set in the present invention is the basic command executed by the processor. The present invention includes the description and rapid verification of the instruction set. The method uses C language plus a part of the self-defined C language syntax extension to fully describe the instruction set. After the description is completed, the correctness of the description function is quickly verified on the host platform using software. After the host platform (such as X86_64) is verified, the description information of the instruction can be used to quickly generate hardware RTL code, simulator, compiler and operating system software and hardware. Multiple instruction sets with different functions can be combined to flexibly customize processors with multiple different functions. The present invention also provides a hardware acceleration instruction determination system, comprising: The acquisition module is used to obtain the code to be converted. The preprocessing module is used to preprocess the code to be converted to obtain an algorithm function. The register file, status register, register operand and immediate operand determination module is used to determine the register file, status register, register operand and immediate operand according to the algorithm function. An adding module is used to add the register file, the status register, the register operand and the immediate operand into a new file to obtain an instruction. The encoding module is used to determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and to write an extended compilation control instruction. The compiling module is used to compile the extended compiling control instruction to obtain a processor file; the processor file is used to generate a hardware acceleration instruction. As an optional implementation, the preprocessing module specifically includes: The verification unit is used to compile and execute the code to be converted on the host platform to obtain a correct code program. The extraction unit is used to extract the code fragments that need to be converted in the correct code program from the source code into an algorithm function; the algorithm function is a function of the C language. The present invention also provides an electronic device, comprising: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the above-mentioned method. The present invention also provides a storage medium on which a computer program is stored, wherein the computer program implements the above method when executed by a processor. The present invention simplifies the difficulty of instruction set design for processor chips, and can quickly convert existing software algorithms implemented in C language into hardware instructions. The design from algorithm to instruction can be completed by simply adding some additional information describing the instructions. Compared with existing solutions, users no longer need to handwrite Verilog and other hardware description languages. The verification and debugging process of instructions is simplified, and the development efficiency of instructions is improved. The verification process in step 1.1 may not rely on any hardware design tools, and the software can be used on the host platform to quickly debug algorithm problems and verify the correctness of the algorithm. The existing solutions can only verify the correctness of the design through tools such as hardware emulators and FPGAs, and are difficult to debug. By using the existing instruction set library, processors with different functions that can meet different needs can be flexibly configured, thereby improving the degree of reuse of instruction set design. By selecting different instruction set libraries, processors with different functions can be The instruction set libraries are combined to generate different processor description files. In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part. The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.< / cond> < / cond> < / cond> < / cond> < / code> < / id> < / name> < / code> < / name> < / id> < / code> < / name> < / id> < / fmt> < / fmt> < / fmt> < / name> < / fmt> < / name> < / name> < / operands> < / name> < / operands> < / name> < / id> < / name> < / id> < / name> < / name> < / name> < / id> < / name> < / id> < / name>

Claims

1. A method for determining a hardware acceleration instruction, characterized in that: include: Get the code to be converted; Preprocessing the code to be converted to obtain an algorithm function; Determine a register file, a status register, a register operand, and an immediate operand according to the algorithm function; Add the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction; Determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and write an extended compilation control instruction; The extended compilation control instruction is compiled to obtain a processor file; the processor file is used to generate a hardware acceleration instruction.

2. The method for determining hardware acceleration instructions according to claim 1, characterized in that: The code to be converted is preprocessed to obtain an algorithm function, which specifically includes: Compiling and executing the code to be converted on a host platform to obtain a correct code program; The code fragments that need to be converted in the correct code program are extracted from the source code into an algorithm function; the algorithm function is a function of the C language.

3. The method for determining hardware acceleration instructions according to claim 1, wherein: Determining a register file, a status register, a register operand, and an immediate operand according to the algorithm function specifically includes: Determine a register file according to a function parameter of the algorithm function; Determining a status register based on a global variable accessed in the algorithm function; Register operands and immediate operands are determined based on all function parameters and return values ​​in the algorithm function.

4. The method for determining hardware acceleration instructions according to claim 1, wherein: Adding the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction specifically includes: Storing the algorithm function in a source file; adding the register file, the status register, the register operand and the immediate operand to a new file; the register file and the status register both including a vector type tag; Add the directive name in said new file; A directive is determined from the source file and a new file to which the directive name is added.

5. The method for determining hardware acceleration instructions according to claim 1, characterized in that: Determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and write an extended compilation control instruction, specifically including: Determine the encoding format of the very long instruction word according to actual needs and add the very long instruction word encoding format to the new file; According to actual needs, the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method are determined and the extended compilation control instruction is written.

6. The method for determining hardware acceleration instructions according to claim 4, characterized in that: Compile the extended compilation control instruction to obtain a processor file, which specifically includes: Compiling the extended compilation control instructions to obtain an instruction set library; The instruction set libraries having different functions are linked to generate processor files.

7. The method for determining hardware acceleration instructions according to claim 6, wherein: Compiling the extended compilation control instructions to obtain an instruction set library specifically includes: Preprocessing the source files of the instructions in sequence to generate an intermediate expression file; the preprocessing includes calling clang compilation, static single assignment conversion, vector scalar conversion and adding a pipeline termination signal; the vector scalar conversion is to perform scalar conversion according to the vector type tag; The intermediate expression file and the extended compilation control instructions are stored and packaged to obtain an instruction set library.

8. A hardware accelerated instruction determination system, characterized in that: include: An acquisition module is used to obtain the code to be converted; A preprocessing module, used for preprocessing the code to be converted to obtain an algorithm function; A register file, status register, register operand and immediate operand determination module, used to determine the register file, status register, register operand and immediate operand according to the algorithm function; An adding module, used for adding the register file, the status register, the register operand and the immediate operand to a new file to obtain an instruction; An encoding module, used to determine the instruction slot occupied by the instruction in the very long instruction word encoding format and the encoding method according to actual needs and to write an extended compilation control instruction; The compiling module is used to compile the extended compiling control instruction to obtain a processor file; the processor file is used to generate a hardware acceleration instruction.

9. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: A computer program is stored thereon, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Compiling and debugging method of embedded equipment

    CN110543425A

  • Compiler and compiling method for extensible instruction set

    CN111078290A

  • Program compiling method and equipment and computer readable medium

    CN113360157A

  • Apparatus and method for secure instruction set execution, emulation, monitoring, and prevention

    US20220197678A1

Cited By

  • Data processing method and device, storage medium and electronic equipment

    CN119342020A