hpe-cct / cct-core

CCT compiler, runtime, graphical debugger, and standard library
Apache License 2.0
15 stars 4 forks source link

Creation of new fields within compute graph after step routine is invoked - This is not allowed #6

Closed shrutiramesh88 closed 8 years ago

shrutiramesh88 commented 8 years ago

val cg = new ComputeGraph(optimize=false){ var c1 = ConvolutionLayer(data, Shape(5, 5), 32, BorderValid, lr) var b1 = BiasLayer(c1, lr) ... ... step(1) val testc1 = Convolution(testdata, c1.weights, BorderValid) //causes error ...

DickJC123 commented 8 years ago

The compilation of a user's ComputeGraph 'cg' to GPU code is triggered by the first call of reset, step, read, etc. on cg. After that point, the user should expect an error if he/she tries to add fields to the cg. The following simple example follows the expected pattern:

object SimpleTest extends App { // Step 1: Build the ComputeGraph, e.g. val cg = new ComputeGraph { val i = ScalarField() // Scalar field having a single value i <== i + 1 // Add 1 on each clock tick } // Step 2: Manipulate the ComputeGraph with reset, step, run, read, etc. // Once any of these commands have been executed- don't add any more fields!

// Use ComputeGraph.withRelease() to ensure OpenCL resources are cleaned up in all cases cg.withRelease { def iValue = cg.read(cg.i).asInstanceOf[ScalarFieldReader].read() for (stepNum <- 1 to 5) { cg.step println(s"Value of field 'i' after $stepNum steps = $iValue") } } }

// produces: Value of field 'i' after 1 steps = 1.0 Value of field 'i' after 2 steps = 2.0 Value of field 'i' after 3 steps = 3.0 Value of field 'i' after 4 steps = 4.0 Value of field 'i' after 5 steps = 5.0