Files
tinygrad/test/external/external_test_tlsf.py
nimlgen c18307e749 AM driver (#6923)
* connect to gpu

* rlc init?

* gfx comp start init

* early init is hardoded, some progress with fw

* gart

* progress, next mqd

* ring setup, still does not execute anything

* ugh write correct reg

* pci2: vm

* pci2: start psp

* vm seems to work

* pci2: gfx start

* pci2: fix psp ring resp

* pci2: try ring

* pci2: mes and some fixes

* pci2: some progress

* pci2: progress

* pci2: mm

* pci2: discovery

* pci2: correct apertures

* pci2: b

* pci2: i

* pci2: l

* pci2: o

* pci2: cmu

* pci2: mes_kiq works

* pci2: mes

* pci2: kcq does not work(

* pci2: unhalt gfx

* ops_am

* minor

* check if amdgpu is there, or we will crash

* bring back graph, it just works

* less prints

* do not init mes (not used)

* remove unused files

* ops_am: start move into core

* ops_am: works

* clcks, but still slower

* faster + no mes_kiq

* vm frags + remove mes

* cleanup fw

* gmc tiny cleanup

* move to ops_amd

* comment out what we dont really need

* driverless

* close in speed

* am clean most of ips

* gmc to ips

* cleaner

* new vm walker

* comment old one

* remove unsued autogens

* last write ups

* remove psp hardcoded values

* more

* add logs

* ih

* p2p and sdma

* vfio hal and interrupts

* smth

* amd dev iface

* minor after rebase

* bind for sdma

* Revert "bind for sdma"

This reverts commit a90766514d.

* tmp

* debug new mm

* ugh, allreduce hangs fixed

* p1

* works

* no pci.py

* cleaner a bit

* smth

* tiny cleanups

* cleaner a bit

* pciiface

* linter

* linter 2

* linter 3

* linter

* pylint

* reverted unrelated changes

* unrelated

* cmp tool

* ugh wrong fw

* clockgating

* unrelated

* alloc smaller chunks

* this

* opt sigs

* collect stat

* ops

* upd

* proclogs

* proclogs2

* vfio

* ruff

* linter pylint

* oops

* mypy p1

* mem fix

* mypy p2

* mypy p3

* mypy p4

* correct

* minor

* more tests

* linter in tests

* pci_regs header

* minor write up

* setup

* do not require libs

---------

Co-authored-by: George Hotz <72895+geohot@users.noreply.github.com>
2024-12-31 23:06:17 +03:00

79 lines
2.2 KiB
Python

import unittest
from tinygrad.runtime.support.allocator import TLSFAllocator
class TestTLSFAllocator(unittest.TestCase):
def setUp(self):
self.allocator = TLSFAllocator(1024, block_size=16)
def test_basic_alloc_free(self):
addr1 = self.allocator.alloc(32)
self.assertEqual(addr1, 0)
addr2 = self.allocator.alloc(64)
self.assertEqual(addr2, 32)
self.allocator.free(addr1)
addr3 = self.allocator.alloc(32)
self.assertEqual(addr3, 0)
def test_block_size_alignment(self):
addr1 = self.allocator.alloc(20)
addr2 = self.allocator.alloc(35)
self.assertEqual(addr1 % 16, 0)
self.assertEqual(addr2 % 16, 0)
def test_merge_blocks(self):
addr1 = self.allocator.alloc(32)
addr2 = self.allocator.alloc(32)
self.allocator.alloc(32)
self.allocator.free(addr1)
self.allocator.free(addr2)
addr4 = self.allocator.alloc(64)
self.assertEqual(addr4, addr1)
def test_split_blocks(self):
addr1 = self.allocator.alloc(128)
self.allocator.free(addr1)
addr2 = self.allocator.alloc(32)
self.assertEqual(addr2, addr1)
addr3 = self.allocator.alloc(32)
self.assertEqual(addr3, addr1 + 32)
def test_out_of_memory(self):
with self.assertRaises(MemoryError):
self.allocator.alloc(2048)
def test_fragmentation_handling(self):
addrs = []
for _ in range(5):
addrs.append(self.allocator.alloc(32))
# Free alternate blocks
for i in range(0, len(addrs), 2):
self.allocator.free(addrs[i])
def test_custom_start_address(self):
allocator = TLSFAllocator(1024, start_addr=1000)
addr1 = allocator.alloc(32)
self.assertEqual(addr1, 1000)
addr2 = allocator.alloc(64)
self.assertEqual(addr2, 1032)
def test_block_tracking(self):
addr1 = self.allocator.alloc(32)
addr2 = self.allocator.alloc(64)
self.assertTrue(addr1 in [addr - self.allocator.start_addr for addr in self.allocator.blocks])
self.assertTrue(addr2 in [addr - self.allocator.start_addr for addr in self.allocator.blocks])
self.allocator.free(addr1)
self.assertTrue(addr1 in [addr - self.allocator.start_addr for addr in self.allocator.blocks])
if __name__ == '__main__':
unittest.main()