Skip to content

Instantly share code, notes, and snippets.

View knwng's full-sized avatar
🐱

Kyle Wang knwng

🐱
  • Mountain View, CA
  • 10:38 (UTC -07:00)
View GitHub Profile
@knwng
knwng / parse_moe_kernel_perf.py
Created July 23, 2025 19:31
A script to parse the perf data generated from OpenAI's open-sourced MoE Triton kernel and draw roofline graphs in one graph. Usage: python3 parse_moe_kernel_perf.py -m log_metadata.json -o output.png -d fp8mx4
from pathlib import Path
import matplotlib.pyplot as plt
import triton.profiler as proton
from triton.profiler import viewer
import torch
from triton_kernels.target_info import get_cdna_version
from dataclasses import dataclass
import argparse
import json
import torch
import triton
import triton.language as tl
DEVICE = triton.runtime.driver.active.get_active_torch_device()
# This kernel is a trimmed version of triton/python/tutorials/03-matrix-multiplication.py
@triton.jit
def matmul_kernel(
@knwng
knwng / triton_hack.py
Last active August 19, 2025 07:36
Usage: export AMD_INSERT_TTGIR/AMD_INSERT_LLVM_IR/AMD_INSERT_AMDGCN="<kernel_name>:<filename>"
# At the end of make_ttgir, e.g., https://github.com/triton-lang/triton/blob/6ca2dda9bdd331d007d6fab342db5a85f9b23c7d/third_party/amd/backend/compiler.py#L258
import os
if "AMD_INSERT_TTGIR" in os.environ.keys():
fn = os.environ['AMD_INSERT_TTGIR']
if ':' in fn:
kernel_name, insert_module_path = fn.split(':')
print(f"Replace kernel {kernel_name}'s ttgir with {insert_module_path}")
if not mod.has_function(kernel_name):
return mod
else:
import triton
import triton.language as tl
import triton.compiler as tc
from triton.backends.compiler import GPUTarget
@triton.jit
def type_convert_triton(src, dst, rounding : tl.constexpr, BLOCK_SIZE : tl.constexpr):
idxs = tl.program_id(0) * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
x = tl.load(src + idxs)
@knwng
knwng / .tcshrc
Created November 13, 2024 21:24
Switch from tcsh to zsh without sudo
setenv SHELL /usr/bin/zsh
exec /usr/bin/zsh -l
@knwng
knwng / cpp.json
Created November 12, 2024 00:21
VSCode Cpp Snippets
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@knwng
knwng / bash.code-snippets
Created November 12, 2024 00:21
VSCode Bash Snippets
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
@knwng
knwng / python.json
Created November 12, 2024 00:20
VSCode Python Snippets
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@knwng
knwng / config.toml
Created November 5, 2024 21:03
Atuin config file. Put it in ~/.config/atuin/config.toml
filter_mode = "host"
filter_mode_shell_up_key_binding = "session"
@knwng
knwng / .wezterm.lua
Last active March 15, 2025 15:47
My Wez Term config for windows
local wezterm = require 'wezterm'
local act = wezterm.action
local config = {}
if wezterm.config_builder then
config = wezterm.config_builder()
end
config.color_scheme = 'Bamboo'