Skip to content

Instantly share code, notes, and snippets.

View leegao's full-sized avatar
💭
Backpacking the 🌍

Lee Gao leegao

💭
Backpacking the 🌍
View GitHub Profile
@leegao
leegao / mali_vk_format_get_bc_fallback_target.md
Created July 24, 2026 08:22
Mali G610 g29p1-11eac-18 (r54p1) Rockchip (DRM-based) driver's BCn -> RGBA8 transcode table
@leegao
leegao / compress.slang
Created May 20, 2026 16:21
ETC1 real-time compression kernel
__glsl_extension(GL_EXT_shader_realtime_clock) uint2 clockRealtime2x32EXT() {
__target_switch {
case spirv:
return spirv_asm {
OpCapability ShaderClockKHR;
OpExtension "SPV_KHR_shader_clock";
result : $$uint2 = OpReadClockKHR Device;
};
case glsl:
@leegao
leegao / unpack_gamblers_table.py
Created April 24, 2026 14:57
Unpacking gamblers-table.pck (reverse engineering)
import hashlib
import io
import os
import struct
from Crypto.Cipher import AES
def unpack_and_decrypt_pck(pck_path, hex_key):
key = bytes.fromhex(hex_key)
@leegao
leegao / fusion_5.txt
Created January 8, 2026 17:23
Annotated libtpu vliw dump for the operation: max(x[64,32] @ w[32,64], axis=1), Input in VMEM. Weights in HBM (need DMA
// Operation: max(x[64,32] @ w[32,64], axis=1), Input in VMEM. Weights in HBM (need DMA).
0x0 : { %v_const_neg_inf = vmov -inf // Init accumulator for Max reduction
;; %ptr_x_in = inlined_call_operand.vmem [shape: f32[64,32]] // operand 0: input x
;; %ptr_w_hbm = inlined_call_operand.hbm [shape: f32[32,64]] // operand 1: weights w (HBM)
;; %ptr_out_max = inlined_call_operand.vmem [shape: f32[64]] // operand 2: output
;; %ptr_out_full = inlined_call_operand.vmem [shape: f32[64,64]] // operand 3: scratch }
0x1 : { %6 = vst [vmem:[#allocation1] sm:$0xff] /*vst_source=*/%v_const_neg_inf } // for another kernel, #allocation1 is an addr of -\infty
// First Phase: get w out of HBM into vmem (the mxu and vpu can only use vmem)
@leegao
leegao / compute.py
Created January 8, 2026 04:32
VLIW dump of mini_attention (softmax(x @ w1) @ w2)
!rm -rf compiler_dump
!rm compiler_dump.zip
import os
# # Create dump directories
DUMP_ROOT = "compiler_dump/"
HLO_DUMP_PATH = os.path.join(DUMP_ROOT, "hlo")
LLO_DUMP_PATH = os.path.join(DUMP_ROOT, "llo")
@leegao
leegao / compute.py
Created January 8, 2026 04:11
TPU v5e softmax kernel
!rm -rf compiler_dump
!rm compiler_dump.zip
import os
# # Create dump directories
DUMP_ROOT = "compiler_dump/"
HLO_DUMP_PATH = os.path.join(DUMP_ROOT, "hlo")
LLO_DUMP_PATH = os.path.join(DUMP_ROOT, "llo")
@leegao
leegao / Gauss.md
Created January 4, 2026 17:29
Numerical sensitivity + floating point roundoff errors for a 2013 computational physics course

Suppose little Gauss lived in the modern age. Little Gauss’ teacher wanted to surf the internet, so he assigned all of his students the following integral to evaluate:

$$ \int_0^1 x^{100} e^{x-1} dx $$

Being the clever alter-ego of the boy who immediately saw $\sum^n_k k = {n+1 \choose 2}$, little Gauss constructed a sequence

$$ s_k = \int_0^1 x^k e^{x-1} dx $$

and with a little bit of clever manipulation (integration by parts), he found that, using $u_k = x^k$, $dv = e^{x-1}dx$, $v = e^{x-1}$

Caching ASTC Parameters to Disk

Intro

Here's a negative result around compressing and caching ASTC parameters to reduce transfer overhead.

Taking an Adreno 650 as our reference:

  1. GPU - 1.2 TFlops (1200 GFlops)
  2. CPU SIMD int8 - 18 GFlops
@leegao
leegao / dxvk 2.0 profile on Android
Created August 2, 2025 00:01
DXVK 2.0 Vulkan Requirements by Android drivers
[REQUIRED] depthBiasClamp / CORE10 (feature)
FL=9.0 - Required for D3D9 and D3D11. Allows clamping the depth bias value.
Qcom Turnip
+ unsupported (0/53): []
+ supported (53/53): ['23.0-26.708 (52/52)']
Qcom Proprietary
+ unsupported (0/163): []
+ supported (163/163): ['512.502-512.826 (162/162)']
Mali Proprietary
+ unsupported (0/67): []
@leegao
leegao / cmds.txt
Created July 21, 2025 13:14
ACC.exe spirv shader causing Mali G715 to fail CreateGraphicsPipeline
CreateFramebuffer
in: device: VkDevice (handle) = 0xb4000075a4e69010
in: pCreateInfo: VkFramebufferCreateInfo*
.flags: VkFramebufferCreateFlags = 0x0
.renderPass: VkRenderPass (handle) = 0xb400007454e8d0d0
.attachmentCount: uint32_t = 0x1
.pAttachments[0]: VkImageView* = 0xb40000746501b800
.width: uint32_t = 0x500
.height: uint32_t = 0x2d0
.layers: uint32_t = 0x1