GPUOcelot

RemoteDevice.h

Go to the documentation of this file.
00001 
00007 #ifndef EXECUTIVE_REMOTEDEVICE_H_INCLUDED
00008 #define EXECUTIVE_REMOTEDEVICE_H_INCLUDED
00009 
00010 // C++ includes
00011 #include <unordered_set>
00012 
00013 // Ocelot includes
00014 #include <ocelot/executive/interface/Device.h>
00015 #include <ocelot/util/interface/RemoteDeviceMessage.h>
00016 
00017 // Hydrazine includes
00018 #include <hydrazine/implementation/Timer.h>
00019 
00020 // Boost includes
00021 #include <boost/thread/thread.hpp>
00022 #include <boost/bind.hpp>
00023 #include <boost/shared_ptr.hpp>
00024 #include <boost/enable_shared_from_this.hpp>
00025 #include <boost/asio.hpp>
00026 
00028 
00029 namespace executive
00030 {
00031   class ExecutableKernel;
00032 }
00033 
00034 namespace executive 
00035 {
00037   class RemoteDevice : public Device
00038   {
00039     public:
00041       class MemoryAllocation : public Device::MemoryAllocation
00042       {
00043         private:
00045           size_t _size;
00047           void* _pointer;
00049           unsigned int _flags;
00051           bool _external;
00053           RemoteDevice* _device;
00054         
00055         public:
00057           MemoryAllocation();
00059           MemoryAllocation(RemoteDevice* d, size_t size,
00060             void* pointer);
00062           MemoryAllocation(RemoteDevice* d, size_t size,
00063             unsigned int flags);
00065           MemoryAllocation(RemoteDevice* d, void* pointer,
00066             size_t size);
00068           ~MemoryAllocation();
00069       
00070         public:
00072           unsigned int flags() const;
00074           void* mappedPointer() const;
00076           void* pointer() const;
00078           size_t size() const;
00080           void copy(size_t offset, const void* host, size_t size );
00082           void copy(void* host, size_t offset, size_t size) const;
00084           void memset(size_t offset, int value, size_t size);
00086           void copy(Device::MemoryAllocation* allocation, 
00087             size_t toOffset, size_t fromOffset, size_t size) const;       
00088       };
00089 
00090       friend class RemoteDevice::MemoryAllocation;
00091 
00093       typedef std::map<void*, MemoryAllocation*> AllocationMap;
00094 
00096       class ConnectionManager
00097       {
00098       public:
00099         ConnectionManager();
00100         ~ConnectionManager();
00101       
00102       public:
00104         void exchange(remote::RemoteDeviceMessage& message);
00105       
00106       private:
00107         void _connect();
00108       
00109       private:        
00111         boost::asio::io_service _io_service;
00112       
00114         boost::asio::ip::tcp::socket _socket;
00115         
00117         boost::mutex _mutex;
00118         
00120         bool _connected;
00121       };
00122       
00123     private:
00125       AllocationMap _allocations;
00126     
00128       bool _selected;
00129       
00131       remote::RemoteDeviceMessage _message;
00132       
00134       unsigned int _id;
00135 
00136     public:
00138       static DeviceVector createDevices(unsigned int flags,
00139         int computeCapability);
00141       static unsigned int deviceCount(int computeCapability);
00142             
00143       static ConnectionManager connectionManager;
00144 
00145     public:
00148       RemoteDevice(unsigned int id, const PropertiesData& props, 
00149         unsigned int flags = 0);
00151       ~RemoteDevice();
00152       
00153     public:
00154       Device::MemoryAllocation* getMemoryAllocation(const void* address, 
00155         AllocationType type) const;
00157       Device::MemoryAllocation* getGlobalAllocation(
00158         const std::string& module, const std::string& name);
00160       Device::MemoryAllocation* allocate(size_t size);
00162       Device::MemoryAllocation* allocateHost(size_t size, 
00163         unsigned int flags);
00165       Device::MemoryAllocation* registerHost(void* pointer, size_t size, 
00166         unsigned int flags);
00168       void free(void* pointer);
00170       MemoryAllocationVector getNearbyAllocations(void* pointer) const;
00172       MemoryAllocationVector getAllAllocations() const;
00174       void clearMemory();     
00175 
00176     public:
00178       void* glRegisterBuffer(unsigned int buffer, 
00179         unsigned int flags);
00181       void* glRegisterImage(unsigned int image, 
00182         unsigned int target, unsigned int flags);
00184       void unRegisterGraphicsResource(void* resource);
00186       void mapGraphicsResource(void** resource, int count, 
00187         unsigned int stream);
00189       void* getPointerToMappedGraphicsResource(size_t& size, 
00190         void* resource);
00192       void setGraphicsResourceFlags(void* resource, 
00193         unsigned int flags);
00195       void unmapGraphicsResource(void** resource, int count,
00196         unsigned int stream);
00197       
00198     public:
00200       void load(const ir::Module* module);
00202       void unload(const std::string& name);
00204       ExecutableKernel* getKernel(const std::string& module, 
00205         const std::string& kernel);
00206 
00207     public:
00209       unsigned int createEvent(int flags);
00211       void destroyEvent(unsigned int event);
00213       bool queryEvent(unsigned int event);
00215       void recordEvent(unsigned int event, unsigned int stream);
00217       void synchronizeEvent(unsigned int event);
00219       float getEventTime(unsigned int start, unsigned int end);
00220     
00221     public:
00223       unsigned int createStream();
00225       void destroyStream(unsigned int stream);
00227       bool queryStream(unsigned int stream);
00229       void synchronizeStream(unsigned int stream);
00231       void setStream(unsigned int stream);
00232       
00233     public:
00236       void select();
00238       bool selected() const;
00240       void unselect();
00241     
00242     public:
00244       void bindTexture(void* pointer,
00245         const std::string& moduleName, const std::string& textureName, 
00246         const textureReference& ref, const cudaChannelFormatDesc& desc, 
00247         const ir::Dim3& size);
00249       void unbindTexture(const std::string& moduleName, 
00250         const std::string& textureName);
00252       void* getTextureReference(const std::string& moduleName, 
00253         const std::string& textureName);
00254 
00255     public:
00267       void launch(const std::string& module, 
00268         const std::string& kernel, const ir::Dim3& grid, 
00269         const ir::Dim3& block, size_t sharedMemory, 
00270         const void* argumentBlock, size_t argumentBlockSize, 
00271         const trace::TraceGeneratorVector& 
00272           traceGenerators = trace::TraceGeneratorVector(),
00273         const ir::ExternalFunctionSet* externals = 0);
00274           
00276       cudaFuncAttributes getAttributes(const std::string& module, 
00277         const std::string& kernel);
00279       unsigned int getLastError();
00281       void synchronize();
00282       
00283     public:
00285       void limitWorkerThreads(unsigned int threads);      
00287       void setOptimizationLevel(
00288         translator::Translator::OptimizationLevel level);
00289   };
00290 }
00291 
00293 
00294 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines