Skip to content

Commit 41f015a

Browse files
authored
Merge pull request #120 from FourierFlows/ImplementCUDAapi
Implement CUDAapi
2 parents 473ca09 + 555742a commit 41f015a

File tree

9 files changed

+121
-27
lines changed

9 files changed

+121
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
docs/build/
1313
docs/site/
1414
coverage/
15+
docs/Manifest.toml

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ os:
55
- linux
66

77
julia:
8-
- 1.1
8+
- 1.2
99
- nightly
1010

1111
matrix:
@@ -19,7 +19,7 @@ after_success:
1919
jobs:
2020
include:
2121
- stage: "Documentation"
22-
julia: 1.1
22+
julia: 1.2
2323
os: linux
2424
script:
2525
- julia --project=docs/ -e 'using Pkg; Pkg.instantiate();

Manifest.toml

Lines changed: 95 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ git-tree-sha1 = "380e36c66edfa099cd90116b24c1ce8cafccac40"
66
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
77
version = "0.4.1"
88

9+
[[Adapt]]
10+
deps = ["LinearAlgebra"]
11+
git-tree-sha1 = "82dab828020b872fa9efd3abec1152b075bc7cbf"
12+
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
13+
version = "1.0.0"
14+
915
[[AxisAlgorithms]]
1016
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
1117
git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9"
@@ -21,6 +27,35 @@ git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648"
2127
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
2228
version = "0.5.6"
2329

30+
[[CEnum]]
31+
git-tree-sha1 = "62847acab40e6855a9b5905ccb99c2b5cf6b3ebb"
32+
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
33+
version = "0.2.0"
34+
35+
[[CSTParser]]
36+
deps = ["Tokenize"]
37+
git-tree-sha1 = "c69698c3d4a7255bc1b4bc2afc09f59db910243b"
38+
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
39+
version = "0.6.2"
40+
41+
[[CUDAapi]]
42+
deps = ["Libdl", "Logging"]
43+
git-tree-sha1 = "9b2b4b71d6b7f946c9689bb4dea03ff92e3c7091"
44+
uuid = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3"
45+
version = "1.1.0"
46+
47+
[[CUDAdrv]]
48+
deps = ["CUDAapi", "Libdl", "Printf"]
49+
git-tree-sha1 = "9ce99b5732c70e06ed97c042187baed876fb1698"
50+
uuid = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde"
51+
version = "3.1.0"
52+
53+
[[CUDAnative]]
54+
deps = ["Adapt", "CUDAapi", "CUDAdrv", "DataStructures", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Printf", "TimerOutputs"]
55+
git-tree-sha1 = "0a00bef482b7c9127495c7f4a2a85e73b13b5af8"
56+
uuid = "be33ccc6-a3ff-5ff2-a52e-74243cff1e17"
57+
version = "2.3.0"
58+
2459
[[CodecZlib]]
2560
deps = ["BinaryProvider", "Libdl", "TranscodingStreams"]
2661
git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e"
@@ -45,6 +80,18 @@ git-tree-sha1 = "f9780daf3fea51ad2d7b7ed4f480ac34ab36587f"
4580
uuid = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
4681
version = "0.9.2"
4782

83+
[[Crayons]]
84+
deps = ["Test"]
85+
git-tree-sha1 = "f621b8ef51fd2004c7cf157ea47f027fdeac5523"
86+
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
87+
version = "4.0.0"
88+
89+
[[CuArrays]]
90+
deps = ["AbstractFFTs", "Adapt", "CUDAapi", "CUDAdrv", "CUDAnative", "GPUArrays", "LinearAlgebra", "MacroTools", "NNlib", "Printf", "Random", "Requires", "SparseArrays", "TimerOutputs"]
91+
git-tree-sha1 = "46b48742a84bb839e74215b7e468a4a1c6ba30f9"
92+
uuid = "3a865a2d-5b23-5a0f-bc46-62713ec82fae"
93+
version = "1.2.1"
94+
4895
[[DataStructures]]
4996
deps = ["InteractiveUtils", "OrderedCollections"]
5097
git-tree-sha1 = "0809951a1774dc724da22d26e4289bbaab77809a"
@@ -75,11 +122,23 @@ git-tree-sha1 = "351f001a78aa1b7ad2696e386e110b5abd071c71"
75122
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
76123
version = "1.0.7"
77124

125+
[[FillArrays]]
126+
deps = ["LinearAlgebra", "Random", "SparseArrays"]
127+
git-tree-sha1 = "8fba6ddaf66b45dec830233cea0aae43eb1261ad"
128+
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
129+
version = "0.6.4"
130+
131+
[[GPUArrays]]
132+
deps = ["Adapt", "FFTW", "FillArrays", "LinearAlgebra", "Printf", "Random", "Serialization", "StaticArrays", "Test"]
133+
git-tree-sha1 = "dd169c636d1d3656a9faca772f5bd7c226a61254"
134+
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
135+
version = "1.0.1"
136+
78137
[[HTTP]]
79138
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"]
80-
git-tree-sha1 = "03ddc88af7f2d963fac5aa9f3ac8e11914d68a78"
139+
git-tree-sha1 = "c4a527dba1d26add0e85946e1a53f42a1b343acc"
81140
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
82-
version = "0.8.4"
141+
version = "0.8.5"
83142

84143
[[IniFile]]
85144
deps = ["Test"]
@@ -109,6 +168,12 @@ git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
109168
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
110169
version = "0.21.0"
111170

171+
[[LLVM]]
172+
deps = ["CEnum", "Libdl", "Printf", "Unicode"]
173+
git-tree-sha1 = "52cfea426bd248a427aace7d88eb5d45b84ea297"
174+
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
175+
version = "1.2.0"
176+
112177
[[LibGit2]]
113178
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
114179

@@ -122,19 +187,31 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
122187
[[Logging]]
123188
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
124189

190+
[[MacroTools]]
191+
deps = ["CSTParser", "Compat", "DataStructures", "Test", "Tokenize"]
192+
git-tree-sha1 = "d6e9dedb8c92c3465575442da456aec15a89ff76"
193+
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
194+
version = "0.5.1"
195+
125196
[[Markdown]]
126197
deps = ["Base64"]
127198
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
128199

129200
[[MbedTLS]]
130-
deps = ["BinaryProvider", "Dates", "Distributed", "Libdl", "Random", "Sockets", "Test"]
131-
git-tree-sha1 = "2d94286a9c2f52c63a16146bb86fd6cdfbf677c6"
201+
deps = ["BinaryProvider", "Dates", "Libdl", "Random", "Sockets"]
202+
git-tree-sha1 = "85f5947b53c8cfd53ccfa3f4abae31faa22c2181"
132203
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
133-
version = "0.6.8"
204+
version = "0.7.0"
134205

135206
[[Mmap]]
136207
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
137208

209+
[[NNlib]]
210+
deps = ["Libdl", "LinearAlgebra", "Requires", "Statistics", "TimerOutputs"]
211+
git-tree-sha1 = "0c667371391fc6bb31f7f12f96a56a17098b3de8"
212+
uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
213+
version = "0.6.0"
214+
138215
[[OffsetArrays]]
139216
git-tree-sha1 = "1af2f79c7eaac3e019a0de41ef63335ff26a0a57"
140217
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
@@ -148,9 +225,9 @@ version = "1.1.0"
148225

149226
[[Parsers]]
150227
deps = ["Dates", "Test"]
151-
git-tree-sha1 = "db2b35dedab3c0e46dc15996d170af07a5ab91c9"
228+
git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b"
152229
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
153-
version = "0.3.6"
230+
version = "0.3.7"
154231

155232
[[Pkg]]
156233
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
@@ -217,6 +294,17 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
217294
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
218295
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
219296

297+
[[TimerOutputs]]
298+
deps = ["Crayons", "Printf", "Test", "Unicode"]
299+
git-tree-sha1 = "b80671c06f8f8bae08c55d67b5ce292c5ae2660c"
300+
uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
301+
version = "0.5.0"
302+
303+
[[Tokenize]]
304+
git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf"
305+
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
306+
version = "0.5.6"
307+
220308
[[TranscodingStreams]]
221309
deps = ["Random", "Test"]
222310
git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c"

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ authors = ["Gregory L. Wagner <wagner.greg@gmail.com>", "Navid C. Constantinou <
66
description = "Tools for solving partial differential equations on periodic domains using Fourier-based pseudospectral methods."
77
documentation = "https://fourierflows.github.io/FourierFlows.jl/dev/"
88
repository = "https://github.com/FourierFlows/FourierFlows.jl"
9-
version ="0.3.1"
9+
version = "0.3.1"
1010
versions = ["0.0.1", "0.0.2", "0.1.0", "0.1.1", "0.1.2", "0.1.3", "0.2.0", "0.2.1", "0.2.2", "0.3.0", "0.3.1"]
1111

1212
[deps]
13+
CUDAapi = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3"
1314
Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
15+
CuArrays = "3a865a2d-5b23-5a0f-bc46-62713ec82fae"
1416
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1517
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1618
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
@@ -22,14 +24,14 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2224
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2325

2426
[compat]
27+
CuArrays = "≥ 1.2.1"
2528
FFTW = "≥ 0.2.4"
2629
Interpolations = "≥ 0.8.0"
2730
JLD2 = "≥ 0.1.2"
2831
julia = "≥ 0.7.0"
2932

3033
[extras]
31-
CuArrays = "3a865a2d-5b23-5a0f-bc46-62713ec82fae"
3234
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3335

3436
[targets]
35-
test = ["Test", "CuArrays"]
37+
test = ["Test"]

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
environment:
22
matrix:
3-
- julia_version: 1
3+
- julia_version: 1.2
44
- julia_version: nightly
55

66
platform:

src/FourierFlows.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ module FourierFlows
22

33
export
44
# Helper variables and macros for determining if machine is CUDA-enabled.
5-
HAVE_CUDA,
6-
@hascuda,
5+
@has_cuda,
76

87
Device,
98
CPU,
@@ -59,6 +58,7 @@ using
5958
JLD2,
6059
Statistics,
6160
Interpolations,
61+
CUDAapi,
6262
Requires
6363

6464
import Base: resize!, getindex, setindex!, lastindex, push!, append!
@@ -89,15 +89,18 @@ include("timesteppers.jl")
8989
include("diffusion.jl")
9090

9191
# Import CUDA utilities if cuda is detected.
92-
const HAVE_CUDA = try
93-
using CuArrays
94-
true
95-
catch
96-
false
92+
if has_cuda()
93+
try
94+
using CuArrays # we have CUDA, so this should not fail
95+
catch ex
96+
# something is wrong with the user's set-up (or there's a bug in CuArrays)
97+
@warn "CUDA is installed, but CuArrays.jl fails to load" exception=(ex, catch_backtrace())
98+
end
9799
end
98100

99-
macro hascuda(ex)
100-
return HAVE_CUDA ? :($(esc(ex))) : :(nothing)
101+
102+
macro has_cuda(ex)
103+
return has_cuda() ? :($(esc(ex))) : :(nothing)
101104
end
102105

103106

src/diffusion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Params(dev, kappa::Number) = Params(kappa)
4545
Params(dev, kappa::AbstractArray) = Params(ArrayType(dev)(kappa))
4646

4747
"""
48-
Equation(p, g)
48+
DiffusionEquation(dev, kappa, grid)
4949
50-
Returns the equation for constant diffusivity problem with params p and grid g.
50+
Returns the equation for constant diffusivity problem with diffusivity kappa and grid.
5151
"""
5252
function DiffusionEquation(dev::Device, kappa::T, grid) where T<:Number
5353
L = zeros(dev, T, grid.nkr)

test/createffttestfunctions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function create_testfuncs(g::TwoDGrid{Tg,<:Array}) where Tg
8686
f₁, f₂, f₁h, f₂h, f₁hr, f₂hr, f₁hr_mul, f₂hr_mul, f₁h_analytical, f₁hr_analytical, f₂h_analytical, f₂hr_analytical
8787
end
8888

89-
@hascuda begin
89+
@has_cuda begin
9090
function create_testfuncs(g::OneDGrid{Tg, <:CuArray}) where Tg
9191
cpugrid = OneDGrid(g.nx, g.Lx)
9292
out = create_testfuncs(cpugrid)

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ using LinearAlgebra: mul!, ldiv!, norm
1313

1414
# the devices on which tests will run
1515
devices = (CPU(),)
16-
@hascuda devices = (CPU(), GPU())
17-
@hascuda using CuArrays
16+
@has_cuda devices = (CPU(), GPU())
17+
@has_cuda using CuArrays
1818

1919
const rtol_fft = 1e-12
2020
const rtol_output = 1e-12

0 commit comments

Comments
 (0)