PhysX SDK 3.2 API Reference: PxCudaMemoryManager.h Source File

PhysX SDK 3.2 API

PxCudaMemoryManager.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you 
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and 
00007 // any modifications thereto. Any use, reproduction, disclosure, or 
00008 // distribution of this software and related documentation without an express 
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 // 
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2012 NVIDIA Corporation. All rights reserved.
00027 
00028 #ifndef PX_CUDA_MEMORY_MANAGER_H
00029 #define PX_CUDA_MEMORY_MANAGER_H
00030 
00031 #include "foundation/PxSimpleTypes.h"
00032 
00033 // some macros to keep the source code more readable
00034 #define NV_ALLOC_INFO(name, ID) __FILE__, __LINE__, name, physx::pxtask::AllocId::ID
00035 #define NV_ALLOC_INFO_PARAMS_DECL(p0, p1, p2, p3)  const char* file = p0, PxU32 line = p1, const char* allocName = p2, physx::pxtask::AllocId::Enum allocId = physx::pxtask::AllocId::p3
00036 #define NV_ALLOC_INFO_PARAMS_DEF()  const char* file, PxU32 line, const char* allocName, physx::pxtask::AllocId::Enum allocId
00037 #define NV_ALLOC_INFO_PARAMS_INPUT()  file, line, allocName, allocId
00038 #define NV_ALLOC_INFO_PARAMS_INPUT_INFO(info) info.getFileName(), info.getLine(), info.getAllocName(), info.getAllocId()
00039 
00040 #ifndef NULL // don't want to include <string.h>
00041 #define NULL 0
00042 #endif
00043 
00044 #ifndef PX_DOXYGEN
00045 namespace physx
00046 {
00047 #endif
00048 
00049 namespace pxtask
00050 {
00051 PX_PUSH_PACK_DEFAULT
00052 
00057 struct AllocId
00058 {
00062     enum Enum
00063     {
00064         UNASSIGNED,     
00065         APEX,           
00066         PARTICLES,      
00067         GPU_UTIL,       
00068         NUM_IDS         
00069     };
00070 };
00071 
00073 struct CudaBufferMemorySpace
00074 {
00078     enum Enum
00079     {
00080         T_GPU,
00081         T_PINNED_HOST,
00082         T_WRITE_COMBINED,
00083         T_HOST,
00084         COUNT
00085     };
00086 };
00087 
00089 class AllocInfo
00090 {
00091 public:
00095     AllocInfo() {}
00096 
00100     AllocInfo(const char* file, int line, const char* allocName, AllocId::Enum allocId)
00101         : mFileName(file)
00102         , mLine(line)
00103         , mAllocName(allocName)
00104         , mAllocId(allocId)
00105     {}
00106 
00108     inline  const char*         getFileName() const
00109     {
00110         return mFileName;
00111     }
00112 
00114     inline  int                 getLine() const
00115     {
00116         return mLine;
00117     }
00118 
00120     inline  const char*         getAllocName() const
00121     {
00122         return mAllocName;
00123     }
00124 
00126     inline  AllocId::Enum       getAllocId() const
00127     {
00128         return mAllocId;
00129     }
00130 
00131 private:
00132     const char*         mFileName;
00133     int                 mLine;
00134     const char*         mAllocName;
00135     AllocId::Enum       mAllocId;
00136 };
00137 
00139 struct AllocIdStats
00140 {
00141     size_t size;        
00142     size_t maxSize;     
00143     size_t elements;    
00144     size_t maxElements; 
00145 };
00146 
00147 class CudaMemoryManager;
00148 typedef size_t CudaBufferPtr;
00149 
00151 struct CudaBufferFlags
00152 {
00154     enum Enum
00155     {
00156         F_READ          = (1 << 0),
00157         F_WRITE         = (1 << 1),
00158         F_READ_WRITE    = F_READ | F_WRITE
00159     };
00160 };
00161 
00162 
00164 struct CudaMemoryManagerStats
00165 {
00166 
00167     size_t          heapSize;       
00168     size_t          totalAllocated; 
00169     size_t          maxAllocated;   
00170     AllocIdStats    allocIdStats[AllocId::NUM_IDS]; 
00171 };
00172 
00173 
00175 struct CudaBufferType
00176 {
00178     PX_INLINE CudaBufferType(const CudaBufferType& t)
00179         : memorySpace(t.memorySpace)
00180         , flags(t.flags)
00181     {}
00182     
00184     PX_INLINE CudaBufferType(CudaBufferMemorySpace::Enum _memSpace, CudaBufferFlags::Enum _flags)
00185         : memorySpace(_memSpace)
00186         , flags(_flags)
00187     {}
00188 
00189     CudaBufferMemorySpace::Enum     memorySpace;    
00190     CudaBufferFlags::Enum           flags;          
00191 };
00192 
00193 
00195 class NvCudaBuffer
00196 {
00197 public:
00199     virtual CudaMemoryManager*          getCudaMemoryManager() const = 0;
00200 
00202     virtual bool                        free() = 0;
00203 
00208     virtual bool                        realloc(size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
00209 
00211     virtual const CudaBufferType&       getType() const = 0;
00212 
00214     virtual CudaBufferPtr               getPtr() const = 0;
00215 
00217     virtual size_t                      getSize() const = 0;
00218 
00219 protected:
00221     virtual ~NvCudaBuffer() {}
00222 };
00223 
00224 
00226 class CudaMemoryManager
00227 {
00228 public:
00230     virtual NvCudaBuffer*               alloc(const CudaBufferType& type, size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
00231 
00233     virtual CudaBufferPtr               alloc(CudaBufferMemorySpace::Enum memorySpace, size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
00234 
00236     virtual bool                        free(CudaBufferMemorySpace::Enum memorySpace, CudaBufferPtr addr) = 0;
00237 
00239     virtual bool                        realloc(CudaBufferMemorySpace::Enum memorySpace, CudaBufferPtr addr, size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
00240 
00242     virtual void                        getStats(const CudaBufferType& type, CudaMemoryManagerStats& outStats) = 0;
00243 
00246     virtual bool                        reserve(const CudaBufferType& type, size_t size) = 0;
00247 
00251     virtual bool                        setPageSize(const CudaBufferType& type, size_t size) = 0;
00252 
00255     virtual bool                        setMaxMemorySize(const CudaBufferType& type, size_t size) = 0;
00256 
00258     virtual size_t                      getBaseSize(const CudaBufferType& type) = 0;
00259 
00261     virtual size_t                      getPageSize(const CudaBufferType& type) = 0;
00262 
00264     virtual size_t                      getMaxMemorySize(const CudaBufferType& type) = 0;
00265 
00266 protected:
00268     virtual ~CudaMemoryManager() {}
00269 };
00270 
00271 PX_POP_PACK
00272 
00273 } // end pxtask namespace
00274 
00275 #ifndef PX_DOXYGEN
00276 } // end physx namespace
00277 #endif
00278 
00279 #endif


Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com