Skip to content

Commit

Permalink
recording and parameter functions (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbauer committed Jan 27, 2023
1 parent aacf427 commit f151c91
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 54 deletions.
6 changes: 3 additions & 3 deletions example/usercode_no_init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ end
# warmup
workload(10, 1)

@scorep_user_region_stored "matmul" workload(500)
@scorep_user_region_stored "matmul large" workload(5000)
@scorep_user_region_stored "matmuls multithreaded" workload_multithreaded(500)
@scorep_user_region "matmul" workload(500)
@scorep_user_region "matmul large" workload(5000)
@scorep_user_region "matmuls multithreaded" workload_multithreaded(500)
6 changes: 5 additions & 1 deletion src/LibScoreP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,11 @@ const SCOREP_TAU_INIT_METRIC_HANDLE = SCOREP_INVALID_SAMPLING_SET

const SCOREP_Tau_ParamHandle = SCOREP_User_ParameterHandle

const SCOREP_USER_INVALID_PARAMETER = -1
# const SCOREP_USER_INVALID_PARAMETER = -1
const SCOREP_USER_INVALID_PARAMETER = typemax(UInt64)
# TODO: is this the same as
# uint64_t x = -1;
# cout << x # gives 18446744073709551615

const SCOREP_TAU_INIT_PARAM_HANDLE = SCOREP_USER_INVALID_PARAMETER

Expand Down
3 changes: 1 addition & 2 deletions src/ScoreP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ include("subsystem.jl")
include("main.jl")

export LibScoreP,
@scorep_user_region,
@scorep_user_region_stored
@scorep_user_region

end # module ScoreP
120 changes: 72 additions & 48 deletions src/jlwrapper.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
SCOREP_User_LastFileHandle::LibScoreP.SCOREP_SourceFileHandle = LibScoreP.SCOREP_INVALID_SOURCE_FILE

regions = Dict{String, LibScoreP.SCOREP_User_RegionHandle}()

function region_begin_stored(region_name::String;
module_name = string(@__MODULE__),
file = @__FILE__,
line = @__LINE__,
type = LibScoreP.SCOREP_USER_REGION_TYPE_COMMON)
if !(region_name in keys(regions))
handle_ref = Ref(LibScoreP.SCOREP_USER_INVALID_REGION)
LibScoreP.SCOREP_User_RegionInit(handle_ref,
C_NULL,
Ref(SCOREP_User_LastFileHandle),
region_name,
type,
file,
line)
LibScoreP.SCOREP_User_RegionSetGroup(handle_ref[], module_name)
handle = handle_ref[]
regions[region_name] = handle
else
handle = regions[region_name]
end
LibScoreP.SCOREP_User_RegionEnter(handle)
return nothing
end

function region_end_stored(region_name::String)
handle = regions[region_name]
LibScoreP.SCOREP_User_RegionEnd(handle)
return nothing
end

function region_begin(region_name::String;
handle = LibScoreP.SCOREP_USER_INVALID_REGION,
file = @__FILE__,
Expand All @@ -53,6 +19,28 @@ function region_end(handle::LibScoreP.SCOREP_User_RegionHandle)
return nothing
end

enable_recording() = LibScoreP.SCOREP_User_EnableRecording()
disable_recording() = LibScoreP.SCOREP_User_DisableRecording()
isrecording() = LibScoreP.SCOREP_User_RecordingEnabled()

function parameter_int(name, value::Int)
param_ref = Ref(LibScoreP.SCOREP_USER_INVALID_PARAMETER)
LibScoreP.SCOREP_User_ParameterInt64(param_ref, name, value)
return nothing
end

function parameter_uint(name, value::UInt)
param_ref = Ref(LibScoreP.SCOREP_USER_INVALID_PARAMETER)
LibScoreP.SCOREP_User_ParameterUint64(param_ref, name, value)
return nothing
end

function parameter_string(name, value::AbstractString)
param_ref = Ref(LibScoreP.SCOREP_USER_INVALID_PARAMETER)
LibScoreP.SCOREP_User_ParameterString(param_ref, name, value)
return nothing
end

# macros / wrapper functions

function scorep_user_region(f, region_name; kwargs...)
Expand All @@ -74,17 +62,53 @@ macro scorep_user_region(region_name, expr)
return esc(q)
end

macro scorep_user_region_stored(region_name, expr)
mod = string(__module__)
file = string(__source__.file)
line = __source__.line
q = quote
ScoreP.region_begin_stored($(region_name);
module_name = $mod,
line = $line,
file = $file)
$expr
ScoreP.region_end_stored($(region_name))
end
return esc(q)
end
# ---- Global handle storage ----

# SCOREP_User_LastFileHandle::LibScoreP.SCOREP_SourceFileHandle = LibScoreP.SCOREP_INVALID_SOURCE_FILE

# regions = Dict{String, LibScoreP.SCOREP_User_RegionHandle}()

# function region_begin_stored(region_name::String;
# module_name = string(@__MODULE__),
# file = @__FILE__,
# line = @__LINE__,
# type = LibScoreP.SCOREP_USER_REGION_TYPE_COMMON)
# if !(region_name in keys(regions))
# handle_ref = Ref(LibScoreP.SCOREP_USER_INVALID_REGION)
# LibScoreP.SCOREP_User_RegionInit(handle_ref,
# C_NULL,
# Ref(SCOREP_User_LastFileHandle),
# region_name,
# type,
# file,
# line)
# LibScoreP.SCOREP_User_RegionSetGroup(handle_ref[], module_name)
# handle = handle_ref[]
# regions[region_name] = handle
# else
# handle = regions[region_name]
# end
# LibScoreP.SCOREP_User_RegionEnter(handle)
# return nothing
# end

# function region_end_stored(region_name::String)
# handle = regions[region_name]
# LibScoreP.SCOREP_User_RegionEnd(handle)
# return nothing
# end

# macro scorep_user_region_stored(region_name, expr)
# mod = string(__module__)
# file = string(__source__.file)
# line = __source__.line
# q = quote
# ScoreP.region_begin_stored($(region_name);
# module_name = $mod,
# line = $line,
# file = $file)
# $expr
# ScoreP.region_end_stored($(region_name))
# end
# return esc(q)
# end

0 comments on commit f151c91

Please sign in to comment.