Package

cogx.compiler

cpu_operator

Permalink

package cpu_operator

Visibility
  1. Public
  2. All

Type Members

  1. abstract class Operator extends SemanticError

    Permalink

    A user-defined operator, allowing the user to write Cog code that can't be easily parallelized and must be executed on the CPU.

    A user-defined operator, allowing the user to write Cog code that can't be easily parallelized and must be executed on the CPU.

    To define an Operator, create an object which extends this class and define a 'compute' method in it. Here's an example:

    /** An operator which flips a picture upside down. */
    object upsideDown extends Operator {
      def compute(in: ScalarFieldReader, out: ScalarFieldWriter) {
        out.setShape(in.fieldShape)
        for (row <- 0 until in.rows; col <- 0 until in.columns) {
          val pixel = in.read(row, col)
          result.write(in.rows - row - 1, col, pixel)
        }
      }
    }

    To invoke this operator, use it like a function:

    val graph = new ComputeGraph {
       val field = ScalarField(...)
       val flipped = upsideDown(field)
    }

    This class does the necessary reflective magic to connect up the compute method, which is written using *FieldReader and *FieldWriter objects, to Fields.

Ungrouped