Check bufers fit on CUDA device

This commit is contained in:
Tom Deakin 2016-04-27 11:52:15 +01:00
parent 9aa27cd91d
commit 40c787d040
2 changed files with 7 additions and 0 deletions

View File

@ -16,6 +16,12 @@ CUDAStream<T>::CUDAStream(const unsigned int ARRAY_SIZE)
{ {
array_size = 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 // Create device buffers
cudaMalloc(&d_a, ARRAY_SIZE*sizeof(T)); cudaMalloc(&d_a, ARRAY_SIZE*sizeof(T));
check_error(); check_error();

View File

@ -1,5 +1,6 @@
#include <iostream> #include <iostream>
#include <stdexcept>
#include "Stream.h" #include "Stream.h"