PxCudaMemoryManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 
11 #ifndef PX_CUDA_MEMORY_MANAGER_H
12 #define PX_CUDA_MEMORY_MANAGER_H
13 
15 
16 // some macros to keep the source code more readable
17 #define NV_ALLOC_INFO(name, ID) __FILE__, __LINE__, name, physx::PxAllocId::ID
18 #define NV_ALLOC_INFO_PARAMS_DECL(p0, p1, p2, p3) const char* file = p0, int line = p1, const char* allocName = p2, physx::PxAllocId::Enum allocId = physx::PxAllocId::p3
19 #define NV_ALLOC_INFO_PARAMS_DEF() const char* file, int line, const char* allocName, physx::PxAllocId::Enum allocId
20 #define NV_ALLOC_INFO_PARAMS_INPUT() file, line, allocName, allocId
21 #define NV_ALLOC_INFO_PARAMS_INPUT_INFO(info) info.getFileName(), info.getLine(), info.getAllocName(), info.getAllocId()
22 
23 #ifndef NULL // don't want to include <string.h>
24 #define NULL 0
25 #endif
26 
27 #ifndef PX_DOXYGEN
28 namespace physx
29 {
30 #endif
31 
33 
38 struct PxAllocId
39 {
43  enum Enum
44  {
46  APEX,
50  NUM_IDS
51  };
52 };
53 
56 {
60  enum Enum
61  {
66  COUNT
67  };
68 };
69 
72 {
73 public:
78 
82  PxAllocInfo(const char* file, int line, const char* allocName, PxAllocId::Enum allocId)
83  : mFileName(file)
84  , mLine(line)
85  , mAllocName(allocName)
86  , mAllocId(allocId)
87  {}
88 
90  inline const char* getFileName() const
91  {
92  return mFileName;
93  }
94 
96  inline int getLine() const
97  {
98  return mLine;
99  }
100 
102  inline const char* getAllocName() const
103  {
104  return mAllocName;
105  }
106 
108  inline PxAllocId::Enum getAllocId() const
109  {
110  return mAllocId;
111  }
112 
113 private:
114  const char* mFileName;
115  int mLine;
116  const char* mAllocName;
118 };
119 
122 {
123  size_t size;
124  size_t maxSize;
125  size_t elements;
126  size_t maxElements;
127 };
128 
130 typedef size_t PxCudaBufferPtr;
131 
134 {
136  enum Enum
137  {
138  F_READ = (1 << 0),
139  F_WRITE = (1 << 1),
140  F_READ_WRITE = F_READ | F_WRITE
141  };
142 };
143 
144 
147 {
148 
149  size_t heapSize;
150  size_t totalAllocated;
151  size_t maxAllocated;
153 };
154 
155 
158 {
161  : memorySpace(t.memorySpace)
162  , flags(t.flags)
163  {}
164 
167  : memorySpace(_memSpace)
168  , flags(_flags)
169  {}
170 
173 };
174 
175 
178 {
179 public:
181  virtual PxCudaMemoryManager* getCudaMemoryManager() const = 0;
182 
184  virtual bool free() = 0;
185 
190  virtual bool realloc(size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
191 
193  virtual const PxCudaBufferType& getType() const = 0;
194 
196  virtual PxCudaBufferPtr getPtr() const = 0;
197 
199  virtual size_t getSize() const = 0;
200 
201 protected:
203  virtual ~PxCudaBuffer() {}
204 };
205 
206 
209 {
210 public:
212  virtual PxCudaBuffer* alloc(const PxCudaBufferType& type, size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
213 
215  virtual PxCudaBufferPtr alloc(PxCudaBufferMemorySpace::Enum memorySpace, size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
216 
218  virtual bool free(PxCudaBufferMemorySpace::Enum memorySpace, PxCudaBufferPtr addr) = 0;
219 
221  virtual bool realloc(PxCudaBufferMemorySpace::Enum memorySpace, PxCudaBufferPtr addr, size_t size, NV_ALLOC_INFO_PARAMS_DECL(NULL, 0, NULL, UNASSIGNED)) = 0;
222 
224  virtual void getStats(const PxCudaBufferType& type, PxCudaMemoryManagerStats& outStats) = 0;
225 
228  virtual bool reserve(const PxCudaBufferType& type, size_t size) = 0;
229 
233  virtual bool setPageSize(const PxCudaBufferType& type, size_t size) = 0;
234 
237  virtual bool setMaxMemorySize(const PxCudaBufferType& type, size_t size) = 0;
238 
240  virtual size_t getBaseSize(const PxCudaBufferType& type) = 0;
241 
243  virtual size_t getPageSize(const PxCudaBufferType& type) = 0;
244 
246  virtual size_t getMaxMemorySize(const PxCudaBufferType& type) = 0;
247 
249  virtual PxCudaBufferPtr getMappedPinnedPtr(PxCudaBufferPtr hostPtr) = 0;
250 
251 protected:
253  virtual ~PxCudaMemoryManager() {}
254 };
255 
257 
258 #ifndef PX_DOXYGEN
259 } // end physx namespace
260 #endif
261 
262 #endif


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