Setup CUDA async pool. As an alternative, the RMM plugin can be used as well. This is the same as using the `CudaAsyncMemoryResource` from RMM, but without the RMM dependency. .. versionadded:: 3.2.0
()
| 143 | |
| 144 | |
| 145 | def setup_async_pool() -> None: |
| 146 | """Setup CUDA async pool. As an alternative, the RMM plugin can be used as well. |
| 147 | This is the same as using the `CudaAsyncMemoryResource` from RMM, but without the |
| 148 | RMM dependency. |
| 149 | |
| 150 | .. versionadded:: 3.2.0 |
| 151 | |
| 152 | """ |
| 153 | import cuda.bindings.runtime as cudart |
| 154 | from cuda.bindings import driver |
| 155 | from cupy.cuda import MemoryAsyncPool |
| 156 | |
| 157 | status, dft_pool = cudart.cudaDeviceGetDefaultMemPool(0) |
| 158 | _checkcu(status) |
| 159 | |
| 160 | total = device_mem_total() |
| 161 | |
| 162 | v = driver.cuuint64_t(int(total * 0.9)) |
| 163 | (status,) = cudart.cudaMemPoolSetAttribute( |
| 164 | dft_pool, |
| 165 | cudart.cudaMemPoolAttr.cudaMemPoolAttrReleaseThreshold, |
| 166 | v, |
| 167 | ) |
| 168 | _checkcu(status) |
| 169 | # Set the allocator for cupy as well. |
| 170 | import cupy as cp |
| 171 | |
| 172 | cp.cuda.set_allocator(MemoryAsyncPool().malloc) |
| 173 | |
| 174 | |
| 175 | R = TypeVar("R") |
no test coverage detected