Skip to content

Instantly share code, notes, and snippets.

@Moelf
Last active July 17, 2025 22:27
Show Gist options
  • Save Moelf/3caa868120015fcc6b8af5e461f19967 to your computer and use it in GitHub Desktop.
Save Moelf/3caa868120015fcc6b8af5e461f19967 to your computer and use it in GitHub Desktop.
GPU Histogram for Python via `juliacall`

Shell

pixi init
pixi add pyjuliacall numpy
pixi s

setup

from juliacall import Main as jl
jl.seval("using Pkg")

jl.Pkg.add("CUDA")
jl.Pkg.add("KernelAbstractions")
jl.Pkg.add(jl.Pkg.PackageSpec(url="https://github.com/Moelf/FHist.jl/", rev="gpu_ext"))

experiment

from juliacall import Main as jl
import numpy as np

jl.seval("using FHist, CUDA, KernelAbstractions")

data = jl.cu(np.random.rand(10**5));

data[:3]
# 3-element view(::CuArray{Float32, 1, CUDA.DeviceMemory}, 1:1:3) with eltype Float32:
#  0.6631426
#  0.6895298
#  0.6301632

jl.FHist.gpu_bincounts(data, sync=True, binedges=jl.range(0, 1, step=0.01))
# 100-element CuArray{Float32, 1, CUDA.DeviceMemory}:
#  1027.0
#   960.0
#   982.0
#  1040.0
#  1045.0
#  1035.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment