Използвам cusp::bicgstab за решаване на линейна система Ax=b, в която A е 3D Poisson върху мрежа MxNxP, x е неизвестно, а b е RHS. Имам K40m Tesla, който има 12 GB памет.
Тествах с M=2000, N=2000, P=20 (80 милиона неизвестни), типът на променливата е double; така че общата използвана памет (за A, x, b, и други) е приблизително 5,5 GB. Кодът работи добре.
След това увеличих стойността на M или N до 2500 (използваната памет все още е много по-малко от 12GB), програмата срещна следната грешка:
terminate, извикан след хвърляне на екземпляр на 'thrust::system::detail::bad_alloc'
what(): std::bad_alloc: липсва памет
Прекратено (ядрото е изхвърлено)
Виждам, че грешката е изчерпана памет на устройството. Затова се чудя за управлението на паметта в библиотеката cusp. Използва ли приблизително същото пространство в паметта за допълнителни променливи (както се използва за A,x,b) по време на повторенията за решаване на системата?
По-долу е моят код:
#include <iostream>
#include <cuda.h>
#include <cuda_runtime_api.h>
#include <cusp/monitor.h>
#include <cusp/krylov/bicgstab.h>
#include <cusp/gallery/poisson.h>
#include <cusp/print.h>
// where to perform the computation
typedef cusp::device_memory MemorySpace;
// which floating point type to use
typedef double ValueType;
int main(int argc, char **argv)
{
size_t avail, total; // Available and Total memory count
int N = 2500, M = 2000, P = 20; // Dimension
// create a matrix for a 3D Poisson problem on a MxNxP grid
cusp::dia_matrix<int, ValueType, MemorySpace> A;
cusp::gallery::poisson7pt(A, N, M, P);
// allocate storage for solution (x) and right hand side (b)
cusp::array1d<ValueType, MemorySpace> x(N*M*P, 0.0);
cusp::array1d<ValueType, MemorySpace> b(N*M*P, 1.0);
// set preconditioner (identity)
cusp::identity_operator<ValueType, MemorySpace> ID(A.num_rows, A.num_rows);
// Set stopping criteria:
// ... iteration_limit = 100
// ... relative_tolerance = 1e-9
// ... absolute_tolerance = 0
cusp::default_monitor <ValueType> monitor(b, 100, 1e-9);
// solve the linear system A x = b
cusp::krylov::bicgstab(A, x, b, monitor, ID);
// Get device memory usage
cudaMemGetInfo( &avail, &total );
size_t used = total - avail;
std::cout << "Device memory used: " << used/(1024.*1024.*1024.) << " Gb " << std::endl;
return 0;
}