1/*******************************************************************************
2* Copyright 2021 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef GPU_OCL_OCL_GPU_ENGINE_ID_HPP
18#define GPU_OCL_OCL_GPU_ENGINE_ID_HPP
19
20#include "gpu/ocl/ocl_utils.hpp"
21
22namespace dnnl {
23namespace impl {
24namespace gpu {
25namespace ocl {
26
27struct ocl_gpu_engine_id_impl_t : public engine_id_impl_t {
28
29 ocl_gpu_engine_id_impl_t(cl_device_id device, cl_context context,
30 engine_kind_t kind, runtime_kind_t runtime_kind, size_t index)
31 : engine_id_impl_t(kind, runtime_kind, index)
32 , device_(device, true)
33 , context_(context, true) {}
34
35 ~ocl_gpu_engine_id_impl_t() override = default;
36
37private:
38 bool compare_resource(const engine_id_impl_t *id_impl) const override {
39 const auto *typed_id
40 = utils::downcast<const ocl_gpu_engine_id_impl_t *>(id_impl);
41 return device_ == typed_id->device_ && context_ == typed_id->context_;
42 }
43
44 size_t hash_resource() const override {
45 size_t seed = 0;
46 seed = hash_combine(seed, device_.get());
47 seed = hash_combine(seed, context_.get());
48 return seed;
49 }
50
51 ocl_wrapper_t<cl_device_id> device_;
52 ocl_wrapper_t<cl_context> context_;
53};
54
55} // namespace ocl
56} // namespace gpu
57} // namespace impl
58} // namespace dnnl
59
60#endif
61