Skip to content

Instantly share code, notes, and snippets.

View staticfloat's full-sized avatar

Elliot Saba staticfloat

View GitHub Profile
using BinaryProvider # requires BinaryProvider 0.3.0 or later
# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
products = [
LibraryProduct(prefix, ["libfftw3"], :libfftw3),
LibraryProduct(prefix, ["libfftw3f"], :libfftw3f),
]
using BinaryProvider # requires BinaryProvider 0.3.0 or later
# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
products = [
LibraryProduct(["libfftw3"], :libfftw3),
LibraryProduct(["libfftw3f"], :libfftw3f),
]
$ strace -e trace=stat,lstat,open,close julia
open("/home/sabae/local/dist/julia-release-1.2/bin/../lib/tls/x86_64/libjulia.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/sabae/local/dist/julia-release-1.2/bin/../lib/tls/x86_64", 0x7ffc823f5290) = -1 ENOENT (No such file or directory)
open("/home/sabae/local/dist/julia-release-1.2/bin/../lib/tls/libjulia.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/sabae/local/dist/julia-release-1.2/bin/../lib/tls", 0x7ffc823f5290) = -1 ENOENT (No such file or directory)
open("/home/sabae/local/dist/julia-release-1.2/bin/../lib/x86_64/libjulia.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/sabae/local/dist/julia-release-1.2/bin/../lib/x86_64", 0x7ffc823f5290) = -1 ENOENT (No such file or directory)
open("/home/sabae/local/dist/julia-release-1.2/bin/../lib/libjulia.so.1", O_RDONLY|O_CLOEXEC) = 3
close(3) = 0
open("/home/sabae/local/dist/julia-release
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@staticfloat
staticfloat / softmax.jl
Created May 29, 2019 20:49
Threading speed test
using Base.Threads
function softmax!(out::AbstractVecOrMat{T}, xs::AbstractVecOrMat{T}) where {T}
# Remove `@threads` for non-threading timing
@inbounds @threads for j = 1:size(xs, 2)
# First, store column-wise maximum in the last element of `out`
out[end, j] = xs[end, j]
@inbounds for i = 1:(size(xs, 1) - 1)
out[end, j] = max(out[end, j], xs[i, j])
end
@staticfloat
staticfloat / github_remote
Last active April 13, 2019 00:23
github_remote
#!/usr/bin/env bash
## Helper script to turn an `https://` clone of a github repository into something that you
## can push from. Supports both invocation as `github_remote`, as well as with an optional
## username, to add a particular user's fork as a remote, e.g. `github_remote avik-pal`.
ORIGIN_URL=$(git remote get-url origin 2>/dev/null)
if [[ -z "${ORIGIN_URL}" ]]; then
echo "ERROR: No origin remote?!"
exit 1
struct CachedConv
conv::Conv
cache::Ref{Tuple}
end
CachedConv(c::Conv) = CachedConv(c, ())
Flux.@treelike CachedConv
function (m::CachedConv)(x::AbstractArray)
# Has the user changed batch size on us? If so, clear our cache and re-up!
if !isempty(m.cache[]) && size(m.cache[][2], 4) != size(x, 4)
@staticfloat
staticfloat / zygote_batch_norm.jl
Last active April 11, 2019 04:01
Zygote BatchNorm implementation
using Zygote, Statistics, Flux
# We modify (the implementation of) batchnorm to be more ammenable to CPUs pretending to be TPUs.
struct ZygoteBatchNorm{F,V,W}
λ::F # activation function
β::V # bias
γ::V # scale
μ::W # moving mean
σ::W # moving std
ϵ::Float32
@staticfloat
staticfloat / fix_nvidia
Created March 8, 2019 23:47
Fixer script for NVidia driver installs on dkms-compatible systems
#!/usr/bin/env bash
function red_echo()
{
tput setaf 1
echo "$*"
tput sgr0
}
if [[ "$*" == *--help* ]]; then
using NNlib, BenchmarkTools, JLD2
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 1.0
results = Dict()
idx = 0
total_trials = 2*2*2*2*2*2*2
# Note; this only works if you've run this with --project={old,new}
version = basename(unsafe_string(Base.JLOptions().project))