From 40c787d0409d5f771cabb29105738752e8f49e2d Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Wed, 27 Apr 2016 11:52:15 +0100 Subject: [PATCH] Check bufers fit on CUDA device --- src/CUDAStream.cu | 6 ++++++ src/CUDAStream.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/CUDAStream.cu b/src/CUDAStream.cu index caf5e1a..5ec1e67 100644 --- a/src/CUDAStream.cu +++ b/src/CUDAStream.cu @@ -16,6 +16,12 @@ CUDAStream::CUDAStream(const unsigned int ARRAY_SIZE) { array_size = ARRAY_SIZE; + // Check buffers fit on the device + cudaDeviceProp props; + cudaGetDeviceProperties(&props, 0); + if (props.totalGlobalMem < 3*ARRAY_SIZE*sizeof(T)) + throw std::runtime_error("Device does not have enough memory for all 3 buffers"); + // Create device buffers cudaMalloc(&d_a, ARRAY_SIZE*sizeof(T)); check_error(); diff --git a/src/CUDAStream.h b/src/CUDAStream.h index 451cfc1..bde574e 100644 --- a/src/CUDAStream.h +++ b/src/CUDAStream.h @@ -1,5 +1,6 @@ #include +#include #include "Stream.h"