Skip to content

Instantly share code, notes, and snippets.

View SimonDanisch's full-sized avatar
🏠
Working from home

Simon SimonDanisch

🏠
Working from home
View GitHub Profile
ARG IMAGE=nvidia/cuda:12.1.1-devel-ubuntu22.04
FROM $IMAGE
ARG JULIA_RELEASE=1.9
ARG JULIA_VERSION=1.9.4
# julia
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
using Preferences
for uuid in ["ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a", "e9467ef8-e4e7-5192-8a1a-b1aee30e663a",
"276b4fcb-3e11-5398-bf8b-a0c2d153d008", "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"]
set_preferences!(Base.UUID(uuid), "precompile_workload" => false; force=true)
end
@SimonDanisch
SimonDanisch / mandelbrot.jl
Created September 9, 2023 09:54
Mojo vs Julia mandelbrot benchmark
# Super simple SIMD implementation for Complex Numbers
struct ComplexSIMD{N,T}
re::NTuple{N,T}
im::NTuple{N,T}
end
Base.abs2(z::ComplexSIMD) = z.re .* z.re .+ z.im .* z.im
Base.:(*)(a::ComplexSIMD, b::ComplexSIMD) = ComplexSIMD(a.re .* b.re .- a.im .* b.im, a.re .* b.im .+ a.im .* b.re)
Base.:(+)(a::ComplexSIMD, b::ComplexSIMD) = ComplexSIMD(a.re .+ b.re, a.im .+ b.im)
function mandelbrot_kernel(c::ComplexSIMD{N,T}) where {N,T}
using Mmap, TextParse
using TextParse: Record, Field, Numeric, tryparsenext, isnull
struct MMapString{T} <: AbstractVector{Char}
x::T
end
MMapString(path::String) = MMapString(Mmap.mmap(open(path), Vector{UInt8}))
# we only need to overload the iteration protocol for TextParse to work!
Base.Base.@propagate_inbounds Base.getindex(x::MMapString, i) = Char(x.x[i])
Base.Base.@propagate_inbounds function Base.iterate(x::MMapString, state...)
julia --project=. -e "using Pkg; pkg"add RadeonProRender#sd/moah GeometryBasics RadeonProRender_jll@2.2.7"

executed with:

julia --project=. --check-bounds=(yes|no) rpr_mwe.jl

Diff of the llvm code: https://www.diffchecker.com/chE5Jtim

using Gtk, GLWindow, GLAbstraction, Reactive, GeometryTypes, Colors, GLVisualize
using GtkReactive
using Gtk.GConstants, ModernGL
mutable struct GtkContext <: GLWindow.AbstractContext
window::Gtk.GLArea
framebuffer::GLWindow.GLFramebuffer
end
function make_context_current(screen::Screen)
using FFMPEG
function save(src::String, out::String;
framerate::Int = 24, compression = 20)
typ = splitext(out)[2]
mktempdir() do dir
if typ == ".mp4"
ffmpeg_exe(`-i $(src) -crf $compression -c:v libx264 -preset slow -r $framerate -pix_fmt yuv420p -c:a libvo_aacenc -b:a 128k -y $out`)
elseif typ == ".webm"
ffmpeg_exe(`-i $(src) -crf $compression -c:v libvpx-vp9 -threads 16 -b:v 2000k -c:a libvorbis -threads 16 -r $framerate -vf scale=iw:ih -y $out`)
elseif typ == ".gif"
@SimonDanisch
SimonDanisch / 2_7billion_points.jl
Created October 31, 2017 11:25
Plotting 2.7 billion points
using TextParse
using TextParse: Record, Field, Numeric, tryparsenext
# Helper type to memory map a file as a string
struct MMapString{T}
# using Type parameter, too lazy to write out the result type of mmap,
# but also don't want to loose performance
x::T
end
MMapString(path::String) = MMapString(Mmap.mmap(open(path), Vector{UInt8}))
using StructArrays
using BenchmarkTools
using LoopVectorization
function juliaset2(re, im, c, maxiter)
result = re % UInt8
for i in 1:maxiter
abs = re*re + im*im
mask = abs > 4f0
result = mask & ((i - 1) % UInt8)
#=
# Perlin noise ported from: https://github.com/caseman/noise
# with the license:
Copyright (c) 2008 Casey Duncan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights