Skip to content

Commit 95b732d

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#2)
2 parents 7bd9143 + 9f8ae50 commit 95b732d

File tree

10 files changed

+324
-181
lines changed

10 files changed

+324
-181
lines changed

sycl/include/CL/sycl/detail/device_info.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010
#include <CL/sycl/detail/common_info.hpp>
1111
#include <CL/sycl/detail/pi.hpp>
12+
#include <CL/sycl/detail/platform_impl.hpp>
1213
#include <CL/sycl/info/info_desc.hpp>
1314
#include <CL/sycl/platform.hpp>
1415

@@ -61,7 +62,7 @@ template <info::device param> struct get_device_info<platform, param> {
6162
PI_CALL(piDeviceGetInfo)(dev, pi::cast<RT::PiDeviceInfo>(param),
6263
sizeof(result), &result, nullptr);
6364
return createSyclObjFromImpl<platform>(
64-
std::make_shared<platform_impl_pi>(result));
65+
std::make_shared<platform_impl>(result));
6566
}
6667
};
6768

sycl/include/CL/sycl/detail/platform_impl.hpp

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <CL/sycl/info/info_desc.hpp>
1515
#include <CL/sycl/stl.hpp>
1616

17-
// 4.6.2 Platform class
1817
namespace cl {
1918
namespace sycl {
2019

@@ -24,88 +23,100 @@ class device;
2423

2524
namespace detail {
2625

26+
// TODO: implement extension management for host device
27+
// TODO: implement parameters treatment for host device
2728
class platform_impl {
2829
public:
29-
platform_impl() = default;
30+
/// Constructs platform_impl for a SYCL host platform.
31+
platform_impl() : MHostPlatform(true) {}
3032

31-
explicit platform_impl(const device_selector &);
33+
/// Constructs platform_impl from a plug-in interoperability platform handle.
34+
///
35+
/// @param Platform is a raw plug-in platform handle.
36+
explicit platform_impl(RT::PiPlatform Platform) : MPlatform(Platform) {}
3237

33-
virtual bool has_extension(const string_class &extension_name) const = 0;
38+
~platform_impl() = default;
3439

35-
virtual vector_class<device>
36-
get_devices(info::device_type = info::device_type::all) const = 0;
40+
/// Checks if this platform supports extension.
41+
///
42+
/// @param ExtensionName is a string containing extension name.
43+
/// @return true if platform supports specified extension.
44+
bool has_extension(const string_class &ExtensionName) const {
45+
if (is_host())
46+
return false;
3747

48+
string_class AllExtensionNames =
49+
get_platform_info<string_class, info::platform::extensions>::get(
50+
MPlatform);
51+
return (AllExtensionNames.find(ExtensionName) != std::string::npos);
52+
}
53+
54+
/// Returns all SYCL devices associated with this platform.
55+
///
56+
/// If this platform is a host platform and device type requested is either
57+
/// info::device_type::all or info::device_type::host, resulting vector
58+
/// contains only a single SYCL host device. If there are no devices that
59+
/// match given device type, resulting vector is empty.
60+
///
61+
/// @param DeviceType is a SYCL device type.
62+
/// @return a vector of SYCL devices.
63+
vector_class<device>
64+
get_devices(info::device_type DeviceType = info::device_type::all) const;
65+
66+
/// Queries this SYCL platform for info.
67+
///
68+
/// The return type depends on information being queried.
3869
template <info::platform param>
3970
typename info::param_traits<info::platform, param>::return_type
4071
get_info() const {
41-
if (is_host()) {
72+
if (is_host())
4273
return get_platform_info_host<param>();
43-
}
74+
4475
return get_platform_info<
4576
typename info::param_traits<info::platform, param>::return_type,
4677
param>::get(this->getHandleRef());
4778
}
4879

49-
virtual bool is_host() const = 0;
80+
/// @return true if this SYCL platform is a host platform.
81+
bool is_host() const { return MHostPlatform; };
5082

51-
virtual cl_platform_id get() const = 0;
52-
53-
// Returns underlying native platform object.
54-
virtual const RT::PiPlatform &getHandleRef() const = 0;
55-
56-
virtual ~platform_impl() = default;
57-
};
83+
/// @return an instance of OpenCL cl_platform_id.
84+
cl_platform_id get() const {
85+
if (is_host())
86+
throw invalid_object_error(
87+
"This instance of platform is a host instance");
5888

59-
// TODO: merge platform_impl_pi, platform_impl_host and platform_impl?
60-
class platform_impl_pi : public platform_impl {
61-
public:
62-
platform_impl_pi(RT::PiPlatform a_platform) : m_platform(a_platform) {}
63-
64-
vector_class<device> get_devices(
65-
info::device_type deviceType = info::device_type::all) const override;
66-
67-
bool has_extension(const string_class &extension_name) const override {
68-
string_class all_extension_names =
69-
get_platform_info<string_class, info::platform::extensions>::get(
70-
m_platform);
71-
return (all_extension_names.find(extension_name) != std::string::npos);
89+
return pi::cast<cl_platform_id>(MPlatform);
7290
}
7391

74-
cl_platform_id get() const override { return pi::cast<cl_platform_id>(m_platform); }
75-
76-
const RT::PiPlatform &getHandleRef() const override { return m_platform; }
77-
78-
bool is_host() const override { return false; }
92+
/// Returns raw underlying plug-in platform handle.
93+
///
94+
/// Unlike get() method, this method does not retain handler. It is caller
95+
/// responsibility to make sure that platform stays alive while raw handle
96+
/// is in use.
97+
///
98+
/// @return a raw plug-in platform handle.
99+
const RT::PiPlatform &getHandleRef() const {
100+
if (is_host())
101+
throw invalid_object_error(
102+
"This instance of platform is a host instance");
103+
104+
return MPlatform;
105+
}
79106

107+
/// Returns all available SYCL platforms in the system.
108+
///
109+
/// By default the resulting vector always contains a single SYCL host
110+
/// platform instance. There are means to override this behavior for testing
111+
/// purposes. See environment variables guide for up-to-date instructions.
112+
///
113+
/// @return a vector of all available SYCL platforms.
80114
static vector_class<platform> get_platforms();
81115

82116
private:
83-
RT::PiPlatform m_platform = 0;
84-
}; // class platform_opencl
85-
86-
// TODO: implement extension management
87-
// TODO: implement parameters treatment
88-
// TODO: merge platform_impl_pi, platform_impl_host and platform_impl?
89-
class platform_impl_host : public platform_impl {
90-
public:
91-
vector_class<device> get_devices(
92-
info::device_type dev_type = info::device_type::all) const override;
93-
94-
bool has_extension(const string_class &extension_name) const override {
95-
return false;
96-
}
97-
98-
cl_platform_id get() const override {
99-
throw invalid_object_error("This instance of platform is a host instance");
100-
}
101-
const RT::PiPlatform &getHandleRef() const override {
102-
throw invalid_object_error("This instance of platform is a host instance");
103-
}
104-
105-
bool is_host() const override { return true; }
106-
}; // class platform_host
107-
108-
117+
bool MHostPlatform = false;
118+
RT::PiPlatform MPlatform = 0;
119+
};
109120
} // namespace detail
110121
} // namespace sycl
111122
} // namespace cl

0 commit comments

Comments
 (0)