Skip to content

Instantly share code, notes, and snippets.

@xinyazhang
xinyazhang / 256-grayvim.lua
Created January 15, 2026 10:17
256-grayvim.lua
-- Neovim color file
-- Port of: 256-grayvim
-- Clear highlights and set basic options
vim.cmd("highlight clear")
if vim.fn.exists("syntax_on") then
vim.cmd("syntax reset")
end
vim.o.background = "dark"
@xinyazhang
xinyazhang / sdpa.py
Created November 5, 2024 21:43
A modifed version of PyTorch's SDPA.py benchmark
import itertools
from collections import defaultdict
from contextlib import nullcontext
from dataclasses import asdict, dataclass
from typing import Callable, List, Tuple
from tabulate import tabulate
from tqdm import tqdm
import torch
@xinyazhang
xinyazhang / with sdpa_kernel.py
Created November 4, 2024 17:34
PyTorch SDPA kernel selection
import contextlib
from torch.nn.functional import scaled_dot_product_attention
from torch.nn.attention import sdpa_kernel, SDPBackend
ctxmgr = contextlib.nullcontext()
# ctxmgr = sdpa_kernel(backends=[SDPBackend.EFFICIENT_ATTENTION])
# ctxmgr = sdpa_kernel(backends=[SDPBackend.FLASH_ATTENTION])
# ctxmgr = sdpa_kernel(backends=[SDPBackend.MATH])
# ctxmgr = sdpa_kernel(backends=[SDPBackend.CUDNN_ATTENTION])
@xinyazhang
xinyazhang / conf-gcc.sh
Created May 6, 2021 22:05
Compile GCC-8 From Source for Matlab 2020B
# Install to /opt/gcc-8
# Do NOT install to /usr/local, because of libstdc++.so.6 naming conflict.
# Your system's compiler are likely incompatible with it.
# There is also no "library-suffix" option. So simply don't install it there.
# Optionally you can add --program-suffix=-8 but this creates quite a few troubles for Matlab to detect GCC.
../gcc-8.4.0/configure --prefix=/opt/gcc-8 --enable-bootstrap --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --build=x86_64-redhat-linux --disable-multilib
# Important. Run this in your shell before "make", otherwise there will be various weird erros.
# Don't know why gcc don't make this default.
@xinyazhang
xinyazhang / pwait.sh
Created January 20, 2021 05:48
Wait for the process of given pid to terminate
#!/bin/bash
tail --pid=$1 -f /dev/null
@xinyazhang
xinyazhang / hamming_c++tmp.cc
Created December 7, 2020 18:42
Hamming Number, C++ Template Metaprogramming
/*
hamming.cpp: a C++ version for calculating hamming numbers, aka regular numbers,
aka ugly numbers, in compile time (using template meta programming).
Copyright (C) 2008 Daniel Gutson
hamming.cpp is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
@xinyazhang
xinyazhang / npz_head.py
Last active May 27, 2021 06:37
Show What are Stored in an .NPZ File
#!/usr/bin/env python3
'''
Copyright © 2020, 2021 Xinya Zhang <xinyazhang@utexas.edu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@xinyazhang
xinyazhang / cli_starter.py
Created October 10, 2020 02:23
Python CLI Tool Starter Code
#!/usr/bin/env python3
import argparse
def parse():
p = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
p.add_argument('example', help='Example usage of parser', type=float, default=0.0)
args = p.parse_args()
# print(args)
return args
@xinyazhang
xinyazhang / f32-screen-share-build-obs.sh
Last active June 10, 2020 01:45
Zoom/Skype ScreenSharing on Fedora 32
#!/bin/bash
# Zoom's Screen Sharing is tricky because
# 1. I'd rather run it (or, any properity software) in containerized
# environment (i.e., flatpak on Fedora 32), so big NO to the official rpm
# 2. I have switched to Gnome Wayland recently and no intention to switch back
# to X11, due to a few reasons like Firefox looks better on Gnome Wayland.
# 3. RPMFusion's OBS is broken on my system for whatever reason.
# After searching on the Internet and github for a while I found and tested the following solutions.
@xinyazhang
xinyazhang / test_tf.sh
Last active December 4, 2019 23:01
Test successful installation of Tensorflow in One Line (Python3)
python3 -c 'import tensorflow as tf; c = tf.constant("Testing"); sess = tf.Session(); print(sess.run(c)); print(tf.test.gpu_device_name())'