Skip to content

Commit

Permalink
Test/fix FLoops.jl without reduce (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Mar 2, 2021
1 parent 064aba9 commit 86a13e5
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 25 deletions.
48 changes: 26 additions & 22 deletions src/transduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,34 @@ end
acc = next(rf, acc, x)
end

# combineblock
offsetb = (igl - 1) * groupsize()[1]
bound = max(0, nbasecases - offsetb)

# shared mem for a complete reduction
shared = @localmem(T, (2 * groupsize()[1]))
@inbounds shared[ill] = acc

m = ill - 1
t = ill
s = 1
c = nextpow(2, groupsize()[1]) >> 1
while c != 0
@synchronize
if t + s <= bound && iseven(m)
@inbounds shared[t] = _combine(rf, shared[t], shared[t+s])
m >>= 1
if Base.issingletontype(T)
# nothing to reduce (e.g., @floop w/o @reduce)
else
# combineblock
offsetb = (igl - 1) * groupsize()[1]
bound = max(0, nbasecases - offsetb)

# shared mem for a complete reduction
shared = @localmem(T, (2 * groupsize()[1]))
@inbounds shared[ill] = acc

m = ill - 1
t = ill
s = 1
c = nextpow(2, groupsize()[1]) >> 1
while c != 0
@synchronize
if t + s <= bound && iseven(m)
@inbounds shared[t] = _combine(rf, shared[t], shared[t+s])
m >>= 1
end
s <<= 1
c >>= 1
end
s <<= 1
c >>= 1
end

if t == 1
@inbounds dest[igl] = shared[1]
if t == 1
@inbounds dest[igl] = shared[1]
end
end
end

Expand Down
19 changes: 16 additions & 3 deletions test/device_tests.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
using FLoops
using Folds
using FoldsKernelAbstractions
using Referenceables
using Test

function inc!(xs, ex = nothing)
@floop ex for x in referenceable(xs)
x[] += 1
end
return xs
end

function test_size(
device;
groupsize,
basesize = 2,
extraitems = 0,
n = groupsize * basesize + extraitems,
)
@test Folds.sum(1:n, KAEx(device; groupsize, basesize)) == sum(1:n)
@test Folds.reduce(xor, 1:n, KAEx(device; groupsize, basesize); init = 0) ==
reduce(xor, 1:n; init = 0)
ex = KAEx(device; groupsize, basesize)

@test Folds.sum(1:n, ex) == sum(1:n)
@test Folds.reduce(xor, 1:n, ex; init = 0) == reduce(xor, 1:n; init = 0)

xs = FoldsKernelAbstractions.arrayfor(device)(1:n)
@test collect(inc!(xs, ex)) == 2:n+1
end

function test_sweep_sizes(device)
Expand Down
46 changes: 46 additions & 0 deletions test/environments/main/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ git-tree-sha1 = "48920211c95a6da1914a06c44ec94be70e84ffff"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.1.0"

[[ContextVariablesX]]
deps = ["Compat", "Logging", "UUIDs"]
git-tree-sha1 = "fc81d9dd4ffdafb56680f01e6d9db464a6b3689d"
uuid = "6add18c4-b38d-439d-96f6-d6bc489c04c5"
version = "0.1.1"

[[DataAPI]]
git-tree-sha1 = "dfb3b7e89e395be1e25c2ad6d7690dc29cc53b1d"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Expand Down Expand Up @@ -142,6 +148,18 @@ git-tree-sha1 = "10407a39b87f29d47ebaca8edbc75d7c302ff93e"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
version = "0.1.3"

[[FLoops]]
deps = ["Compat", "FLoopsBase", "JuliaVariables", "MLStyle", "Setfield", "Transducers"]
git-tree-sha1 = "e38ee2e0fdb95053d26593f92ffaa8353b9ff53f"
uuid = "cc61a311-1640-44b5-9fba-1b764f453329"
version = "0.1.6"

[[FLoopsBase]]
deps = ["ContextVariablesX"]
git-tree-sha1 = "cf3d8b2527be12d204d06aba922b30339a9653dd"
uuid = "b9860ae5-e623-471e-878b-f6a53c775ea6"
version = "0.1.0"

[[Folds]]
deps = ["Accessors", "BangBang", "DefineSingletons", "Distributed", "InitialValues", "MicroCollections", "Test", "Transducers"]
git-tree-sha1 = "1d508282913e9872b748088bea4a83726fcfdfed"
Expand Down Expand Up @@ -189,6 +207,12 @@ git-tree-sha1 = "a431f5f2ca3f4feef3bd7a5e94b8b8d4f2f647a0"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.2.0"

[[JuliaVariables]]
deps = ["MLStyle", "NameResolution"]
git-tree-sha1 = "e0fcfa0a2f6122fbe13603764c5310dde00c5593"
uuid = "b14d175d-62b4-44ba-8fb7-3064adc8c3ec"
version = "0.2.3"

[[KernelAbstractions]]
deps = ["Adapt", "Cassette", "InteractiveUtils", "MacroTools", "SpecialFunctions", "StaticArrays", "UUIDs"]
git-tree-sha1 = "39faf3047b6f03610d1a4a87071091be047e4681"
Expand Down Expand Up @@ -217,6 +241,11 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[MLStyle]]
git-tree-sha1 = "937eda9ce36fcce082a42edd7181c8d23f4eb550"
uuid = "d8e11817-5142-5d16-987a-aa16d5891078"
version = "0.4.6"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "6a8a2a625ab0dea913aba95c11370589e0239ff0"
Expand All @@ -242,6 +271,12 @@ git-tree-sha1 = "df42d0816edfc24f5b82a728f46381613c4dff79"
uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
version = "0.7.14"

[[NameResolution]]
deps = ["PrettyPrint"]
git-tree-sha1 = "1a0fa0e9613f46c9b8c11eee38ebb4f590013c5e"
uuid = "71a1bf82-56d0-4bbc-8a3c-48b961074391"
version = "0.1.5"

[[OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9db77584158d0ab52307f8c04f8e7c08ca76b5b3"
Expand All @@ -257,6 +292,11 @@ version = "1.4.0"
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PrettyPrint]]
git-tree-sha1 = "632eb4abab3449ab30c5e1afaa874f0b98b586e4"
uuid = "8162dcfd-2161-5ef2-ae6c-7681170c5f98"
version = "0.2.0"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand All @@ -274,6 +314,12 @@ git-tree-sha1 = "57d8440b0c7d98fc4f889e478e80f268d534c9d5"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.0.0"

[[Referenceables]]
deps = ["Adapt"]
git-tree-sha1 = "8502ffd7a930b89a5bd612e748d65897955fafcc"
uuid = "42d2dcc6-99eb-4e98-b66c-637b7d73030e"
version = "0.1.1"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "cfbac6c1ed70c002ec6361e7fd334f02820d6419"
Expand Down
2 changes: 2 additions & 0 deletions test/environments/main/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDAKernels = "72cfdca4-0801-4ab0-bf6a-d52aa10adc57"
FLoops = "cc61a311-1640-44b5-9fba-1b764f453329"
Folds = "41a02a25-b8f0-4f67-bc48-60067656b558"
FoldsKernelAbstractions = "52461acb-21f3-48fe-a5ec-9a226775d6ac"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
Referenceables = "42d2dcc6-99eb-4e98-b66c-637b7d73030e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import CUDA
const TEST_CUDA = CUDA.has_cuda_gpu()
const TEST_GPU = TEST_CUDA

TEST_CUDA && CUDA.allowscalar(false)

find_test(subdir = "") = sort([
joinpath(subdir, file) for file in readdir(joinpath(@__DIR__, subdir)) if
match(r"^test_.*\.jl$", file) !== nothing
Expand Down

0 comments on commit 86a13e5

Please sign in to comment.