Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdelrahman912 committed Dec 4, 2024
1 parent 05fb154 commit 4381a76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
5 changes: 2 additions & 3 deletions docs/src/literate-tutorials/gpu_qp_heat_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using CUDA

left = Tensor{1, 2, Float32}((0, -0)) # define the left bottom corner of the grid.
right = Tensor{1, 2, Float32}((1.0, 1.0)) # define the right top corner of the grid.
grid = generate_grid(Quadrilateral, (5, 5), left, right)
grid = generate_grid(Quadrilateral, (1000, 1000), left, right)


ip = Lagrange{RefQuadrilateral, 2}() # define the interpolation function (i.e. Bilinear lagrange)
Expand Down Expand Up @@ -184,12 +184,11 @@ gpu_kernel()

# CUDA.@time setup_bench_gpu(n_cells, n_basefuncs, cellvalues, dh)
# CUDA.@profile trace = true setup_bench_gpu(n_cells, n_basefuncs, cellvalues, dh)
# gpu_kernel = setup_bench_gpu(n_cells, n_basefuncs, cellvalues, dh)
# CUDA.@time gpu_kernel()
# CUDA.@profile trace = true gpu_kernel()


## CPU Benchmarking, remove when not needed ##
# ## CPU Benchmarking, remove when not needed ##
# function setup_bench_cpu( dh)
# K = allocate_matrix(SparseMatrixCSC{Float64, Int}, dh)
# f = zeros(eltype(K), ndofs(dh));
Expand Down
11 changes: 1 addition & 10 deletions ext/GPU/adapt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ end

## Adapt GlobalMemAlloc
function Adapt.adapt_structure(to, mem_alloc::GlobalMemAlloc)
@show "Adapting GlobalMemAlloc"
kes = Adapt.adapt_structure(to, mem_alloc.Kes)
fes = Adapt.adapt_structure(to, mem_alloc.fes)
return GlobalMemAlloc(kes, fes)
end


function Adapt.adapt_structure(to, cv::CellValues)
@show "Adapting CellValues"
fv = Adapt.adapt(to, StaticInterpolationValues(cv.fun_values))
gm = Adapt.adapt(to, StaticInterpolationValues(cv.geo_mapping))
weights = Adapt.adapt(to, ntuple(i -> getweights(cv.qr)[i], getnquadpoints(cv)))
Expand All @@ -39,22 +37,19 @@ end


function Adapt.adapt_structure(to, iter::Ferrite.QuadratureValuesIterator)
@show "Adapting QuadratureValuesIterator"
cv = Adapt.adapt_structure(to, iter.v)
cell_coords = Adapt.adapt_structure(to, iter.cell_coords)
return Ferrite.QuadratureValuesIterator(cv, cell_coords)
end

function Adapt.adapt_structure(to, qv::Ferrite.StaticQuadratureValues)
@show "Adapting StaticQuadratureValues"
det = Adapt.adapt_structure(to, qv.detJdV)
N = Adapt.adapt_structure(to, qv.N)
dNdx = Adapt.adapt_structure(to, qv.dNdx)
M = Adapt.adapt_structure(to, qv.M)
return Ferrite.StaticQuadratureValues(det, N, dNdx, M)
end
function Adapt.adapt_structure(to, qv::StaticQuadratureView)
@show "Adapting StaticQuadratureView"
mapping = Adapt.adapt_structure(to, qv.mapping)
cell_coords = Adapt.adapt_structure(to, qv.cell_coords |> cu)
q_point = Adapt.adapt_structure(to, qv.q_point)
Expand All @@ -63,7 +58,6 @@ function Adapt.adapt_structure(to, qv::StaticQuadratureView)
end

function Adapt.adapt_structure(to, grid::Grid)
@show "Adapting Grid"
# map Int64 to Int32 to reduce number of registers
cu_cells = grid.cells .|> (x -> Int32.(x.nodes)) .|> Quadrilateral |> cu
cells = Adapt.adapt_structure(to, cu_cells)
Expand All @@ -73,7 +67,6 @@ end


function Adapt.adapt_structure(to, iterator::CUDACellIterator)
@show "Adapting CUDACellIterator"
grid = Adapt.adapt_structure(to, iterator.grid)
dh = Adapt.adapt_structure(to, iterator.dh)
ncells = Adapt.adapt_structure(to, iterator.n_cells)
Expand All @@ -88,7 +81,6 @@ end


function Adapt.adapt_structure(to, dh::DofHandler)
@show "Adapting DofHandler"
cell_dofs = Adapt.adapt_structure(to, dh.cell_dofs .|> Int32 |> cu)
cells = Adapt.adapt_structure(to, dh.grid.cells |> cu)
offsets = Adapt.adapt_structure(to, dh.cell_dofs_offset .|> Int32 |> cu)
Expand All @@ -97,9 +89,8 @@ function Adapt.adapt_structure(to, dh::DofHandler)
return GPUDofHandler(cell_dofs, GPUGrid(cells, nodes), offsets, ndofs_cell)
end


## TODO: remove this...not needed
function Adapt.adapt_structure(to, assembler::GPUAssemblerSparsityPattern)
@show "Adapting GPUAssemblerSparsityPattern"
K = Adapt.adapt_structure(to, assembler.K)
f = Adapt.adapt_structure(to, assembler.f)
return Ferrite.GPUAssemblerSparsityPattern(K, f)
Expand Down

0 comments on commit 4381a76

Please sign in to comment.