GPUOcelot

Device.h

Go to the documentation of this file.
00001 
00007 #ifndef DEVICE_H_INCLUDED
00008 #define DEVICE_H_INCLUDED
00009 // C++ standard library includes
00010 #include <fstream>
00011 #include <string>
00012 #include <vector>
00013 
00014 // Ocelot includes
00015 #include <ocelot/ir/interface/Module.h>
00016 #include <ocelot/trace/interface/TraceGenerator.h>
00017 #include <ocelot/translator/interface/Translator.h>
00018 
00019 // Boost includes
00020 #include <boost/thread/thread.hpp>
00021 
00022 // forward declarations
00023 struct cudaChannelFormatDesc;
00024 struct cudaFuncAttributes;
00025 struct textureReference;
00026 
00027 namespace ir { class ExternalFunctionSet; }
00028 
00029 namespace executive 
00030 {
00032   class Device 
00033   {
00034     public:
00035       class PropertiesData
00036       {
00037         public:
00039           ir::Instruction::Architecture ISA;
00041           int addressSpace;
00043           char name[256];
00044 
00047           size_t totalMemory;
00050           unsigned int multiprocessorCount;
00053           int memcpyOverlap;
00055           int maxThreadsPerBlock;
00057           int maxThreadsDim[3];
00059           int maxGridSize[3];
00062           int sharedMemPerBlock;
00064           int totalConstantMemory;
00066           int SIMDWidth;
00068           int memPitch;
00070           int regsPerBlock;
00072           int clockRate;
00074           int textureAlign;
00076           int integrated;
00078           int concurrentKernels;
00080           int major;
00082           int minor;
00084           size_t stackSize;
00086           size_t printfFIFOSize;
00088           bool unifiedAddressing;          
00090           int memoryClockRate;
00092           int memoryBusWidth;
00094           int l2CacheSize;
00096           int maxThreadsPerMultiProcessor;
00097       
00098       };
00099       
00101       class Properties : public PropertiesData
00102       {
00103         public:
00105           Properties(const PropertiesData& = PropertiesData());
00106       
00107         public:
00109           std::ostream& write(std::ostream &out) const;
00110       };
00111 
00113       class MemoryAllocation
00114       {
00115         protected:
00117           bool _global;
00119           bool _host;
00120 
00121         public:
00123           MemoryAllocation(bool global = false, bool host = false);
00125           virtual ~MemoryAllocation();
00126       
00127         public:
00129           virtual bool host() const;
00131           virtual bool global() const;
00133           virtual unsigned int flags() const = 0;
00135           virtual void* mappedPointer() const = 0;
00137           virtual void* pointer() const = 0;
00139           virtual size_t size() const = 0;
00141           virtual void copy(size_t offset, const void* host, 
00142             size_t size ) = 0;
00144           virtual void copy(void* host, size_t offset, 
00145             size_t size) const = 0;
00147           virtual void memset(size_t offset, int value, 
00148             size_t size) = 0;
00150           virtual void copy(MemoryAllocation* allocation, 
00151             size_t toOffset, size_t fromOffset, 
00152             size_t size) const = 0;
00153       };
00154 
00156       typedef std::vector< MemoryAllocation* > MemoryAllocationVector;
00157       
00159       typedef std::vector< Device* > DeviceVector;
00160 
00162       enum AllocationType
00163       {
00164         HostAllocation,
00165         DeviceAllocation,
00166         AnyAllocation,
00167         InvalidAllocation
00168       };
00169 
00170     protected:
00173       typedef std::map<boost::thread::id, bool> ThreadMap;
00174 
00175     protected:
00177       Properties _properties;
00179       int _driverVersion;
00181       int _runtimeVersion;
00183       unsigned int _flags;
00184       
00185     protected:
00187       ThreadMap _selected;
00189       boost::mutex _mutex;
00190       
00191     public:
00193       static DeviceVector createDevices(ir::Instruction::Architecture isa,
00194         unsigned int flags, int computeCapability);
00196       static unsigned int deviceCount(ir::Instruction::Architecture isa,
00197         int computeCapability);
00198 
00199     public:
00201       virtual bool checkMemoryAccess(const void* pointer, 
00202         size_t size) const;
00204       virtual MemoryAllocation* getMemoryAllocation(const void* address, 
00205         AllocationType type = DeviceAllocation) const = 0;
00207       virtual MemoryAllocation* getGlobalAllocation(
00208         const std::string& module, const std::string& name) = 0;
00210       virtual MemoryAllocation* allocate(size_t size) = 0;
00212       virtual MemoryAllocation* registerHost(void* p, size_t size, 
00213         unsigned int flags = 0) = 0;
00215       virtual MemoryAllocation* allocateHost(size_t size, 
00216         unsigned int flags = 0) = 0;
00218       virtual void free(void* pointer) = 0;
00220       virtual MemoryAllocationVector getNearbyAllocations(
00221         void* pointer) const = 0;
00223       virtual MemoryAllocationVector getAllAllocations() const = 0;
00225       virtual std::string nearbyAllocationsToString(void* pointer) const;
00227       virtual void clearMemory() = 0;
00228     
00229     public:
00231       virtual void* glRegisterBuffer(unsigned int buffer, 
00232         unsigned int flags) = 0;
00234       virtual void* glRegisterImage(unsigned int image, 
00235         unsigned int target, unsigned int flags) = 0;
00237       virtual void unRegisterGraphicsResource(void* resource) = 0;
00239       virtual void mapGraphicsResource(void** resource, int count, 
00240         unsigned int stream) = 0;
00242       virtual void* getPointerToMappedGraphicsResource(size_t& size, 
00243         void* resource) = 0;
00245       virtual void setGraphicsResourceFlags(void* resource, 
00246         unsigned int flags) = 0;
00248       virtual void unmapGraphicsResource(void** resource, int count,
00249         unsigned int stream) = 0;
00250 
00251     public:
00253       virtual void load(const ir::Module* module) = 0;
00255       virtual void unload(const std::string& name) = 0;
00257       virtual ExecutableKernel* getKernel(const std::string& module, 
00258         const std::string& kernel) = 0;
00259 
00260     public:
00262       const Properties& properties() const;
00263 
00264     public:
00266       virtual unsigned int createEvent(int flags) = 0;
00268       virtual void destroyEvent(unsigned int event) = 0;
00270       virtual bool queryEvent(unsigned int event) = 0;
00272       virtual void recordEvent(unsigned int event, 
00273         unsigned int stream) = 0;
00275       virtual void synchronizeEvent(unsigned int event) = 0;
00277       virtual float getEventTime(unsigned int start, 
00278         unsigned int end) = 0;
00279     
00280     public:
00282       virtual unsigned int createStream() = 0;
00284       virtual void destroyStream(unsigned int stream) = 0;
00286       virtual bool queryStream(unsigned int stream) = 0;
00288       virtual void synchronizeStream(unsigned int stream) = 0;
00290       virtual void setStream(unsigned int stream) = 0;
00291       
00292     public:
00295       virtual void select();
00297       virtual bool selected();
00299       virtual void unselect();
00300     
00301     public:
00303       virtual void bindTexture(void* pointer, 
00304         const std::string& moduleName, const std::string& textureName,
00305         const textureReference& ref, const cudaChannelFormatDesc& desc, 
00306         const ir::Dim3& size) = 0;
00308       virtual void unbindTexture(const std::string& moduleName, 
00309         const std::string& textureName) = 0;
00311       virtual void* getTextureReference(const std::string& moduleName, 
00312         const std::string& textureName) = 0;
00313     
00314     public:
00316       int driverVersion() const;
00318       int runtimeVersion() const;
00319 
00320     public:
00332       virtual void launch(const std::string& module, 
00333         const std::string& kernel, const ir::Dim3& grid, 
00334         const ir::Dim3& block, size_t sharedMemory, 
00335         const void* argumentBlock, size_t argumentBlockSize, 
00336         const trace::TraceGeneratorVector& 
00337         traceGenerators = trace::TraceGeneratorVector(),
00338         const ir::ExternalFunctionSet* externals = 0) = 0;
00340       virtual cudaFuncAttributes getAttributes(const std::string& module, 
00341         const std::string& kernel) = 0;
00343       virtual unsigned int getLastError() = 0;
00345       virtual void synchronize() = 0;
00346       
00347     public:
00349       virtual void limitWorkerThreads(unsigned int threads) = 0;
00351       virtual void setOptimizationLevel(
00352         translator::Translator::OptimizationLevel level) = 0;
00353       
00354     public:
00356       Device(unsigned int flags = 0);
00358       virtual ~Device();
00359       
00360   };
00361   
00362   typedef Device::DeviceVector DeviceVector;
00363 }
00364 
00365 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines