• Stars
    star
    186
  • Rank 200,360 (Top 5 %)
  • Language
    Julia
  • License
    Other
  • Created 8 months ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AllocCheck

AllocCheck.jl

AllocCheck.jl is a Julia package that statically checks if a function call may allocate by analyzing the generated LLVM IR of it and its callees using LLVM.jl and GPUCompiler.jl

AllocCheck operates on functions, attempting to determine statically whether a function may allocate memory, and if so, where that allocation appears. This is different from measuring allocations using, e.g., @time or @allocated, which measures the allocations that actually happened during the execution of a function.

Getting started

The primary entry point to check allocations is the macro @check_allocs which is used to annotate a function definition that you'd like to enforce allocation checks for:

julia> using AllocCheck

julia> @check_allocs multiply(x, y) = x * y
multiply (generic function with 1 method)

julia> multiply(1.5, 2.5) # call automatically checked for allocations
3.75

julia> multiply(rand(3, 3), rand(3, 3)) # result matrix requires an allocation
ERROR: @check_allocs function encountered 1 errors (1 allocations / 0 dynamic dispatches).

The multiply(::Float64, ::Float64) call happened without error, indicating that the function was proven not to allocate. On the other hand, the multiply(::Matrix{Float64}, ::Matrix{Float64}) call raised an AllocCheckFailure due to one internal allocation.

The errors field can be used to inspect the individual errors:

julia> try
           multiply(rand(3, 3), rand(3, 3))
       catch err
           err.errors[1]
       end
Allocation of Matrix{Float64} in ./boot.jl:477
  | Array{T,2}(::UndefInitializer, m::Int, n::Int) where {T} =

Stacktrace:
 [1] Array
   @ ./boot.jl:477 [inlined]
 [2] Array
   @ ./boot.jl:485 [inlined]
 [3] similar
   @ ./array.jl:418 [inlined]
 [4] *(A::Matrix{Float64}, B::Matrix{Float64})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.10.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/matmul.jl:113
 [5] var"##multiply#235"(x::Matrix{Float64}, y::Matrix{Float64})
   @ Main ./REPL[13]:1

Functions that throw exceptions

Some functions that we do not expect may allocate memory, like sin, actually may:

julia> @allocated try
           sin(Inf)
       catch
       end
48

The reason for this is that sin needs to allocate if it throws an error.

By default, @check_allocs ignores all such allocations and assumes that no exceptions are thrown. If you care about detecting these allocations anyway, you can use ignore_throw=false:

julia> @check_allocs mysin1(x) = sin(x)

julia> @check_allocs ignore_throw = false mysin2(x) = sin(x)

julia> mysin1(1.5)
0.9974949866040544

julia> mysin2(1.5)
ERROR: @check_allocs function encountered 2 errors (1 allocations / 1 dynamic dispatches).

Limitations

Every call into a @check_allocs function behaves like a dynamic dispatch. This means that it can trigger compilation dynamically (involving lots of allocation), and even when the function has already been compiled, a small amount of allocation is still expected on the function entry.

For most applications, the solution is to use @check_allocs to wrap your top-level entry point or your main application loop, in which case those allocations are only incurred once. @check_allocs will guarantee that no dynamic compilation or allocation occurs once your function has started running.

More Repositories

1

julia

The Julia Programming Language
Julia
44,029
star
2

IJulia.jl

Julia kernel for Jupyter
Julia
2,718
star
3

PackageCompiler.jl

Compile your Julia Package
Julia
1,373
star
4

juliaup

Julia installer and version multiplexer
Rust
887
star
5

Pkg.jl

Pkg - Package manager for the Julia programming language
Julia
587
star
6

www.julialang.org

Julia Project website
Julia
342
star
7

JuliaSyntax.jl

The Julia compiler frontend
Julia
263
star
8

METADATA.jl

Metadata for registered Julia packages up to Julia v0.6. No longer maintained. Please see https://github.com/JuliaRegistries/General instead.
Julia
219
star
9

PrecompileTools.jl

Reduce time-to-first-execution of Julia code
Julia
190
star
10

www_old.julialang.org

Julia Project web site (Old)
Jupyter Notebook
149
star
11

Compat.jl

Compatibility across Julia versions
Julia
137
star
12

Example.jl

Example Julia package repo.
Julia
123
star
13

julia-logo-graphics

official versions of the Julia logo
Julia
108
star
14

Tokenize.jl

Tokenization for Julia source code
Julia
99
star
15

Downloads.jl

Julia
90
star
16

JuliaParser.jl

A rewrite of Julia's parser in Julia
Julia
89
star
17

PackageCompilerX.jl

Julia
85
star
18

Microbenchmarks

Microbenchmarks comparing the Julia Programming language with other languages
Jupyter Notebook
83
star
19

PkgDev.jl

Tools for Julia package developers
Julia
70
star
20

Juleps

Julia Enhancement Proposals
67
star
21

FancyDiagnostics.jl

Better parser errors for Julia
Julia
44
star
22

MbedTLS.jl

Wrapper around mbedtls
Julia
41
star
23

TOML.jl

A fast TOML parser for TOML 1.0 written in Julia
Julia
33
star
24

JuliaDoc

Python
28
star
25

docs.julialang.org

Repository for hosting the manual for the Julia language
Julia
25
star
26

SoftGlobalScope.jl

utilities for "soft" global scope in interactive Julia environments
Julia
24
star
27

LinearAlgebra.jl

Julia
21
star
28

Distributed.jl

Create and control multiple Julia processes remotely for distributed computing. Ships as a Julia stdlib.
Julia
18
star
29

BugReporting.jl

Streamlines bug reporting for julia
Julia
17
star
30

devcontainer-features

Julia Development Container Feature
Shell
16
star
31

NetworkOptions.jl

Julia
12
star
32

libosxunwind

Clone of Apple's libunwind, enhanced for the Julia Profiler
C++
11
star
33

BumpStdlibs.jl

Update the hashes and checksums of all Julia stdlibs in just four clicks.
Julia
11
star
34

JuliaSyntaxHighlighting.jl

Julia
9
star
35

StyledStrings.jl

Julia
8
star
36

mintty-julia

5
star
37

Public.jl

Julia
5
star
38

.github

Repository for default community health files
4
star
39

IJuliaCore.jl

Julia
4
star
40

devcontainer-templates

Julia Development Container Template
Shell
4
star
41

pull-request-state-machine

Python
3
star
42

VersionsJSONUtil.jl

Julia
3
star
43

buildkite-rerun-failed

Julia
2
star
44

Test.jl

Julia
1
star