Skip to content

Instantly share code, notes, and snippets.

View bryancatanzaro's full-sized avatar

Bryan Catanzaro bryancatanzaro

View GitHub Profile
@bryancatanzaro
bryancatanzaro / gist:3146033
Created July 19, 2012 19:03
Simple sequential thrust program
//Define the system to be OpenMP to remove all CUDA references
#define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_OMP
#include <thrust/host_vector.h>
#include <thrust/fill.h>
#include <thrust/reduce.h>
#include <iostream>
template<typename T>
struct my_reduction {
typedef T result_type;
@bryancatanzaro
bryancatanzaro / thrust_demo.py
Created May 22, 2012 22:42
PyCUDA/Thrust interop
import pycuda
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np
from codepy.cgen import *
from codepy.bpl import BoostPythonModule
from codepy.cuda import CudaModule
#Make a host_module, compiled for CPU
template<typename T>
struct get_optional_visit {
template<typename U>
std::optional<T> operator()(U) const {
return std::optional<T>();
}
std::optional<T> operator()(const T& t) const {
return std::optional<T>(t);
}
@bryancatanzaro
bryancatanzaro / apply_tuple_to_function.cpp
Last active March 4, 2016 04:31
Call a function by expanding a tuple as its arguments.
#include <iostream>
#include <tuple>
/******************
* Implementation *
******************/
//If you're using C++14, just use std::integer_sequence
//instead of all this index_seq stuff
template<unsigned... Indices>
@bryancatanzaro
bryancatanzaro / count.py
Last active December 29, 2015 01:49
A simple script for counting recurring sentences.
import sys
import re
import operator
if __name__ == '__main__':
filename = sys.argv[1]
f = open(filename, 'r')
sentences = {}
current_sentence = ''
@bryancatanzaro
bryancatanzaro / test.cu
Created July 20, 2012 17:35
Using uniform_sequence
#include <iostream>
#include <prelude/sequences/uniform_sequence.h>
#include <prelude/runtime/tags.h>
#include <thrust/host_vector.h>
#include <thrust/copy.h>
#include <thrust/iterator/counting_iterator.h>
typedef copperhead::cpp_tag Tag;
@bryancatanzaro
bryancatanzaro / log_linear.cpp
Created June 28, 2015 04:58
Log linear spacing
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <cmath>
std::vector<float> make_log_linear(size_t n,
int linear,
int subbin) {
std::vector<float> result;