SpatialOps
MemoryTypes.h
1 /*
2  * DeviceTypes.h
3  *
4  */
5 
6 #ifndef MEMORYTYPES_H_
7 #define MEMORYTYPES_H_
8 #include <string>
9 #include <sstream>
10 #include <stdexcept>
11 
12 namespace SpatialOps{
13 
14 #define CPU_INDEX -1
15 #define GPU_INDEX 0
16 
17 #define IS_CPU_INDEX(INDEX) (INDEX == CPU_INDEX)
18 #define IS_GPU_INDEX(INDEX) (INDEX >= GPU_INDEX)
19 #define IS_VALID_INDEX(INDEX) (INDEX >= CPU_INDEX)
20 
21 namespace DeviceTypeTools {
26  inline std::string get_memory_type_description( short int deviceIndex ) {
27  if( deviceIndex == CPU_INDEX ){
28  return std::string("(Locally allocated, generic system RAM)");
29  }
30  else if( IS_GPU_INDEX(deviceIndex) ){
31  return std::string("(Externally allocated, CUDA GPU device)");
32  }
33  else{
34  return std::string("(Unknown or Invalid)");
35  }
36  }
37 
42  inline void check_valid_index( short int deviceIndex, const char* file, int line) {
43  if( !IS_VALID_INDEX(deviceIndex) ) {
44  std::ostringstream msg;
45  msg << "Given an unknown device index. Given: " << deviceIndex << " ("
46  << DeviceTypeTools::get_memory_type_description(deviceIndex) << ")" << std::endl
47  << "\t - " << file << " : " << line << std::endl;
48  throw(std::runtime_error(msg.str()));
49  }
50  }
51 
52 } // namespace DeviceTypeTools
53 } // namespace SpatialOps
54 
55 #endif /* DEVICETYPES_H_ */
Provide descriptions.