@@ -273,6 +273,52 @@ def device_mem_info():
273273 mem_info ['lock' ] = {'buffers' : lock_buffers .value , 'bytes' : lock_bytes .value }
274274 return mem_info
275275
276+ def print_mem_info (title = "Memory Info" , device_id = None ):
277+ """
278+ Prints the memory used for the specified device.
279+
280+ Parameters
281+ ----------
282+ title: optional. Default: "Memory Info"
283+ - Title to display before printing the memory info.
284+ device_id: optional. Default: None
285+ - Specifies the device for which the memory info should be displayed.
286+ - If None, uses the current device.
287+
288+ Examples
289+ --------
290+
291+ >>> a = af.randu(5,5)
292+ >>> af.print_mem_info()
293+ Memory Info
294+ ---------------------------------------------------------
295+ | POINTER | SIZE | AF LOCK | USER LOCK |
296+ ---------------------------------------------------------
297+ | 0x706400000 | 1 KB | Yes | No |
298+ ---------------------------------------------------------
299+ >>> b = af.randu(5,5)
300+ >>> af.print_mem_info()
301+ Memory Info
302+ ---------------------------------------------------------
303+ | POINTER | SIZE | AF LOCK | USER LOCK |
304+ ---------------------------------------------------------
305+ | 0x706400400 | 1 KB | Yes | No |
306+ | 0x706400000 | 1 KB | Yes | No |
307+ ---------------------------------------------------------
308+ >>> a = af.randu(1000,1000)
309+ >>> af.print_mem_info()
310+ Memory Info
311+ ---------------------------------------------------------
312+ | POINTER | SIZE | AF LOCK | USER LOCK |
313+ ---------------------------------------------------------
314+ | 0x706500000 | 3.815 MB | Yes | No |
315+ | 0x706400400 | 1 KB | Yes | No |
316+ | 0x706400000 | 1 KB | No | No |
317+ ---------------------------------------------------------
318+ """
319+ device_id = device_id if device_id else get_device ()
320+ safe_call (backend .get ().af_print_mem_info (title .encode ('utf-8' ), device_id ))
321+
276322def device_gc ():
277323 """
278324 Ask the garbage collector to free all unlocked memory
0 commit comments