Skip to content

Instantly share code, notes, and snippets.

View athas's full-sized avatar
🐈
how did this get here i am not good with compute

Troels Henriksen athas

🐈
how did this get here i am not good with compute
View GitHub Profile
-- binary literals
1 + 0b101
-- Attributes
#[unsafe] x + y
static inline int smin32(int x, int y)
{
return x < y ? x : y;
}
static inline int sdiv_up32(int x, int y)
{
return (x + y - 1) / y;
}
#define CL_TARGET_OPENCL_VERSION 120
#include <CL/cl.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
static void* slurp_file(const char *filename) {
unsigned char *s;
FILE *f = fopen(filename, "rb"); // To avoid Windows messing with linebreaks.
if (f == NULL) return NULL;
let xs_mem = alloc ...
let ys_mem = alloc ...
...
let xs@xs_mem = ...
...
... last use of xs ...
...
let ys@ys_mem = ...
...
in ys -- or whatever
from contact_map import contact_map
import numpy as np
import time
import jax.numpy as jnp
fut = contact_map()
@profile
def futhark(shape):
arr = np.float32(np.random.normal(0,2,shape[0]*shape[1]))
let dotprod xs ys = f32.sum (map2 (*) xs ys)
let all_pairs_norm [n][k] (A: [n][k]f32) (B: [n][k]f32) : [n][n]f32 =
let sqrA = map (map (**2)) A |> map f32.sum |> replicate n
let sqrB = map (map (**2)) B |> map f32.sum |> map (replicate n)
let diff = map (\a -> map (dotprod a) B) A
in map2 (map2 (+)) sqrA sqrB
|> map2 (map2 (\diff' x -> x-2*diff')) diff
|> map (map f32.sqrt)
let prut x = x + 1
# This default.nix builds a tarball containing a statically linked
# Futhark binary and some manpages. Likely to only work on linux.
#
# Just run 'nix-build' and fish the tarball out of 'result/'.
let
# Fetch the latest haskell.nix and import its default.nix
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
# haskell.nix provides access to the nixpkgs pins which are used by our CI, hence
nix-build '<nixpkgs>' --arg overlays '[ (import /home/mzd885/nixos-rocm/pkgs/all-packages.nix) ]' -A rocm-opencl-runtime | cachix push athas
module Main(main) where
import Control.Concurrent (threadDelay)
import System.IO
import System.IO.Error
import System.Environment (getArgs)
followDelayMicroseconds :: Int
followDelayMicroseconds = 1000000 `div` 60