Skip to content

Instantly share code, notes, and snippets.

@sklam
sklam / README.md
Created May 4, 2022 13:56
prime factorization using trial division

Prime factorization is useful for reshaping an array into the highest dimension form where non of the dimension has size of 1.

@sklam
sklam / README.md
Created July 13, 2021 22:55
Notes on using radare2 with Numba

Numba + Radare2

Information on seeing source info of Numba jit code in radare2.

Getting object file from numba

@njit(debug=True)
def foo():
/*
Compile this with:
$ clang -O3 do_no_evil.c && ./a.out
Reference http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html
*/
#include <stdio.h>
#include <stdlib.h>
@sklam
sklam / jitclass_dict.py
Created September 19, 2019 17:41
JITClass Dictionary Example
from numba import jitclass
from numba import types
from numba.typed import Dict
@jitclass([('d', types.DictType(types.intp, types.float64))])
class DictWrapper(object):
def __init__(self):
d = Dict()
d[1] = 1.2
@sklam
sklam / example_pickle_cuda.py
Created August 26, 2019 13:49
Pickling a specialized CUDA kernel
from numba import cuda, typeof
import numpy as np
import pickle
@cuda.jit
def foo(x, v):
x[0] = v
from numba import njit
@njit
def foo(functor, a, b):
return bar(functor, functor(a, b), b)
@njit
def bar(functor, a, b):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sklam
sklam / device_func_inspect_ptx.ipynb
Created April 23, 2019 17:58
Usage example for cuda_device_fn.inspect_ptx()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sklam
sklam / cuda_ptxas_info.ipynb
Created November 12, 2018 15:05
Getting PTXAS info from a numba cuda kernel
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Usage:

conda create -n volcano_bench python=3.6 numba scipy tbb
conda activate volcano_bench
pip install pythran
pythran -O3 -fopenmp -march=native -DUSE_BOOST_SIMD shade_pythran.py
python driver_pythran.py
python driver_numba.py