Skip to content

Commit 56b9a1d

Browse files
author
Alexander Batashev
authored
[SYCL] Fix instantiation after specialization warning (#2818)
Explicit instantiation of template that occurs after an explicit specialization has no effect. Move template specializations to header to avoid this kind of warnings.
1 parent ebc9886 commit 56b9a1d

File tree

3 files changed

+83
-124
lines changed

3 files changed

+83
-124
lines changed

sycl/source/detail/kernel_impl.cpp

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <CL/sycl/detail/common.hpp>
10-
#include <CL/sycl/info/info_desc.hpp>
11-
#include <CL/sycl/program.hpp>
129
#include <detail/context_impl.hpp>
1310
#include <detail/kernel_impl.hpp>
14-
#include <detail/kernel_info.hpp>
1511
#include <detail/program_impl.hpp>
1612

1713
#include <memory>
@@ -63,121 +59,6 @@ kernel_impl::~kernel_impl() {
6359
}
6460
}
6561

66-
template <info::kernel param>
67-
typename info::param_traits<info::kernel, param>::return_type
68-
kernel_impl::get_info() const {
69-
if (is_host()) {
70-
// TODO implement
71-
assert(0 && "Not implemented");
72-
}
73-
return get_kernel_info<
74-
typename info::param_traits<info::kernel, param>::return_type,
75-
param>::get(this->getHandleRef(), getPlugin());
76-
}
77-
78-
template <> context kernel_impl::get_info<info::kernel::context>() const {
79-
return createSyclObjFromImpl<context>(MContext);
80-
}
81-
82-
template <> program kernel_impl::get_info<info::kernel::program>() const {
83-
return createSyclObjFromImpl<program>(MProgramImpl);
84-
}
85-
86-
template <info::kernel_device_specific param>
87-
typename info::param_traits<info::kernel_device_specific, param>::return_type
88-
kernel_impl::get_info(const device &Device) const {
89-
if (is_host()) {
90-
return get_kernel_device_specific_info_host<param>(Device);
91-
}
92-
return get_kernel_device_specific_info<
93-
typename info::param_traits<info::kernel_device_specific,
94-
param>::return_type,
95-
param>::get(this->getHandleRef(), getSyclObjImpl(Device)->getHandleRef(),
96-
getPlugin());
97-
}
98-
99-
template <info::kernel_device_specific param>
100-
typename info::param_traits<info::kernel_device_specific, param>::return_type
101-
kernel_impl::get_info(
102-
const device &Device,
103-
typename info::param_traits<info::kernel_device_specific, param>::input_type
104-
Value) const {
105-
if (is_host()) {
106-
throw runtime_error("Sub-group feature is not supported on HOST device.",
107-
PI_INVALID_DEVICE);
108-
}
109-
return get_kernel_device_specific_info_with_input<param>::get(
110-
this->getHandleRef(), getSyclObjImpl(Device)->getHandleRef(), Value,
111-
getPlugin());
112-
}
113-
114-
template <info::kernel_work_group param>
115-
typename info::param_traits<info::kernel_work_group, param>::return_type
116-
kernel_impl::get_work_group_info(const device &Device) const {
117-
return get_info<
118-
info::compatibility_param_traits<info::kernel_work_group, param>::value>(
119-
Device);
120-
}
121-
122-
template <info::kernel_sub_group param>
123-
typename info::param_traits<info::kernel_sub_group, param>::return_type
124-
kernel_impl::get_sub_group_info(const device &Device) const {
125-
return get_info<
126-
info::compatibility_param_traits<info::kernel_sub_group, param>::value>(
127-
Device);
128-
}
129-
130-
template <info::kernel_sub_group param>
131-
typename info::param_traits<info::kernel_sub_group, param>::return_type
132-
kernel_impl::get_sub_group_info(
133-
const device &Device,
134-
typename info::param_traits<info::kernel_sub_group, param>::input_type
135-
Value) const {
136-
return get_info<
137-
info::compatibility_param_traits<info::kernel_sub_group, param>::value>(
138-
Device, Value);
139-
}
140-
141-
#define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
142-
template ret_type kernel_impl::get_info<info::param_type::param>() const;
143-
144-
#include <CL/sycl/info/kernel_traits.def>
145-
146-
#undef __SYCL_PARAM_TRAITS_SPEC
147-
148-
#define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
149-
template ret_type kernel_impl::get_info<info::param_type::param>( \
150-
const device &) const;
151-
#define __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(param_type, param, ret_type, \
152-
in_type) \
153-
template ret_type kernel_impl::get_info<info::param_type::param>( \
154-
const device &, in_type) const;
155-
156-
#include <CL/sycl/info/kernel_device_specific_traits.def>
157-
158-
#undef __SYCL_PARAM_TRAITS_SPEC
159-
#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT
160-
161-
#define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
162-
template ret_type kernel_impl::get_work_group_info<info::param_type::param>( \
163-
const device &) const;
164-
165-
#include <CL/sycl/info/kernel_work_group_traits.def>
166-
167-
#undef __SYCL_PARAM_TRAITS_SPEC
168-
169-
#define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
170-
template ret_type kernel_impl::get_sub_group_info<info::param_type::param>( \
171-
const device &) const;
172-
#define __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(param_type, param, ret_type, \
173-
in_type) \
174-
template ret_type kernel_impl::get_sub_group_info<info::param_type::param>( \
175-
const device &, in_type) const;
176-
177-
#include <CL/sycl/info/kernel_sub_group_traits.def>
178-
179-
#undef __SYCL_PARAM_TRAITS_SPEC
180-
#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT
18162

18263
bool kernel_impl::isCreatedFromSource() const {
18364
// TODO it is not clear how to understand whether the SYCL kernel is created

sycl/source/detail/kernel_impl.hpp

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
#include <CL/sycl/detail/pi.hpp>
1313
#include <CL/sycl/device.hpp>
1414
#include <CL/sycl/info/info_desc.hpp>
15+
#include <CL/sycl/program.hpp>
1516
#include <detail/context_impl.hpp>
1617
#include <detail/device_impl.hpp>
18+
#include <detail/kernel_info.hpp>
1719

1820
#include <cassert>
1921
#include <memory>
2022

2123
__SYCL_INLINE_NAMESPACE(cl) {
2224
namespace sycl {
23-
// Forward declaration
24-
class program;
25-
2625
namespace detail {
26+
// Forward declaration
2727
class program_impl;
2828

29-
using ContextImplPtr = std::shared_ptr<detail::context_impl>;
29+
using ContextImplPtr = std::shared_ptr<context_impl>;
3030
using ProgramImplPtr = std::shared_ptr<program_impl>;
3131
class kernel_impl {
3232
public:
@@ -176,6 +176,85 @@ class kernel_impl {
176176
bool MCreatedFromSource = true;
177177
};
178178

179+
template <info::kernel param>
180+
inline typename info::param_traits<info::kernel, param>::return_type
181+
kernel_impl::get_info() const {
182+
if (is_host()) {
183+
// TODO implement
184+
assert(0 && "Not implemented");
185+
}
186+
return get_kernel_info<
187+
typename info::param_traits<info::kernel, param>::return_type,
188+
param>::get(this->getHandleRef(), getPlugin());
189+
}
190+
191+
template <>
192+
inline context kernel_impl::get_info<info::kernel::context>() const {
193+
return createSyclObjFromImpl<context>(MContext);
194+
}
195+
196+
template <>
197+
inline program kernel_impl::get_info<info::kernel::program>() const {
198+
return createSyclObjFromImpl<program>(MProgramImpl);
199+
}
200+
201+
template <info::kernel_device_specific param>
202+
inline typename info::param_traits<info::kernel_device_specific,
203+
param>::return_type
204+
kernel_impl::get_info(const device &Device) const {
205+
if (is_host()) {
206+
return get_kernel_device_specific_info_host<param>(Device);
207+
}
208+
return get_kernel_device_specific_info<
209+
typename info::param_traits<info::kernel_device_specific,
210+
param>::return_type,
211+
param>::get(this->getHandleRef(), getSyclObjImpl(Device)->getHandleRef(),
212+
getPlugin());
213+
}
214+
215+
template <info::kernel_device_specific param>
216+
inline typename info::param_traits<info::kernel_device_specific,
217+
param>::return_type
218+
kernel_impl::get_info(
219+
const device &Device,
220+
typename info::param_traits<info::kernel_device_specific, param>::input_type
221+
Value) const {
222+
if (is_host()) {
223+
throw runtime_error("Sub-group feature is not supported on HOST device.",
224+
PI_INVALID_DEVICE);
225+
}
226+
return get_kernel_device_specific_info_with_input<param>::get(
227+
this->getHandleRef(), getSyclObjImpl(Device)->getHandleRef(), Value,
228+
getPlugin());
229+
}
230+
231+
template <info::kernel_work_group param>
232+
inline typename info::param_traits<info::kernel_work_group, param>::return_type
233+
kernel_impl::get_work_group_info(const device &Device) const {
234+
return get_info<
235+
info::compatibility_param_traits<info::kernel_work_group, param>::value>(
236+
Device);
237+
}
238+
239+
template <info::kernel_sub_group param>
240+
inline typename info::param_traits<info::kernel_sub_group, param>::return_type
241+
kernel_impl::get_sub_group_info(const device &Device) const {
242+
return get_info<
243+
info::compatibility_param_traits<info::kernel_sub_group, param>::value>(
244+
Device);
245+
}
246+
247+
template <info::kernel_sub_group param>
248+
inline typename info::param_traits<info::kernel_sub_group, param>::return_type
249+
kernel_impl::get_sub_group_info(
250+
const device &Device,
251+
typename info::param_traits<info::kernel_sub_group, param>::input_type
252+
Value) const {
253+
return get_info<
254+
info::compatibility_param_traits<info::kernel_sub_group, param>::value>(
255+
Device, Value);
256+
}
257+
179258
} // namespace detail
180259
} // namespace sycl
181260
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/source/detail/kernel_info.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <CL/sycl/detail/pi.hpp>
1414
#include <CL/sycl/device.hpp>
1515
#include <CL/sycl/info/info_desc.hpp>
16-
#include <detail/kernel_impl.hpp>
1716

1817
__SYCL_INLINE_NAMESPACE(cl) {
1918
namespace sycl {

0 commit comments

Comments
 (0)