From cccccbf6cca94a3eaf813b4468453160e91c332b Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Mon, 14 Apr 2014 08:14:45 +0800 Subject: First commit --- src/CuBaseLib/.svn/text-base/cudevice.h.svn-base | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/CuBaseLib/.svn/text-base/cudevice.h.svn-base (limited to 'src/CuBaseLib/.svn/text-base/cudevice.h.svn-base') diff --git a/src/CuBaseLib/.svn/text-base/cudevice.h.svn-base b/src/CuBaseLib/.svn/text-base/cudevice.h.svn-base new file mode 100644 index 0000000..c5eeb7b --- /dev/null +++ b/src/CuBaseLib/.svn/text-base/cudevice.h.svn-base @@ -0,0 +1,79 @@ +#ifndef _CUDEVICE_H_ +#define _CUDEVICE_H_ + +#include +#include +#include + +namespace TNet { + + /** + * Singleton object which represents CUDA device + * responsible for CUBLAS initilalisation + * and memory block registration + */ + class CuDevice + { + // Singleton interface... + private: + CuDevice(); + CuDevice(CuDevice&); + CuDevice& operator=(CuDevice&); + + public: + ~CuDevice(); + static CuDevice& Instantiate() + { return msDevice; } + + private: + static CuDevice msDevice; + + + /**********************************/ + // Instance interface + public: + + void SelectGPU(int gpu_id); + + /// Check if the CUDA device is in the system + bool IsPresent() + { return mIsPresent; } + + void Verbose(bool verbose) + { mVerbose = verbose; } + + /// Sum the IO time + void AccuProfile(const std::string& key,double time) + { + if(mProfileMap.find(key) == mProfileMap.end()) { + mProfileMap[key] = 0.0; + } + mProfileMap[key] += time; + } + + void PrintProfile() + { + std::cout << "[cudevice profile]\n"; + std::map::iterator it; + for(it = mProfileMap.begin(); it != mProfileMap.end(); ++it) { + std::cout << it->first << "\t" << it->second << "s\n"; + } + } + + void ResetProfile() + { mProfileMap.clear(); } + + std::string GetFreeMemory(); + + + private: + std::map mProfileMap; + bool mIsPresent; + bool mVerbose; + }; //class CuDevice + + +} + + +#endif -- cgit v1.2.3-70-g09d2