ddemidov / vexcl
1
#ifndef VEXCL_BACKEND_JIT_FILTER_HPP
2
#define VEXCL_BACKEND_JIT_FILTER_HPP
3

4
/*
5
The MIT License
6

7
Copyright (c) 2012-2018 Denis Demidov <dennis.demidov@gmail.com>
8

9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15

16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18

19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
*/
27

28
/**
29
 * \file   vexcl/backend/jit/filter.hpp
30
 * \author Denis Demidov <dennis.demidov@gmail.com>
31
 * \brief  Device filters for the JIT backend.
32
 */
33

34
#include <string>
35
#include <vector>
36
#include <functional>
37
#include <cstdlib>
38

39
namespace vex {
40
namespace Filter {
41

42
struct DummyFilter {
43
    bool v;
44 2
    DummyFilter(bool v) : v(v) {}
45 2
    bool operator()(const backend::device &d) const { return v; }
46
};
47

48 2
const DummyFilter GPU(false);
49 2
const DummyFilter CPU(true);
50 2
const DummyFilter Accelerator(false);
51 2
const DummyFilter DoublePrecision(true);
52

53 0
struct Name {
54 0
    explicit Name(std::string name) : devname(std::move(name)) {}
55

56 0
    bool operator()(const backend::device &d) const {
57 0
        return d.name().find(devname) != std::string::npos;
58
    }
59

60
    private:
61
        std::string devname;
62
};
63

64
// The JIT backend does not support the exclusive filter functionality,
65
// but provides the filter for compatibility.
66
template <class Filter>
67
Filter Exclusive(Filter&& filter) {
68
    return std::forward<Filter>(filter);
69
}
70

71
inline std::vector< std::function<bool(const backend::device&)> >
72 2
backend_env_filters()
73
{
74 2
    std::vector< std::function<bool(const backend::device&)> > filter;
75

76 2
    if (const char *name = getenv("OCL_DEVICE"))
77 0
        filter.push_back(Name(name));
78

79 2
    return filter;
80
}
81

82
} // namespace Filter
83
} // namespace vex
84

85

86
#endif

Read our documentation on viewing source code .

Loading