gpufilter
GPU-Efficient Recursive Filtering and Summed-Area Tables
|
00001 00008 #ifndef SYMBOL_H 00009 #define SYMBOL_H 00010 00011 //== INCLUDES ================================================================= 00012 00013 #include <string> 00014 #include <vector> 00015 00016 #include <error.h> 00017 00018 //== NAMESPACES =============================================================== 00019 00020 namespace gpufilter { 00021 00022 //== IMPLEMENTATION =========================================================== 00023 00032 template< class T > 00033 void copy_to_symbol( const std::string &name, 00034 const T &value ) { 00035 size_t size_storage; 00036 cudaGetSymbolSize(&size_storage, name.c_str()); 00037 cuda_error("Invalid symbol '"+name+"'"); 00038 00039 if( sizeof(T) > size_storage ) 00040 throw std::runtime_error("'"+name+"'"+" storage overflow"); 00041 00042 cudaMemcpyToSymbol(name.c_str(), &value, sizeof(T), 0, cudaMemcpyHostToDevice); 00043 cuda_error("Error copying '"+name+"' buffer to device"); 00044 } 00045 00053 inline void copy_to_symbol( const std::string &name, 00054 unsigned long value ) { 00055 copy_to_symbol(name, (unsigned int)value); 00056 } 00057 00065 inline void copy_to_symbol( const std::string &name, 00066 long value ) { 00067 copy_to_symbol(name, (int)value); 00068 } 00069 00079 template< class T > 00080 void copy_to_symbol( const std::string &name, 00081 const std::string &size_name, 00082 const std::vector<T> &items ) { 00083 size_t size_storage; 00084 cudaGetSymbolSize(&size_storage, name.c_str()); 00085 cuda_error("Invalid symbol '"+name+"'"); 00086 00087 size_t size = items.size()*sizeof(T); 00088 00089 if( size > size_storage ) 00090 throw std::runtime_error("'"+name+"'"+" storage overflow"); 00091 00092 cudaMemcpyToSymbol(name.c_str(),&items[0], size, 0, 00093 cudaMemcpyHostToDevice); 00094 cuda_error("Error copying '"+name+"' buffer to device"); 00095 00096 if( !size_name.empty() ) 00097 copy_to_symbol(size_name.c_str(), items.size()); 00098 } 00099 00108 template< class T > 00109 void copy_to_symbol( const std::string &name, 00110 const std::vector<T> &items ) { 00111 copy_to_symbol(name, "", items); 00112 } 00113 00114 //============================================================================= 00115 } // namespace gpufilter 00116 //============================================================================= 00117 #endif // SYMBOL_H 00118 //============================================================================= 00119 //vi: ai sw=4 ts=4