summaryrefslogtreecommitdiff
path: root/src/CuBaseLib/.svn/text-base/cudevice.h.svn-base
blob: c5eeb7b0ae0ac82b46905321104f1e79c588d6bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _CUDEVICE_H_
#define _CUDEVICE_H_

#include <map>
#include <string>
#include <iostream>

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<std::string, double>::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<std::string, double> mProfileMap;
      bool mIsPresent;
      bool mVerbose;
  }; //class CuDevice


}


#endif