Skip to content

Instantly share code, notes, and snippets.

View mkolod's full-sized avatar

Marek Kolodziej mkolod

  • San Francisco Bay Area, CA
View GitHub Profile
@mkolod
mkolod / dft_idft.ipynb
Created July 7, 2021 02:31
DFT / IDFT
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mkolod
mkolod / parallel_reservoir_sampling_equivalent.ipynb
Created June 9, 2021 16:59
Parallel Reservoir Sampling Equivalent
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mkolod
mkolod / disjoint_set_forest.py
Last active January 7, 2021 05:24
Disjoint Set Forest
class DisjointForest:
class Subset:
def __init__(self, elem, parent=None, rank=0):
self.elem = elem
self.parent = parent
self.rank = rank
def __repr__(self):
#include <chrono>
#include <cmath>
#include <future>
#include <iostream>
#include <memory>
#include <mutex>
#include <thread>
template<typename Ret, typename Fun, typename Arg>
class ReusableWorkerThreadWithFuture {
# NOTE: The network here is not means to make any sense. It's just for measuring perf impact.
import torch
import torch.nn.functional as F
from time import time
class Net(torch.nn.Module):
def __init__(self):
super(Net, self).__init__()
fcs = [torch.nn.Linear(10, 100)] + [torch.nn.Linear(100, 100) for _ in range(20)]
self.fcs = torch.nn.Sequential(*fcs)
#include <stdio.h>
#include <thread>
#include <chrono>
#include <iostream>
const int N = 1 << 20;
__global__ void kernel(float *x, int n)
{
int tid = threadIdx.x + blockIdx.x * blockDim.x;
#include <chrono>
#include <iostream>
#include <vector>
#include <thread>
__global__ void do_nothing(int time_us, int clock_rate) {
clock_t start = clock64();
clock_t end;
for (;;) {
end = clock64();
@mkolod
mkolod / redirect_streams_and_cuda_checks.cu
Last active September 27, 2020 04:12
Redirect Streams and CUDA checks
#include <csignal>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <limits.h>
#include <iostream>
#include <sstream>
#include <stdexcept>

ImageNet validation set fix:

  1. The training set is organized in directories, with each directory matching a class, e.g. "n01751748" matching "sea snake." However, the valset is a flat dir of JPEGs. The ImageNet labels provided in the devkit for the validation set (ILSVRC2012_validation_ground_truth.txt) are not consistent with the ordering used by PyTorch/TF/Keras/MXNet/Caffe, etc. for pre-trained models. For example, in the the above ground truth label file, "sea snake" is 490, but in PyTorch/TF, it's 65.
    Proof:
  2. Untar the valset file, you will get a flat dir of JPEGs.
  3. Pull in the unflattening script into the directory where the val images were unpa