-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from JuliaAI/acceleration-testing
Add tests for CPUThreads and CPUProceses
- Loading branch information
Showing
3 changed files
with
82 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,26 @@ | ||
include("_models.jl") | ||
using Distributed | ||
# Thanks to https://stackoverflow.com/a/70895939/5056635 for the exeflags tip. | ||
addprocs(; exeflags="--project=$(Base.active_project())") | ||
|
||
@info "nprocs() = $(nprocs())" | ||
import .Threads | ||
@info "nthreads() = $(Threads.nthreads())" | ||
|
||
include("test_utilities.jl") | ||
include_everywhere("_models.jl") | ||
|
||
@everywhere begin | ||
using Test | ||
using Random | ||
using StableRNGs | ||
using MLJEnsembles | ||
using MLJBase | ||
using ..Models | ||
using CategoricalArrays | ||
import Distributions | ||
using StatisticalMeasures | ||
import Distributed | ||
end | ||
|
||
include("ensembles.jl") | ||
include("serialization.jl") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Test | ||
|
||
using ComputationalResources | ||
|
||
macro testset_accelerated(name::String, var, ex) | ||
testset_accelerated(name, var, ex) | ||
end | ||
macro testset_accelerated(name::String, var, opts::Expr, ex) | ||
testset_accelerated(name, var, ex; eval(opts)...) | ||
end | ||
function testset_accelerated(name::String, var, ex; exclude=[]) | ||
final_ex = quote | ||
local $var = CPU1() | ||
@testset $name $ex | ||
end | ||
|
||
resources = AbstractResource[CPUProcesses(), CPUThreads()] | ||
|
||
for res in resources | ||
if any(x->typeof(res)<:x, exclude) | ||
push!(final_ex.args, quote | ||
local $var = $res | ||
@testset $(name*" ($(typeof(res).name))") begin | ||
@test_broken false | ||
end | ||
end) | ||
else | ||
push!(final_ex.args, quote | ||
local $var = $res | ||
@testset $(name*" ($(typeof(res).name))") $ex | ||
end) | ||
end | ||
end | ||
# preserve outer location if possible | ||
if ex isa Expr && ex.head === :block && !isempty(ex.args) && | ||
ex.args[1] isa LineNumberNode | ||
final_ex = Expr(:block, ex.args[1], final_ex) | ||
end | ||
return esc(final_ex) | ||
end | ||
|
||
function include_everywhere(filepath) | ||
include(filepath) # Load on Node 1 first, triggering any precompile | ||
if nprocs() > 1 | ||
fullpath = joinpath(@__DIR__, filepath) | ||
@sync for p in workers() | ||
@async remotecall_wait(include, p, fullpath) | ||
end | ||
end | ||
end |