Check the device can support the array sizes before trying to allocate memory
This commit is contained in:
parent
70ccd22919
commit
ec8799c4db
16
common.h
16
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 >
|
template < typename T >
|
||||||
void check_solution(void* a_in, void* b_in, void* c_in)
|
void check_solution(void* a_in, void* b_in, void* c_in)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -159,6 +159,11 @@ int main(int argc, char *argv[])
|
|||||||
// Print out device name
|
// Print out device name
|
||||||
std::cout << "Using CUDA device " << getDeviceName(deviceIndex) << std::endl;
|
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
|
// Create host vectors
|
||||||
void * h_a = malloc(ARRAY_SIZE*DATATYPE_SIZE);
|
void * h_a = malloc(ARRAY_SIZE*DATATYPE_SIZE);
|
||||||
|
|||||||
@ -165,6 +165,13 @@ int main(int argc, char *argv[])
|
|||||||
std::string name = getDeviceName(device);
|
std::string name = getDeviceName(device);
|
||||||
std::cout << "Using OpenCL device " << name << std::endl;
|
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_DEVICE_GLOBAL_MEM_SIZE>();
|
||||||
|
cl_ulong maxbuffer = device.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>();
|
||||||
|
if (maxbuffer < DATATYPE_SIZE*ARRAY_SIZE) throw badbuffersize();
|
||||||
|
if (totalmem < 3*DATATYPE_SIZE*ARRAY_SIZE) throw badmemsize();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string options = "";
|
std::string options = "";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user