diff --git a/common.h b/common.h index 0e7f66d..03e597e 100644 --- a/common.h +++ b/common.h @@ -77,6 +77,22 @@ struct badarraysize : public std::exception } }; +struct badbuffersize : public std::exception +{ + virtual const char * what () const throw () + { + return "Device cannot allocate a buffer big enough"; + } +}; + +struct badmemsize : public std::exception +{ + virtual const char * what () const throw () + { + return "Device does not have enough memory for all 3 buffers"; + } +}; + template < typename T > void check_solution(void* a_in, void* b_in, void* c_in) { diff --git a/cuda-stream.cu b/cuda-stream.cu index 5178f8a..cb4cbaa 100644 --- a/cuda-stream.cu +++ b/cuda-stream.cu @@ -159,6 +159,11 @@ int main(int argc, char *argv[]) // Print out device name std::cout << "Using CUDA device " << getDeviceName(deviceIndex) << std::endl; + // Check buffers fit on the device + cudaDeviceProp props; + cudaGetDeviceProperties(&props, deviceIndex); + // if (props. < DATATYPE_SIZE*ARRAY_SIZE) throw badbuffersize(); + if (props.totalGlobalMem < 3*DATATYPE_SIZE*ARRAY_SIZE) throw badmemsize(); // Create host vectors void * h_a = malloc(ARRAY_SIZE*DATATYPE_SIZE); diff --git a/ocl-stream.cpp b/ocl-stream.cpp index 70d9c29..9d44cc7 100644 --- a/ocl-stream.cpp +++ b/ocl-stream.cpp @@ -165,6 +165,13 @@ int main(int argc, char *argv[]) std::string name = getDeviceName(device); std::cout << "Using OpenCL device " << name << std::endl; + // Check buffers fit on the device + status = "Getting device memory sizes"; + cl_ulong totalmem = device.getInfo(); + cl_ulong maxbuffer = device.getInfo(); + if (maxbuffer < DATATYPE_SIZE*ARRAY_SIZE) throw badbuffersize(); + if (totalmem < 3*DATATYPE_SIZE*ARRAY_SIZE) throw badmemsize(); + try { std::string options = "";