GPUOcelot
|
00001 00009 #ifndef OCELOT_PASSTHROUGHDEVICE_H_INCLUDED 00010 #define OCELOT_PASSTHROUGHDEVICE_H_INCLUDED 00011 00012 // Ocelot includes 00013 #include <ocelot/executive/interface/Device.h> 00014 #include <ocelot/util/interface/ExtractedDeviceState.h> 00015 00016 namespace executive 00017 { 00018 class ExecutableKernel; 00019 } 00020 00021 namespace executive 00022 { 00024 class PassThroughDevice: public Device 00025 { 00026 public: 00028 bool checkMemoryAccess(const void* pointer, 00029 size_t size) const; 00031 Device::MemoryAllocation* getMemoryAllocation(const void* address, 00032 AllocationType type = DeviceAllocation) const; 00034 Device::MemoryAllocation* getGlobalAllocation( 00035 const std::string& module, const std::string& name); 00037 Device::MemoryAllocation* allocate(size_t size); 00039 Device::MemoryAllocation* allocateHost(size_t size, 00040 unsigned int flags = 0); 00042 Device::MemoryAllocation* registerHost(void* pointer, size_t size, 00043 unsigned int flags); 00045 void free(void* pointer); 00047 Device::MemoryAllocationVector getNearbyAllocations( 00048 void* pointer) const; 00050 Device::MemoryAllocationVector getAllAllocations() const; 00052 std::string nearbyAllocationsToString(void* pointer) const; 00054 void clearMemory(); 00055 00056 public: 00058 void* glRegisterBuffer(unsigned int buffer, 00059 unsigned int flags); 00061 void* glRegisterImage(unsigned int image, 00062 unsigned int target, unsigned int flags); 00064 void unRegisterGraphicsResource(void* resource); 00066 void mapGraphicsResource(void** resource, int count, 00067 unsigned int stream); 00069 void* getPointerToMappedGraphicsResource(size_t& size, 00070 void* resource); 00072 void setGraphicsResourceFlags(void* resource, 00073 unsigned int flags); 00075 void unmapGraphicsResource(void** resource, int count, 00076 unsigned int stream); 00077 00078 public: 00080 void load(const ir::Module* module); 00082 void unload(const std::string& name); 00084 ExecutableKernel* getKernel(const std::string& module, 00085 const std::string& kernel); 00086 00087 public: 00089 unsigned int createEvent(int flags); 00091 void destroyEvent(unsigned int event); 00093 bool queryEvent(unsigned int event); 00095 void recordEvent(unsigned int event, 00096 unsigned int stream); 00098 void synchronizeEvent(unsigned int event); 00100 float getEventTime(unsigned int start, 00101 unsigned int end); 00102 00103 public: 00105 unsigned int createStream(); 00107 void destroyStream(unsigned int stream); 00109 bool queryStream(unsigned int stream); 00111 void synchronizeStream(unsigned int stream); 00113 void setStream(unsigned int stream); 00114 00115 public: 00118 void select(); 00120 bool selected(); 00122 void unselect(); 00123 00124 public: 00126 void bindTexture(void* pointer, 00127 const std::string& moduleName, const std::string& textureName, 00128 const textureReference& ref, const cudaChannelFormatDesc& desc, 00129 const ir::Dim3& size); 00131 void unbindTexture(const std::string& moduleName, 00132 const std::string& textureName); 00134 void* getTextureReference(const std::string& moduleName, 00135 const std::string& textureName); 00136 00137 public: 00149 void launch(const std::string& module, 00150 const std::string& kernel, const ir::Dim3& grid, 00151 const ir::Dim3& block, size_t sharedMemory, 00152 const void* argumentBlock, size_t argumentBlockSize, 00153 const trace::TraceGeneratorVector& 00154 traceGenerators = trace::TraceGeneratorVector(), 00155 const ir::ExternalFunctionSet* externals = 0); 00157 cudaFuncAttributes getAttributes(const std::string& module, 00158 const std::string& kernel); 00160 unsigned int getLastError(); 00162 void synchronize(); 00163 00164 public: 00165 void limitWorkerThreads(unsigned int threads); 00166 void setOptimizationLevel( 00167 translator::Translator::OptimizationLevel level); 00168 00169 public: 00170 PassThroughDevice(Device *target, unsigned int flags = 0); 00171 ~PassThroughDevice(); 00172 00173 private: 00175 typedef std::vector<const ir::Module*> ModuleVector; 00176 00177 private: 00180 void _recordStatePreExecution(); 00181 00183 void _recordKernelLaunch(const std::string& module, 00184 const std::string& kernel, 00185 const ir::Dim3& grid, 00186 const ir::Dim3& block, 00187 size_t sharedMemory, 00188 const void* argumentBlock, 00189 size_t argumentBlockSize); 00190 00193 void _recordStatePostExecution(); 00194 00195 private: 00197 unsigned int _kernelCount; 00198 00200 util::ExtractedDeviceState _state; 00201 00203 Device* _target; 00204 00206 ModuleVector _modules; 00207 }; 00208 } 00209 00210 #endif 00211