viennacl / viennacl-dev

Developer repository for ViennaCL. Visit http://viennacl.sourceforge.net/ for the latest releases.
Other
281 stars 89 forks source link

Wrong copy of a gpu range to a cpu matrix #81

Closed karelp closed 10 years ago

karelp commented 10 years ago

When I copy matrix ranges from the GPU to a CPU matrix the values get copied to wrong indices:

void testMatrix() {
    using viennacl::range;
    viennacl::matrix<float> matrix = viennacl::scalar_matrix<float>(100, 100, 1.0f);

    auto submatrix = viennacl::project(matrix, range(1, matrix.size1()), range(0, matrix.size2()));
    ublas::matrix<float> cpu_copy(submatrix.size1(), submatrix.size2());
    viennacl::copy(submatrix, cpu_copy);

    for (size_t i = 0; i < cpu_copy.size1(); i++) {
        for (size_t j = 0; j < cpu_copy.size2(); j++) {
            assert(abs(cpu_copy(i, j) - 1.0f) <= 1e-5);
        }
    }
}

The above code fails for i = 77, j = 44.

The problem is most likely caused by line 191 in matrix_proxy.hpp:

vcl_size_t num_entries = gpu_matrix_range.size1() * gpu_matrix_range.size2();

It should probably be:

vcl_size_t num_entries = gpu_matrix_range.size1() * gpu_matrix_range.internal_size2();

I'm using Viennacl 1.5.2 with Visual Studio 2012.

karlrupp commented 10 years ago

Thanks, karelp, you are absolutely right. I could reproduce the issue and pushed a fix.

karelp commented 10 years ago

Thanks for the extremely fast response and fix, I appreciate it.

karlrupp commented 10 years ago

Thanks, it was a great report which we could quickly react upon :-)