repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/tinyfs/upload_raid.py
extra/tinyfs/upload_raid.py
from pathlib import Path import multiprocessing, json from tinygrad.tensor import Tensor from tinygrad.helpers import tqdm raid_root = Path("/raid") def upload_file(path: Path): pt = Tensor(path).realize() h = pt.fs_store().realize() pt.uop.realized.deallocate() return h.data().hex(), path, pt.nbytes() if _...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/tinyfs/fetch_raid.py
extra/tinyfs/fetch_raid.py
import json, multiprocessing, functools from pathlib import Path from tinygrad.tensor import Tensor from tinygrad.helpers import tqdm, getenv raid_root = Path(getenv("RAID_ROOT", "/raid")) def fetch_file(item): path, info = item h, size = info["hash"], info["size"] path = raid_root / Path(path) path.parent....
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/tinyfs/fetch_file.py
extra/tinyfs/fetch_file.py
from tinygrad.tensor import Tensor import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--hash", type=str, required=True, help="file hash to fetch") parser.add_argument("--len", type=int, required=True, help="file length to fetch") parser.add_argument("--dest", typ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/pcode.py
extra/assembly/amd/pcode.py
# DSL for RDNA3 pseudocode - makes pseudocode expressions work directly as Python import struct, math, re, functools from extra.assembly.amd.dsl import MASK32, MASK64, _f32, _i32, _sext, _f16, _i16, _f64, _i64 # ═══════════════════════════════════════════════════════════════════════════════ # INTERNAL HELPERS # ══════...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/asm.py
extra/assembly/amd/asm.py
# RDNA3 assembler and disassembler from __future__ import annotations import re from extra.assembly.amd.dsl import Inst, RawImm, Reg, SrcMod, SGPR, VGPR, TTMP, s, v, ttmp, _RegFactory from extra.assembly.amd.dsl import VCC_LO, VCC_HI, VCC, EXEC_LO, EXEC_HI, EXEC, SCC, M0, NULL, OFF from extra.assembly.amd.dsl import SP...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/pdf.py
extra/assembly/amd/pdf.py
# Generate AMD ISA autogen files from PDF documentation # Combines format/enum generation (previously in dsl.py) and pseudocode compilation (previously in pcode.py) # Usage: python -m extra.assembly.amd.pdf [--arch rdna3|rdna4|cdna|all] import re, functools from pathlib import Path from concurrent.futures import Proces...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/dsl.py
extra/assembly/amd/dsl.py
# library for RDNA3 assembly DSL # mypy: ignore-errors from __future__ import annotations import struct, math, re from enum import IntEnum from functools import cache from typing import overload, Annotated, TypeVar, Generic from extra.assembly.amd.autogen.rdna3.enum import (VOP1Op, VOP2Op, VOP3Op, VOP3SDOp, VOP3POp, VO...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/emu.py
extra/assembly/amd/emu.py
# RDNA3 emulator - executes compiled pseudocode from AMD ISA PDF # mypy: ignore-errors from __future__ import annotations import ctypes, functools from tinygrad.runtime.autogen import hsa from extra.assembly.amd.dsl import Inst, unwrap, FLOAT_ENC, MASK32, MASK64, _f32, _i32, _sext, _f16, _i16, _f64, _i64 from extra.ass...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_llvm.py
extra/assembly/amd/test/test_llvm.py
#!/usr/bin/env python3 """Test RDNA3 assembler/disassembler against LLVM test vectors.""" import unittest, re, subprocess from tinygrad.helpers import fetch from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.asm import asm from extra.assembly.amd.test.helpers import get_llvm_mc LLVM_BASE = "htt...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_mockgpu_invalid.py
extra/assembly/amd/test/test_mockgpu_invalid.py
#!/usr/bin/env python3 """Test that invalid instructions raise exceptions through the mock GPU stack.""" import unittest, subprocess, os, time class TestMockGPUInvalidInstruction(unittest.TestCase): def test_unsupported_instruction_raises(self): """Test that unsupported instructions raise immediately through the...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/external_test_usability.py
extra/assembly/amd/test/external_test_usability.py
# Usability tests for the RDNA3 ASM DSL # These tests demonstrate how the DSL *should* work for a good user experience # Currently many of these tests fail - they document desired behavior import unittest from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.dsl import Inst, RawImm, SGPR, VGPR cl...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_compare_emulators.py
extra/assembly/amd/test/test_compare_emulators.py
# Test to compare Python and Rust RDNA3 emulators by running real tinygrad kernels import unittest, ctypes, os from dataclasses import dataclass from pathlib import Path # Set environment before any tinygrad imports to use MOCKGPU # This allows generating AMD GPU kernels without requiring real hardware os.environ["AMD...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/helpers.py
extra/assembly/amd/test/helpers.py
"""Shared test helpers for RDNA3 tests.""" import shutil from dataclasses import dataclass @dataclass class KernelInfo: code: bytes global_size: tuple[int, int, int] local_size: tuple[int, int, int] buf_idxs: list[int] # indices into shared buffer pool buf_sizes: list[int] # sizes for each buffer index # ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_roundtrip.py
extra/assembly/amd/test/test_roundtrip.py
#!/usr/bin/env python3 """Roundtrip tests: generate tinygrad kernels, decode instructions, re-encode, verify match.""" import unittest, io, sys, re, subprocess, os from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.dsl import Inst from extra.assembly.amd.asm import asm from extra.assembly.amd.as...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_formats.py
extra/assembly/amd/test/test_formats.py
#!/usr/bin/env python3 """Test MUBUF, MTBUF, MIMG, EXP, DS formats against LLVM.""" import unittest from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.dsl import encode_src, RawImm from extra.assembly.amd.asm import detect_format class TestMUBUF(unittest.TestCase): """Test MUBUF (buffer) inst...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_pcode.py
extra/assembly/amd/test/test_pcode.py
#!/usr/bin/env python3 """Tests for the RDNA3 pseudocode DSL.""" import unittest from extra.assembly.amd.pcode import (Reg, TypedView, TypedView, MASK32, MASK64, _f32, _i32, _f16, _i16, f32_to_f16, isNAN, _bf16, _ibf16, bf16_to_f32, f32_to_bf16, ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_handwritten.py
extra/assembly/amd/test/test_handwritten.py
# do not change these tests. we need to fix bugs to make them pass # the Inst constructor should be looking at the types of the fields to correctly set the value import unittest, struct from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.dsl import Inst from extra.assembly.amd.asm import asm fro...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/bench_emu.py
extra/assembly/amd/test/bench_emu.py
#!/usr/bin/env python3 """Benchmark comparing Python vs Rust RDNA3 emulators on real tinygrad kernels.""" import ctypes, time, os from pathlib import Path # Set AMD=1 before importing tinygrad os.environ["AMD"] = "1" from extra.assembly.amd.emu import run_asm as python_run_asm, set_valid_mem_ranges, decode_program R...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_pdf_parser.py
extra/assembly/amd/test/test_pdf_parser.py
#!/usr/bin/env python3 """Test that PDF parser correctly extracts format fields.""" import unittest, os from extra.assembly.amd.autogen.rdna3.ins import SOP1, SOP2, SOPK, SOPP, VOP1, VOP2, VOP3SD, VOPC, FLAT, VOPD, SOP1Op, SOP2Op, VOP1Op, VOP3Op # expected formats with key fields and whether they have ENCODING EXPECTE...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_rdna3_asm.py
extra/assembly/amd/test/test_rdna3_asm.py
#!/usr/bin/env python3 import unittest, subprocess from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.test.helpers import get_llvm_mc def llvm_assemble(asm: str) -> bytes: """Assemble using llvm-mc and return bytes.""" result = subprocess.run( [get_llvm_mc(), "-triple=amdgcn", "-mcpu=gf...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/test_integration.py
extra/assembly/amd/test/test_integration.py
#!/usr/bin/env python3 """Integration test: round-trip RDNA3 assembly through AMD toolchain.""" import unittest, re, io, sys, subprocess from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.asm import waitcnt, asm from extra.assembly.amd.test.helpers import get_llvm_mc def disassemble(lib: bytes,...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_vop2.py
extra/assembly/amd/test/hw/test_vop2.py
"""Tests for VOP2 instructions - two operand vector operations. Includes: v_add_f32, v_mul_f32, v_and_b32, v_or_b32, v_xor_b32, v_lshrrev_b32, v_lshlrev_b32, v_fmac_f32, v_fmaak_f32, v_fmamk_f32, v_add_nc_u32, v_cndmask_b32, v_add_f16, v_mul_f16 """ import unittest from extra.assembly.amd.test.hw.h...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_ds.py
extra/assembly/amd/test/hw/test_ds.py
"""Tests for DS instructions - data share (LDS) operations. Includes: ds_store_b32, ds_load_b32, ds_store_2addr_*, ds_load_2addr_*, ds_add_*, ds_max_*, ds_min_*, ds_and_*, ds_or_*, ds_xor_*, ds_inc_*, ds_dec_*, ds_cmpstore_*, ds_storexchg_* """ import unittest from extra.assembly.amd.test.hw.helper...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_vopc.py
extra/assembly/amd/test/hw/test_vopc.py
"""Tests for VOPC instructions - vector compare operations. Includes: v_cmp_class_f32, v_cmp_class_f16, v_cmp_eq_*, v_cmp_lt_*, v_cmp_gt_* """ import unittest from extra.assembly.amd.test.hw.helpers import * VCC = 106 # SGPR index for VCC_LO class TestCmpClass(unittest.TestCase): """Tests for V_CMP_CLASS_F32 floa...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/helpers.py
extra/assembly/amd/test/hw/helpers.py
"""Test infrastructure for hardware-validated RDNA3 emulator tests. Uses run_asm() with memory output, so tests can run on both emulator and real hardware. Set USE_HW=1 to run on both emulator and real hardware, comparing results. """ import ctypes, os, struct from extra.assembly.amd.autogen.rdna3.ins import * from ex...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_vop3p.py
extra/assembly/amd/test/hw/test_vop3p.py
"""Tests for VOP3P instructions - packed 16-bit vector operations. Includes: v_pk_add_f16, v_pk_mul_f16, v_pk_fma_f16, v_pack_b32_f16, v_wmma_*, v_dot2_* """ import unittest from extra.assembly.amd.test.hw.helpers import * class TestPackInstructions(unittest.TestCase): """Tests for pack instructions.""" def test...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/__init__.py
extra/assembly/amd/test/hw/__init__.py
"""Hardware-validated emulator tests for RDNA3 instructions."""
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_sop.py
extra/assembly/amd/test/hw/test_sop.py
"""Tests for SOP instructions - scalar operations. Includes: s_add_u32, s_mov_b32, s_and_b32, s_or_b32, s_quadmask_b32, s_wqm_b32, s_cbranch_vccnz, s_cbranch_vccz """ import unittest from extra.assembly.amd.test.hw.helpers import * class TestBasicScalar(unittest.TestCase): """Tests for basic scalar operat...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_vop3.py
extra/assembly/amd/test/hw/test_vop3.py
"""Tests for VOP3 instructions - three operand vector operations. Includes: v_fma_f32, v_div_scale_f32, v_div_fmas_f32, v_div_fixup_f32, v_alignbit_b32, v_bfe_i32, v_mad_u64_u32, v_readlane_b32, v_writelane_b32 """ import unittest from extra.assembly.amd.test.hw.helpers import * class TestFMA(unittest.TestC...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_flat.py
extra/assembly/amd/test/hw/test_flat.py
"""Tests for FLAT instructions - flat memory operations. Includes: flat_load_*, flat_store_*, flat_atomic_* """ import unittest from extra.assembly.amd.test.hw.helpers import * class TestFlatAtomic(unittest.TestCase): """Tests for FLAT atomic instructions.""" def _make_test(self, setup_instrs, atomic_instr, chec...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_global.py
extra/assembly/amd/test/hw/test_global.py
"""Tests for GLOBAL instructions - global memory operations. Includes: global_load_*, global_store_*, global_atomic_*, global_load_d16_* """ import unittest from extra.assembly.amd.test.hw.helpers import * class TestGlobalAtomic(unittest.TestCase): """Tests for GLOBAL atomic instructions.""" def _make_test(self,...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/test/hw/test_vop1.py
extra/assembly/amd/test/hw/test_vop1.py
"""Tests for VOP1 instructions - single operand vector operations. Includes: v_mov_b32, v_cvt_*, v_sin_f32, v_rcp_f32, v_exp_f32, v_rndne_f32, v_floor_f32, v_trunc_f32, v_fract_f32, v_clz_i32_u32, v_ctz_i32_b32, v_readfirstlane_b32 """ import unittest from extra.assembly.amd.test.hw.helpers import ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna4/enum.py
extra/assembly/amd/autogen/rdna4/enum.py
# autogenerated from AMD RDNA4 ISA PDF by pdf.py - do not edit from enum import IntEnum class SrcEnum(IntEnum): VCC_LO = 106 VCC_HI = 107 NULL = 124 M0 = 125 EXEC_LO = 126 EXEC_HI = 127 ZERO = 128 DPP8 = 233 DPP8FI = 234 SHARED_BASE = 235 SHARED_LIMIT = 236 PRIVATE_BASE = 237 PRIVATE_LIMIT = ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna4/__init__.py
extra/assembly/amd/autogen/rdna4/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna4/str_pcode.py
extra/assembly/amd/autogen/rdna4/str_pcode.py
# autogenerated by pdf.py - do not edit # to regenerate: python -m extra.assembly.amd.pdf --arch rdna4 # ruff: noqa: E501 from extra.assembly.amd.autogen.rdna4.enum import SOP1Op, SOP2Op, SOPCOp, SOPKOp, SOPPOp, SMEMOp, VOP1Op, VOP2Op, VOP3Op, VOP3SDOp, VOP3POp, VOPCOp, DSOp SOP1Op_PCODE = { SOP1Op.S_MOV_B32: 'D0.b3...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna4/ins.py
extra/assembly/amd/autogen/rdna4/ins.py
# autogenerated from AMD RDNA4 ISA PDF by pdf.py - do not edit # ruff: noqa: F401,F403 from typing import Annotated from extra.assembly.amd.dsl import bits, BitField, Inst32, Inst64, Inst96, SGPR, VGPR, TTMP as TTMP, s as s, v as v, ttmp as ttmp, SSrc, Src, SImm, Imm, VDSTYEnc, SGPRField, VGPRField from extra.assembly....
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/cdna/enum.py
extra/assembly/amd/autogen/cdna/enum.py
# autogenerated from AMD CDNA3+CDNA4 ISA PDF by pdf.py - do not edit from enum import IntEnum class SrcEnum(IntEnum): S_ADD_U32 = 0 S_SUB_U32 = 1 S_ADD_I32 = 2 S_SUB_I32 = 3 S_ADDC_U32 = 4 S_SUBB_U32 = 5 S_MIN_I32 = 6 FLAT_SCRATCH_LO = 102 FLAT_SCRATCH_HI = 103 XNACK_MASK_LO = 104 XNACK_MASK_HI =...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/cdna/__init__.py
extra/assembly/amd/autogen/cdna/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/cdna/str_pcode.py
extra/assembly/amd/autogen/cdna/str_pcode.py
# autogenerated by pdf.py - do not edit # to regenerate: python -m extra.assembly.amd.pdf --arch cdna # ruff: noqa: E501 from extra.assembly.amd.autogen.cdna.enum import SOP1Op, SOP2Op, SOPCOp, SOPKOp, SOPPOp, SMEMOp, VOP1Op, VOP2Op, VOP3POp, VOPCOp, VOP3AOp, VOP3BOp, DSOp, FLATOp, GLOBALOp, SCRATCHOp SOP1Op_PCODE = {...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/cdna/ins.py
extra/assembly/amd/autogen/cdna/ins.py
# autogenerated from AMD CDNA3+CDNA4 ISA PDF by pdf.py - do not edit # ruff: noqa: F401,F403 from typing import Annotated from extra.assembly.amd.dsl import bits, BitField, Inst32, Inst64, Inst96, SGPR, VGPR, TTMP as TTMP, s as s, v as v, ttmp as ttmp, SSrc, Src, SImm, Imm, VDSTYEnc, SGPRField, VGPRField from extra.ass...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna3/enum.py
extra/assembly/amd/autogen/rdna3/enum.py
# autogenerated from AMD RDNA3.5 ISA PDF by pdf.py - do not edit from enum import IntEnum class SrcEnum(IntEnum): VCC_LO = 106 VCC_HI = 107 NULL = 124 M0 = 125 EXEC_LO = 126 EXEC_HI = 127 ZERO = 128 DPP8 = 233 DPP8FI = 234 SHARED_BASE = 235 SHARED_LIMIT = 236 PRIVATE_BASE = 237 PRIVATE_LIMIT ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna3/__init__.py
extra/assembly/amd/autogen/rdna3/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna3/str_pcode.py
extra/assembly/amd/autogen/rdna3/str_pcode.py
# autogenerated by pdf.py - do not edit # to regenerate: python -m extra.assembly.amd.pdf --arch rdna3 # ruff: noqa: E501 from extra.assembly.amd.autogen.rdna3.enum import SOP1Op, SOP2Op, SOPCOp, SOPKOp, SOPPOp, SMEMOp, VOP1Op, VOP2Op, VOP3Op, VOP3SDOp, VOP3POp, VOPCOp, DSOp, FLATOp, GLOBALOp, SCRATCHOp SOP1Op_PCODE =...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/assembly/amd/autogen/rdna3/ins.py
extra/assembly/amd/autogen/rdna3/ins.py
# autogenerated from AMD RDNA3.5 ISA PDF by pdf.py - do not edit # ruff: noqa: F401,F403 from typing import Annotated from extra.assembly.amd.dsl import bits, BitField, Inst32, Inst64, Inst96, SGPR, VGPR, TTMP as TTMP, s as s, v as v, ttmp as ttmp, SSrc, Src, SImm, Imm, VDSTYEnc, SGPRField, VGPRField from extra.assembl...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/tiny/fa.py
extra/thunder/tiny/fa.py
import math from tinygrad import Tensor, dtypes from tinygrad.uop.ops import UOp from extra.thunder.tiny.tk import WARP_THREADS from extra.thunder.tiny.tk.kernel import Kernel from extra.thunder.tiny.tk.tiles import GL, TileLayout NUM_WORKERS = 1 Q_BLOCK_SIZE = 16 KV_BLOCK_SIZE = 16 def flash_attention(xq, xk, xv, ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/tiny/visualize_tile.py
extra/thunder/tiny/visualize_tile.py
from tinygrad.helpers import colored WARP_THREADS = 64 BASE_TILE_ROWS = 16 BASE_TILE_COLS = 16 BASE_TILE_NEPT = (BASE_TILE_ROWS * BASE_TILE_COLS) // WARP_THREADS DTYPE_SIZE = 2 INST = "ds_read_b64" def row_col(threadIdx_x): local_warpid = threadIdx_x // WARP_THREADS warp_laneid = threadIdx_x % WARP_THREADS ret...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/tiny/tk/kernel.py
extra/thunder/tiny/tk/kernel.py
from contextlib import AbstractContextManager from tinygrad.uop.ops import UOp, KernelInfo, AxisType, AddrSpace from extra.thunder.tiny.tk import WARP_THREADS from extra.thunder.tiny.tk.group import Group from extra.thunder.tiny.tk.tiles import GL, ST_16X16, ST, RT_16X16, RT, RV, TileLayout, VecLayout class _tk_range:...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/tiny/tk/group.py
extra/thunder/tiny/tk/group.py
import math from typing import cast, Callable from tinygrad import dtypes from tinygrad.uop.ops import AxisType, UOp, Ops from tinygrad.dtype import AddrSpace, PtrDType from tinygrad.helpers import prod from extra.thunder.tiny.tk import WARP_THREADS from extra.thunder.tiny.tk.tiles import ALL_TILES, ST, RT, RV, TileLa...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/tiny/tk/__init__.py
extra/thunder/tiny/tk/__init__.py
from tinygrad.device import Device if Device.DEFAULT == "AMD": WARP_THREADS = 64 else: WARP_THREADS = 32
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/tiny/tk/tiles.py
extra/thunder/tiny/tk/tiles.py
from enum import Enum, auto import functools from typing import Callable from dataclasses import dataclass from tinygrad.dtype import AddrSpace, DType from tinygrad.mixin import MathMixin from tinygrad.uop.ops import UOp, Ops from extra.thunder.tiny.tk import WARP_THREADS def unwrap(x): if hasattr(x, "_uop"): retur...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/cuda/fa.py
extra/thunder/cuda/fa.py
import pathlib from tinygrad import Device, Tensor from tinygrad.helpers import Context from tinygrad.runtime.support.compiler_cuda import pretty_ptx, NVCCCompiler if __name__ == "__main__": code = (pathlib.Path(__file__).parent / "fa.cu").read_text() device = Device["CUDA"] kitten_args = [f"-I{(pathlib.Path(__f...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/cuda/matmul.py
extra/thunder/cuda/matmul.py
import pathlib from tinygrad import Device, Tensor from tinygrad.helpers import Context, getenv from tinygrad.runtime.support.compiler_cuda import pretty_ptx, NVCCCompiler if __name__ == "__main__": if getenv("MATMUL2"): code = (pathlib.Path(__file__).parent / "matmul2.cu").read_text() else: code = (pathli...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thunder/metal/gemm.py
extra/thunder/metal/gemm.py
# include directory copied from https://github.com/HazyResearch/ThunderMittens # https://hazyresearch.stanford.edu/blog/2024-11-28-tk-mlx gemm = """ #include <metal_stdlib> #include "include/tk.metal" using namespace mittens; #define GEMM_PARAMS_DEF(T) \ device T* D [[buffer(0)]], \ device T* A [[buffer(1)]],...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/tinygrad_nv_matmul.py
extra/gemm/tinygrad_nv_matmul.py
from tinygrad import Tensor, dtypes, Device from tinygrad.helpers import getenv, DEBUG from tinygrad.codegen.opt.kernel import Kernel, Opt, OptOps from tinygrad.engine.realize import CompiledRunner, ExecItem, get_program from dataclasses import replace N = 4096 if __name__ == "__main__": if getenv("GEMV"): A, B ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/metal_conv.py
extra/gemm/metal_conv.py
import os #os.environ["METAL"] = "1" import numpy as np BS = 64 CIN = 256 COUT = 256 HW = 32 K = 3 PADDING = 0 # TODO: this is doing some trick, since with CIN=256 COUT=256 it's over 10.4 TFLOPS. # are winograd convs less flops? it appears so if they are batched # https://www.cse.ust.hk/~weiwa/papers/yan-ppopp20.pdf F...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/real_pmatmul.py
extra/gemm/real_pmatmul.py
import time from tinygrad import Tensor, Device, TinyJit from tinygrad.helpers import getenv if __name__ == "__main__": DEVS = [f"NV:{i}" for i in range(getenv("GPUS", 2))] N = getenv("N", 8192) A = Tensor.rand(N, N).shard(DEVS, 0).realize() B = Tensor.rand(N, N).shard(DEVS, 1).realize() print("***** MUL ***...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/mi350x_uop_matmul.py
extra/gemm/mi350x_uop_matmul.py
import os import numpy as np np.set_printoptions(linewidth=1000000) os.environ["AMD_LLVM"] = "0" from tinygrad import Tensor, Context, dtypes, UOp, GlobalCounters from tinygrad.helpers import DEBUG, getenv from tinygrad.dtype import AddrSpace from tinygrad.uop.ops import AxisType, KernelInfo, Ops WARP_SIZE = 64 # Re...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/torch_gemm.py
extra/gemm/torch_gemm.py
import os os.environ["NVIDIA_TF32_OVERRIDE"] = "0" os.environ["MKL_NUM_THREADS"] = "1" os.environ["NUMEXPR_NUM_THREADS"] = "1" os.environ["OMP_NUM_THREADS"] = "1" import time import torch torch.set_num_threads(1) from tinygrad.helpers import getenv CUDA = getenv("CUDA", 1) MPS = getenv("MPS", 0) if getenv("FP16_ACC"): ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/mi350x_uop_matmul_2.py
extra/gemm/mi350x_uop_matmul_2.py
import os import numpy as np np.set_printoptions(linewidth=1000000) os.environ["AMD_LLVM"] = "0" from tinygrad import Tensor, Context, dtypes, UOp, GlobalCounters from tinygrad.helpers import DEBUG, getenv from tinygrad.dtype import AddrSpace from tinygrad.uop.ops import sint, AxisType, KernelInfo, Ops WARP_SIZE = 64...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/max_matmul.py
extra/gemm/max_matmul.py
import numpy as np, os from tinygrad.helpers import getenv, flat_mv from tinygrad import dtypes from tinygrad.engine.realize import get_program # for copied uops from tinygrad import dtypes from tinygrad.dtype import DTYPES_DICT script_dir = os.path.dirname(os.path.abspath(__file__)) # problem variations DTYPE_IN = ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/metal_matvec.py
extra/gemm/metal_matvec.py
import numpy as np import time, torch, torch.mps from tinygrad import Tensor, TinyJit, Device from tinygrad.helpers import flat_mv from tinygrad.runtime.ops_metal import MetalAllocator, MetalDevice, MetalProgram, MetalCompiler N = 16384 M = 4096 FLOPS = N*M*2 nb = np.random.default_rng().standard_normal(size=(N), dt...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/cuda_matmul.py
extra/gemm/cuda_matmul.py
import os import numpy as np os.environ["CUDA"] = "1" from tinygrad.runtime.ops_cuda import CUDAAllocator, CUDADevice, CUDAProgram, CUDACompiler from tinygrad.helpers import flat_mv FLOAT16 = True ACC_FLOAT16 = False N = 4096 na = np.random.default_rng().standard_normal(size=(N,N), dtype=np.float32) nb = np.random.de...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/triton_nv_matmul.py
extra/gemm/triton_nv_matmul.py
import time import triton import triton.language as tl from triton.compiler import AttrsDescriptor, ASTSource, compile as triton_compile import numpy as np from tinygrad import Tensor, dtypes, Device from tinygrad.engine.realize import CompiledRunner, ExecItem, ProgramSpec from tinygrad.helpers import getenv np.set_pri...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/amx.py
extra/gemm/amx.py
#!/usr/bin/env python3 import numpy as np import time import sys np.set_printoptions(linewidth=160) np.set_printoptions(linewidth=1000, threshold=10000000000, suppress=False) from tinygrad.runtime.ops_llvm import LLVMDevice, LLVMProgram, LLVMCompiler from llvmlite import ir # type: ignore from tinygrad.helpers import ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/hip_matmul.py
extra/gemm/hip_matmul.py
import time import numpy as np from tinygrad.helpers import getenv, prod, flat_mv from tinygrad.runtime.ops_amd import AMDAllocator, AMDDevice, AMDProgram # AMD_LOG_LEVEL=3 ./MIOpenDriver gemm --iter 1000 --time 1 --a_w 2048 --a_h 2048 --b_w 2048 # 5.5: Cijk_Ailk_Bljk_HHS_BH_MT128x128x16_MI16x16x16x1_SN_1LDSB0_APM1_AB...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/simple_matmul.py
extra/gemm/simple_matmul.py
import numpy as np from tinygrad import dtypes, Tensor from tinygrad.helpers import getenv, get_single_element from tinygrad.dtype import _to_np_dtype from tinygrad.codegen.opt import OptOps dtype_in = (dtypes.half if getenv("HALF") else dtypes.bfloat16 if getenv("BFLOAT16") else dtypes.fp8e4m3 if getenv("...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/amd_matmul.py
extra/gemm/amd_matmul.py
# kernel8_batched_gmem.s from https://seb-v.github.io/optimization/update/2025/01/20/Fast-GPU-Matrix-multiplication.html # sudo PATH=/opt/homebrew/Cellar/llvm/20.1.6/bin:$PATH AMD_LLVM=0 AMD=1 DEBUG=2 python3 extra/gemm/amd_matmul.py import pathlib from dataclasses import replace from tinygrad import Tensor, Device, Co...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/simple_conv.py
extra/gemm/simple_conv.py
from tinygrad.helpers import getenv from tinygrad import dtypes, Tensor dtype_in = dtypes.half if getenv("HALF") else dtypes.bfloat16 if getenv("BFLOAT16") else dtypes.float acc_dtype = dtypes.half if getenv("ACC_HALF") else dtypes.bfloat16 if getenv("ACC_BFLOAT16") else None CNT = getenv("CNT", 8) BS = getenv("BS", ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/gemm.py
extra/gemm/gemm.py
#!/usr/bin/env python3 import os #os.environ['OMP_NUM_THREADS'] = '1' import time import numpy as np N = 512 if __name__ == "__main__": # N^2 A = np.random.randn(N, N).astype(np.float32) # N^2 B = np.random.randn(N, N).astype(np.float32) # 2N compute in N^2 output cells flop = 2*N*N*N #print(f"{flop / 1...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/fuzz_matmul.py
extra/gemm/fuzz_matmul.py
import numpy as np from tinygrad.helpers import getenv from tinygrad import dtypes, Tensor dtype_in = dtypes.half if getenv("HALF") else dtypes.bfloat16 if getenv("BFLOAT16") else dtypes.float acc_dtype = dtypes.half if getenv("ACC_HALF") else dtypes.bfloat16 if getenv("ACC_BFLOAT16") else None N_START = getenv("N_STAR...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/tvm_gemm.py
extra/gemm/tvm_gemm.py
# https://tvm.apache.org/docs/tutorial/tensor_expr_get_started.html#example-2-manually-optimizing-matrix-multiplication-with-te M, N, K = 1024, 1024, 1024 try: import tvm from tvm import te #print(tvm.target.Target.list_kinds()) # c, opencl target = tvm.target.Target(target="c") # TVM Matrix Multiplicat...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/halide_gemm.py
extra/gemm/halide_gemm.py
import numpy as np import halide as hl from tinygrad.helpers import Timing, getenv # HL_DEBUG_CODEGEN=1 N = getenv("N", 1024) def gemm_pipeline(gpu=False): # ---------------- Vars & Parameters ---------------- i, j = hl.Var("i"), hl.Var("j") # output tile coordinates A = hl.InputBuffer(hl.Float(32), 2) # [M,...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/metal_matmul.py
extra/gemm/metal_matmul.py
import os os.environ["METAL"] = "1" import time import numpy as np from tinygrad import Device, dtypes from tinygrad.helpers import getenv, flat_mv from tinygrad.runtime.ops_metal import MetalAllocator, MetalDevice, MetalProgram, MetalCompiler N = getenv("N", 2048) LID = 2 device = MetalDevice("METAL") metalalloc = M...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/amd_uop_matmul.py
extra/gemm/amd_uop_matmul.py
import numpy as np from tinygrad import Tensor, Device, Context, GlobalCounters, dtypes from tinygrad.uop.ops import UOp, KernelInfo, sint, AxisType from tinygrad.engine.realize import ExecItem, get_runner from tinygrad.dtype import AddrSpace from tinygrad.helpers import getenv N = getenv("N", 4096) M = K = N run_coun...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/simple_matvec.py
extra/gemm/simple_matvec.py
import numpy as np from tinygrad.helpers import getenv from tinygrad import dtypes, Tensor, Device dtype_in = dtypes.half if getenv("HALF") else dtypes.bfloat16 if getenv("BFLOAT16") else dtypes.float acc_dtype = dtypes.half if getenv("ACC_HALF") else dtypes.bfloat16 if getenv("ACC_BFLOAT16") else None GPUS = getenv("...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/metal_uop_matmul.py
extra/gemm/metal_uop_matmul.py
from tinygrad import UOp, dtypes from tinygrad.uop.ops import AxisType, Ops, KernelInfo, AddrSpace from extra.gemm.amd_uop_matmul import test_matmul N = 2048 # metal has an 8x8 tensor core. this is the indexing def mat_idx(buf, g0, g1, warp, u): l = [(warp//2**i)%2 for i in range(5)] return buf[g0, l[4]*4 + l[2]*...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/intel_xmx.py
extra/gemm/intel_xmx.py
#!/usr/bin/env python3 import numpy as np from tinygrad.runtime.ops_cl import CLProgram, CLCompiler from tinygrad import Device, dtypes from tinygrad.device import Buffer from hexdump import hexdump # https://github.com/intel/intel-graphics-compiler/blob/master/documentation/visa/instructions/DPAS.md # https://registr...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/asm/unpack_kd.py
extra/gemm/asm/unpack_kd.py
# unpack the complete kernel descriptor of an amdgpu ELF # https://rocm.docs.amd.com/projects/llvm-project/en/latest/LLVM/llvm/html/AMDGPUUsage.html#code-object-v3-kernel-descriptor import struct, pathlib, sys from tinygrad.runtime.support.elf import elf_loader def bits(x, lo, hi): return (x >> lo) & ((1 << (hi - lo +...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/asm/cdna/test.py
extra/gemm/asm/cdna/test.py
# Run assembly on the AMD runtime and check correctness # VIZ=2 to profile import pathlib from tinygrad import Tensor, Device, dtypes, Context from tinygrad.uop.ops import UOp, Ops, KernelInfo from tinygrad.helpers import getenv fp = pathlib.Path(__file__).parent/"gemm.s" N = getenv("N", 8192) THREADS_PER_WG = 256 NU...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gemm/asm/rdna3/test.py
extra/gemm/asm/rdna3/test.py
import math, pathlib from tinygrad import Device, dtypes from tinygrad.uop.ops import UOp, Ops, KernelInfo from extra.gemm.amd_uop_matmul import test_matmul N = 4096 TN = 96 THREADS_PER_WG = 128 NUM_WG = math.ceil(N / TN) * math.ceil(N / TN) dname:str = Device.DEFAULT template:str = (pathlib.Path(__file__).parent/"...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/test_multigpu.py
extra/torch_backend/test_multigpu.py
import unittest from tinygrad.helpers import getenv import torch import tinygrad.nn.torch torch.set_default_device("tiny") import numpy as np @unittest.skipIf(getenv("GPUS",1)<=1, "only single GPU") class TestTorchBackendMultiGPU(unittest.TestCase): def test_transfer(self): a = torch.Tensor([[1,2],[3,4]]).to("ti...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/backend2.py
extra/torch_backend/backend2.py
# NOTE: this is probably the wrong backend to work on, you want backend.py # discussion about this in #pytorch-backend on our Discord # this is using high level debug features from torch and we should integrate deeper from tinygrad import Tensor import torch, contextlib from torch.utils._python_dispatch import TorchDi...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/torch_tests.py
extra/torch_backend/torch_tests.py
import sys import unittest import torch import extra.torch_backend.backend from torch.testing._internal.common_utils import TestCase, is_privateuse1_backend_available assert is_privateuse1_backend_available() and torch._C._get_privateuse1_backend_name() == "tiny" from torch.testing._internal.common_device_type import ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/example.py
extra/torch_backend/example.py
from PIL import Image from tinygrad.helpers import getenv, GlobalCounters import torch, torchvision, pathlib, warnings import torchvision.transforms as transforms import extra.torch_backend.backend device = "tiny" torch.set_default_device(device) if __name__ == "__main__": GlobalCounters.reset() img = Image.open(p...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/test_compile.py
extra/torch_backend/test_compile.py
# https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html import torch import torch._dynamo from extra.torch_backend.backend import unwrap, wrap from torch._dynamo.backends.registry import register_backend from torch._functorch.aot_autograd import aot_module_simplified from tinygrad import Tensor, Tiny...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/test.py
extra/torch_backend/test.py
# simple tests import unittest import torch import numpy as np from tinygrad.helpers import getenv, GlobalCounters if getenv("TINY_BACKEND2"): import extra.torch_backend.backend2 device = "cpu" else: import extra.torch_backend.backend device = "tiny" class TestTorchBackend(unittest.TestCase): def test_randpe...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/backend.py
extra/torch_backend/backend.py
# ruff: noqa: E501, A001, A002, A006 # A001 Variable `input` is shadowing a Python builtin # A002 Function argument `input` is shadowing a Python builtin # A006 Lambda argument `input` is shadowing a Python builtin from tinygrad import Tensor, dtypes, Device from tinygrad.uop.ops import Ops from tinygrad.helpers import...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/test_inplace.py
extra/torch_backend/test_inplace.py
import unittest import torch import tinygrad.nn.torch torch.set_default_device("tiny") import numpy as np class TestTorchBackendInplace(unittest.TestCase): def test_zero(self): a = torch.ones(4) a.zero_() np.testing.assert_equal(a.cpu().numpy(), [0,0,0,0]) def test_view_zero(self): a = torch.ones(...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_backend/test_kernel_fusion.py
extra/torch_backend/test_kernel_fusion.py
# simple tests import unittest import torch import warnings from tinygrad.helpers import getenv, GlobalCounters if getenv("TINY_BACKEND2"): import extra.torch_backend.backend2 device = "cpu" else: import extra.torch_backend.backend device = "tiny" class TestKernelFusionRegression(unittest.TestCase): def _re...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/qcom_gpu_driver/msm_kgsl.py
extra/qcom_gpu_driver/msm_kgsl.py
# type: ignore # -*- coding: utf-8 -*- # # TARGET arch is: [] # WORD_SIZE is: 8 # POINTER_SIZE is: 8 # LONGDOUBLE_SIZE is: 16 # import ctypes class AsDictMixin: import sys if sys.version_info >= (3, 14): _layout_ = 'ms' @classmethod def as_dict(cls, self): result = {} if not isinstance...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/qcom_gpu_driver/qcom_opencl_interop.py
extra/qcom_gpu_driver/qcom_opencl_interop.py
import ctypes, array from hexdump import hexdump from tinygrad.runtime.ops_cl import CLDevice from tinygrad.helpers import getenv, to_mv, mv_address from tinygrad.dtype import dtypes from tinygrad import Tensor, TinyJit from tinygrad.runtime.autogen import opencl as cl if getenv("IOCTL"): import extra.qcom_gpu_driver.o...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/qcom_gpu_driver/opencl_ioctl.py
extra/qcom_gpu_driver/opencl_ioctl.py
# type: ignore import ctypes, ctypes.util, struct, fcntl, re from hexdump import hexdump from copy import deepcopy import pathlib, sys from tinygrad.helpers import to_mv, getenv from tinygrad.runtime.autogen import adreno sys.path.append(pathlib.Path(__file__).parent.parent.parent.as_posix()) IOCTL = getenv("IOCTL", 0...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/amdpci/proclogs.py
extra/amdpci/proclogs.py
import re, ctypes, sys, importlib from tinygrad.helpers import getenv from tinygrad.runtime.support.am.amdev import AMDev, AMRegister class GFXFake: def __init__(self): self.xccs = 8 class AMDFake(AMDev): def __init__(self, pci_dev, dma_regions=None): self.pci_dev, self.devfmt, self.dma_regions = pci_dev, pc...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/amdpci/am_smi.py
extra/amdpci/am_smi.py
#!/usr/bin/env python3 import time, mmap, sys, shutil, os, glob, subprocess, argparse, collections from tinygrad.helpers import DEBUG, colored, ansilen from tinygrad.runtime.autogen import libc from tinygrad.runtime.autogen.am import am from tinygrad.runtime.support.hcq import MMIOInterface from tinygrad.runtime.suppo...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/amdpci/hive_reset.py
extra/amdpci/hive_reset.py
#!/usr/bin/env python3 from tinygrad.helpers import Context from tinygrad.runtime.support.system import System, PCIDevice, PCIDevImplBase from tinygrad.runtime.support.am.amdev import AMDev if __name__ == "__main__": gpus = System.pci_scan_bus(0x1002, [(0xffff, [0x74a1, 0x75a0])]) pcidevs = [PCIDevice(f"reset:{gp...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/nv_gpu_driver/nv_ioctl.py
extra/nv_gpu_driver/nv_ioctl.py
# type: ignore import ctypes, ctypes.util, struct, platform, pathlib, re, time, os, signal from tinygrad.helpers import from_mv, to_mv, getenv, init_c_struct_t from hexdump import hexdump start = time.perf_counter() # *** ioctl lib *** libc = ctypes.CDLL(ctypes.util.find_library("c")) processor = platform.processor() ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/spec.py
extra/hcqfuzz/spec.py
import os, random class TestSpec: def prepare(self, device, seed): raise NotImplementedError("prepare must be implemented in the derived class") def get_exec_state(self): raise NotImplementedError("get_exec_state must be implemented in the derived class") def name(self): return self.__class__.__name__ c...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/tools.py
extra/hcqfuzz/tools.py
import pickle, datetime, os, tempfile, subprocess, zipfile, importlib.util from extra.hcqfuzz.spec import TestSpec from tinygrad.helpers import getenv BASE_DIR = os.path.dirname(os.path.abspath(__file__)) TEST_DIR = os.path.join(BASE_DIR, "tests") REPORTS_DIR = os.path.join(BASE_DIR, "reports") def collect_tests(): ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/fuzzer.py
extra/hcqfuzz/fuzzer.py
import os, random, subprocess, shlex, datetime, time, signal from extra.hcqfuzz.tools import create_report, on_start_run, collect_tests, init_log, log from extra.hcqfuzz.spec import AMSpec def run_test(dev, test): on_start_run(dev, test) dev_env = dev.get_exec_state() test_env, cmd, timeout = test.get_exec_stat...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/tests/bert.py
extra/hcqfuzz/tests/bert.py
from extra.hcqfuzz.spec import TestSpec import random bert_train_params = { "DEFAULT_FLOAT": "HALF", "SUM_DTYPE": "HALF", "GPUS": 6, "BS": 96, "EVAL_BS": 96, "BASEDIR": "/raid/datasets/wiki", } class TrainBert(TestSpec): def prepare(self, dev, seed): random.seed(seed) self.env = { **bert_...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false