The following shows an example code for adding new layers to SOL’s TensorFlow frontend.
import sol.tensorflow
def parse_OperationXYZ(node, scope):
return tuple(scope[i.unique()] for i in node.inputs())
def my_handler(node, scope):
input, a, b = sol.tensorflow.parse_inputs(node, scope)
c = node.get_attr('whatever')
output, = node.outputs
x = sol.hlir.Tensor(my_backend_lib.add_my_layer(input, a, b, c))
sol.tensorflow.assign(scope, output, x)
sol.tensorflow.add_handler("not_implemented_by_sol", my_handler)
my_handler
gets called with handler(node, scope)
, where node is a
tf.Graph node and scope a dictionary of all variables visible to this node.
sol.tensorflow.parse_inputs(node, scope)
dereferences all inputs.
sol.tensorflow.assign(scope, output, x)
assigns the resulting Tensor
x
to the node’s output within the current scope.
sol.tensorflow.add_handler(...)
is used to assign your handler to the
given TF node type.