1 | /******************************************************************************* |
2 | * Copyright 2022 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_VECTORIZED_RESAMPLING_HPP |
18 | #define GPU_OCL_VECTORIZED_RESAMPLING_HPP |
19 | |
20 | #include "gpu/gpu_primitive.hpp" |
21 | #include "gpu/gpu_resampling_pd.hpp" |
22 | #include "gpu/primitive_conf.hpp" |
23 | |
24 | namespace dnnl { |
25 | namespace impl { |
26 | namespace gpu { |
27 | namespace ocl { |
28 | |
29 | struct vectorized_resampling_bwd_t : public gpu_primitive_t { |
30 | using gpu_primitive_t::gpu_primitive_t; |
31 | struct pd_t : public gpu_resampling_bwd_pd_t { |
32 | pd_t(const resampling_desc_t *adesc, const primitive_attr_t *attr, |
33 | const resampling_fwd_pd_t *hint_fwd_pd) |
34 | : gpu_resampling_bwd_pd_t(adesc, attr, hint_fwd_pd) {} |
35 | virtual ~pd_t() {} |
36 | |
37 | DECLARE_COMMON_PD_T("ocl:vectorized" , vectorized_resampling_bwd_t); |
38 | |
39 | status_t init(engine_t *engine) { |
40 | using namespace data_type; |
41 | assert(engine->kind() == engine_kind::gpu); |
42 | bool ok = !is_fwd() && set_default_params() == status::success |
43 | && attr()->has_default_values(); |
44 | if (!ok) return status::unimplemented; |
45 | |
46 | return init_conf(engine); |
47 | } |
48 | resampling_conf_t conf; |
49 | |
50 | status_t init_conf(engine_t *engine); |
51 | status_t init_kernel_ctx(compute::kernel_ctx_t &kernel_ctx) const; |
52 | }; |
53 | |
54 | status_t init(engine_t *engine) override { |
55 | using namespace alg_kind; |
56 | |
57 | compute::kernel_ctx_t kernel_ctx; |
58 | status_t status = pd()->init_kernel_ctx(kernel_ctx); |
59 | CHECK(status); |
60 | |
61 | create_kernel( |
62 | engine, &kernel_, "vectorized_resampling_bwd" , kernel_ctx); |
63 | if (!kernel_) return status::runtime_error; |
64 | |
65 | return status::success; |
66 | } |
67 | |
68 | status_t execute(const exec_ctx_t &ctx) const override { |
69 | return execute_backward(ctx); |
70 | } |
71 | |
72 | private: |
73 | status_t execute_backward(const exec_ctx_t &ctx) const; |
74 | const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); } |
75 | compute::kernel_t kernel_; |
76 | }; |
77 | |
78 | } // namespace ocl |
79 | } // namespace gpu |
80 | } // namespace impl |
81 | } // namespace dnnl |
82 | |
83 | #endif |
84 | |