Skip to content

Commit b5ff889

Browse files
committed
add limits for too large problems
1 parent 586273f commit b5ff889

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/kernels.cc.cu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ cudaError_t calculatePermanent(cudaStream_t stream,
268268
idx_max *= h_n_ary_limits[i];
269269
}
270270

271+
const uint64_t MAX_IDX_MAX = 100000000;
272+
if (idx_max > MAX_IDX_MAX)
273+
{
274+
cudaFree(d_new_matrix);
275+
cudaFree(d_new_rows);
276+
cudaFree(d_n_ary_limits);
277+
throw std::runtime_error("Problem too large: idx_max exceeds safe limit.");
278+
}
279+
271280
cuda_err = cudaMalloc(&d_n_ary_limits, n_ary_size * sizeof(int));
272281
if (cuda_err != cudaSuccess)
273282
{

src/permanent.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ std::complex<double> permanent(Matrix<std::complex<double>> &A,
126126
idx_max *= n_ary_limits[i];
127127
}
128128

129+
const uint64_t MAX_IDX_MAX = 100000000;
130+
if (idx_max > MAX_IDX_MAX)
131+
{
132+
throw std::runtime_error("Problem too large: idx_max exceeds safe limit.");
133+
}
134+
129135
// determine the concurrency of the calculation
130136
unsigned int n_threads = std::thread::hardware_concurrency();
131137
int64_t concurrency = static_cast<int64_t>(n_threads) * 4;

0 commit comments

Comments
 (0)