Skip to content

Commit d114c8a

Browse files
committed
GPU compatibility
1 parent d60e89b commit d114c8a

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/gpu.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Adapt.@adapt_structure FullGridCellList
1111
Adapt.@adapt_structure SpatialHashingCellList
1212
Adapt.@adapt_structure DynamicVectorOfVectors
1313
Adapt.@adapt_structure GridNeighborhoodSearch
14-
Adapt.@adapt_structure PrecomputedNeighborhoodSearch
1514

1615
# `adapt(CuArray, ::SVector)::SVector`, but `adapt(Array, ::SVector)::Vector`.
1716
# We don't want to change the type of the `SVector` here.
@@ -24,3 +23,13 @@ end
2423
function Adapt.adapt_structure(to::typeof(Array), range::UnitRange)
2524
return range
2625
end
26+
27+
function Adapt.adapt_structure(to, nhs::PrecomputedNeighborhoodSearch)
28+
neighbor_lists = Adapt.adapt_structure(to, nhs.neighbor_lists)
29+
search_radius = Adapt.adapt_structure(to, nhs.search_radius)
30+
periodic_box = Adapt.adapt_structure(to, nhs.periodic_box)
31+
neighborhood_search = nothing# Adapt.adapt_structure(to, nhs.neighborhood_search)
32+
33+
return PrecomputedNeighborhoodSearch{ndims(nhs)}(neighbor_lists, search_radius,
34+
periodic_box, neighborhood_search)
35+
end

src/nhs_precomputed.jl

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,34 @@ struct PrecomputedNeighborhoodSearch{NDIMS, NL, ELTYPE, PB, NHS} <:
4343
periodic_box :: PB
4444
neighborhood_search :: NHS
4545

46-
function PrecomputedNeighborhoodSearch{NDIMS}(; search_radius = 0.0, n_points = 0,
47-
periodic_box = nothing,
48-
update_strategy = nothing,
49-
update_neighborhood_search = GridNeighborhoodSearch{NDIMS}(;
50-
search_radius,
51-
n_points,
52-
periodic_box,
53-
update_strategy),
54-
backend = DynamicVectorOfVectors{Int32},
55-
max_neighbors = 4 * NDIMS^4) where {NDIMS}
56-
neighbor_lists = construct_backend(nothing, backend, n_points, max_neighbors)
57-
58-
new{NDIMS, typeof(neighbor_lists),
59-
typeof(search_radius), typeof(periodic_box),
60-
typeof(update_neighborhood_search)}(neighbor_lists, search_radius,
61-
periodic_box, update_neighborhood_search)
46+
function PrecomputedNeighborhoodSearch{NDIMS}(neighbor_lists, search_radius,
47+
periodic_box,
48+
update_neighborhood_search) where {NDIMS}
49+
return new{NDIMS, typeof(neighbor_lists),
50+
typeof(search_radius),
51+
typeof(periodic_box),
52+
typeof(update_neighborhood_search)}(neighbor_lists, search_radius,
53+
periodic_box,
54+
update_neighborhood_search)
6255
end
6356
end
6457

58+
function PrecomputedNeighborhoodSearch{NDIMS}(; search_radius = 0.0, n_points = 0,
59+
periodic_box = nothing,
60+
update_strategy = nothing,
61+
update_neighborhood_search = GridNeighborhoodSearch{NDIMS}(;
62+
search_radius,
63+
n_points,
64+
periodic_box,
65+
update_strategy),
66+
backend = DynamicVectorOfVectors{Int32},
67+
max_neighbors = 4 * NDIMS^4) where {NDIMS}
68+
neighbor_lists = construct_backend(nothing, backend, n_points, max_neighbors)
69+
70+
PrecomputedNeighborhoodSearch{NDIMS}(neighbor_lists, search_radius,
71+
periodic_box, update_neighborhood_search)
72+
end
73+
6574
@inline Base.ndims(::PrecomputedNeighborhoodSearch{NDIMS}) where {NDIMS} = NDIMS
6675

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

0 commit comments

Comments
 (0)