AlignedAllocs

lightweight cross-platform allocation of aligned memory for an n-Vector{T} where isbitstype(T)

https://github.com/jeffreysarnoff/alignedallocs.jl

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.2%) to scientific vocabulary

Keywords

julia memory-alignment memory-allocation
Last synced: 6 months ago · JSON representation ·

Repository

lightweight cross-platform allocation of aligned memory for an n-Vector{T} where isbitstype(T)

Basic Info
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • Open Issues: 0
  • Releases: 13
Topics
julia memory-alignment memory-allocation
Created 12 months ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

AlignedAllocs.jl

lightweight cross-platform allocation of aligned memory

Copyright 2025 by Jeffrey Sarnoff. Relased under the MIT License.


image


exports

  • memalign(T, item_count, byte_alignment)

    • returns an uninitialized DenseVector{T} of length item_count aligned to byte_alignment bytes
    • T is a bitstype
  • memalign_clear(T, item_count, byte_alignment)

    • returns a zeroed DenseVector{T} of length item_count aligned to byte_alignment bytes
    • T is a bitstype (ensure zero(T) exists)
  • alignment(vector)

    • returns the byte alignment of the vector

why it matters

Modern processors retrieve data in memory into fast chip-local caches. In practice, the unit of memory retrieval is the cache line. For most general purpose computing, the size of (the Level 1) cache line is 64 bytes (one cache line holds 64 UInt8s, 32 Int16s, 16 Float32s, or 8 Float64s). When data is stored aligned to this size, its retrieval is simpler. Straddling two cache lines with a single primitive bitstype value incurs costly delays.

When using SIMD, alignment of 256 bytes (or more, depending on the processor) is critical to getting the throughput one expects from SIMD operations. Running unaligned data through SIMD slows the processing down significantly.

Julia memory alignment for dense vectors of numeric bitstypes is at least 16 bytes and may be 64 bytes. Which of these alignments obtains depends :). At the time of this writing on a Windows system, 512 Float32s align to 64 bytes while 500 or fewer Float32s may align to 16 bytes. Similarly, 256 Float64s align to 64 bytes while 250 or fewer may align to 16 bytes. Without this module, a dense vector of 2008 or fewer UInt8s may align to 16 bytes. If that is not enough uncertainty, the allocation mechanism on Windows differs from the allocation mechanism on Apple and 'nix compatible systems. The specifics are internal to Julia and may change going forward.

The take away is that for smallish dense vectors, you do not know what allocation alignment will be with certainty.

There is some good news. GPU allocations are written to work well with the GPU.


function encodings(bitwidth, typ=UInt16) n = 2^bitwidth codes = memalign_clear(typ, n) codes[:] = collect(map(typ, 0:(n-1))) codes end

```

vec::DenseVector = memalign(itemtype, itemcount, byte_alignment = 64)

bitstype , > 0 , 2^p where p > 2

elementtype = Float32 # a type T for which isbitstype(T) is true elementcount = 1024 elementbytes = sizeof(elementtype) * element_count

bytesofalignment = 64 # bytes

vec = memalign(elementtype, elementcount, bytesofalignment)

vec behaves as a DenseVector with enhanced cache-line performance vec is unsafe_wrapped contiguous memory from LLVM intrinsic or C/C++ library function ```


also consider

ArrayAllocators.jl - a type for aligned arrays


Thank you

  • Stephan Karpinski
  • Gabriel Baraldi
  • Diogo Netto
  • Bradley
  • chakravala
  • Jakob Nybo Nissen
  • Sinh Trung
  • Daniel Wennberg
  • foobar_lv2

Owner

  • Name: Jeffrey Sarnoff
  • Login: JeffreySarnoff
  • Kind: user
  • Location: New York

Citation (CITATION.cff)

# Go to https://citation-file-format.github.io/cff-initializer-javascript/#/ to finish this
cff-version: 1.2.0
title: AlignedAllocs.jl
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Jeffrey Sarnoff
    email: jeffrey.sarnoff@gmail.com
doi: 10.5281/zenodo.15095672

GitHub Events

Total
  • Create event: 15
  • Commit comment event: 30
  • Release event: 10
  • Issues event: 3
  • Delete event: 1
  • Issue comment event: 18
  • Public event: 1
  • Push event: 169
  • Pull request event: 4
  • Fork event: 1
Last Year
  • Create event: 15
  • Commit comment event: 30
  • Release event: 10
  • Issues event: 3
  • Delete event: 1
  • Issue comment event: 18
  • Public event: 1
  • Push event: 169
  • Pull request event: 4
  • Fork event: 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 2
  • Total pull requests: 5
  • Average time to close issues: 3 days
  • Average time to close pull requests: 3 days
  • Total issue authors: 2
  • Total pull request authors: 2
  • Average comments per issue: 1.5
  • Average comments per pull request: 2.4
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 3
Past Year
  • Issues: 2
  • Pull requests: 5
  • Average time to close issues: 3 days
  • Average time to close pull requests: 3 days
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 1.5
  • Average comments per pull request: 2.4
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
  • chakravala (1)
  • JuliaTagBot (1)
Pull Request Authors
  • dependabot[bot] (3)
  • PallHaraldsson (2)
Top Labels
Issue Labels
Pull Request Labels
dependencies (3) github_actions (1)

Packages

  • Total packages: 1
  • Total downloads:
    • julia 3 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 11
juliahub.com: AlignedAllocs

lightweight cross-platform allocation of aligned memory for an n-Vector{T} where isbitstype(T)

  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 3 Total
Rankings
Dependent repos count: 8.5%
Dependent packages count: 36.7%
Average: 43.4%
Forks count: 53.3%
Stargazers count: 75.1%
Last synced: 6 months ago