EMAN2
emdata_cuda.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__emdatacuda_h__
33#define eman__emdatacuda_h__ 1
34
35#ifdef EMAN2_USING_CUDA
36
37#define MEMPOOL_SIZE 10
38public:
39
42 bool copy_to_cuda() const;
43
46 bool copy_to_cudaro() const;
47
50 bool copy_from_device(const bool rocpy = false);
51
54 bool copy_rw_to_ro() const; //we are not changing any of the CPU data!!!
55
58 void elementaccessed() const;
59
62 void bindcudaarrayA(const bool intp_mode) const;
63
66 void unbindcudaarryA() const;
67
70 void bindcudaarrayB(const bool intp_mode) const;
71
74 void unbindcudaarryB() const;
75
78 void runcuda(float * results) const;
79
83 bool isrodataongpu() const;
84
85 inline void roneedsanupdate()
86 {
87 roneedsupdate = true;
88 }
89
90 inline float* getcudarwdata() const
91 {
92 if(cudarwdata != 0) elementaccessed();
93 return cudarwdata;
94 }
95
96 inline cudaArray* getcudarodata() const
97 {
98 if(cudarodata != 0) elementaccessed();
99 return cudarodata;
100 }
101
104 bool rw_alloc() const;
105
108 bool ro_alloc() const;
109
112 void rw_free() const;
113
116 void ro_free() const;
117
120 void addtolist() const;
121
124 void removefromlist() const;
125
128 bool freeup_devicemem(const int& num_bytes) const;
129
130 void setdirtybit() const;
131
132 static void switchoncuda();
133
134 static void switchoffcuda();
135
136 static void cuda_cleanup();
137
138 static bool cuda_initialize();
139
140 static bool usecuda;
141
142 static const char* getcudalock();
143
144private:
145 //pointers to cuda data
146 mutable float* cudarwdata; //we can still change GPU data on a cost object
147 mutable cudaArray* cudarodata; //we can still change GPU data on a cost object
148
149 mutable size_t num_bytes;
150
151 //pointers used in doubly limked list
152 const mutable EMData* nextlistitem;
153 const mutable EMData* prevlistitem;
154
155 mutable bool roneedsupdate;
156 mutable bool cudadirtybit;
157
158 static int cudadevicenum;
159 static int memused;
160 static int fudgemem;
161 const static EMData* firstinlist;
162 const static EMData* lastinlist;
163 static bool nocudainit;
164
165#endif // EMAN2_USING_CUDA
166
167#endif //eman__emdatacuda_h__ 1
168