Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cuda heat example w quaditer #913

Draft
wants to merge 154 commits into
base: master
Choose a base branch
from

Conversation

Abdelrahman912
Copy link
Contributor

Heat Example Prototype using CUDA.jl and StaticCellValues

@Abdelrahman912
Copy link
Contributor Author

What I did for now, and it's still work in progress:

  1. I added some higher-level abstractions and some restructuring to match the original example (still need some refactoring).
  2. I used the QuadratureValuesIterator and edited the StaticCellValue object to be compatible with the GPU.

This still work in progress and as my discussion with @termi-official last week I still need to work on the assembler, coloring algorthim.

Some problems I have encountered that might be so straightforward to tackle:

  1. Grid object contains Dict type which is not GPU compatible.

@termi-official
Copy link
Member

Great to see some quick progress here!

Some problems I have encountered that might be so straightforward to tackle:

1. `Grid` object contains `Dict` type which is not GPU compatible.

I think that is straight forward to solve. We never really need the Dicts directly during assembly. We should be able to get away by just convert the Vectors (once) to GPUVectors and run the assembly with these. This might require 2 structs. One holding the full information (e.g. GPUGrid) and one which we use in the kernels (e.g. GPUGridView). Maybe the latter could be something like

struct GPUGridView{TEA, TNA, TSA <: Union{Nothing, <:AbstractVector{Int}, <: AbstractVector{FaceIndex}, ..., TCA} <: AbstractGrid (?)
    cells::TEA
    nodes::TNA
    subdomain::TSA
    color::TCA
end

where subdomain just holds the data which we want to iterate over (or nothing for all cells) and color is a vector for elements with one color of the current subdomain.

@KnutAM
Copy link
Member

KnutAM commented May 23, 2024

A longer-term thing just to throw out the idea, but perhaps a more slim Grid could be nice?

struct Grid{dim, C, T, CV, NV, S}
    cells::CV
    nodes::NV
    gridsets::S
    function Grid(cells::AbstractVector{C}, nodes::AbstractVector{Node{dim, T}}, gridsets) where {C, dim, T}
        return new{dim, C, T, typeof(cells), typeof(nodes), typeof(sets)}(cells, nodes, gridsets)
     end
end
struct GridSets
    facetsets::Dict{String, OrderedSet{FacetIndex}}
    cellsets::Dict{String, OrderedSets{Int}}
    ....
end

allowing also gridsets=nothing

@termi-official
Copy link
Member

termi-official commented Jun 4, 2024

A longer-term thing just to throw out the idea, but perhaps a more slim Grid could be nice?

struct Grid{dim, C, T, CV, NV, S}
    cells::CV
    nodes::NV
    gridsets::S
    function Grid(cells::AbstractVector{C}, nodes::AbstractVector{Node{dim, T}}, gridsets) where {C, dim, T}
        return new{dim, C, T, typeof(cells), typeof(nodes), typeof(sets)}(cells, nodes, gridsets)
     end
end
struct GridSets
    facetsets::Dict{String, OrderedSet{FacetIndex}}
    cellsets::Dict{String, OrderedSets{Int}}
    ....
end

allowing also gridsets=nothing

I thought of this quite a bit already, whether we should have our grid in the form

struct Grid{dim, C, T, CV, NV, S, TT}
    cells::CV
    nodes::NV
    subdomain_info::S
    function Grid(cells::AbstractVector{C}, nodes::AbstractVector{Node{dim, T}}, subdomain_info) where {C, dim, T}
        return new{dim, C, T, typeof(cells), typeof(nodes), typeof(sets)}(cells, nodes, subdomain_info)
     end
end

where subdomain info contains any kind of subdomain information. This could also include potentially some optional topology information which we need for some problems. In the simplest case it would be just facesets and cellsets.

However, we should do this in a separate PR. What do you think @fredrikekre ?

@Abdelrahman912
Copy link
Contributor Author

So far:

  1. example implementation using the coloring algorithm and I did my best to follow the same abstraction as in the CPU case (also one could circumvent this by introducing metaprogramming to set up the kernel before launching but this might be relevant for later discussion)
  2. I had to implement a custom assembler (naive implementation) gpu_assembler because the already existing one cannot be used because the permutation and sorteddofs attributes are mutable (regarding to the elements and the size) so it's anly valid for sequential code, not to mention the resize!
  3. Also, setting an index for CuSparseMatrixCSC is not allowed inside a kernel (ref: https://discourse.julialang.org/t/cuda-jl-atomic-addition-error-to-a-sparse-array-inside-cuda-kernel/78789/2), so I write a very naive GPUSparseMatrixCSC.
  4. Final observation, in create_sparsity_pattern it only create sparse matrix with nzvals of type Float64 as follows :
    - K = spzeros!!(Float64, I, J, ndofs(dh), ndofs(dh)) #old code
    + K = spzeros!!(T, I, J, ndofs(dh), ndofs(dh)) # my proposal

I don't know whether this was intended or what but I found it worth mentioning.

@termi-official
Copy link
Member

Thanks for putting this so far together! Some quick comments before the next meeting for you.

2. I had to implement a custom assembler (naive implementation) `gpu_assembler` because the already existing one cannot be used because the `permutation` and `sorteddofs` attributes are mutable (regarding to the elements and the size) so it's anly valid for sequential code, not to mention the `resize!`

Indeed and I started refactoring some of the assembly code here #916 . I also think that we cannot get away with reusing the existing assembler and that we need a custom one.

3. Also, setting an index for `CuSparseMatrixCSC` is not allowed inside a kernel (ref: https://discourse.julialang.org/t/cuda-jl-atomic-addition-error-to-a-sparse-array-inside-cuda-kernel/78789/2), so I write a very naive `GPUSparseMatrixCSC`.

Indeed, but you should be able to write into nzval directly. Your GPUSparseMatrixCSC struct has very similar structure to the one of CUSPARSE already, so switching should be straight forward.

4. Final observation, in `create_sparsity_pattern` it only create sparse matrix with `nzvals` of type `Float64`  as follows :
    - K = spzeros!!(Float64, I, J, ndofs(dh), ndofs(dh)) #old code
    + K = spzeros!!(T, I, J, ndofs(dh), ndofs(dh)) # my proposal

I don't know whether this was intended or what but I found it worth mentioning.

Indeed. Frekdrik has put something great together to fix this already here #888 and I hope we can merge it in the not so far future to have more direct support of different formats.

@Abdelrahman912
Copy link
Contributor Author

A GPU benchmark with 1000 X 1000 grid, Biquadratic Lagrange as an approximation function, and 3 x 3 quadrature rule for numerical integration.

Profiler ran for 477.09 ms, capturing 2844 events.
Host-side activity: calling CUDA APIs took 303.82 ms (63.68% of the trace)
┌──────┬───────────┬───────────┬────────┬─────────────────────────┬────────────────────────────┐
│   ID │     Start │      Time │ Thread │ Name                    │                    Details │
├──────┼───────────┼───────────┼────────┼─────────────────────────┼────────────────────────────┤
│    519.55 µs │   8.82 µs │      1 │ cuMemAllocFromPoolAsync │  15.274 MiB, device memory │
│   1938.39 µs │ 953.67 ns │      1 │ cuStreamSynchronize     │                          - │
│   2844.35 µs │   2.66 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│   332.71 ms │   7.15 µs │      1 │ cuMemAllocFromPoolAsync │ 244.202 MiB, device memory │
│  1702.84 ms │   1.43 µs │      1 │ cuStreamSynchronize     │                          - │
│  1792.84 ms │  44.51 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  18447.38 ms │  27.18 µs │      1 │ cuMemAllocFromPoolAsync │ 244.202 MiB, device memory │
│  30947.47 ms │   3.58 µs │      1 │ cuStreamSynchronize     │                          - │
│  31847.49 ms │  41.89 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  32389.42 ms │  38.86 µs │      1 │ cuMemAllocFromPoolAsync │  15.274 MiB, device memory │
│  33589.48 ms │  64.61 µs │      1 │ cuMemsetD32Async        │                          - │
│  35698.81 ms │  30.76 µs │      1 │ cuMemAllocFromPoolAsync │  34.332 MiB, device memory │
│  37098.86 ms │   4.29 µs │      1 │ cuStreamSynchronize     │                          - │
│  37998.88 ms │    5.4 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  388104.32 ms │  21.46 µs │      1 │ cuMemAllocFromPoolAsync │  30.518 MiB, device memory │
│  516104.41 ms │   2.38 µs │      1 │ cuStreamSynchronize     │                          - │
│  525104.42 ms │   4.74 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  534110.25 ms │  24.56 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│  548110.29 ms │   4.53 µs │      1 │ cuStreamSynchronize     │                          - │
│  557110.31 ms │ 797.99 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│  566111.12 ms │  13.35 µs │      1 │ cuMemAllocFromPoolAsync │   7.645 MiB, device memory │
│ 1054111.3 ms │   1.19 µs │      1 │ cuStreamSynchronize     │                          - │
│ 1063111.3 ms │   1.39 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 1072114.73 ms │  13.59 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│ 1086114.75 ms │   1.91 µs │      1 │ cuStreamSynchronize     │                          - │
│ 1095114.76 ms │ 598.67 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 1112115.43 ms │   8.11 µs │      1 │ cuMemAllocFromPoolAsync │   3.164 MiB, device memory │
│ 1124115.44 ms │  50.54 µs │      1 │ cuMemsetD32Async        │                          - │
│ 1129115.49 ms │   6.91 µs │      1 │ cuMemAllocFromPoolAsync │ 360.000 KiB, device memory │
│ 1141115.5 ms │   6.44 µs │      1 │ cuMemsetD32Async        │                          - │
│ 1162149.56 ms │   1.22 ms │      1 │ cuMemAllocFromPoolAsync │  34.332 MiB, device memory │
│ 1176150.8 ms │   4.29 µs │      1 │ cuStreamSynchronize     │                          - │
│ 1185150.82 ms │   7.98 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 1194158.81 ms │ 722.41 µs │      1 │ cuMemAllocFromPoolAsync │  30.518 MiB, device memory │
│ 1208159.55 ms │   3.58 µs │      1 │ cuStreamSynchronize     │                          - │
│ 1217159.56 ms │   6.86 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 1226167.29 ms │  15.02 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│ 1240167.34 ms │   3.58 µs │      1 │ cuStreamSynchronize     │                          - │
│ 1249167.35 ms │ 777.24 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 1258168.14 ms │   6.68 µs │      1 │ cuMemAllocFromPoolAsync │   7.645 MiB, device memory │
│ 1965168.38 ms │   1.19 µs │      1 │ cuStreamSynchronize     │                          - │
│ 1974168.39 ms │   1.41 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 1983171.42 ms │  12.87 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│ 1997171.46 ms │   2.15 µs │      1 │ cuStreamSynchronize     │                          - │
│ 2006171.47 ms │ 816.58 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│ 2023172.42 ms │   84.4 µs │      1 │ cuLaunchKernel          │                          - │
│ 2801172.93 ms │  13.11 µs │      2 │ cuMemFreeAsync          │   3.815 MiB, device memory │
│ 2806172.95 ms │   2.38 µs │      2 │ cuMemFreeAsync          │   7.645 MiB, device memory │
│ 2811172.96 ms │   2.38 µs │      2 │ cuMemFreeAsync          │   3.815 MiB, device memory │
│ 2816172.96 ms │   2.62 µs │      2 │ cuMemFreeAsync          │  30.518 MiB, device memory │
│ 2821172.97 ms │   2.86 µs │      2 │ cuMemFreeAsync          │  34.332 MiB, device memory │
│ 2824172.97 ms │  303.8 ms │      2 │ cuStreamSynchronize     │                          - │
└──────┴───────────┴───────────┴────────┴─────────────────────────┴────────────────────────────┘

Device-side activity: GPU was busy for 418.87 ms (87.80% of the trace)
┌──────┬───────────┬───────────┬─────────┬────────┬──────┬─────────────┬──────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────
│   ID │     Start │      Time │ Threads │ Blocks │ Regs │        Size │   Throughput │ Name                                                                                            
├──────┼───────────┼───────────┼─────────┼────────┼──────┼─────────────┼──────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────
│   28247.24 µs │    2.6 ms │       ---15.274 MiB │  5.741 GiB/s │ [copy pageable to device memory]                                                                1793.02 ms │  44.45 ms │       ---244.202 MiB │  5.365 GiB/s │ [copy pageable to device memory]                                                                31847.62 ms │  41.88 ms │       ---244.202 MiB │  5.694 GiB/s │ [copy pageable to device memory]                                                                33589.97 ms │  250.1 µs │       ---15.274 MiB │ 59.640 GiB/s │ [set device memory]                                                                             37999.14 ms │   5.27 ms │       ---34.332 MiB │  6.362 GiB/s │ [copy pageable to device memory]                                                                525104.54 ms │   4.76 ms │       ---30.518 MiB │  6.262 GiB/s │ [copy pageable to device memory]                                                                557110.52 ms │ 791.31 µs │       ---3.815 MiB │  4.708 GiB/s │ [copy pageable to device memory]                                                                1063111.5 ms │   1.35 ms │       ---7.645 MiB │  5.519 GiB/s │ [copy pageable to device memory]                                                                1095114.97 ms │ 537.16 µs │       ---3.815 MiB │  6.935 GiB/s │ [copy pageable to device memory]                                                                1124115.95 ms │  58.41 µs │       ---3.164 MiB │ 52.898 GiB/s │ [set device memory]                                                                             1141116.02 ms │  13.11 µs │       ---360.000 KiB │ 26.182 GiB/s │ [set device memory]                                                                             1185153.41 ms │   5.53 ms │       ---34.332 MiB │  6.064 GiB/s │ [copy pageable to device memory]                                                                1217161.78 ms │   4.81 ms │       ---30.518 MiB │  6.200 GiB/s │ [copy pageable to device memory]                                                                1249167.66 ms │ 730.51 µs │       ---3.815 MiB │  5.100 GiB/s │ [copy pageable to device memory]                                                                1974168.68 ms │   1.34 ms │       ---7.645 MiB │  5.582 GiB/s │ [copy pageable to device memory]                                                                2006171.79 ms │ 721.93 µs │       ---3.815 MiB │  5.160 GiB/s │ [copy pageable to device memory]                                                                2023172.92 ms │ 303.78 ms │     2564095--assemble_gpu_(CuSparseDeviceMatrixCSC<Float32, Int32, 1l>, CuDeviceArray<Float32, 1l, 1l>, Stat 
└──────┴───────────┴───────────┴─────────┴────────┴──────┴─────────────┴──────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────

Copy link
Member

@termi-official termi-official left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the first review round covering the example, parts of the assembly logic and some of the kernel infrastructure.

docs/src/literate-tutorials/gpu_qp_heat_equation.jl Outdated Show resolved Hide resolved
docs/src/literate-tutorials/gpu_qp_heat_equation.jl Outdated Show resolved Hide resolved
docs/src/literate-tutorials/gpu_qp_heat_equation.jl Outdated Show resolved Hide resolved
docs/src/literate-tutorials/gpu_qp_heat_equation.jl Outdated Show resolved Hide resolved
docs/src/literate-tutorials/gpu_qp_heat_equation.jl Outdated Show resolved Hide resolved
ext/GPU/adapt.jl Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these dispatches CUDA-specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe yes, but just out of curiosity, is there any performance-related reason that I might have overlooked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is more about making the code extensible (e.g. to allow using AMD).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allocation dispatches (Ferrite.allocate_matrix) are missing. Just allocate the analogue CPU matrix and shove it into CUSPARSE á la

Kcpu = allocate_matrix(SparseMatrixCSC{Float32, Int32}, dh)
allocate_matrix(CUSPARSE.CuSparseMatrixCSC{Float32, Int32}, dh)

where we extract the type parameters from the dispatch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To what does this file belong to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, no idea, first time to notice it 😂

## gpu_kernel = init_kernel(BackendCUDA, n_cells, n_basefuncs, assemble_gpu!, (Kgpu, fgpu, cellvalues, dh))
## gpu_kernel()
## end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are missing the analogue benchmark using QuadraturePointIterator

src/GPU/gpu_grid.jl Show resolved Hide resolved
@Abdelrahman912
Copy link
Contributor Author

GPU Setup Benchmarking

function setup_bench_gpu(n_cells, n_basefuncs, cellvalues, dh)
    Kgpu = allocate_matrix(CUSPARSE.CuSparseMatrixCSC{Float32, Int32}, dh)
    fgpu = CUDA.zeros(eltype(Kgpu), ndofs(dh));
    gpu_kernel = init_kernel(BackendCUDA, n_cells, n_basefuncs, assemble_gpu!, (Kgpu, fgpu, cellvalues, dh))
end
Profiler ran for 3.21 s, capturing 107 events.

Host-side activity: calling CUDA APIs took 375.8 ms (11.72% of the trace)
┌─────┬────────┬───────────┬─────────────────────────┬────────────────────────────┐
│  ID │  Start │      Time │ Name                    │                    Details │
├─────┼────────┼───────────┼─────────────────────────┼────────────────────────────┤
│   52.83 s │  92.27 µs │ cuMemAllocFromPoolAsync │  15.274 MiB, device memory │
│  192.83 s │   4.77 µs │ cuStreamSynchronize     │                          - │
│  282.83 s │  10.39 ms │ cuMemcpyHtoDAsync       │                          - │
│  332.84 s │   9.14 ms │ cuMemAllocFromPoolAsync │ 244.202 MiB, device memory │
│  472.85 s │  12.16 µs │ cuStreamSynchronize     │                          - │
│  562.85 s │ 195.62 ms │ cuMemcpyHtoDAsync       │                          - │
│  613.04 s │   7.37 ms │ cuMemAllocFromPoolAsync │ 244.202 MiB, device memory │
│  753.05 s │   5.01 µs │ cuStreamSynchronize     │                          - │
│  843.05 s │ 152.64 ms │ cuMemcpyHtoDAsync       │                          - │
│  893.2 s │  46.49 µs │ cuMemAllocFromPoolAsync │  15.274 MiB, device memory │
│ 1013.2 s │ 399.59 µs │ cuMemsetD32Async        │                          - │
└─────┴────────┴───────────┴─────────────────────────┴────────────────────────────┘

Device-side activity: GPU was busy for 301.98 ms (9.42% of the trace)
┌─────┬────────┬───────────┬─────────────┬───────────────┬──────────────────────────────────┐
│  ID │  Start │      Time │        Size │    Throughput │ Name                             │
├─────┼────────┼───────────┼─────────────┼───────────────┼──────────────────────────────────┤
│  282.83 s │  10.54 ms │  15.274 MiB │   1.416 GiB/s │ [copy pageable to device memory] │
│  562.88 s │ 168.79 ms │ 244.202 MiB │   1.413 GiB/s │ [copy pageable to device memory] │
│  843.08 s │ 122.56 ms │ 244.202 MiB │   1.946 GiB/s │ [copy pageable to device memory] │
│ 1013.21 s │  91.31 µs │  15.274 MiB │ 163.349 GiB/s │ [set device memory]              │
└─────┴────────┴───────────┴─────────────┴───────────────┴──────────────────────────────────┘

GPU Kernel Benchmarking

CUDA.@profile trace = true gpu_kernel()
Profiler ran for 373.97 ms, capturing 1731 events.

Host-side activity: calling CUDA APIs took 315.64 ms (84.40% of the trace)
┌──────┬──────────┬───────────┬────────┬─────────────────────────┬────────────────────────────┐
│   ID │    Start │      Time │ Thread │ Name                    │                    Details │
├──────┼──────────┼───────────┼────────┼─────────────────────────┼────────────────────────────┤
│   2111.25 ms │   39.1 µs │      1 │ cuMemAllocFromPoolAsync │  34.332 MiB, device memory │
│   3511.32 ms │   5.48 µs │      1 │ cuStreamSynchronize     │                          - │
│   4411.34 ms │   5.62 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│   5317.0 ms │  28.85 µs │      1 │ cuMemAllocFromPoolAsync │  30.518 MiB, device memory │
│  13917.07 ms │    3.1 µs │      1 │ cuStreamSynchronize     │                          - │
│  14817.08 ms │   4.88 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  15722.87 ms │  27.89 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│  17122.92 ms │   3.34 µs │      1 │ cuStreamSynchronize     │                          - │
│  18022.93 ms │  706.2 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│  18923.65 ms │   8.58 µs │      1 │ cuMemAllocFromPoolAsync │   7.645 MiB, device memory │
│  30523.81 ms │   1.43 µs │      1 │ cuStreamSynchronize     │                          - │
│  31423.81 ms │   1.13 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  32326.6 ms │   12.4 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│  33726.63 ms │   1.67 µs │      1 │ cuStreamSynchronize     │                          - │
│  34626.63 ms │ 582.93 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│  36327.29 ms │   8.34 µs │      1 │ cuMemAllocFromPoolAsync │   3.164 MiB, device memory │
│  37527.3 ms │  65.09 µs │      1 │ cuMemsetD32Async        │                          - │
│  38027.37 ms │   4.05 µs │      1 │ cuMemAllocFromPoolAsync │ 360.000 KiB, device memory │
│  39227.37 ms │  36.95 µs │      1 │ cuMemsetD32Async        │                          - │
│  41338.88 ms │  27.89 µs │      1 │ cuMemAllocFromPoolAsync │  34.332 MiB, device memory │
│  42738.93 ms │   4.29 µs │      1 │ cuStreamSynchronize     │                          - │
│  43638.95 ms │   5.96 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  44544.94 ms │   23.6 µs │      1 │ cuMemAllocFromPoolAsync │  30.518 MiB, device memory │
│  55545.05 ms │   5.48 µs │      1 │ cuCtxSetCurrent         │                          - │
│  55645.05 ms │ 239.13 µs │      1 │ cuCtxGetDevice          │                          - │
│  55745.33 ms │ 715.26 ns │      1 │ cuDeviceGetCount        │                          - │
│  56045.34 ms │  12.16 µs │      1 │ cuMemFreeAsync          │   3.815 MiB, device memory │
│  56545.36 ms │   2.38 µs │      1 │ cuMemFreeAsync          │   7.645 MiB, device memory │
│  57045.36 ms │   2.15 µs │      1 │ cuMemFreeAsync          │   3.815 MiB, device memory │
│  57545.37 ms │    3.1 µs │      1 │ cuMemFreeAsync          │  30.518 MiB, device memory │
│  58045.37 ms │   3.81 µs │      1 │ cuMemFreeAsync          │  34.332 MiB, device memory │
│  58645.51 ms │   4.05 µs │      1 │ cuStreamSynchronize     │                          - │
│  59545.52 ms │   4.83 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  60451.4 ms │  14.78 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│  61851.43 ms │   2.86 µs │      1 │ cuStreamSynchronize     │                          - │
│  62751.44 ms │ 727.89 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│  63652.18 ms │  15.97 µs │      1 │ cuMemAllocFromPoolAsync │   7.645 MiB, device memory │
│  88152.4 ms │   1.67 µs │      1 │ cuStreamSynchronize     │                          - │
│  89052.41 ms │    1.3 ms │      1 │ cuMemcpyHtoDAsync       │                          - │
│  89955.51 ms │   17.4 µs │      1 │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│  91355.54 ms │   2.15 µs │      1 │ cuStreamSynchronize     │                          - │
│  92255.55 ms │ 687.12 µs │      1 │ cuMemcpyHtoDAsync       │                          - │
│  93956.33 ms │ 882.39 µs │      1 │ cuLaunchKernel          │                          - │
│ 171558.13 ms │ 315.64 ms │      2 │ cuStreamSynchronize     │                          - │
└──────┴──────────┴───────────┴────────┴─────────────────────────┴────────────────────────────┘

Device-side activity: GPU was busy for 343.25 ms (91.78% of the trace)
┌─────┬──────────┬───────────┬─────────┬────────┬──────┬─────────────┬──────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│  ID │    Start │      Time │ Threads │ Blocks │ Regs │        Size │   Throughput │ Name                                                                                                                                     
├─────┼──────────┼───────────┼─────────┼────────┼──────┼─────────────┼──────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│  4411.67 ms │   5.43 ms │       ---34.332 MiB │  6.175 GiB/s │ [copy pageable to device memory]                                                                                                         14817.26 ms │   4.85 ms │       ---30.518 MiB │  6.139 GiB/s │ [copy pageable to device memory]                                                                                                         18023.28 ms │ 532.15 µs │       ---3.815 MiB │  7.000 GiB/s │ [copy pageable to device memory]                                                                                                         31423.97 ms │   1.16 ms │       ---7.645 MiB │  6.456 GiB/s │ [copy pageable to device memory]                                                                                                         34626.81 ms │ 599.15 µs │       ---3.815 MiB │  6.218 GiB/s │ [copy pageable to device memory]                                                                                                         37527.47 ms │  40.53 µs │       ---3.164 MiB │ 76.235 GiB/s │ [set device memory]                                                                                                                      39227.52 ms │   9.54 µs │       ---360.000 KiB │ 36.000 GiB/s │ [set device memory]                                                                                                                      43639.24 ms │    5.8 ms │       ---34.332 MiB │  5.778 GiB/s │ [copy pageable to device memory]                                                                                                         59545.71 ms │   4.88 ms │       ---30.518 MiB │  6.101 GiB/s │ [copy pageable to device memory]                                                                                                         62751.69 ms │ 735.76 µs │       ---3.815 MiB │  5.063 GiB/s │ [copy pageable to device memory]                                                                                                         89052.58 ms │   1.37 ms │       ---7.645 MiB │  5.467 GiB/s │ [copy pageable to device memory]                                                                                                         92255.78 ms │ 664.71 µs │       ---3.815 MiB │  5.604 GiB/s │ [copy pageable to device memory]                                                                                                         93956.52 ms │ 317.17 ms │     2564095--assemble_gpu_(CuSparseDeviceMatrixCSC<Float32, Int32, 1l>, CuDeviceArray<Float32, 1l, 1l>, StaticCellValues<StaticInterpolationValues<La 
└─────┴──────────┴───────────┴─────────┴────────┴──────┴─────────────┴──────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────

CPU Setup Benchmarking

function setup_bench_cpu( dh)
    K = allocate_matrix(SparseMatrixCSC{Float64, Int}, dh)
    f = zeros(eltype(K), ndofs(dh));
    return K,f
end
BenchmarkTools.Trial: 2 samples with 1 evaluation.
 Range (min  max):  2.188 s  10.796 s  ┊ GC (min  max): 5.31%  1.65%
 Time  (median):     6.492 s             ┊ GC (median):    2.27%
 Time  (mean ± σ):   6.492 s ±  6.086 s  ┊ GC (mean ± σ):  2.27% ± 2.59%

  █                                                      █  
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  2.19 s        Histogram: frequency by time        10.8 s <

 Memory estimate: 2.12 GiB, allocs estimate: 2009.

CPU Assemble Benchmarking

1. Standard Assembly

@benchmark assemble_global_std!($cellvalues, $dh, $K, $f)
BenchmarkTools.Trial: 4 samples with 1 evaluation.
 Range (min  max):  1.404 s    1.439 s  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     1.437 s              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.429 s ± 16.653 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▁                                                 ▁     █  
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁█ ▁
  1.4 s          Histogram: frequency by time        1.44 s <

 Memory estimate: 1.45 KiB, allocs estimate: 15.

2. QuadratureValueIterator

@benchmark assemble_global_qp!($cellvalues, $dh, $K, $f)
BenchmarkTools.Trial: 5 samples with 1 evaluation.
 Range (min  max):  1.201 s    1.246 s  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     1.215 s              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.221 s ± 18.214 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █          █     █                      █               █  
  █▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  1.2 s          Histogram: frequency by time        1.25 s <

 Memory estimate: 1.45 KiB, allocs estimate: 15.

@Abdelrahman912
Copy link
Contributor Author

GPU Benchmarking

Setup:

Profiler ran for 3.52 s, capturing 389 events.

Host-side activity: calling CUDA APIs took 276.41 ms (7.86% of the trace)
┌─────┬────────┬───────────┬─────────────────────────┬────────────────────────────┐
│  ID │  Start │      Time │ Name                    │                    Details │
├─────┼────────┼───────────┼─────────────────────────┼────────────────────────────┤
│   53.21 s │   1.11 ms │ cuMemAllocFromPoolAsync │  15.274 MiB, device memory │
│  193.21 s │   2.86 µs │ cuStreamSynchronize     │                          - │
│  273.21 s │  14.58 ms │ cuMemcpyHtoDAsync       │                          - │
│  323.22 s │   6.52 ms │ cuMemAllocFromPoolAsync │ 244.202 MiB, device memory │
│  463.23 s │    3.1 µs │ cuStreamSynchronize     │                          - │
│  543.23 s │ 157.46 ms │ cuMemcpyHtoDAsync       │                          - │
│  593.39 s │   4.67 ms │ cuMemAllocFromPoolAsync │ 244.202 MiB, device memory │
│  733.39 s │   2.38 µs │ cuStreamSynchronize     │                          - │
│  813.39 s │  54.99 ms │ cuMemcpyHtoDAsync       │                          - │
│  863.45 s │  41.25 µs │ cuMemAllocFromPoolAsync │  15.274 MiB, device memory │
│  983.45 s │ 393.39 µs │ cuMemsetD32Async        │                          - │
│ 1053.47 s │   1.37 ms │ cuMemAllocFromPoolAsync │  34.332 MiB, device memory │
│ 1193.47 s │   5.01 µs │ cuStreamSynchronize     │                          - │
│ 1273.47 s │   8.08 ms │ cuMemcpyHtoDAsync       │                          - │
│ 1323.47 s │   1.38 ms │ cuMemAllocFromPoolAsync │  30.518 MiB, device memory │
│ 1463.48 s │   2.15 µs │ cuStreamSynchronize     │                          - │
│ 1543.48 s │  11.79 ms │ cuMemcpyHtoDAsync       │                          - │
│ 1593.49 s │ 815.87 µs │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│ 1733.49 s │   1.43 µs │ cuStreamSynchronize     │                          - │
│ 1813.49 s │   2.56 ms │ cuMemcpyHtoDAsync       │                          - │
│ 1863.49 s │  82.97 µs │ cuMemAllocFromPoolAsync │   7.645 MiB, device memory │
│ 3053.49 s │   1.91 µs │ cuStreamSynchronize     │                          - │
│ 3133.49 s │   1.55 ms │ cuMemcpyHtoDAsync       │                          - │
│ 3183.5 s │  11.21 µs │ cuMemAllocFromPoolAsync │   3.815 MiB, device memory │
│ 3323.5 s │ 953.67 ns │ cuStreamSynchronize     │                          - │
│ 3403.5 s │  606.3 µs │ cuMemcpyHtoDAsync       │                          - │
│ 3473.5 s │   7.64 ms │ cuMemAllocFromPoolAsync │ 308.990 MiB, device memory │
│ 3593.51 s │  55.31 µs │ cuMemsetD32Async        │                          - │
│ 3643.51 s │ 427.01 µs │ cuMemAllocFromPoolAsync │  34.332 MiB, device memory │
│ 3763.51 s │  34.09 µs │ cuMemsetD32Async        │                          - │
└─────┴────────┴───────────┴─────────────────────────┴────────────────────────────┘

Device-side activity: GPU was busy for 210.53 ms (5.98% of the trace)
┌─────┬────────┬───────────┬─────────────┬───────────────┬──────────────────────────────────┐
│  ID │  Start │      Time │        Size │    Throughput │ Name                             │
├─────┼────────┼───────────┼─────────────┼───────────────┼──────────────────────────────────┤
│  273.21 s │  10.63 ms │  15.274 MiB │   1.403 GiB/s │ [copy pageable to device memory] │
│  543.25 s │ 131.97 ms │ 244.202 MiB │   1.807 GiB/s │ [copy pageable to device memory] │
│  813.4 s │  46.19 ms │ 244.202 MiB │   5.163 GiB/s │ [copy pageable to device memory] │
│  983.45 s │  90.36 µs │  15.274 MiB │ 165.073 GiB/s │ [set device memory]              │
│ 1273.47 s │   5.96 ms │  34.332 MiB │   5.629 GiB/s │ [copy pageable to device memory] │
│ 1543.48 s │  10.47 ms │  30.518 MiB │   2.847 GiB/s │ [copy pageable to device memory] │
│ 1813.49 s │ 881.67 µs │   3.815 MiB │   4.225 GiB/s │ [copy pageable to device memory] │
│ 3133.49 s │   1.45 ms │   7.645 MiB │   5.154 GiB/s │ [copy pageable to device memory] │
│ 3403.5 s │ 609.87 µs │   3.815 MiB │   6.108 GiB/s │ [copy pageable to device memory] │
│ 3593.52 s │   2.07 ms │ 308.990 MiB │ 145.709 GiB/s │ [set device memory]              │
│ 3763.52 s │ 210.29 µs │  34.332 MiB │ 159.439 GiB/s │ [set device memory]              │
└─────┴────────┴───────────┴─────────────┴───────────────┴──────────────────────────────────┘

kernel launch

Profiler ran for 479.87 ms, capturing 829 events.

Host-side activity: calling CUDA APIs took 478.53 ms (99.72% of the trace)
┌─────┬──────────┬───────────┬────────┬─────────────────────┐
│  ID │    Start │      Time │ Thread │ Name                │
├─────┼──────────┼───────────┼────────┼─────────────────────┤
│  4989.65 µs │ 352.62 µs │      1 │ cuLaunchKernel      │
│ 8251.02 ms │ 478.53 ms │      2 │ cuStreamSynchronize │
└─────┴──────────┴───────────┴────────┴─────────────────────┘

Device-side activity: GPU was busy for 478.59 ms (99.73% of the trace)
┌────┬───────────┬───────────┬─────────┬────────┬──────┬──────┐
│ ID │     Start │      Time │ Threads │ Blocks │ Regs │ Name │
├────┼───────────┼───────────┼─────────┼────────┼──────┼──────┤
│ 49949.62 µs │ 478.59 ms │     25640255 │ _4   │
└────┴───────────┴───────────┴─────────┴────────┴──────┴──────┘

CPU Benchmarking

Setup

BenchmarkTools.Trial: 2 samples with 1 evaluation.
 Range (min  max):  2.599 s  5.068 s  ┊ GC (min  max): 6.36%  1.17%
 Time  (median):     3.834 s            ┊ GC (median):    2.93%
 Time  (mean ± σ):   3.834 s ± 1.746 s  ┊ GC (mean ± σ):  2.93% ± 3.67%

  █                                                     █  
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  2.6 s         Histogram: frequency by time       5.07 s <

 Memory estimate: 2.12 GiB, allocs estimate: 2009.

Kernel launch

BenchmarkTools.Trial: 4 samples with 1 evaluation.
 Range (min  max):  1.406 s    1.526 s  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     1.454 s              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.460 s ± 49.409 ms  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █                   █    █                              █  
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  1.41 s         Histogram: frequency by time        1.53 s <

 Memory estimate: 1.45 KiB, allocs estimate: 15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants