From 86f71ee553b06411500cb789d034b54e8ff6913a Mon Sep 17 00:00:00 2001 From: chriselrod Date: Sun, 23 Jan 2022 16:20:50 -0500 Subject: [PATCH 01/21] Add option to put all tasks to sleep --- Project.toml | 2 +- src/threadtasks.jl | 16 +++++++++++++++- test/staticarrays.jl | 2 ++ test/threadingutilities.jl | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index ac2849e..2fa3a32 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ThreadingUtilities" uuid = "8290d209-cae3-49c0-8002-c8c24d57dab5" authors = ["Chris Elrod and contributors"] -version = "0.4.7" +version = "0.5.0" [deps] ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667" diff --git a/src/threadtasks.jl b/src/threadtasks.jl index c7bd3ce..dbb5b03 100644 --- a/src/threadtasks.jl +++ b/src/threadtasks.jl @@ -26,7 +26,6 @@ function (tt::ThreadTask)() while true if _atomic_state(p) == TASK _call(p) - _atomic_store!(p, SPIN) wait_counter = zero(UInt32) continue end @@ -39,6 +38,21 @@ function (tt::ThreadTask)() end end +function _sleep(p::Ptr{UInt}) + _atomic_store!(p, WAIT) + Base.wait() + return nothing +end + +function sleep_all_tasks() + for tid ∈ eachindex(TASKS) + fptr = @cfunction(_sleep, Cvoid, (Ptr{UInt},)) + p = taskpointer(tid) + ThreadingUtilities.store!(p, fptr, sizeof(UInt)) + _atomic_cas_cmp!(p, SPIN, TASK) + end +end + # 1-based tid, pushes into task 2-nthreads() @noinline function wake_thread!(_tid::T) where {T <: Integer} tid = _tid % Int diff --git a/test/staticarrays.jl b/test/staticarrays.jl index f82577b..5fa0f6c 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -3,6 +3,7 @@ struct MulStaticArray{P} end function (::MulStaticArray{P})(p::Ptr{UInt}) where {P} _, (ptry,ptrx) = ThreadingUtilities.load(p, P, 2*sizeof(UInt)) unsafe_store!(ptry, unsafe_load(ptrx) * 2.7) + ThreadingUtilities._atomic_store!(p, ThreadingUtilities.SPIN) nothing end @generated function mul_staticarray_ptr(::A, ::B) where {A,B} @@ -65,6 +66,7 @@ end Wans = A*2.7; Xans = B*2.7; Yans = C*2.7; Zans = waste_time(A, B) for i ∈ 1:100 # repeat rapdily W,X,Y,Z = mul_svector_threads(A, B, C) + iseven(i) && ThreadingUtilities.sleep_all_tasks() @test W == Wans @test X == Xans @test Y == Yans diff --git a/test/threadingutilities.jl b/test/threadingutilities.jl index 6215c1b..bc6767b 100644 --- a/test/threadingutilities.jl +++ b/test/threadingutilities.jl @@ -5,6 +5,7 @@ function (::Copy{P})(p::Ptr{UInt}) where {P} @simd ivdep for n ∈ 1:N unsafe_store!(ptry, unsafe_load(ptrx, n), n) end + ThreadingUtilities._atomic_store!(p, ThreadingUtilities.SPIN) end @generated function copy_ptr(::A, ::B) where {A,B} c = Copy{Tuple{A,B,Int}}() From bdd95b0ecd57d100a07f85f26de9b544a3fa6384 Mon Sep 17 00:00:00 2001 From: chriselrod Date: Sun, 23 Jan 2022 16:37:32 -0500 Subject: [PATCH 02/21] timeout 20 min --- .github/workflows/ci-julia-nightly.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-julia-nightly.yml b/.github/workflows/ci-julia-nightly.yml index eb12df8..b6f4701 100644 --- a/.github/workflows/ci-julia-nightly.yml +++ b/.github/workflows/ci-julia-nightly.yml @@ -17,7 +17,7 @@ on: - '.github/workflows/TagBot.yml' jobs: test-julia-nightly: - timeout-minutes: 10 + timeout-minutes: 20 name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 330fba1..cc71d4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: - '.github/workflows/TagBot.yml' jobs: test: - timeout-minutes: 10 + timeout-minutes: 20 name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: From 9be7960ce55e2e7a6aab0a55ad77b4b0540d72a6 Mon Sep 17 00:00:00 2001 From: chriselrod Date: Sun, 23 Jan 2022 16:42:21 -0500 Subject: [PATCH 03/21] run StaticArray tests --- test/runtests.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 79ffaf5..3ec8510 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,9 +4,7 @@ include("test-suite-preamble.jl") include("internals.jl") include("threadingutilities.jl") -if (!parse(Bool, get(ENV, "GITHUB_ACTIONS", "false"))) && Threads.nthreads() > 3 - include("staticarrays.jl") -end +include("staticarrays.jl") include("threadpool.jl") include("warnings.jl") From 36c89e56e79808b3a06d727fbc7653bd942b4798 Mon Sep 17 00:00:00 2001 From: chriselrod Date: Sun, 23 Jan 2022 16:49:26 -0500 Subject: [PATCH 04/21] use more threads on github actions --- src/ThreadingUtilities.jl | 3 ++- test/runtests.jl | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ThreadingUtilities.jl b/src/ThreadingUtilities.jl index 8fdd567..83702c9 100644 --- a/src/ThreadingUtilities.jl +++ b/src/ThreadingUtilities.jl @@ -45,7 +45,8 @@ if Sys.WORD_SIZE == 32 end function __init__() _print_exclusivity_warning() - nt = min(Threads.nthreads(), (Sys.CPU_THREADS)::Int) - 1 + sys_threads::Int = parse(Bool, get(ENV, "GITHUB_ACTIONS", "false")) ? Threads.nthreads() : (Sys.CPU_THREADS)::Int + nt = min(Threads.nthreads(), sys_threads) - 1 resize!(THREADPOOL, (THREADBUFFERSIZE ÷ sizeof(UInt)) * nt + (LINESPACING ÷ sizeof(UInt)) - 1) copyto!(THREADPOOL, zero(UInt)) # align to LINESPACING boundary, and then subtract THREADBUFFERSIZE to make the pointer 1-indexed diff --git a/test/runtests.jl b/test/runtests.jl index 3ec8510..2748b9b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,9 @@ include("test-suite-preamble.jl") include("internals.jl") include("threadingutilities.jl") -include("staticarrays.jl") +if Threads.nthreads() > 3 + include("staticarrays.jl") +end include("threadpool.jl") include("warnings.jl") From 835afcb1e3bbf3196a19c1c5e03d71f6071026d1 Mon Sep 17 00:00:00 2001 From: chriselrod Date: Sun, 23 Jan 2022 17:05:44 -0500 Subject: [PATCH 05/21] update for special handling of github actions --- test/threadpool.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/threadpool.jl b/test/threadpool.jl index 47ab8a1..06e50f8 100644 --- a/test/threadpool.jl +++ b/test/threadpool.jl @@ -1,6 +1,7 @@ @testset "THREADPOOL" begin - @test isconst(ThreadingUtilities, :THREADPOOL) # test that ThreadingUtilities.THREADPOOL is a constant - @test ThreadingUtilities.THREADPOOL isa Vector{UInt} - @test eltype(ThreadingUtilities.THREADPOOL) === UInt - @test length(ThreadingUtilities.THREADPOOL) == (ThreadingUtilities.THREADBUFFERSIZE÷sizeof(UInt)) * (min(Threads.nthreads(),(Sys.CPU_THREADS)::Int) - 1) + (256 ÷ sizeof(UInt)) - 1 + @test isconst(ThreadingUtilities, :THREADPOOL) # test that ThreadingUtilities.THREADPOOL is a constant + @test ThreadingUtilities.THREADPOOL isa Vector{UInt} + @test eltype(ThreadingUtilities.THREADPOOL) === UInt + sys_threads::Int = parse(Bool, get(ENV, "GITHUB_ACTIONS", "false")) ? Threads.nthreads() : (Sys.CPU_THREADS)::Int + @test length(ThreadingUtilities.THREADPOOL) == (ThreadingUtilities.THREADBUFFERSIZE÷sizeof(UInt)) * (min(Threads.nthreads(),sys_threads) - 1) + (256 ÷ sizeof(UInt)) - 1 end From b9f1719280f748377209b80fc00319a07abf7bbc Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Sun, 23 Jan 2022 17:45:40 -0500 Subject: [PATCH 06/21] bump timeout --- .github/workflows/ci-julia-nightly.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-julia-nightly.yml b/.github/workflows/ci-julia-nightly.yml index b6f4701..3eaf9a1 100644 --- a/.github/workflows/ci-julia-nightly.yml +++ b/.github/workflows/ci-julia-nightly.yml @@ -17,7 +17,7 @@ on: - '.github/workflows/TagBot.yml' jobs: test-julia-nightly: - timeout-minutes: 20 + timeout-minutes: 30 name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc71d4f..e0257b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: - '.github/workflows/TagBot.yml' jobs: test: - timeout-minutes: 20 + timeout-minutes: 30 name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: From f3e9678b46391f90c278930daae125c916542748 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Wed, 16 Feb 2022 00:04:24 -0500 Subject: [PATCH 07/21] fix x86 --- src/ThreadingUtilities.jl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ThreadingUtilities.jl b/src/ThreadingUtilities.jl index 83702c9..342d4ea 100644 --- a/src/ThreadingUtilities.jl +++ b/src/ThreadingUtilities.jl @@ -53,15 +53,6 @@ function __init__() THREADPOOLPTR[] = reinterpret(Ptr{UInt}, (reinterpret(UInt, pointer(THREADPOOL))+LINESPACING-1) & (-LINESPACING)) - THREADBUFFERSIZE resize!(TASKS, nt) foreach(initialize_task, 1:nt) - @static if Sys.WORD_SIZE == 32 - if nt > 0 - fptr = @cfunction(retnothing, Cvoid, (Ptr{UInt},)) - store!(taskpointer(1), fptr, sizeof(UInt)) - _atomic_xchg!(taskpointer(1), TASK) - wake_thread!(1) - wait(1) - end - end end end # module From d550c985a0b5442fd1501f0baa22538f603e1ade Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Wed, 16 Feb 2022 00:06:07 -0500 Subject: [PATCH 08/21] fix x86 Co-authored-by: Yingbo Ma --- src/threadtasks.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/threadtasks.jl b/src/threadtasks.jl index dbb5b03..f2b4d69 100644 --- a/src/threadtasks.jl +++ b/src/threadtasks.jl @@ -13,7 +13,8 @@ end @inline function launch(f::F, tid::Integer, args::Vararg{Any,K}) where {F,K} p = taskpointer(tid) f(p, args...) - state = _atomic_xchg!(p, TASK) # exchange must happen atomically, to prevent it from switching to `WAIT` after reading + # exchange must happen atomically, to prevent it from switching to `WAIT` after reading + state = _atomic_xchg!(p, TASK) state == WAIT && wake_thread!(tid) return nothing end From 7f19812a908321a14a2422ee86f9a68686454fcc Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Wed, 16 Feb 2022 00:15:16 -0500 Subject: [PATCH 09/21] Try to stop Windows from allocating Co-authored-by: Yingbo Ma --- test/staticarrays.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 5fa0f6c..29c846f 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -49,13 +49,17 @@ function mul_svector_threads(a::T, b::T, c::T) where {T} end rx[], ry[], rz[], w end +function count_allocated(a, b, c) + @allocated(mul_svector_threads(a,b,c)) +end + @testset "SVector Test" begin a = @SVector rand(16); b = @SVector rand(16); c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) - @test @allocated(mul_svector_threads(a, b, c)) == 0 + @test count_allocated(a, b, c) @test w == a*2.7 @test x == b*2.7 @test y == c*2.7 From a072eb23ccb07f5730f7d57d965871d982764db1 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Wed, 16 Feb 2022 08:26:20 -0500 Subject: [PATCH 10/21] Update staticarrays.jl --- test/staticarrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 29c846f..d23fc59 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -59,7 +59,7 @@ end b = @SVector rand(16); c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) - @test count_allocated(a, b, c) + @test count_allocated(a, b, c) == 0 @test w == a*2.7 @test x == b*2.7 @test y == c*2.7 From 3ec85905864c09ac7450f45a85b8203a4b1cd1ef Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Wed, 16 Feb 2022 08:37:54 -0500 Subject: [PATCH 11/21] Update ThreadingUtilities.jl --- src/ThreadingUtilities.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ThreadingUtilities.jl b/src/ThreadingUtilities.jl index 342d4ea..509bf23 100644 --- a/src/ThreadingUtilities.jl +++ b/src/ThreadingUtilities.jl @@ -40,9 +40,6 @@ function initialize_task(tid) return nothing end -if Sys.WORD_SIZE == 32 - retnothing(::Ptr{UInt}) = nothing -end function __init__() _print_exclusivity_warning() sys_threads::Int = parse(Bool, get(ENV, "GITHUB_ACTIONS", "false")) ? Threads.nthreads() : (Sys.CPU_THREADS)::Int From da0f80737eca7c3ac91f1e7c97611b920b04565f Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 00:16:24 -0500 Subject: [PATCH 12/21] Update staticarrays.jl --- test/staticarrays.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index d23fc59..36dd419 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -25,7 +25,7 @@ end function waste_time(a, b) s = a * b' - for i ∈ 1:00 + for i ∈ 1:0 s += a * b' end s @@ -59,7 +59,15 @@ end b = @SVector rand(16); c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) - @test count_allocated(a, b, c) == 0 + if Sys.iswindows() + if VERSION < v"1.6" && Sys.WORD_SIZE == 32 + @show count_allocated(a, b, c) + else + @test_broken count_allocated(a, b, c) == 0 + end + else + @test count_allocated(a, b, c) == 0 + end @test w == a*2.7 @test x == b*2.7 @test y == c*2.7 From 817e3d592e065c65cedac7554a7ade8c23d32f76 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 11:41:44 -0500 Subject: [PATCH 13/21] hoist @cfunction --- src/threadtasks.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/threadtasks.jl b/src/threadtasks.jl index f2b4d69..d02d14d 100644 --- a/src/threadtasks.jl +++ b/src/threadtasks.jl @@ -41,13 +41,13 @@ end function _sleep(p::Ptr{UInt}) _atomic_store!(p, WAIT) - Base.wait() + Base.wait(); return nothing end function sleep_all_tasks() + fptr = @cfunction(_sleep, Cvoid, (Ptr{UInt},)) for tid ∈ eachindex(TASKS) - fptr = @cfunction(_sleep, Cvoid, (Ptr{UInt},)) p = taskpointer(tid) ThreadingUtilities.store!(p, fptr, sizeof(UInt)) _atomic_cas_cmp!(p, SPIN, TASK) From c8a3f784e2aa5ab3e72b1d713af4a038695ff699 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 11:44:12 -0500 Subject: [PATCH 14/21] wait on tasks when sleeping all tasks --- src/threadtasks.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/threadtasks.jl b/src/threadtasks.jl index d02d14d..5475990 100644 --- a/src/threadtasks.jl +++ b/src/threadtasks.jl @@ -52,6 +52,9 @@ function sleep_all_tasks() ThreadingUtilities.store!(p, fptr, sizeof(UInt)) _atomic_cas_cmp!(p, SPIN, TASK) end + for tid ∈ eachindex(TASKS) + wait(tid) + end end # 1-based tid, pushes into task 2-nthreads() From 2b7d3b2b3ae08b96f7154c93f8713c9f05c673cb Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 12:05:59 -0500 Subject: [PATCH 15/21] test adjustments --- test/staticarrays.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 36dd419..030fdf3 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -60,8 +60,10 @@ end c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) if Sys.iswindows() - if VERSION < v"1.6" && Sys.WORD_SIZE == 32 + # if VERSION < v"1.6" && Sys.WORD_SIZE == 32 + if Sys.WORD_SIZE == 32 @show count_allocated(a, b, c) + @test count_allocated(a, b, c) == 0 else @test_broken count_allocated(a, b, c) == 0 end @@ -75,13 +77,15 @@ end A = @SMatrix rand(7,9); B = @SMatrix rand(7,9); C = @SMatrix rand(7,9); - Wans = A*2.7; Xans = B*2.7; Yans = C*2.7; Zans = waste_time(A, B) + Wans = A*2.7; Xans = B*2.7; Yans = C*2.7; for i ∈ 1:100 # repeat rapdily + C, A, B = A, B, C W,X,Y,Z = mul_svector_threads(A, B, C) iseven(i) && ThreadingUtilities.sleep_all_tasks() + (Yans, Wans, Xans) = Wans, Xans, Yans @test W == Wans @test X == Xans @test Y == Yans - @test Z ≈ Zans + @test Z ≈ waste_time(A, B) end end From da1a332dbebbcce689e3e85e4976f3bdb4dd63ca Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 12:17:27 -0500 Subject: [PATCH 16/21] Windows stopped allocating??? --- test/staticarrays.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 030fdf3..09dc48d 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -59,17 +59,17 @@ end b = @SVector rand(16); c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) - if Sys.iswindows() - # if VERSION < v"1.6" && Sys.WORD_SIZE == 32 - if Sys.WORD_SIZE == 32 - @show count_allocated(a, b, c) - @test count_allocated(a, b, c) == 0 - else - @test_broken count_allocated(a, b, c) == 0 - end - else - @test count_allocated(a, b, c) == 0 - end + # if Sys.iswindows() + # if VERSION < v"1.6" && Sys.WORD_SIZE == 32 + # @show count_allocated(a, b, c) + # @test count_allocated(a, b, c) == 0 + # else + # @test_broken count_allocated(a, b, c) == 0 + # end + # else + # @test count_allocated(a, b, c) == 0 + # end + @test count_allocated(a, b, c) == 0 @test w == a*2.7 @test x == b*2.7 @test y == c*2.7 From dba4f5b507cfbdb2d3158d2bb5921f903c6ba49c Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 12:45:30 -0500 Subject: [PATCH 17/21] try not testing allocations again --- test/staticarrays.jl | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 09dc48d..dd49621 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -49,7 +49,10 @@ function mul_svector_threads(a::T, b::T, c::T) where {T} end rx[], ry[], rz[], w end -function count_allocated(a, b, c) +function count_allocated() + a = @SVector rand(16); + b = @SVector rand(16); + c = @SVector rand(16); @allocated(mul_svector_threads(a,b,c)) end @@ -59,17 +62,8 @@ end b = @SVector rand(16); c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) - # if Sys.iswindows() - # if VERSION < v"1.6" && Sys.WORD_SIZE == 32 - # @show count_allocated(a, b, c) - # @test count_allocated(a, b, c) == 0 - # else - # @test_broken count_allocated(a, b, c) == 0 - # end - # else - # @test count_allocated(a, b, c) == 0 - # end - @test count_allocated(a, b, c) == 0 + count_allocated() + @test count_allocated() == 0 @test w == a*2.7 @test x == b*2.7 @test y == c*2.7 From 4a65d59fa2ec0a8dda2004dd5a46389f50450eea Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 12:52:51 -0500 Subject: [PATCH 18/21] BenchmarkTools --- Project.toml | 3 ++- test/staticarrays.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 2fa3a32..22488e4 100644 --- a/Project.toml +++ b/Project.toml @@ -13,9 +13,10 @@ julia = "1.5" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "InteractiveUtils", "StaticArrays", "Test"] +test = ["Aqua", "BenchmarkTools", "InteractiveUtils", "StaticArrays", "Test"] diff --git a/test/staticarrays.jl b/test/staticarrays.jl index dd49621..8de9528 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -53,7 +53,7 @@ function count_allocated() a = @SVector rand(16); b = @SVector rand(16); c = @SVector rand(16); - @allocated(mul_svector_threads(a,b,c)) + @ballocated(mul_svector_threads($a,$b,$c)) end From 6ff7c78bea26f5baef588f17948c08f71357fd0c Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 13:04:00 -0500 Subject: [PATCH 19/21] need to using BenchmarkTools --- test/staticarrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 8de9528..8891ac2 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -1,4 +1,4 @@ -using StaticArrays, ThreadingUtilities +using StaticArrays, ThreadingUtilities, BenchmarkTools struct MulStaticArray{P} end function (::MulStaticArray{P})(p::Ptr{UInt}) where {P} _, (ptry,ptrx) = ThreadingUtilities.load(p, P, 2*sizeof(UInt)) From 59de5fe4842d5e9eeedce6a4468a6ac8c017d6e7 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 13:04:40 -0500 Subject: [PATCH 20/21] i not used in loop --- test/staticarrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 8891ac2..2d3c410 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -25,7 +25,7 @@ end function waste_time(a, b) s = a * b' - for i ∈ 1:0 + for _ ∈ 1:0 s += a * b' end s From 39f293214993268d8a0eb5dc57d4c7a8cab76f25 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Thu, 17 Feb 2022 13:27:16 -0500 Subject: [PATCH 21/21] don't test allocated on Windows --- README.md | 3 +++ test/staticarrays.jl | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c8a3e3a..7338417 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,6 @@ Utilities for low overhead threading in Julia. Please see the [documentation](https://JuliaSIMD.github.io/ThreadingUtilities.jl/stable). + +If you're using Windows, please note that Windows often allocates memory when neither Mac or Linux do. I do not know why. If you can help diagnose/fix the problem, please take a look at `count_allocated()` in `/test/staticarrays.jl`. + diff --git a/test/staticarrays.jl b/test/staticarrays.jl index 2d3c410..366af15 100644 --- a/test/staticarrays.jl +++ b/test/staticarrays.jl @@ -63,7 +63,11 @@ end c = @SVector rand(16); w,x,y,z = mul_svector_threads(a, b, c) count_allocated() - @test count_allocated() == 0 + if !Sys.iswindows() + @test count_allocated() == 0 + else + @show count_allocated() + end @test w == a*2.7 @test x == b*2.7 @test y == c*2.7