-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpu_acceleration.jl
More file actions
47 lines (36 loc) · 1012 Bytes
/
gpu_acceleration.jl
File metadata and controls
47 lines (36 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
gpu_acceleration.jl
GPU backend example with strict qualified imports.
Run from package root:
julia --project=examples examples/gpu_acceleration.jl
"""
using StructureFunctions: StructureFunctions as SF
use_cuda = false
CUDA_mod = nothing
try
@eval using CUDA: CUDA
use_cuda = CUDA.functional()
CUDA_mod = CUDA
catch
use_cuda = false
end
N = use_cuda ? 500_000 : 50_000
x_cpu = randn(Float32, N, 2)
u_cpu = randn(Float32, N, 2)
x = use_cuda ? CUDA_mod.cu(x_cpu) : x_cpu
u = use_cuda ? CUDA_mod.cu(u_cpu) : u_cpu
operator = SF.FullVectorStructureFunctionType{Float32}(order = 2)
bins = collect(Float32, 10.0:25.0:2000.0)
backend = SF.GPUBackend()
result = @time SF.calculate_structure_function(
operator,
x,
u,
bins;
backend = backend,
show_progress = true,
verbose = true,
)
println("Computed bins: $(length(result.distance))")
println("First SF value: $(result.structure_function[1, 1])")
println("Mode: $(use_cuda ? "CUDA" : "CPU fallback")")