Skip to content

Commit 8e44ef0

Browse files
committed
fix exercise 03
1 parent 60db0d9 commit 8e44ef0

File tree

4 files changed

+584
-2023
lines changed

4 files changed

+584
-2023
lines changed

additional/profiling_accelerated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ md"""
3232
# ╔═╡ d74c49ed-eaf2-4c2e-a1f9-0139d349eccf
3333
md"""
3434
Also available on Google Colab:
35-
[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vchuravy/rse-course/blob/main/src/mod3_parallelism/Introduction_to_KernelAbstractions.ipynb)
35+
[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hpsc-lab/spp2256-software-dev/blob/main/notebooks/Introduction_to_KernelAbstractions.ipynb)
3636
"""
3737

3838
# ╔═╡ 3acfbfad-1233-4e08-a7d4-66508dad8c0d

exercise_03_intro_accelerated.jl

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ PlutoUI.TableOfContents(; depth=4)
5151
# ╔═╡ 8577787d-d72d-4d92-8c69-9e516a85b779
5252
ChooseDisplayMode()
5353

54+
# ╔═╡ 30d8b257-4694-4bc3-b38c-54929c1c5c1b
55+
md"""
56+
Also available on Google Colab:
57+
[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hpsc-lab/spp2256-software-dev/blob/main/notebooks/Introduction_to_Accelerated_Computing.ipynb)
58+
"""
59+
5460
# ╔═╡ d4c35d94-5a04-43a3-99b4-c8e9f05a2d5e
5561
md"""
5662
# Exercise: Introduction to accelerated computing
@@ -256,17 +262,21 @@ end
256262
end
257263

258264
# ╔═╡ aa2d455e-c9fc-4a7b-b50e-77709481c2a7
259-
function heat_2D!(du, u, (a, dx, dy), t)
265+
function heat_2D!(du, u, (a, dx, dy, xs, ys), t)
260266
N, M = size(u)
261267
N = N - 2
262268
M = M - 2
263269

264270
# update boundary condition (wrap around)
265-
u[0, :] .= u[N, :]
266-
u[N+1, :] .= u[1, :]
267-
u[:, 0] .= u[:, N]
268-
u[:, N+1] .= u[:, 0]
271+
u[1, :] .= u[N+1, :]
272+
u[N+2, :] .= u[2, :]
273+
u[:, 1] .= u[:, N+1]
274+
u[:, N+2] .= u[:, 1]
269275

276+
# OffsetArray and CUDA don't compose neatly :/
277+
u = OffsetArray(u, xs, ys)
278+
du = OffsetArray(u, xs, ys)
279+
270280
kernel = heat_2D_kernel!(get_backend(du))
271281
kernel(du, u, a, dx, dy; ndrange=(N,M))
272282

@@ -291,20 +301,21 @@ begin
291301
xs = 0:(N+1)
292302
ys = 0:(N+1)
293303

294-
u₀ = OffsetArray(
295-
KernelAbstractions.zeros(
304+
u₀ = KernelAbstractions.zeros(
296305
backend, Float32, N+2, N+2)
297-
, xs, ys)
298-
parent(u₀)[16:32, 16:32] .= 5
306+
u₀[16:32, 16:32] .= 5
299307

300308
nothing
301309
end
302310

303311
# ╔═╡ cdf61aff-ec98-4174-9d48-c287977742cb
304-
prob = ODEProblem(heat_2D!, u₀, (0.0, t_final), (a, dx, dy));
312+
prob = ODEProblem(heat_2D!, u₀, (0.0, t_final), (a, dx, dy, xs, ys));
305313

306314
# ╔═╡ 8e963ae6-06fd-47fc-a1de-e884468de234
307-
sol = solve(prob, Tsit5(), saveat=0.2);
315+
begin
316+
CUDA.allowscalar(false)
317+
sol = solve(prob, Tsit5(), saveat=0.2);
318+
end
308319

309320
# ╔═╡ 78f7884c-3523-4d96-9dfc-fbe9de36a86b
310321
let
@@ -2816,6 +2827,7 @@ version = "4.1.0+0"
28162827
# ╟─75b9bee9-7d03-4c90-b828-43e9e946517b
28172828
# ╟─3e5c3c97-4401-41d4-a701-d9b24f9acdc6
28182829
# ╟─8577787d-d72d-4d92-8c69-9e516a85b779
2830+
# ╟─30d8b257-4694-4bc3-b38c-54929c1c5c1b
28192831
# ╟─d4c35d94-5a04-43a3-99b4-c8e9f05a2d5e
28202832
# ╠═51588c4c-2b03-4ff2-b64e-7fd2e3bef81c
28212833
# ╠═91f3684d-ed56-4ee2-b914-79ab4b6ed87a

0 commit comments

Comments
 (0)