Skip to content

Instantly share code, notes, and snippets.

View alcides's full-sized avatar

Alcides Fonseca alcides

View GitHub Profile
NodeName=localhost Name=gpu type=a30 File=/dev/nvidia[0-1]
NodeName=localhost Name=mps count=200 File=/dev/nvidia[0-1]
@alcides
alcides / flatten.py
Created July 4, 2023 20:34
Script to (recursively) literally include all \input or \include, and put all files in the root folder (for submission in journals with an awful UI system)
"""
This script flattens the structure of this project in the output folder.
"""
import os
import re
import sys
import shutil
from datetime import date
from pathlib import Path
@alcides
alcides / Readme.md
Last active February 28, 2023 03:52
MyFirstCompiler

My First Compiler

Overview

This project shows an example of a compiler pipeline.

The frontend is responsible for parsing the input file (example.lang) and returning an AST. The AST is designed using an OO approach, with two main types (Statement and Expression), and multiple options for each. A program is a list of statements. There is one semantic validation: we are detecting if variables are used before they are defined. If so, we raise an exception.

@alcides
alcides / stats.py
Last active October 18, 2022 08:23
Solution to Timothy Gowers's Daughter Homework
# Puzzle from: https://twitter.com/wtgowers/status/1581667648592826369?s=12&t=5CR5L4TsH2MJWDJwBO8Wmw
import z3
s = z3.Solver()
a, b, c, d, e = z3.Ints("a b c d e")
# order
s.add( a <= c )
s.add( b <= c )
s.add( c <= d )
• [alcides@franklin:~/Code/srbench] (Competition2022) $ ~/bin/act
[CI/check] 🚀 Start image=ghcr.io/catthehacker/ubuntu:act-latest
[CI/check] 🐳 docker pull image=ghcr.io/catthehacker/ubuntu:act-latest platform= username= forcePull=false
[CI/check] 🐳 docker create image=ghcr.io/catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI/check] 🐳 docker run image=ghcr.io/catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI/check] 🐳 docker exec cmd=[mkdir -m 0777 -p /var/run/act] user=root workdir=
[CI/check] 🐳 docker cp src=/home/alcides/Code/srbench/. dst=/home/alcides/Code/srbench
[CI/check] 🐳 docker exec cmd=[mkdir -p /home/alcides/Code/srbench] user= workdir=
[CI/check] ⭐ Run Checkout code
[CI/check] ✅ Success - Checkout code
@alcides
alcides / Proofs.hs
Created March 31, 2022 09:31
Lean vs LiquidHaskell for proofs about Haskell programs
import Language.Haskell.Liquid.ProofCombinators
{-@ reflect map1 @-}
map1 :: (Int -> Int) -> [Int] -> [Int]
map1 f [] = []
map1 f (x:xs) = (f x):(map1 f xs)
{-@ reflect length1 @-}
length1 :: [Int] -> Int
@alcides
alcides / lean_forin.lean
Created December 5, 2021 11:54
Lean benchmarks
def countPairs (xm ym:Nat) : IO Nat := do
let mut count := 0
for x in [0:xm+1] do
for y in [0:ym+1] do
count := if x == y then count + 1 else count
return count
def main (args : List String) : IO UInt32 :=
do
let xmax := 10000

How to run:

Install lean4 (using elan), and run:

lean --c=hello.c hello.lean
@alcides
alcides / blockwidesync.cu
Last active November 12, 2021 19:12
MWE for grid-wide synchronization in CUDA 9+. Source: https://stackoverflow.com/questions/6404992/cuda-block-synchronization
#include <cuda_runtime_api.h>
#include <cuda.h>
#include <cooperative_groups.h>
#include "workshop.h"
#define N 10
__global__ void block_wide_kernel() {
int index = blockIdx.x * blockDim.x + threadIdx.x;
@alcides
alcides / lazy_insertion_sort.py
Created July 20, 2021 08:19
Insertion sort written in generators (to simulate haskell), so the head of a sorted list has linear complexity.
def insert_sort_generator(li):
if len(li) <= 0:
return
h = li[0]
done = False
for v in insert_sort_generator(li[1:]):
if h < v and not done:
yield h
done = True
yield v