Skip to content

Instantly share code, notes, and snippets.

View brandondube's full-sized avatar

Brandon Dube brandondube

View GitHub Profile
@brandondube
brandondube / gist:dfe7210b58860c3d82718de36dcc65b8
Created January 12, 2024 19:06
nvidia-smi log utilization
nvidia-smi --query-gpu=power.draw,clocks.current.graphics,clocks.current.memory,utilization.gpu,utilization.memory --format=csv --loop-ms=1000
import time
import numpy as np
from matplotlib import pyplot as plt
# replace with np.fft or scipy.fft if you don't have it installed,
# not central to the demonstration, but better multi-threading
# "the point" is to examine parallelization over N "whole tasks"
# using ray or another lib, vs using low-level parallelization
# by threading each array op
@brandondube
brandondube / batch_dot.py
Created December 29, 2021 15:34
dot product batch with einsum
from concurrent.futures import ThreadPoolExecutor, wait
def slices_for_split(N, m):
"""Split an array of length N into m chunks, with the final chunk being a bit smaller if need be.
Does not actually split, returns a list of slice objects for reuse.
"""
# this code is largely adapted from the numpy source code
Neach_section, extras = divmod(N, m)
Neach_section, extras
@brandondube
brandondube / cupy-mwe-client.py
Created October 25, 2021 17:09
cupy 9.5.0 memory leak and setDevice not working
from io import BytesIO
import requests
from imageio import imread
if __name__ == '__main__':
url = 'http://localhost:5000/wrong-gpu-and-memory-leak'
while True:
resp = requests.get(url)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brandondube
brandondube / r.jl
Created October 11, 2020 21:00
recursive-zernike2.jl
"""
calcac/b(n, α, β, x)
Two functions calcac and calcb compute the three coefficients in the recurrence
relation for the Jacobi polynomial. It is broken into two functions to separate
a and c, which do not depend on x and can be calculated once for a vector of x,
from b which does depend on x and must be calculated for each element.
n is the order of the polynomial.
@brandondube
brandondube / recursive_zernike.jl
Created October 11, 2020 03:35
recursive_zernike.jl
function abc(n, α, β, x)
# the parens emphasize the terms, not PEMDAS
a = (2n) * (n + α + β) * (2n + α + β - 2)
b1 = (2n + α + β -1)
b2 = (2n + α + β)
b2 = b2 * (b2 - 2)
b = b1 * (b2 * x + α^2 - β^2)
c = 2 * (n + α - 1) * (n + β - 1) * (2n + α + β)
return a, b, c
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brandondube
brandondube / demo.py
Created July 28, 2020 16:05
deconv demo
from prysm import AiryDisk, SiemensStar
from matplotlib import pyplot as plt
oversamp=8
obj = SiemensStar(32, sinusoidal=False, sample_spacing=5/oversamp, samples=512*oversamp).msaa(oversamp)
psf = AiryDisk(fno=32, wavelength=.55, extent=obj.support/2, samples=obj.samples_x)
obj.plot2d(xlim=50, interpolation='bilinear')
blurred = obj.conv(psf)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.