void level_scheduling_substitute(vector<ScalarType> & vec,
                                  viennacl::backend::mem_handle const & row_index_array,
                                  viennacl::backend::mem_handle const & row_buffer,
                                  viennacl::backend::mem_handle const & col_buffer,
                                  viennacl::backend::mem_handle const & element_buffer,
                                  std::size_t num_rows
                                  )
      {
        assert( viennacl::traits::handle(vec).get_active_handle_id() == row_index_array.get_active_handle_id() && bool("Incompatible memory domains"));
        assert( viennacl::traits::handle(vec).get_active_handle_id() ==      row_buffer.get_active_handle_id() && bool("Incompatible memory domains"));
        assert( viennacl::traits::handle(vec).get_active_handle_id() ==      col_buffer.get_active_handle_id() && bool("Incompatible memory domains"));
        assert( viennacl::traits::handle(vec).get_active_handle_id() ==  element_buffer.get_active_handle_id() && bool("Incompatible memory domains"));
        
        switch (viennacl::traits::handle(vec).get_active_handle_id())
        {
          case viennacl::MAIN_MEMORY:
            viennacl::linalg::host_based::detail::level_scheduling_substitute(vec, row_index_array, row_buffer, col_buffer, element_buffer, num_rows);
            break;
#ifdef VIENNACL_WITH_OPENCL
          case viennacl::OPENCL_MEMORY:
            viennacl::linalg::opencl::detail::level_scheduling_substitute(vec, row_index_array, row_buffer, col_buffer, element_buffer, num_rows);
            break;
#endif
#ifdef VIENNACL_WITH_CUDA
          case viennacl::CUDA_MEMORY:
            viennacl::linalg::cuda::detail::level_scheduling_substitute(vec, row_index_array, row_buffer, col_buffer, element_buffer, num_rows);
            break;
#endif
          default:
            throw "not implemented";
        }
      }
Пример #2
0
/** @brief Returns an ID for the currently active memory domain of an object */
inline viennacl::context context(viennacl::backend::mem_handle const & h)
{
#ifdef VIENNACL_WITH_OPENCL
  if (h.get_active_handle_id() == OPENCL_MEMORY)
    return viennacl::context(h.opencl_handle().context());
#endif

  return viennacl::context(h.get_active_handle_id());
}
Пример #3
0
static ViennaCLStatus init_host_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
{
  h.switch_active_handle_id(viennacl::MAIN_MEMORY);
  h.ram_handle().reset(x->host_mem);
  h.ram_handle().inc();
  if (x->precision == ViennaCLFloat)
    h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(float)); // not necessary, but still set for conciseness
  else if (x->precision == ViennaCLDouble)
    h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(double)); // not necessary, but still set for conciseness
  else
    return ViennaCLGenericFailure;

  return ViennaCLSuccess;
}
Пример #4
0
 void level_scheduling_substitute(vector<ScalarType> & vec,
                              viennacl::backend::mem_handle const & row_index_array,
                              viennacl::backend::mem_handle const & row_buffer,
                              viennacl::backend::mem_handle const & col_buffer,
                              viennacl::backend::mem_handle const & element_buffer,
                              std::size_t num_rows
                             )
 {
   viennacl::linalg::kernels::ilu<ScalarType, 1>::init();
   viennacl::ocl::kernel & k = viennacl::ocl::get_kernel(viennacl::linalg::kernels::ilu<ScalarType, 1>::program_name(), "level_scheduling_substitute");
   
   viennacl::ocl::enqueue(k(row_index_array.opencl_handle(), row_buffer.opencl_handle(), col_buffer.opencl_handle(), element_buffer.opencl_handle(),
                            vec, 
                            static_cast<cl_uint>(num_rows)));
 }
Пример #5
0
void level_scheduling_substitute(vector<NumericT> & x,
                                 viennacl::backend::mem_handle const & row_index_array,
                                 viennacl::backend::mem_handle const & row_buffer,
                                 viennacl::backend::mem_handle const & col_buffer,
                                 viennacl::backend::mem_handle const & element_buffer,
                                 vcl_size_t num_rows
                                )
{
  viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(x).context());

  viennacl::linalg::opencl::kernels::ilu<NumericT>::init(ctx);
  viennacl::ocl::kernel & k = ctx.get_kernel(viennacl::linalg::opencl::kernels::ilu<NumericT>::program_name(), "level_scheduling_substitute");

  viennacl::ocl::enqueue(k(row_index_array.opencl_handle(), row_buffer.opencl_handle(), col_buffer.opencl_handle(), element_buffer.opencl_handle(),
                           x,
                           static_cast<cl_uint>(num_rows)));
}
Пример #6
0
static ViennaCLStatus init_opencl_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
{
#ifdef VIENNACL_WITH_OPENCL
  h.switch_active_handle_id(viennacl::OPENCL_MEMORY);
  h.opencl_handle() = x->opencl_mem;
  h.opencl_handle().inc();
  if (x->precision == ViennaCLFloat)
    h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(float)); // not necessary, but still set for conciseness
  else if (x->precision == ViennaCLDouble)
    h.raw_size(static_cast<viennacl::vcl_size_t>(x->inc) * static_cast<viennacl::vcl_size_t>(x->size) * sizeof(double)); // not necessary, but still set for conciseness
  else
    return ViennaCLGenericFailure;

  return ViennaCLSuccess;
#else
  (void)h;
  (void)x;
  return ViennaCLGenericFailure;
#endif
}
Пример #7
0
static ViennaCLStatus init_cuda_vector(viennacl::backend::mem_handle & h, ViennaCLVector x)
{
#ifdef VIENNACL_WITH_CUDA
  h.switch_active_handle_id(viennacl::CUDA_MEMORY);
  h.cuda_handle().reset(x->cuda_mem);
  h.cuda_handle().inc();
  if (x->precision == ViennaCLFloat)
    h.raw_size(x->inc * x->size * sizeof(float)); // not necessary, but still set for conciseness
  else if (x->precision == ViennaCLDouble)
    h.raw_size(x->inc * x->size * sizeof(double)); // not necessary, but still set for conciseness
  else
    return ViennaCLGenericFailure;

  return ViennaCLSuccess;
#else
  (void)h;
  (void)x;
  return ViennaCLGenericFailure;
#endif
}
Пример #8
0
 static void dump(viennacl::backend::mem_handle const & buff, uniform_tag tag, cl_uint start, cl_uint size){
   viennacl::ocl::kernel & k = viennacl::ocl::get_kernel(viennacl::linalg::kernels::rand<ScalarType,1>::program_name(),"dump_uniform");
   k.global_work_size(0, viennacl::tools::roundUpToNextMultiple<unsigned int>(size,k.local_work_size(0)));
   viennacl::ocl::enqueue(k(buff.opencl_handle(), start, size, cl_float(tag.a), cl_float(tag.b) , cl_uint(time(0))));
 }