Skip to content

Instantly share code, notes, and snippets.

View lovely-error's full-sized avatar
😆
Don't forget that you will die some day

Enigma Lav lovely-error

😆
Don't forget that you will die some day
View GitHub Profile
@lovely-error
lovely-error / ocl_enable.md
Last active April 14, 2024 02:05
Get OpenCL working on RX580 amdgpu using APT
  1. Create this file sudo touch /etc/apt/sources.list.d/rocm.list
  2. put this line in there deb [arch=amd64] https://repo.radeon.com/rocm/apt/3.5.1/ xenial main
  3. sudo apt update
  4. install ocl sudo apt install rocm-opencl3.5.0
  5. this script doesnt write icd path to /etc/OpenCL/vendors/ so that's on us
  6. touch /etc/OpenCL/vendors/amdocl64.icd
  7. echo "/opt/rocm-3.5.1/opencl/lib/libamdocl64.so" > /etc/OpenCL/vendors/amdocl64.icd
  8. done. run clinfo. thing work at this point
@lovely-error
lovely-error / kern.cl
Last active March 6, 2024 07:52
Conditional execution without branches on gpu
// this kernel writes a value only if invoaction index is even *_*
// when _flag is true, the store adress gets computed to be beyound (1 << 48) byte location .
// apparently stores beyound valid adress space on gpu... just become noops!
#define store_if_true(Ty, addr, val, flag) \
*((__global Ty*)(((unsigned long)addr) + (((unsigned long)(flag == 0)) * ((1LU << 48) - ((unsigned long)addr))))) = val;
__kernel void kern(__global unsigned int* buffer) {
@lovely-error
lovely-error / crapy_integ.hs
Last active February 21, 2024 07:21
Computing definite integral over sinus in range [0;pi] (with terrible precision :3 ~2.0097% deviation from analytic solution)
-- basically this in wolfram alpha terms
-- 2*(Integrate[sin\(40)x\(41),{x,0,Divide[pi,4]}]+Integrate[sin\(40)x\(41),{x,Divide[pi,4],Divide[pi,2]}])
-- https://www.desmos.com/calculator/1fokxfyphz
-- https://www.wolframalpha.com/input?i2d=true&i=Integrate%5Bsin%5C%2840%29x%5C%2841%29%2C%7Bx%2C0%2Cpi%7D%5D
-- https://www.wolframalpha.com/input?i2d=true&i=2*%5C%2840%29Integrate%5Bsin%5C%2840%29x%5C%2841%29%2C%7Bx%2C0%2CDivide%5Bpi%2C4%5D%7D%5D%2BIntegrate%5Bsin%5C%2840%29x%5C%2841%29%2C%7Bx%2CDivide%5Bpi%2C4%5D%2CDivide%5Bpi%2C2%5D%7D%5D%5C%2841%29
import Text.Printf (printf)
@lovely-error
lovely-error / erase.zig
Last active January 15, 2024 12:48
Easified type erasure in zig
pub fn main() !void {
const AbstractedObject = Opaque(&.{
.{"f1", fn (*anyopaque) u1},
.{"f2", fn (*anyopaque, u8, u8, u8, u8) L},
.{"ferry", fn (*anyopaque)error{boo}!void},
});
var a = std.heap.ArenaAllocator.init(std.heap.page_allocator);
var T = K {};
@lovely-error
lovely-error / ptrs.zig
Created January 13, 2024 10:06
zig pointer utils
const std = @import("std");
pub const @"1KiB of bytes": comptime_int = 1024;
pub const @"1MiB of bytes": comptime_int = 1024 * 1024;
pub const @"1GiB of bytes": comptime_int = 1 << 30;
pub const @"Byte amount fitting within 48 bit address space": comptime_int = (1 << 48) - 1;
pub fn Ptr(comptime Pointee: type, comptime is_mutable: bool) type {
const Ty = if (is_mutable) *Pointee else *const Pointee;
return struct {
@lovely-error
lovely-error / lol.agda
Last active January 13, 2024 10:03
automorphisms of Z2
{-# OPTIONS --type-in-type #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat
open import Agda.Builtin.Sigma
open import Agda.Builtin.List
data Void : Set where
@lovely-error
lovely-error / kal.hs
Created August 3, 2023 08:26
The world simplest calculator with infix expressions and parens
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PartialTypeSignatures #-}
import Data.Char (isNumber, isSpace)
infixl |>
v |> f = f v
main = do
print "Hey! I am ready to accept input :)"
@lovely-error
lovely-error / hs.hs
Created April 20, 2023 14:24
Stochastic bin packing algorithm, kinda. Was made for one of my lovers
import Data.List
infixl ///
class LaxDivision a where
(///) :: a -> a -> a
instance LaxDivision Int where
(///) = div
@lovely-error
lovely-error / selfreflections.md
Created November 5, 2022 10:22
Those which have many names, but only a single essence

Statement

Somehow, it is not possible to lie. These things are with the definiteviness of a combinatorial object. They are not fractals.

I heard one man once said that homological algebra is the most remarkable thing that has been discovered. In most unlike places I noticed glimpses of its presense.

@lovely-error
lovely-error / more_types!.swift
Created October 2, 2021 21:50
Typelevelisation
import Foundation
func fix <A>(_ f : (A) -> A) -> A { f (fix (f)) }
// _ = fix { _ in }
indirect enum N {
case s(N), z