-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add experimental support for customisable benchmarking #347
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
We might need to set up Buildkite CI on this repo. @vchuravy @staticfloat |
f27a5de
to
bbfb733
Compare
This comment was marked as outdated.
This comment was marked as outdated.
cfa2cef
to
fb0b711
Compare
b1bc53c
to
468b607
Compare
I'd like to mark this feature as experimental or something to that effect so that we can make breaking changes to it without making a breaking change to BenchmarkTools. I'll make a separate pr removing Buildkite. I've moved the LinuxPerf stuff to https://github.com/Zentrik/BenchmarkToolsPlusLinuxPerf.jl. I do have a version of bprofile_setup_prehook(_) = Profile.check_init()
function bprofile_prehook()
results = samplefunc_prehook()
status = ccall(:jl_profile_start_timer, Cint, ())
if status < 0
error(Profile.error_codes[status])
end
return results
end
function bprofile_posthook()
Profile.stop_timer()
return samplefunc_posthook()
end
# """
# @bprofile expression [other parameters...]
# Run `@benchmark` while profiling. This is similar to
# @profile @benchmark expression [other parameters...]
# but the profiling is applied only to the main
# execution (after compilation and tuning).
# The profile buffer is cleared prior to execution.
# View the profile results with `Profile.print(...)`.
# See the profiling section of the Julia manual for more
# information.
# """
macro bprofile(args...)
_, params = prunekwargs(args...)
if !haskw(args, :gctrial)
args = (args..., Expr(:kw, :gctrial, false))
end
if !haskw(args, :gcsample)
args = (args..., Expr(:kw, :gcsample, false))
end
tmp = gensym()
return esc(
quote
local $tmp = $BenchmarkTools.@benchmarkable $(args...)
$(
if hasevals(params)
:(run(
$tmp, $BenchmarkTools.Parameters($tmp.params; evals=1); warmup=false
))
else
:($BenchmarkTools.tune!($tmp))
end
)
$BenchmarkTools.Profile.stop_timer()
$BenchmarkTools.Profile.clear()
$BenchmarkTools.run(
$tmp;
setup_prehook=$BenchmarkTools.bprofile_setup_prehook,
prehook=$BenchmarkTools.bprofile_prehook,
posthook=$BenchmarkTools.bprofile_posthook,
sample_result=$BenchmarkTools.samplefunc_sample_result,
enable_customisable_func=:ALL,
run_customisable_func_only=true,
)
end,
)
end |
This should theoretically allow FunctionWrappers or callable structs to be used, though serialization may be an issue.
Fairly late to the game here, but I would find something like this useful. |
@vchuravy I agree, it would be nice to avoid code duplication, and I wonder if this PR could be achieved using functions as arguments. |
Is the code duplication concern referring to the changes in parameters.jl? |
apologies for my delayed review as I finished up my graduate studies. I would also like to see linuxperf working here. When I discuss duplicated code, I'm referring to how this PR uses several kwargs with similar names, such as
as well as several repetitions of things like
I don't know whether it is possible to make a simpler and hopefully more modular approach just yet, but I'd like to try! By "using functions as arguments", I was insufficiently gesturing at something like the following approach (let me know whether you think this would work): To benchmark the function
Then we would wrap this in the standard timing infrastructure
Then, if a user wishes to produce a custom benchmarking function, they might do
And at the end of the day, we would have a BenchmarkResult with a namedtuple of attributes, which might include things like cpu counts and sampling profilers. Perhaps we could use a more involved approach using wrapper objects instead of wrapper functions, and call methods like Would this approach be something that would support both profiling and LinuxPerf-ing? |
No worries for the delay, thanks for the review, you do raise some good points. But anyways I'm fairly busy now so if we're going to move forward with #375 then I'm not going to bother working on this. Thanks again for all the time you've put into this. |
Replaces #325 (closes #325)
This pr adds the ability to run a custom benchmarking function which has hooks to inject in custom functions. The current design supports running
perf
on a benchmark (see https://github.com/Zentrik/BenchmarkToolsPlusLinuxPerf.jl) and profiling benchmarks (excluding the setup, teardown and gcscrub which the currentbprofile
includes).