• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2012 Francisco Jerez
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22 
23 #include "core/platform.hpp"
24 #include "util/u_debug.h"
25 
26 using namespace clover;
27 
platform()28 platform::platform() : adaptor_range(evals(), devs) {
29    int n = pipe_loader_probe(NULL, 0);
30    std::vector<pipe_loader_device *> ldevs(n);
31 
32    unsigned major = 1, minor = 1;
33    debug_get_version_option("CLOVER_PLATFORM_VERSION_OVERRIDE", &major, &minor);
34    version = CL_MAKE_VERSION(major, minor, 0);
35 
36    pipe_loader_probe(&ldevs.front(), n);
37 
38    for (pipe_loader_device *ldev : ldevs) {
39       try {
40          if (ldev)
41             devs.push_back(create<device>(*this, ldev));
42       } catch (error &) {
43          pipe_loader_release(&ldev, 1);
44       }
45    }
46 }
47 
48 std::vector<cl_name_version>
supported_extensions() const49 platform::supported_extensions() const {
50    std::vector<cl_name_version> vec;
51 
52    vec.push_back( cl_name_version{ CL_MAKE_VERSION(1, 0, 0), "cl_khr_icd" } );
53    return vec;
54 }
55 
56 std::string
supported_extensions_as_string() const57 platform::supported_extensions_as_string() const {
58    static std::string extensions_string;
59 
60    if (!extensions_string.empty())
61       return extensions_string;
62 
63    const auto extension_list = supported_extensions();
64    for (const auto &extension : extension_list) {
65       if (!extensions_string.empty())
66          extensions_string += " ";
67       extensions_string += extension.name;
68    }
69    return extensions_string;
70 }
71 
72 std::string
platform_version_as_string() const73 platform::platform_version_as_string() const {
74    static const std::string version_string =
75       std::to_string(CL_VERSION_MAJOR(version)) + "." +
76       std::to_string(CL_VERSION_MINOR(version));
77    return version_string;
78 }
79 
80 cl_version
platform_version() const81 platform::platform_version() const {
82    return version;
83 }
84