Skip to content

Instantly share code, notes, and snippets.

View louchenyao's full-sized avatar

Chenyao Lou louchenyao

View GitHub Profile
@louchenyao
louchenyao / two_or_three.cpp
Created January 7, 2021 04:10
two_or_three.cpp
// clang++ two_or_three.cpp -O3 --std=c++17
// results:
// two : 130.3 ns
// two+ : 131.0 ns
// three: 133.2 ns
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// This is a C++ CUDA port of the Zipf Distribution generator from https://github.com/jonhoo/rust-zipf/blob/master/src/lib.rs, written in Rust.
#include <cassert>
#include <cstdio>
#include <cmath>
#include <curand_kernel.h>
namespace Zipf {
struct ZipfDist {
#include <cassert>
#include <cstdio>
#include <cmath>
#include <random>
int zipf(double alpha, int n, std::mt19937_64 &rng)
{
static bool first = true; // Static first time flag
static double c = 0; // Normalization constant
static double *sum_probs; // Pre-calculated sum of probabilities
#include <algorithm>
#include <cstdio>
#include <cstdlib>
template <typename T>
void cmp(T &a, T &b) {
if (a > b) {
std::swap(a, b);
}
}
CREATE TABLE date_ (
d_datekey INTEGER,
d_date TEXT ENCODING DICT(32),
d_dayofweek TEXT ENCODING DICT(8),
d_month TEXT ENCODING DICT(8),
d_year SMALLINT,
d_yearmonthnum INTEGER,
d_yearmonth TEXT ENCODING DICT(16),
d_daynuminweek SMALLINT,
d_daynuminmonth SMALLINT,
@louchenyao
louchenyao / bench_seq.cu
Last active July 31, 2020 01:49
Benchmark of GPU sequential read performance
// nvcc bench_seq.cu -O3 -gencode arch=compute_70,code=sm_70
// Result on V100:
// bench_seq max throughput: 769.856 GiB/s
// bench_seq_unroll max throughput: 833.067 GiB/s
#include <iostream>
__device__
int64_t reduce(int64_t *buf, uint64_t s) {
// The more effecient way is to reduce within the wrap firstly, but it's not the bottleneck
#! /usr/bin/env python3
import sys
# if the dns server of the wireguard are showed in the resolve.conf, then we skim off other servers to make sure the wireguard has the highest priority.
with open("/etc/resolv.conf") as f:
old_resolv = f.read()
if "10.56.100.1" in old_resolv:
with open("/etc/resolv.conf", "w") as f:
f.write("# generated by /etc/NetworkManager/dispatcher.d/refresh_dns.py\nnameserver 10.56.100.1\n")
#cloud-config
users:
- name: louchenyao
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCudAF5jQCs+HTk9ST93yyhXNUFtxldah+D9gU7xSKXW4c6xC1ZuVHZuBvrorArDUbXwByrB/bnjC8fQy4VH0JaS3qfjofroXnLWwHqQS4RC6N1H20EYm5+fsMu0GzzbgoCJOO99QT85UghN661iPzLd7gCdc96O/AiYmDliBlsYCMVblcHkD2D9VTzeKYKmCDjl4d1kjMBdK4H8xbzpbvrhRO5Xtexm+D5foH/elB7aB3CtoCSaHl+GHFOQWidI9MIwVNlYj0i+97fYbhk0V0dir3DuIaHHy5h2PCm0ruoeESKp2e0UirEH8NwkHS/dbiC4UlrAvSHFetSJdfEabMl louchenyao
runcmd:
@louchenyao
louchenyao / ifstat_influx.py
Created December 27, 2018 14:36
ifstat_influx.py
#!/usr/bin/env python3
import subprocess
delay = 4
def ifstat():
result = subprocess.check_output(["ifstat", str(delay), "1"]).decode()
lines = result.splitlines()
devs = lines[0].split()
#! /usr/bin/env python3
import requests
import subprocess
import time
USER = "USERNAME"
MD5 = "YOUR_PASSOWRD_MD5" # echo -n "password" | md5
AUTH4 = "https://auth4.tsinghua.edu.cn/do_login.php?action=login&username=%s&password={MD5_HEX}%s&ac_id=1" % (USER, MD5)