clang-tools 19.0.0git
Classes | Functions
CompletionModelCodegen Namespace Reference

Classes

class  CppClass
 

Functions

def header_guard (filename)
 
def boost_node (n, label, next_label)
 
def if_greater_node (n, label, next_label)
 
def if_member_node (n, label, next_label)
 
def node (n, label, next_label)
 
def tree (t, tree_num, node_num)
 
def gen_header_code (features_json, cpp_class, filename)
 
def order_encode (v)
 
def evaluate_func (forest_json, cpp_class)
 
def gen_cpp_code (forest_json, features_json, filename, cpp_class)
 
def main ()
 

Detailed Description

Code generator for Code Completion Model Inference.

Tool runs on the Decision Forest model defined in {model} directory.
It generates two files: {output_dir}/{filename}.h and {output_dir}/{filename}.cpp
The generated files defines the Example class named {cpp_class} having all the features as class members.
The generated runtime provides an `Evaluate` function which can be used to score a code completion candidate.

Function Documentation

◆ boost_node()

def CompletionModelCodegen.boost_node (   n,
  label,
  next_label 
)
Returns code snippet for a leaf/boost node.

Definition at line 40 of file CompletionModelCodegen.py.

◆ evaluate_func()

def CompletionModelCodegen.evaluate_func (   forest_json,
  cpp_class 
)
Generates evaluation functions for each tree and combines them in
`float Evaluate(const {Example}&)` function. This function can be
used to score an Example.

Definition at line 204 of file CompletionModelCodegen.py.

References tree().

Referenced by gen_cpp_code().

◆ gen_cpp_code()

def CompletionModelCodegen.gen_cpp_code (   forest_json,
  features_json,
  filename,
  cpp_class 
)
Generates code for the .cpp file.

Definition at line 238 of file CompletionModelCodegen.py.

References evaluate_func().

Referenced by main().

◆ gen_header_code()

def CompletionModelCodegen.gen_header_code (   features_json,
  cpp_class,
  filename 
)
Returns code for header declaring the inference runtime.

Declares the Example class named {cpp_class} inside relevant namespaces.
The Example class contains all the features as class members. This
class can be used to represent a code completion candidate.
Provides `float Evaluate()` function which can be used to score the Example.

Definition at line 119 of file CompletionModelCodegen.py.

References header_guard().

Referenced by main().

◆ header_guard()

def CompletionModelCodegen.header_guard (   filename)
Returns the header guard for the generated header.

Definition at line 35 of file CompletionModelCodegen.py.

Referenced by gen_header_code().

◆ if_greater_node()

def CompletionModelCodegen.if_greater_node (   n,
  label,
  next_label 
)
Returns code snippet for a if_greater node.
Jumps to true_label if the Example feature (NUMBER) is greater than the threshold.
Comparing integers is much faster than comparing floats. Assuming floating points
are represented as IEEE 754, it order-encodes the floats to integers before comparing them.
Control falls through if condition is evaluated to false.

Definition at line 45 of file CompletionModelCodegen.py.

References order_encode().

◆ if_member_node()

def CompletionModelCodegen.if_member_node (   n,
  label,
  next_label 
)
Returns code snippet for a if_member node.
Jumps to true_label if the Example feature (ENUM) is present in the set of enum values
described in the node.
Control falls through if condition is evaluated to false.

Definition at line 61 of file CompletionModelCodegen.py.

◆ main()

def CompletionModelCodegen.main ( )

Definition at line 293 of file CompletionModelCodegen.py.

References gen_cpp_code(), gen_header_code(), and main().

Referenced by main().

◆ node()

def CompletionModelCodegen.node (   n,
  label,
  next_label 
)
Returns code snippet for the node.

Definition at line 77 of file CompletionModelCodegen.py.

Referenced by tree().

◆ order_encode()

def CompletionModelCodegen.order_encode (   v)

Definition at line 195 of file CompletionModelCodegen.py.

Referenced by if_greater_node().

◆ tree()

def CompletionModelCodegen.tree (   t,
  tree_num,
  node_num 
)
Returns code for inferencing a Decision Tree.
Also returns the size of the decision tree.

A tree starts with its label `t{tree#}`.
A node of the tree starts with label `t{tree#}_n{node#}`.

The tree contains two types of node: Conditional node and Leaf node.
-   Conditional node evaluates a condition. If true, it jumps to the true node/child.
    Code is generated using pre-order traversal of the tree considering
    false node as the first child. Therefore the false node is always the
    immediately next label.
-   Leaf node adds the value to the score and jumps to the next tree.

Definition at line 86 of file CompletionModelCodegen.py.

References node(), and tree().

Referenced by evaluate_func(), and tree().