2015-11-04 15 views
0

我使用尖:: BICGSTAB求解線性系統Ax = b的,其中是3D泊松上MxNxP齧合,X是未知數,並且b是RHS。我有一個K40m特斯拉它有12GB的內存。內存使用解算器

我與M = 2000,N = 2000,P = 20(80個百萬未知數),變量類型是雙測試;所以使用的總內存(對於A,x,b,等)大約是5.5GB。代碼工作正常。

然後I M或N的值增加到2500(使用的存儲器仍比12GB少得多),則程序遇到下列錯誤:

terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'

what(): std::bad_alloc: out of memory
Aborted (core dumped)

我看到錯誤是「出的設備存儲器「。因此,我想知道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; 
} 

回答

1

您可以閱讀sourcebicgstab解算自己,但它看起來像有八個臨時陣列,每個陣列具有相同數量的條目在你的矩陣行。如果我已經正確讀取了您的代碼,那意味着您需要至少有8 * N * M * P * sizeof(double)字節的空閒GPU內存才能進入求解器運行的bicgstab調用。

+0

你說得對。 'bicgstab'中有8個額外的臨時數組。泊松三維問題有9個數組(A:7,b:1,x:1),所以使用的峯值存儲大約爲'17 * N * M * P * sizeof(double)'。現在一切都很清楚。 – PLe