11#include < AdvectionParams.hpp>
22#include < AdvectionSolver.hpp>
3- #include < advectors.hpp>
43#include < iostream>
54#include < sycl/sycl.hpp>
65#include < unique_ref.hpp>
1514// ==========================================
1615// returns duration for maxIter-1 iterations
1716std::chrono::duration<double >
18- advection (sycl::queue &Q, real_t * fidst_dev ,
19- sref::unique_ref<IAdvectorX> &advector, const AdvectionSolver &solver ) {
17+ advection (sycl::queue &Q, span3d_t data, const AdvectionSolver &solver ,
18+ BkmaOptimParams &optim_params ) {
2019
2120 auto static const maxIter = solver.params .maxIter ;
2221
2322 auto start = std::chrono::high_resolution_clock::now ();
2423 // Time loop
2524 for (size_t t = 0 ; t < maxIter; ++t) {
26- advector (Q, fidst_dev, solver);
25+ bkma_run<AdvectionSolver, BkmaImpl::AdaptiveWg>(Q, data, solver,
26+ optim_params);
2727 Q.wait ();
28+
2829 } // end for t < T
2930 auto end = std::chrono::high_resolution_clock::now ();
3031
@@ -42,24 +43,11 @@ main(int argc, char **argv) {
4243 ADVParamsNonCopyable strParams;// = ADVParamsNonCopyable();
4344 strParams.setup (configMap);
4445
45- const auto run_on_gpu = strParams.gpu ;
46-
47- sycl::device d;
48- if (run_on_gpu)
49- try {
50- d = sycl::device{sycl::gpu_selector_v};
51- } catch (const sycl::exception e) {
52- std::cout
53- << " GPU was requested but none is available, running kernels "
54- " on the CPU\n "
55- << std::endl;
56- d = sycl::device{sycl::cpu_selector_v};
57- strParams.gpu = false ;
58- }
59- else
60- d = sycl::device{sycl::cpu_selector_v};
61-
62- sycl::queue Q{d};
46+ const bool run_on_gpu = strParams.gpu ;
47+ auto device = pick_device (run_on_gpu);
48+ strParams.gpu = device.is_gpu () ? true : false ;
49+
50+ sycl::queue Q{device};
6351
6452 /* Display infos on current device */
6553 std::cout << " Using device: "
@@ -76,24 +64,21 @@ main(int argc, char **argv) {
7664
7765 /* Buffer for the distribution function containing the probabilities of
7866 having a particle at a particular speed and position, plus a fictive dim */
79- real_t * fdist = sycl::malloc_device< real_t >( n0*n1*n2, Q);
67+ span3d_t data ( sycl_alloc ( n0*n1*n2, Q), n0, n1, n2 );
8068 Q.wait ();
81- fill_buffer (Q, fdist , params);
69+ fill_buffer_adv (Q, data , params);
8270
8371 AdvectionSolver solver (params);
84- auto advector = kernel_impl_factory (Q, strParams, solver );
72+ auto optim_params = create_optim_params<ADVParams> (Q, params );
8573
86- auto elapsed_seconds = advection (Q, fdist, advector, solver );
74+ auto elapsed_seconds = advection (Q, data, solver, optim_params );
8775
88- std::cout << " \n RESULTS_VALIDATION:" << std::endl;
89- validate_result (Q, fdist, params);
76+ validate_result_adv (Q, data, params);
9077
91- std::cout << " PERF_DIAGS: " << std::endl ;
92- std::cout << " elapsed_time: " << elapsed_seconds.count () << " s \n " ;
78+ auto const n_cells = n0 * n1 * n2 * (maxIter) ;
79+ print_perf ( elapsed_seconds.count (), n_cells) ;
9380
94- auto gcells = ((n0*n1*n2*(maxIter)) / elapsed_seconds.count ()) / 1e9 ;
95- std::cout << " upd_cells_per_sec: " << gcells << " Gcell/sec\n " ;
96- std::cout << " estimated_throughput: " << gcells * sizeof (real_t ) * 2
97- << " GB/s" << std::endl;
81+ sycl::free (data.data_handle (), Q);
82+ Q.wait ();
9883 return 0 ;
9984}
0 commit comments