ComputableOperator

public protocol ComputableOperator

This protocol defines the common computation APIs of Operator.

  • ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MARK: - Attributes Computation delegate.

    The assigned delegate can track the computation status and \ result through methods from OperatorComputationDelegate.

    Usually the delegate is a Flow object.

    Declaration

    Swift

    var computationDelegate: OperatorCalculationDelegate?
  • Kernel function name

    Declaration

    Swift

    var metalKernelFuncLabel: String
  • Operator readable label

    Declaration

    Swift

    var operatorLabel: String
  • Input tensors to operate

    Declaration

    Swift

    var inputTensors: [Tensor]?
  • Output tensors

    Declaration

    Swift

    var outputTensors: [Tensor]?
  • If true, operator will not call inputOutputTensorsCheck() before doing calculation. This is used inside framework to speed up in situation we know it will not be wrong.

    Declaration

    Swift

    var disableInputOutputCheck: Bool
  • Indicate if this operator would do paramter update

    Declaration

    Swift

    var trainable: Bool
  • The mapping type of this operator

    Declaration

    Swift

    var mapType: OperatorMappingType
  • Indicate if this operator allows in-place operation.

    Declaration

    Swift

    var inPlaceble: Bool
  • Calulate the output tensor shape given an input tensor shape. If the operator cannot operate on the input tensor shape, return nil.

    - Parameters:
       - shapeArray: An array of `TensorShape`
    
    - Returns: A `TensorShape` object or `nil` if the operator could not operate on the input shape.
    

    Declaration

    Swift

    func outputShape(shapeArray shapes:[TensorShape]) -> [TensorShape]?
  • Check if the input tensors and output tensors’s shape matching

    Declaration

    Swift

    func inputOutputTensorsCheck() -> (check: Bool, msg: String)

    Return Value

    check is true if match; msg error info if not match

  • Compute sync

    Declaration

    Swift

    func compute(_ computationMode: OperatorComputationMode)

    Parameters

    computationMode

    computationMode

  • Compute the output tensor asyncally. Output result will be passed to computationDelegate.

    Note

    If the computationDelegate is nil, the computed output will be lost.

    Declaration

    Swift

    func computeAsync(_ computationMode: OperatorComputationMode)
  • ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MARK: - Differentiaion realted methods (backward) Compute grads from output against each input tensor and involving parameters.

    ## Identify corresponding input The returned label of data could be used to identify its correspoding input following below rules:

  • Input tensor. input_{i} where i is the corresponding input tensor’s index in inputTensors

    • Parameter. The parameter’s name.
  • Note

    Operator will not store grads tensor. If the returned value not used, grads will lost.

    Declaration

    Swift

    func gradCompute(_ computationMode: OperatorComputationMode) -> [String: DataSymbolSupportedDataType]

    Parameters

    computationMode

    computationMode description

    Return Value

    grads list for each input tensor and involving parameters with label

  • Compute async grads from output against each input tensor and involving parameters.

    Declaration

    Swift

    func gradComputAsync(_ computationMode: OperatorComputationMode)

    Parameters

    computationMode

    computationMode

    upGrds

    Optional. Grads from upstream operators in a Graph computation.

  • Bind data from symbol to parameter of this operator.

    Declaration

    Swift

    func bindParamSymbols(_ symbols: [GraphSymbol])

    Parameters

    symbols

    binded symbols

  • An array of GraphSymbol for this operator’s parameters. This array may be empty if operator needs no parameter. This function is used in constructing computaion graph.

    Declaration

    Swift

    func paramSymbols() -> [GraphSymbol]

    Return Value

    An array.