This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 |