{"id":30807676,"url":"https://github.com/juliagpu/weirdfloats.jl","last_synced_at":"2026-03-13T14:34:38.715Z","repository":{"id":301027590,"uuid":"1007915669","full_name":"JuliaGPU/WeirdFloats.jl","owner":"JuliaGPU","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-25T10:12:21.000Z","size":9,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T11:11:29.884Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JuliaGPU.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-24T18:23:19.000Z","updated_at":"2025-07-26T23:48:58.000Z","dependencies_parsed_at":"2025-06-24T20:35:16.972Z","dependency_job_id":null,"html_url":"https://github.com/JuliaGPU/WeirdFloats.jl","commit_stats":null,"previous_names":["juliagpu/weirdfloats.jl"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JuliaGPU/WeirdFloats.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaGPU%2FWeirdFloats.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaGPU%2FWeirdFloats.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaGPU%2FWeirdFloats.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaGPU%2FWeirdFloats.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaGPU","download_url":"https://codeload.github.com/JuliaGPU/WeirdFloats.jl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaGPU%2FWeirdFloats.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30468352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-06T02:49:05.383Z","updated_at":"2026-03-13T14:34:38.673Z","avatar_url":"https://github.com/JuliaGPU.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WeirdFloats.jl\n\nThis package is for experimenting with interesting numerical formats available on some GPUs.\n\n## Installation\n\nTo install this package:\n\n```julia\nimport Pkg\nPkg.add(; url=\"https://github.com/JuliaGPU/WeirdFloats.jl\")\n```\n\nThis requires an AMD MI300 GPU or later generation and Julia v1.12 or later (to have LLVM 18 or later, to support that generation of GPU):\n\n```julia-repl\njulia\u003e versioninfo()\nJulia Version 1.12.0-beta4\nCommit 600ac61d3d2 (2025-06-05 07:03 UTC)\nBuild Info:\n  Official https://julialang.org release\nPlatform Info:\n  OS: Linux (x86_64-linux-gnu)\n  CPU: 384 × AMD EPYC 9654 96-Core Processor\n  WORD_SIZE: 64\n  LLVM: libLLVM-18.1.7 (ORCJIT, znver4)\n  GC: Built with stock GC\nThreads: 1 default, 1 interactive, 1 GC (on 384 virtual cores)\n\njulia\u003e AMDGPU.versioninfo()\n[ Info: AMDGPU versioninfo\n┌───────────┬──────────────────┬───────────┬────────────────────────────────────────────────────────────────────────────────────────┐\n│ Available │ Name             │ Version   │ Path                                                                                   │\n├───────────┼──────────────────┼───────────┼────────────────────────────────────────────────────────────────────────────────────────┤\n│     +     │ LLD              │ -         │ /opt/rocm/llvm/bin/ld.lld                                                              │\n│     +     │ Device Libraries │ -         │ /home/cceamgi/.julia/artifacts/b46ab46ef568406312e5f500efb677511199c2f9/amdgcn/bitcode │\n│     +     │ HIP              │ 6.4.43482 │ /opt/rocm/lib/libamdhip64.so                                                           │\n│     +     │ rocBLAS          │ 4.4.0     │ /opt/rocm/lib/librocblas.so                                                            │\n│     +     │ rocSOLVER        │ 3.28.0    │ /opt/rocm/lib/librocsolver.so                                                          │\n│     +     │ rocSPARSE        │ 3.4.0     │ /opt/rocm/lib/librocsparse.so                                                          │\n│     +     │ rocRAND          │ 2.10.5    │ /opt/rocm/lib/librocrand.so                                                            │\n│     +     │ rocFFT           │ 1.0.32    │ /opt/rocm/lib/librocfft.so                                                             │\n│     +     │ MIOpen           │ 3.4.0     │ /opt/rocm/lib/libMIOpen.so                                                             │\n└───────────┴──────────────────┴───────────┴────────────────────────────────────────────────────────────────────────────────────────┘\n\n[ Info: AMDGPU devices\n┌────┬─────────────────────┬────────────────────────┬───────────┬─────────────┬───────────────┐\n│ Id │                Name │               GCN arch │ Wavefront │      Memory │ Shared Memory │\n├────┼─────────────────────┼────────────────────────┼───────────┼─────────────┼───────────────┤\n│  1 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  2 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  3 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  4 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  5 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  6 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  7 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n│  8 │ AMD Instinct MI300X │ gfx942:sramecc+:xnack- │        64 │ 191.984 GiB │    64.000 KiB │\n└────┴─────────────────────┴────────────────────────┴───────────┴─────────────┴───────────────┘\n```\n\n## Examples\n\n### Downcasting to FP8 with stochasting rounding\n\nWe want to convert four `Float32` numbers to the 8-bit floating point format (FP8) used on AMD GPUs (or `DLFP8Types.Float8_E4M3FNUZ`, using the [`DLFP8Types.jl`](https://github.com/chengchingwen/DLFP8Types.jl) package)\n\n```julia-repl\njulia\u003e using AMDGPU, WeirdFloats, DLFP8Types\n\njulia\u003e A = AMDGPU.rand(Float32, 4)\n4-element ROCArray{Float32, 1, AMDGPU.Runtime.Mem.HIPBuffer}:\n 0.3193292\n 0.007127027\n 0.77079546\n 0.036067273\n\njulia\u003e B = AMDGPU.zeros(Int32, 1); C = AMDGPU.zeros(Int32, 1); D = AMDGPU.zeros(Int32, 1)\n1-element ROCArray{Int32, 1, AMDGPU.Runtime.Mem.HIPBuffer}:\n 0\n```\n\nWith deterministic rounding we expect to have\n\n```julia-repl\njulia\u003e Float8_E4M3FNUZ.(Array(A))\n4-element Vector{Float8_E4M3FNUZ}:\n 0.3125\n 0.0068359375\n 0.75\n 0.03515625\n```\n\nLet's define a kernel which converts the elements of `A` to FP8 with [stochastic rounding](https://doi.org/10.1098/rsos.211631) by using `WeirdFloats.convert_sr`, and run the kernel multiple times, storing the result in the arrays `B`, `C`, and `D`:\n\n```julia-repl\njulia\u003e @inbounds function kernel_sr(A, B)\n           v = reinterpret(WeirdFloats.VFP8, Int32(0))\n           v = WeirdFloats.convert_sr(v, A[1], rand(Int32), Int32(0))\n           v = WeirdFloats.convert_sr(v, A[2], rand(Int32), Int32(1))\n           v = WeirdFloats.convert_sr(v, A[3], rand(Int32), Int32(2))\n           v = WeirdFloats.convert_sr(v, A[4], rand(Int32), Int32(3))\n           B[1] = reinterpret(Int32, v)\n\n           return nothing\n       end\nkernel_sr (generic function with 1 method)\n\njulia\u003e @device_code dir=\"fp8\" @roc kernel_sr(A, B); B\n1-element ROCArray{Int32, 1, AMDGPU.Runtime.Mem.HIPBuffer}:\n 440141618\n\njulia\u003e @device_code dir=\"fp8\" @roc kernel_sr(A, C); C\n1-element ROCArray{Int32, 1, AMDGPU.Runtime.Mem.HIPBuffer}:\n 423364658\n\njulia\u003e @device_code dir=\"fp8\" @roc kernel_sr(A, D); D\n1-element ROCArray{Int32, 1, AMDGPU.Runtime.Mem.HIPBuffer}:\n 423364403\n```\n\nThe four output FP8 numbers are packed in the one-element `Float32` arrays `B`, `C`, and `D`, we can unpack them to see their values:\n\n```julia-repl\njulia\u003e for shift in (0, 8, 16, 24); println(reinterpret(Float8_E4M3FNUZ, (Array(B)[1] \u003e\u003e shift \u0026 0xff) % UInt8)); end\n0.3125\n0.0068359375\n0.75\n0.0390625\n\njulia\u003e for shift in (0, 8, 16, 24); println(reinterpret(Float8_E4M3FNUZ, (Array(C)[1] \u003e\u003e shift \u0026 0xff) % UInt8)); end\n0.3125\n0.0078125\n0.75\n0.03515625\n\njulia\u003e for shift in (0, 8, 16, 24); println(reinterpret(Float8_E4M3FNUZ, (Array(D)[1] \u003e\u003e shift \u0026 0xff) % UInt8)); end\n0.34375\n0.0068359375\n0.75\n0.03515625\n```\n\nWe can see that the elements of `A` have not been downcast deterministically to FP8 according to the expected result shown above, but in some cases they were rounded to the other adject number in FP8.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliagpu%2Fweirdfloats.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliagpu%2Fweirdfloats.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliagpu%2Fweirdfloats.jl/lists"}