6. Function

6.1. Compiler

enum topsgraphResult

Topsgraph defines the following enumeration type and function for API call error handling.

Values:

enumerator TOPS_GRAPH_SUCCESS
enumerator TOPS_GRAPH_ERROR_INVALID_INPUT
enumerator TOPS_GRAPH_ERROR_INVALID_PROGRAM
enumerator TOPS_GRAPH_ERROR_INVALID_OPTION
enumerator TOPS_GRAPH_ERROR_OUT_OF_MEMORY
typedef void *topsgraphProgram
topsgraphResult topsgraphCreateProgramFromString(topsgraphProgram *program, const char *module)

The topsgraphCreateProgramFromString creates an instance of topsgraphProgram with the given input parameters, and sets the output parameter program with it.

Parameters
  • program – The program is the unit of compilation and an opaque handle.

  • module – Input of hlir ir dump char *.

Returns

The error code of topsgraphResult type.

topsgraphResult topsgraphCreateProgramFromModule(topsgraphProgram *program, hlir::Module *module)

The topsgraphCreateProgramFromModule creates an instance of topsgraphProgram with the given input parameters, and sets the output parameter program with it.

Parameters
  • program – The program is the unit of compilation and an opaque handle.

  • module – Input of parsed hlir model.

Returns

The error code of topsgraphResult type.

topsgraphResult topsgraphDestroyProgram(topsgraphProgram *program)

The topsgraphDestroyProgram destroys the given program.

Parameters

program – The program is the unit of compilation and an opaque handle.

Returns

The error code of topsgraphResult type.

topsgraphResult topsgraphCompileProgram(topsgraphProgram program, int options_num, const char **options)

The topsgraphCompileProgram compiles the given program.

Parameters
  • program – The program is the unit of compilation and an opaque handle.

  • options_num – The numOptions is the number of parameters in options and must be greater than or equal to 0 less than or equal to the actual number of parameters.

  • options – The options is a pointer to an array, and each element in the array is a zero ended char *. The “-arch” and “-resource” in options must be filled in. If more than one “-arch” or others is written, the last one is used. The options supports three options: example: “-arch=gcu210” “-resource=1c4s” “-hlir=hlir-training-pipeline”

Returns

The error code of topsgraphResult type.

topsgraphResult topsgraphGetBin(topsgraphProgram program, char *binary)

The topsgraphGetBin stores the binary generated by the previous compilation of program in the memory pointed by binary.

Parameters
  • program – The program is the unit of compilation and an opaque handle.

  • binary – The buffers are compiled in raw binary format and need to be allocated and managed by the customer.

Returns

The error code of topsgraphResult type.

topsgraphResult topsgraphGetBinSize(topsgraphProgram program, size_t *binary_size)

The topsgraphGetBin sets binary_size with the size of the binary generated by the previous compilation of program.

Parameters
  • program – The program is the unit of compilation and an opaque handle.

  • binary_size – Size of the generated binary.

Returns

The error code of topsgraphResult type.

topsgraphResult topsgraphSaveBinFile(topsgraphProgram program, const char *save_file)

The topsgraphSaveBinFile save binary to a file.

Parameters
  • program – The program is the unit of compilation and an opaque handle.

  • save_file – Path to saves the file.

Returns

The error code of topsgraphResult type.