From f151c91cf43addee85202b8c021671fb5b0ce47e Mon Sep 17 00:00:00 2001 From: Carsten Bauer Date: Fri, 27 Jan 2023 15:49:06 +0100 Subject: [PATCH] recording and parameter functions (#5) --- example/usercode_no_init.jl | 6 +- src/LibScoreP.jl | 6 +- src/ScoreP.jl | 3 +- src/jlwrapper.jl | 120 +++++++++++++++++++++--------------- 4 files changed, 81 insertions(+), 54 deletions(-) diff --git a/example/usercode_no_init.jl b/example/usercode_no_init.jl index b3f66a2..8b95302 100644 --- a/example/usercode_no_init.jl +++ b/example/usercode_no_init.jl @@ -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) diff --git a/src/LibScoreP.jl b/src/LibScoreP.jl index 8891117..cde593b 100644 --- a/src/LibScoreP.jl +++ b/src/LibScoreP.jl @@ -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 diff --git a/src/ScoreP.jl b/src/ScoreP.jl index af0dcdd..3dab2ea 100644 --- a/src/ScoreP.jl +++ b/src/ScoreP.jl @@ -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 diff --git a/src/jlwrapper.jl b/src/jlwrapper.jl index d8886e1..66f5a56 100644 --- a/src/jlwrapper.jl +++ b/src/jlwrapper.jl @@ -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__, @@ -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...) @@ -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