Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

emdata_cuda.h

Go to the documentation of this file.
00001 /*
00002  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00003  * Copyright (c) 2000-2006 Baylor College of Medicine
00004  *
00005  * This software is issued under a joint BSD/GNU license. You may use the
00006  * source code in this file under either license. However, note that the
00007  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00008  * so you are responsible for compliance with the licenses of these packages
00009  * if you opt to use BSD licensing. The warranty disclaimer below holds
00010  * in either instance.
00011  *
00012  * This complete copyright notice must be included in any revised version of the
00013  * source code. Additional authorship citations may be added, but existing
00014  * author citations must be preserved.
00015  *
00016  * This program is free software; you can redistribute it and/or modify
00017  * it under the terms of the GNU General Public License as published by
00018  * the Free Software Foundation; either version 2 of the License, or
00019  * (at your option) any later version.
00020  *
00021  * This program is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024  * GNU General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU General Public License
00027  * along with this program; if not, write to the Free Software
00028  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00029  *
00030  * */
00031 
00032 #ifndef eman__emdatacuda_h__
00033 #define eman__emdatacuda_h__ 1
00034 
00035 #ifdef EMAN2_USING_CUDA
00036 
00037 #define MEMPOOL_SIZE 10
00038 public:
00039         
00042         bool copy_to_cuda_keepcpu() const;
00043         
00046         bool copy_to_cuda();
00047         
00050         bool copy_to_cudaro() const;
00051         
00054         bool copy_from_device(const bool rocpy = false);
00055         
00058         bool copy_rw_to_ro() const; //we are not changing any of the CPU data!!!
00059         
00062         void elementaccessed() const;
00063         
00066         void bindcudaarrayA(const bool intp_mode) const;
00067         
00070         void unbindcudaarryA() const;
00071         
00074         void bindcudaarrayB(const bool intp_mode) const;
00075         
00078         void unbindcudaarryB() const;
00079         
00082         void runcuda(float * results) const;
00083         
00087         bool isrodataongpu() const;
00088         
00089         inline  void roneedsanupdate()
00090         {
00091                 roneedsupdate = true;
00092         }
00093 
00094         inline float* getcudarwdata() const
00095         {
00096                 return cudarwdata;
00097         }
00098         
00099         inline cudaArray* getcudarodata() const
00100         {
00101                 return cudarodata;
00102         }
00103         
00105         static void usemempool(int size);
00106         
00108         static void freemempool();
00109         
00112         bool rw_alloc() const;
00113         
00116         bool ro_alloc() const;
00117         
00120         void rw_free() const;
00121         
00124         void ro_free() const;
00125         
00128         void addtolist() const;
00129         
00132         void removefromlist() const;
00133         
00136         bool freeup_devicemem(const int& num_bytes) const;
00137         
00138         static void switchoncuda();
00139         
00140         static void switchoffcuda();
00141         
00142         static void cuda_cleanup();
00143         
00144         static bool cuda_initialize();
00145         
00146         static bool usecuda;
00147 
00148 private:
00149         //pointers to cuda data
00150         mutable float* cudarwdata;      //we can still change GPU data on a cost object
00151         mutable cudaArray* cudarodata;  //we can still change GPU data on a cost object
00152         
00153         mutable size_t num_bytes;
00154         
00155         //pointers used in doubly limked list
00156         const mutable EMData* nextlistitem;
00157         const mutable EMData* prevlistitem;
00158         
00159         mutable bool roneedsupdate;
00160         
00161         static int memused;
00162         static int fudgemem;
00163         const static EMData* firstinlist;
00164         const static EMData* lastinlist;
00165         
00166         // mempool stuff
00167         static float* mempool[MEMPOOL_SIZE];
00168         static int  mempoolused;
00169         static int mempoolarraysize;
00170         static bool usemempoolswitch;
00171         
00172 #endif // EMAN2_USING_CUDA      
00173 
00174 #endif //eman__emdatacuda_h__ 1
00175 

Generated on Tue Jul 12 13:49:25 2011 for EMAN2 by  doxygen 1.3.9.1