mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-10 07:28:15 -05:00
* nak works * TestOps::test_add works * testop has no crashes * fix bool casts * fix typo * add disassemble * RANGE and locals/regs * simplify NAKCompiler * disass cleanup * cleanup nir codegen * almost all tests passing * cleanup notes in extra/ * old notes * only import nak if NIR=1 * fix new SPECIAL syntax * fix local/shared memory * more tests passing * add DEFINE_VAR support * llvmpipe kinda works * diskcache * some mypy stuff * lvp passing test_ops.py * fix imports * actually fix imports * remove 'stdout' * fix llvm import * fix mypy issues * nicer errors * simpler test_dtype skips * test lvp in CI * fix github action syntax * fix more actions typos * switch to mesa 25.1.0 * diskcache_put * better generation for lvp nir_options * b64encode shader blobs * Revert diskcache changes This reverts commits930fa3de8aand8428c694b3. * general cleanup * better error messages * fix llvm import * fix windows tests * link with libm and libgcc_s * fix some errors * dont check for 'float4' * NIR uses pointer arithmetic * use tinymesa * bump tinymesa * bump tinymesa again * update lvp nir_options * print nir shader with DEBUG * simplify LVPCompiler * more tests * "gated" STORE * NAK is cacheable * more tests * all tests pass locally for NAK * test autogen in CI * autogen deps * more deps * fix uop_gc * fix macos * mypy * save 2 lines * save two more lines * save 1 line * save 4 lines * save more lines * Revert "save more lines" This reverts commitdd3a720c5a. * save more lines * fix LVP on windows * refactor * reorganize some code * refactor lib_gpu * move LVP check * out of order loads * remove support.mesa * bump tinymesa version * simplify LVP jit * macos * macos ci * shell: bash * testing * more testing * compute brew prefix * stupid typo * actually fix * lib * stdout on macos * inline gallivm_compile_module * Revert "inline gallivm_compile_module" This reverts commitb65983b151. * elf macos * semicolon * inherit from CPULLVMCompiler * ruff * disas test * fix libm linking * default is fine actually * arm works * add elf loader link test * fix NAK beam * pylint is too smart by half --------- Co-authored-by: George Hotz <72895+geohot@users.noreply.github.com> Co-authored-by: nimlgen <138685161+nimlgen@users.noreply.github.com>
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
import unittest, subprocess, platform
|
|
from tinygrad.runtime.ops_cpu import ClangJITCompiler
|
|
from tinygrad.runtime.support.elf import elf_loader
|
|
|
|
class TestElfLoader(unittest.TestCase):
|
|
def test_load_clang_jit_strtab(self):
|
|
src = '''
|
|
int something; // will be a load from a relocation (needed for .rela.text to exist)
|
|
int test(int x) {
|
|
return something + x;
|
|
}
|
|
'''
|
|
args = ('-x', 'c', '-c', '-target', f'{platform.machine()}-none-unknown-elf', '-march=native', '-fPIC', '-O2', '-ffreestanding', '-nostdlib')
|
|
obj = subprocess.check_output(('clang',) + args + ('-', '-o', '-'), input=src.encode('utf-8'))
|
|
_, sections, _ = elf_loader(obj)
|
|
section_names = [sh.name for sh in sections]
|
|
assert '.text' in section_names and '.rela.text' in section_names, str(section_names)
|
|
def test_clang_jit_compiler_external_raise(self):
|
|
src = '''
|
|
int evil_external_function(int);
|
|
int test(int x) {
|
|
return evil_external_function(x+2)*2;
|
|
}
|
|
'''
|
|
with self.assertRaisesRegex(RuntimeError, 'evil_external_function'):
|
|
ClangJITCompiler().compile(src)
|
|
def test_link(self):
|
|
src = '''
|
|
float powf(float, float); // from libm
|
|
float test(float x, float y) { return powf(x, y); }
|
|
'''
|
|
args = ('-x', 'c', '-c', '-target', f'{platform.machine()}-none-unknown-elf', '-march=native', '-fPIC', '-O2', '-ffreestanding', '-nostdlib')
|
|
obj = subprocess.check_output(('clang',) + args + ('-', '-o', '-'), input=src.encode())
|
|
with self.assertRaisesRegex(RuntimeError, 'powf'): elf_loader(obj)
|
|
elf_loader(obj, link_libs=['m'])
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|