 
             device_internals.cusolver_handle().Call(
                 geqrf_bufferSize,
-                m, n, a_ptr, lda, &lwork_geqrf);
+                m, n, r_ptr, lda, &lwork_geqrf);
 
             device_internals.cusolver_handle().Call(
                 orgqr_bufferSize,
-                m, n, n, a_ptr, lda, tau_ptr, &lwork_orgqr);
+                m, n, n, r_ptr, lda, tau_ptr, &lwork_orgqr);
 
             lwork = (lwork_geqrf > lwork_orgqr) ? lwork_geqrf : lwork_orgqr;
 

                throw ChainerxError{"Unsuccessfull geqrf (QR) execution. Info = ", devInfo_h};
            }

            device_internals.cusolver_handle().Call(
                orgqr,
                m, n, n, a_ptr, lda, tau_ptr, work_ptr, lwork, devInfo);

            CheckCudaError(cudaMemcpy(&devInfo_h, devInfo, sizeof(int), cudaMemcpyDeviceToHost));
            if (devInfo_h != 0) {
                throw ChainerxError{"Unsuccessfull orgqr (QR) execution. Info = ", devInfo_h};
            }
        };

        if (a.dtype() == Dtype::kFloat32) {
            qr_impl(PrimitiveType<float>{}, cusolverDnSgeqrf_bufferSize, cusolverDnSorgqr_bufferSize, cusolverDnSgeqrf, cusolverDnSorgqr);
        } else {
            CHAINERX_ASSERT(a.dtype() == Dtype::kFloat64);
            qr_impl(PrimitiveType<double>{}, cusolverDnDgeqrf_bufferSize, cusolverDnDorgqr_bufferSize, cusolverDnDgeqrf, cusolverDnDorgqr);
        }

        return std::make_tuple(std::move(Q), std::move(R));

    }
};


            device_internals.cusolver_handle().Call(
                geqrf,
                m, n, r_ptr, lda, tau_ptr, work_ptr, lwork, devInfo);

            int devInfo_h = 0;
            CheckCudaError(cudaMemcpy(&devInfo_h, devInfo, sizeof(int), cudaMemcpyDeviceToHost));
