예제 #1
0
 void copy(const compressed_matrix<SCALARTYPE, ALIGNMENT> & gpu_matrix,
                  CPU_MATRIX & cpu_matrix )
 {
   if ( gpu_matrix.size1() > 0 && gpu_matrix.size2() > 0 )
   {
     cpu_matrix.resize(gpu_matrix.size1(), gpu_matrix.size2());
     
     //get raw data from memory:
     std::vector<unsigned int> row_buffer(gpu_matrix.size1() + 1);
     std::vector<unsigned int> col_buffer(gpu_matrix.nnz());
     std::vector<SCALARTYPE> elements(gpu_matrix.nnz());
     
     //std::cout << "GPU->CPU, nonzeros: " << gpu_matrix.nnz() << std::endl;
     
     cl_int err;
     err = clEnqueueReadBuffer(viennacl::ocl::device().queue().get(), gpu_matrix.handle1().get(), CL_TRUE, 0, sizeof(unsigned int)*(gpu_matrix.size1() + 1), &(row_buffer[0]), 0, NULL, NULL);
     CL_ERR_CHECK(err);
     err = clEnqueueReadBuffer(viennacl::ocl::device().queue().get(), gpu_matrix.handle2().get(), CL_TRUE, 0, sizeof(unsigned int)*gpu_matrix.nnz(), &(col_buffer[0]), 0, NULL, NULL);
     CL_ERR_CHECK(err);
     err = clEnqueueReadBuffer(viennacl::ocl::device().queue().get(), gpu_matrix.handle().get(), CL_TRUE, 0, sizeof(SCALARTYPE)*gpu_matrix.nnz(), &(elements[0]), 0, NULL, NULL);
     CL_ERR_CHECK(err);
     viennacl::ocl::finish();
     
     //fill the cpu_matrix:
     unsigned int data_index = 0;
     for (unsigned int row = 1; row <= gpu_matrix.size1(); ++row)
     {
       while (data_index < row_buffer[row])
       {
         if (col_buffer[data_index] >= gpu_matrix.size1())
         {
           std::cerr << "ViennaCL encountered invalid data at colbuffer[" << data_index << "]: " << col_buffer[data_index] << std::endl;
           return;
         }
         
         if (elements[data_index] != static_cast<SCALARTYPE>(0.0))
           cpu_matrix(row-1, col_buffer[data_index]) = elements[data_index];
         ++data_index;
       }
     }
   }
 }
    void inplace_solve(compressed_matrix<SCALARTYPE, MAT_ALIGNMENT> const & L, vector<SCALARTYPE, VEC_ALIGNMENT> & vec, viennacl::linalg::unit_lower_tag)
    {
      viennacl::ocl::kernel & k = viennacl::ocl::get_kernel(viennacl::linalg::kernels::compressed_matrix<SCALARTYPE, MAT_ALIGNMENT>::program_name(), "lu_forward");
      unsigned int threads = k.local_work_size();

      k.global_work_size(k.local_work_size());
      viennacl::ocl::enqueue(k(L.handle1(), L.handle2(), L,
                                                              viennacl::ocl::local_mem(sizeof(int) * (threads+1)),
                                                              viennacl::ocl::local_mem(sizeof(SCALARTYPE) * threads),
                                                              vec, L.size1()));        
    }