Skip to content

Instantly share code, notes, and snippets.

View mratsim's full-sized avatar
:shipit:

Mamy Ratsimbazafy mratsim

:shipit:
  • Paris
View GitHub Profile
# Copyright MIT and Apache, Mamy Ratsimbazafy 2019
import std/atomics #, optim_hints # for prefetch
const WV_CacheLineSize = 128
type
Enqueueable = concept x, type T
x is ptr
x.next is Atomic[T]
from pyutils.ssz.ssz_typing import uint64, List, Bitlist, Bytes32, Bytes96, Container
from pyutils.ssz.ssz_impl import hash_tree_root
# Minimal
# MAX_VALIDATORS_PER_COMMITTEE = 2048
# Mainnet
MAX_VALIDATORS_PER_COMMITTEE = 4096
class Checkpoint(Container):
@mratsim
mratsim / design_threading_API.md
Last active November 11, 2019 10:31
Some design questions on Threading API
  • Atomic Rc vs Rc taxes for single-threaded module compile with threads:on
  • API to allow to switch runtimes:
    • Simple threadpool, custom one
    • Throughput optimized (work-stealing)
    • Latency-optimized (Earliest Deadline First schedulers / priority queues)
    • Plug in Cuda/OpenCL async (Streams and Command Queue) or external system like MPI, (Hadoop/Kafka?) etc
  • 2 spawns
    • spawn that access a global default threadpool for Nim programs composability
    • spawn that takes a threadpool as first argument
@mratsim
mratsim / experimental.go
Created November 7, 2019 17:38 — forked from protolambda/experimental.go
Binary Tree as immutable state backing, with rebinding pattern for minimal copy-on-write modifications. Every merkle cached *by default*.
package experimental
import "encoding/binary"
// Experimental code! Everything a tree and cached by default.
type HashFn func(a Root, b Root) Root
// A link is called to rebind a value
@mratsim
mratsim / 2019-11-07 Eth2 impl call.md
Last active November 7, 2019 14:45
2019-11-07 Eth2 impl call
@mratsim
mratsim / compilation_command.md
Created November 2, 2019 15:47
Nim to Assembly

Either

nim c --passC:"-fno-asynchronous-unwind-tables -fno-exceptions -fno-rtti -fverbose-asm -masm=intel -S" -d:release --noLinking:on "path/to/file.nim"

The result will be in $HOME/.cache/file_r/file.c.o (_r for release) The C sources or Nim sources (with --debugger:native) will be interleaved with ASM

Otherwise use:

#!/bin/bash
set -eo pipefail
# Clone Nimbus Eth 2
SRCDIR=${NIMBUS_PATH:-"nim-beacon-chain"}
# Read in variables
source "$(dirname "$0")/vars.sh"
@mratsim
mratsim / myproj.nim
Last active October 23, 2019 19:40 — forked from xmonader/myproj.nim
myproj.nim
# This is just an example to get you started. A typical binary package
# uses this file as the main entry point of the application.
import strformat, tables, json, strutils, asyncdispatch, asyncnet, strutils, parseutils, options, net
from cgi import decodeUrl
import terminaltables
import mimetypes
type
@mratsim
mratsim / loopvec.c
Last active September 27, 2019 10:19
// ----------------------------------
// Time measurements
#include <sys/time.h>
#include <time.h>
// Number of seconds since the Epoch
static inline double Wtime_sec(void)
{
struct timeval tv;
@mratsim
mratsim / nim_magic.py
Created September 26, 2019 11:40 — forked from apahl/nim_magic.py
Nim cell magic for Jupyter and JLab Notebooks
"""
nim_magic.py
Jupyter cell magic for your favorite programming language.
This is now also available as a proper repo:
https://github.com/apahl/nim_magic
All further changes will be tracked there.
Requirements: Nim (https://nim-lang.org), nimpy (`nimble install nimpy`, thanks to @yglukhov for this great library!)