Skip to content

Commit 09f5a6a

Browse files
committed
Make it work on GPUs
1 parent 4b18d80 commit 09f5a6a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/gpu.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# `Adapt.@adapt_structure` automatically generates the `adapt` function for our custom types.
1010
Adapt.@adapt_structure FullGridCellList
1111
Adapt.@adapt_structure DynamicVectorOfVectors
12+
# Adapt.@adapt_structure PrecomputedNeighborhoodSearch
1213

1314
# `adapt(CuArray, ::SVector)::SVector`, but `adapt(Array, ::SVector)::Vector`.
1415
# We don't want to change the type of the `SVector` here.
@@ -31,3 +32,11 @@ function Adapt.adapt_structure(to, nhs::GridNeighborhoodSearch)
3132
return GridNeighborhoodSearch(cell_list, search_radius, periodic_box, n_cells,
3233
cell_size, update_buffer, nhs.update_strategy)
3334
end
35+
36+
function Adapt.adapt_structure(to, nhs::PrecomputedNeighborhoodSearch)
37+
neighbor_lists = Adapt.adapt_structure(to, nhs.neighbor_lists)
38+
periodic_box = Adapt.adapt_structure(to, nhs.periodic_box)
39+
neighborhood_search = TrivialNeighborhoodSearch{ndims(nhs)}(search_radius = search_radius(nhs))
40+
41+
return PrecomputedNeighborhoodSearch(neighborhood_search, neighbor_lists, periodic_box)
42+
end

src/nhs_precomputed.jl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,26 @@ struct PrecomputedNeighborhoodSearch{NDIMS, NHS, NL, PB} <: AbstractNeighborhood
3737
neighbor_lists :: NL
3838
periodic_box :: PB
3939

40-
function PrecomputedNeighborhoodSearch{NDIMS}(; search_radius = 0.0, n_points = 0,
41-
periodic_box = nothing,
42-
update_strategy = nothing,
43-
backend = VectorOfVectors{Int}) where {NDIMS}
44-
nhs = GridNeighborhoodSearch{NDIMS}(; search_radius, n_points,
45-
periodic_box, update_strategy)
46-
47-
neighbor_lists = backend()
48-
49-
new{NDIMS, typeof(nhs),
50-
typeof(neighbor_lists),
51-
typeof(periodic_box)}(nhs, neighbor_lists, periodic_box)
40+
# This constructor is necessary for Adapt.jl to work with this struct.
41+
# See the comments in gpu.jl for more details.
42+
function PrecomputedNeighborhoodSearch(nhs, neighbor_lists, periodic_box)
43+
new{ndims(nhs), typeof(nhs),
44+
typeof(neighbor_lists), typeof(periodic_box)}(nhs, neighbor_lists, periodic_box)
5245
end
5346
end
5447

48+
function PrecomputedNeighborhoodSearch{NDIMS}(; search_radius = 0.0, n_points = 0,
49+
periodic_box = nothing,
50+
update_strategy = nothing,
51+
backend = VectorOfVectors{Int}) where {NDIMS}
52+
nhs = GridNeighborhoodSearch{NDIMS}(; search_radius, n_points,
53+
periodic_box, update_strategy)
54+
55+
neighbor_lists = backend()
56+
57+
return PrecomputedNeighborhoodSearch(nhs, neighbor_lists, periodic_box)
58+
end
59+
5560
@inline Base.ndims(::PrecomputedNeighborhoodSearch{NDIMS}) where {NDIMS} = NDIMS
5661

5762
@inline requires_update(::PrecomputedNeighborhoodSearch) = (true, true)

0 commit comments

Comments
 (0)