示例#1
0
    const Matrix* BooleanInvolutiveBasis<MonomType>::ToMatrix() const
    {
        MatrixConstructor matrixConstructor(PRing->make_FreeModule(1), 0);
        const Monoid* monoid = PRing->getMonoid();
        const ring_elem coefficientUnit = PRing->getCoefficients()->one();
        monomial tmpRingMonomial = monoid->make_one();
        
        for (typename std::list<Polynom<MonomType>*>::const_iterator currentPolynom = GBasis.begin(); 
             currentPolynom != GBasis.end(); 
             ++currentPolynom)
        {
            if (!*currentPolynom)
            {
                continue;
            }
            
            ring_elem currentRingPolynomial;

            for (const MonomType* currentMonom = &(**currentPolynom).Lm(); 
                 currentMonom; 
                 currentMonom = currentMonom->Next)
            {
                exponents currentExponent = newarray_atomic_clear(int, MonomType::GetDimIndepend());
                typename std::set<typename MonomType::Integer> variablesSet = currentMonom->GetVariablesSet();
                
                for (typename std::set<typename MonomType::Integer>::const_iterator currentVariable = variablesSet.begin();
                     currentVariable != variablesSet.end();
                     ++currentVariable)
                {
                    currentExponent[*currentVariable] = 1;
                }
                
                monoid->from_expvector(currentExponent, tmpRingMonomial);
                deletearray(currentExponent);

                ring_elem tmpRingPolynomial = PRing->make_flat_term(coefficientUnit, tmpRingMonomial);
                PRing->add_to(currentRingPolynomial, tmpRingPolynomial);
            }
            
            matrixConstructor.append(PRing->make_vec(0, currentRingPolynomial));
        }
        
        return matrixConstructor.to_matrix();
    }
示例#2
0
void Generator<Annotation, Runtime, Driver>::generate(
  const LoopTrees<Annotation> & loop_trees,
  std::set<std::list<Kernel<Annotation, Runtime> *> > & kernel_lists,
  LoopMapper<Annotation, Runtime> & loop_mapper,
  LoopTiler<Annotation, Runtime> & loop_tiler,
  DataFlow<Annotation, Runtime> & data_flow
) {
  typedef typename LoopTrees<Annotation>::loop_t loop_t;
  typedef typename LoopTiler<Annotation, Runtime>::loop_tiling_t loop_tiling_t;
  typedef Kernel<Annotation, Runtime> Kernel;

  typename std::set<std::list<Kernel *> >::const_iterator it_kernel_list;
  typename std::list<Kernel *>::const_iterator it_kernel;

  typename DataFlow<Annotation, Runtime>::context_t df_ctx;

  // 0 - init data flow

  data_flow.createContextFromLoopTree(loop_trees, df_ctx);
  data_flow.markSplittedData(df_ctx);

  // 1 - Loop Selection : Generate multiple list of kernel that implement the given LoopTree

  loop_mapper.createKernels(loop_trees, kernel_lists);

  // 2 - Data Flow : performs data-flow analysis for each list of kernel

  for (it_kernel_list = kernel_lists.begin(); it_kernel_list != kernel_lists.end(); it_kernel_list++)
    data_flow.generateFlowSets(*it_kernel_list, df_ctx);

  // 3 - Arguments : determines the list of arguments needed by each kernel

  for (it_kernel_list = kernel_lists.begin(); it_kernel_list != kernel_lists.end(); it_kernel_list++)
    for (it_kernel = it_kernel_list->begin(); it_kernel != it_kernel_list->end(); it_kernel++)
      buildArgumentLists(loop_trees, *it_kernel);

  for (it_kernel_list = kernel_lists.begin(); it_kernel_list != kernel_lists.end(); it_kernel_list++)
    for (it_kernel = it_kernel_list->begin(); it_kernel != it_kernel_list->end(); it_kernel++) {

      // 4 - Iterations Mapping : determines the "shape" of every loop of each kernel.
      //     The "shape" of a loop is how this loop is adapted to the execution model.

      std::map<loop_t *, std::vector<loop_tiling_t *> > tiling_map;

      loop_tiler.determineTiles(*it_kernel, tiling_map);

      std::set<std::map<loop_t *, loop_tiling_t *> > loop_tiling_set;
      buildAllTileConfigs<Annotation, Runtime>(
        std::map<loop_t *, loop_tiling_t *>(),
        tiling_map.begin(),
        tiling_map.end(),
        loop_tiling_set
      );

      // 5 - Code Generation

      size_t cnt = 0;
      typename std::set<std::map<loop_t *, loop_tiling_t *> >::iterator it_loop_tiling_map;
      for (it_loop_tiling_map = loop_tiling_set.begin(); it_loop_tiling_map != loop_tiling_set.end(); it_loop_tiling_map++) {
        typename ::MFB::KLT<Kernel>::object_desc_t kernel_desc(cnt++, *it_kernel, p_file_id);

        kernel_desc.tiling.insert(it_loop_tiling_map->begin(), it_loop_tiling_map->end());

        typename Kernel::kernel_desc_t * kernel = p_driver.template build<Kernel>(kernel_desc);

        (*it_kernel)->addKernel(kernel);
      }
      typename std::map<loop_t *, std::vector<loop_tiling_t *> >::const_iterator it_tiling_vect;
      typename std::vector<loop_tiling_t *>::const_iterator it_tiling;
      for (it_tiling_vect = tiling_map.begin(); it_tiling_vect != tiling_map.end(); it_tiling_vect++)
        for (it_tiling = it_tiling_vect->second.begin(); it_tiling != it_tiling_vect->second.end(); it_tiling++)
          delete *it_tiling;
      
    }
}