@@ -28,31 +28,13 @@ def num_blocks(self):
2828 return self ._num_blocks
2929
3030
31- class PhysicalMemory :
32- """Physical memory blocks."""
33-
34- def __init__ (self , num_cpu_blocks : int , num_gpu_blocks : int ) -> None :
35- self ._num_cpu_blocks = num_cpu_blocks
36- self ._num_gpu_blocks = num_gpu_blocks
37- self ._num_blocks = num_cpu_blocks + num_gpu_blocks
38-
39- def num_cpu_blocks (self ):
40- """Get num cpu blocks."""
41- return self ._num_cpu_blocks
42-
43- def num_gpu_blocks (self ):
44- """Get num gpu blocks."""
45- return self ._num_gpu_blocks
46-
47-
4831class PhysicalAllocator :
4932 """The physical block allocator.
5033
5134 The allocator won't allocate real memory. It is used to support block manager.
5235 """
5336
54- def __init__ (self , memory : PhysicalMemory , num_blocks : int , offset : int = 0 ):
55- self ._mem = memory
37+ def __init__ (self , num_blocks : int , offset : int = 0 ):
5638 self ._num_blocks = num_blocks
5739 self ._offset = offset
5840
@@ -87,13 +69,13 @@ def get_num_free_blocks(self):
8769class LogicalAllocator :
8870 """The logical block allocator."""
8971
90- def __init__ (self , num_cpu_blocks : int , num_gpu_blocks : int ) -> None :
72+ def __init__ (self , num_cpu_blocks : int , num_gpu_blocks : int , num_gpu_reserved : int = 0 ) -> None :
9173 self ._log_mem = LogicalMemory (num_cpu_blocks + num_gpu_blocks )
92- self ._phy_mem = PhysicalMemory (num_cpu_blocks , num_gpu_blocks )
9374
9475 self ._cpu_mem_offset = num_gpu_blocks
95- self ._gpu_allocator = PhysicalAllocator (self ._phy_mem , num_gpu_blocks , 0 )
96- self ._cpu_allocator = PhysicalAllocator (self ._phy_mem , num_cpu_blocks , self ._cpu_mem_offset )
76+ num_gpu_blocks -= num_gpu_reserved
77+ self ._gpu_allocator = PhysicalAllocator (num_gpu_blocks , num_gpu_reserved )
78+ self ._cpu_allocator = PhysicalAllocator (num_cpu_blocks , self ._cpu_mem_offset )
9779
9880 num_blocks = self ._log_mem .num_blocks ()
9981 self ._num_blocks = num_blocks
@@ -225,11 +207,11 @@ class BaseBlockManager:
225207 num_cpu_blocks (int): number of cpu blocks.
226208 """
227209
228- def __init__ (self , num_gpu_blocks : int , num_cpu_blocks : int ) -> None :
210+ def __init__ (self , num_gpu_blocks : int , num_cpu_blocks : int , num_gpu_reserved : int = 0 ) -> None :
229211 self .num_gpu_blocks = num_gpu_blocks
230212 self .num_cpu_blocks = num_cpu_blocks
231213
232- self .allocator = LogicalAllocator (num_cpu_blocks , num_gpu_blocks )
214+ self .allocator = LogicalAllocator (num_cpu_blocks , num_gpu_blocks , num_gpu_reserved )
233215
234216 self .block_tables : Dict [int , BlockTable ] = {}
235217
0 commit comments