Ejemplo n.º 1
0
// unpickle the network!
u8* net_unpickle(const u8* src) {
  u32 i, count, val;
  op_id_t id;
  op_t* op;

  // reset operator count, param count, pool offset, etc
  // no system operators after this
  net_deinit();


  // get count of operators
  // (use 4 bytes for alignment)
  src = unpickle_32(src, &count);

  #ifdef PRINT_PICKLE
    print_dbg("\r\n count of ops: ");
    print_dbg_ulong(count);
  #endif

  // loop over operators
  for(i=0; i<count; ++i) {
    // get operator class id
    src = unpickle_32(src, &val);
    id = (op_id_t)val;

    #ifdef PRINT_PICKLE
        print_dbg("\r\n adding op, class id: ");
        print_dbg_ulong(id);
    #endif

    // add and initialize from class id
    /// .. this should update the operator count, inodes and onodes
    net_add_op(id);

    // unpickle operator state (if needed)
    op = net->ops[net->numOps - 1];

    if(op->unpickle != NULL)  {
      #ifdef PRINT_PICKLE
            print_dbg(" ... unpickling op .... ");
            print_dbg_ulong(id);
      #endif
      src = (*(op->unpickle))(op, src);
    }
  }

#if 1

  /// copy ALL i/o nodes, even unused!
  print_dbg("\r\n reading all input nodes ");
  
  for(i=0; i < (NET_INS_MAX); ++i) {
#ifdef PRINT_PICKLE
    print_dbg("\r\n unpickling input node, idx: ");
    print_dbg_ulong(i);
#endif

    src = inode_unpickle(src, &(net->ins[i]));
  }

#ifdef PRINT_PICKLE
  print_dbg("\r\n reading all output nodes");
#endif
  // read output nodes
  for(i=0; i < NET_OUTS_MAX; ++i) {
#ifdef PRINT_PICKLE
    print_dbg("\r\n unpickling output node, idx: ");
    print_dbg_ulong(i);
#endif 

    src = onode_unpickle(src, &(net->outs[i]));
    if(i < net->numOuts) {
      if(net->outs[i].target >= 0) {
	// reconnect so the parent operator knows what to do
	net_connect(i, net->outs[i].target);
      }
    }
  }

#else 
#error broken input node unserialization
/* /\* #ifdef PRINT_PICKLE *\/ */
/* /\*   print_dbg("\r\n reading input nodes, count: "); *\/ */
/* /\*   print_dbg_ulong(net->numIns); *\/ */
/* /\* #endif *\/ */
  
/*   for(i=0; i < (net->numIns); ++i) { */
/*     src = inode_unpickle(src, &(net->ins[i])); */
/*   } */

/* /\* #ifdef PRINT_PICKLE *\/ */
/* /\*   print_dbg("\r\n reading output nodes, count: "); *\/ */
/* /\*   print_dbg_ulong(net->numOuts); *\/ */
/* /\* #endif *\/ */

/*   // read output nodes */
/*   for(i=0; i < net->numOuts; ++i) { */
/*     src = onode_unpickle(src, &(net->outs[i])); */
/*     // reconnect so the parent operator knows what to do */
/*     net_connect(i, net->outs[i].target); */
/*   } */
#endif

  // get count of parameters
  src = unpickle_32(src, &val);
  net->numParams = (u16)val;

#ifdef PRINT_PICKLE
  print_dbg("\r\n reading params, count: ");
  print_dbg_ulong(net->numParams);
#endif

  // read parameter nodes (includes value and descriptor)
  for(i=0; i<(net->numParams); ++i) {
#ifdef PRINT_PICKLE
    print_dbg("\r\n unpickling param, idx: ");
    print_dbg_ulong(i);
#endif

    src = param_unpickle(&(net->params[i]), src);
  }
  
  return (u8*)src;
}
Ejemplo n.º 2
0
Archivo: net.c Proyecto: doomglue/aleph
// unpickle the network!
u8* net_unpickle(const u8* src) {
  u32 i, count, val;
  op_id_t id;
  op_t* op;

  // reset operator count, param count, pool offset, etc
  // no system operators after this
  net_deinit();


  // get count of operators
  // (use 4 bytes for alignment)
  src = unpickle_32(src, &count);

  print_dbg("\r\n count of ops: ");
  print_dbg_ulong(count);

  // loop over operators
  for(i=0; i<count; ++i) {
    // get operator class id
    src = unpickle_32(src, &val);
    id = (op_id_t)val;

    // add and initialize from class id
    /// .. this should update the operator count, inodes and onodes
    print_dbg("\r\n adding op, class id: ");
    print_dbg_ulong(id);
  
    net_add_op(id);

    // unpickle operator state (if needed)
    op = net->ops[net->numOps - 1];

    if(op->unpickle != NULL) {
      print_dbg(" ... unpickling op .... ");
      print_dbg_ulong(id);
      src = (*(op->unpickle))(op, src);
    }
  }

  // read input nodes
  //  for(i=0; i < (net->numIns + net->numParams); ++i) {
  ///// FIXME: 
  /// tried adding the params to input list here, for play-mode flag
  /// but somehow, this breaks stuff.
#if 1
  /// copy ALL i/o nodes, even unused
  print_dbg("\r\n reading all input nodes ");
  
  for(i=0; i < (NET_INS_MAX); ++i) {
    print_dbg("\r\n unpickling input node, idx: ");
    print_dbg_ulong(i);

    src = inode_unpickle(src, &(net->ins[i]));
  }

  print_dbg("\r\n reading all output nodes");
  // read output nodes
  for(i=0; i < NET_OUTS_MAX; ++i) {
    print_dbg("\r\n unpickling output node, idx: ");
    print_dbg_ulong(i);

    src = onode_unpickle(src, &(net->outs[i]));
    if(i < net->numOuts) {
      if(net->outs[i].target >= 0) {
	// reconnect so the parent operator knows what to do
	net_connect(i, net->outs[i].target);
      }
    }
  }
#else
  print_dbg("\r\n reading input nodes, count: ");
  print_dbg_ulong(net->numIns);
  
  for(i=0; i < (net->numIns); ++i) {
    src = inode_unpickle(src, &(net->ins[i]));
  }

  print_dbg("\r\n reading output nodes, count: ");
  print_dbg_ulong(net->numOuts);

  // read output nodes
  for(i=0; i < net->numOuts; ++i) {
    src = onode_unpickle(src, &(net->outs[i]));
    // reconnect so the parent operator knows what to do
    net_connect(i, net->outs[i].target);
  }
#endif

  // get count of parameters
  src = unpickle_32(src, &val);
  net->numParams = (u16)val;

  print_dbg("\r\n reading params, count: ");
  print_dbg_ulong(net->numParams);

  // read parameter nodes (includes value and descriptor)
  for(i=0; i<(net->numParams); ++i) {
    print_dbg("\r\n unpickling param, idx: ");
    print_dbg_ulong(i);

    src = param_unpickle(&(net->params[i]), src);
  }
  
  return (u8*)src;
}