Skip to content

Instantly share code, notes, and snippets.

@jhaberstro
jhaberstro / gpu_arch_resources
Last active October 26, 2023 00:14
GPU Architecture Learning Resources
http://courses.cms.caltech.edu/cs179/
http://www.amd.com/Documents/GCN_Architecture_whitepaper.pdf
https://community.arm.com/graphics/b/blog
http://cdn.imgtec.com/sdk-documentation/PowerVR+Hardware.Architecture+Overview+for+Developers.pdf
http://cdn.imgtec.com/sdk-documentation/PowerVR+Series5.Architecture+Guide+for+Developers.pdf
https://www.imgtec.com/blog/a-look-at-the-powervr-graphics-architecture-tile-based-rendering/
https://www.imgtec.com/blog/the-dr-in-tbdr-deferred-rendering-in-rogue/
http://developer.amd.com/tools-and-sdks/opencl-zone/amd-accelerated-parallel-processing-app-sdk/opencl-optimization-guide/#50401334_pgfId-412605
https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/
https://community.arm.com/graphics/b/documents/posts/moving-mobile-graphics#siggraph2015
@jhaberstro
jhaberstro / parser_combinator.cpp
Created May 20, 2014 23:00
The beginnings of a C++ parser combinator library
#include <algorithm>
#include <iostream>
#include <iterator>
#include <functional>
#include <tuple>
#include <type_traits>
#include <vector>
template< typename T >
using ParseResult = std::vector<std::tuple<T, std::string>>;
@jhaberstro
jhaberstro / ScopeStackDemo.cpp
Created November 5, 2010 22:00
ScopeStack implementation stolen from Andreas Fredriksson's DICE presentation on Scope Stack Allocation.
// Simplified scope stack implementation
#include <new>
#include <cstdio>
#include <cassert>
typedef unsigned char u8;
class LinearAllocator {
public:
@jhaberstro
jhaberstro / spinlock.cpp
Created April 15, 2016 08:34
C++11 recursive spinlock
// spinlock.h
#include <thread>
class Mutex
{
public:
Mutex();
Mutex(Mutex const&) = delete;
@jhaberstro
jhaberstro / hkt.cpp
Last active September 25, 2020 12:28
Functor, Maybe, and Higher-Kinded Types in C++
// Example program
#include <iostream>
#include <string>
#include <vector>
#include <type_traits>
//---------------------
// Maybe and MyVector, two totally unrelated classes whose only commanilty is that they are both type constructors of the same arity (e.g. 1) and order (e.g. 1).
//---------------------
template< typename T >
@jhaberstro
jhaberstro / unfair-casino-hmm.js
Created January 25, 2019 07:33
WebPPL Hidden Markov Model Inference
/*
Dealer repeatedly flips a coin. Sometimes the coin is fair, with P(heads) = 0.5,
sometimes it’s loaded, with P(heads) = 0.8. Dealer occasionally switches coins,
invisibly to you. Given an list of observed coin flips, infer if the coin was
fair for each individual flip.
*/
var hmm = function(n, initial, transitionf, observef) {
var impl = function(N) {
if (N > 1) {
@jhaberstro
jhaberstro / linear_algebra_notes.md
Created September 29, 2015 00:23
Notes for MIT's "Linear Algebra 18.06"
Linear Algebra 18.06 notes

=============================

  • Lecture 1: The Geometry of Linear Equations
    • The matrix A (whose columns are u, v, w) times the column vector x (whose components are c, d, e) is the same as the combination cu + dv + ew of the three columns.
  • Lecture 2: Elimination with Matrices
    • Elimination works by creating a triangular matrix, which for a system of 3 equations and three variables gives us a new system of 3 equations that has one equation with only one variable, another with two variables, and the last with three variables. This system can then be easily solved.
  • Lecture 3: Multiplication and Inverse Matrices
    • When multiply matrices, A*B=C, the element in the i-th row and j-th column of the resultant matrix, C, is calculated by taking the dot product of the i-th row of A with the j-th column of B.
  • Another way to view matrix multiplication: in A*B=C, each column of C is a linear combination of the columns of A. e.g.
@jhaberstro
jhaberstro / optical_flow_horn_schunk.py
Last active January 10, 2018 05:52
Horn-Schunck Dense Optical Flow
import numpy as np
from skimage import filters
from scipy.sparse import csc_matrix
from scipy.sparse.linalg import spsolve
def optical_flow_hs(t0, t1, alpha):
h, w = t0.shape[:2]
gradients = np.gradient(t0)
dx, dy = gradients[1], gradients[0]
dt = t1 - t0
@jhaberstro
jhaberstro / optical_flow_lucas_kanade.py
Last active January 9, 2018 04:30
Lucas-Kanade Dense Optical Flow
import numpy as np
from skimage import filters
def optical_flow_lk(t0, t1, sigma):
# setup the local linear systems of equations
gradients = np.gradient(t0)
dx, dy = gradients[1], gradients[0]
dt = t1 - t0
A00 = filters.gaussian(dx * dx, sigma)
A11 = filters.gaussian(dy * dy, sigma)