Esempio n. 1
0
// This is the "inner loop" of the neural simulation.
// Every spike event could cause upto 256 different weights to
// be put into the ring buffer.
static inline void process_fixed_synapses (address_t fixed)
{
  register uint32_t *synaptic_words = fixed_weight_controls(fixed);
  register uint32_t fixed_synapse  = num_fixed_synapses(fixed);
  register uint32_t synaptic_word, delay;
  register uint32_t weight;
  register uint32_t offset, index;
  register ring_entry_t *rp = ring_buffer;
  register uint32_t t = time;
  
  for ( ; fixed_synapse > 0; fixed_synapse--) 
  {
    // Get the next 32 bit word from the synaptic_row (should autoincrement pointer in single instruction)
    synaptic_word = *synaptic_words++;

    // Extract components from this word
    delay = sparse_delay(synaptic_word);
    index = sparse_type_index(synaptic_word);
    weight = sparse_weight(synaptic_word);
    
    // Convert into ring buffer offset
    offset = offset_sparse(delay + t, index);
    
    // Add weight to ring-buffer entry
    // **NOTE** Dave suspects that this could be a potential location for overflow
    rp[offset] += weight;         // Add the weight to the current ring_buffer value.
    
#define TEACHING_SYNAPSE 1 //settle for inhibitory at the moment    
    if (sparse_type(synaptic_word) == TEACHING_SYNAPSE) {
        plasticity_process_teaching_synaptic_event(sparse_index(synaptic_word));
    }
#ifdef DEBUG
      io_printf (IO_BUF, "pA) d: %2u, %c, n = %3u)] - {%08x %08x}\n",
      sparse_delay(synaptic_word),
      (sparse_type(synaptic_word)==0)? 'X': 'I',
      sparse_index(synaptic_word),
      SYNAPSE_DELAY_MASK,
      SYNAPSE_TYPE_INDEX_BITS
    );
#endif
  }
}
Esempio n. 2
0
Stokhos::SparseGridQuadrature<ordinal_type, value_type>::
SparseGridQuadrature(
  const Teuchos::RCP<const ProductBasis<ordinal_type,value_type> >& product_basis,
  ordinal_type sparse_grid_level,
  value_type duplicate_tol,
  ordinal_type growth_rate) :
  coordinate_bases(product_basis->getCoordinateBases())
{
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos: Sparse Grid Generation");
#endif

  ordinal_type d = product_basis->dimension();
  ordinal_type p = product_basis->order();
  ordinal_type sz = product_basis->size();
  ordinal_type level = sparse_grid_level;

  // Make level = order the default, which is correct for Gaussian abscissas
  // slow, linear growth, and total-order basis
  if (level == 0) {
    level = p;
  }

  //std::cout << "Sparse grid level = " << level << std::endl;

  // Compute quad points, weights, values
  Teuchos::Array<typename OneDOrthogPolyBasis<ordinal_type,value_type>::LevelToOrderFnPtr> growth_rules(d);
  
  Teuchos::Array< void (*) ( int order, int dim, double x[] ) > compute1DPoints(d);
  Teuchos::Array< void (*) ( int order, int dim, double w[] ) > compute1DWeights(d);
  for (ordinal_type i=0; i<d; i++) {
    compute1DPoints[i] = &(getMyPoints);
    compute1DWeights[i] = &(getMyWeights);
    growth_rules[i] = coordinate_bases[i]->getSparseGridGrowthRule();
  }

  // Set the static sparse grid quadrature pointer to this
  // (this will cause a conflict if another sparse grid quadrature object
  // is trying to access the VPISparseGrid library, but that's all we can
  // do at this point).
  sgq = this;

  int num_total_pts  =
    webbur::sgmg_size_total(d, level, growth_rate, &growth_rules[0]);
  ordinal_type ntot =
    webbur::sgmg_size(d, level, &compute1DPoints[0], duplicate_tol, 
                      growth_rate, &growth_rules[0]);
  Teuchos::Array<int> sparse_order(ntot*d);
  Teuchos::Array<int> sparse_index(ntot*d);
  Teuchos::Array<int> sparse_unique_index(num_total_pts);
  quad_points.resize(ntot);
  quad_weights.resize(ntot);
  quad_values.resize(ntot);
  Teuchos::Array<value_type> gp(ntot*d);

  webbur::sgmg_unique_index(d, level, &compute1DPoints[0],
			    duplicate_tol, ntot, num_total_pts, 
			    growth_rate, &growth_rules[0],
			    &sparse_unique_index[0]);
  webbur::sgmg_index(d, level, ntot, num_total_pts, 
		     &sparse_unique_index[0], growth_rate, 
		     &growth_rules[0], 
		     &sparse_order[0], &sparse_index[0]);
  webbur::sgmg_weight(d, level, &compute1DWeights[0],
		      ntot, num_total_pts, 
		      &sparse_unique_index[0], growth_rate,
		      &growth_rules[0],
		      &quad_weights[0]);
  webbur::sgmg_point(d, level, &compute1DPoints[0],
		     ntot, &sparse_order[0], 
		     &sparse_index[0], growth_rate,
		     &growth_rules[0], 
		     &gp[0]);
  
  for (ordinal_type i=0; i<ntot; i++) {
    quad_values[i].resize(sz);
    quad_points[i].resize(d);
    for (ordinal_type j=0; j<d; j++)
      quad_points[i][j] = gp[i*d+j];
    product_basis->evaluateBases(quad_points[i], quad_values[i]);
  }

  //std::cout << "Number of quadrature points = " << ntot << std::endl;
}
Stokhos::AnisoSparseGridQuadrature<ordinal_type, value_type>::
AnisoSparseGridQuadrature(
  const Teuchos::RCP<const ProductBasis<ordinal_type,value_type> >& product_basis,
  ordinal_type sparse_grid_level, value_type dim_weights[]) :
  coordinate_bases(product_basis->getCoordinateBases())
{
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::AnisoSparseGridQuadrature -- Quad Grid Generation");
  ordinal_type d = product_basis->dimension();
  ordinal_type p = product_basis->order();
  ordinal_type sz = product_basis->size();
  ordinal_type level = sparse_grid_level;

  // Mike's heuristic formula for computing the level
  if (level == 0) {
    level = static_cast<ordinal_type>(std::ceil(0.5*(p+d-1)));
    if (level < d)
      level = p;
  }

  std::cout << "Sparse grid level = " << level << std::endl;

  // Compute quad points, weights, values
  Teuchos::Array<int> rules(d), growthRules(d);

  Teuchos::Array< void (*) ( int order, int dim, double x[] ) > compute1DPoints(d);
  Teuchos::Array< void (*) ( int order, int dim, double w[] ) > compute1DWeights(d);
  for (ordinal_type i=0; i<d; i++) {
    compute1DPoints[i] = &(getMyPoints);
    compute1DWeights[i] = &(getMyWeights);
    rules[i] = coordinate_bases[i]->getSparseGridRule();
    growthRules[i] = coordinate_bases[i]->getSparseGridGrowthRule();
  }

  // Set the static sparse grid quadrature pointer to this
  // (this will cause a conflict if another sparse grid quadrature object
  // is trying to access the VPISparseGrid library, but that's all we can
  // do at this point).
  sgq = this;

  int num_total_pts =
    webbur::sandia_sgmga_size_total(d,&dim_weights[0],level,&rules[0],
				    &growthRules[0]);

  ordinal_type ntot =
    webbur::sandia_sgmga_size(d,&dim_weights[0],level,&rules[0],
			      &compute1DPoints[0], 1e-15,&growthRules[0]);

  Teuchos::Array<int> sparse_order(ntot*d);
  Teuchos::Array<int> sparse_index(ntot*d);
  Teuchos::Array<int> sparse_unique_index(num_total_pts);
  quad_points.resize(ntot);
  quad_weights.resize(ntot);
  quad_values.resize(ntot);
  Teuchos::Array<value_type> gp(ntot*d);

  webbur::sandia_sgmga_unique_index(d, &dim_weights[0], level, &rules[0],
				    &compute1DPoints[0],
				    1e-15, ntot, num_total_pts,
				    &growthRules[0],
				    &sparse_unique_index[0] );


  webbur::sandia_sgmga_index(d, &dim_weights[0], level,
			     &rules[0], ntot, num_total_pts, 
			     &sparse_unique_index[0],
			     &growthRules[0],
			     &sparse_order[0], &sparse_index[0]);

  webbur::sandia_sgmga_weight(d,&dim_weights[0],level,
			      &rules[0], &compute1DWeights[0],
			      ntot, num_total_pts, &sparse_unique_index[0],
			      &growthRules[0],
			      &quad_weights[0]);

  webbur::sandia_sgmga_point(d, &dim_weights[0], level,
			     &rules[0], &compute1DPoints[0],
			     ntot, &sparse_order[0], &sparse_index[0],
			     &growthRules[0],
			     &gp[0]);

  for (ordinal_type i=0; i<ntot; i++) {
    quad_values[i].resize(sz);
    quad_points[i].resize(d);
    for (ordinal_type j=0; j<d; j++)
      quad_points[i][j] = gp[i*d+j];
    product_basis->evaluateBases(quad_points[i], quad_values[i]);
  }

  std::cout << "Number of quadrature points = " << ntot << std::endl;
}