MAJ terminée. Nous sommes passés en version 14.6.2 . Pour consulter les "releases notes" associées c'est ici :

https://about.gitlab.com/releases/2022/01/11/security-release-gitlab-14-6-2-released/
https://about.gitlab.com/releases/2022/01/04/gitlab-14-6-1-released/

Descriptors.hpp 18.4 KB
Newer Older
Quentin Khan's avatar
Quentin Khan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef DESCRIPTORS_HPP
#define DESCRIPTORS_HPP

#include <cstddef>
#include <memory>

#include "Utils/make_unique.hpp"
#include "FPerfTestParams.hpp"

/**
 * \brief Kernel descriptor base model
 */
template<typename FReal, std::size_t I>
struct kernel_descriptor {
    /// Optional, detected via SFINAE
    enum : bool {disabled = true};
    /// Kernel name for runtime lookup, must be unique
    constexpr static const char* name = "";

Quentin Khan's avatar
Quentin Khan committed
20
    /// Cell tree type used by kernel
Quentin Khan's avatar
Quentin Khan committed
21
    using cell_data_t = void;
Quentin Khan's avatar
Quentin Khan committed
22
23
    /// Particle container type used in tree
    using container_t = void;
Quentin Khan's avatar
Quentin Khan committed
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

    /// Used after a successful kernel lookup to build the kernel
    template<typename tree_desc> struct kernel_factory {
        /**
         * \brief Build the kernel
         *
         * \note Template parameters are there to explain the method
         * signature. It does not need to be a template.
         *
         * \tparam kernel_t Kernel type, should already be known or deduced
         * \tparam tree_t Tree type
         */
        template<typename kernel_t, typename tree_t>
        std::unique_ptr<kernel_t> build(FPerfTestParams&, tree_t&);
    };
};

/// Tree descriptor base model
struct tree_descriptor {
    /// Used to build the tree
    template<typename algo_desc, typename kernel_desc>
    struct tree_factory {
        /**
         * \brief Build the tree
         *
         * \note Template parameters are there to explain the method
         * signature. It does not need to be a template.
         *
         * \tparam tree_t Tree type, should already be known or deduced
         * \tparam loader_t Loader type
         */
        template<typename tree_t, typename loader_t>
        std::unique_ptr<tree_t> build(FPerfTestParams&, loader_t&);
    };
};

/// Tree loader descriptor base model
struct loader_descriptor {
    /// Loads particles in a tree
    struct loader {
        /**
         * \brief Load the tree
         * \tparam tree_t Tree type
         * \note Does not need to be a template
         */
        template<typename tree_t>
        void load(tree_t&);
    };

    /// Used to build the loader
    struct loader_factory {
        /// Build the loader
        std::unique_ptr<loader> build(FPerfTestParams&);
    };
};


/**
 * \brief Algorithm descriptor base model
 */
template<typename FReal, std::size_t I>
struct algo_descriptor {
    /// Optional, detected via SFINAE
    enum : bool {disabled = true};
    /// Algorithm name for runtime lookup, must be unique
    constexpr static const char* name = "";
    /// Tree descriptor associated to this algorithm
    using tree_desc = tree_descriptor;
    /// Used after a successful algorithm lookup to build algorithm
    template<typename kernel_desc> struct algo_factory {
        /**
         * \brief Build the algorithm
         *
         * \note Template parameters are there to explain the method
         * signature. It does not need to be a template.
         *
         * \tparam algo_t Algorithm type, should already be known or deduced
         * \tparam tree_t Tree type
         * \tparam kernel_t Kernel type
         */
        template<typename algo_t, typename tree_t, typename kernel_t>
        std::unique_ptr<algo_t> build(FPerfTestParams&, tree_t&, kernel_t&);
    };
};


// Lagrange kernel descriptor ////////////////////

Quentin Khan's avatar
Quentin Khan committed
112
113
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"

Quentin Khan's avatar
Quentin Khan committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
#include "Kernels/Uniform/FUnifCell.hpp"
#include "Adaptive/new/FAdaptUnifKernel.hpp"

/**
 * \brief Lagrange kernel descriptor specialisation
 */
template<typename FReal>
struct kernel_descriptor<FReal, 0> {
    /// Kernel lookup name
    constexpr static const char* name = "lagrange";
    /// Interpolation order
    constexpr static const int ORDER = 7;
    /// Kernel cell data type
    using cell_data_t = FUnifCell<FReal, ORDER>;
Quentin Khan's avatar
Quentin Khan committed
129
130
    /// Particle container data type
    using container_t = FP2PParticleContainerIndexed<FReal>;
Quentin Khan's avatar
Quentin Khan committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    /// Direct interaction kernel type
    using MatrixKernelClass = FInterpMatrixKernelR<FReal>;

    template<typename tree_descriptor>
    struct kernel_factory {
        /// Kernel type
        using kernel_t = FAdaptUnifKernel<FReal, cell_data_t, container_t , MatrixKernelClass, ORDER>;

        /// Direct interation kernel instance
        MatrixKernelClass MatrixKernel;

        /** \brief Build method */
        template<typename tree_t>
        std::unique_ptr<kernel_t> build(const FPerfTestParams&, tree_t& tree) {
            return std::make_unique<kernel_t>(static_cast<int>(tree.getHeight()),
                                              tree.getBoxWidth(),
                                              tree.getBoxCenter(),
                                              &(this->MatrixKernel));
        }
    };
};


// Chebyshev kernel descriptor ///////////////////

#include "Kernels/Chebyshev/FChebCell.hpp"
#include "Adaptive/new/FAdaptChebKernel.hpp"

template<typename FReal> struct kernel_descriptor<FReal, 1> {
    /// Kernel lookup name
    constexpr static const char* name = "chebyshev";
    /// Kernel interpolation order
    constexpr static const int ORDER = 7;
    /// Kernel cell data
    using cell_data_t = FChebCell<FReal, ORDER>;
Quentin Khan's avatar
Quentin Khan committed
166
167
    /// Particle container data type
    using container_t = FP2PParticleContainerIndexed<FReal>;
Quentin Khan's avatar
Quentin Khan committed
168
169
170
171
172
173
174
175
176
177
178
    /// Direct interaction kernel type
    using MatrixKernelClass = FInterpMatrixKernelR<FReal>;

    template<typename tree_descriptor>
    struct kernel_factory {
        /// Kernel type
        using kernel_t = FAdaptChebKernel<FReal, cell_data_t, container_t , MatrixKernelClass, ORDER>;

        /// Direct interaction kernel instance
        MatrixKernelClass MatrixKernel;

Quentin Khan's avatar
Quentin Khan committed
179
        /** \brief Build method */
Quentin Khan's avatar
Quentin Khan committed
180
181
182
183
184
185
186
187
188
189
190
        template<typename tree_t>
        std::unique_ptr<kernel_t> build(const FPerfTestParams&, tree_t& tree) {
            return std::make_unique<kernel_t>(static_cast<int>(tree.getHeight()),
                                              tree.getBoxWidth(),
                                              tree.getBoxCenter(),
                                              &(this->MatrixKernel));
        }
    };
};


Quentin Khan's avatar
Quentin Khan committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Count kernel descriptor ///////////////////////

#include "../Adaptive/FCountKernel.hpp"

template<typename FReal> struct kernel_descriptor<FReal, 2> {
    /// Kernel lookup name
    constexpr static const char* name = "count";
    /// Kernel cell data
    using cell_data_t = TestCountNodeData;
    /// Particle type
    using particle_t = TestCountParticle<FReal, 3>;
    /// Particle container type
    using container_t = FVariadicParticleContainer<particle_t>;

    /// Kernel type
    using kernel_t = FCountKernel<cell_data_t, container_t>;

    template<typename tree_descriptor>
    struct kernel_factory {
        /// Kernel type
211
        using kernel_t = kernel_descriptor<FReal, 2>::kernel_t;
Quentin Khan's avatar
Quentin Khan committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

        /** \brief Build method */
        template<typename tree_t>
        std::unique_ptr<kernel_t> build(const FPerfTestParams&, tree_t& /*tree*/) {
            return std::make_unique<kernel_t>();
        }
    };

    static void info(FPerfTestParams& params, const kernel_t& kernel) {
        for(auto t : kernel.call_count) {
            params.json["calls"][t.first] = t.second;
        }
    }
};


Quentin Khan's avatar
Quentin Khan committed
228
229
230
231
232
233
234
235
236
237
// Shared memory adaptive tree descriptor ////////

#include "Adaptive/new/FTree.hpp"

template<typename FReal>
struct adaptive_tree_descriptor {
    constexpr static const char* name = "adaptive-tree";

    template<typename algo_desc, typename kernel_desc>
    struct tree_factory {
Quentin Khan's avatar
Quentin Khan committed
238
        using tree_t = FTree<typename kernel_desc::container_t, typename kernel_desc::cell_data_t>;
Quentin Khan's avatar
Quentin Khan committed
239
240
241
242
243
244
245
246

        template<typename loader_t>
        std::unique_ptr<tree_t> build(const FPerfTestParams& params, loader_t& loader) {
            auto tree = std::make_unique<tree_t>(typename tree_t::box_t{loader.getBoxWidth(), loader.getCenterOfBox()});
            tree->leaf_max_particle_count(params.adaptive_density);
            return tree;
        }
    };
Quentin Khan's avatar
Quentin Khan committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

    template<typename tree_t>
    static void info(FPerfTestParams& params, const tree_t& tree) {
        params.json["config"]["tree"]["height"] = tree.height();
        params.json["config"]["tree"]["leaf density"] = tree.leaf_max_particle_count();

        std::size_t min = std::numeric_limits<std::size_t>::max(), max = 0;
        for(auto& leaf : tree.leaves()) {
            if(leaf->getParticleContainer() && leaf->getParticleContainer()->size()) {
                auto size = leaf->getParticleContainer()->size();
                min = std::min(min, size);
                max = std::max(max, size);
            }
        }

        params.json["config"]["tree"]["min"] = min;
        params.json["config"]["tree"]["max"] = max;

        std::fstream fout("test.obj", std::ios::out);
        fout << scalfmm::fmt::obj << tree;
        fout << std::flush;
        fout.close();
    }

Quentin Khan's avatar
Quentin Khan committed
271
272
273
274
275
276
277
278
279
280
281
282
};


// Shared memory uniform tree descriptor /////////

#include "Containers/FOctree.hpp"
#include "Components/FSimpleLeaf.hpp"

template<typename FReal>
struct uniform_tree_descriptor {
    constexpr static const char* name = "uniform-tree";

Quentin Khan's avatar
Quentin Khan committed
283
284
    template<typename kernel_desc>
    using leaf_tpl = FSimpleLeaf<FReal, typename kernel_desc::container_t>;
Quentin Khan's avatar
Quentin Khan committed
285
286
287

    template<typename algo_desc, typename kernel_desc>
    struct tree_factory {
Quentin Khan's avatar
Quentin Khan committed
288
289
290

        using leaf_t = leaf_tpl<kernel_desc>;
        using tree_t = FOctree<FReal, typename kernel_desc::cell_data_t, typename kernel_desc::container_t, leaf_t>;
Quentin Khan's avatar
Quentin Khan committed
291
292
293
294
295
296
297

        template<typename loader_t>
        std::unique_ptr<tree_t> build(const FPerfTestParams& params, loader_t& loader) {
            return std::make_unique<tree_t>(params.treeHeight, params.subTreeHeight, loader.getBoxWidth(), loader.getCenterOfBox());
        }
    };

Quentin Khan's avatar
Quentin Khan committed
298
299
300
301
302
    template<typename tree_t>
    static void info(FPerfTestParams& params, tree_t& tree) {
        params.json["config"]["tree"]["height"] = tree.getHeight();
    }

Quentin Khan's avatar
Quentin Khan committed
303
304
305
306
307
308
};


// Basic loader descriptor ///////////////////////
#include <thread>

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
struct progress_bar {
    std::stringstream sstr;
    std::thread t;

    progress_bar() {
        this->sstr.precision(3);
    }

    template<typename Loader>
    void follow(FSize& idx, Loader& l) {
        this->t = std::thread(
            [this,&idx,&l]() {
                bool run = true;
                while(run) {
                    sstr.str("");
                    sstr.clear();
                    sstr.precision(4);
                    double p = static_cast<double>(idx) * 100.
                        / static_cast<double>(l.getNumberOfParticles());
                    sstr << "Loading particles: [";
                    for(double i = 0; i < 100; i += 7.5) {
                        sstr << (i < p ? '|' : ' ');
                    }
                    sstr << "] " << p << "%    ";
                    std::cout << '\r' << sstr.str() << std::flush;
                    run = idx < l.getNumberOfParticles();
                    std::this_thread::sleep_for(std::chrono::milliseconds(200));
                }
            });
    }

    void finish() {
        this->t.join();
    }
};

#include "Files/FFmaGenericLoader.hpp"
Quentin Khan's avatar
Quentin Khan committed
346
347
348
349
350

template<typename FReal>
struct default_loader_descriptor {
    struct loader_t : public FFmaGenericLoader<FReal> {

351
        progress_bar progress;
Quentin Khan's avatar
Quentin Khan committed
352
353
354
355
356
357
358
359
360
361
362
363
364

        loader_t(const FPerfTestParams& params)
            : FFmaGenericLoader<FReal>(params.filename){
        }

        template<typename tree_t>
        void load(tree_t& tree) {
            std::cout << "Loading particles: " << std::flush;

            FSize idxPart = 0;
            FPoint<FReal> position;
            FReal physicalValue = 0.0;

365
            progress.follow(idxPart,*this);
Quentin Khan's avatar
Quentin Khan committed
366
367
368
369
370
371
372

            for(idxPart = 0 ; idxPart < this->getNumberOfParticles() ; ++idxPart){
                // Read particle per particle from file
                this->fillParticle(&position,&physicalValue);
                // put particle in octree
                tree.insert(position, idxPart, physicalValue);
            }
373
            progress.finish();
Quentin Khan's avatar
Quentin Khan committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
            std::cout << "done." << std::endl;
        }
    };

    struct loader_factory {
        std::unique_ptr<loader_t> build(const FPerfTestParams& params) {
            return std::make_unique<loader_t>(params);
        }
    };
};


// Sequential adaptive FMM algorithm descriptor //

#include "Adaptive/new/FAdaptiveSequential.hpp"

template<typename FReal> struct algo_descriptor<FReal, 0> {
    constexpr static const char* name = "adaptive-sequential";

    using tree_desc = adaptive_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;


    template<typename kernel_factory>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FAdaptiveSequential<tree_t, kernel_t>;

        template<typename tree_t, typename kernel_t>
        std::unique_ptr<algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique<algo_t<tree_t, kernel_t> >(tree, kernel);
        }
    };
};


// Task adaptive FMM algorithm ///////////////////

#include "Adaptive/new/FAdaptiveTask.hpp"
template<typename FReal> struct algo_descriptor<FReal, 1> {
    constexpr static const char* name = "adaptive-task";

    using tree_desc = adaptive_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;


    template<typename kernel_factory>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FAdaptiveTask<tree_t, kernel_t>;

        template<typename tree_t, typename kernel_t>
        std::unique_ptr<algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique<algo_t<tree_t, kernel_t> >(tree, kernel);
        }
    };
};



// Sequential uniform FMM algorithm descriptor ///

#include "Core/FFmmAlgorithm.hpp"

template<typename FReal> struct algo_descriptor<FReal, 2> {
    constexpr static const char* name = "uniform-sequential";

    using tree_desc = uniform_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;

    template<typename kernel_descriptor>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FFmmAlgorithm<
            tree_t, typename kernel_descriptor::cell_data_t,
Quentin Khan's avatar
Quentin Khan committed
454
455
            typename kernel_descriptor::container_t, kernel_t,
            typename tree_desc::template leaf_tpl<kernel_descriptor> >;
Quentin Khan's avatar
Quentin Khan committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481

        template<typename tree_t, typename kernel_t>
        std::unique_ptr< algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique< algo_t<tree_t, kernel_t> >(&tree, &kernel);
        }
    };
};


// Threaded uniform FMM algorithm descriptor ////

#include "Core/FFmmAlgorithmThread.hpp"

template<typename FReal> struct algo_descriptor<FReal, 3> {
    constexpr static const char* name = "uniform-thread";

    using tree_desc = uniform_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;

    template<typename kernel_descriptor>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FFmmAlgorithmThread<
            tree_t, typename kernel_descriptor::cell_data_t,
Quentin Khan's avatar
Quentin Khan committed
482
483
            typename kernel_descriptor::container_t, kernel_t,
            typename tree_desc::template leaf_tpl<kernel_descriptor> >;
Quentin Khan's avatar
Quentin Khan committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

        template<typename tree_t, typename kernel_t>
        std::unique_ptr< algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique< algo_t<tree_t, kernel_t> >(&tree, &kernel);
        }
    };
};


// Task uniform FMM algorithm descriptor

#include "Core/FFmmAlgorithmTask.hpp"

template<typename FReal> struct algo_descriptor<FReal, 4> {
    constexpr static const char* name = "uniform-task";

    using tree_desc = uniform_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;

    template<typename kernel_descriptor>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FFmmAlgorithmTask<
            tree_t, typename kernel_descriptor::cell_data_t,
Quentin Khan's avatar
Quentin Khan committed
510
511
            typename kernel_descriptor::container_t, kernel_t,
            typename tree_desc::template leaf_tpl<kernel_descriptor> >;
Quentin Khan's avatar
Quentin Khan committed
512
513
514
515
516
517
518
519
520

        template<typename tree_t, typename kernel_t>
        std::unique_ptr< algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique< algo_t<tree_t, kernel_t> >(&tree, &kernel);
        }
    };
};

521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// Section task uniform FMM algorithm descriptor

#include "Core/FFmmAlgorithmSectionTask.hpp"

template<typename FReal> struct algo_descriptor<FReal, 5> {
    constexpr static const char* name = "uniform-sectiontask";

    using tree_desc = uniform_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;

    template<typename kernel_descriptor>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FFmmAlgorithmSectionTask<
            tree_t, typename kernel_descriptor::cell_data_t,
Quentin Khan's avatar
Quentin Khan committed
537
538
            typename kernel_descriptor::container_t, kernel_t,
            typename tree_desc::template leaf_tpl<kernel_descriptor> >;
539
540
541
542
543
544
545
546
547

        template<typename tree_t, typename kernel_t>
        std::unique_ptr< algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique< algo_t<tree_t, kernel_t> >(&tree, &kernel);
        }
    };
};

Quentin Khan's avatar
Quentin Khan committed
548
549
550
551
552
553
554

// OpenMP 4 task uniform fmm algorithm ///////////

#ifndef __clang__

#include "Core/FFmmAlgorithmOmp4.hpp"

555
template<typename FReal> struct algo_descriptor<FReal, 6> {
Quentin Khan's avatar
Quentin Khan committed
556
557
558
559
560
561
562
563
564
565
566
    constexpr static const char* name = "uniform-task-omp4";

    using tree_desc = uniform_tree_descriptor<FReal>;
    using loader_descriptor = default_loader_descriptor<FReal>;

    template<typename kernel_descriptor>
    struct algo_factory {

        template<typename tree_t, typename kernel_t>
        using algo_t = FFmmAlgorithmOmp4<
            tree_t, typename kernel_descriptor::cell_data_t,
Quentin Khan's avatar
Quentin Khan committed
567
568
            typename kernel_descriptor::container_t, kernel_t,
            typename tree_desc::template leaf_tpl<kernel_descriptor> >;
Quentin Khan's avatar
Quentin Khan committed
569
570
571
572
573
574
575
576
577
578
579

        template<typename tree_t, typename kernel_t>
        std::unique_ptr< algo_t<tree_t, kernel_t> >
        build(const FPerfTestParams&, tree_t& tree, kernel_t& kernel) {
            return std::make_unique< algo_t<tree_t, kernel_t> >(&tree, &kernel);
        }
    };
};

#endif

Quentin Khan's avatar
Quentin Khan committed
580

Quentin Khan's avatar
Quentin Khan committed
581
#endif /* DESCRIPTORS_HPP */