Skip to content

Instantly share code, notes, and snippets.

@JonathanRaiman
JonathanRaiman / openmp.cpp
Created October 18, 2016 04:45
Cute openmp timing tests
// clang++ openmp.cpp -o openmp -fopenmp -O3 -std=c+11
#include <cassert>
#include <stdlib.h>
#include <cmath>
#include <omp.h>
#include <iostream>
template<typename T>
struct Vector {
@JonathanRaiman
JonathanRaiman / array.h
Created September 3, 2016 23:36
Runtime Compilation of CUDA kernels
#ifndef RTC_ARRAY_H
#define RTC_ARRAY_H
#include <vector>
#include <string>
#include <memory>
#include <sstream>
#include <iostream>
#define XINLINE __device__ __host__
@JonathanRaiman
JonathanRaiman / gemm_parallel.cpp
Created July 20, 2016 17:32
Explicit and implicit BLAS gemm parallelism.
/*
Comparing explicit BLAS parallelism using a thread pool
with vendor-implemented parallelism.
Program prints the runtime averaged over 100 runs of a matrix
multiply between two float matrices.
To run:
./gemm_parallel [<int> USE_EXPLICIT_PARALELLISM 0/1] [<int> LEADING_DIMENSION]
@JonathanRaiman
JonathanRaiman / awesome_scan.py
Created July 11, 2016 18:50
Scan multi arg in tensorflow
def listify(x):
if isinstance(x, tuple):
return list(x)
return x
def awesome_scan(fn, elems, initializer=None, parallel_iterations=10, back_prop=True,
swap_memory=False, name=None):
"""scan on the list of tensors unpacked from `elems` on dimension 0.
This scan operator repeatedly applies the callable `fn` to a sequence
of elements from first to last. The elements are made of the tensors
@JonathanRaiman
JonathanRaiman / array.cu
Created July 8, 2016 07:43
CUDA / CPU one file Array library
#include <vector>
#include <string>
#include <memory>
#include <sstream>
#include <iostream>
#define XINLINE __device__ __host__
#define MAX_DIM 10
#define INDENT_INCREMENT 2
@JonathanRaiman
JonathanRaiman / some_file.cu
Created April 23, 2016 21:17
Get reduction over all dimensions to work in mshadow
/*
Reduction over all dimensions in mshadow. Requires changing the structs in
mshadow expression to store their input expressions by value instead of
reference.
Installation:
nvcc some_file.cu -std=c++11 -O3 -w -o some_file -I /usr/local/include
Usage:
@JonathanRaiman
JonathanRaiman / mshadow_eigen.h
Last active August 29, 2015 14:24
Mshadow using Eigen's dot product engine
#ifndef DALI_MATH_MSHADOW_EIGEN_DOT_H
#define DALI_MATH_MSHADOW_EIGEN_DOT_H
#if MSHADOW_USE_EIGEN_DOT
#include <Eigen/Eigen>
#include <mshadow/tensor.h>
#include <cblas.h>
// Eigen Backend for Dot-Product in Mshadow
// Causes Adagrad to be slower.
@JonathanRaiman
JonathanRaiman / install_python3.sh
Last active August 29, 2015 14:16
Dot Installation of Python on OS X
#!/bin/bash
# stop script on error and print it
set -e
# inform me of undefined variables
set -u
# handle cascading failures well
set -o pipefail
# install homebrew
@JonathanRaiman
JonathanRaiman / Lattice_Learning.py
Last active August 29, 2015 14:13
Lattice Learning
import matplotlib.pyplot as plt
import theano, theano.tensor as T, numpy as np
import theano_lstm
import os
from collections import Counter
to_softmax = lambda x: T.nnet.softmax(x)[0] if x.ndim == 1 else T.nnet.softmax(x.T).T
class LatticeModel(object):
def __init__(self,
word_size,
@JonathanRaiman
JonathanRaiman / sqlite + pickle
Created December 23, 2014 01:13
Python pickling of objects into sqlite db
import sqlite3
import pickle
protocol = 0
sqlite3.register_converter("pickle", pickle.loads)
sqlite3.register_adapter(list, pickle.dumps)
sqlite3.register_adapter(set, pickle.dumps)