apply_geqrf Class — pytorch Architecture
Architecture documentation for the apply_geqrf class in BatchLinearAlgebraLib.cpp from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/cuda/linalg/BatchLinearAlgebraLib.cpp lines 962–1046
template <typename scalar_t>
static void apply_geqrf(const Tensor& A, const Tensor& tau) {
int64_t m = A.size(-2);
int64_t n = A.size(-1);
int64_t lda = std::max<int64_t>(1, m);
int64_t batch_size = batchCount(A);
auto A_stride = matrixStride(A);
auto tau_stride = tau.size(-1);
auto A_data = A.data_ptr<scalar_t>();
auto tau_data = tau.data_ptr<scalar_t>();
auto infos = at::zeros({1}, A.options().dtype(at::kInt));
auto infos_data = infos.data_ptr<int>();
// get the optimal work size and allocate workspace tensor
#ifdef USE_CUSOLVER_64_BIT
size_t worksize_device; // workspaceInBytesOnDevice
size_t worksize_host; // workspaceInBytesOnHost
cusolverDnParams_t params = nullptr; // use default algorithm (currently it's the only option)
at::cuda::solver::xgeqrf_bufferSize<scalar_t>(
at::cuda::getCurrentCUDASolverDnHandle(),
params,
m,
n,
A_data,
lda,
tau_data,
&worksize_device,
&worksize_host);
#else
int lwork;
int m_32 = cuda_int_cast(m, "m");
int n_32 = cuda_int_cast(n, "n");
int lda_32 = cuda_int_cast(lda, "lda");
at::cuda::solver::geqrf_bufferSize<scalar_t>(
at::cuda::getCurrentCUDASolverDnHandle(), m_32, n_32, A_data, lda_32, &lwork);
#endif // USE_CUSOLVER_64_BIT
for (decltype(batch_size) i = 0; i < batch_size; i++) {
scalar_t* A_working_ptr = &A_data[i * A_stride];
scalar_t* tau_working_ptr = &tau_data[i * tau_stride];
auto handle = at::cuda::getCurrentCUDASolverDnHandle();
#ifdef USE_CUSOLVER_64_BIT
// allocate workspace storage on device and host
auto& device_allocator = *at::cuda::getCUDADeviceAllocator();
auto work_device_data = device_allocator.allocate(worksize_device);
auto& host_allocator = *at::getCPUAllocator();
auto work_host_data = host_allocator.allocate(worksize_host);
at::cuda::solver::xgeqrf<scalar_t>(
handle,
params,
m,
n,
A_working_ptr,
lda,
tau_working_ptr,
static_cast<scalar_t*>(work_device_data.get()),
worksize_device,
static_cast<scalar_t*>(work_host_data.get()),
worksize_host,
infos_data);
#else
// allocate workspace storage on device
auto& allocator = *at::cuda::getCUDADeviceAllocator();
auto work_data = allocator.allocate(sizeof(scalar_t) * std::max<int>(1, lwork));
at::cuda::solver::geqrf<scalar_t>(
handle,
m_32,
n_32,
A_working_ptr,
lda_32,
tau_working_ptr,
static_cast<scalar_t*>(work_data.get()),
lwork,
infos_data);
#endif // USE_CUSOLVER_64_BIT
}
// info from geqrf only reports if the i-th parameter is wrong, not about the matrix singularity
// so we don't need to check it all the time
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(infos.item().toInt() == 0);
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free