Skip to content

Instantly share code, notes, and snippets.

View haampie's full-sized avatar

Harmen Stoppels haampie

View GitHub Profile
@haampie
haampie / givens.jl
Created May 10, 2020 19:10
givens.jl
using SIMD
using BenchmarkTools
using Test
struct Rot{T}
c::T
s::T
end
mul(G::Rot, a, b) = (G.c * a + G.s * b, -G.s * a + G.c * b)
@haampie
haampie / sort_cache_by.jl
Created April 14, 2020 11:05
sort_cache_by.jl
import Base: getindex, setindex, length, isless
struct SortPair{A,B}
x::A
mapped::B
end
struct SortCache{A,B,AV,BV} <: AbstractVector{SortPair{A,B}}
xs::AV
mapped::BV
@haampie
haampie / unet.jl
Created January 30, 2020 15:43
unet.jl
function concat_and_crop(mx::AbstractArray{T,4}, x::AbstractArray{T,4}) where T
w, h = size(x)
mw, mh = size(mx)
rx = (1:mw) .+ ((w - mw) ÷ 2)
ry = (1:mh) .+ ((h - mh) ÷ 2)
return cat(x[rx, ry, :, :], mx, dims = 3)
end
create_model_2d_classes() = Chain(
BatchNorm(1),
@haampie
haampie / Dockerfile
Created January 24, 2020 10:16
Build some Qt modules with AddressSanitizer
FROM ubuntu:18.04 AS builder
SHELL ["/bin/bash", "-c"]
WORKDIR /development
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
curl \
file \
@haampie
haampie / PrimeMonstrosity.jl
Created December 18, 2019 17:32
prime-monstrosity.jl
module PrimeMonstrosity
const bit_1 = ~(0x01 << 7)
const bit_2 = ~(0x01 << 6)
const bit_3 = ~(0x01 << 5)
const bit_4 = ~(0x01 << 4)
const bit_5 = ~(0x01 << 3)
const bit_6 = ~(0x01 << 2)
const bit_7 = ~(0x01 << 1)
const bit_8 = ~(0x01 << 0)
@haampie
haampie / trace.txt
Last active August 29, 2019 08:42
btmon trace
Bluetooth monitor ver 5.50
= Note: Linux version 5.0.0-25-generic (x86_64) 0.401834
= Note: Bluetooth subsystem version 2.22 0.401835
= New Index: 80:C5:F2:F8:D6:54 (Primary,USB,hci0) [hci0] 0.401836
@ MGMT Open: btmon (privileged) version 1.14 {0x0001} 0.401851
= bluetoothd: Bluetooth daemon 5.50 3.341004
@ MGMT Open: bluetoothd (privileged) version 1.14 {0x0002} 3.342105
= bluetoothd: Starting SDP server 3.342212
= bluetoothd: Excluding (cli) wiimote 3.342323
@ MGMT Command: Read Management Version In.. (0x0001) plen 0 {0x0002} 3.343725
@haampie
haampie / testing.cpp
Last active March 15, 2019 21:42
everything_compile_time.cpp
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
using namespace std;
// Some instances of events; we're using "public" const data members.
struct UsernameChanged {
string const username;
@haampie
haampie / cerfacs.cu
Created December 3, 2018 16:30
cerfacs.cu
// Computes y <- alpha * A * x + beta * y for tall and skinny A.
// Compile with `nvcc -O3 -o cerfacs cerfacs.cu`
// Assumes we have a *large* basis of COLS = 100 columns, you can play with this param
// Timing is measured without copies from / to device (copies should not happen in a good impl of arnoldi anyways)
// Assumes a fixed number of 256 threads per block.
#include <stdio.h>
#include <sys/time.h>
#define COLS 100
@haampie
haampie / spmvbench.jl
Created October 6, 2018 17:35
spmvbench.jl
"""
This is the implementation currently in SparseArrays
"""
function simple_mul!(y, A, x)
@inbounds for i = Base.OneTo(A.n)
xi = x[i]
for j = A.colptr[i] : A.colptr[i + 1] - 1
y[A.rowval[j]] += A.nzval[j] * xi
end
@haampie
haampie / micro.cc
Created September 27, 2018 14:25
cpp_vs_julia
#include <cstdint>
#include <cmath>
// g++ -Wall -O3 -std=c++14 -march=native -fPIC -shared -o givenlib.so micro.cc
extern "C" {
void fused_horizontal(double * __restrict__ A, int64_t cols, double c1, double s1, double c2, double s2, double c3, double s3, double c4, double s4)
{
for (int64_t col = 0; col < cols; ++col, A += 4)
{