-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathmaxwell_gpu_s.cu
More file actions
93 lines (76 loc) · 2.83 KB
/
Copy pathmaxwell_gpu_s.cu
File metadata and controls
93 lines (76 loc) · 2.83 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright (c) 2022 NVIDIA Corporation
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file causes clangd to crash during parsing
#if !defined(STDEXEC_CLANGD_INVOKED)
# include "maxwell/cuda.cuh"
# include "maxwell/snr.cuh"
# include "maxwell/stdpar.cuh" // IWYU pragma: keep
auto main(int argc, char *argv[]) -> int
{
auto params = parse_cmd(argc, argv);
if (value(params, "help") || value(params, "h"))
{
std::cout << "Usage: " << argv[0] << " [OPTION]...\n"
<< "\t--write-vtk\n"
<< "\t--iterations\n"
<< (STDEXEC_NO_STDCPP_PARALLEL_ALGORITHMS() ? "" : "\t--run-stdpar\n") //
<< "\t--run-cuda\n"
<< "\t--run-stream-scheduler\n"
<< "\t--N\n"
<< std::endl;
return 0;
}
bool const write_vtk = value(params, "write-vtk");
std::size_t const n_iterations = value(params, "iterations", 1000);
std::size_t const N = value(params, "N", 512);
auto run_snr_on = [&](std::string_view scheduler_name, stdexec::scheduler auto &&scheduler)
{
grid_t grid{N, is_gpu_scheduler(scheduler)};
auto accessor = grid.accessor();
auto dt = calculate_dt(accessor.dx, accessor.dy);
run_snr(dt,
write_vtk,
n_iterations,
grid,
scheduler_name,
std::forward<decltype(scheduler)>(scheduler));
};
report_header();
if (value(params, "run-cuda"))
{
grid_t grid{N, true /* gpu */};
auto accessor = grid.accessor();
auto dt = calculate_dt(accessor.dx, accessor.dy);
run_cuda(dt, write_vtk, n_iterations, grid, "GPU (cuda)");
}
if (value(params, "run-stream-scheduler"))
{
nvexec::stream_context stream_ctx{};
run_snr_on("GPU (snr cuda stream)", stream_ctx.get_scheduler());
}
# if !STDEXEC_NO_STDCPP_PARALLEL_ALGORITHMS()
if (value(params, "run-stdpar"))
{
bool const gpu = is_gpu_policy(stdexec::par_unseq);
std::string_view method = gpu ? "GPU (stdpar)" : "CPU (stdpar)";
grid_t grid{N, gpu};
auto accessor = grid.accessor();
auto dt = calculate_dt(accessor.dx, accessor.dy);
run_stdpar(dt, write_vtk, n_iterations, grid, stdexec::par_unseq, method);
}
# endif // !STDEXEC_NO_STDCPP_PARALLEL_ALGORITHMS()
}
#endif // !defined(STDEXEC_CLANGD_INVOKED)