allocator
AllocationStrategy
AllocationRequest
dataclass
AllocationRequest(size: int, alignment: int = 1, stream: Optional[int] = None, priority: int = 0, metadata: Optional[Dict[str, Any]] = None)
Represents a memory allocation request
AllocationResult
dataclass
AllocationResult(success: bool, block: Optional[MemoryBlock] = None, address: Optional[int] = None, actual_size: Optional[int] = None, allocation_time_ns: Optional[int] = None, error_message: Optional[str] = None, strategy_info: Optional[Dict[str, Any]] = None)
Represents the result of an allocation attempt
FreeRequest
dataclass
FreeRequest(address: int, expected_size: Optional[int] = None, metadata: Optional[Dict[str, Any]] = None)
Represents a memory deallocation request
FreeResult
dataclass
FreeResult(success: bool, address: Optional[int] = None, freed_size: Optional[int] = None, free_time_ns: Optional[int] = None, coalesced: bool = False, coalesced_size: Optional[int] = None, error_message: Optional[str] = None, strategy_info: Optional[Dict[str, Any]] = None)
Represents the result of a deallocation attempt
MemoryAllocator
MemoryAllocator(name: str)
Bases: ABC
Abstract base class for memory allocation algorithms
Source code in ures/memory/allocator.py
72 73 74 75 76 77 78 79 80 81 82 | |
allocate
abstractmethod
allocate(pool: BlockPool, request: AllocationRequest) -> AllocationResult
Allocate memory according to the algorithm's strategy
Source code in ures/memory/allocator.py
84 85 86 87 | |
free
abstractmethod
free(pool: BlockPool, request: FreeRequest) -> FreeResult
Free memory according to the algorithm's strategy
Source code in ures/memory/allocator.py
89 90 91 92 | |
can_allocate
abstractmethod
can_allocate(pool: BlockPool, request: AllocationRequest) -> bool
Check if allocation is possible without actually allocating
Source code in ures/memory/allocator.py
94 95 96 97 | |
can_free
can_free(pool: BlockPool, request: FreeRequest) -> bool
Check if deallocation is possible
Source code in ures/memory/allocator.py
99 100 101 | |
get_statistics
get_statistics() -> Dict[str, Any]
Get allocator statistics
Source code in ures/memory/allocator.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
FirstFitAllocator
FirstFitAllocator()
Bases: MemoryAllocator
First-fit allocation algorithm
Source code in ures/memory/allocator.py
132 133 | |
BestFitAllocator
BestFitAllocator()
Bases: MemoryAllocator
Best-fit allocation algorithm
Source code in ures/memory/allocator.py
254 255 | |
WorstFitAllocator
WorstFitAllocator()
Bases: MemoryAllocator
Worst-fit allocation algorithm
Source code in ures/memory/allocator.py
382 383 | |
NextFitAllocator
NextFitAllocator()
Bases: MemoryAllocator
Next-fit allocation algorithm
Source code in ures/memory/allocator.py
510 511 512 | |
BuddySystemAllocator
BuddySystemAllocator()
Bases: MemoryAllocator
Buddy system allocation algorithm
Source code in ures/memory/allocator.py
675 676 677 | |
DeviceMemorySimulator
DeviceMemorySimulator(device_id: int, total_memory: int, base_address: int = 268435456)
Simulate a device heap and swap among allocation algorithms.
Examples:
>>> from ures.memory import DeviceMemorySimulator
>>> sim = DeviceMemorySimulator(device_id=0, total_memory=1024)
>>> result = sim.allocate(size=64)
>>> result.success
True
>>> sim.free(result.address).success
True
Source code in ures/memory/allocator.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |
register_allocator
register_allocator(allocator: MemoryAllocator)
Register a new allocation algorithm
Source code in ures/memory/allocator.py
927 928 929 | |
set_allocator
set_allocator(allocator_name: str) -> bool
Set the active allocation algorithm
Source code in ures/memory/allocator.py
931 932 933 934 935 936 | |
get_available_allocators
get_available_allocators() -> List[str]
Get list of available allocator names
Source code in ures/memory/allocator.py
938 939 940 | |
allocate
allocate(size: int, alignment: int = 1, stream: Optional[int] = None, priority: int = 0, metadata: Optional[Dict[str, Any]] = None) -> AllocationResult
Allocate memory using the current algorithm
Source code in ures/memory/allocator.py
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 | |
free
free(address: int, expected_size: Optional[int] = None) -> FreeResult
Free memory at the given address using the current allocator
Source code in ures/memory/allocator.py
967 968 969 970 971 972 973 974 975 976 977 978 979 | |
can_allocate
can_allocate(size: int, stream: Optional[int] = None) -> bool
Check if allocation is possible without actually allocating
Source code in ures/memory/allocator.py
981 982 983 984 985 986 987 | |
get_memory_info
get_memory_info() -> Dict[str, Any]
Get current memory status information
Source code in ures/memory/allocator.py
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
get_allocator_statistics
get_allocator_statistics() -> Dict[str, Dict[str, Any]]
Get statistics for all allocators
Source code in ures/memory/allocator.py
1007 1008 1009 1010 1011 1012 | |
reset_device
reset_device()
Reset device to initial state
Source code in ures/memory/allocator.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
simulate_workload
simulate_workload(num_operations: int = 100, size_range: Tuple[int, int] = (64, 4096), free_probability: float = 0.3) -> Dict[str, Any]
Simulate a random workload
Source code in ures/memory/allocator.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 | |
print_status
print_status()
Print current device status
Source code in ures/memory/allocator.py
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | |