Skip to content

Instantly share code, notes, and snippets.

View bwasti's full-sized avatar

Bram Wasti bwasti

View GitHub Profile
@bwasti
bwasti / run.py
Created September 12, 2022 13:50
import os
for cmd in ["add", "mm"]:
print(cmd)
for n in range(0, 14):
N = 2**n
best_cpu = 0
best_cuda = 0
for thread in [1, 2, 4, 8, 16, 32, 64, 80]:
full_cmd = f"OMP_NUM_THREADS={thread} python comp.py {cmd} {N}"
import torch
import time
import sys
fn = sys.argv[1]
N = int(sys.argv[2])
iters = 1000
mps = torch.device("mps")
a = torch.randn(N, N)
#include <cstdint>
extern "C" {
void init() {}
int64_t bytesUsed() {
return 0;
}
//
// Metal.hpp
//
// Autogenerated on September 04, 2022.
//
// Copyright 2020-2021 Apple Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

About

metal-cpp is a low overhead and header only C++ interface for Metal that helps developers add Metal functionality to graphics applications that are written in C++ (such as game engines). metal-cpp removes the need to create a shim and allows developers to call Metal functions directly from anywhere in their existing C++ code.

Highlights

  • Drop in C++ alternative interface to the Metal Objective-C headers.
  • Direct mapping of all Metal Objective-C classes, constants and enums to C++ in the MTL C++ namespace.
  • No measurable overhead compared to calling Metal Objective-C headers, due to inlining of C++ function calls.
import * as sm from '@shumai/shumai'
class EvalTuner {
constructor() {
this.best_delta = 1
this.best_time = Infinity
this.last_i = 0
}
calculate_better_delta(time_spent) {
// g++ bleh.cc --shared -o bleh.so -I$HOME/code/bun/src/napi -Wl,-undefined,dynamic_lookup
//
#include "node_api.h"
#include <iostream>
int a;
void *create() {
return (void*)&a;
std::cerr << "CREATING!\n";
}
// g++ ptr_test.cc --shared -o ptr_test.so
#include <cstdint>
static uint32_t g_p = 0;
extern "C" {
void* gen_ptr() {
return (void*)&g_p;
}
import fs from "node:fs"
import readline from "node:readline"
const t0 = performance.now()
const stream = fs.createReadStream("input.txt")
const rl = readline.createInterface({
input: stream,
crlfDelay: Infinity
})
@bwasti
bwasti / readlines.js
Created August 15, 2022 14:31
Fast line reading in bun
async function readlines(stream, callback, buffer_len = 16) {
const reader = stream.getReader()
const td = new TextDecoder('ascii')
let overflow = null
let buffer = []
function flush_buffer() {
for (let b of buffer) {
callback(td.decode(b))
}