Skip to content

Instantly share code, notes, and snippets.

View jumbojets's full-sized avatar

James jumbojets

View GitHub Profile
@jumbojets
jumbojets / autograd.ml
Last active April 28, 2024 18:42
proof of concept autograd implementation in ocaml
(* TODO: multicore and/or gpu computation would be fun *)
(* TODO: mnist sample *)
module Matrix = struct
module FA = Float.Array
type t = { data : FA.t; cols : int }
let make m n value =
let data = FA.make (m * n) value in
@jumbojets
jumbojets / tagless-final-const-generics.rs
Last active January 24, 2023 16:58
tagless final, const generics
trait Interp {
type Repr<const M: usize, const N: usize>;
fn lit<const M: usize, const N: usize>(mat: [[f32; N]; M]) -> Self::Repr<M, N>;
fn neg<const M: usize, const N: usize>(x: Self::Repr<M, N>) -> Self::Repr<M, N>;
fn avg<const M: usize, const N: usize>(x: Self::Repr<M, N>) -> Self::Repr<1, 1>;
fn add<const M: usize, const N: usize>(
l: Self::Repr<M, N>,
@jumbojets
jumbojets / tfhe-execution-context.rs
Last active February 17, 2023 23:34
tfhe-rs execution context example
use tfhe::shortint::{gen_keys, Parameters, context::{ExecutionContext, OperationFlavor}};
let (client_key, server_key) = gen_key(Parameters::default());
let msg1 = 1;
let msg2 = 0;
let ct_1 = client_key.encrypt(msg1);
let ct_2 = client_key.encrypt(msg2);
type Fun<D, C> = Box<dyn Fn(D) -> C>;
trait Form {
type Repr<T>;
fn lam<A, B>(f: Fun<Self::Repr<A>, Self::Repr<B>>) -> Self::Repr<Fun<A, B>>;
fn appl<A, B>(f: Self::Repr<Fun<A, B>>, x: Self::Repr<A>) -> Self::Repr<B>;
}
@jumbojets
jumbojets / O1.s
Created December 29, 2023 16:39
optimization levels can change program output
.arch armv8-a
.text
.cstring
.align 3
lC0:
.ascii "%f\0"
.align 3
lC1:
.ascii "%f\12\0"
.section __TEXT,__text_startup,regular,pure_instructions
@jumbojets
jumbojets / jit.py
Last active November 2, 2024 02:57
# modifies following code to work on macos
# https://eli.thegreenplace.net/2017/adventures-in-jit-compilation-part-4-in-python/
# interesting: https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon?language=objc
import ctypes, mmap as mmap_flags
libc = ctypes.cdll.LoadLibrary(None)
mmap = libc.mmap
mmap.restype = ctypes.c_void_p