Skip to content

Commit c6fb5b2

Browse files
committed
sycl, ocl: avoid duplication of common engine functions
1 parent 8187bb5 commit c6fb5b2

File tree

8 files changed

+22
-29
lines changed

8 files changed

+22
-29
lines changed

src/cpu/sycl/engine.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,12 @@ class engine_t : public cpu::cpu_engine_t {
4747
return cpu::sycl::stream_t::create_stream(stream, this, stream_impl);
4848
}
4949

50-
const ::sycl::device &device() const { return impl()->device(); }
51-
const ::sycl::context &context() const { return impl()->context(); }
52-
53-
xpu::sycl::backend_t backend() const { return impl()->backend(); }
54-
5550
bool mayiuse_system_memory_allocators() const override {
5651
return impl()->mayiuse_system_memory_allocators();
5752
}
5853

54+
DECLARE_COMMON_SYCL_ENGINE_FUNCTIONS();
55+
5956
protected:
6057
const xpu::sycl::engine_impl_t *impl() const {
6158
return (const xpu::sycl::engine_impl_t *)impl::engine_t::impl();

src/gpu/amd/engine.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class engine_t : public gpu::engine_t {
5555
void activate_stream_miopen(HIPstream hip_stream);
5656
void activate_stream_rocblas(HIPstream hip_stream);
5757

58-
const ::sycl::device &device() const { return impl()->device(); }
59-
const ::sycl::context &context() const { return impl()->context(); }
60-
61-
xpu::sycl::backend_t backend() const { return impl()->backend(); }
62-
6358
hipCtx_t get_underlying_context() const;
6459
hipDevice_t get_underlying_device() const;
6560
miopenHandle_t *get_miopen_handle();
@@ -70,6 +65,8 @@ class engine_t : public gpu::engine_t {
7065
return impl()->mayiuse_system_memory_allocators();
7166
}
7267

68+
DECLARE_COMMON_SYCL_ENGINE_FUNCTIONS();
69+
7370
protected:
7471
const xpu::sycl::engine_impl_t *impl() const {
7572
return (const xpu::sycl::engine_impl_t *)impl::engine_t::impl();

src/gpu/generic/sycl/engine.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ class engine_t : public gpu::engine_t {
4343
status_t create_stream(
4444
impl::stream_t **stream, impl::stream_impl_t *stream_impl) override;
4545

46-
const ::sycl::device &device() const { return impl()->device(); }
47-
const ::sycl::context &context() const { return impl()->context(); }
48-
49-
xpu::sycl::backend_t backend() const { return impl()->backend(); }
50-
5146
bool mayiuse_system_memory_allocators() const override {
5247
return impl()->mayiuse_system_memory_allocators();
5348
}
5449

50+
DECLARE_COMMON_SYCL_ENGINE_FUNCTIONS();
51+
5552
protected:
5653
const xpu::sycl::engine_impl_t *impl() const {
5754
return (const xpu::sycl::engine_impl_t *)impl::engine_t::impl();

src/gpu/intel/ocl/ocl_gpu_engine.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ class ocl_gpu_engine_t : public compute::compute_engine_t {
9393
return gpu_impl_list_t::get_implementation_list(desc);
9494
}
9595

96-
cl_device_id device() const { return impl()->device(); }
97-
cl_context context() const { return impl()->context(); }
98-
cl_platform_id platform() const { return impl()->platform(); }
99-
10096
gpu_utils::device_id_t device_id() const override {
10197
return std::make_tuple(0, reinterpret_cast<uint64_t>(device()), 0);
10298
}
@@ -111,6 +107,8 @@ class ocl_gpu_engine_t : public compute::compute_engine_t {
111107
return device_info_->get_cache_blob(size, cache_blob);
112108
}
113109

110+
DECLARE_COMMON_OCL_ENGINE_FUNCTIONS();
111+
114112
protected:
115113
const xpu::ocl::engine_impl_t *impl() const {
116114
return (const xpu::ocl::engine_impl_t *)engine_t::impl();

src/gpu/intel/sycl/engine.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ class engine_t : public gpu::intel::compute::compute_engine_t {
159159
return status::success;
160160
}
161161

162-
const ::sycl::device &device() const { return impl()->device(); }
163-
const ::sycl::context &context() const { return impl()->context(); }
164-
165-
xpu::sycl::backend_t backend() const { return impl()->backend(); }
166-
167162
cl_device_id ocl_device() const {
168163
if (backend() != xpu::sycl::backend_t::opencl) {
169164
assert(!"not expected");
@@ -188,6 +183,8 @@ class engine_t : public gpu::intel::compute::compute_engine_t {
188183
return gpu::intel::sycl::device_id(device());
189184
}
190185

186+
DECLARE_COMMON_SYCL_ENGINE_FUNCTIONS();
187+
191188
protected:
192189
const xpu::sycl::engine_impl_t *impl() const {
193190
return (const xpu::sycl::engine_impl_t *)impl::engine_t::impl();

src/gpu/nvidia/engine.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class engine_t : public gpu::engine_t {
4949
void activate_stream_cudnn(CUstream cuda_stream);
5050
void activate_stream_cublas(CUstream cuda_stream);
5151

52-
const ::sycl::device &device() const { return impl()->device(); }
53-
const ::sycl::context &context() const { return impl()->context(); }
54-
55-
xpu::sycl::backend_t backend() const { return impl()->backend(); }
56-
5752
CUcontext get_underlying_context() const;
5853
CUdevice get_underlying_device() const;
5954
cudnnHandle_t *get_cudnn_handle();
@@ -63,6 +58,8 @@ class engine_t : public gpu::engine_t {
6358
return impl()->mayiuse_system_memory_allocators();
6459
}
6560

61+
DECLARE_COMMON_SYCL_ENGINE_FUNCTIONS();
62+
6663
protected:
6764
const xpu::sycl::engine_impl_t *impl() const {
6865
return (const xpu::sycl::engine_impl_t *)impl::engine_t::impl();

src/xpu/ocl/engine_impl.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ class engine_impl_t : public impl::engine_impl_t {
144144
bool is_user_context_;
145145
};
146146

147+
#define DECLARE_COMMON_OCL_ENGINE_FUNCTIONS() \
148+
cl_device_id device() const { return impl()->device(); } \
149+
cl_context context() const { return impl()->context(); } \
150+
cl_platform_id platform() const { return impl()->platform(); }
151+
147152
} // namespace ocl
148153
} // namespace xpu
149154
} // namespace impl

src/xpu/sycl/engine_impl.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class engine_impl_t : public impl::engine_impl_t {
113113
backend_t backend_;
114114
};
115115

116+
#define DECLARE_COMMON_SYCL_ENGINE_FUNCTIONS() \
117+
const ::sycl::device &device() const { return impl()->device(); } \
118+
const ::sycl::context &context() const { return impl()->context(); } \
119+
xpu::sycl::backend_t backend() const { return impl()->backend(); }
120+
116121
} // namespace sycl
117122
} // namespace xpu
118123
} // namespace impl

0 commit comments

Comments
 (0)