Intel VTune Profiler + Julia


Content


General notes

Remote usage - GUI

Example code

using ThreadPinning
using IntelITT

# Multithreaded SAXPY kernel: Y[i] = a * X[i] + Y[i]
function saxpy_kernel(a, X, Y)
    Threads.@threads :static for i in eachindex(Y)
        @inbounds Y[i] = a * X[i] + Y[i]
    end
    return nothing
end

"""
  measure_membw(; kwargs...) -> membw, flops

Estimate the memory bandwidth (GB/s) by performing a time measurement of a
SAXPY kernel. Returns the memory bandwidth (GB/s) and the compute (GFLOP/s).

**Keyword arguments:**
- `pin` (default: `:compact`): pinning strategy (supported by ThreadPinning)
- `init` (default: `:serial`): initialize arrays in serial or in parallel (`:parallel`)
- `N` (default: `1024*100_000``): problem size, i.e. vector length
"""
function measure_membw(; N = 1024 * 100_000)
    bytes = 3 * sizeof(Float64) * N # num bytes transferred in SAXPY
    flops = 2 * N # num flops in SAXPY

    # pinning the Julia threads
    ThreadPinning.pinthreads(:numa)

    # initialize data in parallel
    a = 3.141
    X = Vector{Float64}(undef, N)
    Y = Vector{Float64}(undef, N)
    Threads.@threads :static for i in eachindex(Y)
        X[i] = rand()
        Y[i] = rand()
    end
    
    # warmup
    saxpy_kernel(a, X, Y)

    IntelITT.resume()
    t = Float64(Inf)
    for i in 1:10
        t_cur = @elapsed begin
            saxpy_kernel(a, X, Y)
            saxpy_kernel(a, X, Y)
        end
        t = min(t, t_cur/2)
    end
    IntelITT.pause()
    
    mem_rate = bytes * 1e-9 / t # GB/s
    flop_rate = flops * 1e-9 / t # GFLOP/s

    return mem_rate, flop_rate
end

measure_membw(; pin=:numa, init=:parallel)

Profiling via the GUI

Results

Command-line interface (CLI)

Useful commands:

vtune -report hotspots -r r000hs -group-by source-line > reports/hotspots.report
vtune -report top-down -r r000hs > reports/top_down.report
vtune -report callstacks -r r000hs > reports/callstacks.report

Check out the julia-intelvtune repository by Carsten Bauer which contains a basic demonstration.