jasonfan commited on
Commit
4fa1554
·
verified ·
1 Parent(s): 64126b1

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_batch_normalization.hpp +282 -0
  2. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_benchmark_scheduler.hpp +60 -0
  3. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_binary.hpp +278 -0
  4. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_convolution_utils.hpp +128 -0
  5. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_deconvolution.hpp +335 -0
  6. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_depthwise_convolution.hpp +141 -0
  7. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_eltwise.hpp +162 -0
  8. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_gemm_convolution.hpp +156 -0
  9. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_indirect_gemm_convolution.hpp +147 -0
  10. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_inner_product.hpp +314 -0
  11. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_layer_normalization.hpp +258 -0
  12. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_pooling.hpp +225 -0
  13. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_post_ops.hpp +194 -0
  14. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_prelu.hpp +159 -0
  15. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_softmax.hpp +239 -0
  16. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_thread.hpp +57 -0
  17. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_threadpool_scheduler.hpp +68 -0
  18. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_utils.hpp +132 -0
  19. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/cpu_barrier.hpp +84 -0
  20. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/cpu_isa_traits.hpp +237 -0
  21. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/cpu_reducer.hpp +357 -0
  22. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/injector_utils.hpp +113 -0
  23. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/jit_uni_binary_injector.hpp +631 -0
  24. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp +359 -0
  25. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/jit_uni_postops_injector.hpp +167 -0
  26. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_generator.hpp +728 -0
  27. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_op_imm_check.hpp +97 -0
  28. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_primitive_conf.hpp +581 -0
  29. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_1x1_conv_kernel.hpp +204 -0
  30. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_1x1_convolution.hpp +534 -0
  31. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_conv_kernel.hpp +602 -0
  32. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_convolution.hpp +274 -0
  33. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_core_x8s8s32x_deconvolution.hpp +352 -0
  34. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_x8s8s32x_conv_kernel.hpp +254 -0
  35. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_x8s8s32x_convolution.hpp +122 -0
  36. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_1x1_conv_utils.hpp +680 -0
  37. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_batch_normalization.hpp +105 -0
  38. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_batch_normalization_s8.hpp +77 -0
  39. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_binary.hpp +116 -0
  40. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_binary_kernel.hpp +164 -0
  41. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_deconv_zp_pad_str_kernel.hpp +124 -0
  42. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_dw_conv_kernel_f32.hpp +268 -0
  43. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_dw_conv_kernel_utils.hpp +596 -0
  44. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_dw_convolution.hpp +277 -0
  45. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_eltwise.hpp +94 -0
  46. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_eltwise_int.hpp +72 -0
  47. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_i8i8_pooling.hpp +99 -0
  48. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_pool_kernel.hpp +178 -0
  49. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_pooling.hpp +191 -0
  50. miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_reorder.hpp +314 -0
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_batch_normalization.hpp ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_BATCH_NORMALIZATION_HPP
18
+ #define CPU_AARCH64_ACL_BATCH_NORMALIZATION_HPP
19
+
20
+ #include "cpu/cpu_batch_normalization_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_post_ops.hpp"
23
+ #include "cpu/aarch64/acl_utils.hpp"
24
+
25
+ namespace dnnl {
26
+ namespace impl {
27
+ namespace cpu {
28
+ namespace aarch64 {
29
+
30
+ struct acl_batch_normalization_obj_t {
31
+ arm_compute::NEBatchNormalizationLayer bnorm;
32
+ arm_compute::Tensor src_tensor;
33
+ arm_compute::Tensor dst_tensor;
34
+ arm_compute::Tensor mean_tensor;
35
+ arm_compute::Tensor var_tensor;
36
+ arm_compute::Tensor beta_tensor; // shift
37
+ arm_compute::Tensor gamma_tensor; // scale
38
+ };
39
+
40
+ struct acl_batch_normalization_conf_t {
41
+ // src and dst
42
+ arm_compute::TensorInfo data_info;
43
+ // TensorInfo for statistics (mean and/or variance), shift and scale
44
+ arm_compute::TensorInfo stats_info;
45
+ arm_compute::ActivationLayerInfo act_info;
46
+ };
47
+
48
+ struct acl_batch_normalization_resource_t : public resource_t {
49
+ acl_batch_normalization_resource_t()
50
+ : acl_obj_(utils::make_unique<acl_batch_normalization_obj_t>()) {}
51
+
52
+ status_t configure(const acl_batch_normalization_conf_t &abp,
53
+ const batch_normalization_pd_t *pd) {
54
+ if (!acl_obj_) return status::out_of_memory;
55
+
56
+ // Init Compute Library tensors based on info from descriptor
57
+ acl_obj_->src_tensor.allocator()->init(abp.data_info);
58
+ acl_obj_->dst_tensor.allocator()->init(abp.data_info);
59
+
60
+ acl_obj_->mean_tensor.allocator()->init(abp.stats_info);
61
+ acl_obj_->var_tensor.allocator()->init(abp.stats_info);
62
+ if (pd->use_shift())
63
+ acl_obj_->beta_tensor.allocator()->init(abp.stats_info);
64
+ if (pd->use_scale())
65
+ acl_obj_->gamma_tensor.allocator()->init(abp.stats_info);
66
+
67
+ // clang-format off
68
+ acl_obj_->bnorm.configure(
69
+ &acl_obj_->src_tensor,
70
+ &acl_obj_->dst_tensor,
71
+ &acl_obj_->mean_tensor,
72
+ &acl_obj_->var_tensor,
73
+ pd->use_shift() ? &acl_obj_->beta_tensor : nullptr,
74
+ pd->use_scale() ? &acl_obj_->gamma_tensor : nullptr,
75
+ pd->desc()->batch_norm_epsilon,
76
+ abp.act_info);
77
+ // clang-format on
78
+
79
+ return status::success;
80
+ }
81
+
82
+ acl_batch_normalization_obj_t &get_acl_obj() const { return *acl_obj_; }
83
+
84
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_batch_normalization_resource_t);
85
+
86
+ private:
87
+ std::unique_ptr<acl_batch_normalization_obj_t> acl_obj_;
88
+ }; // acl_batch_normalization_resource_t
89
+
90
+ struct acl_batch_normalization_fwd_t : public primitive_t {
91
+ struct pd_t : public cpu_batch_normalization_fwd_pd_t {
92
+ using cpu_batch_normalization_fwd_pd_t::
93
+ cpu_batch_normalization_fwd_pd_t;
94
+
95
+ pd_t(const batch_normalization_desc_t *adesc,
96
+ const primitive_attr_t *attr,
97
+ const typename pd_t::base_class *hint_fwd_pd)
98
+ : cpu_batch_normalization_fwd_pd_t(adesc, attr, hint_fwd_pd)
99
+ , abp() {}
100
+
101
+ DECLARE_COMMON_PD_T("acl", acl_batch_normalization_fwd_t);
102
+
103
+ status_t init(engine_t *engine) {
104
+ using namespace format_tag;
105
+
106
+ // Get memory desc to find sizes and dims
107
+ const memory_desc_wrapper src_d(src_md_);
108
+ const memory_desc_wrapper stat_d(stat_md_);
109
+
110
+ using smask_t = primitive_attr_t::skip_mask_t;
111
+ ACL_CHECK_SUPPORT(!attr()->has_default_values(smask_t::post_ops),
112
+ "attr must have default values");
113
+
114
+ ACL_CHECK_SUPPORT(!set_default_formats_common(),
115
+ "Failed to set default formats");
116
+ ACL_CHECK_SUPPORT(src_d != memory_desc_wrapper(dst_md()),
117
+ "Source and destination must have the same layout");
118
+
119
+ // Stats must already have been calculated
120
+ ACL_CHECK_SUPPORT(!use_global_stats(),
121
+ "stats must already have been computed (use global stats)");
122
+
123
+ ACL_CHECK_SUPPORT(!is_fwd(), "must be forward mode");
124
+
125
+ ACL_CHECK_SUPPORT(!utils::one_of(src_d.data_type(), data_type::f32,
126
+ data_type::f16),
127
+ "data type must be f32/f16");
128
+
129
+ // Dimensions can be permuted but no blocking or padding
130
+ ACL_CHECK_SUPPORT((!src_d.is_plain() || !stat_d.is_plain()),
131
+ "tensors must be plain");
132
+ ACL_CHECK_SUPPORT((!src_d.is_dense() || !stat_d.is_dense()),
133
+ "tensors must be dense");
134
+
135
+ ACL_CHECK_SUPPORT(src_d.is_zero() || src_d.has_zero_dim(),
136
+ "zero sized src tensor");
137
+ ACL_CHECK_SUPPORT(stat_d.is_zero() || stat_d.has_zero_dim(),
138
+ "zero sized stats tensor");
139
+
140
+ // mean, var, scale and shift all have a single dimension with size
141
+ // equal to the number of channels
142
+ auto acl_stats_dt = acl_utils::get_acl_data_t(stat_d.data_type());
143
+ abp.stats_info
144
+ = arm_compute::TensorInfo(arm_compute::TensorShape(C()), 1,
145
+ acl_stats_dt, arm_compute::DataLayout::NHWC);
146
+
147
+ // We can simplify into two cases: channels are dense or not dense
148
+ auto channel_stride = src_d.blocking_desc().strides[1];
149
+ if (channel_stride == 1) {
150
+ // Channels are dense => NHWC
151
+ // Collapse all dims except channels into W
152
+ auto elems = src_d.nelems();
153
+ dim_t w = elems / C();
154
+
155
+ // For small problems, it is better to disable threads with ACL
156
+ bool use_acl_threads = elems > 20000;
157
+
158
+ // The number of threads each candidate implementation
159
+ // (acl,nspc) is able to use for these problem parameters
160
+ int max_threads = dnnl_get_max_threads();
161
+ int acl_threads
162
+ = use_acl_threads ? std::min((int)w, max_threads) : 1;
163
+ int nspc_threads = std::min((int)MB(), max_threads);
164
+
165
+ // A simple empirical heuristic which is negative when ACL is
166
+ // faster, positive when slower. The first term represents a
167
+ // constant overhead when calling ACL as an external library,
168
+ // the second term represents the cost per tensor elem for the
169
+ // two candidate implementations (scaling for the number of
170
+ // threads used)
171
+ double acl_ref_time_diff = 33
172
+ + elems * (0.11 / acl_threads - 0.48 / nspc_threads);
173
+
174
+ // Threads in ACL incur an additional cost
175
+ if (use_acl_threads) {
176
+ acl_ref_time_diff += 1500.0 + 130.0 * (acl_threads - 1);
177
+ }
178
+
179
+ // If ACL is slower, don't use it, fall back to nspc_bnorm
180
+ if (acl_ref_time_diff > 0) return status::unimplemented;
181
+
182
+ // We disable threading in ACL by moving the width into height
183
+ auto data_shape = use_acl_threads
184
+ ? arm_compute::TensorShape(C(), w, 1, 1)
185
+ : arm_compute::TensorShape(C(), 1, w, 1);
186
+ auto acl_data_dt = acl_utils::get_acl_data_t(src_d.data_type());
187
+ abp.data_info = arm_compute::TensorInfo(data_shape, 1,
188
+ acl_data_dt, arm_compute::DataLayout::NHWC);
189
+ } else {
190
+ // Implemented in ACL but not yet optimal
191
+ return status::unimplemented;
192
+ }
193
+
194
+ ACL_CHECK_SUPPORT(fuse_norm_relu()
195
+ && desc()->prop_kind == prop_kind::forward_training,
196
+ "forward training with fused ReLU is not supported");
197
+
198
+ // oneDNN only supports eltwise post ops with bnorm
199
+ for (int i = 0; i < attr()->post_ops_.len(); ++i)
200
+ if (!attr()->post_ops_.entry_[i].is_eltwise())
201
+ return status::unimplemented;
202
+
203
+ if (fuse_norm_relu()) {
204
+ abp.act_info = arm_compute::ActivationLayerInfo(arm_compute::
205
+ ActivationLayerInfo::ActivationFunction::RELU);
206
+ // ACL BNorm supports fusing ReLU. If this validate fails, it
207
+ // will be for a different, unrecoverable reason
208
+ CHECK(validate(abp.act_info));
209
+ // init any additional post ops
210
+ CHECK(post_ops.init(engine, attr_.post_ops_, src_md_));
211
+ } else {
212
+ // init post ops, removing first eltwise for fusion
213
+ arm_compute::ActivationLayerInfo act_info;
214
+ CHECK(post_ops.init(
215
+ engine, attr_.post_ops_, src_md_, act_info));
216
+ // ACL BNorm doesn't support all the same eltwise ops as the
217
+ // standalone ACL operator, so fall back to unfused eltwise if
218
+ // validate fails
219
+ if (validate(act_info) == status::success) {
220
+ // validate succeeded => we can fuse the eltwise
221
+ abp.act_info = act_info;
222
+ } else {
223
+ // validate unfused eltwise + remaining post ops
224
+ CHECK(validate());
225
+ CHECK(post_ops.init(engine, attr_.post_ops_, src_md_));
226
+ }
227
+ }
228
+
229
+ return status::success;
230
+ }
231
+
232
+ status_t validate() { return validate(abp.act_info); }
233
+
234
+ status_t validate(arm_compute::ActivationLayerInfo &act_info) {
235
+ ACL_CHECK_VALID(arm_compute::NEBatchNormalizationLayer::validate(
236
+ &abp.data_info, &abp.data_info, &abp.stats_info,
237
+ &abp.stats_info, use_shift() ? &abp.stats_info : nullptr,
238
+ use_scale() ? &abp.stats_info : nullptr,
239
+ desc()->batch_norm_epsilon, act_info));
240
+ return status::success;
241
+ }
242
+
243
+ acl_batch_normalization_conf_t abp;
244
+
245
+ acl_post_ops_t post_ops;
246
+ }; // pd_t
247
+
248
+ acl_batch_normalization_fwd_t(const pd_t *apd) : primitive_t(apd) {}
249
+
250
+ status_t create_resource(
251
+ engine_t *engine, resource_mapper_t &mapper) const override {
252
+ if (mapper.has_resource(this)) return status::success;
253
+
254
+ auto r = utils::make_unique<acl_batch_normalization_resource_t>();
255
+ if (!r) return status::out_of_memory;
256
+
257
+ // Configure the resource based on information from primitive descriptor
258
+ CHECK(r->configure(pd()->abp, pd()));
259
+ mapper.add(this, std::move(r));
260
+
261
+ CHECK(pd()->post_ops.create_resource(engine, mapper));
262
+
263
+ return status::success;
264
+ }
265
+
266
+ status_t execute(const exec_ctx_t &ctx) const override {
267
+ return execute_forward(ctx);
268
+ }
269
+
270
+ private:
271
+ // To guard the const execute_forward, the mutex must be 'mutable'
272
+ mutable std::mutex mtx;
273
+ status_t execute_forward(const exec_ctx_t &ctx) const;
274
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
275
+ }; // acl_batch_normalization_fwd_t
276
+
277
+ } // namespace aarch64
278
+ } // namespace cpu
279
+ } // namespace impl
280
+ } // namespace dnnl
281
+
282
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_benchmark_scheduler.hpp ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2023 Arm Ltd. and affiliates
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
+ #ifndef CPU_AARCH64_ACL_BENCHMARK_SCHEDULER_HPP
17
+ #define CPU_AARCH64_ACL_BENCHMARK_SCHEDULER_HPP
18
+
19
+ #include "arm_compute/core/CPP/ICPPKernel.h"
20
+ #include "arm_compute/runtime/IScheduler.h"
21
+
22
+ namespace dnnl {
23
+ namespace impl {
24
+ namespace cpu {
25
+ namespace aarch64 {
26
+ // BenchmarkScheduler implement's ACL IScheduler interface and acts as an interceptor scheduler
27
+ // when DNNL_VERBOSE=profile,profile_externals. It intercepts calls made by the actual scheduler used by ACL and adds
28
+ // timers to benchmark execution time of ACL kernels and store kernel information.
29
+ class BenchmarkScheduler final : public arm_compute::IScheduler {
30
+ public:
31
+ BenchmarkScheduler(IScheduler &real_scheduler);
32
+
33
+ ~BenchmarkScheduler();
34
+
35
+ void set_num_threads(unsigned int num_threads) override;
36
+ unsigned int num_threads() const override;
37
+ void set_num_threads_with_affinity(
38
+ unsigned int num_threads, BindFunc func) override;
39
+ void schedule(arm_compute::ICPPKernel *kernel,
40
+ const arm_compute::IScheduler::Hints &hints) override;
41
+ void schedule_op(arm_compute::ICPPKernel *kernel,
42
+ const arm_compute::IScheduler::Hints &hints,
43
+ const arm_compute::Window &window,
44
+ arm_compute::ITensorPack &tensors) override;
45
+
46
+ protected:
47
+ void run_workloads(std::vector<Workload> &workloads) override;
48
+ void run_tagged_workloads(
49
+ std::vector<Workload> &workloads, const char *tag) override;
50
+
51
+ private:
52
+ IScheduler &_real_scheduler;
53
+ };
54
+
55
+ #endif // CPU_AARCH64_ACL_BENCHMARK_SCHEDULER_HPP
56
+
57
+ } // namespace aarch64
58
+ } // namespace cpu
59
+ } // namespace impl
60
+ } // namespace dnnl
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_binary.hpp ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022 Arm Ltd. and affiliates
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 tos 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 CPU_AARCH64_ACL_BINARY_HPP
18
+ #define CPU_AARCH64_ACL_BINARY_HPP
19
+
20
+ #include "cpu/cpu_binary_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_utils.hpp"
23
+
24
+ namespace dnnl {
25
+ namespace impl {
26
+ namespace cpu {
27
+ namespace aarch64 {
28
+
29
+ struct acl_binary_obj_t {
30
+ std::unique_ptr<arm_compute::IFunction> binary_op;
31
+ arm_compute::Tensor src0_tensor;
32
+ arm_compute::Tensor src1_tensor;
33
+ arm_compute::Tensor dst_tensor;
34
+ };
35
+
36
+ struct acl_binary_conf_t {
37
+ arm_compute::TensorInfo src0_info;
38
+ arm_compute::TensorInfo src1_info;
39
+ arm_compute::TensorInfo dst_info;
40
+ alg_kind_t alg;
41
+ };
42
+
43
+ struct acl_binary_resource_t : public resource_t {
44
+ acl_binary_resource_t()
45
+ : acl_obj_(utils::make_unique<acl_binary_obj_t>()) {}
46
+
47
+ status_t configure(const acl_binary_conf_t &asp) {
48
+ if (!acl_obj_) return status::out_of_memory;
49
+
50
+ // Init Compute Library tensors based on info from descriptor
51
+ acl_obj_->src0_tensor.allocator()->init(asp.src0_info);
52
+ acl_obj_->src1_tensor.allocator()->init(asp.src1_info);
53
+ acl_obj_->dst_tensor.allocator()->init(asp.dst_info);
54
+
55
+ switch (asp.alg) {
56
+ case alg_kind::binary_add: {
57
+ auto add_op
58
+ = std::make_unique<arm_compute::NEArithmeticAddition>();
59
+ add_op->configure(&acl_obj_->src0_tensor,
60
+ &acl_obj_->src1_tensor, &acl_obj_->dst_tensor,
61
+ arm_compute::ConvertPolicy::SATURATE);
62
+ acl_obj_->binary_op = std::move(add_op);
63
+ break;
64
+ }
65
+ case alg_kind::binary_sub: {
66
+ auto sub_op = std::make_unique<
67
+ arm_compute::NEArithmeticSubtraction>();
68
+ sub_op->configure(&acl_obj_->src0_tensor,
69
+ &acl_obj_->src1_tensor, &acl_obj_->dst_tensor,
70
+ arm_compute::ConvertPolicy::SATURATE);
71
+ acl_obj_->binary_op = std::move(sub_op);
72
+ break;
73
+ }
74
+ case alg_kind::binary_div: {
75
+ auto div_op = std::make_unique<
76
+ arm_compute::NEElementwiseDivision>();
77
+ div_op->configure(&acl_obj_->src0_tensor,
78
+ &acl_obj_->src1_tensor, &acl_obj_->dst_tensor);
79
+ acl_obj_->binary_op = std::move(div_op);
80
+ break;
81
+ }
82
+ case alg_kind::binary_mul: {
83
+ auto mul_op = std::make_unique<
84
+ arm_compute::NEPixelWiseMultiplication>();
85
+ mul_op->configure(&acl_obj_->src0_tensor,
86
+ &acl_obj_->src1_tensor, &acl_obj_->dst_tensor, 1.0f,
87
+ arm_compute::ConvertPolicy::SATURATE,
88
+ arm_compute::RoundingPolicy::TO_ZERO);
89
+ acl_obj_->binary_op = std::move(mul_op);
90
+ break;
91
+ }
92
+ case alg_kind::binary_min: {
93
+ auto min_op = std::make_unique<arm_compute::NEElementwiseMin>();
94
+ min_op->configure(&acl_obj_->src0_tensor,
95
+ &acl_obj_->src1_tensor, &acl_obj_->dst_tensor);
96
+ acl_obj_->binary_op = std::move(min_op);
97
+ break;
98
+ }
99
+ case alg_kind::binary_max: {
100
+ auto max_op = std::make_unique<arm_compute::NEElementwiseMax>();
101
+ max_op->configure(&acl_obj_->src0_tensor,
102
+ &acl_obj_->src1_tensor, &acl_obj_->dst_tensor);
103
+ acl_obj_->binary_op = std::move(max_op);
104
+ break;
105
+ }
106
+ default: return status::runtime_error;
107
+ }
108
+
109
+ return status::success;
110
+ }
111
+
112
+ acl_binary_obj_t &get_acl_obj() const { return *acl_obj_; }
113
+
114
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_binary_resource_t);
115
+
116
+ private:
117
+ std::unique_ptr<acl_binary_obj_t> acl_obj_;
118
+ }; // acl_binary_resource_t
119
+
120
+ struct acl_binary_t : public primitive_t {
121
+ struct pd_t : public cpu_binary_pd_t {
122
+ using cpu_binary_pd_t::cpu_binary_pd_t;
123
+
124
+ DECLARE_COMMON_PD_T("acl", acl_binary_t);
125
+
126
+ status_t init(engine_t *engine) {
127
+
128
+ using namespace acl_utils;
129
+
130
+ // Only support f16/f32/s32 for now
131
+ data_type_t ddt = dst_md(0)->data_type;
132
+ if (!utils::one_of(
133
+ ddt, data_type::f16, data_type::f32, data_type::s32))
134
+ return status::unimplemented;
135
+
136
+ // Only support src and dst all matching for now
137
+ if (ddt != src_md(0)->data_type || src_md(1)->data_type != ddt)
138
+ return status::unimplemented;
139
+
140
+ // Sets the memory format of dst from any to src_md(0) blocking desc
141
+ CHECK(set_default_params());
142
+
143
+ if (!attr()->has_default_values()) return status::unimplemented;
144
+
145
+ asp_.alg = desc()->alg_kind;
146
+
147
+ // All the algorithms we support
148
+ if (!utils::one_of(asp_.alg, alg_kind::binary_add,
149
+ alg_kind::binary_sub, alg_kind::binary_mul,
150
+ alg_kind::binary_div, alg_kind::binary_max,
151
+ alg_kind::binary_min))
152
+ return status::unimplemented;
153
+
154
+ // s32 div in ACL does not round as oneDNN expects
155
+ if (ddt == data_type::s32 && asp_.alg == alg_kind::binary_div)
156
+ return status::unimplemented;
157
+
158
+ // ACL pointwise arithmetic operators assume that the innermost
159
+ // dimensions are dense for src0, src1 and dst. Reordering the
160
+ // logical dimensions by stride does this (if reordered_dims >= 1 )
161
+ // and also makes memory accesses contiguous in ACL (without any
162
+ // data reordering).
163
+ memory_desc_t src_d0_permed, src_d1_permed, dst_d_permed;
164
+ int reordered_dims = reorder_dimensions_by_stride(
165
+ {&src_d0_permed, &src_d1_permed, &dst_d_permed},
166
+ {src_md(0), src_md(1), dst_md()});
167
+ if (reordered_dims < 1) return status::unimplemented;
168
+
169
+ // Create ACL tensor infos with permuted descs
170
+ CHECK(tensor_info(asp_.src0_info, src_d0_permed));
171
+ CHECK(tensor_info(asp_.src1_info, src_d1_permed));
172
+ CHECK(tensor_info(asp_.dst_info, dst_d_permed));
173
+
174
+ // In this case ACL tries to treat src0 and src1 as a 1D array, but
175
+ // fails because the strides aren't equal. TODO: remove when fixed
176
+ // in ACL
177
+ if (asp_.alg == alg_kind::binary_add
178
+ && asp_.src0_info.tensor_shape()
179
+ == asp_.src1_info.tensor_shape()
180
+ && asp_.src0_info.strides_in_bytes()
181
+ != asp_.src1_info.strides_in_bytes()) {
182
+ return status::unimplemented;
183
+ }
184
+
185
+ // This forces ACL not to parallelise with small workloads, this is
186
+ // a temporary fix and should be removed in future versions (TODO)
187
+ memory_desc_wrapper dst_d(dst_md());
188
+ if (dst_d.nelems() < 40000) {
189
+ size_t acl_y_axis_i = 1;
190
+ CHECK(insert_singleton_dimension(asp_.src0_info, acl_y_axis_i));
191
+ CHECK(insert_singleton_dimension(asp_.src1_info, acl_y_axis_i));
192
+ CHECK(insert_singleton_dimension(asp_.dst_info, acl_y_axis_i));
193
+ }
194
+
195
+ // Call operator specific validate function to check support
196
+ ACL_CHECK_VALID(validate(asp_));
197
+
198
+ return status::success;
199
+ }
200
+
201
+ acl_binary_conf_t asp_;
202
+
203
+ private:
204
+ arm_compute::Status validate(const acl_binary_conf_t &asp) {
205
+ switch (asp.alg) {
206
+ case alg_kind::binary_add:
207
+ return arm_compute::NEArithmeticAddition::validate(
208
+ &asp.src0_info, &asp.src1_info, &asp.dst_info,
209
+ arm_compute::ConvertPolicy::SATURATE);
210
+ case alg_kind::binary_sub:
211
+ return arm_compute::NEArithmeticSubtraction::validate(
212
+ &asp.src0_info, &asp.src1_info, &asp.dst_info,
213
+ arm_compute::ConvertPolicy::SATURATE);
214
+ case alg_kind::binary_div:
215
+ return arm_compute::NEElementwiseDivision::validate(
216
+ &asp.src0_info, &asp.src1_info, &asp.dst_info);
217
+ case alg_kind::binary_mul:
218
+ return arm_compute::NEPixelWiseMultiplication::validate(
219
+ &asp.src0_info, &asp.src1_info, &asp.dst_info, 1.0f,
220
+ arm_compute::ConvertPolicy::SATURATE,
221
+ arm_compute::RoundingPolicy::TO_ZERO);
222
+ case alg_kind::binary_min:
223
+ return arm_compute::NEElementwiseMin::validate(
224
+ &asp.src0_info, &asp.src1_info, &asp.dst_info);
225
+ case alg_kind::binary_max:
226
+ return arm_compute::NEElementwiseMax::validate(
227
+ &asp.src0_info, &asp.src1_info, &asp.dst_info);
228
+ default:
229
+ return arm_compute::Status(
230
+ arm_compute::ErrorCode::RUNTIME_ERROR,
231
+ "unsupported alg_kind");
232
+ }
233
+ }
234
+
235
+ friend struct acl_post_ops_t;
236
+ }; // pd_t
237
+
238
+ acl_binary_t(const pd_t *apd) : primitive_t(apd) {}
239
+
240
+ status_t create_resource(
241
+ engine_t *engine, resource_mapper_t &mapper) const override {
242
+ if (mapper.has_resource(this)) return status::success;
243
+
244
+ auto r = utils::make_unique<acl_binary_resource_t>();
245
+ if (!r) return status::out_of_memory;
246
+
247
+ // Configure the resource based on information from primitive descriptor
248
+ auto st = r->configure(pd()->asp_);
249
+ if (st == status::success) { mapper.add(this, std::move(r)); }
250
+
251
+ return st;
252
+ }
253
+
254
+ status_t execute(const exec_ctx_t &ctx) const override {
255
+ return execute_forward(ctx);
256
+ }
257
+
258
+ private:
259
+ // To guard the const execute_forward, the mutex must be 'mutable'
260
+ mutable std::mutex mtx;
261
+
262
+ status_t execute_forward(const exec_ctx_t &ctx) const;
263
+ // Execute forward with arbitrary src0, src1 and dst, used by acl_post_ops_t
264
+ status_t execute_forward(const exec_ctx_t &ctx, const void *src0,
265
+ const void *src1, void *dst) const;
266
+
267
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
268
+
269
+ friend struct acl_post_ops_t;
270
+
271
+ }; // acl_binary_t
272
+
273
+ } // namespace aarch64
274
+ } // namespace cpu
275
+ } // namespace impl
276
+ } // namespace dnnl
277
+
278
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_convolution_utils.hpp ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_CONVOLUTION_UTILS_HPP
18
+ #define CPU_AARCH64_ACL_CONVOLUTION_UTILS_HPP
19
+
20
+ #include "cpu/cpu_convolution_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_post_ops.hpp"
23
+ #include "cpu/aarch64/acl_utils.hpp"
24
+
25
+ namespace dnnl {
26
+ namespace impl {
27
+ namespace cpu {
28
+ namespace aarch64 {
29
+
30
+ template <typename NEConv>
31
+ struct acl_obj_t {
32
+ NEConv conv;
33
+ arm_compute::Tensor src_tensor;
34
+ arm_compute::Tensor wei_tensor;
35
+ arm_compute::Tensor bia_tensor;
36
+ arm_compute::Tensor dst_tensor;
37
+ };
38
+
39
+ struct acl_conv_conf_t {
40
+ bool with_bias;
41
+ bool fast_math;
42
+ // If this is true, the result of the convolution goes into a temporarily
43
+ // allocated ACL tensor to be accumulated into the oneDNN dst during postops
44
+ bool use_dst_acc;
45
+ arm_compute::TensorInfo src_tensor_info;
46
+ arm_compute::TensorInfo wei_tensor_info;
47
+ arm_compute::TensorInfo bia_tensor_info;
48
+ arm_compute::TensorInfo dst_tensor_info;
49
+ arm_compute::PadStrideInfo padstride_info;
50
+ arm_compute::Size2D dilation_info;
51
+ // Additional information about the weights not included in wei_tensor_info
52
+ arm_compute::WeightsInfo weights_info;
53
+ // Note: this will default to not enabled, and will do nothing
54
+ arm_compute::ActivationLayerInfo act_info;
55
+ };
56
+
57
+ namespace acl_convolution_utils {
58
+
59
+ status_t init_conf_gemm(acl_conv_conf_t &acp, memory_desc_t &src_md,
60
+ memory_desc_t &weights_md, memory_desc_t &dst_md,
61
+ memory_desc_t &bias_md, const convolution_desc_t &cd,
62
+ const primitive_attr_t &attr);
63
+
64
+ status_t init_conf_indirect_gemm(acl_conv_conf_t &acp, memory_desc_t &src_md,
65
+ memory_desc_t &weights_md, memory_desc_t &dst_md,
66
+ memory_desc_t &bias_md, const convolution_desc_t &cd,
67
+ const primitive_attr_t &attr);
68
+
69
+ status_t init_conf_depthwise(acl_conv_conf_t &acp, memory_desc_t &src_md,
70
+ memory_desc_t &weights_md, memory_desc_t &dst_md,
71
+ memory_desc_t &bias_md, const convolution_desc_t &cd,
72
+ const primitive_attr_t &attr);
73
+
74
+ } // namespace acl_convolution_utils
75
+
76
+ template <typename conv_obj_t, typename conv_pd_t, typename src_data_t,
77
+ typename wei_data_t = src_data_t, typename dst_data_t = src_data_t,
78
+ typename bia_data_t = src_data_t>
79
+ status_t execute_forward_conv_acl(
80
+ const exec_ctx_t &ctx, conv_obj_t &acl_conv_obj, const conv_pd_t *pd) {
81
+ bool with_bias = pd->acp_.with_bias;
82
+ bool use_dst_acc = pd->acp_.use_dst_acc;
83
+
84
+ auto src_base = CTX_IN_MEM(const src_data_t *, DNNL_ARG_SRC);
85
+ auto wei_base = CTX_IN_MEM(const wei_data_t *, DNNL_ARG_WEIGHTS);
86
+
87
+ // import_memory() and free() methods do not allocate/free any additional
88
+ // memory, only acquire/release pointers.
89
+ acl_conv_obj.src_tensor.allocator()->import_memory(
90
+ const_cast<src_data_t *>(src_base));
91
+ acl_conv_obj.wei_tensor.allocator()->import_memory(
92
+ const_cast<wei_data_t *>(wei_base));
93
+
94
+ if (use_dst_acc) {
95
+ // Put the result in a new tensor, it will be accumalated to the dst
96
+ // during the post ops
97
+ acl_conv_obj.dst_tensor.allocator()->allocate();
98
+ } else {
99
+ auto dst_base = CTX_OUT_MEM(dst_data_t *, DNNL_ARG_DST);
100
+ acl_conv_obj.dst_tensor.allocator()->import_memory(dst_base);
101
+ }
102
+
103
+ if (with_bias) {
104
+ auto bia_base = CTX_IN_MEM(const bia_data_t *, DNNL_ARG_BIAS);
105
+ acl_conv_obj.bia_tensor.allocator()->import_memory(
106
+ const_cast<bia_data_t *>(bia_base));
107
+ }
108
+
109
+ acl_conv_obj.conv.run();
110
+
111
+ acl_conv_obj.src_tensor.allocator()->free();
112
+ acl_conv_obj.wei_tensor.allocator()->free();
113
+ if (with_bias) { acl_conv_obj.bia_tensor.allocator()->free(); }
114
+
115
+ void *dst = acl_conv_obj.dst_tensor.buffer();
116
+ pd->post_ops.execute(ctx, dst);
117
+
118
+ acl_conv_obj.dst_tensor.allocator()->free();
119
+
120
+ return status::success;
121
+ }
122
+
123
+ } // namespace aarch64
124
+ } // namespace cpu
125
+ } // namespace impl
126
+ } // namespace dnnl
127
+
128
+ #endif // CPU_AARCH64_ACL_CONVOLUTION_UTILS_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_deconvolution.hpp ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_DECONVOLUTION_HPP
18
+ #define CPU_AARCH64_ACL_DECONVOLUTION_HPP
19
+
20
+ #include "cpu/aarch64/acl_post_ops.hpp"
21
+ #include "cpu/cpu_deconvolution_pd.hpp"
22
+
23
+ namespace dnnl {
24
+ namespace impl {
25
+ namespace cpu {
26
+ namespace aarch64 {
27
+
28
+ struct acl_deconv_obj_t {
29
+ arm_compute::NEDeconvolutionLayer deconv;
30
+ arm_compute::Tensor src_tensor;
31
+ arm_compute::Tensor wei_tensor;
32
+ arm_compute::Tensor bia_tensor;
33
+ arm_compute::Tensor dst_tensor;
34
+ };
35
+
36
+ struct acl_deconv_conf_t {
37
+ bool with_bias;
38
+ // If this is true, the result of the convolution goes into a temporarily
39
+ // allocated ACL tensor to be accumulated into the oneDNN dst during postops
40
+ bool use_dst_acc;
41
+ bool fast_math;
42
+ arm_compute::TensorInfo src_info;
43
+ arm_compute::TensorInfo wei_info;
44
+ arm_compute::TensorInfo bia_info;
45
+ arm_compute::TensorInfo dst_info;
46
+ arm_compute::PadStrideInfo deconv_info;
47
+ };
48
+
49
+ struct acl_deconv_resource_t : public resource_t {
50
+ acl_deconv_resource_t()
51
+ : acl_obj_(utils::make_unique<acl_deconv_obj_t>()) {}
52
+
53
+ status_t configure(const acl_deconv_conf_t &adp) {
54
+ if (!acl_obj_) return status::out_of_memory;
55
+
56
+ // Init Compute Library tensors based on info from descriptor
57
+ acl_obj_->src_tensor.allocator()->init(adp.src_info);
58
+ acl_obj_->wei_tensor.allocator()->init(adp.wei_info);
59
+ acl_obj_->bia_tensor.allocator()->init(adp.bia_info);
60
+ acl_obj_->dst_tensor.allocator()->init(adp.dst_info);
61
+
62
+ // clang-format off
63
+ acl_obj_->deconv.configure(
64
+ &acl_obj_->src_tensor,
65
+ &acl_obj_->wei_tensor,
66
+ adp.with_bias ? &acl_obj_->bia_tensor : nullptr,
67
+ &acl_obj_->dst_tensor,
68
+ adp.deconv_info, adp.fast_math);
69
+ // clang-format on
70
+
71
+ return status::success;
72
+ }
73
+
74
+ acl_deconv_obj_t &get_acl_obj() const { return *acl_obj_; }
75
+
76
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_deconv_resource_t);
77
+
78
+ private:
79
+ std::unique_ptr<acl_deconv_obj_t> acl_obj_;
80
+ }; // acl_deconv_resource_t
81
+
82
+ struct acl_deconvolution_fwd_t : public primitive_t {
83
+ struct pd_t : public cpu_deconvolution_fwd_pd_t {
84
+ using cpu_deconvolution_fwd_pd_t::cpu_deconvolution_fwd_pd_t;
85
+ pd_t(const deconvolution_desc_t *adesc, const primitive_attr_t *attr,
86
+ const deconvolution_fwd_pd_t *hint_fwd_pd)
87
+ : cpu_deconvolution_fwd_pd_t(adesc, attr, hint_fwd_pd)
88
+ , acl_pd_conf()
89
+ , post_ops() {}
90
+
91
+ DECLARE_COMMON_PD_T("acl", acl_deconvolution_fwd_t);
92
+
93
+ status_t init(engine_t *engine) {
94
+ using namespace data_type;
95
+ using namespace format_tag;
96
+
97
+ const memory_desc_wrapper src_d(&src_md_);
98
+ const memory_desc_wrapper wei_d(&weights_md_);
99
+ const memory_desc_wrapper dst_d(&dst_md_);
100
+ const memory_desc_wrapper bia_d(&bias_md_);
101
+
102
+ const auto src_data_t = src_d.data_type();
103
+ const auto wei_data_t = wei_d.data_type();
104
+ const auto dst_data_t = dst_d.data_type();
105
+ const auto bia_data_t = bia_d.data_type();
106
+
107
+ const bool ok = is_fwd() // Only forward deconvolutions
108
+ && utils::one_of(
109
+ desc()->alg_kind, alg_kind::deconvolution_direct)
110
+ && attr()->has_default_values(
111
+ primitive_attr_t::skip_mask_t::post_ops,
112
+ dst_data_t);
113
+ if (!ok) return status::unimplemented;
114
+
115
+ // Strides
116
+ const auto sh = KSH();
117
+ const auto sw = KSW();
118
+
119
+ // Padding
120
+ const auto pt = padT();
121
+ const auto pb = padB();
122
+ const auto pl = padL();
123
+ const auto pr = padR();
124
+
125
+ acl_pd_conf.deconv_info = arm_compute::PadStrideInfo(sw, sh, pl, pr,
126
+ pt, pb, arm_compute::DimensionRoundingType::FLOOR);
127
+
128
+ // Tensor info
129
+ const auto mb = MB();
130
+
131
+ const auto ih = IH();
132
+ const auto iw = IW();
133
+ const auto ic = IC();
134
+
135
+ const auto oh = OH();
136
+ const auto ow = OW();
137
+ const auto oc = OC();
138
+
139
+ const auto kw = KW();
140
+ const auto kh = KH();
141
+
142
+ const bool with_groups = G() != 1;
143
+ const int ndims = src_d.ndims();
144
+ const bool is_1d = ndims == 3;
145
+ const bool is_3d = ndims == 5;
146
+
147
+ // Compute Library unsupported shape scenarios
148
+ if (utils::one_of(true, is_3d, is_1d, with_groups)) {
149
+ return status::unimplemented;
150
+ }
151
+
152
+ acl_pd_conf.with_bias
153
+ = desc_.bias_desc.format_kind != format_kind::undef;
154
+
155
+ // Data type
156
+
157
+ auto acl_src_data_t = acl_utils::get_acl_data_t(src_data_t);
158
+ auto acl_wei_data_t = acl_utils::get_acl_data_t(wei_data_t);
159
+ auto acl_dst_data_t = acl_utils::get_acl_data_t(dst_data_t);
160
+ auto acl_bia_data_t = acl_utils::get_acl_data_t(bia_data_t);
161
+
162
+ if (acl_bia_data_t == arm_compute::DataType::UNKNOWN) {
163
+ acl_bia_data_t = arm_compute::DataType::F32;
164
+ }
165
+
166
+ // Set memory formats
167
+ auto src_tag = src_d.format_kind() == format_kind::any
168
+ ? nhwc
169
+ : memory_desc_matches_one_of_tag(src_md_, nhwc, nchw);
170
+ auto dst_tag = dst_d.format_kind() == format_kind::any
171
+ ? nhwc
172
+ : memory_desc_matches_one_of_tag(dst_md_, nhwc, nchw);
173
+
174
+ bool is_nspc = src_tag == nhwc;
175
+
176
+ auto wei_tag = wei_d.format_kind() == format_kind::any
177
+ ? (is_nspc ? ohwi : oihw)
178
+ : memory_desc_matches_one_of_tag(weights_md_, ohwi, oihw);
179
+
180
+ // Compute Library does not support mismatching layouts
181
+ if ((src_tag != wei_tag) || (src_tag != dst_tag)) {
182
+ return status::unimplemented;
183
+ }
184
+
185
+ CHECK(memory_desc_init_by_tag(src_md_, src_tag));
186
+ CHECK(memory_desc_init_by_tag(dst_md_, dst_tag));
187
+ CHECK(memory_desc_init_by_tag(weights_md_, wei_tag));
188
+ if (acl_pd_conf.with_bias) {
189
+ CHECK(memory_desc_init_by_tag(bias_md_, format_tag::a));
190
+ }
191
+
192
+ // Data layout
193
+ const auto acl_layout = is_nspc ? arm_compute::DataLayout::NHWC
194
+ : arm_compute::DataLayout::NCHW;
195
+
196
+ acl_pd_conf.src_info = arm_compute::TensorInfo(is_nspc
197
+ ? arm_compute::TensorShape(ic, iw, ih, mb)
198
+ : arm_compute::TensorShape(iw, ih, ic, mb),
199
+ 1, acl_src_data_t, acl_layout);
200
+
201
+ acl_pd_conf.wei_info = arm_compute::TensorInfo(is_nspc
202
+ ? arm_compute::TensorShape(ic, kw, kh, oc)
203
+ : arm_compute::TensorShape(kw, kh, ic, oc),
204
+ 1, acl_wei_data_t, acl_layout);
205
+
206
+ acl_pd_conf.dst_info = arm_compute::TensorInfo(is_nspc
207
+ ? arm_compute::TensorShape(oc, ow, oh, mb)
208
+ : arm_compute::TensorShape(ow, oh, oc, mb),
209
+ 1, acl_dst_data_t, acl_layout);
210
+
211
+ acl_pd_conf.bia_info = arm_compute::TensorInfo(acl_pd_conf.with_bias
212
+ ? arm_compute::TensorShape(oc)
213
+ : arm_compute::TensorShape(),
214
+ 1, acl_bia_data_t, acl_layout);
215
+
216
+ acl_pd_conf.fast_math = utils::one_of(
217
+ attr()->fpmath_mode_, fpmath_mode::bf16, fpmath_mode::any);
218
+
219
+ ACL_CHECK_VALID(arm_compute::NEDeconvolutionLayer::validate(
220
+ &acl_pd_conf.src_info, &acl_pd_conf.wei_info,
221
+ acl_pd_conf.with_bias ? &acl_pd_conf.bia_info : nullptr,
222
+ &acl_pd_conf.dst_info, acl_pd_conf.deconv_info,
223
+ acl_pd_conf.fast_math));
224
+
225
+ // Calculate scaled output tensor info for determining the convolution method
226
+ auto out_dims = arm_compute::deconvolution_output_dimensions(
227
+ iw, ih, kw, kh, acl_pd_conf.deconv_info);
228
+ uint32_t deconv_pad_x = 0;
229
+ uint32_t deconv_pad_y = 0;
230
+ auto scale_out_shape = arm_compute::misc::shape_calculator::
231
+ compute_deconvolution_upsampled_shape(acl_pd_conf.src_info,
232
+ acl_pd_conf.wei_info, sw, sh, out_dims,
233
+ deconv_pad_x, deconv_pad_y);
234
+
235
+ // If strides are unit in all dimensions, upsampling of input is skipped and a correct
236
+ // padding is set for convolution. Otherwise, describe deconvolution as convolution of
237
+ // upsampling input with stride = 1 and pad = 0.
238
+ arm_compute::ConvolutionMethod conv_method;
239
+ arm_compute::TensorInfo *conv_src_info;
240
+ unsigned int pad_left = 0;
241
+ unsigned int pad_right = 0;
242
+ unsigned int pad_top = 0;
243
+ unsigned int pad_bottom = 0;
244
+ if (sh != 1 || sw != 1) {
245
+ arm_compute::TensorInfo scale_out_info(
246
+ acl_pd_conf.src_info.clone()
247
+ ->set_is_resizable(true)
248
+ .reset_padding()
249
+ .set_tensor_shape(scale_out_shape));
250
+ conv_src_info = &scale_out_info;
251
+ } else {
252
+ // compute correct padding here
253
+ pad_left = pr > pl ? pr - pl : 0;
254
+ pad_right = pl > pr ? pl - pr : 0;
255
+ pad_top = pb > pt ? pb - pt : 0;
256
+ pad_bottom = pt > pb ? pt - pb : 0;
257
+
258
+ deconv_pad_x -= pad_left + pad_right;
259
+ deconv_pad_y -= pad_top + pad_bottom;
260
+
261
+ pad_left += deconv_pad_x / 2;
262
+ pad_right += deconv_pad_x / 2;
263
+ pad_top += deconv_pad_y / 2;
264
+ pad_bottom += deconv_pad_y / 2;
265
+
266
+ conv_src_info = &acl_pd_conf.src_info;
267
+ }
268
+ const arm_compute::PadStrideInfo conv_info(1, 1, pad_left,
269
+ pad_right, pad_top, pad_bottom,
270
+ arm_compute::DimensionRoundingType::CEIL);
271
+ conv_method
272
+ = arm_compute::NEConvolutionLayer::get_convolution_method(
273
+ conv_src_info, &acl_pd_conf.wei_info,
274
+ &acl_pd_conf.dst_info, conv_info,
275
+ arm_compute::WeightsInfo(),
276
+ arm_compute::Size2D(1U, 1U),
277
+ arm_compute::ActivationLayerInfo(),
278
+ acl_pd_conf.fast_math);
279
+
280
+ // Disable use of winograd based convolution algorithm when performing
281
+ // direct deconvolution because it introduces accuracy loss.
282
+ if (conv_method == arm_compute::ConvolutionMethod::WINOGRAD) {
283
+ return status::unimplemented;
284
+ }
285
+
286
+ CHECK(post_ops.init(engine, attr_.post_ops_, dst_md_));
287
+ acl_pd_conf.use_dst_acc = post_ops.has_sum();
288
+
289
+ return status::success;
290
+ }
291
+
292
+ acl_deconv_conf_t acl_pd_conf;
293
+ acl_post_ops_t post_ops;
294
+
295
+ private:
296
+ bool post_ops_ok() const {
297
+ return attr()->post_ops_.find(primitive_kind::convolution) == -1;
298
+ }
299
+ }; // pd_t
300
+
301
+ acl_deconvolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
302
+
303
+ status_t execute(const exec_ctx_t &ctx) const override {
304
+ return execute_forward(ctx);
305
+ }
306
+
307
+ status_t create_resource(
308
+ engine_t *engine, resource_mapper_t &mapper) const override {
309
+ if (mapper.has_resource(this)) return status::success;
310
+
311
+ auto r = utils::make_unique<acl_deconv_resource_t>();
312
+ if (!r) return status::out_of_memory;
313
+
314
+ // Configure the resource based on information from primitive descriptor
315
+ auto st = r->configure(pd()->acl_pd_conf);
316
+ if (st == status::success) { mapper.add(this, std::move(r)); }
317
+
318
+ CHECK(pd()->post_ops.create_resource(engine, mapper));
319
+
320
+ return st;
321
+ }
322
+
323
+ private:
324
+ // To guard the const execute_forward, the mutex must be 'mutable'
325
+ mutable std::mutex mtx;
326
+ status_t execute_forward(const exec_ctx_t &ctx) const;
327
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
328
+ }; // acl_deconvolution_fwd_t
329
+
330
+ } // namespace aarch64
331
+ } // namespace cpu
332
+ } // namespace impl
333
+ } // namespace dnnl
334
+
335
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_depthwise_convolution.hpp ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_DEPTHWISE_CONVOLUTION_HPP
18
+ #define CPU_AARCH64_ACL_DEPTHWISE_CONVOLUTION_HPP
19
+
20
+ #include "cpu/aarch64/acl_convolution_utils.hpp"
21
+ #include "cpu/cpu_convolution_pd.hpp"
22
+
23
+ namespace dnnl {
24
+ namespace impl {
25
+ namespace cpu {
26
+ namespace aarch64 {
27
+
28
+ struct acl_depthwise_convolution_resource_t : public resource_t {
29
+ acl_depthwise_convolution_resource_t()
30
+ : acl_obj_(utils::make_unique<
31
+ acl_obj_t<arm_compute::NEDepthwiseConvolutionLayer>>()) {}
32
+
33
+ status_t configure(const acl_conv_conf_t &acp) {
34
+ if (!acl_obj_) return status::out_of_memory;
35
+
36
+ acl_obj_->src_tensor.allocator()->init(acp.src_tensor_info);
37
+ acl_obj_->wei_tensor.allocator()->init(acp.wei_tensor_info);
38
+ acl_obj_->dst_tensor.allocator()->init(acp.dst_tensor_info);
39
+ acl_obj_->bia_tensor.allocator()->init(acp.bia_tensor_info);
40
+
41
+ // clang-format off
42
+ acl_obj_->conv.configure(
43
+ &acl_obj_->src_tensor,
44
+ &acl_obj_->wei_tensor,
45
+ acp.with_bias ? &acl_obj_->bia_tensor : nullptr,
46
+ &acl_obj_->dst_tensor,
47
+ acp.padstride_info,
48
+ 1, // depth multiplier default value
49
+ acp.act_info);
50
+
51
+ // clang-format on
52
+ return status::success;
53
+ }
54
+
55
+ acl_obj_t<arm_compute::NEDepthwiseConvolutionLayer> &get_acl_obj() const {
56
+ return *acl_obj_;
57
+ }
58
+
59
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_depthwise_convolution_resource_t);
60
+
61
+ private:
62
+ std::unique_ptr<acl_obj_t<arm_compute::NEDepthwiseConvolutionLayer>>
63
+ acl_obj_;
64
+ };
65
+
66
+ struct acl_depthwise_convolution_fwd_t : public primitive_t {
67
+
68
+ struct pd_t : public cpu_convolution_fwd_pd_t {
69
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
70
+ const typename pd_t::base_class *hint_fwd_pd)
71
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd), acp_() {}
72
+
73
+ DECLARE_COMMON_PD_T("depthwise_convolution:acl",
74
+ acl_depthwise_convolution_fwd_t, USE_GLOBAL_SCRATCHPAD);
75
+
76
+ status_t init(engine_t *engine) {
77
+ using namespace data_type;
78
+
79
+ const bool is_fp16_ok = expect_data_types(f16, f16, f16, f16, undef)
80
+ && attr()->has_default_values(
81
+ primitive_attr_t::skip_mask_t::post_ops, f16);
82
+ const bool is_fp32_ok = expect_data_types(f32, f32, f32, f32, undef)
83
+ && attr()->has_default_values(
84
+ primitive_attr_t::skip_mask_t::post_ops, f32);
85
+ bool ok = is_fwd()
86
+ && set_default_alg_kind(alg_kind::convolution_direct)
87
+ && utils::one_of(true, is_fp16_ok, is_fp32_ok)
88
+ && !has_zero_dim_memory();
89
+ if (!ok) return status::unimplemented;
90
+
91
+ CHECK(acl_convolution_utils::init_conf_depthwise(acp_, src_md_,
92
+ weights_md_, dst_md_, bias_md_, *desc(), *attr()));
93
+
94
+ CHECK(post_ops.init(
95
+ engine, attr_.post_ops_, dst_md_, acp_.act_info));
96
+ acp_.use_dst_acc = post_ops.has_sum();
97
+
98
+ return status::success;
99
+ }
100
+
101
+ acl_conv_conf_t acp_;
102
+
103
+ acl_post_ops_t post_ops;
104
+ };
105
+
106
+ acl_depthwise_convolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
107
+
108
+ status_t create_resource(
109
+ engine_t *engine, resource_mapper_t &mapper) const override {
110
+ if (mapper.has_resource(this)) return status::success;
111
+
112
+ auto r = utils::make_unique<acl_depthwise_convolution_resource_t>();
113
+ if (!r) return status::out_of_memory;
114
+
115
+ CHECK(r->configure(pd()->acp_));
116
+ mapper.add(this, std::move(r));
117
+
118
+ CHECK(pd()->post_ops.create_resource(engine, mapper));
119
+
120
+ return status::success;
121
+ }
122
+
123
+ typedef typename prec_traits<data_type::f32>::type data_t;
124
+
125
+ status_t execute(const exec_ctx_t &ctx) const override {
126
+ return execute_forward(ctx);
127
+ }
128
+
129
+ private:
130
+ mutable std::mutex mtx;
131
+ status_t execute_forward(const exec_ctx_t &ctx) const;
132
+
133
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
134
+ };
135
+
136
+ } // namespace aarch64
137
+ } // namespace cpu
138
+ } // namespace impl
139
+ } // namespace dnnl
140
+
141
+ #endif // CPU_AARCH64_ACL_DEPTHWISE_CONVOLUTION_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_eltwise.hpp ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2022 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_ELTWISE_HPP
18
+ #define CPU_AARCH64_ACL_ELTWISE_HPP
19
+
20
+ #include "cpu/cpu_eltwise_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_utils.hpp"
23
+
24
+ namespace dnnl {
25
+ namespace impl {
26
+ namespace cpu {
27
+ namespace aarch64 {
28
+
29
+ struct acl_eltwise_obj_t {
30
+ arm_compute::NEActivationLayer act;
31
+ arm_compute::Tensor src_tensor;
32
+ arm_compute::Tensor dst_tensor;
33
+ };
34
+
35
+ struct acl_eltwise_conf_t {
36
+ arm_compute::ActivationLayerInfo act_info;
37
+ // src and dst have the same info
38
+ arm_compute::TensorInfo data_info;
39
+ };
40
+
41
+ struct acl_eltwise_resource_t : public resource_t {
42
+ acl_eltwise_resource_t()
43
+ : acl_eltwise_obj_(utils::make_unique<acl_eltwise_obj_t>()) {}
44
+
45
+ status_t configure(const acl_eltwise_conf_t &aep) {
46
+ if (!acl_eltwise_obj_) return status::out_of_memory;
47
+
48
+ // Init Compute Library tensors based on info from descriptor
49
+ acl_eltwise_obj_->src_tensor.allocator()->init(aep.data_info);
50
+ acl_eltwise_obj_->dst_tensor.allocator()->init(aep.data_info);
51
+
52
+ acl_eltwise_obj_->act.configure(&acl_eltwise_obj_->src_tensor,
53
+ &acl_eltwise_obj_->dst_tensor, aep.act_info);
54
+
55
+ return status::success;
56
+ }
57
+
58
+ acl_eltwise_obj_t &get_acl_obj() const { return *acl_eltwise_obj_; }
59
+
60
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_eltwise_resource_t);
61
+
62
+ private:
63
+ std::unique_ptr<acl_eltwise_obj_t> acl_eltwise_obj_;
64
+ }; // acl_eltwise_resource_t
65
+
66
+ struct acl_eltwise_fwd_t : public primitive_t {
67
+ struct pd_t : public cpu_eltwise_fwd_pd_t {
68
+ using cpu_eltwise_fwd_pd_t::cpu_eltwise_fwd_pd_t;
69
+
70
+ DECLARE_COMMON_PD_T("acl", acl_eltwise_fwd_t);
71
+
72
+ status_t init(engine_t *engine) {
73
+ using namespace utils;
74
+ using namespace data_type;
75
+ const memory_desc_wrapper src_d(src_md());
76
+
77
+ bool ok = is_fwd() && one_of(src_d.data_type(), f32, f16, s32, s8)
78
+ && !has_zero_dim_memory() && attr()->has_default_values()
79
+ && set_default_formats_common() && src_d.is_dense()
80
+ && src_d == memory_desc_wrapper(dst_md());
81
+ if (!ok) return status::unimplemented;
82
+
83
+ // Workaround for the nan-value caused by tanh of ACL for fp16
84
+ // ARM-software/ComputeLibrary#998. Workaround for the inaccuracies
85
+ // caused by logistic/soft_relu/elu of ACL for fp16.
86
+ // TODO: Relax the error bounds in eltwise checks, or rework these
87
+ // fp16 operations in ACL for better accuracy.
88
+ using namespace dnnl::impl::alg_kind;
89
+ if (src_d.data_type() == f16
90
+ && utils::one_of(desc_.alg_kind, eltwise_tanh,
91
+ eltwise_logistic, eltwise_soft_relu, eltwise_elu)) {
92
+ return status::unimplemented;
93
+ }
94
+
95
+ auto acl_data_t = acl_utils::get_acl_data_t(src_d.data_type());
96
+
97
+ // Operator acts elementwise, so we only require that the product of
98
+ // all the dimensions equals the total number of elements. We are
99
+ // free to swap/combine dimensions. ACL performs SIMD parallelism
100
+ // over the first dimension and thread parallelism over the second.
101
+ // We pick a single dimension to thread over (taking the max of 2 to
102
+ // reduce the chance of it being 1), with the remaining dimensions
103
+ // to SIMD over.
104
+ dim_t thread_dim = std::max(W(), ndims() >= 2 ? C() : 1);
105
+ auto shape = arm_compute::TensorShape(
106
+ src_d.nelems() / thread_dim, thread_dim);
107
+ aep.data_info = arm_compute::TensorInfo(shape, 1, acl_data_t);
108
+
109
+ CHECK(acl_utils::convert_to_acl_act(desc_, aep.act_info));
110
+
111
+ ACL_CHECK_VALID(arm_compute::NEActivationLayer::validate(
112
+ &aep.data_info, &aep.data_info, aep.act_info));
113
+
114
+ return status::success;
115
+ }
116
+
117
+ acl_eltwise_conf_t aep;
118
+
119
+ friend struct acl_post_ops_t;
120
+ };
121
+
122
+ acl_eltwise_fwd_t(const pd_t *apd) : primitive_t(apd) {}
123
+
124
+ status_t execute(const exec_ctx_t &ctx) const override {
125
+ return execute_forward(ctx);
126
+ }
127
+
128
+ status_t create_resource(
129
+ engine_t *engine, resource_mapper_t &mapper) const override {
130
+ if (mapper.has_resource(this)) return status::success;
131
+
132
+ auto r = utils::make_unique<acl_eltwise_resource_t>();
133
+ if (!r) return status::out_of_memory;
134
+
135
+ // Configure the resource based on information from primitive descriptor
136
+ CHECK(r->configure(pd()->aep));
137
+ mapper.add(this, std::move(r));
138
+
139
+ return status::success;
140
+ }
141
+
142
+ private:
143
+ // execute_forward has to be const thus mutability of mtx
144
+ mutable std::mutex mtx;
145
+
146
+ status_t execute_forward(const exec_ctx_t &ctx) const;
147
+
148
+ // Execute forward with arbitrary src and dst, used by acl_post_ops_t
149
+ status_t execute_forward(
150
+ const exec_ctx_t &ctx, const void *src, void *dst) const;
151
+
152
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
153
+
154
+ friend struct acl_post_ops_t;
155
+ }; // acl_eltwise_fwd_t
156
+
157
+ } // namespace aarch64
158
+ } // namespace cpu
159
+ } // namespace impl
160
+ } // namespace dnnl
161
+
162
+ #endif // CPU_AARCH64_ACL_ELTWISE_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_gemm_convolution.hpp ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_GEMM_CONVOLUTION_HPP
18
+ #define CPU_AARCH64_ACL_GEMM_CONVOLUTION_HPP
19
+
20
+ #include "cpu/cpu_convolution_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_convolution_utils.hpp"
23
+ #include "cpu/aarch64/acl_post_ops.hpp"
24
+
25
+ namespace dnnl {
26
+ namespace impl {
27
+ namespace cpu {
28
+ namespace aarch64 {
29
+
30
+ struct acl_resource_t : public resource_t {
31
+ acl_resource_t()
32
+ : acl_obj_(utils::make_unique<
33
+ acl_obj_t<arm_compute::NEGEMMConvolutionLayer>>()) {}
34
+
35
+ status_t configure(const acl_conv_conf_t &acp) {
36
+ if (!acl_obj_) return status::out_of_memory;
37
+
38
+ // Init Compute Library tensors based on info from descriptor
39
+ acl_obj_->src_tensor.allocator()->init(acp.src_tensor_info);
40
+ acl_obj_->wei_tensor.allocator()->init(acp.wei_tensor_info);
41
+ acl_obj_->dst_tensor.allocator()->init(acp.dst_tensor_info);
42
+ acl_obj_->bia_tensor.allocator()->init(acp.bia_tensor_info);
43
+
44
+ acl_obj_->conv.configure(&acl_obj_->src_tensor, &acl_obj_->wei_tensor,
45
+ acp.with_bias ? &acl_obj_->bia_tensor : nullptr,
46
+ &acl_obj_->dst_tensor, acp.padstride_info, acp.weights_info,
47
+ acp.dilation_info, acp.act_info, acp.fast_math);
48
+ return status::success;
49
+ }
50
+
51
+ acl_obj_t<arm_compute::NEGEMMConvolutionLayer> &get_acl_obj() const {
52
+ return *acl_obj_;
53
+ }
54
+
55
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_resource_t);
56
+
57
+ private:
58
+ std::unique_ptr<acl_obj_t<arm_compute::NEGEMMConvolutionLayer>> acl_obj_;
59
+
60
+ }; // acl_resource_t
61
+
62
+ template <data_type_t src_type, data_type_t wei_type = src_type,
63
+ data_type_t dst_type = src_type, data_type_t bia_type = dst_type>
64
+ struct acl_gemm_convolution_fwd_t : public primitive_t {
65
+ struct pd_t : public cpu_convolution_fwd_pd_t {
66
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
67
+ const typename pd_t::base_class *hint_fwd_pd)
68
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd), acp_() {}
69
+
70
+ DECLARE_COMMON_PD_T(
71
+ "gemm:acl", acl_gemm_convolution_fwd_t, USE_GLOBAL_SCRATCHPAD);
72
+
73
+ status_t init(engine_t *engine) {
74
+ using namespace data_type;
75
+ using smask_t = primitive_attr_t::skip_mask_t;
76
+
77
+ bool ok = is_fwd()
78
+ && set_default_alg_kind(alg_kind::convolution_direct)
79
+ && expect_data_types(
80
+ src_type, wei_type, bia_type, dst_type, undef)
81
+ && !has_zero_dim_memory()
82
+ && attr()->has_default_values(smask_t::post_ops, dst_type)
83
+ && output_scales_mask_ok() && zero_points_ok();
84
+ if (!ok) return status::unimplemented;
85
+
86
+ CHECK(acl_convolution_utils::init_conf_gemm(acp_, src_md_,
87
+ weights_md_, dst_md_, bias_md_, *desc(), *attr()));
88
+
89
+ CHECK(post_ops.init(
90
+ engine, attr_.post_ops_, dst_md_, acp_.act_info));
91
+ acp_.use_dst_acc = post_ops.has_sum();
92
+
93
+ return status::success;
94
+ }
95
+
96
+ acl_conv_conf_t acp_;
97
+
98
+ acl_post_ops_t post_ops;
99
+
100
+ protected:
101
+ bool output_scales_mask_ok() const {
102
+ using namespace data_type;
103
+ const auto &mask = attr()->output_scales_.mask_;
104
+ return IMPLICATION(!utils::one_of(src_type, s8, u8),
105
+ attr()->output_scales_.has_default_values())
106
+ // TODO: add support for per_channel quantization
107
+ && mask == 0;
108
+ }
109
+
110
+ bool zero_points_ok() const {
111
+ using namespace data_type;
112
+ // TODO: add support for asymmetric quantization
113
+ return attr()->zero_points_.has_default_values();
114
+ }
115
+ };
116
+
117
+ acl_gemm_convolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
118
+
119
+ status_t create_resource(
120
+ engine_t *engine, resource_mapper_t &mapper) const override {
121
+ if (mapper.has_resource(this)) return status::success;
122
+
123
+ auto r = utils::make_unique<acl_resource_t>();
124
+ if (!r) return status::out_of_memory;
125
+
126
+ // Configure the resource based on information from primitive descriptor
127
+ CHECK(r->configure(pd()->acp_));
128
+ mapper.add(this, std::move(r));
129
+
130
+ CHECK(pd()->post_ops.create_resource(engine, mapper));
131
+
132
+ return status::success;
133
+ }
134
+
135
+ typedef typename prec_traits<src_type>::type src_data_t;
136
+ typedef typename prec_traits<wei_type>::type wei_data_t;
137
+ typedef typename prec_traits<dst_type>::type dst_data_t;
138
+ typedef typename prec_traits<bia_type>::type bia_data_t;
139
+
140
+ status_t execute(const exec_ctx_t &ctx) const override {
141
+ return execute_forward(ctx);
142
+ }
143
+
144
+ private:
145
+ // To guard the const execute_forward(), the mutex must be 'mutable'
146
+ mutable std::mutex mtx;
147
+ status_t execute_forward(const exec_ctx_t &ctx) const;
148
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
149
+ }; // acl_gemm_convolution_fwd_t
150
+
151
+ } // namespace aarch64
152
+ } // namespace cpu
153
+ } // namespace impl
154
+ } // namespace dnnl
155
+
156
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_indirect_gemm_convolution.hpp ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_INDIRECT_GEMM_CONVOLUTION_HPP
18
+ #define CPU_AARCH64_ACL_INDIRECT_GEMM_CONVOLUTION_HPP
19
+
20
+ #include "cpu/cpu_convolution_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_convolution_utils.hpp"
23
+
24
+ namespace dnnl {
25
+ namespace impl {
26
+ namespace cpu {
27
+ namespace aarch64 {
28
+
29
+ struct acl_indirect_gemm_resource_t : public resource_t {
30
+ acl_indirect_gemm_resource_t()
31
+ : acl_obj_(utils::make_unique<acl_obj_t<arm_compute::NEGEMMConv2d>>()) {
32
+ }
33
+
34
+ status_t configure(const acl_conv_conf_t &acp) {
35
+ if (!acl_obj_) return status::out_of_memory;
36
+
37
+ // Init Compute Library tensors based on info from descriptor
38
+ acl_obj_->src_tensor.allocator()->init(acp.src_tensor_info);
39
+ acl_obj_->wei_tensor.allocator()->init(acp.wei_tensor_info);
40
+ acl_obj_->dst_tensor.allocator()->init(acp.dst_tensor_info);
41
+ acl_obj_->bia_tensor.allocator()->init(acp.bia_tensor_info);
42
+
43
+ // clang-format off
44
+ acl_obj_->conv.configure(
45
+ &acl_obj_->src_tensor,
46
+ &acl_obj_->wei_tensor,
47
+ acp.with_bias ? &acl_obj_->bia_tensor : nullptr,
48
+ &acl_obj_->dst_tensor,
49
+ arm_compute::Conv2dInfo(acp.padstride_info,
50
+ acp.dilation_info,
51
+ acp.act_info,
52
+ acp.fast_math,
53
+ 1,
54
+ {},
55
+ acp.weights_info));
56
+ // clang-format on
57
+
58
+ return status::success;
59
+ }
60
+
61
+ acl_obj_t<arm_compute::NEGEMMConv2d> &get_acl_obj() const {
62
+ return *acl_obj_;
63
+ }
64
+
65
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_indirect_gemm_resource_t);
66
+
67
+ private:
68
+ std::unique_ptr<acl_obj_t<arm_compute::NEGEMMConv2d>> acl_obj_;
69
+
70
+ }; // acl_indirect_gemm_resource_t
71
+
72
+ struct acl_indirect_gemm_convolution_fwd_t : public primitive_t {
73
+
74
+ struct pd_t : public cpu_convolution_fwd_pd_t {
75
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
76
+ const typename pd_t::base_class *hint_fwd_pd)
77
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd), acp_() {}
78
+
79
+ DECLARE_COMMON_PD_T("indirect_gemm:acl",
80
+ acl_indirect_gemm_convolution_fwd_t, USE_GLOBAL_SCRATCHPAD);
81
+
82
+ status_t init(engine_t *engine) {
83
+ using namespace data_type;
84
+ const bool is_fp16_ok = expect_data_types(f16, f16, f16, f16, undef)
85
+ && attr()->has_default_values(
86
+ primitive_attr_t::skip_mask_t::post_ops, f16);
87
+ const bool is_fp32_ok = expect_data_types(f32, f32, f32, f32, undef)
88
+ && attr()->has_default_values(
89
+ primitive_attr_t::skip_mask_t::post_ops, f32);
90
+ bool ok = is_fwd()
91
+ && set_default_alg_kind(alg_kind::convolution_direct)
92
+ && utils::one_of(true, is_fp16_ok, is_fp32_ok)
93
+ && !has_zero_dim_memory();
94
+ if (!ok) return status::unimplemented;
95
+
96
+ CHECK(acl_convolution_utils::init_conf_indirect_gemm(acp_, src_md_,
97
+ weights_md_, dst_md_, bias_md_, *desc(), *attr()));
98
+
99
+ CHECK(post_ops.init(
100
+ engine, attr_.post_ops_, dst_md_, acp_.act_info));
101
+ acp_.use_dst_acc = post_ops.has_sum();
102
+
103
+ return status::success;
104
+ }
105
+
106
+ acl_conv_conf_t acp_;
107
+
108
+ acl_post_ops_t post_ops;
109
+ };
110
+
111
+ acl_indirect_gemm_convolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
112
+
113
+ status_t create_resource(
114
+ engine_t *engine, resource_mapper_t &mapper) const override {
115
+ if (mapper.has_resource(this)) return status::success;
116
+
117
+ auto r = utils::make_unique<acl_indirect_gemm_resource_t>();
118
+ if (!r) return status::out_of_memory;
119
+
120
+ // Configure the resource based on information from primitive descriptor
121
+ CHECK(r->configure(pd()->acp_));
122
+ mapper.add(this, std::move(r));
123
+
124
+ CHECK(pd()->post_ops.create_resource(engine, mapper));
125
+
126
+ return status::success;
127
+ }
128
+
129
+ typedef typename prec_traits<data_type::f32>::type data_t;
130
+
131
+ status_t execute(const exec_ctx_t &ctx) const override {
132
+ return execute_forward(ctx);
133
+ }
134
+
135
+ private:
136
+ // To guard the const execute_forward(), the mutex must be 'mutable'
137
+ mutable std::mutex mtx;
138
+ status_t execute_forward(const exec_ctx_t &ctx) const;
139
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
140
+ };
141
+
142
+ } // namespace aarch64
143
+ } // namespace cpu
144
+ } // namespace impl
145
+ } // namespace dnnl
146
+
147
+ #endif // CPU_AARCH64_ACL_INDIRECT_GEMM_CONVOLUTION_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_inner_product.hpp ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_INNER_PRODUCT_HPP
18
+ #define CPU_AARCH64_ACL_INNER_PRODUCT_HPP
19
+
20
+ #include "cpu/aarch64/acl_utils.hpp"
21
+ #include "cpu/cpu_inner_product_pd.hpp"
22
+
23
+ #include "cpu/aarch64/acl_post_ops.hpp"
24
+
25
+ namespace dnnl {
26
+ namespace impl {
27
+ namespace cpu {
28
+ namespace aarch64 {
29
+
30
+ struct acl_ip_obj_t {
31
+ arm_compute::NEFullyConnectedLayer fc;
32
+ arm_compute::Tensor src_tensor;
33
+ arm_compute::Tensor wei_tensor;
34
+ arm_compute::Tensor bia_tensor;
35
+ arm_compute::Tensor dst_tensor;
36
+ };
37
+
38
+ struct acl_ip_conf_t {
39
+ bool with_bias;
40
+ // If this is true, the result of the inner product goes into a temporarily
41
+ // allocated ACL tensor to be accumulated into the oneDNN dst during postops
42
+ bool use_dst_acc;
43
+ arm_compute::TensorInfo src_tensor_info;
44
+ arm_compute::TensorInfo wei_tensor_info;
45
+ arm_compute::TensorInfo bia_tensor_info;
46
+ arm_compute::TensorInfo dst_tensor_info;
47
+ arm_compute::FullyConnectedLayerInfo fc_info;
48
+ // Additional information about the weights not included in wei_tensor_info
49
+ arm_compute::WeightsInfo weights_info;
50
+ };
51
+ struct acl_ip_resource_t : public resource_t {
52
+ acl_ip_resource_t() : acl_ip_obj_(utils::make_unique<acl_ip_obj_t>()) {}
53
+
54
+ status_t configure(const acl_ip_conf_t &aip) {
55
+ if (!acl_ip_obj_) return status::out_of_memory;
56
+
57
+ // Init Compute Library tensors based on info from descriptor
58
+ acl_ip_obj_->src_tensor.allocator()->init(aip.src_tensor_info);
59
+ acl_ip_obj_->wei_tensor.allocator()->init(aip.wei_tensor_info);
60
+ acl_ip_obj_->dst_tensor.allocator()->init(aip.dst_tensor_info);
61
+ acl_ip_obj_->bia_tensor.allocator()->init(aip.bia_tensor_info);
62
+
63
+ // clang-format off
64
+ acl_ip_obj_->fc.configure(
65
+ &acl_ip_obj_->src_tensor,
66
+ &acl_ip_obj_->wei_tensor,
67
+ aip.with_bias ? &acl_ip_obj_->bia_tensor : nullptr,
68
+ &acl_ip_obj_->dst_tensor,
69
+ aip.fc_info,
70
+ aip.weights_info);
71
+ // clang-format on
72
+
73
+ return status::success;
74
+ }
75
+
76
+ acl_ip_obj_t &get_acl_obj() const { return *acl_ip_obj_; }
77
+
78
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_ip_resource_t);
79
+
80
+ private:
81
+ std::unique_ptr<acl_ip_obj_t> acl_ip_obj_;
82
+ }; // acl_ip_resource_t
83
+
84
+ struct acl_inner_product_fwd_t : public primitive_t {
85
+ struct pd_t : public cpu_inner_product_fwd_pd_t {
86
+ using cpu_inner_product_fwd_pd_t::cpu_inner_product_fwd_pd_t;
87
+
88
+ pd_t(const inner_product_desc_t *adesc, const primitive_attr_t *attr,
89
+ const typename pd_t::base_class *hint_fwd_pd)
90
+ : cpu_inner_product_fwd_pd_t(adesc, attr, hint_fwd_pd), aip() {}
91
+
92
+ DECLARE_COMMON_PD_T("acl", acl_inner_product_fwd_t);
93
+
94
+ status_t init(engine_t *engine) {
95
+ using namespace data_type;
96
+ const bool is_fp16_ok = expect_data_types(f16, f16, f16, f16, undef)
97
+ && attr()->has_default_values(
98
+ primitive_attr_t::skip_mask_t::post_ops, f16);
99
+ const bool is_fp32_ok = expect_data_types(f32, f32, f32, f32, undef)
100
+ && attr()->has_default_values(
101
+ primitive_attr_t::skip_mask_t::post_ops, f32);
102
+ const bool ok = is_fwd() && !has_zero_dim_memory()
103
+ && utils::one_of(true, is_fp16_ok, is_fp32_ok)
104
+ && weights_md_.format_kind == format_kind::any
105
+ && set_default_params() == status::success;
106
+
107
+ if (!ok) return status::unimplemented;
108
+
109
+ CHECK(init_conf_ip(engine));
110
+
111
+ return status::success;
112
+ }
113
+
114
+ acl_ip_conf_t aip;
115
+
116
+ acl_post_ops_t post_ops;
117
+
118
+ status_t init_conf_ip(engine_t *engine) {
119
+
120
+ ACL_CHECK_SUPPORT(src_md()->ndims != weights_md()->ndims,
121
+ "source and weights dimensions must match");
122
+
123
+ const int ndims = src_md()->ndims;
124
+
125
+ const bool is_2d = (ndims == 2);
126
+ const bool is_4d = (ndims == 4);
127
+
128
+ ACL_CHECK_SUPPORT(
129
+ !(is_2d || is_4d), "ACL supports only 2d or 4d cases");
130
+
131
+ using namespace format_tag;
132
+ auto src_tag
133
+ = memory_desc_matches_one_of_tag(src_md_, nhwc, nchw, nc);
134
+ auto dst_tag = memory_desc_matches_one_of_tag(dst_md_, nc);
135
+
136
+ ACL_CHECK_SUPPORT(
137
+ utils::one_of(format_tag::undef, src_tag, dst_tag),
138
+ "unsupported memory layout");
139
+
140
+ ACL_CHECK_SUPPORT(is_2d && src_tag != dst_tag,
141
+ "for src and dst layouts must match");
142
+
143
+ const dim_t ic_total = IC_total();
144
+ const dim_t n = MB();
145
+ const dim_t oc = OC();
146
+
147
+ aip.src_tensor_info = arm_compute::TensorInfo(
148
+ arm_compute::TensorShape(ic_total, n), 1,
149
+ acl_utils::get_acl_data_t(src_md()->data_type));
150
+
151
+ // ACL requires the weights to be in 2D flattened shape
152
+ aip.wei_tensor_info = arm_compute::TensorInfo(
153
+ arm_compute::TensorShape(oc, ic_total), 1,
154
+ acl_utils::get_acl_data_t(weights_md(0)->data_type));
155
+
156
+ auto acl_dst_data_t
157
+ = acl_utils::get_acl_data_t(dst_md()->data_type);
158
+ aip.dst_tensor_info = arm_compute::TensorInfo(
159
+ arm_compute::TensorShape(oc, n), 1, acl_dst_data_t);
160
+
161
+ aip.with_bias = desc()->bias_desc.format_kind != format_kind::undef;
162
+ auto acl_bia_data_t = aip.with_bias
163
+ ? acl_utils::get_acl_data_t(weights_md(1)->data_type)
164
+ : acl_dst_data_t;
165
+ aip.bia_tensor_info = arm_compute::TensorInfo(aip.with_bias
166
+ ? arm_compute::TensorShape(oc)
167
+ : arm_compute::TensorShape(),
168
+ 1, acl_bia_data_t);
169
+
170
+ aip.fc_info.transpose_weights = false;
171
+
172
+ aip.fc_info.enable_fast_math = utils::one_of(
173
+ attr()->fpmath_mode_, fpmath_mode::bf16, fpmath_mode::any);
174
+
175
+ CHECK(post_ops.init(engine, attr_.post_ops_, dst_md_,
176
+ aip.fc_info.activation_info));
177
+ aip.use_dst_acc = post_ops.has_sum();
178
+
179
+ // WeightFormat::ANY tells ACL we can handle any format
180
+ aip.weights_info = arm_compute::WeightsInfo(false, 1, 1, ic_total,
181
+ false, arm_compute::WeightFormat::ANY);
182
+
183
+ // Get the format that the ACL kernel will expect the weights to be
184
+ // in (if a kernel exists) Note that these are referred to as fixed
185
+ // format kernels, because they require one specific weights format
186
+ arm_compute::WeightFormat expected_weight_format;
187
+ ACL_CHECK_VALID(arm_compute::NEFullyConnectedLayer::has_opt_impl(
188
+ expected_weight_format, &aip.src_tensor_info,
189
+ &aip.wei_tensor_info,
190
+ aip.with_bias ? &aip.bia_tensor_info : nullptr,
191
+ &aip.dst_tensor_info, aip.fc_info, aip.weights_info));
192
+
193
+ // Set weights info to the one returned by has_opt_impl
194
+ aip.weights_info.set_weight_format(expected_weight_format);
195
+
196
+ // has_opt_impl may return a non fast math kernel, even if requested
197
+ aip.fc_info.enable_fast_math
198
+ = arm_compute::is_fixed_format_fast_math(
199
+ expected_weight_format);
200
+
201
+ // Inner product is the same as the matmul n x (chw) * (ihw) x o
202
+ // (note that the src c and weights i both correspond to the input
203
+ // channel). ACL FullyConnectedLayer assumes the chw dimensions of
204
+ // src and ihw dimensions of weights are collapsed, so we need to
205
+ // make sure that they have the same layout. Given that weights are
206
+ // more often fixed, (so reorders can be hoisted) it makes sense to
207
+ // reorder the weights to fit the src.
208
+
209
+ // For 4D tensors we need to:
210
+ // - reorder the ihw of the weights to match the src chw
211
+ // - collapse ihw
212
+ // - pad the collapsed ihw
213
+ // But there is not yet a way to express this collapse+pad as a
214
+ // reorder. So we try to reorder the weights to match the src,
215
+ // implicitly collapse ihw in our definition of the weights
216
+ // TensorInfo and hope that the inner_dim has zero padding
217
+ // (weights_md_.dims[inner_dim] % block_by == 0). If it does, we
218
+ // fall back to a kernel without blocking (currently this is
219
+ // equivalent to non-fastmath).
220
+
221
+ // 2D just works because we just pad the only dimension.
222
+
223
+ // o_dim is always the first logical dimension (oihw, ohwi, oi)
224
+ dim_t o_dim = 0;
225
+ dim_t inner_dim;
226
+ // Rest of logical dimensions in order of innermost to outermost
227
+ std::vector<dim_t> remaining_dims = {};
228
+
229
+ if (src_tag == nchw) {
230
+ inner_dim = 3; // w
231
+ remaining_dims = {2, 1}; // h, i
232
+ } else if (src_tag == nhwc) {
233
+ inner_dim = 1; // i
234
+ remaining_dims = {3, 2}; // w, h
235
+ } else { // Only remaining case is 2D (nc)
236
+ inner_dim = 1; // i
237
+ remaining_dims = {}; // No other dimensions for 2D
238
+ }
239
+
240
+ // Fallback
241
+ int block_by = arm_compute::block_by(expected_weight_format);
242
+ if (is_4d && weights_md_.dims[inner_dim] % block_by != 0
243
+ && aip.fc_info.enable_fast_math) {
244
+ aip.fc_info.enable_fast_math = false;
245
+ aip.weights_info.set_weight_format(
246
+ arm_compute::WeightFormat::ANY);
247
+ ACL_CHECK_VALID(
248
+ arm_compute::NEFullyConnectedLayer::has_opt_impl(
249
+ expected_weight_format, &aip.src_tensor_info,
250
+ &aip.wei_tensor_info,
251
+ aip.with_bias ? &aip.bia_tensor_info : nullptr,
252
+ &aip.dst_tensor_info, aip.fc_info,
253
+ aip.weights_info));
254
+ aip.weights_info.set_weight_format(expected_weight_format);
255
+ block_by = arm_compute::block_by(expected_weight_format);
256
+ if (weights_md_.dims[inner_dim] % block_by != 0)
257
+ return status::unimplemented;
258
+ }
259
+
260
+ acl_utils::reorder_to_weight_format(aip.wei_tensor_info,
261
+ weights_md_, expected_weight_format, inner_dim, o_dim,
262
+ remaining_dims, {});
263
+
264
+ // clang-format off
265
+
266
+ // Validate fully connected layer manually to check for return status
267
+ ACL_CHECK_VALID(arm_compute::NEFullyConnectedLayer::validate(
268
+ &aip.src_tensor_info,
269
+ &aip.wei_tensor_info,
270
+ aip.with_bias ? &aip.bia_tensor_info : nullptr,
271
+ &aip.dst_tensor_info,
272
+ aip.fc_info,
273
+ aip.weights_info));
274
+ // clang-format on
275
+
276
+ return status::success;
277
+ }
278
+ }; // pd_t
279
+
280
+ acl_inner_product_fwd_t(const pd_t *apd) : primitive_t(apd) {}
281
+
282
+ status_t create_resource(
283
+ engine_t *engine, resource_mapper_t &mapper) const override {
284
+ if (mapper.has_resource(this)) return status::success;
285
+
286
+ auto r = utils::make_unique<acl_ip_resource_t>();
287
+ if (!r) return status::out_of_memory;
288
+
289
+ // Configure the resource based on information from primitive descriptor
290
+ CHECK(r->configure(pd()->aip));
291
+ mapper.add(this, std::move(r));
292
+
293
+ CHECK(pd()->post_ops.create_resource(engine, mapper));
294
+
295
+ return status::success;
296
+ }
297
+
298
+ status_t execute(const exec_ctx_t &ctx) const override {
299
+ return execute_forward(ctx);
300
+ }
301
+
302
+ private:
303
+ //To guard the const execute_forward, the mutex must be 'mutable'
304
+ mutable std::mutex mtx;
305
+ status_t execute_forward(const exec_ctx_t &ctx) const;
306
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
307
+ }; // acl_inner_product_fwd_t
308
+
309
+ } // namespace aarch64
310
+ } // namespace cpu
311
+ } // namespace impl
312
+ } // namespace dnnl
313
+
314
+ #endif // CPU_AARCH64_ACL_INNER_PRODUCT_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_layer_normalization.hpp ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_LAYER_NORMALIZATION_HPP
18
+ #define CPU_AARCH64_ACL_LAYER_NORMALIZATION_HPP
19
+
20
+ #include "cpu/aarch64/acl_utils.hpp"
21
+ #include "cpu/cpu_layer_normalization_pd.hpp"
22
+
23
+ namespace dnnl {
24
+ namespace impl {
25
+ namespace cpu {
26
+ namespace aarch64 {
27
+
28
+ struct acl_msdnorm_obj_t {
29
+ arm_compute::NEMeanStdDevNormalizationLayer msdNorm;
30
+ arm_compute::Tensor src_tensor;
31
+ arm_compute::Tensor dst_tensor;
32
+ };
33
+
34
+ struct acl_msdnorm_conf_t {
35
+ arm_compute::TensorInfo data_info; // src and dst tensors
36
+ };
37
+
38
+ struct acl_layer_normalization_resource_t : public resource_t {
39
+ acl_layer_normalization_resource_t()
40
+ : acl_obj(utils::make_unique<acl_msdnorm_obj_t>()) {}
41
+
42
+ status_t configure(
43
+ const acl_msdnorm_conf_t &anp, const layer_normalization_pd_t *pd) {
44
+ if (!acl_obj) return status::out_of_memory;
45
+
46
+ acl_obj->src_tensor.allocator()->init(anp.data_info);
47
+ acl_obj->dst_tensor.allocator()->init(anp.data_info);
48
+
49
+ // clang-format off
50
+ acl_obj->msdNorm.configure(
51
+ &acl_obj->src_tensor,
52
+ &acl_obj->dst_tensor,
53
+ pd->desc()->layer_norm_epsilon);
54
+ // clang-format on
55
+
56
+ return status::success;
57
+ }
58
+
59
+ acl_msdnorm_obj_t &get_acl_obj() const { return *acl_obj; }
60
+
61
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_layer_normalization_resource_t);
62
+
63
+ private:
64
+ std::unique_ptr<acl_msdnorm_obj_t> acl_obj;
65
+ }; // acl_layer_normalization_resource_t
66
+
67
+ struct acl_layer_normalization_fwd_t : public primitive_t {
68
+ struct pd_t : public cpu_layer_normalization_fwd_pd_t {
69
+ using cpu_layer_normalization_fwd_pd_t::
70
+ cpu_layer_normalization_fwd_pd_t;
71
+ pd_t(const layer_normalization_desc_t *adesc,
72
+ const primitive_attr_t *attr,
73
+ const typename pd_t::base_class *hint_fwd_pd)
74
+ : cpu_layer_normalization_fwd_pd_t(adesc, attr, hint_fwd_pd)
75
+ , anp() {}
76
+
77
+ DECLARE_COMMON_PD_T("acl", acl_layer_normalization_fwd_t);
78
+
79
+ status_t init(engine_t *engine) {
80
+
81
+ // dir and flags
82
+ ACL_CHECK_SUPPORT(
83
+ !is_fwd(), "ACL lnorm supports forward propagation only");
84
+ ACL_CHECK_SUPPORT(is_training() && !use_global_stats(),
85
+ "ACL only supports forward training with lnorm if stats "
86
+ "are provided (use global stats)");
87
+ ACL_CHECK_SUPPORT(use_scale() || use_shift(),
88
+ "ACL does not support lnorm scale and shift");
89
+
90
+ // attr-scales
91
+ ACL_CHECK_SUPPORT(!attr()->has_default_values(),
92
+ "ACL does not support scales attribute");
93
+
94
+ // tag and stat_tag
95
+ ACL_CHECK_SUPPORT(src_md()->ndims < 2 || src_md()->ndims > 5,
96
+ "src tensor must have between 2 and 5 (inclusive) "
97
+ "dimensions");
98
+
99
+ // msdNorm only supports lnorm for src in a channels last format.
100
+ // So if channels aren't last (ie. if they aren't dense),
101
+ // then reorder into a channels last format
102
+ std::string ref_implementation_guess = "simple:any";
103
+ if (src_md()->format_desc.blocking.strides[ndims() - 1] != 1) {
104
+ CHECK(memory_desc_init_by_tag(
105
+ src_md_, get_channels_last_format(src_md_.ndims)));
106
+ ref_implementation_guess = "ref:any";
107
+ }
108
+ if (dst_md_ != src_md_)
109
+ // Make sure dst and src share a format
110
+ CHECK(memory_desc_init_by_md_and_dt(
111
+ dst_md_, src_md_, src_md()->data_type));
112
+ if (!set_default_stat_md_format(src_md_))
113
+ return status::unimplemented;
114
+
115
+ const memory_desc_wrapper src_d(src_md_);
116
+ const memory_desc_wrapper dst_d(dst_md_);
117
+
118
+ ACL_CHECK_SUPPORT(src_d.has_zero_dim() || dst_d.has_zero_dim(),
119
+ "data tensor(s) must not have a zero dimension");
120
+
121
+ // data type
122
+ ACL_CHECK_SUPPORT(src_d.data_type() != data_type::f32,
123
+ "ACL Lnorm only supports F32");
124
+ ACL_CHECK_SUPPORT(dst_d.data_type() != src_d.data_type(),
125
+ "src and dst must share data types");
126
+
127
+ // Problem shape
128
+ int C = norm_axis(); // Channel dim size
129
+ int X = src_d.nelems() / C; // Non-channel dims size
130
+
131
+ ACL_CHECK_SUPPORT(!use_acl_heuristic(X, C, dnnl_get_max_threads(),
132
+ is_training(), ref_implementation_guess),
133
+ "ACL is unoptimal in this case");
134
+
135
+ anp.data_info
136
+ = arm_compute::TensorInfo(arm_compute::TensorShape(C, X), 1,
137
+ arm_compute::DataType::F32);
138
+
139
+ ACL_CHECK_VALID(
140
+ arm_compute::NEMeanStdDevNormalizationLayer::validate(
141
+ &anp.data_info, &anp.data_info,
142
+ desc()->layer_norm_epsilon));
143
+
144
+ return status::success;
145
+ }
146
+
147
+ format_tag_t get_channels_last_format(size_t ndim) {
148
+ assert(ndim > 1 && ndim < 6);
149
+ switch (ndim) {
150
+ case 2: return format_tag::nc;
151
+ case 3: return format_tag::tnc;
152
+ case 4: return format_tag::ldnc;
153
+ case 5: return format_tag::abcde;
154
+ default: return format_tag::undef;
155
+ }
156
+ }
157
+
158
+ bool use_acl_heuristic(int X, int C, int threads, bool ref_has_stats,
159
+ std::string ref_implementation_guess) {
160
+ // Above a certain C, acl is always better, and below a certain C,
161
+ // acl is always worse. for C in between these two, whether acl is
162
+ // better can be approximated with the workload (X*C) per thread.
163
+ // The values here were derived empirically and all depend on
164
+ // threads, whether ref can use provided stats, and which reference
165
+ // implementation acl is competing with.
166
+
167
+ int acl_competitive_C = C;
168
+ int acl_better_C = C;
169
+ int acl_better_XC_per_thread = X * C;
170
+
171
+ if (ref_implementation_guess == "simple:any") {
172
+ acl_competitive_C = 64;
173
+ if (ref_has_stats) {
174
+ acl_better_C = 4096;
175
+ acl_better_XC_per_thread = threads == 1 ? 4096 : 8192;
176
+ } else {
177
+ acl_better_C = threads <= 2 ? 1024 : 4096;
178
+ acl_better_XC_per_thread = threads == 1 ? 1024 : 4096;
179
+ }
180
+ } else if (ref_implementation_guess == "ref:any") {
181
+ acl_competitive_C = 0;
182
+ if (ref_has_stats) {
183
+ if (threads == 1) {
184
+ acl_better_C = 64;
185
+ } else if (threads == 2) {
186
+ acl_better_C = 256;
187
+ } else {
188
+ acl_better_C = 1024;
189
+ }
190
+
191
+ if (threads == 1) {
192
+ acl_better_XC_per_thread = 256;
193
+ } else if (threads <= 16) {
194
+ acl_better_XC_per_thread = 512;
195
+ } else {
196
+ acl_better_XC_per_thread = 1024;
197
+ }
198
+ } else {
199
+ if (threads == 1) {
200
+ acl_better_C = 64;
201
+ } else if (threads <= 32) {
202
+ acl_better_C = 256;
203
+ } else {
204
+ acl_better_C = 1024;
205
+ }
206
+
207
+ if (threads == 1) {
208
+ acl_better_XC_per_thread = 128;
209
+ } else if (threads <= 32) {
210
+ acl_better_XC_per_thread = 256;
211
+ } else {
212
+ acl_better_XC_per_thread = 512;
213
+ }
214
+ }
215
+ }
216
+
217
+ return C > acl_competitive_C
218
+ && (C > acl_better_C
219
+ || X * C > acl_better_XC_per_thread * threads);
220
+ }
221
+
222
+ acl_msdnorm_conf_t anp;
223
+
224
+ }; // pd_t
225
+
226
+ acl_layer_normalization_fwd_t(const pd_t *apd) : primitive_t(apd) {}
227
+
228
+ status_t create_resource(
229
+ engine_t *engine, resource_mapper_t &mapper) const override {
230
+ if (mapper.has_resource(this)) return status::success;
231
+
232
+ auto r = utils::make_unique<acl_layer_normalization_resource_t>();
233
+ if (!r) return status::out_of_memory;
234
+
235
+ // Configure the resource based on information from primitive descriptor
236
+ CHECK(r->configure(pd()->anp, pd()));
237
+ mapper.add(this, std::move(r));
238
+
239
+ return status::success;
240
+ }
241
+
242
+ status_t execute(const exec_ctx_t &ctx) const override {
243
+ return execute_forward(ctx);
244
+ }
245
+
246
+ private:
247
+ // To guard the const execute_forward, the mutex must be 'mutable'
248
+ mutable std::mutex mtx;
249
+ status_t execute_forward(const exec_ctx_t &ctx) const;
250
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
251
+ }; // acl_layer_normalization_fwd_t
252
+
253
+ } // namespace aarch64
254
+ } // namespace cpu
255
+ } // namespace impl
256
+ } // namespace dnnl
257
+
258
+ #endif // CPU_AARCH64_ACL_LAYER_NORMALIZATION_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_pooling.hpp ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_POOLING_HPP
18
+ #define CPU_AARCH64_ACL_POOLING_HPP
19
+
20
+ #include "cpu/aarch64/acl_utils.hpp"
21
+ #include "cpu/cpu_pooling_pd.hpp"
22
+
23
+ namespace dnnl {
24
+ namespace impl {
25
+ namespace cpu {
26
+ namespace aarch64 {
27
+
28
+ struct acl_pooling_obj_t {
29
+ arm_compute::NEPoolingLayer pool;
30
+ arm_compute::Tensor src_tensor;
31
+ arm_compute::Tensor dst_tensor;
32
+ };
33
+
34
+ struct acl_pooling_conf_t {
35
+ arm_compute::PoolingLayerInfo pool_info;
36
+ arm_compute::TensorInfo src_info;
37
+ arm_compute::TensorInfo dst_info;
38
+ };
39
+
40
+ struct acl_pooling_resource_t : public resource_t {
41
+ acl_pooling_resource_t()
42
+ : acl_pooling_obj_(utils::make_unique<acl_pooling_obj_t>()) {}
43
+
44
+ status_t configure(const acl_pooling_conf_t &app) {
45
+ if (!acl_pooling_obj_) return status::out_of_memory;
46
+
47
+ // Init Compute Library tensors based on info from descriptor
48
+ acl_pooling_obj_->src_tensor.allocator()->init(app.src_info);
49
+ acl_pooling_obj_->dst_tensor.allocator()->init(app.dst_info);
50
+
51
+ acl_pooling_obj_->pool.configure(&acl_pooling_obj_->src_tensor,
52
+ &acl_pooling_obj_->dst_tensor, app.pool_info);
53
+
54
+ return status::success;
55
+ }
56
+
57
+ acl_pooling_obj_t &get_acl_obj() const { return *acl_pooling_obj_; }
58
+
59
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_pooling_resource_t);
60
+
61
+ private:
62
+ std::unique_ptr<acl_pooling_obj_t> acl_pooling_obj_;
63
+ }; // acl_pooling_resource_t
64
+
65
+ struct acl_pooling_fwd_t : public primitive_t {
66
+ struct pd_t : public cpu_pooling_fwd_pd_t {
67
+ using cpu_pooling_fwd_pd_t::cpu_pooling_fwd_pd_t;
68
+ pd_t(const pooling_desc_t *adesc, const primitive_attr_t *attr,
69
+ const pooling_fwd_pd_t *hint_fwd_pd)
70
+ : cpu_pooling_fwd_pd_t(adesc, attr, hint_fwd_pd), app() {}
71
+
72
+ DECLARE_COMMON_PD_T("acl", acl_pooling_fwd_t);
73
+
74
+ status_t init(engine_t *engine) {
75
+ bool ok = set_default_params() == status::success
76
+ && is_fwd() // ACL supports forward propagation only
77
+ && utils::everyone_is(
78
+ src_md()->data_type, dst_md()->data_type)
79
+ && utils::one_of(
80
+ src_md()->data_type, data_type::f32, data_type::f16)
81
+ && attr()->has_default_values()
82
+ && attr_.set_default_formats(dst_md(0)) == status::success
83
+ && !is_dilated() && !has_zero_dim_memory();
84
+ if (!ok) return status::unimplemented;
85
+
86
+ const pooling_desc_t *pod = desc();
87
+
88
+ // Choose the pooling type
89
+ const alg_kind_t alg = pod->alg_kind;
90
+ const bool is_max_pool = (alg == alg_kind::pooling_max);
91
+ app.pool_info.pool_type = is_max_pool
92
+ ? arm_compute::PoolingType::MAX
93
+ : arm_compute::PoolingType::AVG;
94
+
95
+ // Max forward training requires a worksace tensor.
96
+ // For this workspace tensor, oneDNN uses pool window coordinates,
97
+ // Whereas ACL uses absolute image coordinates.
98
+ // Due to this mismatch, reject max forward training cases
99
+ ACL_CHECK_SUPPORT(
100
+ (is_max_pool
101
+ && pod->prop_kind == prop_kind::forward_training),
102
+ "ACL does not support training for max pooling in oneDNN");
103
+
104
+ // When padding is larger than the kernel, infinite values are
105
+ // produced.
106
+ // ACL and oneDNN use different values to represent infinity
107
+ // which is difficult to account for, so return unimplemented.
108
+ // See https://github.com/oneapi-src/oneDNN/issues/1205
109
+ ACL_CHECK_SUPPORT(KH() <= padT() || KH() <= padB() || KW() <= padL()
110
+ || KW() <= padR(),
111
+ "ACL does not support pooling cases where padding >= kernel"
112
+ " in oneDNN");
113
+
114
+ auto src_tag = memory_desc_matches_one_of_tag(
115
+ *src_md(), format_tag::nhwc, format_tag::nchw);
116
+ auto dst_tag = memory_desc_matches_one_of_tag(
117
+ *dst_md(), format_tag::nhwc, format_tag::nchw);
118
+
119
+ ACL_CHECK_SUPPORT(
120
+ utils::one_of(format_tag::undef, src_tag, dst_tag),
121
+ "src or dst is not format nhwc or nchw");
122
+ ACL_CHECK_SUPPORT(src_tag != dst_tag,
123
+ "src and dst have different memory formats");
124
+
125
+ const memory_desc_wrapper src_d(src_md());
126
+ const memory_desc_wrapper dst_d(dst_md());
127
+ const int ndims = src_d.ndims();
128
+ ACL_CHECK_SUPPORT(ndims != 4, "Tensor is not 4d");
129
+
130
+ // Pooling window
131
+ app.pool_info.pool_size = arm_compute::Size2D(KW(), KH());
132
+ // Choose the data layout
133
+ bool is_nspc = utils::one_of(src_tag, format_tag::nhwc);
134
+ const auto acl_layout = is_nspc ? arm_compute::DataLayout::NHWC
135
+ : arm_compute::DataLayout::NCHW;
136
+ app.pool_info.data_layout = acl_layout;
137
+ const auto acl_data_t
138
+ = acl_utils::get_acl_data_t(src_d.data_type());
139
+
140
+ ACL_CHECK_SUPPORT(
141
+ !use_acl_heuristic(MB() * IC() * OH() * OW() * KH() * KW(),
142
+ dnnl_get_max_threads(), is_max_pool, is_nspc),
143
+ "ACL is unoptimal in this case");
144
+
145
+ app.pool_info.exclude_padding
146
+ = (alg == alg_kind::pooling_avg_exclude_padding);
147
+
148
+ app.pool_info.pad_stride_info = arm_compute::PadStrideInfo(KSW(),
149
+ KSH(), padL(), padR(), padT(), padB(),
150
+ arm_compute::DimensionRoundingType::FLOOR);
151
+
152
+ app.src_info = arm_compute::TensorInfo(is_nspc
153
+ ? arm_compute::TensorShape(IC(), IW(), IH(), MB())
154
+ : arm_compute::TensorShape(IW(), IH(), IC(), MB()),
155
+ 1, acl_data_t, acl_layout);
156
+ app.dst_info = arm_compute::TensorInfo(is_nspc
157
+ ? arm_compute::TensorShape(OC(), OW(), OH(), MB())
158
+ : arm_compute::TensorShape(OW(), OH(), OC(), MB()),
159
+ 1, acl_data_t, acl_layout);
160
+
161
+ ACL_CHECK_VALID(arm_compute::NEPoolingLayer::validate(
162
+ &app.src_info, &app.dst_info, app.pool_info));
163
+
164
+ return status::success;
165
+ }
166
+
167
+ bool use_acl_heuristic(
168
+ int problem_size, int thread_count, bool is_max, bool is_nhwc) {
169
+ // For nhwc, ACL is faster above a certain problem size 'cutoff'
170
+ // This cutoff scales linearly with thread count (except 1 thread)
171
+ // So return true iff problem size is larger than this cutoff.
172
+ // Note: This rule is approximate, Not all problems follow this rule
173
+ if (is_nhwc) {
174
+ if (is_max) {
175
+ if (thread_count == 1)
176
+ return problem_size > 512;
177
+ else
178
+ return problem_size > 4096 * thread_count;
179
+ } else { // pooling_alg == avg_p || pooling_alg == avg_np
180
+ if (thread_count == 1)
181
+ return problem_size > 1024;
182
+ else
183
+ return problem_size > 8192 * thread_count;
184
+ }
185
+ } else { // memory_format == nchw
186
+ return false;
187
+ }
188
+ }
189
+
190
+ acl_pooling_conf_t app;
191
+ };
192
+
193
+ acl_pooling_fwd_t(const pd_t *apd) : primitive_t(apd) {}
194
+
195
+ status_t execute(const exec_ctx_t &ctx) const override {
196
+ return execute_forward(ctx);
197
+ }
198
+
199
+ status_t create_resource(
200
+ engine_t *engine, resource_mapper_t &mapper) const override {
201
+ if (mapper.has_resource(this)) return status::success;
202
+
203
+ auto r = utils::make_unique<acl_pooling_resource_t>();
204
+ if (!r) return status::out_of_memory;
205
+
206
+ // Configure the resource based on information from primitive descriptor
207
+ auto st = r->configure(pd()->app);
208
+ if (st == status::success) { mapper.add(this, std::move(r)); }
209
+
210
+ return st;
211
+ }
212
+
213
+ private:
214
+ // execute_forward has to be const thus mutability of mtx
215
+ mutable std::mutex mtx;
216
+ status_t execute_forward(const exec_ctx_t &ctx) const;
217
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
218
+ }; // acl_pooling_fwd_t
219
+
220
+ } // namespace aarch64
221
+ } // namespace cpu
222
+ } // namespace impl
223
+ } // namespace dnnl
224
+
225
+ #endif // CPU_AARCH64_ACL_POOLING_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_post_ops.hpp ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_POST_OPS_HPP
18
+ #define CPU_AARCH64_ACL_POST_OPS_HPP
19
+
20
+ #include "cpu/aarch64/acl_binary.hpp"
21
+ #include "cpu/aarch64/acl_eltwise.hpp"
22
+
23
+ namespace dnnl {
24
+ namespace impl {
25
+ namespace cpu {
26
+ namespace aarch64 {
27
+
28
+ struct acl_post_ops_t {
29
+
30
+ acl_post_ops_t() = default;
31
+
32
+ // init the acl_post_ops_t. Note that this function modifies the passed in
33
+ // post ops by setting the preferred memory formats
34
+ status_t init(engine_t *engine, post_ops_t &post_ops,
35
+ const memory_desc_t &dst_md) {
36
+
37
+ CHECK(post_ops.set_default_formats(&dst_md));
38
+ dst_data_type = dst_md.data_type;
39
+
40
+ // Reset properties derived from post_ops
41
+ sum_index = -1;
42
+ post_op_primitives = {};
43
+
44
+ for (int i = 0; i < post_ops.len(); i++) {
45
+ auto &po = post_ops.entry_[i];
46
+
47
+ if (po.is_sum()) {
48
+ ACL_CHECK_SUPPORT(po.sum.scale != 1.0f,
49
+ "sum post op scale must be 1 (no scale)");
50
+
51
+ ACL_CHECK_SUPPORT(po.sum.zero_point != 0,
52
+ "sum post op zero point must be 0 (no shift)");
53
+
54
+ // >= 0 means we had one already
55
+ ACL_CHECK_SUPPORT(sum_index >= 0,
56
+ "there must not be more than 1 sum post op");
57
+
58
+ sum_index = i;
59
+
60
+ // Sum is an add primitive where dst = temp_dst + dst
61
+ binary_desc_t po_desc;
62
+ po_desc.primitive_kind = primitive_kind::binary;
63
+ po_desc.alg_kind = alg_kind::binary_add;
64
+ po_desc.src_desc[0] = dst_md;
65
+ po_desc.src_desc[1] = dst_md;
66
+ po_desc.dst_desc = dst_md;
67
+ auto empty_attr = dnnl_primitive_attr();
68
+ typename acl_binary_t::pd_t acl_binary_pd(
69
+ &po_desc, &empty_attr, nullptr);
70
+ CHECK(acl_binary_pd.init(engine));
71
+
72
+ auto acl_binary
73
+ = std::make_shared<acl_binary_t>(&acl_binary_pd);
74
+ CHECK(acl_binary->init(engine));
75
+ post_op_primitives.push_back(acl_binary);
76
+
77
+ } else if (po.is_binary()) {
78
+ binary_desc_t po_desc;
79
+ po_desc.primitive_kind = primitive_kind::binary;
80
+ po_desc.alg_kind = po.binary.alg;
81
+ po_desc.src_desc[0] = dst_md;
82
+ po_desc.src_desc[1] = po.binary.src1_desc;
83
+ po_desc.dst_desc = dst_md;
84
+ auto empty_attr = dnnl_primitive_attr();
85
+ typename acl_binary_t::pd_t acl_binary_pd(
86
+ &po_desc, &empty_attr, nullptr);
87
+ CHECK(acl_binary_pd.init(engine));
88
+
89
+ auto acl_binary
90
+ = std::make_shared<acl_binary_t>(&acl_binary_pd);
91
+ CHECK(acl_binary->init(engine));
92
+ post_op_primitives.push_back(acl_binary);
93
+
94
+ } else if (po.is_eltwise()) {
95
+ ACL_CHECK_SUPPORT(po.eltwise.scale != 1.0f,
96
+ "eltwise post op scale must be 1 (no scale)");
97
+
98
+ eltwise_desc_t eltwise_desc;
99
+ eltwise_desc.primitive_kind = primitive_kind::eltwise;
100
+ eltwise_desc.alg_kind = po.eltwise.alg;
101
+ eltwise_desc.alpha = po.eltwise.alpha;
102
+ eltwise_desc.beta = po.eltwise.beta;
103
+ memory_desc_t temp_dst = dst_md;
104
+ // pass eltwise a desc with f32 datatype to perform the operation in fp32 rather than fp16
105
+ // since oneDNN requires all post-ops to run in fp32.
106
+ // we don't need to do that to the other post-ops as executing them in fp16 yields the same result.
107
+ if (dst_data_type == data_type::f16) {
108
+ temp_dst.data_type = data_type::f32;
109
+ }
110
+ eltwise_desc.src_desc = temp_dst;
111
+ eltwise_desc.dst_desc = temp_dst;
112
+ eltwise_desc.prop_kind = prop_kind_t::dnnl_forward;
113
+ auto empty_attr = dnnl_primitive_attr();
114
+ typename acl_eltwise_fwd_t::pd_t acl_eltwise_pd(
115
+ &eltwise_desc, &empty_attr, nullptr);
116
+ CHECK(acl_eltwise_pd.init(engine));
117
+
118
+ auto acl_eltwise
119
+ = std::make_shared<acl_eltwise_fwd_t>(&acl_eltwise_pd);
120
+ CHECK(acl_eltwise->init(engine));
121
+ post_op_primitives.push_back(acl_eltwise);
122
+
123
+ } else {
124
+ // Unsupported catchall
125
+ return status::unimplemented;
126
+ }
127
+ }
128
+
129
+ return status::success;
130
+ }
131
+
132
+ // init acl_post_ops_t, ignoring the first post op if it is an eltwise so
133
+ // that it can be fused, placing it in act_info_to_fuse. Note that this
134
+ // function modifies the passed in post ops by setting the preferred memory
135
+ // formats
136
+ status_t init(engine_t *engine, post_ops_t &base_post_ops,
137
+ const memory_desc_t &dst_md,
138
+ arm_compute::ActivationLayerInfo &act_info_to_fuse) {
139
+
140
+ CHECK(base_post_ops.set_default_formats(&dst_md));
141
+ dst_data_type = dst_md.data_type;
142
+ // If the first entry is eltwise, we fuse it, except when the datatype
143
+ // is fp16 because in this case we want to execute the eltwise in fp32.
144
+ if (base_post_ops.len() >= 1 && base_post_ops.entry_[0].is_eltwise()
145
+ && dst_data_type != data_type::f16) {
146
+
147
+ const auto &first_po = base_post_ops.entry_[0].eltwise;
148
+ ACL_CHECK_SUPPORT(first_po.scale != 1.0f,
149
+ "eltwise post op scale must be 1 (no scale)");
150
+ CHECK(acl_utils::convert_to_acl_act(first_po, act_info_to_fuse));
151
+
152
+ // Copy all but the first, because it has been fused
153
+ post_ops_t post_ops;
154
+ for (int idx = 1; idx < base_post_ops.len(); ++idx) {
155
+ // Construct empty entry then copy, so that we can check for failure
156
+ post_ops.entry_.emplace_back();
157
+ post_ops.entry_.back().copy_from(base_post_ops.entry_[idx]);
158
+ }
159
+ return init(engine, post_ops, dst_md);
160
+
161
+ } else {
162
+ // Nothing to fuse, just copy all post ops
163
+ return init(engine, base_post_ops, dst_md);
164
+ }
165
+ }
166
+
167
+ bool has_sum() const { return sum_index >= 0; }
168
+
169
+ status_t create_resource(
170
+ engine_t *engine, resource_mapper_t &mapper) const {
171
+ for (const auto &post_op : post_op_primitives) {
172
+ CHECK(post_op->create_resource(engine, mapper));
173
+ }
174
+ return status::success;
175
+ }
176
+
177
+ status_t execute(const exec_ctx_t &ctx, void *src) const;
178
+
179
+ private:
180
+ // Index of the sum post op if there is one, < 0 means no sum
181
+ int sum_index = -1;
182
+ data_type_t dst_data_type;
183
+ // Vector of primitives used to execute the post ops. They are constructed
184
+ // in init to be either acl_binary_t (for sum, add, sub, div, mul, min and
185
+ // max) or acl_eltwise_fwd_t (for relu, elu, tanh, square, abs etc)
186
+ std::vector<std::shared_ptr<primitive_t>> post_op_primitives;
187
+ };
188
+
189
+ } // namespace aarch64
190
+ } // namespace cpu
191
+ } // namespace impl
192
+ } // namespace dnnl
193
+
194
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_prelu.hpp ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022 Arm Ltd. and affiliates
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
+ #ifndef CPU_AARCH64_ACL_PRELU_HPP
17
+ #define CPU_AARCH64_ACL_PRELU_HPP
18
+
19
+ #include "cpu/aarch64/acl_utils.hpp"
20
+ #include "cpu/cpu_prelu_pd.hpp"
21
+
22
+ namespace dnnl {
23
+ namespace impl {
24
+ namespace cpu {
25
+ namespace aarch64 {
26
+
27
+ struct acl_prelu_obj_t {
28
+ arm_compute::NEPReluLayer prelu;
29
+ arm_compute::Tensor src_tensor;
30
+ arm_compute::Tensor weights_tensor;
31
+ arm_compute::Tensor dst_tensor;
32
+ };
33
+
34
+ struct acl_prelu_conf_t {
35
+ arm_compute::TensorInfo src_info;
36
+ arm_compute::TensorInfo weights_info;
37
+ arm_compute::TensorInfo dst_info;
38
+ };
39
+
40
+ struct acl_prelu_resource_t : public resource_t {
41
+ acl_prelu_resource_t() : acl_obj_(utils::make_unique<acl_prelu_obj_t>()) {}
42
+
43
+ status_t configure(const acl_prelu_conf_t &app) {
44
+ if (!acl_obj_) return status::out_of_memory;
45
+
46
+ // Init Compute Library tensors based on info from descriptor
47
+ acl_obj_->src_tensor.allocator()->init(app.src_info);
48
+ acl_obj_->weights_tensor.allocator()->init(app.weights_info);
49
+ acl_obj_->dst_tensor.allocator()->init(app.dst_info);
50
+
51
+ // clang-format off
52
+ acl_obj_->prelu.configure(
53
+ &acl_obj_->src_tensor,
54
+ &acl_obj_->weights_tensor,
55
+ &acl_obj_->dst_tensor);
56
+ // clang-format on
57
+
58
+ return status::success;
59
+ }
60
+
61
+ acl_prelu_obj_t &get_acl_obj() const { return *acl_obj_; }
62
+
63
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_prelu_resource_t);
64
+
65
+ private:
66
+ std::unique_ptr<acl_prelu_obj_t> acl_obj_;
67
+ }; // acl_prelu_resource_t
68
+
69
+ struct acl_prelu_fwd_t : public primitive_t {
70
+ struct pd_t : public cpu_prelu_fwd_pd_t {
71
+ using cpu_prelu_fwd_pd_t::cpu_prelu_fwd_pd_t;
72
+
73
+ DECLARE_COMMON_PD_T("acl", acl_prelu_fwd_t);
74
+
75
+ status_t init(engine_t *engine) {
76
+ using namespace format_tag;
77
+ using namespace acl_utils;
78
+
79
+ // Forward only
80
+ if (!prelu_pd_t::is_fwd()) return status::unimplemented;
81
+
82
+ // Only support f32 and f16 for now
83
+ data_type_t ddt = dst_md(0)->data_type;
84
+ if (!utils::one_of(ddt, data_type::f32, data_type::f16))
85
+ return status::unimplemented;
86
+
87
+ if (!set_default_formats()) return status::unimplemented;
88
+
89
+ if (!attr()->has_default_values()) return status::unimplemented;
90
+
91
+ // ACL pointwise arithmetic operators assume that the innermost
92
+ // dimensions are dense for src, weights and dst. Reordering the
93
+ // logical dimensions by stride does this (if reordered_dims >= 1 )
94
+ // and also makes memory accesses contiguous in ACL (without any
95
+ // data reordering).
96
+ memory_desc_t src_d_permed, weights_d_permed, dst_d_permed;
97
+ int reordered_dims = reorder_dimensions_by_stride(
98
+ {&src_d_permed, &weights_d_permed, &dst_d_permed},
99
+ {src_md(0), weights_md(0), dst_md(0)});
100
+ if (reordered_dims < 1) return status::unimplemented;
101
+
102
+ // Create ACL tensor infos with permuted descs
103
+ CHECK(tensor_info(app_.src_info, src_d_permed));
104
+ CHECK(tensor_info(app_.weights_info, weights_d_permed));
105
+ CHECK(tensor_info(app_.dst_info, dst_d_permed));
106
+
107
+ // This forces ACL not to parallelise with small workloads, this is
108
+ // a temporary fix and should be removed in future versions (TODO)
109
+ memory_desc_wrapper dst_d(dst_md(0));
110
+ if (dst_d.nelems() < 40000) {
111
+ size_t acl_y_axis_i = 1;
112
+ CHECK(insert_singleton_dimension(app_.src_info, acl_y_axis_i));
113
+ CHECK(insert_singleton_dimension(
114
+ app_.weights_info, acl_y_axis_i));
115
+ CHECK(insert_singleton_dimension(app_.dst_info, acl_y_axis_i));
116
+ }
117
+
118
+ ACL_CHECK_VALID(arm_compute::NEPReluLayer::validate(
119
+ &app_.src_info, &app_.weights_info, &app_.dst_info));
120
+
121
+ return status::success;
122
+ }
123
+
124
+ acl_prelu_conf_t app_;
125
+ }; // pd_t
126
+
127
+ acl_prelu_fwd_t(const pd_t *apd) : primitive_t(apd) {}
128
+
129
+ status_t create_resource(
130
+ engine_t *engine, resource_mapper_t &mapper) const override {
131
+ if (mapper.has_resource(this)) return status::success;
132
+
133
+ auto r = utils::make_unique<acl_prelu_resource_t>();
134
+ if (!r) return status::out_of_memory;
135
+
136
+ // Configure the resource based on information from primitive descriptor
137
+ CHECK(r->configure(pd()->app_));
138
+
139
+ mapper.add(this, std::move(r));
140
+ return status::success;
141
+ }
142
+
143
+ status_t execute(const exec_ctx_t &ctx) const override {
144
+ return execute_forward(ctx);
145
+ }
146
+
147
+ private:
148
+ // To guard the const execute_forward, the mutex must be 'mutable'
149
+ mutable std::mutex mtx;
150
+ status_t execute_forward(const exec_ctx_t &ctx) const;
151
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
152
+ }; // acl_prelu_fwd_t
153
+
154
+ } // namespace aarch64
155
+ } // namespace cpu
156
+ } // namespace impl
157
+ } // namespace dnnl
158
+
159
+ #endif // CPU_AARCH64_ACL_PRELU_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_softmax.hpp ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2022 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_SOFTMAX_HPP
18
+ #define CPU_AARCH64_ACL_SOFTMAX_HPP
19
+
20
+ #include "cpu/cpu_softmax_pd.hpp"
21
+
22
+ #include "cpu/aarch64/acl_utils.hpp"
23
+
24
+ namespace dnnl {
25
+ namespace impl {
26
+ namespace cpu {
27
+ namespace aarch64 {
28
+
29
+ struct acl_softmax_obj_t {
30
+ std::unique_ptr<arm_compute::IFunction> softmax;
31
+ arm_compute::Tensor src_tensor;
32
+ arm_compute::Tensor dst_tensor;
33
+ };
34
+
35
+ struct acl_softmax_conf_t {
36
+ arm_compute::TensorInfo src_info;
37
+ arm_compute::TensorInfo dst_info;
38
+ float beta;
39
+ int32_t axis;
40
+ bool is_logsoftmax;
41
+ };
42
+
43
+ struct acl_softmax_resource_t : public resource_t {
44
+ acl_softmax_resource_t()
45
+ : acl_obj_(utils::make_unique<acl_softmax_obj_t>()) {}
46
+
47
+ status_t configure(const acl_softmax_conf_t &asp) {
48
+ if (!acl_obj_) return status::out_of_memory;
49
+
50
+ // Init Compute Library tensors based on info from descriptor
51
+ acl_obj_->src_tensor.allocator()->init(asp.src_info);
52
+ acl_obj_->dst_tensor.allocator()->init(asp.dst_info);
53
+
54
+ if (asp.is_logsoftmax) {
55
+ auto logsoftmax
56
+ = std::make_unique<arm_compute::NELogSoftmaxLayer>();
57
+ // clang-format off
58
+ logsoftmax->configure(
59
+ &acl_obj_->src_tensor,
60
+ &acl_obj_->dst_tensor,
61
+ asp.beta,
62
+ asp.axis);
63
+ // clang-format on
64
+ acl_obj_->softmax = std::move(logsoftmax);
65
+ } else {
66
+ auto softmax = std::make_unique<arm_compute::NESoftmaxLayer>();
67
+ // clang-format off
68
+ softmax->configure(
69
+ &acl_obj_->src_tensor,
70
+ &acl_obj_->dst_tensor,
71
+ asp.beta,
72
+ asp.axis);
73
+ // clang-format on
74
+ acl_obj_->softmax = std::move(softmax);
75
+ }
76
+
77
+ return status::success;
78
+ }
79
+
80
+ acl_softmax_obj_t &get_acl_obj() const { return *acl_obj_; }
81
+
82
+ DNNL_DISALLOW_COPY_AND_ASSIGN(acl_softmax_resource_t);
83
+
84
+ private:
85
+ std::unique_ptr<acl_softmax_obj_t> acl_obj_;
86
+ }; // acl_softmax_resource_t
87
+
88
+ struct acl_softmax_fwd_t : public primitive_t {
89
+ struct pd_t : public cpu_softmax_fwd_pd_t {
90
+ using cpu_softmax_fwd_pd_t::cpu_softmax_fwd_pd_t;
91
+
92
+ DECLARE_COMMON_PD_T("acl", acl_softmax_fwd_t);
93
+
94
+ status_t init(engine_t *engine) {
95
+
96
+ bool ok = is_fwd()
97
+ // ACL only supports matching src/dst data types
98
+ && src_md()->data_type == dst_md()->data_type
99
+ && utils::one_of(
100
+ src_md()->data_type, data_type::f32, data_type::f16)
101
+ && attr()->has_default_values()
102
+ && set_default_formats() == status::success;
103
+ if (!ok) return status::unimplemented;
104
+
105
+ // Get memory desc to find sizes and dims
106
+ const memory_desc_wrapper src_d(src_md());
107
+ const data_type_t data_type = src_d.data_type();
108
+
109
+ // ACL only supports plain tensors, can be permuted but not blocked
110
+ if (!src_d.is_plain()) return status::unimplemented;
111
+
112
+ // Guards against a 0-sized dimension
113
+ if (src_d.has_zero_dim()) return status::unimplemented;
114
+
115
+ // No scaling
116
+ asp_.beta = 1;
117
+
118
+ asp_.is_logsoftmax = is_logsoftmax();
119
+
120
+ // The strides give us the in memory inner size
121
+ dim_t inner_size_ = src_d.blocking_desc().strides[axis()];
122
+
123
+ dim_t axis_size_ = axis_size();
124
+
125
+ // The outer size is any left-over dimensions not inner or on the axis
126
+ dim_t outer_size_ = src_d.nelems() / (inner_size_ * axis_size_);
127
+
128
+ // In this context, NHWC tells ACL that the logical and physical
129
+ // dimensions are the same
130
+ arm_compute::DataLayout acl_layout = arm_compute::DataLayout::NHWC;
131
+
132
+ const arm_compute::DataType acl_data_t
133
+ = acl_utils::get_acl_data_t(data_type);
134
+
135
+ const int threads = dnnl_get_max_threads();
136
+ if (inner_size_ == 1) {
137
+ // A rough empirical heuristic created by fitting a polynomial
138
+ // of the tensor sizes and thread count to the run time of the
139
+ // ref and ACL softmax. This variable is greater than zero when
140
+ // ref is faster, and less than zero when ACL is faster. We can
141
+ // interpret the constant term as the constant overhead
142
+ // associated with calling the external library and the negative
143
+ // coefficient on total_size as ACL being faster at processing
144
+ // each element
145
+ double acl_ref_performance_diff = 1 + 0.005 * outer_size_
146
+ - 0.0027 * axis_size_
147
+ * std::ceil(double(outer_size_) / threads);
148
+ if (threads > 1 || outer_size_ > 1) {
149
+ // Using threads within ACL adds another constant overhead
150
+ acl_ref_performance_diff += 17;
151
+ }
152
+ if (acl_ref_performance_diff > 0) return status::unimplemented;
153
+
154
+ // If the inner size is 1, we can get rid of the dimension.
155
+ // This stops ACL doing a unnecessary permute
156
+ arm_compute::TensorShape acl_tensor_shape
157
+ = arm_compute::TensorShape(axis_size_, outer_size_);
158
+ asp_.axis = 0;
159
+
160
+ asp_.src_info = arm_compute::TensorInfo(
161
+ acl_tensor_shape, 1, acl_data_t, acl_layout);
162
+ asp_.dst_info = arm_compute::TensorInfo(
163
+ acl_tensor_shape, 1, acl_data_t, acl_layout);
164
+ } else {
165
+ // A rough empirical heuristic, see comment above
166
+ // The only difference here is that ACL does a reorder, and so
167
+ // is considerably better
168
+ double acl_ref_performance_diff = 1 + 0.005 * outer_size_
169
+ - 0.01 * inner_size_ * axis_size_
170
+ * std::ceil(double(outer_size_) / threads);
171
+ if (threads > 1 || outer_size_ > 1) {
172
+ // Using threads within ACL adds another constant overhead
173
+ acl_ref_performance_diff += 17;
174
+ }
175
+
176
+ if (acl_ref_performance_diff > 0) return status::unimplemented;
177
+
178
+ // Irrespective of the input dimensions, we construct a tensor
179
+ // with dimensions such that softmax can be applied over the
180
+ // middle axis (1), with the correct stride and vector length.
181
+ arm_compute::TensorShape acl_tensor_shape
182
+ = arm_compute::TensorShape(
183
+ inner_size_, axis_size_, outer_size_);
184
+ asp_.axis = 1;
185
+
186
+ asp_.src_info = arm_compute::TensorInfo(
187
+ acl_tensor_shape, 1, acl_data_t, acl_layout);
188
+ asp_.dst_info = arm_compute::TensorInfo(
189
+ acl_tensor_shape, 1, acl_data_t, acl_layout);
190
+ }
191
+
192
+ // Validate manually to check for return status
193
+ if (asp_.is_logsoftmax) {
194
+ ACL_CHECK_VALID(arm_compute::NELogSoftmaxLayer::validate(
195
+ &asp_.src_info, &asp_.dst_info, asp_.beta, asp_.axis));
196
+ } else {
197
+ ACL_CHECK_VALID(arm_compute::NESoftmaxLayer::validate(
198
+ &asp_.src_info, &asp_.dst_info, asp_.beta, asp_.axis));
199
+ }
200
+
201
+ return status::success;
202
+ }
203
+
204
+ acl_softmax_conf_t asp_;
205
+ }; // pd_t
206
+
207
+ acl_softmax_fwd_t(const pd_t *apd) : primitive_t(apd) {}
208
+
209
+ status_t create_resource(
210
+ engine_t *engine, resource_mapper_t &mapper) const override {
211
+ if (mapper.has_resource(this)) return status::success;
212
+
213
+ auto r = utils::make_unique<acl_softmax_resource_t>();
214
+ if (!r) return status::out_of_memory;
215
+
216
+ // Configure the resource based on information from primitive descriptor
217
+ auto st = r->configure(pd()->asp_);
218
+ if (st == status::success) { mapper.add(this, std::move(r)); }
219
+
220
+ return st;
221
+ }
222
+
223
+ status_t execute(const exec_ctx_t &ctx) const override {
224
+ return execute_forward(ctx);
225
+ }
226
+
227
+ private:
228
+ // To guard the const execute_forward, the mutex must be 'mutable'
229
+ mutable std::mutex mtx;
230
+ status_t execute_forward(const exec_ctx_t &ctx) const;
231
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
232
+ }; // acl_softmax_fwd_t
233
+
234
+ } // namespace aarch64
235
+ } // namespace cpu
236
+ } // namespace impl
237
+ } // namespace dnnl
238
+
239
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_thread.hpp ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_THREAD_HPP
18
+ #define CPU_AARCH64_ACL_THREAD_HPP
19
+
20
+ #include "common/dnnl_thread.hpp"
21
+ #include "common/verbose.hpp"
22
+
23
+ #include "arm_compute/runtime/Scheduler.h"
24
+
25
+ namespace dnnl {
26
+ namespace impl {
27
+ namespace cpu {
28
+ namespace aarch64 {
29
+
30
+ namespace acl_thread_utils {
31
+
32
+ #if DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_OMP
33
+ // Number of threads in Compute Library is set by OMP_NUM_THREADS
34
+ // dnnl_get_max_threads() == OMP_NUM_THREADS
35
+ void acl_thread_bind();
36
+ // Swap BenchmarkScheduler for default ACL scheduler builds (i.e. CPPScheduler, OMPScheduler)
37
+ // for DNNL_VERBOSE=profile,profile_externals
38
+ void acl_set_benchmark_scheduler_default();
39
+ #endif
40
+
41
+ #if DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_THREADPOOL
42
+ // Retrieve threadpool size during primitive execution and set ThreadpoolScheduler num_threads
43
+ void acl_set_tp_scheduler();
44
+ void acl_set_threadpool_num_threads();
45
+ // Swap BenchmarkScheduler for custom scheduler builds (i.e. ThreadPoolScheduler) for DNNL_VERBOSE=profile,profile_externals
46
+ void acl_set_tp_benchmark_scheduler();
47
+ #endif
48
+ // Set threading for ACL
49
+ void set_acl_threading();
50
+ } // namespace acl_thread_utils
51
+
52
+ } // namespace aarch64
53
+ } // namespace cpu
54
+ } // namespace impl
55
+ } // namespace dnnl
56
+
57
+ #endif // CPU_AARCH64_ACL_THREAD_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_threadpool_scheduler.hpp ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_THREADPOOL_SCHEDULER_HPP
18
+ #define CPU_AARCH64_ACL_THREADPOOL_SCHEDULER_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl_config.h"
21
+
22
+ #if DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_THREADPOOL
23
+
24
+ #include "arm_compute/runtime/IScheduler.h"
25
+ #include "support/Mutex.h"
26
+
27
+ namespace dnnl {
28
+ namespace impl {
29
+ namespace cpu {
30
+ namespace aarch64 {
31
+
32
+ class ThreadpoolScheduler final : public arm_compute::IScheduler {
33
+ public:
34
+ ThreadpoolScheduler();
35
+ ~ThreadpoolScheduler();
36
+
37
+ /// Sets the number of threads the scheduler will use to run the kernels.
38
+ void set_num_threads(unsigned int num_threads) override;
39
+ /// Returns the number of threads that the ThreadpoolScheduler has in its pool.
40
+ unsigned int num_threads() const override;
41
+
42
+ /// Multithread the execution of the passed kernel if possible.
43
+ void schedule(arm_compute::ICPPKernel *kernel,
44
+ const arm_compute::IScheduler::Hints &hints) override;
45
+
46
+ /// Multithread the execution of the passed kernel if possible.
47
+ void schedule_op(arm_compute::ICPPKernel *kernel,
48
+ const arm_compute::IScheduler::Hints &hints,
49
+ const arm_compute::Window &window,
50
+ arm_compute::ITensorPack &tensors) override;
51
+
52
+ protected:
53
+ /// Execute workloads in parallel using num_threads
54
+ void run_workloads(std::vector<Workload> &workloads) override;
55
+
56
+ private:
57
+ uint _num_threads {};
58
+ arm_compute::Mutex _run_workloads_mutex {};
59
+ };
60
+
61
+ } // namespace aarch64
62
+ } // namespace cpu
63
+ } // namespace impl
64
+ } // namespace dnnl
65
+
66
+ #endif // CPU_AARCH64_ACL_THREADPOOL_SCHEDULER_HPP
67
+
68
+ #endif // DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_THREADPOOL
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/acl_utils.hpp ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Arm Ltd. and affiliates
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 CPU_AARCH64_ACL_UTILS_HPP
18
+ #define CPU_AARCH64_ACL_UTILS_HPP
19
+
20
+ #include <mutex>
21
+
22
+ #include "oneapi/dnnl/dnnl_types.h"
23
+
24
+ #include "common/dnnl_thread.hpp"
25
+ #include "common/memory_tracking.hpp"
26
+ #include "common/primitive.hpp"
27
+ #include "common/resource.hpp"
28
+ #include "common/utils.hpp"
29
+
30
+ #include "arm_compute/runtime/NEON/NEFunctions.h"
31
+ #include "arm_compute/runtime/Scheduler.h"
32
+
33
+ namespace dnnl {
34
+ namespace impl {
35
+ namespace cpu {
36
+ namespace aarch64 {
37
+
38
+ namespace acl_utils {
39
+
40
+ arm_compute::DataType get_acl_data_t(
41
+ const dnnl_data_type_t dt, const bool is_quantized = false);
42
+
43
+ // Convert alg_kind_t, alpha and beta into an ACL ActivationLayerInfo. Will
44
+ // return unimplemented and a disabled ActivationLayerInfo if the conversion
45
+ // fails
46
+ status_t convert_to_acl_act(alg_kind_t eltwise_alg, float alpha, float beta,
47
+ arm_compute::ActivationLayerInfo &act_info);
48
+
49
+ // Convert an eltwise_desc_t into an ACL ActivationLayerInfo. Will return
50
+ // unimplemented and a disabled ActivationLayerInfo if the conversion fails
51
+ status_t convert_to_acl_act(
52
+ const eltwise_desc_t &ed, arm_compute::ActivationLayerInfo &act_info);
53
+
54
+ // Convert an eltwise post op into an ACL ActivationLayerInfo. Will return
55
+ // unimplemented and a disabled ActivationLayerInfo if the conversion fails
56
+ status_t convert_to_acl_act(const post_ops_t::entry_t::eltwise_t &elt,
57
+ arm_compute::ActivationLayerInfo &act_info);
58
+
59
+ // Convert a memory desc to an arm_compute::TensorInfo. Note that memory desc
60
+ // must be blocking format, plain, dense and have no zero dimensions.
61
+ status_t tensor_info(arm_compute::TensorInfo &info, const memory_desc_t &md);
62
+ status_t tensor_info(
63
+ arm_compute::TensorInfo &info, const memory_desc_wrapper &md);
64
+
65
+ // Insert a dimension of size 1 at the index dim_i of TensorInfo
66
+ status_t insert_singleton_dimension(arm_compute::TensorInfo &ti, size_t dim_i);
67
+
68
+ // Reorder the logical dimensions of the memory descriptors (mds) by stride so
69
+ // that accessing the tensor elements in the natural order is dense. Note, this
70
+ // does not reorder the data, it just reorders the logical indices. The
71
+ // permutation is common to all mds, so the function returns when it cannot find
72
+ // a dimension with a common smallest stride. Returns the number of dimensions
73
+ // that we managed to reorder to be dense.
74
+ int reorder_dimensions_by_stride(std::vector<memory_desc_t *> permuted_mds,
75
+ std::vector<const memory_desc_t *> mds);
76
+
77
+ // Reorder a memory_desc_t and set the strides on a arm_compute::TensorInfo to
78
+ // match an arm_compute::WeightFormat. You are required to specify how various
79
+ // logical dimensions in oneDNN correspond to logical dimensions in arm_compute.
80
+ // info TensorInfo where the strides will be changed to match the reordering
81
+ // md memory descriptor where the stride and padded dimensions will be
82
+ // changed or reordering
83
+ // wf Describes the memory format/layout of the weights
84
+ // I_dim The logical dimension of md corresponding to the input channel of
85
+ // a convolution or the K dimension in a matmul
86
+ // O_dim The logical dimension of md corresponding to the output channel of a
87
+ //   convolution or the N dimension in a matmul
88
+ // spatial_dims The logical dimensions of md corresponding to the spatial
89
+ // dimensions of the weights (H, W, D for example). These will be
90
+ // the next densest after the inner blocks and the input channel.
91
+ // batch_dims The logical dimensions of md related to the batch in a batched
92
+ // matmul, ordered from innermost to outermost. ACL calls these
93
+ // the multi_stride_b. These will become the outermost (least dense)
94
+ // dimensions and will be collapsed.
95
+ void reorder_to_weight_format(arm_compute::TensorInfo &info, memory_desc_t &md,
96
+ arm_compute::WeightFormat wf, dim_t I_dim, dim_t O_dim,
97
+ std::vector<dim_t> spatial_dims, std::vector<dim_t> batch_dims = {});
98
+
99
+ // Logs a custom 'info' line describing an unsupported case
100
+ #define LOG_ACL_UNSUPPORTED(msg) \
101
+ do { \
102
+ if (verbose_has_create_dispatch()) \
103
+ printf("onednn_verbose,cpu,acl,unsupported: %s\n", (msg)); \
104
+ } while (0)
105
+
106
+ // Returns unimplemented if error code x is NOT OK
107
+ #define ACL_CHECK_VALID(x) \
108
+ do { \
109
+ arm_compute::Status s = x; \
110
+ if (s.error_code() != arm_compute::ErrorCode::OK) { \
111
+ LOG_ACL_UNSUPPORTED(s.error_description().c_str()); \
112
+ return dnnl::impl::status::unimplemented; \
113
+ } \
114
+ } while (0)
115
+
116
+ // Returns unimplemented on condition x == true
117
+ #define ACL_CHECK_SUPPORT(x, msg) \
118
+ do { \
119
+ if (x) { \
120
+ LOG_ACL_UNSUPPORTED(msg); \
121
+ return dnnl::impl::status::unimplemented; \
122
+ } \
123
+ } while (0)
124
+
125
+ } // namespace acl_utils
126
+
127
+ } // namespace aarch64
128
+ } // namespace cpu
129
+ } // namespace impl
130
+ } // namespace dnnl
131
+
132
+ #endif // CPU_AARCH64_ACL_UTILS_HPP
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/cpu_barrier.hpp ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2021 Intel Corporation
3
+ * Copyright 2020-2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_CPU_BARRIER_HPP
19
+ #define CPU_AARCH64_CPU_BARRIER_HPP
20
+
21
+ #include <assert.h>
22
+
23
+ #include "common/utils.hpp"
24
+ #include "cpu/aarch64/jit_generator.hpp"
25
+
26
+ namespace dnnl {
27
+ namespace impl {
28
+ namespace cpu {
29
+ namespace aarch64 {
30
+
31
+ namespace simple_barrier {
32
+
33
+ #define CTX_ALIGNMENT 4096
34
+
35
+ STRUCT_ALIGN(
36
+ CTX_ALIGNMENT, struct ctx_t {
37
+ enum { CACHE_LINE_SIZE = 256 };
38
+ volatile size_t ctr;
39
+ char pad1[CACHE_LINE_SIZE - 1 * sizeof(size_t)];
40
+ volatile size_t sense;
41
+ char pad2[CACHE_LINE_SIZE - 1 * sizeof(size_t)];
42
+ });
43
+
44
+ /* TODO: remove ctx_64_t once batch normalization switches to barrier-less
45
+ * implementation.
46
+ * Different alignments of context structure affect performance differently for
47
+ * convolution and batch normalization. Convolution performance becomes more
48
+ * stable with page alignment compared to cache line size alignment.
49
+ * Batch normalization (that creates C / simd_w barriers) degrades with page
50
+ * alignment due to significant overhead of ctx_init in case of mb=1. */
51
+ STRUCT_ALIGN(
52
+ 256, struct ctx_64_t {
53
+ enum { CACHE_LINE_SIZE = 256 };
54
+ volatile size_t ctr;
55
+ char pad1[CACHE_LINE_SIZE - 1 * sizeof(size_t)];
56
+ volatile size_t sense;
57
+ char pad2[CACHE_LINE_SIZE - 1 * sizeof(size_t)];
58
+ });
59
+
60
+ template <typename ctx_t>
61
+ inline void ctx_init(ctx_t *ctx) {
62
+ *ctx = utils::zero<ctx_t>();
63
+ }
64
+ void barrier(ctx_t *ctx, int nthr);
65
+
66
+ /** injects actual barrier implementation into another jitted code
67
+ * @params:
68
+ * code -- jit_generator object where the barrier is to be injected
69
+ * reg_ctx -- read-only register with pointer to the barrier context
70
+ * reg_nnthr -- read-only register with the # of synchronizing threads
71
+ */
72
+ void generate(jit_generator &code, Xbyak_aarch64::XReg reg_ctx,
73
+ Xbyak_aarch64::XReg reg_nthr, bool usedAsFunc = false);
74
+
75
+ } // namespace simple_barrier
76
+
77
+ } // namespace aarch64
78
+ } // namespace cpu
79
+ } // namespace impl
80
+ } // namespace dnnl
81
+
82
+ #endif
83
+
84
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/cpu_isa_traits.hpp ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2018-2023 Intel Corporation
3
+ * Copyright 2020-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_CPU_ISA_TRAITS_HPP
19
+ #define CPU_AARCH64_CPU_ISA_TRAITS_HPP
20
+
21
+ #include <type_traits>
22
+
23
+ #include "dnnl_types.h"
24
+
25
+ #include "common/dnnl_thread.hpp"
26
+ #include "common/utils.hpp"
27
+
28
+ /* in order to make selinux happy memory that would be marked with X-bit should
29
+ * be obtained with mmap */
30
+ #if !defined(_WIN32)
31
+ #define XBYAK_USE_MMAP_ALLOCATOR
32
+ #endif
33
+
34
+ #include "cpu/aarch64/xbyak_aarch64/xbyak_aarch64/xbyak_aarch64.h"
35
+ #include "cpu/aarch64/xbyak_aarch64/xbyak_aarch64/xbyak_aarch64_util.h"
36
+
37
+ namespace dnnl {
38
+ namespace impl {
39
+ namespace cpu {
40
+ namespace aarch64 {
41
+
42
+ /* The following enum is temporal implementation.
43
+ It should be made in dnnl_types.h,
44
+ but an RFC is requird to modify dnnl_types.h.
45
+ The following values are used with
46
+ static_cast<dnnl_cpu_isa_t>, the same values
47
+ defined in dnnl_cpu_isa_t are temporaly used. */
48
+ /// CPU instruction set flags
49
+ enum {
50
+ /// AARCH64 Advanced SIMD & floating-point
51
+ dnnl_cpu_isa_asimd = 0x1,
52
+ /// AARCH64 SVE 128 bits
53
+ dnnl_cpu_isa_sve_128 = 0x3,
54
+ /// AARCH64 SVE 256 bits
55
+ dnnl_cpu_isa_sve_256 = 0x7,
56
+ /// AARCH64 SVE 384 bits
57
+ dnnl_cpu_isa_sve_384 = 0xf,
58
+ /// AARCH64 SVE 512 bits
59
+ dnnl_cpu_isa_sve_512 = 0x27,
60
+ };
61
+
62
+ enum cpu_isa_bit_t : unsigned {
63
+ asimd_bit = 1u << 0,
64
+ sve_128_bit = 1u << 1,
65
+ sve_256_bit = 1u << 2,
66
+ sve_384_bit = 1u << 3,
67
+ sve_512_bit = 1u << 4,
68
+ };
69
+
70
+ enum cpu_isa_t : unsigned {
71
+ isa_undef = 0u,
72
+ asimd = asimd_bit,
73
+ sve_128 = sve_128_bit | asimd,
74
+ sve_256 = sve_256_bit | sve_128,
75
+ sve_384 = sve_384_bit | sve_256,
76
+ sve_512 = sve_512_bit | sve_384,
77
+ isa_all = ~0u,
78
+ };
79
+
80
+ enum class cpu_isa_cmp_t {
81
+ // List of infix comparison relations between two cpu_isa_t
82
+ // where we take isa_1 and isa_2 to be two cpu_isa_t instances.
83
+
84
+ // isa_1 SUBSET isa_2 if all feature flags supported by isa_1
85
+ // are supported by isa_2 as well (equality allowed)
86
+ SUBSET,
87
+
88
+ // isa_1 SUPERSET isa_2 if all feature flags supported by isa_2
89
+ // are supported by isa_1 as well (equality allowed)
90
+ SUPERSET,
91
+
92
+ // Few more options that (depending upon need) can be enabled in future
93
+
94
+ // 1. PROPER_SUBSET: isa_1 SUBSET isa_2 and isa_1 != isa_2
95
+ // 2. PROPER_SUPERSET: isa_1 SUPERSET isa_2 and isa_1 != isa_2
96
+ };
97
+
98
+ const char *get_isa_info();
99
+
100
+ cpu_isa_t get_max_cpu_isa();
101
+ cpu_isa_t DNNL_API get_max_cpu_isa_mask(bool soft = false);
102
+ status_t set_max_cpu_isa(dnnl_cpu_isa_t isa);
103
+ dnnl_cpu_isa_t get_effective_cpu_isa();
104
+
105
+ static inline bool compare_isa(
106
+ cpu_isa_t isa_1, cpu_isa_cmp_t cmp, cpu_isa_t isa_2) {
107
+ // By default, comparison between ISA ignores ISA specific hints
108
+ unsigned mask_1 = static_cast<unsigned>(isa_1);
109
+ unsigned mask_2 = static_cast<unsigned>(isa_2);
110
+ unsigned mask_common = mask_1 & mask_2;
111
+
112
+ switch (cmp) {
113
+ case cpu_isa_cmp_t::SUBSET: return mask_1 == mask_common;
114
+ case cpu_isa_cmp_t::SUPERSET: return mask_2 == mask_common;
115
+ default: assert(!"unsupported comparison of isa"); return false;
116
+ }
117
+ }
118
+
119
+ static inline bool is_subset(cpu_isa_t isa_1, cpu_isa_t isa_2) {
120
+ return compare_isa(isa_1, cpu_isa_cmp_t::SUBSET, isa_2);
121
+ }
122
+
123
+ static inline bool is_superset(cpu_isa_t isa_1, cpu_isa_t isa_2) {
124
+ return compare_isa(isa_1, cpu_isa_cmp_t::SUPERSET, isa_2);
125
+ }
126
+
127
+ template <cpu_isa_t>
128
+ struct cpu_isa_traits {}; /* ::vlen -> 32 (for avx2) */
129
+
130
+ template <>
131
+ struct cpu_isa_traits<isa_all> {
132
+ static constexpr dnnl_cpu_isa_t user_option_val = dnnl_cpu_isa_default;
133
+ static constexpr const char *user_option_env = "default";
134
+ };
135
+
136
+ template <>
137
+ struct cpu_isa_traits<asimd> {
138
+ typedef Xbyak_aarch64::VReg TReg;
139
+ typedef Xbyak_aarch64::VReg16B TRegB;
140
+ typedef Xbyak_aarch64::VReg8H TRegH;
141
+ typedef Xbyak_aarch64::VReg4S TRegS;
142
+ typedef Xbyak_aarch64::VReg2D TRegD;
143
+ static constexpr int vlen_shift = 4;
144
+ static constexpr int vlen = 16;
145
+ static constexpr int n_vregs = 32;
146
+ static constexpr dnnl_cpu_isa_t user_option_val
147
+ = static_cast<dnnl_cpu_isa_t>(dnnl_cpu_isa_asimd);
148
+ static constexpr const char *user_option_env = "advanced_simd";
149
+ };
150
+
151
+ #define CPU_ISA_SVE(bits, shift) \
152
+ template <> \
153
+ struct cpu_isa_traits<sve_##bits> { \
154
+ typedef Xbyak_aarch64::ZReg TReg; \
155
+ typedef Xbyak_aarch64::ZRegB TRegB; \
156
+ typedef Xbyak_aarch64::ZRegH TRegH; \
157
+ typedef Xbyak_aarch64::ZRegS TRegS; \
158
+ typedef Xbyak_aarch64::ZRegD TRegD; \
159
+ static constexpr int vlen_shift = shift; \
160
+ static constexpr int vlen = bits / 8; \
161
+ static constexpr int n_vregs = 32; \
162
+ static constexpr dnnl_cpu_isa_t user_option_val \
163
+ = static_cast<dnnl_cpu_isa_t>(dnnl_cpu_isa_sve_##bits); \
164
+ static constexpr const char *user_option_env = "sve_ ## bits"; \
165
+ };
166
+
167
+ CPU_ISA_SVE(128, 4)
168
+ CPU_ISA_SVE(256, 5)
169
+ CPU_ISA_SVE(512, 6)
170
+ #undef CPU_ISA_SVE
171
+
172
+ inline const Xbyak_aarch64::util::Cpu &cpu() {
173
+ const static Xbyak_aarch64::util::Cpu cpu_;
174
+ return cpu_;
175
+ }
176
+
177
+ namespace {
178
+
179
+ static inline bool mayiuse(const cpu_isa_t cpu_isa, bool soft = false) {
180
+ using namespace Xbyak_aarch64::util;
181
+
182
+ unsigned cpu_isa_mask = aarch64::get_max_cpu_isa_mask(soft);
183
+ if ((cpu_isa_mask & cpu_isa) != cpu_isa) return false;
184
+
185
+ switch (cpu_isa) {
186
+ case asimd: return cpu().has(XBYAK_AARCH64_HWCAP_ADVSIMD);
187
+ case sve_128:
188
+ return cpu().has(XBYAK_AARCH64_HWCAP_SVE)
189
+ && cpu().getSveLen() >= SVE_128;
190
+ case sve_256:
191
+ return cpu().has(XBYAK_AARCH64_HWCAP_SVE)
192
+ && cpu().getSveLen() >= SVE_256;
193
+ case sve_384:
194
+ return cpu().has(XBYAK_AARCH64_HWCAP_SVE)
195
+ && cpu().getSveLen() >= SVE_384;
196
+ case sve_512:
197
+ return cpu().has(XBYAK_AARCH64_HWCAP_SVE)
198
+ && cpu().getSveLen() >= SVE_512;
199
+ case isa_undef: return true;
200
+ case isa_all: return false;
201
+ }
202
+ return false;
203
+ }
204
+
205
+ static inline uint64_t get_sve_length() {
206
+ return cpu().getSveLen();
207
+ }
208
+
209
+ static inline bool mayiuse_atomic() {
210
+ using namespace Xbyak_aarch64::util;
211
+ return cpu().isAtomicSupported();
212
+ }
213
+
214
+ inline bool isa_has_bf16(cpu_isa_t isa) {
215
+ return false;
216
+ }
217
+
218
+ } // namespace
219
+
220
+ /* whatever is required to generate string literals... */
221
+ #include "common/z_magic.hpp"
222
+ /* clang-format off */
223
+ #define JIT_IMPL_NAME_HELPER(prefix, isa, suffix_if_any) \
224
+ ((isa) == isa_undef ? prefix STRINGIFY(any) : \
225
+ ((isa) == asimd ? prefix STRINGIFY(asimd) : \
226
+ ((isa) == sve_128 ? prefix STRINGIFY(sve_128) : \
227
+ ((isa) == sve_256 ? prefix STRINGIFY(sve_256) : \
228
+ ((isa) == sve_512 ? prefix STRINGIFY(sve_512) : \
229
+ prefix suffix_if_any)))))
230
+ /* clang-format on */
231
+
232
+ } // namespace aarch64
233
+ } // namespace cpu
234
+ } // namespace impl
235
+ } // namespace dnnl
236
+
237
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/cpu_reducer.hpp ADDED
@@ -0,0 +1,357 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2021 Intel Corporation
3
+ * Copyright 2020-2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_CPU_REDUCER_HPP
19
+ #define CPU_AARCH64_CPU_REDUCER_HPP
20
+
21
+ #include <assert.h>
22
+
23
+ #include "common/c_types_map.hpp"
24
+ #include "common/dnnl_thread.hpp"
25
+ #include "common/memory_tracking.hpp"
26
+ #include "common/nstl.hpp"
27
+ #include "common/type_helpers.hpp"
28
+ #include "common/utils.hpp"
29
+ #include "dnnl_types.h"
30
+
31
+ #include "cpu/aarch64/cpu_barrier.hpp"
32
+
33
+ namespace dnnl {
34
+ namespace impl {
35
+ namespace cpu {
36
+ namespace aarch64 {
37
+
38
+ /** class to perform balancing over 3D array
39
+ *
40
+ * Conceptually the reduction happens according to the picture below:
41
+ *
42
+ * <--job_size->
43
+ * +-----------+ +-----------+ +-----------+ ^
44
+ * | | | | | | |
45
+ * | | | | | | |
46
+ * | 1 | | 2 | . . . | njobs | | reduction_size
47
+ * | | | | | | |
48
+ * | | | | | | |
49
+ * +-----------+ +-----------+ +-----------+ v
50
+ *
51
+ * | | | | | | | | |
52
+ * v v v v v v v v v
53
+ * ===================================================== vertical reduction
54
+ *
55
+ * +-----------+ +-----------+ . . . +-----------+ result
56
+ *
57
+ * In a simple case the result must be contiguous in memory.
58
+ * @class cpu_reducer_t is an implementation.
59
+ *
60
+ * Threads are divided into groups. The groups are independent of each other.
61
+ * Each group may work on several jobs (the distribution is not uniform, since
62
+ * njobs might be not a multiple of groups). Threads within a group work on
63
+ * different parts of the reduction dimension. Thread 0 in each group is called
64
+ * master (@sa reduce_balancer_t::master()).
65
+ *
66
+ * If threading driver does not allow sync between sub-group of threads (e.g.
67
+ * TBB) the # of thread per group is enforced to be 1.
68
+ */
69
+ struct reduce_balancer_t {
70
+ reduce_balancer_t() { init(1, 1, 1, 1, 0); } /* trivial balance */
71
+ reduce_balancer_t(int nthr, int job_size, int njobs, int reduction_size,
72
+ size_t max_buffer_size, bool lock_free = false) {
73
+ init(nthr, job_size, njobs, reduction_size, max_buffer_size, lock_free);
74
+ }
75
+
76
+ reduce_balancer_t &init(int nthr, int job_size, int njobs,
77
+ int reduction_size, size_t max_buffer_size,
78
+ bool lock_free = false) {
79
+ allow_nthr_in_group_ = lock_free ? true : dnnl_thr_syncable();
80
+ nthr_ = nthr;
81
+ job_size_ = job_size;
82
+ njobs_ = njobs;
83
+ reduction_size_ = reduction_size;
84
+ max_buffer_size_ = max_buffer_size;
85
+ balance();
86
+ return *this;
87
+ }
88
+
89
+ bool allow_nthr_in_group_;
90
+ int nthr_;
91
+ int job_size_, njobs_, reduction_size_;
92
+
93
+ int ngroups_; /** number of independent work (thread) groups */
94
+ int nthr_per_group_; /** number of threads within a single work group */
95
+ int njobs_per_group_ub_; /** the max # of jobs within a work group */
96
+
97
+ bool master(int ithr) const { return id_in_group(ithr) == 0; }
98
+ bool idle(int ithr) const { return ithr >= nthr_per_group_ * ngroups_; }
99
+
100
+ int group_id(int ithr) const { return ithr / nthr_per_group_; }
101
+ int id_in_group(int ithr) const { return ithr % nthr_per_group_; }
102
+
103
+ int grp_njobs(int grp) const {
104
+ if (grp >= ngroups_) return 0;
105
+ return njobs_ / ngroups_ + (grp < njobs_ % ngroups_);
106
+ }
107
+ int grp_job_off(int grp) const {
108
+ if (grp >= ngroups_) return njobs_;
109
+ return njobs_ / ngroups_ * grp + nstl::min(grp, njobs_ % ngroups_);
110
+ }
111
+
112
+ int ithr_njobs(int ithr) const { return grp_njobs(group_id(ithr)); }
113
+ int ithr_job_off(int ithr) const { return grp_job_off(group_id(ithr)); }
114
+
115
+ private:
116
+ size_t max_buffer_size_;
117
+ void balance();
118
+ };
119
+
120
+ /** forward declaration of reduce driver */
121
+ template <impl::data_type_t data_type>
122
+ struct reducer_2d_driver_t;
123
+
124
+ /** class to perform a reduction over 3D array
125
+ *
126
+ * Balancing is based on @class reduce_balancer_t.
127
+ * Restrictions: the result of the reduction must be contiguous in memory. *
128
+ * The reduction happens according to the picture below (once more):
129
+ *
130
+ * <--job_size->
131
+ * +-----------+ +-----------+ +-----------+ ^
132
+ * | | | | | | |
133
+ * | | | | | | |
134
+ * | 1 | | 2 | . . . | njobs | | reduction_size
135
+ * | | | | | | |
136
+ * | | | | | | |
137
+ * +-----------+ +-----------+ +-----------+ v
138
+ *
139
+ * | | | | | | | | |
140
+ * v v v v v v v v v
141
+ * ===================================================== vertical reduction
142
+ *
143
+ * +-----------+ +-----------+ . . . +-----------+ (contiguous) result
144
+ *
145
+ * An example how work might be shared is shown below.
146
+ *
147
+ * In this example group 0 owns 2 (independent) jobs -- 2 big squares.
148
+ * The number of threads per group is also 2 (thread 0 of group 0 and thread 1
149
+ * of group 0). Master threads (i.e. threads with id 0 in corresponding group)
150
+ * from each group put the partial result directly into destination memory,
151
+ * while all the other threads with-in the group use workspace (on the picture
152
+ * the only thread 1). Once intermediate results obtained each group reduces
153
+ * corresponding part (own jobs) to the destination memory.
154
+ *
155
+ * <------- group 0 ------->
156
+ *
157
+ * +-----------+ +-----------+ ^
158
+ * | | | | | thread 0 of reduces to the dest-memory
159
+ * | | | | | group 0 +-----------+ +-----------+
160
+ * |- - - - - -| |- - - - - -| X
161
+ * | | | | | thread 1 of reduces to workspace[tid=1]:
162
+ * | | | | | group 0 +-----------+ +-----------+
163
+ * +-----------+ +-----------+ v
164
+ * | | | | | |
165
+ * v v v v v v
166
+ * ((barrier)) =============================
167
+ *
168
+ * dest-memory: +-----------+ +-----------+
169
+ */
170
+ template <impl::data_type_t data_type>
171
+ struct cpu_reducer_t {
172
+ typedef typename prec_traits<data_type>::type data_t;
173
+
174
+ struct conf_t {
175
+ conf_t() = default;
176
+ conf_t &init(const reduce_balancer_t &balancer) {
177
+ balancer_ = balancer;
178
+ return *this;
179
+ }
180
+
181
+ void init_scratchpad(memory_tracking::registrar_t &scratchpad) const;
182
+
183
+ reduce_balancer_t balancer_;
184
+ };
185
+
186
+ status_t create_kernel();
187
+
188
+ cpu_reducer_t(const conf_t &conf);
189
+ ~cpu_reducer_t();
190
+
191
+ /** initializes reducer.
192
+ * Must be called from a single thread prior to actual usage */
193
+ void init(const memory_tracking::grantor_t &scratchpad) const {
194
+ if (balancer().nthr_per_group_ == 1 || !dnnl_thr_syncable()) return;
195
+
196
+ auto bctx = scratchpad.template get<simple_barrier::ctx_t>(
197
+ memory_tracking::names::key_reducer_space_bctx);
198
+ for (int i = 0; i < balancer().ngroups_; ++i)
199
+ simple_barrier::ctx_init(&bctx[i]);
200
+ }
201
+
202
+ /** for given thread returns the pointer where to put partial results.
203
+ * Reduction destination @p dst must be provided as well (master threads
204
+ * from each group will use it for partial result to reduce memory
205
+ * pressure).
206
+ *
207
+ * @note: job offset is already applied by get_local_ptr(), which means all
208
+ * threads should start writing from the very beginning of returned
209
+ * address.
210
+ */
211
+ data_t *get_local_ptr(int ithr, data_t *dst,
212
+ const memory_tracking::grantor_t &scratchpad) const;
213
+
214
+ /** performs the reduction with built-in synchronization. */
215
+ void reduce(int ithr, data_t *dst,
216
+ const memory_tracking::grantor_t &scratchpad) const {
217
+ bool redundant_reduction
218
+ = balancer().nthr_per_group_ == 1 || balancer().idle(ithr);
219
+ if (redundant_reduction) return;
220
+
221
+ auto bctx = scratchpad.template get<simple_barrier::ctx_t>(
222
+ memory_tracking::names::key_reducer_space_bctx);
223
+ simple_barrier::barrier(
224
+ &bctx[balancer().group_id(ithr)], balancer().nthr_per_group_);
225
+
226
+ reduce_nolock(ithr, dst, scratchpad);
227
+ }
228
+
229
+ void reduce_nolock(int ithr, data_t *dst,
230
+ const memory_tracking::grantor_t &scratchpad) const;
231
+
232
+ const reduce_balancer_t &balancer() const { return conf_.balancer_; }
233
+
234
+ private:
235
+ static size_t space_per_thread(const reduce_balancer_t &balancer) {
236
+ return balancer.njobs_per_group_ub_ * balancer.job_size_;
237
+ }
238
+
239
+ /* The scratchpad is organized as follows:
240
+ *
241
+ * data_t space[nthr_][njobs_per_group_ub_][jobs_size_];
242
+ * simple_barrier::ctx_t barriers[groups_]; */
243
+
244
+ const conf_t conf_;
245
+ reducer_2d_driver_t<data_type> *drv_;
246
+
247
+ DNNL_DISALLOW_COPY_AND_ASSIGN(cpu_reducer_t);
248
+ };
249
+
250
+ template <impl::data_type_t data_type>
251
+ struct cpu_reducer_2d_t {
252
+ typedef typename prec_traits<data_type>::type data_t;
253
+
254
+ struct conf_t {
255
+ conf_t() = default;
256
+ conf_t &init(const reduce_balancer_t &balancer, int job_size_x,
257
+ int job_size_y, int x_block, int dst_x, int dst_y) {
258
+ balancer_ = balancer;
259
+ job_size_x_ = job_size_x;
260
+ job_size_y_ = job_size_y;
261
+ x_block_ = x_block;
262
+ dst_x_ = dst_x;
263
+ dst_y_ = dst_y;
264
+ return *this;
265
+ }
266
+
267
+ void init_scratchpad(memory_tracking::registrar_t &scratchpad) const;
268
+
269
+ reduce_balancer_t balancer_;
270
+ int job_size_x_, job_size_y_, x_block_, dst_x_, dst_y_;
271
+ };
272
+
273
+ status_t create_kernel();
274
+
275
+ cpu_reducer_2d_t(const conf_t &conf);
276
+ ~cpu_reducer_2d_t();
277
+
278
+ /** initializes reducer.
279
+ * Must be called from a single thread prior to actual usage */
280
+ void init(const memory_tracking::grantor_t &scratchpad) const {
281
+ if (balancer().nthr_per_group_ == 1 || !dnnl_thr_syncable()) return;
282
+
283
+ auto bctx = scratchpad.template get<simple_barrier::ctx_t>(
284
+ memory_tracking::names::key_reducer_space_bctx);
285
+ for (int i = 0; i < balancer().ngroups_; ++i)
286
+ simple_barrier::ctx_init(&bctx[i]);
287
+ }
288
+
289
+ /** for given thread returns the pointer where to put partial results */
290
+ data_t *get_local_ptr(
291
+ int ithr, const memory_tracking::grantor_t &scratchpad) const;
292
+
293
+ /** performs the reduction with built-in synchronization. */
294
+ void reduce(int ithr, data_t *dst,
295
+ const memory_tracking::grantor_t &scratchpad) const {
296
+ bool redundant_reduction
297
+ = balancer().nthr_per_group_ == 1 || balancer().idle(ithr);
298
+ if (redundant_reduction) return;
299
+
300
+ auto bctx = scratchpad.template get<simple_barrier::ctx_t>(
301
+ memory_tracking::names::key_reducer_space_bctx);
302
+ simple_barrier::barrier(
303
+ &bctx[balancer().group_id(ithr)], balancer().nthr_per_group_);
304
+
305
+ reduce_nolock(ithr, dst, scratchpad);
306
+ }
307
+
308
+ void reduce_nolock(int ithr, data_t *dst,
309
+ const memory_tracking::grantor_t &scratchpad) const;
310
+
311
+ const reduce_balancer_t &balancer() const { return conf_.balancer_; }
312
+
313
+ private:
314
+ static size_t space_per_thread(const reduce_balancer_t &balancer) {
315
+ return balancer.njobs_per_group_ub_ * balancer.job_size_;
316
+ }
317
+
318
+ /* The scratchpad is organized as follows:
319
+ *
320
+ * data_t space[nthr_][njobs_per_group_ub_][jobs_size_];
321
+ * simple_barrier::ctx_t barriers[groups_]; */
322
+
323
+ const conf_t conf_;
324
+ reducer_2d_driver_t<data_type> *drv_;
325
+
326
+ int choose_x_blocking(int nx, int ny, int nthr_per_grp) const;
327
+ void reduce_block(const data_t *space_base, data_t *dst, int job,
328
+ int start_y, int start_x, int ny_start, int nx_start, int ny_step,
329
+ int nx_step) const;
330
+
331
+ DNNL_DISALLOW_COPY_AND_ASSIGN(cpu_reducer_2d_t);
332
+ };
333
+
334
+ /** simple 1d accumulator: y[:] += x[:] */
335
+ template <impl::data_type_t data_type>
336
+ struct cpu_accumulator_1d_t {
337
+ typedef typename prec_traits<data_type>::type data_t;
338
+
339
+ cpu_accumulator_1d_t();
340
+ ~cpu_accumulator_1d_t();
341
+ void accumulate(data_t *dst, const data_t *src, size_t size);
342
+
343
+ status_t create_kernel();
344
+
345
+ reducer_2d_driver_t<data_type> *drv_;
346
+
347
+ DNNL_DISALLOW_COPY_AND_ASSIGN(cpu_accumulator_1d_t);
348
+ };
349
+
350
+ } // namespace aarch64
351
+ } // namespace cpu
352
+ } // namespace impl
353
+ } // namespace dnnl
354
+
355
+ #endif
356
+
357
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/injector_utils.hpp ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2022 Intel Corporation
3
+ * Copyright 2021-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+ #ifndef CPU_AARCH64_JIT_INJECTOR_UTILS_HPP
18
+ #define CPU_AARCH64_JIT_INJECTOR_UTILS_HPP
19
+
20
+ #include <array>
21
+ #include <cstddef>
22
+ #include <set>
23
+ #include <stack>
24
+
25
+ #include "cpu/aarch64/jit_generator.hpp"
26
+
27
+ namespace dnnl {
28
+ namespace impl {
29
+ namespace cpu {
30
+ namespace aarch64 {
31
+ namespace injector_utils {
32
+
33
+ using vmm_index_set_t = typename std::set<size_t>;
34
+ using vmm_index_set_iterator_t = typename std::set<size_t>::iterator;
35
+ template <cpu_isa_t isa>
36
+ struct vmm_size_t;
37
+
38
+ template <>
39
+ struct vmm_size_t<sve_512> {
40
+ static constexpr std::size_t bytes = 64u;
41
+ };
42
+
43
+ /*
44
+ template <>
45
+ struct vmm_size_t<sve_256> {
46
+ static constexpr std::size_t bytes = 32u;
47
+ };
48
+
49
+ template <>
50
+ struct vmm_size_t<sve_128> {
51
+ static constexpr std::size_t bytes = 16u;
52
+ };*/
53
+
54
+ enum class layout_t { ncsp, c_blocked, nspc, cspn, unsupported };
55
+
56
+ inline layout_t get_layout_type(const memory_desc_wrapper &dst_d) {
57
+ const auto strides = dst_d.blocking_desc().strides;
58
+ if (!dst_d.is_plain()) return layout_t::c_blocked;
59
+ if (strides[0] >= strides[1]
60
+ && IMPLICATION(dst_d.ndims() >= 3, strides[1] >= strides[2]))
61
+ return layout_t::ncsp;
62
+ if (strides[1] == 1) return layout_t::nspc;
63
+ if (strides[0] == 1) return layout_t::cspn;
64
+ return layout_t::unsupported;
65
+ }
66
+
67
+ /*
68
+ * Scope guard for general purpose register and vector registers preservation.
69
+ * Pushes registers to stack during construction and pops during destruction.
70
+ */
71
+ template <cpu_isa_t isa>
72
+ class register_preserve_guard_t {
73
+
74
+ public:
75
+ register_preserve_guard_t(jit_generator *host,
76
+ std::initializer_list<Xbyak_aarch64::XReg> reg64_to_preserve,
77
+ std::initializer_list<Xbyak_aarch64::VReg> vmm_to_preserve = {});
78
+ register_preserve_guard_t(register_preserve_guard_t &&other) = default;
79
+ register_preserve_guard_t &operator=(register_preserve_guard_t &&other)
80
+ = default;
81
+ DNNL_DISALLOW_COPY_AND_ASSIGN(register_preserve_guard_t);
82
+ ~register_preserve_guard_t();
83
+ size_t calc_vmm_to_preserve_size_bytes(
84
+ const std::initializer_list<Xbyak_aarch64::VReg> &vmm_to_preserve)
85
+ const;
86
+ size_t stack_space_occupied() const;
87
+
88
+ private:
89
+ jit_generator *host_;
90
+ std::stack<Xbyak_aarch64::XReg> reg64_stack_;
91
+ std::stack<Xbyak_aarch64::VReg> vmm_stack_;
92
+ const uint64_t cpu_sveLen_ = get_sve_length();
93
+ size_t vmm_to_preserve_size_bytes_;
94
+ };
95
+
96
+ template <cpu_isa_t isa>
97
+ class conditional_register_preserve_guard_t
98
+ : public register_preserve_guard_t<isa> {
99
+ public:
100
+ conditional_register_preserve_guard_t(bool condition_to_be_met,
101
+ jit_generator *host,
102
+ std::initializer_list<Xbyak_aarch64::XReg> reg64_to_preserve,
103
+ std::initializer_list<Xbyak_aarch64::VReg> vmm_to_preserve = {});
104
+ DNNL_DISALLOW_COPY_AND_ASSIGN(conditional_register_preserve_guard_t);
105
+ };
106
+
107
+ } // namespace injector_utils
108
+ } // namespace aarch64
109
+ } // namespace cpu
110
+ } // namespace impl
111
+ } // namespace dnnl
112
+
113
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/jit_uni_binary_injector.hpp ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2023 Intel Corporation
3
+ * Copyright 2022-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_BINARY_INJECTOR_HPP
19
+ #define CPU_AARCH64_JIT_UNI_BINARY_INJECTOR_HPP
20
+
21
+ #include <array>
22
+ #include <cassert>
23
+ #include <functional>
24
+ #include <map>
25
+ #include <utility>
26
+ #include <vector>
27
+ #include <unordered_set>
28
+
29
+ #include "common/broadcast_strategy.hpp"
30
+ #include "common/c_types_map.hpp"
31
+ #include "common/primitive_attr.hpp"
32
+ #include "common/primitive_exec_types.hpp"
33
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
34
+ #include "cpu/aarch64/injectors/injector_utils.hpp"
35
+ #include "cpu/aarch64/jit_generator.hpp"
36
+ #include "cpu/binary_injector_utils.hpp"
37
+
38
+ namespace dnnl {
39
+ namespace impl {
40
+ namespace cpu {
41
+ namespace aarch64 {
42
+ namespace binary_injector {
43
+ using dnnl::impl::cpu::binary_injector_utils::prepare_binary_args;
44
+
45
+ bool binary_args_matches_tag(format_tag_t tag, const post_ops_t &post_ops);
46
+
47
+ bool binary_args_broadcast_supported(const post_ops_t &post_ops,
48
+ const memory_desc_wrapper &dst_d,
49
+ const bcast_set_t &supported_strategy_set);
50
+
51
+ bool binary_args_tail_supported(const post_ops_t &post_ops,
52
+ const memory_desc_wrapper &dst_d, int vlen,
53
+ const bcast_set_t &supported_strategy_set);
54
+
55
+ bool any_binary_postop_rhs_per_oc_broadcast(
56
+ const post_ops_t &post_ops, const memory_desc_wrapper &dst_d);
57
+ bool any_binary_postop_rhs_per_oc_broadcast(const post_ops_t &post_ops,
58
+ const memory_desc_wrapper &dst_d,
59
+ const bcast_set_t &supported_strategy_set);
60
+
61
+ bool all_binary_postop_rhs_per_oc_broadcast(const post_ops_t &post_ops,
62
+ const memory_desc_wrapper &dst_d,
63
+ const std::function<bool(const memory_desc_wrapper &)> &predicate);
64
+ bool all_binary_postop_rhs_per_oc_broadcast(const post_ops_t &post_ops,
65
+ const memory_desc_wrapper &dst_d,
66
+ const bcast_set_t &supported_strategy_set,
67
+ const std::function<bool(const memory_desc_wrapper &)> &predicate);
68
+
69
+ /*
70
+ * Represents params related to all binary post-ops right-hand side arguments
71
+ * (arg1) that don't change during jit_uni_binary_injector_t object lifetime
72
+ * and between compute_vector_range calls.
73
+ *
74
+ * @param rhs_dt_helper_vmm_idx - index of vmm helper used when loading data for
75
+ * calculations. Treated as hint from user. If inside compute_vector_range hint
76
+ * turns out to be invalid, it will be overwriten by register preserving logic inside
77
+ * binary injector.
78
+ * @param rhs_addr_reg - gpr register, used as the currently processed address of
79
+ * rhs tensor slice. Data of rhs(arg1) for the binary operation is loaded from address
80
+ * stored inside rhs_addr_reg.
81
+ * @param rhs_helper_reg - gpr register used as helper for calculations during data
82
+ * loading phase.
83
+ * @param rhs_addr_cache_reg - gpr register used for caching part of calculated
84
+ * offset, this register is always preserved.
85
+ * @param preserve_gpr_helpers - determines whether gpr registers specified above
86
+ * should be preserved (pushed to stack and poped back afterwords) between
87
+ * compute_vector_range calls.
88
+ * @param preserve_vmm_helper - determines whether vmm helper register specified
89
+ * above should be preserved between compute_vector_range calls.
90
+ * @param abi_param_offset - offset to rhs tensor from first binary post-op operation
91
+ * specified by user from runtime structure passed to kernel as abi param 1.
92
+ * @param dst_orig_offset - offset 0 to destination tensor
93
+ * @param dst_d - descriptor of destination tensor (result after applying all post-ops
94
+ * operations).
95
+ * @param tail_opmask - register with loaded by user mask, used in avx512 for load with
96
+ * tail handling.
97
+ * @param tail_size - size of processed tail in elements.
98
+ * @param use_exact_tail_scalar_bcast - in case of scalar broadcast user can disable
99
+ * loading data with tail, usually bcast through entire vector is faster (usually 1 instruction)
100
+ * vs. broadcasting limited by tail size (potentially several instructions). In case
101
+ * when user during storing ignores values from vmm above tail size, setting this option to
102
+ * false can result in better performance.
103
+ * @param reg_tail_size - register with loaded size of tail, used in sse41/avx/avx2
104
+ * for load with tail in runtime.
105
+ */
106
+ struct rhs_arg_static_params_t {
107
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
108
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
109
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
110
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
111
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
112
+ std::size_t abi_param_offset, const memory_desc_wrapper &dst_d,
113
+ std::size_t tail_size = 0u,
114
+ bool use_exact_tail_scalar_bcast = false);
115
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
116
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
117
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
118
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
119
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
120
+ std::size_t abi_param_offset, std::size_t dst_orig_offset,
121
+ const memory_desc_wrapper &dst_d, std::size_t tail_size = 0u,
122
+ bool use_exact_tail_scalar_bcast = false);
123
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
124
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
125
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
126
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
127
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
128
+ std::size_t abi_param_offset, const memory_desc_wrapper &dst_d,
129
+ std::size_t tail_size, const Xbyak_aarch64::PReg &tail_opmask,
130
+ bool use_exact_tail_scalar_bcast);
131
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
132
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
133
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
134
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
135
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
136
+ std::size_t abi_param_offset, std::size_t dst_orig_offset,
137
+ const memory_desc_wrapper &dst_d, std::size_t tail_size,
138
+ const Xbyak_aarch64::PReg &tail_opmask,
139
+ bool use_exact_tail_scalar_bcast);
140
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
141
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
142
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
143
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
144
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
145
+ std::size_t abi_param_offset, const memory_desc_wrapper &dst_d,
146
+ std::size_t tail_size, const Xbyak_aarch64::PReg &tail_opmask,
147
+ const Xbyak_aarch64::XReg &reg_tail_size,
148
+ bool use_exact_tail_scalar_bcast);
149
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
150
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
151
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
152
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
153
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
154
+ std::size_t abi_param_offset, std::size_t dst_orig_offset,
155
+ const memory_desc_wrapper &dst_d, std::size_t tail_size,
156
+ const Xbyak_aarch64::PReg &tail_opmask,
157
+ const Xbyak_aarch64::XReg &reg_tail_size,
158
+ bool use_exact_tail_scalar_bcast);
159
+
160
+ bool is_opmask_set() const noexcept { return is_opmask_set_; }
161
+ bool is_dst_orig_set() const noexcept { return is_dst_orig_set_; }
162
+
163
+ mutable std::size_t rhs_dt_helper_vmm_idx;
164
+ Xbyak_aarch64::XReg rhs_addr_reg;
165
+ Xbyak_aarch64::XReg rhs_helper_reg;
166
+ Xbyak_aarch64::XReg rhs_addr_cache_reg;
167
+ bool preserve_gpr_helpers;
168
+ bool preserve_vmm_helper;
169
+ std::size_t abi_param_offset;
170
+ std::size_t dst_orig_offset;
171
+ memory_desc_wrapper dst_d;
172
+ std::size_t tail_size;
173
+ Xbyak_aarch64::PReg tail_opmask;
174
+ bool use_exact_tail_scalar_bcast;
175
+ Xbyak_aarch64::XReg reg_tail_size;
176
+ bool is_tail;
177
+
178
+ private:
179
+ rhs_arg_static_params_t(std::size_t rhs_dt_helper_vmm_idx,
180
+ const Xbyak_aarch64::XReg &rhs_addr_reg,
181
+ const Xbyak_aarch64::XReg &rhs_helper_reg,
182
+ const Xbyak_aarch64::XReg &rhs_addr_cache_reg,
183
+ bool preserve_gpr_helpers, bool preserve_vmm_helper,
184
+ std::size_t abi_param_offset, std::size_t dst_orig_offset,
185
+ const memory_desc_wrapper &dst_d, std::size_t tail_size,
186
+ const Xbyak_aarch64::PReg &tail_opmask,
187
+ bool use_exact_tail_scalar_bcast,
188
+ const Xbyak_aarch64::XReg &reg_tail_size, bool is_opmask_set,
189
+ bool is_dst_orig_set);
190
+
191
+ bool is_opmask_set_;
192
+ bool is_dst_orig_set_;
193
+ };
194
+
195
+ /*
196
+ * Represents params required by jit_uni_binary_injector_t that don't change
197
+ * during it's entire lifetime.
198
+ *
199
+ * @param param1 - register storing abi param1. At the moment of calling
200
+ * compute_vector_range method can be different than the default one defined
201
+ * inside jit_generator.
202
+ * @param bcast_set_t supported_strategy_set - set allowing disabling particular
203
+ * bcast strategies
204
+ * @param rhs_arg_static_params - params related to all binary post-ops right-hand side
205
+ * arguments that don't change during entire lifetime of jit_uni_binary_injector_t
206
+ * object.
207
+ */
208
+ struct static_params_t {
209
+ static_params_t(const Xbyak_aarch64::XReg &param1,
210
+ const bcast_set_t &supported_strategy_set,
211
+ const rhs_arg_static_params_t &rhs_arg_static_params);
212
+ static_params_t(const Xbyak_aarch64::XReg &param1,
213
+ const rhs_arg_static_params_t &rhs_arg_static_params);
214
+
215
+ Xbyak_aarch64::XReg param1;
216
+ const bcast_set_t supported_strategy_set;
217
+ rhs_arg_static_params_t rhs_arg_static_params;
218
+ };
219
+
220
+ /*
221
+ * Mode of data load with tail for rhs:
222
+ * STATIC - load based on given integer.
223
+ * DYNAMIC - load based on opmask or 64-bit register.
224
+ * DEFAULT - DYNAMIC for avx512, STATIC for others.
225
+ */
226
+
227
+ enum class tail_lode_mode_t { STATIC, DYNAMIC, DEFAULT };
228
+
229
+ struct rhs_address_t {
230
+ Xbyak_aarch64::XReg base_;
231
+ int64_t offt_ = 0;
232
+ bool isBroadcast_ = false;
233
+ uint32_t bits_ = 0;
234
+
235
+ rhs_address_t(const Xbyak_aarch64::XReg &base, const int64_t offt = 0,
236
+ bool isBroadcast = false, const uint32_t bits = 0)
237
+ : base_(base), offt_(offt), isBroadcast_(isBroadcast), bits_(bits) {}
238
+
239
+ bool operator==(const rhs_address_t &rhs) const {
240
+ return getBit() == rhs.getBit()
241
+ && getBase().getIdx() == rhs.getBase().getIdx()
242
+ && isBroadcast_ == rhs.isBroadcast();
243
+ }
244
+ bool operator!=(const rhs_address_t &rhs) const { return !operator==(rhs); }
245
+
246
+ Xbyak_aarch64::XReg getBase() const { return base_; }
247
+ uint32_t getBit() const { return bits_; }
248
+ bool isBroadcast() const { return isBroadcast_; }
249
+ };
250
+
251
+ struct rhs_operand_t {
252
+
253
+ bool isAddress_ = false;
254
+ uint32_t idx_;
255
+ rhs_address_t address_;
256
+
257
+ bool operator==(const rhs_operand_t &rhs) const {
258
+ if (isAddress_) {
259
+ if (isAddress_ == rhs.isAddress_ && address_ == rhs.address_)
260
+ return true;
261
+ else
262
+ return false;
263
+ } else {
264
+ if (isAddress_ == rhs.isAddress_ && idx_ == rhs.idx_)
265
+ return true;
266
+ else
267
+ return false;
268
+ }
269
+ }
270
+
271
+ bool operator!=(const rhs_operand_t &rhs) const { return !operator==(rhs); }
272
+
273
+ bool isBroadcast() const { return isAddress_ && address_.isBroadcast(); }
274
+ };
275
+
276
+ /*
277
+ * Represents params passed to compute_vector_range method of
278
+ * jit_uni_binary_injector_t that can be different for each call.
279
+ * Contains configurable std::maps where key is vmm index and value is
280
+ * offset in elements. The offset value identifies tensor slice in particular
281
+ * vmm. This is utilized by broadcasting mechanism. Offset, depending on the
282
+ * implementation particular kernels, can be passed as value (usually during
283
+ * unrolling), inside operand, under memory address.
284
+ *
285
+ * @param vmm_idx_to_out_addr - vmm mapped to address of destination tensor with offset,
286
+ * used to calculate offset in no_broadcast strategy, but also in other strategies whose
287
+ * calculations are based on no_broadcast strategy.
288
+ * @param vmm_idx_to_out_reg - vmm mapped to register containing address of destination
289
+ * with offset, used to calculate offset in no_broadcast strategy, but also in other
290
+ * strategies whose calculations are based on no_broadcast strategy.
291
+ * @param vmm_idx_to_out_elem_off_addr - vmm mapped to offset in elements stored under
292
+ * memory address intended to use in no_broadcast strategy.
293
+ * @param vmm_idx_to_out_elem_off_addr - vmm mapped to offset in elements stored under
294
+ * memory address intended to use in no_broadcast strategy.
295
+ * @param vmm_idx_to_out_elem_off_val - vmm mapped to offset in elements passed as raw
296
+ * value intended to use in no_broadcast strategy
297
+ * @param vmm_idx_to_out_off_oprnd - vmm mapped to offset in elements inside operand
298
+ * intended to use in no_broadcast strategy
299
+ * @param vmm_idx_to_oc_elem_off_addr - vmm mapped to output channel offset in elements
300
+ * stored under memory address intended to use in per_oc broadcast strategies.
301
+ * @param vmm_idx_to_oc_elem_off_val - vmm mapped to output channel offset in elements
302
+ * passed as raw value intended to use in per_oc broadcast strategies.
303
+ * @param vmm_idx_to_oc_off_oprnd - vmm mapped to output channel offset in elements inside
304
+ * operand intended to use in per_oc broadcast strategies.
305
+ * @param vmm_idx_to_sp_elem_off_addr - vmm mapped to proper output spatial offset in
306
+ * elements stored under memory address intended to use in per_mb_spatial strategies.
307
+ * @param vmm_idx_to_sp_elem_off_val - vmm mapped to proper output spatial offset in
308
+ * elements passed as raw value intended to use in per_mb_spatial strategies.
309
+ * @param vmm_idx_to_sp_off_oprnd - vmm mapped to proper output spatial offset in
310
+ * elements inside operand intended to use in per_mb_spatial strategies.
311
+ * @param vmm_idx_to_mb_w_elem_off_addr - vmm mapped to proper output last dim
312
+ * per first dim offset in elements stored under memory address intended to use
313
+ * in per_mb_w strategies.
314
+ * @param vmm_idx_to_mb_w_elem_off_val - vmm mapped to proper output last dim
315
+ * per first dim offset in elements passed as raw value intended to use in
316
+ * per_mb_w strategies.
317
+ * @param vmm_idx_to_mb_w_off_oprnd - vmm mapped to proper output last dim
318
+ * per first dim offset in elements inside operand intended to use in per_mb_w
319
+ * strategies.
320
+ * @param vmm_idx_to_w_elem_off_addr - vmm mapped to proper output last dim
321
+ * offset in elements stored under memory address intended to use in per_w strategy.
322
+ * @param vmm_idx_to_w_elem_off_val - vmm mapped to proper output last dim
323
+ * offset in elements passed as raw value intended to use in per_w strategy.
324
+ * @param vmm_idx_to_w_off_oprnd - vmm mapped to proper output last dim offset
325
+ * in elements inside operand intended to use in per_w strategy.
326
+ * @param vmm_tail_idx - vmm indices that contains data don't fill the whole vector (tail).
327
+ * @param is_dynamic_tail_load - determines whether to load with tail in
328
+ * runtime (based on the value from reg_tail_size or opmask) or based on given
329
+ * integer.
330
+ */
331
+
332
+ struct rhs_arg_dynamic_params_t {
333
+ std::map<int, rhs_address_t> vmm_idx_to_out_addr;
334
+ std::map<int, Xbyak_aarch64::XReg> vmm_idx_to_out_reg;
335
+
336
+ std::map<int, rhs_address_t> vmm_idx_to_out_elem_off_addr;
337
+ std::map<int, size_t> vmm_idx_to_out_elem_off_val;
338
+ std::map<int, rhs_operand_t> vmm_idx_to_out_off_oprnd;
339
+
340
+ std::map<int, rhs_address_t> vmm_idx_to_oc_elem_off_addr;
341
+ std::map<int, size_t> vmm_idx_to_oc_elem_off_val;
342
+ std::map<int, rhs_operand_t> vmm_idx_to_oc_off_oprnd;
343
+
344
+ std::map<int, rhs_address_t> vmm_idx_to_sp_elem_off_addr;
345
+ std::map<int, size_t> vmm_idx_to_sp_elem_off_val;
346
+ std::map<int, rhs_operand_t> vmm_idx_to_sp_off_oprnd;
347
+
348
+ std::map<int, rhs_address_t> vmm_idx_to_mb_w_elem_off_addr;
349
+ std::map<int, size_t> vmm_idx_to_mb_w_elem_off_val;
350
+ std::map<int, rhs_operand_t> vmm_idx_to_mb_w_off_oprnd;
351
+
352
+ std::map<int, rhs_address_t> vmm_idx_to_w_elem_off_addr;
353
+ std::map<int, size_t> vmm_idx_to_w_elem_off_val;
354
+ std::map<int, rhs_operand_t> vmm_idx_to_w_off_oprnd;
355
+
356
+ std::unordered_set<int> vmm_tail_idx_;
357
+ tail_lode_mode_t tail_load_mode = tail_lode_mode_t::DEFAULT;
358
+ };
359
+
360
+ /*
361
+ * Checks if src1 data type is supported by binary injector.
362
+ */
363
+ bool is_data_supported(cpu_isa_t isa, data_type_t data_type);
364
+
365
+ /*
366
+ * Checks if broadcast of src1 is supported by binary injector.
367
+ */
368
+ bool is_bcast_supported(const dnnl::impl::memory_desc_t &src1_desc,
369
+ const memory_desc_wrapper &dst_d,
370
+ const bcast_set_t &supported_strategy_set);
371
+
372
+ /*
373
+ * Checks if binary injection for given args is supported.
374
+ */
375
+ bool is_supported(cpu_isa_t isa, const dnnl::impl::memory_desc_t &src1_desc,
376
+ const memory_desc_wrapper &dst_d,
377
+ const bcast_set_t &supported_strategy_set);
378
+
379
+ /*
380
+ * Main mechanism responsible for injecting binary postops supporting various
381
+ * isa: sve_512
382
+ * types: f32, s32, u8, s8.
383
+ */
384
+ template <cpu_isa_t isa>
385
+ class jit_uni_binary_injector_t {
386
+ using TReg = typename cpu_isa_traits<isa>::TReg;
387
+ using TRegS = typename cpu_isa_traits<isa>::TRegS;
388
+ using Vmm = typename cpu_isa_traits<isa>::TReg;
389
+
390
+ public:
391
+ jit_uni_binary_injector_t(
392
+ jit_generator *host, const static_params_t &static_params);
393
+
394
+ /*
395
+ * Generates code of binary post_op injected to host primitive. Applied to
396
+ * ordered set of vector registers' indexes. Function loads appropriate
397
+ * slice of rhs tensor for computations based on internally determined
398
+ * broadcast strategy and information about stored data in particular vmm
399
+ * described inside rhs_arg_params.
400
+ */
401
+ void compute_vector_range(const injector_utils::vmm_index_set_t &vmm_idxs,
402
+ std::size_t rhs_arg_idx, const dnnl_post_ops::entry_t &post_op,
403
+ const rhs_arg_dynamic_params_t &rhs_arg_params) const;
404
+
405
+ /*
406
+ * Generates code of binary post_op injected to host primitive. Applied to
407
+ * range <start_idx, end_idx) of vector registers' indexes. Function loads
408
+ * appropriate slice of rhs tensor for computations based on internally
409
+ * determined broadcast strategy and information about stored data in particular
410
+ * vmm described inside rhs_arg_params.
411
+ */
412
+ void compute_vector_range(size_t start_idx, size_t end_idx,
413
+ std::size_t rhs_arg_idx, const dnnl_post_ops::entry_t &post_op,
414
+ const rhs_arg_dynamic_params_t &rhs_arg_params) const;
415
+
416
+ /*
417
+ * Generates code of binary post_op injected to host primitive. Applied to
418
+ * a single vector register index. Function loads appropriate slice of rhs tensor
419
+ * for computations based on internally determined broadcast strategy and information
420
+ * about stored data in particular vmm described inside rhs_arg_params.
421
+ */
422
+ void compute_vector(size_t idx, std::size_t rhs_arg_idx,
423
+ const dnnl_post_ops::entry_t &post_op,
424
+ const rhs_arg_dynamic_params_t &rhs_arg_params) const;
425
+
426
+ private:
427
+ /*
428
+ * Determines if hint passed by user is valid (is inside range
429
+ * <start_idx, end_idx>). If not it returns new vmm idx value that will be
430
+ * used as temporary vmm in future computations.
431
+ */
432
+ int adjust_temp_vmm_hint(
433
+ int user_hint, int start_idx, int end_idx, int max_vmm_idx) const;
434
+ /*
435
+ * Taking into account rhs_broadcasting_strategy and information from user
436
+ * about tensor slice (rhs_arg_params) stored in Vmm(vmm_idx) calculates
437
+ * address of rhs tensor slice needed for binary operation and returns
438
+ * ptr to it.
439
+ */
440
+ rhs_address_t prepare_rhs_arg_addr(std::size_t vmm_idx,
441
+ std::size_t rhs_arg_idx, const dnnl_post_ops::entry_t &post_op,
442
+ const rhs_arg_dynamic_params_t &rhs_arg_params,
443
+ const broadcasting_strategy_t rhs_broadcasting_strategy) const;
444
+ /*
445
+ * Loads data and applies particular binary operation.
446
+ */
447
+ void inject_binary(const dnnl_post_ops::entry_t &post_op, Vmm dst,
448
+ const rhs_address_t &rhs_addr, bool with_tail,
449
+ const tail_lode_mode_t tail_load_mode) const;
450
+
451
+ /*
452
+ * Helper functions responsible for preparing rhs tensor slice address.
453
+ */
454
+ void append_offset_from_operand(
455
+ const std::map<int, rhs_operand_t> &vmm_idx_to_elem_addr_off,
456
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
457
+ const Xbyak_aarch64::XReg &tmp_reg,
458
+ std::size_t elem_size_bytes) const;
459
+ void append_offset_under_mem_addr(
460
+ const std::map<int, rhs_address_t> &vmm_idx_to_elem_addr_off,
461
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
462
+ const Xbyak_aarch64::XReg &tmp_reg,
463
+ std::size_t elem_size_bytes) const;
464
+ void append_value_offset(
465
+ const std::map<int, size_t> &vmm_idx_to_elem_val_off, int vmm_idx,
466
+ const Xbyak_aarch64::XReg &addr_reg,
467
+ std::size_t elem_size_bytes) const;
468
+
469
+ void append_no_broadcast_offset(
470
+ const std::map<int, rhs_address_t> &vmm_idx_to_out_addr,
471
+ const std::map<int, Xbyak_aarch64::XReg> &vmm_idx_to_out_reg,
472
+ const std::map<int, size_t> &vmm_idx_to_out_elem_off_val,
473
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
474
+ const Xbyak_aarch64::XReg &tmp_reg,
475
+ std::size_t elem_size_bytes) const;
476
+ void calculate_no_broadcast(rhs_address_t addr, std::size_t offset,
477
+ const Xbyak_aarch64::XReg &out_reg) const;
478
+
479
+ void append_oc_offset(
480
+ const std::map<int, rhs_address_t> &vmm_idx_to_out_addr,
481
+ const std::map<int, Xbyak_aarch64::XReg> &vmm_idx_to_out_reg,
482
+ const std::map<int, size_t> &vmm_idx_to_out_elem_off_val,
483
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
484
+ const Xbyak_aarch64::XReg &tmp_reg,
485
+ std::size_t elem_size_bytes) const;
486
+ void calculate_oc_ncsp(const dim_t *strides,
487
+ const Xbyak_aarch64::XReg &tmp_reg,
488
+ const bool residue = false) const;
489
+ void calculate_oc_blocked(
490
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
491
+ void calculate_oc_nspc(
492
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
493
+ void calculate_oc_cspn(
494
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
495
+
496
+ void append_mb_sp_offset(
497
+ const std::map<int, rhs_address_t> &vmm_idx_to_out_addr,
498
+ const std::map<int, Xbyak_aarch64::XReg> &vmm_idx_to_out_reg,
499
+ const std::map<int, size_t> &vmm_idx_to_out_elem_off_val,
500
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
501
+ const Xbyak_aarch64::XReg &tmp_reg,
502
+ std::size_t elem_size_bytes) const;
503
+ void calculate_mb_sp_ncsp(
504
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
505
+ void calculate_mb_sp_blocked(
506
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
507
+ void calculate_mb_sp_nspc(
508
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
509
+ void calculate_mb_sp_cspn(
510
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
511
+
512
+ void append_mb_w_offset(
513
+ const std::map<int, rhs_address_t> &vmm_idx_to_out_addr,
514
+ const std::map<int, Xbyak_aarch64::XReg> &vmm_idx_to_out_reg,
515
+ const std::map<int, size_t> &vmm_idx_to_out_elem_off_val,
516
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
517
+ const Xbyak_aarch64::XReg &tmp_reg,
518
+ std::size_t elem_size_bytes) const;
519
+ void calculate_mb_w_ncsp(
520
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
521
+ void calculate_mb_w_blocked(
522
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
523
+ void calculate_mb_w_nspc(
524
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
525
+ void calculate_mb_w_cspn(
526
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
527
+
528
+ void append_w_offset(
529
+ const std::map<int, rhs_address_t> &vmm_idx_to_out_addr,
530
+ const std::map<int, Xbyak_aarch64::XReg> &vmm_idx_to_out_reg,
531
+ const std::map<int, size_t> &vmm_idx_to_out_elem_off_val,
532
+ int vmm_idx, const Xbyak_aarch64::XReg &addr_reg,
533
+ const Xbyak_aarch64::XReg &tmp_reg,
534
+ std::size_t elem_size_bytes) const;
535
+ void calculate_w_ncsp(
536
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
537
+ void calculate_w_blocked(
538
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
539
+ void calculate_w_nspc(
540
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
541
+ void calculate_w_cspn(
542
+ const dim_t *strides, const Xbyak_aarch64::XReg &tmp_reg) const;
543
+
544
+ void compute_cmp_mask(const Xbyak_aarch64::PReg &cmp_dst,
545
+ const Xbyak_aarch64::PReg &mask, const Xbyak_aarch64::ZReg &cmp_src,
546
+ const Xbyak_aarch64::ZReg &cmp_src2, const unsigned int uimm) const;
547
+
548
+ template <typename T>
549
+ void fdiv(const Vmm &dst, const Xbyak_aarch64::PReg &mask, const Vmm &lhs,
550
+ const T &rhs) const;
551
+ template <typename T>
552
+ void fdiv(const Vmm &dst, const Vmm &lhs, const T &rhs) const;
553
+
554
+ void execute_cmp_binary(const Vmm &dst, const Xbyak_aarch64::PReg &mask,
555
+ const Vmm &lhs, const Vmm &rhs,
556
+ const unsigned int cmp_predicate) const;
557
+ template <typename T>
558
+ void execute_binary(alg_kind_t binary_alg, const Vmm &dst,
559
+ const Xbyak_aarch64::PReg &mask, const Vmm &lhs,
560
+ const T &rhs) const;
561
+ /*
562
+ * Used in scalar broadcast strategy, broadcasting single value of given
563
+ * data type over entire vector Vmm register.
564
+ */
565
+ void execute_broadcast(const data_type_t &data_type, const Vmm &tmp_reg,
566
+ const rhs_address_t &rhs_addr,
567
+ const tail_lode_mode_t tail_load_mode,
568
+ bool with_tail = false) const;
569
+ void load_rhs(const data_type_t &data_type, const Vmm &tmp_reg,
570
+ const rhs_address_t &rhs_addr,
571
+ const tail_lode_mode_t tail_load_mode,
572
+ bool with_tail = false) const;
573
+ void execute_broadcast_tail_with_opmask(const data_type_t &data_type,
574
+ const Vmm &tmp_reg, const rhs_address_t &rhs_addr) const;
575
+ void execute_broadcast_tail_statically(const data_type_t &data_type,
576
+ const Vmm &tmp_reg, const rhs_address_t &rhs_addr,
577
+ const std::size_t tail_size) const;
578
+ void execute_broadcast_tail_with_gpr(const data_type_t &data_type,
579
+ const Vmm &tmp_reg, const rhs_address_t &rhs_addr) const;
580
+ void load_rhs_tail_dynamically_with_opmask(const data_type_t &data_type,
581
+ const Vmm &tmp_vmm, const rhs_address_t &rhs_addr) const;
582
+ void load_rhs_tail_dynamically_with_gpr(
583
+ const data_type_t &data_type, const Vmm &tmp_vmm) const;
584
+ void load_rhs_tail_statically(const data_type_t &data_type,
585
+ const Vmm &tmp_vmm, const rhs_address_t &rhs_addr) const;
586
+ void execute_broadcast_no_tail(const data_type_t &data_type,
587
+ const Vmm &tmp_vmm, const rhs_address_t &rhs_addr) const;
588
+ void execute_broadcast_s8u8_no_tail(const data_type_t &data_type,
589
+ const Vmm &tmp_vmm, const rhs_address_t &rhs_addr) const;
590
+ void load_rhs_no_tail(const data_type_t &data_type, const Vmm &tmp_reg,
591
+ const rhs_address_t &rhs_addr) const;
592
+ void load_rhs_i8_no_tail(const data_type_t &data_type, const Vmm &tmp_reg,
593
+ const rhs_address_t &rhs_addr) const;
594
+ void cvt_to_f32(const Vmm &tmp_reg) const;
595
+ /*
596
+ * Returns pair consisting of flag indication preservation is needed for vmm
597
+ * index in second member that should be used as temporary vmm inside inject
598
+ * binary.
599
+ */
600
+ std::pair<bool, int> should_preserve_vmm(int curr_idx, int vmm_hint,
601
+ int max_vmm_idx, bool dt_helper_vmm_needed) const;
602
+ /*
603
+ * Used in isa != avx512 where m32bcst is not supported, replaces ptr_b
604
+ * with ptr.
605
+ */
606
+ rhs_address_t remove_bcast_bit(const rhs_address_t &rhs_addr) const;
607
+
608
+ jit_generator *host_;
609
+ const rhs_arg_static_params_t rhs_arg_static_params_;
610
+ const Xbyak_aarch64::XReg param1_;
611
+ const bcast_set_t supported_strategy_set_;
612
+
613
+ static constexpr int sizeof_reg64 = 8;
614
+ /*
615
+ * Instructions from SSE/AVX used to compute binary result like vaddps where
616
+ * second operand is memory, require mem operand to be 16/32 byte explicitly
617
+ * aligned. (Intel Manual chapter 2.4).
618
+ * Rule is relaxed from AVX2 (Intel Manual chapter 14.9).
619
+ * When using benchdnn zmalloc_protect doesn't guarantee that tensor memory
620
+ * address is 64 byte aligned, which can cause segmentation fault.
621
+ */
622
+ static constexpr bool binary_op_with_unaligned_mem_operand_allowed_ = true;
623
+ };
624
+
625
+ } // namespace binary_injector
626
+ } // namespace aarch64
627
+ } // namespace cpu
628
+ } // namespace impl
629
+ } // namespace dnnl
630
+
631
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2019-2023 Intel Corporation
3
+ * Copyright 2021-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_ELTWISE_INJECTOR_HPP
19
+ #define CPU_AARCH64_JIT_UNI_ELTWISE_INJECTOR_HPP
20
+
21
+ #include <assert.h>
22
+ #include <type_traits>
23
+
24
+ #include "common/c_types_map.hpp"
25
+ #include "common/primitive_attr.hpp"
26
+ #include "common/type_helpers.hpp"
27
+ #include "common/utils.hpp"
28
+
29
+ #include "cpu/aarch64/injectors/injector_utils.hpp"
30
+ #include "cpu/aarch64/jit_generator.hpp"
31
+
32
+ namespace dnnl {
33
+ namespace impl {
34
+ namespace cpu {
35
+ namespace aarch64 {
36
+
37
+ namespace eltwise_injector {
38
+ struct static_params_t {
39
+
40
+ static_params_t(bool save_state = true,
41
+ Xbyak_aarch64::XReg x_table = Xbyak_aarch64::XReg(0),
42
+ Xbyak_aarch64::PReg p_mask = Xbyak_aarch64::PReg(1),
43
+ Xbyak_aarch64::PReg p_tmp0 = Xbyak_aarch64::PReg(4),
44
+ bool is_fwd = true, bool use_dst = false, bool preserve_vmm = true,
45
+ bool preserve_p_table = true)
46
+ : save_state(save_state)
47
+ , x_table(x_table)
48
+ , p_mask(p_mask)
49
+ , p_tmp0(p_tmp0)
50
+ , is_fwd(is_fwd)
51
+ , use_dst(use_dst)
52
+ , preserve_vmm(preserve_vmm)
53
+ , preserve_p_table(preserve_p_table) {}
54
+
55
+ bool save_state;
56
+ Xbyak_aarch64::XReg x_table;
57
+ Xbyak_aarch64::PReg p_mask;
58
+ Xbyak_aarch64::PReg p_tmp0;
59
+ bool is_fwd;
60
+ bool use_dst;
61
+ bool preserve_vmm;
62
+ bool preserve_p_table;
63
+ };
64
+
65
+ /*
66
+ * Checks if isa is supported by eltwise injector.
67
+ */
68
+ bool is_isa_supported(cpu_isa_t isa);
69
+
70
+ /*
71
+ * Checks if eltwise algorithm is supported by eltwise injector.
72
+ */
73
+ bool is_alg_supported(alg_kind_t alg);
74
+
75
+ /*
76
+ * Checks if eltwise injection for given args is supported.
77
+ */
78
+ bool is_supported(cpu_isa_t isa, alg_kind_t alg);
79
+
80
+ } // namespace eltwise_injector
81
+
82
+ template <cpu_isa_t isa>
83
+ struct jit_uni_eltwise_injector_f32 {
84
+ using TReg = typename cpu_isa_traits<isa>::TReg;
85
+ using TRegS = typename cpu_isa_traits<isa>::TRegS;
86
+
87
+ // Arguments description:
88
+ // host - jit generator which is filled with instructions
89
+ // alg, alpha, beta, scale - user eltwise arguments
90
+ // save_state - when true, preserves on stack vmm_aux registers preventing
91
+ // results spoiling. Restores them when done in injector_postamble().
92
+ // p_table - GPR where table label is stored to get access for pre-defined
93
+ // constants used in alg codes.
94
+ // k_mask - k_register to operate with masks in alg codes.
95
+ // is_fwd - when true, computes d = alg(s), otherwise, computes ds = alg'(s)
96
+ // - algorithm derivative.
97
+ // use_dst - defines whether source or destination point is passed to alg
98
+ // code. Depends on algorithm. See `_use_dst_for_bwd` algs definition.
99
+ jit_uni_eltwise_injector_f32(jit_generator *host, alg_kind_t alg,
100
+ float alpha, float beta, float scale, bool save_state = true,
101
+ Xbyak_aarch64::XReg x_table = Xbyak_aarch64::XReg(0),
102
+ Xbyak_aarch64::PReg p_mask = Xbyak_aarch64::PReg(1),
103
+ Xbyak_aarch64::PReg p_tmp0 = Xbyak_aarch64::PReg(4),
104
+ bool is_fwd = true, bool use_dst = false, bool preserve_vmm = true,
105
+ bool preserve_p_table = true)
106
+ : alg_(alg)
107
+ , alpha_(alpha)
108
+ , beta_(beta)
109
+ , scale_(scale)
110
+ , h(host)
111
+ , save_state_(save_state)
112
+ , x_table(x_table)
113
+ , p_mask(p_mask)
114
+ , p_tmp0(p_tmp0)
115
+ , is_fwd_(is_fwd)
116
+ , use_dst_(use_dst)
117
+ , preserve_vmm_(preserve_vmm)
118
+ , preserve_p_table_(preserve_p_table) {
119
+ assert(eltwise_injector::is_supported(isa, alg_));
120
+
121
+ register_table_entries();
122
+ }
123
+
124
+ jit_uni_eltwise_injector_f32(jit_generator *host,
125
+ const post_ops_t::entry_t::eltwise_t &eltwise,
126
+ bool save_state = true,
127
+ Xbyak_aarch64::XReg x_table = Xbyak_aarch64::XReg(0),
128
+ Xbyak_aarch64::PReg p_mask = Xbyak_aarch64::PReg(1),
129
+ Xbyak_aarch64::PReg p_tmp0 = Xbyak_aarch64::PReg(4),
130
+ bool is_fwd = true, bool use_dst = false, bool preserve_vmm = true,
131
+ bool preserve_p_table = true)
132
+ : jit_uni_eltwise_injector_f32(host, eltwise.alg, eltwise.alpha,
133
+ eltwise.beta, eltwise.scale, save_state, x_table, p_mask,
134
+ p_tmp0, is_fwd, use_dst, preserve_vmm, preserve_p_table) {}
135
+
136
+ void compute_vector_range(size_t start_idx, size_t end_idx);
137
+ void compute_vector_range(const injector_utils::vmm_index_set_t &vmm_idxs);
138
+ void compute_vector(size_t idx) { compute_vector_range(idx, idx + 1); }
139
+ void prepare_table(bool gen_table = true);
140
+ void load_table_addr() { h->adr(x_table, l_table); }
141
+
142
+ private:
143
+ const alg_kind_t alg_;
144
+ const float alpha_;
145
+ const float beta_;
146
+ const float scale_;
147
+
148
+ jit_generator *const h;
149
+
150
+ const bool save_state_;
151
+ const Xbyak_aarch64::XReg x_table;
152
+ // 99 is dummy and must be replaced meaningfull value at runtime.
153
+ Xbyak_aarch64::PReg p_all = Xbyak_aarch64::PReg(99);
154
+ const Xbyak_aarch64::PReg p_mask;
155
+ const Xbyak_aarch64::PReg p_tmp0;
156
+ const bool is_fwd_;
157
+ const bool use_dst_;
158
+ const bool preserve_vmm_;
159
+ const bool preserve_p_table_;
160
+
161
+ Xbyak_aarch64::Label l_table;
162
+
163
+ // if only the injector was inherited from jit_generator...
164
+ enum {
165
+ _cmp_eq_oq = jit_generator::_cmp_eq_oq,
166
+ _cmp_lt_os = jit_generator::_cmp_lt_os,
167
+ _cmp_le_os = jit_generator::_cmp_le_os,
168
+ _cmp_ge_os = jit_generator::_cmp_nlt_us,
169
+ _cmp_gt_os = jit_generator::_cmp_nle_us,
170
+ _op_floor = jit_generator::_op_floor,
171
+ _op_mxcsr = jit_generator::_op_mxcsr
172
+ };
173
+
174
+ const size_t vlen = get_sve_length();
175
+ static constexpr size_t preserved_vecs_max = 9;
176
+ static constexpr size_t preserved_gprs_max = 4;
177
+ static constexpr size_t vecs_count = cpu_isa_traits<isa>::n_vregs;
178
+ static constexpr int n_mantissa_bits = 23;
179
+ static constexpr int k_mask_size = 8;
180
+
181
+ size_t vecs_to_preserve = 0;
182
+ size_t preserved_vecs_count = 0;
183
+ size_t preserved_vec_idxs[preserved_vecs_max] = {0};
184
+ size_t preserved_gpr_idxs[preserved_gprs_max] = {0};
185
+ injector_utils::vmm_index_set_iterator_t start_idx_tail;
186
+
187
+ /* These vector register must be assigned proper index. */
188
+ TRegS vmm_mask {0}, vmm_aux0 {0}, vmm_aux1 {0}, vmm_aux2 {0}, vmm_aux3 {0},
189
+ vmm_aux4 {0}, vmm_aux5 {0}, vmm_aux6 {0}, vmm_aux7 {0}, vmm_tmp {0};
190
+ /* Default tempooral index. Chose a SVE register
191
+ not to be same as jit_uni_eltwise.(cpp|hpp).
192
+ This index is changed by assign_regs() in case of eltwise injection.
193
+ */
194
+ TRegS z_tmp {31};
195
+
196
+ size_t aux_vecs_count();
197
+ size_t aux_gprs_count();
198
+
199
+ void compute_body(
200
+ const injector_utils::vmm_index_set_iterator_t &start_idx_it,
201
+ const injector_utils::vmm_index_set_iterator_t &end_idx_it);
202
+ void injector_preamble(const injector_utils::vmm_index_set_t &vmm_idxs);
203
+ void injector_preamble_tail(
204
+ const injector_utils::vmm_index_set_iterator_t start_idx_it);
205
+ void injector_postamble();
206
+ void assign_regs();
207
+ void set_coef_to_regs();
208
+ void compute_cmp_mask(
209
+ const TRegS &vmm_src, const TRegS &vmm_cmpare, int cmp_predicate);
210
+ void blend_with_mask(const TRegS &vmm_dst, const TRegS &src);
211
+ void test_mask();
212
+
213
+ void exp_compute_vector_fwd(const TRegS &vmm_src);
214
+ void relu_compute_vector_fwd(const TRegS &vmm_src);
215
+ void relu_zero_ns_compute_vector_fwd(const TRegS &vmm_src);
216
+ void elu_compute_vector_fwd(const TRegS &vmm_src);
217
+ void tanh_compute_vector_fwd(const TRegS &vmm_src);
218
+ void square_compute_vector_fwd(const TRegS &vmm_src);
219
+ void abs_compute_vector_fwd(const TRegS &vmm_src);
220
+ void sqrt_compute_vector_fwd(const TRegS &vmm_src);
221
+ void linear_compute_vector_fwd(const TRegS &vmm_src);
222
+ void soft_relu_compute_vector_fwd(const TRegS &vmm_src);
223
+ void mish_compute_vector_fwd(const TRegS &vmm_src);
224
+ void logistic_compute_vector_fwd(const TRegS &vmm_src);
225
+ void gelu_tanh_compute_vector_fwd(const TRegS &vmm_src);
226
+ void swish_compute_vector_fwd(const TRegS &vmm_src);
227
+ void log_compute_vector_fwd(const TRegS &vmm_src);
228
+ void clip_compute_vector_fwd(const TRegS &vmm_src);
229
+ void gelu_erf_compute_vector_fwd(const TRegS &vmm_src);
230
+ void gelu_erf_minimax_approx_compute_vector_fwd(const TRegS &vmm_src);
231
+ void round_compute_vector_fwd(const TRegS &vmm_src);
232
+ void hardswish_compute_vector_fwd(const TRegS &vmm_src);
233
+ void hardsigmoid_compute_vector_fwd(const TRegS &vmm_src);
234
+
235
+ void exp_compute_vector_bwd(const TRegS &vmm_src);
236
+ void relu_compute_vector_bwd(const TRegS &vmm_src);
237
+ void elu_compute_vector_bwd(const TRegS &vmm_src);
238
+ void tanh_compute_vector_bwd(const TRegS &vmm_src);
239
+ void square_compute_vector_bwd(const TRegS &vmm_src);
240
+ void abs_compute_vector_bwd(const TRegS &vmm_src);
241
+ void sqrt_compute_vector_bwd(const TRegS &vmm_src);
242
+ void linear_compute_vector_bwd(const TRegS &vmm_src);
243
+ void soft_relu_compute_vector_bwd(const TRegS &vmm_src);
244
+ void logistic_compute_vector_bwd(const TRegS &vmm_src);
245
+ void mish_compute_vector_bwd(const TRegS &vmm_src);
246
+ void gelu_tanh_compute_vector_bwd(const TRegS &vmm_src);
247
+ void swish_compute_vector_bwd(const TRegS &vmm_src);
248
+ void log_compute_vector_bwd(const TRegS &vmm_src);
249
+ void clip_compute_vector_bwd(const TRegS &vmm_src);
250
+ void gelu_erf_compute_vector_bwd(const TRegS &vmm_src);
251
+ void hardswish_compute_vector_bwd(const TRegS &vmm_src);
252
+ void hardsigmoid_compute_vector_bwd(const TRegS &vmm_src);
253
+
254
+ enum key_t {
255
+ scale = 0, // scale argument
256
+ alpha, // alpha argument
257
+ beta, // beta argument
258
+ zero, // 0.f
259
+ half, // 0.5f
260
+ one, // 1.f or mask for exponent bits
261
+ two, // 2.f
262
+ minus_one, // -1.f or changes sign to opposite
263
+ minus_two, // -2.f
264
+ ln2f, // 0.69314718f
265
+ positive_mask, // changes sign to positive
266
+ sign_mask, // gets sign value
267
+ exponent_bias, // (127 = 2^7 - 1), gets exponent bits
268
+ exp_log2ef, // 1.44269502f - formula-based for approx
269
+ exp_ln_flt_max_f, // logf(FLT_MAX) - max normal value
270
+ exp_ln_flt_min_f, // logf(FLT_MIN) - min normal value
271
+ exp_pol, // see correspondent table for float values
272
+ exp_coeff1, // 0.6931473921 (0x3f31721c)
273
+ exp_coeff2, // 0.2413862043 (0x3e772df2)
274
+ exp_not_mask17, // ~((1u << 17) - 1)
275
+ fwd_mish_max_x_for_equation_f,
276
+ // e^x(e^3x+4e^2x+e^x*(6+4*x)+4*(1+x)) = FLT_MAX; x =~ 22.18070976278534
277
+ bwd_mish_max_x_for_equation_f,
278
+ tanh_range, // tanh(x) = x - x^3/3 for |x| < tanh_range
279
+ tanh_m1d3, // -1/3
280
+ soft_relu_one_twenty_six, // 126.f
281
+ soft_relu_mantissa_sign_mask, // mask for mantissa bits and sign
282
+ soft_relu_pol, // see correspondent table for float values
283
+ gelu_tanh_fitting_const, // 0.044715f
284
+ gelu_tanh_fitting_const_times_three, // 0.134145f
285
+ gelu_tanh_sqrt_two_over_pi, // sqrtf(2.f/pi) = 0.797884f
286
+ gelu_erf_approx_const, // 0.3275911f - implementation based for approx
287
+ gelu_erf_one_over_sqrt_two, // 1.f / sqrtf(2.f)
288
+ gelu_erf_one_over_sqrt_pi, // 1.f / sqrtf(pi) = 0.564190f
289
+ gelu_erf_pol, // see correspondent table for float values
290
+ log_minus_inf, // -inf
291
+ log_qnan, // qnan
292
+ log_mantissa_mask, // gets mantissa bits
293
+ log_full_k_reg_mask, // sets k_register with all bits of 1
294
+ log_full_vector_reg_mask, // sets vector register will all bits of 1
295
+ log_five_bit_offset, // 5 bits off (31 = 2^5 - 1)
296
+ log_pol, // see correspondent table for float values
297
+ log_predefined_vals, // see correspondent table for float values
298
+ log_i127shl23,
299
+ log_x7fffff,
300
+ log_log2,
301
+ log_log1p5,
302
+ log_f2div3,
303
+ log_coeffTbl,
304
+ undef_key,
305
+ };
306
+
307
+ size_t table_off(key_t key, size_t key_off_val_shift = 0) {
308
+ // assumption: all table entries sharing the same key also
309
+ // share their broadcast property
310
+ // TODO: enforce through data structure
311
+ const auto it = entry_map_.find(key); // search an entry for a key
312
+ assert(it != entry_map_.end());
313
+ const auto &te = (*it).second;
314
+ const auto scale = te.bcast ? vlen : sizeof(table_entry_val_t);
315
+ return te.off + key_off_val_shift * scale;
316
+ }
317
+
318
+ TRegS table_val(key_t key, TRegS zreg, size_t key_off_val_shift = 0) {
319
+ Xbyak_aarch64::XReg x_addr(h->X_DEFAULT_ADDR);
320
+ auto off = table_off(key, key_off_val_shift);
321
+
322
+ if (off) {
323
+ h->add_imm(x_addr, x_table, off, h->X_TMP_0);
324
+ } else {
325
+ x_addr = x_table;
326
+ }
327
+
328
+ h->ldr(TReg(zreg.getIdx()), ptr(x_addr));
329
+ return zreg;
330
+ }
331
+
332
+ // we accept only 32bit hexadecimal table values to avoid any rounding
333
+ using table_entry_val_t = uint32_t;
334
+ using table_entry_offset_t = size_t; // offsets are in bytes wrt p_table
335
+ using table_entry_bcast_t = bool; // true => bcast value
336
+
337
+ struct table_entry_t {
338
+ table_entry_val_t val;
339
+ table_entry_bcast_t bcast;
340
+ };
341
+ struct mapped_table_entry_t {
342
+ table_entry_offset_t off;
343
+ table_entry_val_t val;
344
+ table_entry_bcast_t bcast;
345
+ };
346
+
347
+ using table_t = std::multimap<key_t, table_entry_t>;
348
+ using mapped_table_t = std::multimap<key_t, mapped_table_entry_t>;
349
+
350
+ void register_table_entries();
351
+ mapped_table_t entry_map_;
352
+ };
353
+
354
+ } // namespace aarch64
355
+ } // namespace cpu
356
+ } // namespace impl
357
+ } // namespace dnnl
358
+
359
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/injectors/jit_uni_postops_injector.hpp ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2023 Intel Corporation
3
+ * Copyright 2022-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+ #ifndef CPU_AARCH64_JIT_UNI_POSTOPS_INJECTOR_HPP
18
+ #define CPU_AARCH64_JIT_UNI_POSTOPS_INJECTOR_HPP
19
+
20
+ #include <functional>
21
+ #include <map>
22
+ #include <memory>
23
+
24
+ #include "common/c_types_map.hpp"
25
+ #include "common/primitive_attr.hpp"
26
+ #include "common/type_helpers.hpp"
27
+ #include "common/utils.hpp"
28
+ #include "cpu/aarch64/injectors/injector_utils.hpp"
29
+ #include "cpu/aarch64/injectors/jit_uni_binary_injector.hpp"
30
+ #include "cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp"
31
+ #include "cpu/aarch64/jit_generator.hpp"
32
+ #include <initializer_list>
33
+
34
+ namespace dnnl {
35
+ namespace impl {
36
+ namespace cpu {
37
+ namespace aarch64 {
38
+ namespace injector {
39
+
40
+ /*
41
+ * Allows specifying custom injector function for given post-op type - one
42
+ * function per primitive. There are post-ops type (example: sum) that don't
43
+ * have specialized injector. They heavily rely on kernel specific intrnals,
44
+ * which makes the generalization unreasonable. As so user can prepare internal
45
+ * kernel lambda and pass it explicitly to injector.
46
+ */
47
+ using lambda_jit_injectors_t
48
+ = std::map<dnnl_primitive_kind_t, std::function<void()>>;
49
+
50
+ struct post_ops_ok_args_t;
51
+ /*
52
+ * Checks if postops injection for given args is supported.
53
+ */
54
+ bool is_supported(const post_ops_ok_args_t &post_ops_ok_args);
55
+
56
+ /*
57
+ * Main mechanism of handling various post-ops types. It utilizes internally
58
+ * specialized injectors to generate post-ops code to host primitive. Random
59
+ * order of post-ops is supported.
60
+ */
61
+ template <cpu_isa_t isa>
62
+ class jit_uni_postops_injector_t {
63
+ public:
64
+ /*
65
+ * @param host <required> - user primitive where post-ops generated code is
66
+ * injected
67
+ * @param post_ops <required> - struct representing requested post-ops chain
68
+ * @binary_static_params <reguired> - static params needed for binary_injector.
69
+ * see: jit_uni_binary_injector.hpp for more info.
70
+ * @param eltwise_static_params <optional> - allows user specify non default
71
+ * params for eltwise_injector
72
+ * @param lambda_jit_injectors <optional> - allows user specify custom injector
73
+ * function for given post-op type
74
+ */
75
+ jit_uni_postops_injector_t(jit_generator *host, const post_ops_t &post_ops,
76
+ const binary_injector::static_params_t &binary_static_params);
77
+ jit_uni_postops_injector_t(jit_generator *host, const post_ops_t &post_ops,
78
+ const binary_injector::static_params_t &binary_static_params,
79
+ const lambda_jit_injectors_t &lambda_jit_injectors);
80
+ jit_uni_postops_injector_t(jit_generator *host, const post_ops_t &post_ops,
81
+ const binary_injector::static_params_t &binary_static_params,
82
+ const eltwise_injector::static_params_t &eltwise_static_params);
83
+ jit_uni_postops_injector_t(jit_generator *host, const post_ops_t &post_ops,
84
+ const binary_injector::static_params_t &binary_static_params,
85
+ const eltwise_injector::static_params_t &eltwise_static_params,
86
+ const lambda_jit_injectors_t &lambda_jit_injectors);
87
+
88
+ /*
89
+ * Generates code of post_ops chain injected to host primitive. Applied to
90
+ * ordered set of vector registers' indexes.
91
+ *
92
+ * @rhs_arg_params: see jit_uni_binary_injector description
93
+ */
94
+ void compute_vector_range(const injector_utils::vmm_index_set_t &vmm_idxs,
95
+ const binary_injector::rhs_arg_dynamic_params_t &rhs_arg_params);
96
+
97
+ void compute_vector_range(const injector_utils::vmm_index_set_t &vmm_idxs);
98
+
99
+ /*
100
+ * Generates code of post_ops chain injected to host primitive. Applied to
101
+ * range <start_idx, end_idx) of vector registers' indexes.
102
+ *
103
+ * @rhs_arg_params: see jit_uni_binary_injector description
104
+ */
105
+ void compute_vector_range(size_t start_idx, size_t end_idx,
106
+ const binary_injector::rhs_arg_dynamic_params_t &rhs_arg_params);
107
+
108
+ void compute_vector_range(size_t start_idx, size_t end_idx);
109
+
110
+ /*
111
+ * Generates code of post_ops chain injected to host primitive. Applied to
112
+ * a single vector register index.
113
+ *
114
+ * @rhs_arg_params: see jit_uni_binary_injector description
115
+ */
116
+ void compute_vector(size_t idx,
117
+ const binary_injector::rhs_arg_dynamic_params_t &rhs_arg_params);
118
+ void compute_vector(size_t idx);
119
+
120
+ /*
121
+ * Thin wrapper for eltwise injector specific function
122
+ */
123
+ void prepare_table(bool gen_table = true);
124
+ void set_lambda_injector(lambda_jit_injectors_t::key_type,
125
+ const lambda_jit_injectors_t::mapped_type &jit_injector);
126
+
127
+ private:
128
+ post_ops_t post_ops_;
129
+ jit_generator *host_;
130
+ // Key is a numerical order of a post-op in attributes.
131
+ std::map<int, jit_uni_eltwise_injector_f32<isa>> alg_to_eltwise_injector_;
132
+ std::unique_ptr<binary_injector::jit_uni_binary_injector_t<isa>>
133
+ binary_injector_;
134
+ lambda_jit_injectors_t lambda_jit_injectors_;
135
+ };
136
+
137
+ enum post_op_type { sum = 0, eltwise, binary };
138
+
139
+ struct post_ops_ok_args_t {
140
+ post_ops_ok_args_t(const cpu_isa_t isa,
141
+ const std::vector<post_op_type> &accepted_post_op_types,
142
+ const post_ops_t &post_ops, const memory_desc_wrapper *dst_d,
143
+ const bool sum_at_pos_0_only, const bool sum_requires_scale_one,
144
+ const bool sum_requires_zp_zero = true,
145
+ const bool sum_requires_same_params = true,
146
+ const bcast_set_t &enabled_bcast_strategy = default_strategies());
147
+
148
+ const cpu_isa_t isa;
149
+ const std::vector<post_op_type> &accepted_post_op_types;
150
+ const post_ops_t &post_ops;
151
+ const memory_desc_wrapper *dst_d;
152
+ const bool sum_at_pos_0_only;
153
+ const bool sum_requires_scale_one;
154
+ const bool sum_requires_zp_zero;
155
+ const bool sum_requires_same_params;
156
+ const bcast_set_t enabled_bcast_strategy;
157
+ };
158
+
159
+ bool post_ops_ok(const post_ops_ok_args_t &args);
160
+
161
+ } // namespace injector
162
+ } // namespace aarch64
163
+ } // namespace cpu
164
+ } // namespace impl
165
+ } // namespace dnnl
166
+
167
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_generator.hpp ADDED
@@ -0,0 +1,728 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2016-2023 Intel Corporation
3
+ * Copyright 2020-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_GENERATOR_HPP
19
+ #define CPU_AARCH64_JIT_GENERATOR_HPP
20
+
21
+ #include <limits.h>
22
+
23
+ #include "common/bit_cast.hpp"
24
+ #include "common/type_helpers.hpp"
25
+ #include "common/utils.hpp"
26
+
27
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
28
+
29
+ #include "cpu/jit_utils/jit_utils.hpp"
30
+
31
+ #if defined(_WIN32) && !defined(__GNUC__)
32
+ #define STRUCT_ALIGN(al, ...) __declspec(align(al)) __VA_ARGS__
33
+ #else
34
+ #define STRUCT_ALIGN(al, ...) __VA_ARGS__ __attribute__((__aligned__(al)))
35
+ #endif
36
+
37
+ #define DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_name) \
38
+ const char *name() const override { return STRINGIFY(jit_name); } \
39
+ const char *source_file() const override { return __FILE__; }
40
+
41
+ static const size_t CSIZE = sizeof(uint32_t);
42
+
43
+ namespace dnnl {
44
+ namespace impl {
45
+ namespace cpu {
46
+ namespace aarch64 {
47
+
48
+ // TODO: move this to jit_generator class?
49
+ namespace {
50
+
51
+ typedef enum {
52
+ MAX_CODE_SIZE = 256 * 1024,
53
+ } max_code_size_t;
54
+
55
+ // Callee-saved registers
56
+ constexpr Xbyak_aarch64::Operand::Code abi_save_gpr_regs[]
57
+ = {Xbyak_aarch64::Operand::X16, Xbyak_aarch64::Operand::X17,
58
+ Xbyak_aarch64::Operand::X19, Xbyak_aarch64::Operand::X20,
59
+ Xbyak_aarch64::Operand::X21, Xbyak_aarch64::Operand::X22,
60
+ Xbyak_aarch64::Operand::X23, Xbyak_aarch64::Operand::X24,
61
+ Xbyak_aarch64::Operand::X25, Xbyak_aarch64::Operand::X26,
62
+ Xbyak_aarch64::Operand::X27, Xbyak_aarch64::Operand::X28};
63
+
64
+ // See "Procedure Call Standsard for the ARM 64-bit Architecture (AArch64)"
65
+ static const Xbyak_aarch64::XReg abi_param1(Xbyak_aarch64::Operand::X0),
66
+ abi_param2(Xbyak_aarch64::Operand::X1),
67
+ abi_param3(Xbyak_aarch64::Operand::X2),
68
+ abi_param4(Xbyak_aarch64::Operand::X3),
69
+ abi_param5(Xbyak_aarch64::Operand::X4),
70
+ abi_param6(Xbyak_aarch64::Operand::X5),
71
+ abi_param7(Xbyak_aarch64::Operand::X6),
72
+ abi_param8(Xbyak_aarch64::Operand::X7),
73
+ abi_not_param1(Xbyak_aarch64::Operand::X15);
74
+ } // namespace
75
+
76
+ class jit_generator : public Xbyak_aarch64::CodeGenerator, public c_compatible {
77
+ public:
78
+ using c_compatible::operator new;
79
+ using c_compatible::operator new[];
80
+ using c_compatible::operator delete;
81
+ using c_compatible::operator delete[];
82
+
83
+ private:
84
+ const size_t xreg_len = 8;
85
+ const size_t vreg_len_preserve = 8; // Only bottom 8byte must be preserved.
86
+ const size_t vreg_to_preserve = 8; // VREG8 - VREG15
87
+
88
+ const size_t num_abi_save_gpr_regs
89
+ = sizeof(abi_save_gpr_regs) / sizeof(abi_save_gpr_regs[0]);
90
+
91
+ const size_t preserved_stack_size = xreg_len * (2 + num_abi_save_gpr_regs)
92
+ + vreg_len_preserve * vreg_to_preserve;
93
+
94
+ const size_t size_of_abi_save_regs = num_abi_save_gpr_regs * x0.getBit() / 8
95
+ + vreg_to_preserve * vreg_len_preserve;
96
+
97
+ public:
98
+ enum {
99
+ _cmp_eq_oq = 0u,
100
+ _cmp_lt_os = 1u,
101
+ _cmp_le_os = 2u,
102
+ _cmp_neq_uq = 4u,
103
+ _cmp_nlt_us = 5u,
104
+ _cmp_nle_us = 6u,
105
+
106
+ _op_floor = 1u,
107
+ _op_mxcsr = 4u,
108
+ };
109
+
110
+ const uint64_t cpu_sveLen = get_sve_length();
111
+
112
+ const Xbyak_aarch64::WReg W_TMP_0 = w23;
113
+ const Xbyak_aarch64::WReg W_TMP_1 = w24;
114
+ const Xbyak_aarch64::WReg W_TMP_2 = w25;
115
+ const Xbyak_aarch64::WReg W_TMP_3 = w26;
116
+ const Xbyak_aarch64::WReg W_TMP_4 = w27;
117
+ const Xbyak_aarch64::XReg X_TMP_0 = x23;
118
+ const Xbyak_aarch64::XReg X_TMP_1 = x24;
119
+ const Xbyak_aarch64::XReg X_TMP_2 = x25;
120
+ const Xbyak_aarch64::XReg X_TMP_3 = x26;
121
+ const Xbyak_aarch64::XReg X_TMP_4 = x27;
122
+ const Xbyak_aarch64::XReg X_DEFAULT_ADDR = x28;
123
+ const Xbyak_aarch64::XReg X_SP = x21;
124
+ const Xbyak_aarch64::XReg X_TRANSLATOR_STACK = x22;
125
+ const Xbyak_aarch64::PReg P_TMP = p7;
126
+ const Xbyak_aarch64::PReg P_TMP_0 = p11;
127
+ const Xbyak_aarch64::PReg P_TMP_1 = p12;
128
+ const Xbyak_aarch64::PReg P_ALL_ZERO = p10;
129
+ const Xbyak_aarch64::PReg P_NOT_256 = p13;
130
+ const Xbyak_aarch64::PReg P_NOT_128 = p14;
131
+ const Xbyak_aarch64::PReg P_ALL_ONE = p0;
132
+
133
+ const std::vector<Xbyak_aarch64::XReg> x_tmp_vec
134
+ = {X_TMP_0, X_TMP_1, X_TMP_2, X_TMP_3, X_TMP_4};
135
+ const int x_tmp_vec_size = x_tmp_vec.size();
136
+
137
+ const Xbyak_aarch64::XReg param1 = abi_param1;
138
+ constexpr static size_t translator_stack_offset = 1024 * 128;
139
+ constexpr static uint32_t DUMMY_IDX = 99;
140
+
141
+ inline size_t get_size_of_abi_save_regs() { return size_of_abi_save_regs; }
142
+
143
+ void preamble() {
144
+ using namespace Xbyak_aarch64::util;
145
+ uint64_t sveLen = get_sve_length();
146
+
147
+ stp(x29, x30, pre_ptr(sp, -16));
148
+ /* x29 is a frame pointer. */
149
+ mov(x29, sp);
150
+ sub(sp, sp, static_cast<int64_t>(preserved_stack_size) - 16);
151
+
152
+ /* x9 can be used as a temporal register. */
153
+ mov(x9, sp);
154
+
155
+ if (vreg_to_preserve) {
156
+ st4((v8.d - v11.d)[0], post_ptr(x9, vreg_len_preserve * 4));
157
+ st4((v12.d - v15.d)[0], post_ptr(x9, vreg_len_preserve * 4));
158
+ }
159
+ for (size_t i = 0; i < num_abi_save_gpr_regs; i += 2) {
160
+ stp(Xbyak_aarch64::XReg(abi_save_gpr_regs[i]),
161
+ Xbyak_aarch64::XReg(abi_save_gpr_regs[i + 1]),
162
+ post_ptr(x9, xreg_len * 2));
163
+ }
164
+
165
+ if (sveLen) { /* SVE is available. */
166
+ ptrue(P_ALL_ONE.b);
167
+ pfalse(P_ALL_ZERO.b);
168
+ }
169
+ if (sveLen >= SVE_256) {
170
+ ptrue(P_NOT_128.b, Xbyak_aarch64::VL16);
171
+ not_(P_NOT_128.b, P_ALL_ONE / Xbyak_aarch64::T_z, P_NOT_128.b);
172
+ }
173
+ if (sveLen >= SVE_512) {
174
+ ptrue(P_NOT_256.b, Xbyak_aarch64::VL32);
175
+ not_(P_NOT_256.b, P_ALL_ONE / Xbyak_aarch64::T_z, P_NOT_256.b);
176
+ }
177
+
178
+ mov(X_SP, sp);
179
+ sub_imm(X_TRANSLATOR_STACK, X_SP, translator_stack_offset, X_TMP_0);
180
+ }
181
+
182
+ void postamble() {
183
+ using namespace Xbyak_aarch64::util;
184
+
185
+ mov(x9, sp);
186
+
187
+ if (vreg_to_preserve) {
188
+ ld4((v8.d - v11.d)[0], post_ptr(x9, vreg_len_preserve * 4));
189
+ ld4((v12.d - v15.d)[0], post_ptr(x9, vreg_len_preserve * 4));
190
+ }
191
+
192
+ for (size_t i = 0; i < num_abi_save_gpr_regs; i += 2) {
193
+ ldp(Xbyak_aarch64::XReg(abi_save_gpr_regs[i]),
194
+ Xbyak_aarch64::XReg(abi_save_gpr_regs[i + 1]),
195
+ post_ptr(x9, xreg_len * 2));
196
+ }
197
+
198
+ add(sp, sp, static_cast<int64_t>(preserved_stack_size) - 16);
199
+ ldp(x29, x30, post_ptr(sp, 16));
200
+ ret();
201
+ }
202
+
203
+ // Disallow char-based labels completely
204
+ void L(const char *label) = delete;
205
+ void L(Xbyak_aarch64::Label &label) {
206
+ Xbyak_aarch64::CodeGenerator::L(label);
207
+ }
208
+
209
+ void L_aligned(Xbyak_aarch64::Label &label, int alignment = 16) {
210
+ align(alignment);
211
+ L(label);
212
+ }
213
+
214
+ template <typename T>
215
+ Xbyak_aarch64::XReg addr_off(const Xbyak_aarch64::XReg &base, const T off,
216
+ const Xbyak_aarch64::XReg &addr, const Xbyak_aarch64::XReg &x_tmp) {
217
+ if (off == 0) return base;
218
+
219
+ add_imm(addr, base, off, x_tmp);
220
+ return addr;
221
+ }
222
+
223
+ template <typename PRegBHSD, typename T>
224
+ void set_preg(const PRegBHSD &p, T tail_size,
225
+ const Xbyak_aarch64::XReg x_tmp0 = Xbyak_aarch64::XReg(DUMMY_IDX),
226
+ const Xbyak_aarch64::XReg x_tmp1 = Xbyak_aarch64::XReg(DUMMY_IDX)) {
227
+ using namespace Xbyak_aarch64;
228
+
229
+ assert(tail_size <= 64); // Implemented only for "SVE size <= 512"
230
+
231
+ switch (tail_size) {
232
+ case 0: pfalse(PRegB(p.getIdx())); return;
233
+ case 1: ptrue(p, VL1); return;
234
+ case 2: ptrue(p, VL2); return;
235
+ case 3: ptrue(p, VL3); return;
236
+ case 4: ptrue(p, VL4); return;
237
+ case 5: ptrue(p, VL5); return;
238
+ case 6: ptrue(p, VL6); return;
239
+ case 7: ptrue(p, VL7); return;
240
+ case 8: ptrue(p, VL8); return;
241
+ case 16: ptrue(p, VL16); return;
242
+ case 32: ptrue(p, VL32); return;
243
+ case 64: ptrue(p, VL64); return;
244
+ }
245
+
246
+ assert(x_tmp0.getIdx() != DUMMY_IDX && x_tmp1.getIdx() != DUMMY_IDX);
247
+ mov_imm(x_tmp0, 0);
248
+ mov_imm(x_tmp1, tail_size);
249
+ whilelt(p, x_tmp0, x_tmp1);
250
+ }
251
+
252
+ template <typename T>
253
+ void uni_add(const T &x1, const T &x2, const T &op) {
254
+ add(x1, x2, op);
255
+ }
256
+
257
+ void uni_add(const Xbyak_aarch64::VReg4S &x1,
258
+ const Xbyak_aarch64::VReg4S &x2, const Xbyak_aarch64::VReg4S &op) {
259
+ add(x1, x2, op);
260
+ }
261
+
262
+ void uni_add(const Xbyak_aarch64::ZReg &x1, const Xbyak_aarch64::ZReg &x2,
263
+ const Xbyak_aarch64::ZReg &op) {
264
+ add(Xbyak_aarch64::ZRegS(x1.getIdx()),
265
+ Xbyak_aarch64::ZRegS(x2.getIdx()),
266
+ Xbyak_aarch64::ZRegS(op.getIdx()));
267
+ }
268
+
269
+ template <typename T>
270
+ void udiv_mod(const T &q, const T &r, const T &divend, const T &divisor) {
271
+ assert(q.getIdx() != divisor.getIdx());
272
+ assert(q.getIdx() != divend.getIdx());
273
+ assert(r.getIdx() != divend.getIdx());
274
+
275
+ udiv(q, divend, divisor);
276
+ mul(r, q, divisor);
277
+ sub(r, divend, r);
278
+ }
279
+
280
+ template <typename T>
281
+ void umod(const T &r, const T &divend, const T &divisor) {
282
+ assert(r.getIdx() != divend.getIdx());
283
+ assert(r.getIdx() != divisor.getIdx());
284
+
285
+ udiv(r, divend, divisor);
286
+ mul(r, r, divisor);
287
+ sub(r, divend, r);
288
+ }
289
+
290
+ void uni_clear(const Xbyak_aarch64::VReg &dst) { eor(dst.b, dst.b, dst.b); }
291
+
292
+ void uni_clear(const Xbyak_aarch64::ZReg &dst) { eor(dst.d, dst.d, dst.d); }
293
+
294
+ template <typename T>
295
+ void uni_fadd(const T &dst, const T &src, const T &src2) {
296
+ fadd(dst, src, src2);
297
+ }
298
+
299
+ void uni_fcvtzs(
300
+ const Xbyak_aarch64::VReg4S &d, const Xbyak_aarch64::VReg4S &s) {
301
+ fcvtzs(d, s);
302
+ }
303
+
304
+ void uni_fcvtzs(
305
+ const Xbyak_aarch64::ZRegS &d, const Xbyak_aarch64::ZRegS &s) {
306
+ fcvtzs(d, P_ALL_ONE / Xbyak_aarch64::T_z, s);
307
+ }
308
+
309
+ template <typename TReg>
310
+ void uni_fdiv(const TReg &dst, const TReg &src, const TReg &src2,
311
+ const TReg &tmp, const Xbyak_aarch64::PReg &pred) {
312
+ uint32_t dstIdx = dst.getIdx();
313
+ uint32_t srcIdx = src.getIdx();
314
+ uint32_t src2Idx = src2.getIdx();
315
+ uint32_t tmpIdx = tmp.getIdx();
316
+
317
+ if (dstIdx == src2Idx) {
318
+ assert(tmpIdx != srcIdx && tmpIdx != src2Idx);
319
+
320
+ mov(Xbyak_aarch64::ZRegD(tmpIdx), Xbyak_aarch64::ZRegD(src2Idx));
321
+ mov(dst, pred / Xbyak_aarch64::T_m, src);
322
+ fdiv(dst, pred / Xbyak_aarch64::T_m, tmp);
323
+ } else if (dstIdx == srcIdx) {
324
+ fdiv(dst, pred / Xbyak_aarch64::T_m, src2);
325
+ } else {
326
+ mov(dst, P_ALL_ONE / Xbyak_aarch64::T_m, src);
327
+ fdiv(dst, pred / Xbyak_aarch64::T_m, src2);
328
+ }
329
+ }
330
+
331
+ template <typename TReg>
332
+ void uni_fdiv(const TReg &dst, const TReg &src, const TReg &src2) {
333
+ fdiv(dst, src, src2);
334
+ }
335
+
336
+ void uni_fdiv(const Xbyak_aarch64::VReg4S &dst,
337
+ const Xbyak_aarch64::VReg4S &src, const Xbyak_aarch64::VReg4S &src2,
338
+ const Xbyak_aarch64::VReg4S &tmp, const Xbyak_aarch64::PReg &pred) {
339
+ UNUSED(tmp);
340
+ UNUSED(pred);
341
+ fdiv(dst, src, src2);
342
+ }
343
+
344
+ template <typename T>
345
+ void uni_fmad(const T &dst, const T &src, const T &src2) {
346
+ fmad(dst, P_ALL_ONE / Xbyak_aarch64::T_m, src, src2);
347
+ }
348
+
349
+ void uni_fmad(const Xbyak_aarch64::VReg4S &dst,
350
+ const Xbyak_aarch64::VReg4S &src,
351
+ const Xbyak_aarch64::VReg4S &src2) {
352
+ fmul(dst, dst, src);
353
+ fadd(dst, dst, src2);
354
+ }
355
+
356
+ template <typename T>
357
+ void uni_fmax(const T &dst, const T &src, const T &src2) {
358
+ uint32_t dstIdx = dst.getIdx();
359
+ uint32_t srcIdx = src.getIdx();
360
+ if (dstIdx != srcIdx)
361
+ mov(Xbyak_aarch64::ZRegD(dstIdx), Xbyak_aarch64::ZRegD(srcIdx));
362
+ fmax(dst, P_ALL_ONE / Xbyak_aarch64::T_m, src2);
363
+ }
364
+
365
+ template <typename T>
366
+ void uni_fmaxnm(const T &dst, const T &src, const T &src2) {
367
+ uint32_t dstIdx = dst.getIdx();
368
+ uint32_t srcIdx = src.getIdx();
369
+ if (dstIdx != srcIdx)
370
+ mov(Xbyak_aarch64::ZRegD(dstIdx), Xbyak_aarch64::ZRegD(srcIdx));
371
+ fmaxnm(dst, P_ALL_ONE / Xbyak_aarch64::T_m, src2);
372
+ }
373
+
374
+ void uni_fmaxnm(const Xbyak_aarch64::VReg4S &dst,
375
+ const Xbyak_aarch64::VReg4S &src,
376
+ const Xbyak_aarch64::VReg4S &src2) {
377
+ fmaxnm(dst, src, src2);
378
+ }
379
+
380
+ template <typename T>
381
+ void uni_fmin(const T &dst, const T &src, const T &src2) {
382
+ uint32_t dstIdx = dst.getIdx();
383
+ uint32_t srcIdx = src.getIdx();
384
+ if (dstIdx != srcIdx)
385
+ mov(Xbyak_aarch64::ZRegD(dstIdx), Xbyak_aarch64::ZRegD(srcIdx));
386
+ fmin(dst, P_ALL_ONE / Xbyak_aarch64::T_m, src2);
387
+ }
388
+
389
+ template <typename T>
390
+ void uni_fmul(const T &dst, const T &src, const T &src2) {
391
+ fmul(dst, src, src2);
392
+ }
393
+
394
+ void uni_frinti(
395
+ const Xbyak_aarch64::VReg4S &d, const Xbyak_aarch64::VReg4S &s) {
396
+ frinti(d, s);
397
+ }
398
+
399
+ void uni_frinti(
400
+ const Xbyak_aarch64::ZRegS &d, const Xbyak_aarch64::ZRegS &s) {
401
+ frinti(d, P_ALL_ONE / Xbyak_aarch64::T_m, s);
402
+ }
403
+
404
+ template <typename T>
405
+ void uni_fsqrt(const T &dst, const T &src) {
406
+ fsqrt(dst, P_ALL_ONE / Xbyak_aarch64::T_m, src);
407
+ }
408
+
409
+ void uni_fsqrt(const Xbyak_aarch64::VReg4S &dst,
410
+ const Xbyak_aarch64::VReg4S &src) {
411
+ fsqrt(dst, src);
412
+ }
413
+
414
+ void uni_fsub(const Xbyak_aarch64::VReg4S &v1,
415
+ const Xbyak_aarch64::VReg4S &v2, const Xbyak_aarch64::VReg4S &v3) {
416
+ fsub(v1, v2, v3);
417
+ }
418
+
419
+ template <typename T>
420
+ void uni_fsub(const T &dst, const T &src, const T &src2) {
421
+ fsub(dst, src, src2);
422
+ }
423
+
424
+ void uni_fsub(const Xbyak_aarch64::ZRegS &z1,
425
+ const Xbyak_aarch64::ZRegS &z2, const Xbyak_aarch64::ZRegS &z3) {
426
+ fsub(z1, z2, z3);
427
+ }
428
+
429
+ void uni_eor(const Xbyak_aarch64::VReg &v1, const Xbyak_aarch64::VReg &v2,
430
+ const Xbyak_aarch64::VReg &v3) {
431
+ eor(Xbyak_aarch64::VReg16B(v1.getIdx()),
432
+ Xbyak_aarch64::VReg16B(v2.getIdx()),
433
+ Xbyak_aarch64::VReg16B(v3.getIdx()));
434
+ }
435
+
436
+ void uni_eor(const Xbyak_aarch64::ZReg &z1, const Xbyak_aarch64::ZReg &z2,
437
+ const Xbyak_aarch64::ZReg &z3) {
438
+ eor(Xbyak_aarch64::ZRegD(z1.getIdx()),
439
+ Xbyak_aarch64::ZRegD(z2.getIdx()),
440
+ Xbyak_aarch64::ZRegD(z3.getIdx()));
441
+ }
442
+
443
+ void uni_ld1rw(const Xbyak_aarch64::VReg4S &dst,
444
+ const Xbyak_aarch64::XReg &base, const int64_t off) {
445
+ if (off == 0) {
446
+ ld1r(dst, ptr(base));
447
+ } else {
448
+ add_imm(X_DEFAULT_ADDR, base, off, X_TMP_0);
449
+ ld1r(dst, ptr(X_DEFAULT_ADDR));
450
+ }
451
+ }
452
+
453
+ void uni_ld1rw(const Xbyak_aarch64::ZRegS &dst,
454
+ const Xbyak_aarch64::XReg &base, const int64_t off) {
455
+ if (-32 <= off && off < 32) {
456
+ ld1rw(dst, P_ALL_ONE / Xbyak_aarch64::T_z, ptr(base, (int)off));
457
+ } else {
458
+ add_imm(X_DEFAULT_ADDR, base, off, X_TMP_0);
459
+ ld1rw(dst, P_ALL_ONE / Xbyak_aarch64::T_z, ptr(X_DEFAULT_ADDR));
460
+ }
461
+ }
462
+
463
+ void uni_ldr(
464
+ const Xbyak_aarch64::VReg &dst, const Xbyak_aarch64::XReg &addr) {
465
+ ldr(Xbyak_aarch64::QReg(dst.getIdx()), ptr(addr));
466
+ }
467
+
468
+ void uni_ldr(
469
+ const Xbyak_aarch64::ZReg &dst, const Xbyak_aarch64::XReg &addr) {
470
+ ldr(dst, ptr(addr));
471
+ }
472
+
473
+ template <typename T>
474
+ void uni_ldr(const Xbyak_aarch64::ZReg &r, const Xbyak_aarch64::XReg &base,
475
+ const T off) {
476
+ const int off_mod = off % cpu_sveLen;
477
+ const int off_mul_vl = off / cpu_sveLen;
478
+
479
+ if (off_mod == 0 && -256 <= off_mul_vl && off_mul_vl <= 255) {
480
+ ldr(r, Xbyak_aarch64::ptr(base, off_mul_vl, Xbyak_aarch64::MUL_VL));
481
+ } else {
482
+ const int offset = off_mod * 0x10 * (cpu_sveLen / 16);
483
+ add_imm(X_DEFAULT_ADDR, base, offset, X_TMP_0);
484
+ ldr(r, Xbyak_aarch64::ptr(X_DEFAULT_ADDR));
485
+ }
486
+ }
487
+
488
+ template <typename T>
489
+ void uni_ldr(const Xbyak_aarch64::VReg &r, const Xbyak_aarch64::XReg &base,
490
+ const T off) {
491
+ const int off_mod = off % 16;
492
+ const int off_mul_vl = off / 16;
493
+
494
+ if (off_mod == 0 && 0 <= off_mul_vl && off_mul_vl <= 65520) {
495
+ ldr(Xbyak_aarch64::QReg(r.getIdx()), Xbyak_aarch64::ptr(base, off));
496
+ } else {
497
+ add_imm(X_DEFAULT_ADDR, base, off_mod * 4, X_TMP_0);
498
+ ldr(Xbyak_aarch64::QReg(r.getIdx()),
499
+ Xbyak_aarch64::ptr(X_DEFAULT_ADDR));
500
+ }
501
+ }
502
+
503
+ void uni_orr(const Xbyak_aarch64::VReg &d, const Xbyak_aarch64::VReg &s0,
504
+ const Xbyak_aarch64::VReg &s1) {
505
+ orr(d.b16, s0.b16, s1.b16);
506
+ }
507
+
508
+ void uni_orr(const Xbyak_aarch64::ZReg &d, const Xbyak_aarch64::ZReg &s0,
509
+ const Xbyak_aarch64::ZReg &s1) {
510
+ orr(d.d, s0.d, s1.d);
511
+ }
512
+
513
+ void uni_scvtf(
514
+ const Xbyak_aarch64::VReg4S &t0, const Xbyak_aarch64::VReg4S &t1) {
515
+ scvtf(t0, t1);
516
+ }
517
+
518
+ void uni_scvtf(
519
+ const Xbyak_aarch64::ZRegS &t0, const Xbyak_aarch64::ZRegS &t1) {
520
+ scvtf(t0, P_ALL_ONE / Xbyak_aarch64::T_m, t1);
521
+ }
522
+
523
+ void uni_str(
524
+ const Xbyak_aarch64::VReg &src, const Xbyak_aarch64::XReg &addr) {
525
+ str(Xbyak_aarch64::QReg(src.getIdx()), ptr(addr));
526
+ }
527
+
528
+ void uni_str(
529
+ const Xbyak_aarch64::ZReg &src, const Xbyak_aarch64::XReg &addr) {
530
+ str(src, ptr(addr));
531
+ }
532
+
533
+ template <typename T>
534
+ void uni_sub(const T &x1, const T &x2, const T &op) {
535
+ sub(x1, x2, op);
536
+ }
537
+
538
+ /*
539
+ Saturation facility functions. enable to prepare the register
540
+ holding the saturation upperbound and apply the saturation on
541
+ the floating point register
542
+ */
543
+ template <typename Vmm>
544
+ void init_vmm(Vmm vmm, Xbyak_aarch64::XReg reg_tmp, float value) {
545
+ using namespace data_type;
546
+ bool isSVE = get_sve_length() ? true : false;
547
+ Xbyak_aarch64::ZRegS z_tmp(vmm.getIdx());
548
+ Xbyak_aarch64::VReg4S v_tmp(vmm.getIdx());
549
+ Xbyak_aarch64::WReg w_tmp(reg_tmp.getIdx());
550
+ mov_imm(w_tmp, float2int(value));
551
+ if (isSVE) /* SVE is available. */
552
+ dup(z_tmp, w_tmp);
553
+ else
554
+ dup(v_tmp, w_tmp);
555
+ }
556
+
557
+ template <typename Vmm>
558
+ void init_saturate_f32(Vmm vmm_lbound, Vmm vmm_ubound,
559
+ Xbyak_aarch64::XReg reg_tmp, data_type_t idt, data_type_t odt,
560
+ bool force_lbound = false) {
561
+ using namespace data_type;
562
+ bool isSVE = get_sve_length() ? true : false;
563
+
564
+ if (!((idt == f32) && utils::one_of(odt, u8, data_type::s8, s32)))
565
+ return;
566
+
567
+ assert(IMPLICATION(
568
+ idt == u8, vmm_lbound.getIdx() != vmm_ubound.getIdx()));
569
+ // No need to saturate on lower bound for signed integer types, as
570
+ // the conversion to int would return INT_MIN, and then proper
571
+ // saturation will happen in store_data. The param force_lbound, will
572
+ // force saturate values unconditionally to lbound.
573
+ if (odt == u8) {
574
+ if (isSVE) /* SVE is available. */
575
+ dup(Xbyak_aarch64::ZRegS(vmm_lbound.getIdx()), 0);
576
+ else if (mayiuse(asimd))
577
+ movi(Xbyak_aarch64::VReg4S(vmm_lbound.getIdx()), 0);
578
+ else
579
+ assert(!"unreachable");
580
+ } else if (force_lbound) {
581
+ const float saturation_lbound
582
+ = odt == data_type::s8 ? INT8_MIN : INT32_MIN;
583
+ init_vmm(vmm_lbound, reg_tmp, saturation_lbound);
584
+ }
585
+
586
+ float saturation_ubound = types::max_value<float>(odt);
587
+ init_vmm(vmm_ubound, reg_tmp, saturation_ubound);
588
+ }
589
+
590
+ template <typename Vmm>
591
+ void saturate_f32(const Vmm &vmm, const Vmm &vmm_lbound,
592
+ const Vmm &vmm_ubound, data_type_t odt,
593
+ const Xbyak_aarch64::PReg &p_true, bool force_lbound = false) {
594
+ // This function is used to saturate to odt in f32 before converting
595
+ // to s32 in order to avoid bad saturation due to cvtps2dq
596
+ // behavior (it returns INT_MIN if the f32 is out of the
597
+ // s32 range)
598
+ using namespace data_type;
599
+ bool isSVE = get_sve_length() ? true : false;
600
+
601
+ if (!utils::one_of(odt, u8, data_type::s8, s32)) return;
602
+
603
+ Xbyak_aarch64::VReg4S v_tmp(vmm.getIdx());
604
+ Xbyak_aarch64::VReg4S v_lbound(vmm_lbound.getIdx());
605
+ Xbyak_aarch64::VReg4S v_ubound(vmm_ubound.getIdx());
606
+ Xbyak_aarch64::ZRegS z_tmp(vmm.getIdx());
607
+ Xbyak_aarch64::ZRegS z_lbound(vmm_lbound.getIdx());
608
+ Xbyak_aarch64::ZRegS z_ubound(vmm_ubound.getIdx());
609
+
610
+ // no need to apply lower saturation bound when odt is
611
+ // signed, as cvtps2dq will return MIN_INT if the value
612
+ // does not fit. The param force_lbound, will force saturate values
613
+ // unconditionally to lbound.
614
+ if (odt == u8 || force_lbound) {
615
+ if (isSVE) /* SVE is available. */
616
+ fmax(z_tmp, p_true / Xbyak_aarch64::T_m, z_lbound);
617
+ else if (mayiuse(asimd))
618
+ fmax(v_tmp, v_tmp, v_lbound);
619
+ else
620
+ assert(!"unreachable");
621
+ }
622
+ if (isSVE) /* SVE is available. */
623
+ fmin(z_tmp, p_true / Xbyak_aarch64::T_m, z_ubound);
624
+ else if (mayiuse(asimd))
625
+ fmin(v_tmp, v_tmp, v_ubound);
626
+ else
627
+ assert(!"unreachable");
628
+ }
629
+
630
+ /* A utility function to process f32 tail (load, store or other) depending
631
+ * on tail size, stored in Reg64. Tail size must be value from 0 to 3/7
632
+ * (Xmm/Ymm). Tail process functions require integer as argument to specify
633
+ * behavior for each tail size.
634
+ *
635
+ * Only supported for Xmm and Ymm.
636
+ */
637
+ template <cpu_isa_t isa>
638
+ void runtime_tail_process(const Xbyak_aarch64::XReg &reg_tail,
639
+ const Xbyak_aarch64::XReg &reg_tmp,
640
+ const std::function<void(int)> &tail_process) {
641
+ constexpr int simd_w_ymm = 8;
642
+ constexpr int f32_bits = sizeof(float) * 8;
643
+ const auto simd_w = cpu_isa_traits<isa>::vlen * 8 / f32_bits;
644
+ assert(simd_w != cpu_isa_traits<isa>::vlen * 8 / f32_bits);
645
+
646
+ Xbyak_aarch64::Label label_tbl, label_tbl_end;
647
+ Xbyak_aarch64::Label l_case[simd_w_ymm];
648
+
649
+ adr(reg_tmp, label_tbl);
650
+ mov_imm(X_TMP_0, sizeof(void *));
651
+ madd(X_DEFAULT_ADDR, reg_tail, X_TMP_0, reg_tmp);
652
+ br(X_DEFAULT_ADDR);
653
+
654
+ // create jump table
655
+ L(label_tbl);
656
+ for (size_t i = 0; i < simd_w; i++)
657
+ putL(l_case[i]);
658
+
659
+ // cases for each tail size - from 0 to 3/7
660
+ L(l_case[0]);
661
+ b(label_tbl_end);
662
+ for (size_t i = 1; i < simd_w; i++) {
663
+ L(l_case[i]);
664
+ tail_process(i);
665
+ b(label_tbl_end);
666
+ }
667
+ L(label_tbl_end);
668
+ }
669
+
670
+ DNNL_DISALLOW_COPY_AND_ASSIGN(jit_generator);
671
+
672
+ public:
673
+ jit_generator(void *code_ptr = nullptr, size_t code_size = MAX_CODE_SIZE,
674
+ bool use_autogrow = true)
675
+ : Xbyak_aarch64::CodeGenerator(code_size,
676
+ (code_ptr == nullptr && use_autogrow) ? Xbyak_aarch64::AutoGrow
677
+ : code_ptr) {}
678
+ virtual ~jit_generator() {}
679
+
680
+ virtual const char *name() const = 0;
681
+ virtual const char *source_file() const = 0;
682
+
683
+ void register_jit_code(const uint8_t *code, size_t code_size) const {
684
+ jit_utils::register_jit_code(code, code_size, name(), source_file());
685
+ }
686
+
687
+ const uint8_t *jit_ker() const { return jit_ker_; }
688
+
689
+ template <typename... kernel_args_t>
690
+ void operator()(kernel_args_t... args) const {
691
+ using jit_kernel_func_t = void (*)(const kernel_args_t... args);
692
+ auto *fptr = (jit_kernel_func_t)jit_ker_;
693
+ (*fptr)(std::forward<kernel_args_t>(args)...);
694
+ }
695
+
696
+ virtual status_t create_kernel() {
697
+ generate();
698
+ jit_ker_ = getCode();
699
+ return (jit_ker_) ? status::success : status::runtime_error;
700
+ }
701
+
702
+ private:
703
+ const uint8_t *getCode() {
704
+ this->ready();
705
+ if (!is_initialized()) return nullptr;
706
+ const uint8_t *code
707
+ = reinterpret_cast<const uint8_t *>(CodeGenerator::getCode());
708
+ register_jit_code(code, getSize() * CSIZE);
709
+ return code;
710
+ }
711
+
712
+ static inline bool is_initialized() {
713
+ /* At the moment, Xbyak_aarch64 does not have GetError()\
714
+ so that return dummy result. */
715
+ return true;
716
+ }
717
+
718
+ protected:
719
+ virtual void generate() = 0;
720
+ const uint8_t *jit_ker_ = nullptr;
721
+ };
722
+
723
+ } // namespace aarch64
724
+ } // namespace cpu
725
+ } // namespace impl
726
+ } // namespace dnnl
727
+
728
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_op_imm_check.hpp ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2021 FUJITSU LIMITED
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 JIT_OP_IMM_CHECK_HPP
18
+ #define JIT_OP_IMM_CHECK_HPP
19
+
20
+ #define LDRMAX 255
21
+ #define LDRMIN (-256)
22
+ #define STRMAX 255
23
+ #define STRMIN (-256)
24
+ #define LD1RWMAX 252
25
+ #define PRFMMAX 32760
26
+ #define PRFMMIN 0
27
+ #define PRFWMAX 31
28
+ #define PRFWMIN (-32)
29
+
30
+ namespace dnnl {
31
+ namespace impl {
32
+ namespace cpu {
33
+ namespace aarch64 {
34
+
35
+ // Check the immediate value for LDR(vector) instruction
36
+ //
37
+ // The imm9 in the LDR instruction is the optional signed immediate vector
38
+ // offset, in the range -256 to 255, defaulting to 0.
39
+ template <typename T>
40
+ bool ldr_imm_check(T ofs) {
41
+ int vlen = cpu_isa_traits<sve_512>::vlen;
42
+ int vlen_shift = cpu_isa_traits<sve_512>::vlen_shift;
43
+ int shifted_ofs = ofs >> vlen_shift;
44
+ return ((shifted_ofs) <= LDRMAX) && (shifted_ofs >= LDRMIN)
45
+ && ((ofs % vlen) == 0);
46
+ }
47
+
48
+ // Check the immediate value for SDR(vector) instruction
49
+ //
50
+ // The imm9 in the STR instruction is the optional signed immediate vector
51
+ // offset, in the range -256 to 255, defaulting to 0.
52
+ template <typename T>
53
+ bool str_imm_check(T ofs) {
54
+ int vlen = cpu_isa_traits<sve_512>::vlen;
55
+ int vlen_shift = cpu_isa_traits<sve_512>::vlen_shift;
56
+ int shifted_ofs = ofs >> vlen_shift;
57
+ return ((shifted_ofs) <= STRMAX) && (shifted_ofs >= STRMIN)
58
+ && ((ofs % vlen) == 0);
59
+ }
60
+
61
+ // Check the immediate value for LD1RW instruction
62
+ //
63
+ // The imm6 in the LD1RW instruction is the optional unsigned immediate byte
64
+ // offset, a multiple of 4 in the range 0 to 252, defaulting to 0.
65
+ template <typename T>
66
+ bool ld1rw_imm_check(T ofs) {
67
+ return ((ofs & 0x3) == 0) && (ofs <= LD1RWMAX) && (ofs >= 0);
68
+ }
69
+
70
+ // Check the immediate value for PRFM(immediate) instruction
71
+ //
72
+ // The pimm in the PRFM instruction is the optional positive immediate byte
73
+ // offset, a multiple of 8 in the range 0 to 32760, defaulting to 0.
74
+ template <typename T>
75
+ bool prfm_imm_check(T ofs) {
76
+ return (ofs <= PRFMMAX) && (ofs >= PRFMMIN) && ((ofs & 0x7) == 0);
77
+ }
78
+
79
+ // Check the immediate value for PRFW(scalar plus immediate) instruction
80
+ //
81
+ // The imm6 in the PRFW instruction is the optional signed immediate vector
82
+ // offset, in the range -32 to 31, defaulting to 0.
83
+ template <typename T>
84
+ bool prfw_imm_check(T ofs) {
85
+ int vlen = cpu_isa_traits<sve_512>::vlen;
86
+ int vlen_shift = cpu_isa_traits<sve_512>::vlen_shift;
87
+ int shifted_ofs = ofs >> vlen_shift;
88
+
89
+ return (shifted_ofs <= PRFWMAX) && (shifted_ofs >= PRFWMIN)
90
+ && ((ofs % vlen) == 0);
91
+ }
92
+
93
+ } // namespace aarch64
94
+ } // namespace cpu
95
+ } // namespace impl
96
+ } // namespace dnnl
97
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_primitive_conf.hpp ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2016-2022 Intel Corporation
3
+ * Copyright 2020-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_PRIMITIVE_CONF_HPP
19
+ #define CPU_AARCH64_JIT_PRIMITIVE_CONF_HPP
20
+
21
+ #include <stdint.h>
22
+
23
+ #include "common/primitive_attr.hpp"
24
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
25
+
26
+ namespace dnnl {
27
+ namespace impl {
28
+ namespace cpu {
29
+ namespace aarch64 {
30
+
31
+ enum class jit_memory_tag_kind_t { ncsp, nspc, blocked, undef };
32
+
33
+ /* convolution */
34
+ enum conv_version_t {
35
+ ver_unused,
36
+ ver_fma,
37
+ ver_sve_512,
38
+ };
39
+
40
+ enum conv_loop_order_t {
41
+ loop_cgn,
42
+ loop_gnc,
43
+ loop_ngc,
44
+ loop_gncw,
45
+ loop_cwgn,
46
+ loop_ngcw,
47
+ loop_nhwcg,
48
+ loop_nwcg
49
+ };
50
+
51
+ enum conv_kernel_kind_t { embd_bcast, expl_bcast };
52
+
53
+ enum conv_1x1_loop_order_t {
54
+ loop_rbl,
55
+ loop_rlb,
56
+ loop_lbr,
57
+ loop_lrb,
58
+ loop_blr,
59
+ loop_brl
60
+ };
61
+
62
+ enum conv_harness_t {
63
+ harness_2d_reduction,
64
+ harness_3d_reduction,
65
+ harness_mb_reduction,
66
+ harness_compute_full_spatial,
67
+ harness_nxc
68
+ };
69
+
70
+ enum {
71
+ FLAG_MB_FIRST = 1 << 0,
72
+ FLAG_MB_LAST = 1 << 1,
73
+ FLAG_OC_FIRST = 1 << 2,
74
+ FLAG_OC_LAST = 1 << 3,
75
+ FLAG_IC_FIRST = 1 << 4,
76
+ FLAG_IC_LAST = 1 << 5,
77
+ FLAG_SP_FIRST = 1 << 6,
78
+ FLAG_SP_LAST = 1 << 7,
79
+ FLAG_REDUCE_FIRST = 1 << 8,
80
+ FLAG_REDUCE_LAST = 1 << 9,
81
+ FLAG_ZERO_FILTER = 1 << 0, /* Controls whether the inner kernel skips
82
+ loading weights-data from memory; this
83
+ needs to happen on the first Group/16
84
+ iteration. */
85
+ FLAG_ZERO_BIAS = 1 << 1, /* Controls whether the inner kernel skip
86
+ loading bias data from memory */
87
+ FLAG_COMPUTE_BIAS = 1 << 2, /* Controls bias computation during execution
88
+ pass */
89
+ };
90
+
91
+ struct jit_conv_conf_t {
92
+ prop_kind_t prop_kind;
93
+ conv_version_t ver;
94
+ conv_loop_order_t loop_order;
95
+ conv_harness_t harness;
96
+
97
+ int simd_w;
98
+ int ndims;
99
+ int mb;
100
+ int ngroups, ic, oc, oc_without_padding, ic_without_padding;
101
+ int id, ih, iw, od, oh, ow;
102
+ int f_pad, l_pad, t_pad;
103
+ int back_pad, r_pad, b_pad;
104
+ int kd, kh, kw;
105
+ int stride_d, stride_h, stride_w;
106
+ int dilate_d, dilate_h, dilate_w;
107
+ format_tag_t src_tag, wei_tag, dst_tag; // temporary workaround
108
+ bool with_bias;
109
+ bool with_sum;
110
+ bool with_eltwise;
111
+ bool with_binary;
112
+
113
+ bool is_fused_conv;
114
+ int dw_conv_buffer_oc;
115
+
116
+ post_ops_t::entry_t::eltwise_t eltwise;
117
+ post_ops_t post_ops;
118
+
119
+ int nthr, nthr_mb, nthr_g, nthr_oc_b, nthr_ic_b;
120
+
121
+ int idp, ihp, iwp, ohp, owp;
122
+ int nb_ic, ic_block;
123
+ int nb_oc, oc_block;
124
+ int nb_iw, iw_block;
125
+ int nb_ow, ow_block;
126
+ int nb_oc_blocking; /* used in jit kernels for nb_oc work blocking taking
127
+ into account vector registers distribution */
128
+ int nb_oc_blocking_thr_chunk; /* used for distribution of nb_oc work
129
+ within threads */
130
+ int nb_ic_blocking, nb_ic_blocking_max; // blocking of nb_ic work
131
+ int nb_ic_L2;
132
+ int h_blocking;
133
+ int nb_oc_L2;
134
+ int ic_tail, oc_tail;
135
+ int ur_h, ur_w;
136
+ int ur_w_tail;
137
+ int ur_ic, ur_kw;
138
+ bool is_1stconv;
139
+ int nonblk_group_off;
140
+ /* fma sve512_core */
141
+ conv_kernel_kind_t kernel_kind;
142
+
143
+ int tr_iw, tr_ih;
144
+ int tr_kw, tr_kh;
145
+ int tr_src_num_guard_elems;
146
+
147
+ // Transpose buffer management
148
+ size_t tr_src_buf_size, tr_src_buf_count;
149
+ size_t tr_diff_dst_buf_size, tr_diff_dst_buf_count;
150
+ int nthr_mb_work;
151
+
152
+ /* 1st conv */
153
+ int tr_ld;
154
+ int kh_step;
155
+ /* sve_512_u8s8u8 */
156
+ int typesize_in;
157
+ int typesize_out;
158
+ int typesize_bia;
159
+ int typesize_acc;
160
+ int ic_nb1, ic_nb2;
161
+ int oc_nb1;
162
+ int ur_ow_max, ur_ow, ur_ow_tail;
163
+ int ur_ow_nsteps;
164
+ data_type_t bia_dt;
165
+ /* bf16 data-type for output */
166
+ data_type_t dst_dt;
167
+ data_type_t src_dt;
168
+ /* bf16 weights update */
169
+ data_type_t wei_dt;
170
+ data_type_t dsrc_dt;
171
+ data_type_t dwei_dt;
172
+ bool expl_bcast;
173
+ bool large_spatial, large_w_filter;
174
+ int is_oc_scale;
175
+ int max_regs_ur; // maximum accumulation registers
176
+ // dw conv
177
+ int nb_ch, ch_block, nb_ch_blocking;
178
+ bool is_depthwise, is_fast_depthwise, is_resrc_depthwise;
179
+ int aligned_threads;
180
+ // large spatial
181
+ int h_blk_size, oh_blk_size;
182
+ // s8s8 convolution
183
+ bool signed_input;
184
+ bool need_saturation;
185
+ float wei_adj_scale;
186
+ // zero-point compensation
187
+ bool src_zero_point;
188
+ bool dst_zero_point;
189
+ bool zp_src_is_common; // common, otherwise (TODO) per-channel
190
+
191
+ bool uses_permw_transposition;
192
+ bool transpose_src;
193
+ bool transpose_dst;
194
+ int ic_block_step;
195
+
196
+ cpu_isa_t isa;
197
+
198
+ bool is_hw_transp; // spatial dim height-width transposed
199
+ };
200
+
201
+ // calculates filter size taking into account dilation
202
+ inline int calculate_extended_filter_size(int filter_size, int dilation) {
203
+ return (filter_size - 1) * (dilation + 1) + 1;
204
+ }
205
+
206
+ inline int calculate_end_padding(int start_padding, int dst_size, int src_size,
207
+ int spatial_stride, int dilated_filter_size) {
208
+ return (dst_size - 1) * spatial_stride + dilated_filter_size
209
+ - (src_size + start_padding);
210
+ }
211
+
212
+ inline status_t init_tag(format_tag_t &tag, const memory_desc_wrapper &mdw,
213
+ const format_tag_t &tag_value) {
214
+ if (mdw.format_kind() == format_kind::any) return status::unimplemented;
215
+
216
+ tag = mdw.matches_one_of_tag(tag_value);
217
+ return tag == tag_value ? status::success : status::unimplemented;
218
+ }
219
+
220
+ struct jit_conv_call_s {
221
+ const void *src; /* hack, non-const for backward_data */
222
+ const void *dst; /* hack, non-const for forward */
223
+ const void *filt; /* hack, non-const for backward_weights */
224
+ const void *bias; /* hack, non-const for backward_bias */
225
+ const void *src_prf;
226
+ const void *dst_prf;
227
+ const void *filt_prf;
228
+ const void *bias_prf;
229
+ const void *scales;
230
+ const void *acc_s32;
231
+ const void *compensation;
232
+ const int32_t *zp_compensation;
233
+ const int32_t *src_zero_point;
234
+ const int32_t *dst_zero_point;
235
+ const void *tile_cfg;
236
+ const void *tile_cfg_tail;
237
+
238
+ // ptr to table of void * elements that are pointers to
239
+ // post_op binary src1 tensors
240
+ const void *post_ops_binary_rhs_arg_vec;
241
+ // logical (# of elems) offset to the processed output channel
242
+ // (for broadcasting [1,OC,1,1])
243
+ size_t oc_l_off;
244
+ const void *dst_orig; // pointer to dst memory (no offset)
245
+
246
+ size_t oc_l_off_prf;
247
+ const void *dst_orig_prf;
248
+
249
+ size_t kd_offset;
250
+ size_t kd_offset_prf;
251
+ size_t kh_offset;
252
+ size_t kh_offset_prf;
253
+ size_t os_index_begin;
254
+ size_t os_index_begin_prf;
255
+ size_t os_index_end;
256
+ size_t os_index_end_prf;
257
+ size_t kd_padding;
258
+ size_t kd_padding_prf;
259
+ size_t kh_padding;
260
+ size_t kh_padding_prf;
261
+ size_t iwb;
262
+ size_t iwb_prf;
263
+ size_t owb;
264
+ size_t owb_prf;
265
+ size_t kw_padding;
266
+ size_t channel;
267
+ size_t channel_prf;
268
+ size_t oc_blocks;
269
+ size_t ur_w;
270
+ size_t ur_str_w;
271
+ size_t ch_blocks;
272
+ size_t ch_blocks_prf;
273
+ size_t reduce_work;
274
+ size_t reduce_work_prf;
275
+ size_t load_work;
276
+ size_t load_work_prf;
277
+ size_t t_overflow;
278
+ size_t b_overflow;
279
+ size_t f_overflow;
280
+ size_t back_overflow;
281
+ size_t last_h;
282
+ size_t tail;
283
+ size_t current_iw;
284
+ size_t is_osb;
285
+ int flags;
286
+ int flags_prf;
287
+ int oc_flag;
288
+ };
289
+
290
+ struct jit_deconv_call_s {
291
+ const void *src; /* hack, non-const for backward_data */
292
+ const void *dst; /* hack, non-const for forward */
293
+ const void *filt; /* hack, non-const for backward_weights */
294
+ const void *bias; /* hack, non-const for backward_bias */
295
+ const void *scales;
296
+ const void *compensation;
297
+ const int32_t *zp_src_pad_str_compensation;
298
+ const int32_t *zp_compensation;
299
+ const int32_t *src_zero_point;
300
+ const int32_t *dst_zero_point;
301
+
302
+ /*
303
+ * ptr to table of void * elements that are pointers to post_op binary
304
+ * src1 tensors
305
+ */
306
+ const void *post_ops_binary_rhs_arg_vec;
307
+ const void *dst_orig; /* pointer to dst memory (no offset) */
308
+ /*
309
+ * logical (# of elems) offset to the processed output channel
310
+ * (for broadcasting [1,OC,1,1])
311
+ */
312
+ size_t oc_l_off;
313
+ size_t t_overflow;
314
+ size_t b_overflow;
315
+ size_t f_overflow;
316
+ size_t back_overflow;
317
+ size_t kh_padding;
318
+ size_t kd_padding;
319
+ size_t oc_blocks;
320
+ };
321
+
322
+ struct jit_dw_conv_call_s {
323
+ const void *input;
324
+ const void *output;
325
+ const void *filter;
326
+ const void *bias;
327
+ size_t kh_count;
328
+ size_t oh_count;
329
+ size_t oh_index;
330
+ size_t filter_pad_off;
331
+ unsigned char
332
+ exec_flags; /* Flags passed by driver execution to inner kernel */
333
+ };
334
+
335
+ struct jit_1x1_conv_conf_t {
336
+ prop_kind_t prop_kind;
337
+ conv_version_t ver;
338
+
339
+ int ndims;
340
+ int mb;
341
+ int ngroups, ic, oc, oc_without_padding, ic_without_padding;
342
+ int id, ih, iw, od, oh, ow;
343
+ int f_pad, t_pad, l_pad;
344
+ int kd, kh, kw;
345
+ int stride_d, stride_h, stride_w;
346
+ format_tag_t src_tag, wei_tag, dst_tag; // temporary workaround
347
+ bool with_bias;
348
+ bool with_sum;
349
+ bool with_eltwise;
350
+ bool with_binary;
351
+ bool with_dw_conv;
352
+
353
+ post_ops_t post_ops;
354
+ post_ops_t::entry_t::eltwise_t eltwise;
355
+
356
+ int is, os;
357
+ int ic_block, oc_block;
358
+
359
+ int ur, ur_tail;
360
+
361
+ int reduce_dim, reduce_block, nb_reduce, nb_reduce_blocking,
362
+ nb_reduce_blocking_max;
363
+ int load_dim, load_block, nb_load, nb_load_blocking, nb_load_blocking_max,
364
+ nb_load_chunk;
365
+ int bcast_dim, bcast_block, nb_bcast, nb_bcast_blocking,
366
+ nb_bcast_blocking_max;
367
+
368
+ int reduce_loop_unroll, reduce_loop_bcast_step, reduce_loop_load_step;
369
+ int load_loop_load_step, load_loop_iter_step;
370
+ int bcast_loop_output_step, bcast_loop_output_substep;
371
+ int bcast_loop_bcast_step, bcast_loop_bcast_substep;
372
+ int fma_step;
373
+ int load_grp_count;
374
+ conv_1x1_loop_order_t loop_order;
375
+ bool use_vmovntps;
376
+ /* sve512 core */
377
+ bool expl_bcast;
378
+ int typesize_in;
379
+ int typesize_out;
380
+ int typesize_bia;
381
+ int typesize_acc;
382
+ /* 4fma */
383
+ bool transpose_src;
384
+ int tr_is;
385
+ int nthr, nthr_mb, nthr_g, nthr_oc_b, nthr_ic_b;
386
+ int is_oc_scale;
387
+ data_type_t bia_dt;
388
+ data_type_t dst_dt;
389
+ bool signed_input;
390
+ float wei_adj_scale;
391
+ // zero-point compensation
392
+ bool src_zero_point;
393
+ bool dst_zero_point;
394
+ bool zp_src_is_common; // common, otherwise (TODO) per-channel
395
+
396
+ cpu_isa_t isa;
397
+ bool uses_permw_transposition;
398
+ };
399
+
400
+ struct jit_1x1_conv_call_s {
401
+ const void *bcast_data;
402
+ const void *load_data;
403
+ const void *output_data;
404
+ const void *bias_data; // used in forward and backward_weights only
405
+ const void *acc_s32;
406
+ const void *scales;
407
+ const void *compensation;
408
+ const void *store_buffer;
409
+ const int32_t *zp_compensation;
410
+ const int32_t *src_zero_point;
411
+ const int32_t *dst_zero_point;
412
+
413
+ // ptr to table of void * elements that are pointers to
414
+ // post_op binary src1 tensors
415
+ const void *post_ops_binary_rhs_arg_vec;
416
+ // logical (# of elems) offset to the processed output channel
417
+ // (for broadcasting [1,OC,1,1])
418
+ size_t oc_l_off;
419
+ const void *dst_orig; // pointer to dst memory (not offseted)
420
+
421
+ size_t load_dim;
422
+ size_t bcast_dim;
423
+ size_t reduce_dim;
424
+
425
+ size_t output_stride; // used in backward_weights only
426
+
427
+ size_t first_last_flag;
428
+ };
429
+
430
+ struct jit_pool_conf_t {
431
+ int ndims;
432
+ int mb, c, c_without_padding;
433
+ int id, ih, iw, od, oh, ow;
434
+ int stride_d, stride_h, stride_w;
435
+ int kd, kh, kw;
436
+ int f_pad, t_pad, l_pad;
437
+ alg_kind_t alg;
438
+ bool is_training;
439
+ bool pad_w_is_null;
440
+ bool is_backward;
441
+ bool simple_alg;
442
+ bool is_c_padded;
443
+ data_type_t ind_dt;
444
+
445
+ int c_block, c_tail, nb_c;
446
+ int ur_bc, ur_bc_tail;
447
+ int ur_c, ur_c_tail;
448
+ int ur;
449
+ size_t tail[4];
450
+ bool safe_c_tail;
451
+ data_type_t src_dt;
452
+ data_type_t dst_dt;
453
+
454
+ int dt_size;
455
+ bool is_bf16;
456
+ bool is_f16;
457
+ jit_memory_tag_kind_t tag_kind;
458
+ bool is_plain() const {
459
+ return (tag_kind == jit_memory_tag_kind_t::ncsp
460
+ || tag_kind == jit_memory_tag_kind_t::nspc);
461
+ }
462
+
463
+ cpu_isa_t isa;
464
+ post_ops_t post_ops;
465
+ bool with_postops;
466
+ bool with_eltwise;
467
+ bool with_binary;
468
+ int nthr;
469
+ memory_desc_t tmp_md;
470
+ };
471
+
472
+ struct jit_pool_call_s {
473
+ const void *src;
474
+ const void *dst;
475
+ const void *indices;
476
+ const void *src_prf;
477
+ const void *dst_prf;
478
+ const void *indices_prf;
479
+ const void *post_ops_binary_rhs_arg_vec;
480
+ const void *dst_orig;
481
+ const void *dst_po_helper;
482
+ size_t zero_ih;
483
+ size_t zero_id;
484
+ const void *zero_ptr;
485
+ size_t kd_padding;
486
+ size_t kh_padding;
487
+ size_t kh_padding_shift;
488
+ size_t kd_padding_shift;
489
+ size_t kw_padding;
490
+ const void *init_value;
491
+ float ker_area_h;
492
+ size_t ur_bc; // contains number of channel blocks to processing
493
+ size_t b_c; // contains number of channel blocks already processed
494
+ };
495
+
496
+ struct jit_shuffle_conf_t {
497
+ unsigned ndims = 0;
498
+
499
+ unsigned mb = 0, c = 0, d = 0, h = 0, w = 0, sp = 0;
500
+
501
+ unsigned stride_mb = 0;
502
+ unsigned blk_size = 0;
503
+ unsigned group_size = 0;
504
+ unsigned axis = 0;
505
+ unsigned axis_size = 0;
506
+ unsigned simd_tail = 0;
507
+ unsigned simd_w = 0;
508
+
509
+ jit_memory_tag_kind_t tag_kind = jit_memory_tag_kind_t::undef;
510
+ data_type_t data_type = data_type::undef;
511
+ size_t dt_size = 0;
512
+ unsigned el_size_of_indices = 0;
513
+ dim_t c_split_size = 0;
514
+ dim_t sp_split_size = 0;
515
+
516
+ cpu_isa_t isa = isa_undef;
517
+ };
518
+
519
+ struct jit_shuffle_call_s {
520
+ const void *src = nullptr;
521
+ void *dst = nullptr;
522
+ const void *input_off_ptr = nullptr;
523
+
524
+ dim_t cb_loop_size
525
+ = 0; // number of loop iterations over corresponding C batches
526
+ bool is_padded_block = false;
527
+ };
528
+
529
+ enum class binary_op_t : unsigned { none, c_blocked, n_spatial_c, n_c_spatial };
530
+
531
+ enum class binary_bcast_t : unsigned {
532
+ none, // tensor operation
533
+ scalar,
534
+ per_batch,
535
+ per_c,
536
+ per_w
537
+ };
538
+
539
+ struct jit_binary_conf_t {
540
+ binary_op_t op_type = binary_op_t::none;
541
+ binary_bcast_t bcast_type = binary_bcast_t::none;
542
+ bool do_scale_src0 = false;
543
+ bool do_scale_src1 = false;
544
+ bool do_sum = false;
545
+ bool with_eltwise = false;
546
+ bool with_binary = false;
547
+ bool with_postops = false;
548
+ float sum_scale = 0.f;
549
+ bool use_stride_src1 = false;
550
+ bool broadcast_src1_value = false;
551
+ bool use_stride_rhs_postops = false;
552
+ bool postops_per_oc_broadcast_exists = false;
553
+ bool is_i8 = false;
554
+ bool is_bf16 = false;
555
+ bool is_src_different_layouts = false;
556
+ dim_t outer_dims = 1;
557
+ int src1_stride = 1;
558
+ int not_bcasted_sp_dims = 0;
559
+ cpu_isa_t isa = isa_undef;
560
+
561
+ data_type_t src0_type = data_type::undef;
562
+ data_type_t src1_type = data_type::undef;
563
+ data_type_t dst_type = data_type::undef;
564
+ };
565
+
566
+ struct jit_binary_call_s {
567
+ // keep all sizes at 8 bytes -- jit code expects this
568
+ const void *src0, *src1, *dst, *indices;
569
+ const float *scales_src0, *scales_src1;
570
+ size_t spat_offt_count;
571
+ const void *post_ops_binary_rhs_arg_vec;
572
+ size_t src1_stride_range;
573
+ const void *dst_orig;
574
+ };
575
+
576
+ } // namespace aarch64
577
+ } // namespace cpu
578
+ } // namespace impl
579
+ } // namespace dnnl
580
+
581
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_1x1_conv_kernel.hpp ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Intel Corporation
3
+ * Copyright 2021-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_1x1_CONV_KERNEL_HPP
19
+ #define CPU_AARCH64_JIT_SVE_1x1_CONV_KERNEL_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/memory_tracking.hpp"
23
+
24
+ #include "cpu/aarch64/injectors/jit_uni_postops_injector.hpp"
25
+ #include "cpu/aarch64/jit_generator.hpp"
26
+ #include "cpu/aarch64/jit_op_imm_check.hpp"
27
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
28
+
29
+ using namespace Xbyak_aarch64;
30
+
31
+ namespace dnnl {
32
+ namespace impl {
33
+ namespace cpu {
34
+ namespace aarch64 {
35
+
36
+ /* Get vector offsets, ofs / VL(VL: 512bits = 64Bytes) */
37
+ #define VL64_OFS(ofs) ((ofs) >> 6)
38
+
39
+ struct jit_sve_512_1x1_conv_kernel : public jit_generator {
40
+ jit_sve_512_1x1_conv_kernel(const jit_1x1_conv_conf_t &ajcp,
41
+ const primitive_attr_t &attr, const memory_desc_t &dst_md);
42
+
43
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_sve_512_1x1_conv_kernel)
44
+
45
+ static status_t init_conf(jit_1x1_conv_conf_t &jcp,
46
+ const convolution_desc_t &cd, const memory_desc_wrapper &src_d,
47
+ const memory_desc_wrapper &weights_d,
48
+ const memory_desc_wrapper &dst_d, const primitive_attr_t &attr,
49
+ int nthreads, bool reduce_src);
50
+
51
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
52
+ const jit_1x1_conv_conf_t &jcp);
53
+
54
+ jit_1x1_conv_conf_t jcp;
55
+ const primitive_attr_t &attr_;
56
+
57
+ private:
58
+ using reg64_t = const XReg;
59
+
60
+ /* Flags and loop variables */
61
+ reg64_t reg_reduce_pos_flag = x1;
62
+ reg64_t reduce_loop_iter = x2;
63
+ reg64_t reg_bcast_loop_iter = x3;
64
+ reg64_t reg_relu_ns = x20; // For forward
65
+ reg64_t reg_output_stride = x20; // For backward
66
+
67
+ /* Pointer */
68
+ reg64_t reg_bcast_data = x5; // Input
69
+ reg64_t reg_load_data = x6; // Weight
70
+ reg64_t reg_output_data = x7; // Output
71
+ reg64_t reg_bias_data = x8; // bias
72
+ reg64_t aux1_reg_bcast_data = x9;
73
+ reg64_t aux_reg_output_data = x10;
74
+ reg64_t aux_reg_bcast_data = x11;
75
+ reg64_t aux_reg_load_data = x12;
76
+ reg64_t reg_prev_bcast_addr
77
+ = x13; // Input: The reg keeps addr accessed by previous ldr inst
78
+ reg64_t reg_prev_out_addr
79
+ = x14; // Output: The reg keeps addr accessed by previous ldr or str inst
80
+
81
+ /* Workload */
82
+ reg64_t reg_load_loop_work = x15;
83
+ reg64_t reg_reduce_loop_work = x16;
84
+ reg64_t reg_bcast_loop_work = x17;
85
+
86
+ /* Temporay registers */
87
+ reg64_t reg_tmp_imm = x27; // tmp for add_imm
88
+ reg64_t reg_tmp_ofs = x19; // tmp reg to calc bwd wei offset in out_load
89
+
90
+ reg64_t reg_load_dim_tail_mask = aux_reg_load_data;
91
+
92
+ std::unique_ptr<injector::jit_uni_postops_injector_t<sve_512>>
93
+ postops_injector_;
94
+
95
+ constexpr static int isa_simd_width_
96
+ = cpu_isa_traits<sve_512>::vlen / sizeof(float);
97
+
98
+ ZReg vreg_bcast = ZReg(31);
99
+ PReg k_load_dim_mask = p2;
100
+ PReg k_load_dim_tail_mask = p3;
101
+ ZReg zreg_tmp = ZReg(31);
102
+ ZReg zreg_tmp1 = ZReg(30);
103
+
104
+ constexpr static int reg64_size_ = sizeof(int64_t);
105
+ constexpr static int reg_bcast_loop_work_offt = 0;
106
+ constexpr static int reg_binary_post_op_acc_off = 1 * reg64_size_;
107
+ constexpr static int reg_abi_param1_backup = 2 * reg64_size_;
108
+ constexpr static int stack_space_needed = 3 * reg64_size_;
109
+
110
+ template <typename T>
111
+ Xbyak_aarch64::XReg EVEX_compress_addr(const Xbyak_aarch64::XReg &addr,
112
+ const Xbyak_aarch64::XReg &x_tmp, Xbyak_aarch64::XReg base,
113
+ T raw_offt, bool bcast = false) {
114
+
115
+ assert(raw_offt <= INT_MAX);
116
+ auto offt = static_cast<int>(raw_offt);
117
+
118
+ add_imm(addr, base, offt, x_tmp);
119
+ if (bcast) {
120
+ // addr is the same as addr when bcast is false.
121
+ }
122
+ return addr;
123
+ }
124
+
125
+ void prefetch(
126
+ const std::string prfop, int level, reg64_t in, long long int ofs) {
127
+ bool for_load = false;
128
+ if (prfop == "LD") {
129
+ for_load = true;
130
+ } else if (prfop == "ST") {
131
+ for_load = false;
132
+ } else {
133
+ assert(!"invalid prfop");
134
+ }
135
+
136
+ bool cacheline_aligned = ((ofs & 0xFF) == 0) ? true : false;
137
+ if (cacheline_aligned == true) {
138
+ Prfop op;
139
+ switch (level) {
140
+ case 1: op = (for_load == true) ? PLDL1KEEP : PSTL1KEEP; break;
141
+ case 2: op = (for_load == true) ? PLDL2KEEP : PSTL2KEEP; break;
142
+ case 3: op = (for_load == true) ? PLDL3KEEP : PSTL3KEEP; break;
143
+ default: assert(!"invalid prfop"); break;
144
+ }
145
+
146
+ if (prfm_imm_check(ofs)) {
147
+ prfm(op, ptr(in, static_cast<int32_t>(ofs)));
148
+ } else {
149
+ add_imm(reg_tmp_ofs, in, ofs, reg_tmp_imm);
150
+ prfm(op, ptr(reg_tmp_ofs));
151
+ }
152
+ } else {
153
+ PrfopSve op_sve;
154
+ switch (level) {
155
+ case 1:
156
+ op_sve = (for_load == true) ? PLDL1KEEP_SVE : PSTL1KEEP_SVE;
157
+ break;
158
+ case 2:
159
+ op_sve = (for_load == true) ? PLDL2KEEP_SVE : PSTL2KEEP_SVE;
160
+ break;
161
+ case 3:
162
+ op_sve = (for_load == true) ? PLDL3KEEP_SVE : PSTL3KEEP_SVE;
163
+ break;
164
+ default: assert(!"invalid prfop"); break;
165
+ }
166
+
167
+ if (prfw_imm_check(ofs)) {
168
+ prfw(op_sve, P_ALL_ONE,
169
+ ptr(in, static_cast<int32_t>(VL64_OFS(ofs))));
170
+ } else {
171
+ add_imm(reg_tmp_ofs, in, ofs, reg_tmp_imm);
172
+ prfw(op_sve, P_ALL_ONE, ptr(reg_tmp_ofs));
173
+ }
174
+ }
175
+ }
176
+
177
+ void bcast_loop(int load_loop_blk);
178
+ void reduce_loop(int load_loop_blk, int ur, int substep, bool wraparound);
179
+
180
+ void generate() override;
181
+ static void balance(jit_1x1_conv_conf_t &jcp);
182
+
183
+ inline size_t get_output_offset(
184
+ const bool is_out_layout_nxc, const int i_load, const int i_ur) {
185
+ const size_t i_load_shift = is_out_layout_nxc
186
+ ? jcp.load_block
187
+ : (jcp.with_dw_conv ? jcp.ow : jcp.bcast_dim) * jcp.load_block;
188
+ const size_t i_ur_shift
189
+ = is_out_layout_nxc ? jcp.load_dim : jcp.load_block;
190
+ return jcp.typesize_out * (i_load * i_load_shift + i_ur * i_ur_shift);
191
+ }
192
+
193
+ Xbyak_aarch64::XReg output_ptr(const bool out_layout_nxc, const int i_load,
194
+ const int i_ur, Xbyak_aarch64::XReg addr);
195
+ void apply_postops(const bool is_out_layout_nxc, const int load_loop_blk,
196
+ const int ur);
197
+ };
198
+
199
+ } // namespace aarch64
200
+ } // namespace cpu
201
+ } // namespace impl
202
+ } // namespace dnnl
203
+
204
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_1x1_convolution.hpp ADDED
@@ -0,0 +1,534 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Intel Corporation
3
+ * Copyright 2021-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_1X1_CONVOLUTION_HPP
19
+ #define CPU_AARCH64_JIT_SVE_1X1_CONVOLUTION_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/dnnl_thread.hpp"
23
+ #include "common/memory_tracking.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/primitive_hashing.hpp"
26
+ #include "common/utils.hpp"
27
+
28
+ #include "cpu/cpu_convolution_pd.hpp"
29
+ #include "cpu/dw_convolution_utils.hpp"
30
+ #include "cpu/platform.hpp"
31
+
32
+ #include "cpu/aarch64/cpu_reducer.hpp"
33
+ #include "cpu/aarch64/jit_sve_512_1x1_conv_kernel.hpp"
34
+ #include "cpu/aarch64/jit_uni_1x1_conv_utils.hpp"
35
+ #include "cpu/aarch64/jit_uni_dw_convolution.hpp"
36
+
37
+ namespace dnnl {
38
+ namespace impl {
39
+ namespace cpu {
40
+ namespace aarch64 {
41
+
42
+ template <impl::data_type_t src_type, impl::data_type_t wei_type = src_type,
43
+ impl::data_type_t dst_type = src_type>
44
+ struct jit_sve_512_1x1_convolution_fwd_t : public primitive_t {
45
+ struct pd_t : public cpu_convolution_fwd_pd_t {
46
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
47
+ const typename pd_t::base_class *hint_fwd_pd)
48
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd)
49
+ , jcp_()
50
+ , rtus_() {}
51
+ pd_t(const pd_t &other) : cpu_convolution_fwd_pd_t(other) {
52
+ if (copy(other) != status::success) is_initialized_ = false;
53
+ }
54
+
55
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_1x1:", sve_512, ""),
56
+ jit_sve_512_1x1_convolution_fwd_t);
57
+
58
+ status_t init(engine_t *engine) {
59
+ using namespace utils;
60
+
61
+ bool ok = true && is_fwd()
62
+ && set_default_alg_kind(alg_kind::convolution_direct)
63
+ && expect_data_types(src_type, wei_type, dst_type, dst_type,
64
+ data_type::undef)
65
+ && attr()->has_default_values(
66
+ primitive_attr_t::skip_mask_t::post_ops, dst_type)
67
+ && !has_zero_dim_memory() && set_default_formats()
68
+ && attr_.set_default_formats(dst_md(0)) == status::success;
69
+ if (!ok) return status::unimplemented;
70
+
71
+ const convolution_desc_t *conv_d = desc();
72
+ const memory_desc_t *src_d = src_md();
73
+ rtus_prepare(this, conv_d, src_d, dst_md());
74
+
75
+ CHECK(jit_sve_512_1x1_conv_kernel::init_conf(jcp_, *conv_d, *src_d,
76
+ *weights_md(), *dst_md(), *attr(), dnnl_get_max_threads(),
77
+ rtus_.reduce_src_));
78
+ if (jcp_.with_dw_conv) CHECK(depthwise_po_init(engine));
79
+
80
+ auto scratchpad = scratchpad_registry().registrar();
81
+ jit_sve_512_1x1_conv_kernel::init_scratchpad(scratchpad, jcp_);
82
+
83
+ rtus_prepare_space_info(this, scratchpad, jcp_.nthr);
84
+
85
+ return status::success;
86
+ }
87
+
88
+ const memory_desc_t *dst_md(
89
+ int index = 0, bool user_input = false) const override {
90
+ return jcp_.with_dw_conv
91
+ ? dw_conv_pd_->dst_md(index, user_input)
92
+ : cpu_convolution_fwd_pd_t::dst_md(index, user_input);
93
+ }
94
+
95
+ const memory_desc_t *arg_md(
96
+ int arg, bool user_input = false) const override {
97
+ if (jcp_.with_dw_conv) {
98
+ switch (arg) {
99
+ case DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_SRC:
100
+ return cpu_convolution_fwd_pd_t::dst_md(0, user_input);
101
+ case DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_WEIGHTS:
102
+ return dw_conv_pd_->weights_md(0);
103
+ case DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_BIAS:
104
+ return dw_conv_pd_->weights_md(1);
105
+ default: break;
106
+ }
107
+ }
108
+ return convolution_fwd_pd_t::arg_md(arg, user_input);
109
+ }
110
+
111
+ arg_usage_t arg_usage(int arg) const override {
112
+ if (arg == (DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_WEIGHTS))
113
+ return arg_usage_t::input;
114
+
115
+ if (arg == (DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_BIAS)
116
+ && attr_post_op_dw_inputs() > 1)
117
+ return arg_usage_t::input;
118
+
119
+ return convolution_fwd_pd_t::arg_usage(arg);
120
+ }
121
+
122
+ jit_1x1_conv_conf_t jcp_;
123
+ reduce_to_unit_stride_t rtus_;
124
+ using dw_pd_t = jit_sve_512_dw_convolution_fwd_t::pd_t;
125
+ std::unique_ptr<dw_pd_t> dw_conv_pd_;
126
+
127
+ protected:
128
+ bool set_default_formats() {
129
+ using namespace format_tag;
130
+
131
+ const memory_desc_wrapper src_d(&src_md_);
132
+ const memory_desc_wrapper dst_d(&dst_md_);
133
+
134
+ const auto dat_tag_nxc = utils::pick(ndims() - 3, nwc, nhwc, ndhwc);
135
+ const auto dat_tag_nCx16c
136
+ = utils::pick(ndims() - 3, nCw16c, nChw16c, nCdhw16c);
137
+ const auto curr_src_tag
138
+ = src_d.matches_one_of_tag(dat_tag_nxc, dat_tag_nCx16c);
139
+ const auto curr_dst_tag
140
+ = dst_d.matches_one_of_tag(dat_tag_nxc, dat_tag_nCx16c);
141
+ const auto is_data_layout_nxc
142
+ = IMPLICATION(curr_src_tag != dat_tag_nxc,
143
+ src_d.format_kind() == format_kind::any)
144
+ && IMPLICATION(curr_dst_tag != dat_tag_nxc,
145
+ dst_d.format_kind() == format_kind::any)
146
+ && utils::one_of(dat_tag_nxc, curr_src_tag, curr_dst_tag);
147
+ auto dat_tag = is_data_layout_nxc ? dat_tag_nxc : dat_tag_nCx16c;
148
+ auto wei_tag = utils::pick(2 * ndims() - 6 + with_groups(),
149
+ OIw16i16o, gOIw16i16o, OIhw16i16o, gOIhw16i16o, OIdhw16i16o,
150
+ gOIdhw16i16o);
151
+
152
+ return set_default_formats_common(dat_tag, wei_tag, dat_tag);
153
+ }
154
+ status_t copy(const pd_t &other) {
155
+ jcp_ = other.jcp_;
156
+ rtus_ = other.rtus_;
157
+ if (other.dw_conv_pd_) {
158
+ dw_conv_pd_.reset(other.dw_conv_pd_->clone());
159
+ if (!dw_conv_pd_) return status::out_of_memory;
160
+ }
161
+ return status::success;
162
+ }
163
+
164
+ status_t depthwise_po_init(engine_t *engine) {
165
+
166
+ using namespace memory_tracking;
167
+ auto &jcp_1x1 = jcp_;
168
+ primitive_attr_t attr_1x1(*attr());
169
+ if (!attr_1x1.is_initialized()) return status::out_of_memory;
170
+ const auto &src_md = dst_md_;
171
+ const memory_desc_wrapper src_d(src_md);
172
+ const auto nthr = dnnl_get_max_threads();
173
+ auto l2_cache = platform::get_per_core_cache_size(2) * nthr;
174
+
175
+ // Note: A robust fusion implementation would be to check if both
176
+ // 1x1 conv and dw conv that are considered here for fusion are
177
+ // optimal independently. This would require creating a new
178
+ // primitive_desc through primitive_iterator & check if they match.
179
+ // Due to concern that these creations and/or checks could be heavy,
180
+ // for 1x1: Check that no better ISA is available.
181
+ // for dw: Always fuse with same ISA.
182
+ // Caveat: May be a better dw conv exists.
183
+
184
+ // TODO: Add a check if better ISA exists following above note.
185
+ bool ok = true
186
+ && (attr_1x1.post_ops_.find(primitive_kind::sum) == -1)
187
+ // TODO: Below may be further tuned.
188
+ && (l2_cache * 2 < src_d.size())
189
+ // load_grp_count check can be redundant due to l2 check
190
+ // above. Adding it explicitly as the current driver doesn't
191
+ // work if this condition fails.
192
+ && (jcp_1x1.load_grp_count < 2);
193
+ if (!ok) return status::unimplemented;
194
+
195
+ int dw_po_index
196
+ = attr_1x1.post_ops_.find(primitive_kind::convolution);
197
+ convolution_desc_t cd_dw;
198
+ primitive_attr_t attr_dw;
199
+ CHECK(get_depthwise_conv_desc(
200
+ cd_dw, src_md, attr_1x1, attr_dw, dw_po_index));
201
+
202
+ CHECK(safe_ptr_assign(
203
+ dw_conv_pd_, new dw_pd_t(&cd_dw, &attr_dw, nullptr)));
204
+ CHECK(dw_conv_pd_->init(engine));
205
+ auto &jcp_dw = dw_conv_pd_->jcp_;
206
+
207
+ ok = true
208
+ && (dnnl_memory_desc_equal(&src_md, dw_conv_pd_->src_md(0)))
209
+ && (jcp_1x1.oc_without_padding % jcp_1x1.oc_block == 0)
210
+ && IMPLICATION(
211
+ jcp_dw.ow_block, jcp_dw.ow_block == jcp_dw.ow);
212
+ if (!ok) return status::unimplemented;
213
+
214
+ assert(dw_conv_pd_->dst_md(0)->format_kind != format_kind::any);
215
+ assert(dw_conv_pd_->weights_md(0)->format_kind != format_kind::any);
216
+ assert(IMPLICATION(
217
+ dw_conv_pd_->weights_md(1)->data_type != data_type::undef,
218
+ dw_conv_pd_->weights_md(1)->format_kind
219
+ != format_kind::any));
220
+
221
+ jcp_dw.is_fused_conv = true;
222
+ // TODO: Support/experiment arbitary oc_work in dw conv.
223
+ // Until then we keep oc_work perfectly divisible.
224
+ while (jcp_1x1.nb_load % jcp_1x1.nb_load_blocking != 0)
225
+ --jcp_1x1.nb_load_blocking;
226
+ jcp_1x1.nb_load_blocking_max = jcp_1x1.nb_load_blocking;
227
+
228
+ while (jcp_1x1.nb_load_blocking % jcp_dw.nb_ch_blocking != 0)
229
+ --jcp_dw.nb_ch_blocking;
230
+
231
+ jcp_dw.dw_conv_buffer_oc
232
+ = jcp_1x1.nb_load_blocking * jcp_1x1.oc_block;
233
+
234
+ const auto dat_tag_nxc = utils::pick(ndims() - 3, format_tag::nwc,
235
+ format_tag::nhwc, format_tag::ndhwc);
236
+ const bool is_data_nxc = utils::everyone_is(
237
+ dat_tag_nxc, jcp_1x1.src_tag, jcp_1x1.dst_tag);
238
+ if (!is_data_nxc)
239
+ jcp_1x1.bcast_loop_output_step = jcp_1x1.ur * jcp_1x1.load_block
240
+ * jcp_1x1.typesize_out;
241
+
242
+ registrar_t scratchpad(scratchpad_registry_);
243
+ registrar_t dw_scratchpad(scratchpad, names::prefix_fusion);
244
+
245
+ size_t dw_conv_buffer_size_ = (size_t)nthr * jcp_dw.kh * jcp_dw.iw
246
+ * jcp_dw.dw_conv_buffer_oc;
247
+ assert(dw_conv_buffer_size_);
248
+ dw_scratchpad.book(memory_tracking::names::key_fusion_inout_buffer,
249
+ dw_conv_buffer_size_,
250
+ types::data_type_size(dw_conv_pd_->src_md()->data_type));
251
+
252
+ jit_uni_dw_conv_fwd_kernel<sve_512,
253
+ data_type::f32>::init_scratchpad(dw_scratchpad, jcp_dw);
254
+
255
+ return status::success;
256
+ }
257
+ };
258
+
259
+ template <cpu_isa_t isa, typename conv_t>
260
+ friend status_t init_rtus_driver(conv_t *self);
261
+
262
+ jit_sve_512_1x1_convolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
263
+
264
+ typedef typename prec_traits<src_type>::type src_data_t;
265
+ typedef typename prec_traits<wei_type>::type wei_data_t;
266
+ typedef typename prec_traits<dst_type>::type dst_data_t;
267
+
268
+ status_t init(engine_t *engine) override {
269
+ CHECK(safe_ptr_assign(kernel_,
270
+ new jit_sve_512_1x1_conv_kernel(
271
+ pd()->jcp_, *pd()->attr(), *pd()->dst_md(0))));
272
+ CHECK(kernel_->create_kernel());
273
+
274
+ if (pd()->jcp_.with_dw_conv) {
275
+ CHECK(safe_ptr_assign(
276
+ kernel_dw_, new dw_conv_kernel_t(pd()->dw_conv_pd_->jcp_)));
277
+ CHECK(kernel_dw_->create_kernel());
278
+ }
279
+
280
+ CHECK(init_rtus_driver<sve_512>(this));
281
+ return status::success;
282
+ }
283
+
284
+ status_t execute(const exec_ctx_t &ctx) const override {
285
+ execute_forward(ctx);
286
+ return status::success;
287
+ }
288
+
289
+ private:
290
+ void execute_forward(const exec_ctx_t &ctx) const;
291
+ void execute_forward_thr(const int ithr, const int nthr,
292
+ const src_data_t *src, const wei_data_t *weights,
293
+ const dst_data_t *bias, const wei_data_t *weights_dw,
294
+ const dst_data_t *bias_dw, dst_data_t *dst,
295
+ const memory_tracking::grantor_t &scratchpad,
296
+ const void *post_ops_binary_rhs_arg_vec,
297
+ const void *post_ops_binary_rhs_arg_vec_dw) const;
298
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
299
+
300
+ std::unique_ptr<jit_sve_512_1x1_conv_kernel> kernel_;
301
+ std::unique_ptr<rtus_driver_t<sve_512>> rtus_driver_;
302
+ using dw_conv_kernel_t = jit_uni_dw_conv_fwd_kernel_f32<sve_512>;
303
+ std::unique_ptr<dw_conv_kernel_t> kernel_dw_;
304
+ };
305
+
306
+ using jit_sve_512_1x1_convolution_fwd_f32_t
307
+ = jit_sve_512_1x1_convolution_fwd_t<data_type::f32>;
308
+
309
+ template <impl::data_type_t diff_dst_type,
310
+ impl::data_type_t wei_type = diff_dst_type,
311
+ impl::data_type_t diff_src_type = diff_dst_type>
312
+ struct jit_sve_512_1x1_convolution_bwd_data_t : public primitive_t {
313
+ struct pd_t : public cpu_convolution_bwd_data_pd_t {
314
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
315
+ const convolution_fwd_pd_t *hint_fwd_pd)
316
+ : cpu_convolution_bwd_data_pd_t(adesc, attr, hint_fwd_pd)
317
+ , jcp_()
318
+ , rtus_() {}
319
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_1x1:", sve_512, ""),
320
+ jit_sve_512_1x1_convolution_bwd_data_t);
321
+
322
+ status_t init(engine_t *engine) {
323
+ bool ok = true && desc()->prop_kind == prop_kind::backward_data
324
+ && set_default_alg_kind(alg_kind::convolution_direct)
325
+ && expect_data_types(diff_src_type, wei_type,
326
+ data_type::undef, diff_dst_type, data_type::undef)
327
+ && attr()->has_default_values() && !has_zero_dim_memory()
328
+ && set_default_formats();
329
+ if (!ok) return status::unimplemented;
330
+
331
+ const convolution_desc_t *conv_d = desc();
332
+ const memory_desc_t *diff_src_d = diff_src_md();
333
+ rtus_prepare(this, conv_d, diff_src_d, diff_dst_md());
334
+
335
+ status_t status = jit_sve_512_1x1_conv_kernel::init_conf(jcp_,
336
+ *conv_d, *diff_src_d, *weights_md(), *diff_dst_md(),
337
+ *attr(), dnnl_get_max_threads(), rtus_.reduce_src_);
338
+ if (status != status::success) return status;
339
+
340
+ auto scratchpad = scratchpad_registry().registrar();
341
+ jit_sve_512_1x1_conv_kernel::init_scratchpad(scratchpad, jcp_);
342
+
343
+ rtus_prepare_space_info(this, scratchpad, jcp_.nthr);
344
+
345
+ return status::success;
346
+ }
347
+
348
+ // TODO (Roma): structs conf header cleanup
349
+ jit_1x1_conv_conf_t jcp_;
350
+ reduce_to_unit_stride_t rtus_;
351
+
352
+ protected:
353
+ bool set_default_formats() {
354
+ using namespace format_tag;
355
+
356
+ const memory_desc_wrapper diff_src_d(&diff_src_md_);
357
+ const memory_desc_wrapper diff_dst_d(&diff_dst_md_);
358
+
359
+ const auto dat_tag_nxc = utils::pick(ndims() - 3, nwc, nhwc, ndhwc);
360
+ const auto dat_tag_nCx16c
361
+ = utils::pick(ndims() - 3, nCw16c, nChw16c, nCdhw16c);
362
+ const auto curr_src_tag = diff_src_d.matches_one_of_tag(
363
+ dat_tag_nxc, dat_tag_nCx16c);
364
+ const auto curr_dst_tag = diff_dst_d.matches_one_of_tag(
365
+ dat_tag_nxc, dat_tag_nCx16c);
366
+ const auto is_data_layout_nxc
367
+ = IMPLICATION(curr_src_tag != dat_tag_nxc,
368
+ diff_src_d.format_kind() == format_kind::any)
369
+ && IMPLICATION(curr_dst_tag != dat_tag_nxc,
370
+ diff_dst_d.format_kind() == format_kind::any)
371
+ && utils::one_of(dat_tag_nxc, curr_src_tag, curr_dst_tag);
372
+ auto dat_tag = is_data_layout_nxc ? dat_tag_nxc : dat_tag_nCx16c;
373
+ auto wei_tag = utils::pick(2 * ndims() - 6 + with_groups(),
374
+ IOw16o16i, gIOw16o16i, IOhw16o16i, gIOhw16o16i, IOdhw16o16i,
375
+ gIOdhw16o16i);
376
+
377
+ return set_default_formats_common(dat_tag, wei_tag, dat_tag);
378
+ }
379
+ };
380
+
381
+ template <cpu_isa_t isa, typename conv_t>
382
+ friend status_t init_rtus_driver(conv_t *self);
383
+
384
+ jit_sve_512_1x1_convolution_bwd_data_t(const pd_t *apd)
385
+ : primitive_t(apd) {}
386
+
387
+ typedef typename prec_traits<diff_dst_type>::type diff_dst_data_t;
388
+ typedef typename prec_traits<wei_type>::type wei_data_t;
389
+ typedef typename prec_traits<diff_src_type>::type diff_src_data_t;
390
+
391
+ status_t init(engine_t *engine) override {
392
+ CHECK(safe_ptr_assign(kernel_,
393
+ new jit_sve_512_1x1_conv_kernel(
394
+ pd()->jcp_, *pd()->attr(), *pd()->dst_md(0))));
395
+ CHECK(kernel_->create_kernel());
396
+ CHECK(init_rtus_driver<sve_512>(this));
397
+ return status::success;
398
+ }
399
+
400
+ status_t execute(const exec_ctx_t &ctx) const override {
401
+ execute_backward_data(ctx);
402
+ return status::success;
403
+ }
404
+
405
+ private:
406
+ void execute_backward_data(const exec_ctx_t &ctx) const;
407
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
408
+ std::unique_ptr<jit_sve_512_1x1_conv_kernel> kernel_;
409
+ std::unique_ptr<rtus_driver_t<sve_512>> rtus_driver_;
410
+ };
411
+
412
+ using jit_sve_512_1x1_convolution_bwd_data_f32_t
413
+ = jit_sve_512_1x1_convolution_bwd_data_t<data_type::f32>;
414
+
415
+ /* Backward weight */
416
+ struct jit_sve_512_1x1_convolution_bwd_weights_t : public primitive_t {
417
+ struct pd_t : public cpu_convolution_bwd_weights_pd_t {
418
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
419
+ const convolution_fwd_pd_t *hint_fwd_pd)
420
+ : cpu_convolution_bwd_weights_pd_t(adesc, attr, hint_fwd_pd)
421
+ , jcp_()
422
+ , rtus_() {}
423
+
424
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_1x1:", sve_512, ""),
425
+ jit_sve_512_1x1_convolution_bwd_weights_t);
426
+
427
+ status_t init(engine_t *engine) {
428
+ bool ok = true && desc()->prop_kind == prop_kind::backward_weights
429
+ && set_default_alg_kind(alg_kind::convolution_direct)
430
+ && expect_data_types(data_type::f32, data_type::f32,
431
+ data_type::f32, data_type::f32, data_type::f32)
432
+ && attr()->has_default_values() && !has_zero_dim_memory()
433
+ && set_default_formats();
434
+ if (!ok) return status::unimplemented;
435
+
436
+ const convolution_desc_t *conv_d = desc();
437
+ const memory_desc_t *src_d = src_md();
438
+ rtus_prepare(this, conv_d, src_d, diff_dst_md());
439
+
440
+ status_t status = jit_sve_512_1x1_conv_kernel::init_conf(jcp_,
441
+ *conv_d, *src_d, *diff_weights_md(), *diff_dst_md(),
442
+ *attr(), dnnl_get_max_threads(), rtus_.reduce_src_);
443
+ if (status != status::success) return status;
444
+
445
+ init_balancers();
446
+
447
+ auto scratchpad = scratchpad_registry().registrar();
448
+ jit_sve_512_1x1_conv_kernel::init_scratchpad(scratchpad, jcp_);
449
+
450
+ auto reducer_bia_scratchpad = memory_tracking::registrar_t(
451
+ scratchpad, memory_tracking::names::prefix_reducer_bia);
452
+ reducer_bia_conf_.init_scratchpad(reducer_bia_scratchpad);
453
+ rtus_prepare_space_info(this, scratchpad, jcp_.nthr);
454
+
455
+ return status::success;
456
+ }
457
+
458
+ // TODO (Roma): structs conf header cleanup
459
+ jit_1x1_conv_conf_t jcp_;
460
+ cpu_reducer_t<data_type::f32>::conf_t reducer_bia_conf_;
461
+ reduce_to_unit_stride_t rtus_;
462
+
463
+ protected:
464
+ bool set_default_formats() {
465
+ using namespace format_tag;
466
+
467
+ const memory_desc_wrapper src_d(&src_md_);
468
+ const memory_desc_wrapper diff_dst_d(&diff_dst_md_);
469
+
470
+ const auto dat_tag_nxc = utils::pick(ndims() - 3, nwc, nhwc, ndhwc);
471
+ const auto dat_tag_nCx16c
472
+ = utils::pick(ndims() - 3, nCw16c, nChw16c, nCdhw16c);
473
+ const auto curr_src_tag
474
+ = src_d.matches_one_of_tag(dat_tag_nxc, dat_tag_nCx16c);
475
+ const auto curr_dst_tag = diff_dst_d.matches_one_of_tag(
476
+ dat_tag_nxc, dat_tag_nCx16c);
477
+ const auto is_data_layout_nxc
478
+ = IMPLICATION(curr_src_tag != dat_tag_nxc,
479
+ src_d.format_kind() == format_kind::any)
480
+ && IMPLICATION(curr_dst_tag != dat_tag_nxc,
481
+ diff_dst_d.format_kind() == format_kind::any)
482
+ && utils::one_of(dat_tag_nxc, curr_src_tag, curr_dst_tag);
483
+
484
+ auto dat_tag = is_data_layout_nxc ? dat_tag_nxc : dat_tag_nCx16c;
485
+ auto wei_tag = utils::pick(2 * ndims() - 6 + with_groups(),
486
+ OIw16i16o, gOIw16i16o, OIhw16i16o, gOIhw16i16o, OIdhw16i16o,
487
+ gOIdhw16i16o);
488
+
489
+ return set_default_formats_common(dat_tag, wei_tag, dat_tag);
490
+ }
491
+
492
+ private:
493
+ void init_balancers() {
494
+ const size_t max_buffer_size = jcp_.nthr * 3 * 5 * 5 * 16 * 16;
495
+ if (with_bias()) {
496
+ reducer_bia_conf_.init(reduce_balancer_t(jcp_.nthr,
497
+ jcp_.oc_block, jcp_.ngroups * jcp_.nb_load, jcp_.mb,
498
+ max_buffer_size, true));
499
+ }
500
+ }
501
+ };
502
+
503
+ template <cpu_isa_t isa, typename conv_t>
504
+ friend status_t init_rtus_driver(conv_t *self);
505
+
506
+ jit_sve_512_1x1_convolution_bwd_weights_t(const pd_t *apd)
507
+ : primitive_t(apd) {}
508
+
509
+ typedef typename prec_traits<data_type::f32>::type data_t;
510
+
511
+ status_t init(engine_t *engine) override;
512
+
513
+ status_t execute(const exec_ctx_t &ctx) const override {
514
+ execute_backward_weights(ctx);
515
+ return status::success;
516
+ }
517
+
518
+ private:
519
+ void execute_backward_weights(const exec_ctx_t &ctx) const;
520
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
521
+
522
+ std::unique_ptr<jit_sve_512_1x1_conv_kernel> kernel_;
523
+ std::unique_ptr<cpu_accumulator_1d_t<data_type::f32>> acc_ker_;
524
+ std::unique_ptr<cpu_reducer_t<data_type::f32>> reducer_bias_;
525
+ // std::unique_ptr<jit_transpose4x16_src> trans_kernel_;
526
+ std::unique_ptr<rtus_driver_t<sve_512>> rtus_driver_;
527
+ };
528
+
529
+ } // namespace aarch64
530
+ } // namespace cpu
531
+ } // namespace impl
532
+ } // namespace dnnl
533
+
534
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_conv_kernel.hpp ADDED
@@ -0,0 +1,602 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2022 Intel Corporation
3
+ * Copyright 2020-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_CONV_KERNEL_HPP
19
+ #define CPU_AARCH64_JIT_SVE_CONV_KERNEL_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/memory_tracking.hpp"
23
+
24
+ #include "cpu/aarch64/jit_generator.hpp"
25
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
26
+
27
+ #include "cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp"
28
+
29
+ #include "cpu/aarch64/jit_op_imm_check.hpp"
30
+
31
+ #define LDRWMAX 252
32
+ #define ADDMAX 4095
33
+ /* Get vector offsets, ofs / VL(VL: 512bits = 64Bytes) */
34
+ #define VL_OFS(ofs) ((ofs) >> 6)
35
+
36
+ using namespace Xbyak_aarch64;
37
+
38
+ namespace dnnl {
39
+ namespace impl {
40
+ namespace cpu {
41
+ namespace aarch64 {
42
+
43
+ struct jit_sve_512_conv_fwd_kernel : public jit_generator {
44
+
45
+ jit_sve_512_conv_fwd_kernel(
46
+ const jit_conv_conf_t &ajcp, const primitive_attr_t &attr)
47
+ : jcp(ajcp), attr_(attr), eltwise_injector_(nullptr) {
48
+
49
+ if (jcp.with_eltwise)
50
+ eltwise_injector_ = new jit_uni_eltwise_injector_f32<sve_512>(
51
+ this, jcp.eltwise);
52
+ }
53
+
54
+ ~jit_sve_512_conv_fwd_kernel() { delete eltwise_injector_; }
55
+
56
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_sve_512_conv_fwd_kernel)
57
+
58
+ jit_conv_conf_t jcp;
59
+ const primitive_attr_t &attr_;
60
+
61
+ static bool post_ops_ok(jit_conv_conf_t &jcp, const primitive_attr_t &attr);
62
+ static status_t init_conf(jit_conv_conf_t &jcp,
63
+ const convolution_desc_t &cd, memory_desc_t &src_pd,
64
+ memory_desc_t &weights_pd, memory_desc_t &dst_pd,
65
+ memory_desc_t &bias_pd, const primitive_attr_t &attr, int nthreads);
66
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
67
+ const jit_conv_conf_t &jcp);
68
+
69
+ private:
70
+ using reg64_t = const XReg;
71
+ enum {
72
+ typesize = sizeof(float),
73
+ ker_reg_base_idx = 28,
74
+ };
75
+
76
+ reg64_t param = abi_param1;
77
+ reg64_t reg_inp = x1; // src base addr (2d)
78
+ reg64_t reg_ker = x2; // ker base addr (2d)
79
+ reg64_t aux_reg_ker_d = x2; // ker addr (3d)
80
+ reg64_t reg_out = x3; // dst base addr (2d)
81
+ reg64_t reg_ki = x3; // d-dim loop var? (3d)
82
+ reg64_t reg_owb = x5; // num of ow-block
83
+ reg64_t reg_out_prf = x6; // addr for prefetch
84
+
85
+ reg64_t aux_reg_inp = x7; // src addr (main loop)
86
+ reg64_t aux_reg_inp2 = x24; // src addr (main loop)
87
+ reg64_t aux_reg_inp3 = x25; // src addr (main loop)
88
+ reg64_t reg_out_ofs = x7; // dst addr (store_output)
89
+ reg64_t aux_reg_ker = x8; // ker addr (main loop)
90
+ reg64_t reg_channel = x9; // reduce workload
91
+ reg64_t reg_bias = x10; // bias addr (prepare_out)
92
+
93
+ reg64_t aux_reg_inp_d = x11; // src addr (3d)
94
+ reg64_t reg_oi = x11;
95
+
96
+ reg64_t reg_kh = x12; // ker h size
97
+ reg64_t reg_kj = x13; // ker h workload
98
+
99
+ /* Temporary registers for ARM insts */
100
+ reg64_t reg_tmp_addr = x14;
101
+ reg64_t reg_prev_bcast_addr = x15;
102
+ reg64_t reg_prev_wei_addr = x16;
103
+ reg64_t reg_tmp_imm = x17;
104
+
105
+ reg64_t reg_out_org = x27; // dst base addr (3d)
106
+ reg64_t reg_oi_org = x19; // base oi (3d)
107
+ reg64_t aux_reg_ker_d_org = x20;
108
+ reg64_t reg_ker_org = x21; // ker base addr (3d)
109
+ reg64_t reg_inp_org = x29; // src base addr (3d)
110
+
111
+ void prefetch(
112
+ const std::string prfop, int level, reg64_t in, long long int ofs) {
113
+ bool for_load = false;
114
+ if (prfop == "LD") {
115
+ for_load = true;
116
+ } else if (prfop == "ST") {
117
+ for_load = false;
118
+ } else {
119
+ assert(!"invalid prfop");
120
+ }
121
+
122
+ bool cacheline_aligned = ((ofs & 0xFF) == 0) ? true : false;
123
+ if (cacheline_aligned == true) {
124
+ Prfop op = PLDL1KEEP;
125
+ switch (level) {
126
+ case 1: op = (for_load == true) ? PLDL1KEEP : PSTL1KEEP; break;
127
+ case 2: op = (for_load == true) ? PLDL2KEEP : PSTL2KEEP; break;
128
+ case 3: op = (for_load == true) ? PLDL3KEEP : PSTL3KEEP; break;
129
+ default: assert(!"invalid prfop"); break;
130
+ }
131
+
132
+ if ((ofs <= PRFMMAX) && (ofs >= 0)) {
133
+ prfm(op, ptr(in, static_cast<int32_t>(ofs)));
134
+ } else {
135
+ add_imm(reg_tmp_addr, in, ofs, reg_tmp_imm);
136
+ prfm(op, ptr(reg_tmp_addr));
137
+ }
138
+ } else {
139
+ PrfopSve op_sve = PLDL1KEEP_SVE;
140
+ switch (level) {
141
+ case 1:
142
+ op_sve = (for_load == true) ? PLDL1KEEP_SVE : PSTL1KEEP_SVE;
143
+ break;
144
+ case 2:
145
+ op_sve = (for_load == true) ? PLDL2KEEP_SVE : PSTL2KEEP_SVE;
146
+ break;
147
+ case 3:
148
+ op_sve = (for_load == true) ? PLDL3KEEP_SVE : PSTL3KEEP_SVE;
149
+ break;
150
+ default: assert(!"invalid level"); break;
151
+ }
152
+
153
+ if ((VL_OFS(ofs) <= PRFWMAX)
154
+ && (VL_OFS(ofs) >= (-1 * PRFWMAX - 1))) {
155
+ prfw(op_sve, P_ALL_ONE,
156
+ ptr(in, static_cast<int32_t>(VL_OFS(ofs))));
157
+ } else {
158
+ add_imm(reg_tmp_addr, in, ofs, reg_tmp_imm);
159
+ prfw(op_sve, P_ALL_ONE, ptr(reg_tmp_addr));
160
+ }
161
+ }
162
+ }
163
+
164
+ jit_uni_eltwise_injector_f32<sve_512> *eltwise_injector_;
165
+
166
+ inline void prepare_output(int ur_w);
167
+ inline void store_output(int ur_w);
168
+ inline void compute_loop_fma_core(int ur_w, int pad_l, int pad_r);
169
+ inline void compute_loop(int ur_w, int pad_l, int pad_r);
170
+
171
+ void generate() override;
172
+
173
+ inline size_t get_output_offset(int oi, int n_oc_block) {
174
+ const bool is_nxc_layout = is_dst_layout_nxc();
175
+ size_t ow_str = is_nxc_layout ? jcp.ngroups * jcp.oc : jcp.oc_block;
176
+ size_t ocb_str = is_nxc_layout
177
+ ? jcp.oc_block
178
+ : (size_t)jcp.od * jcp.oh * jcp.ow * jcp.oc_block;
179
+
180
+ return jcp.typesize_out * (n_oc_block * ocb_str + oi * ow_str);
181
+ }
182
+
183
+ inline size_t get_input_offset(int ki, int ic, int oi, int pad_l) {
184
+ const bool is_nxc_layout = is_src_layout_nxc();
185
+ size_t iw_str = is_nxc_layout ? jcp.ngroups * jcp.ic
186
+ : (!jcp.is_1stconv ? jcp.ic_block : 1);
187
+ size_t ic_str = !jcp.is_1stconv || is_nxc_layout
188
+ ? 1
189
+ : (size_t)jcp.iw * jcp.ih * jcp.id;
190
+ size_t iw_idx = ki * (jcp.dilate_w + 1) + oi * jcp.stride_w - pad_l;
191
+
192
+ return jcp.typesize_in * (iw_idx * iw_str + ic * ic_str);
193
+ }
194
+
195
+ inline int get_kernel_offset(
196
+ int ki, int ic, int n_oc_block, int ker_number) {
197
+ return jcp.typesize_in * jcp.oc_block
198
+ * (n_oc_block * jcp.nb_ic * jcp.ic_block * jcp.kh * jcp.kw
199
+ * jcp.kd
200
+ + (ic + ker_number) + ki * jcp.ic_block);
201
+ }
202
+
203
+ inline int get_ow_start(int ki, int pad_l) {
204
+ return nstl::max(0,
205
+ utils::div_up(pad_l - ki * (jcp.dilate_w + 1), jcp.stride_w));
206
+ }
207
+
208
+ inline int get_ow_end(int ur_w, int ki, int pad_r) {
209
+ return ur_w
210
+ - nstl::max(0,
211
+ utils::div_up(
212
+ pad_r - (jcp.kw - 1 - ki) * (jcp.dilate_w + 1),
213
+ jcp.stride_w));
214
+ }
215
+ inline bool is_src_layout_nxc() {
216
+ return utils::one_of(jcp.src_tag, format_tag::ndhwc, format_tag::nhwc,
217
+ format_tag::nwc);
218
+ }
219
+ inline bool is_dst_layout_nxc() {
220
+ return utils::one_of(jcp.dst_tag, format_tag::ndhwc, format_tag::nhwc,
221
+ format_tag::nwc);
222
+ }
223
+ };
224
+
225
+ struct jit_sve_512_conv_bwd_data_kernel_f32 : public jit_generator {
226
+
227
+ jit_sve_512_conv_bwd_data_kernel_f32(const jit_conv_conf_t &ajcp)
228
+ : jcp(ajcp) {}
229
+
230
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_sve_512_conv_bwd_data_kernel_f32)
231
+ jit_conv_conf_t jcp;
232
+ void (*jit_ker_)(jit_conv_call_s *);
233
+
234
+ static status_t init_conf(jit_conv_conf_t &jcp,
235
+ const convolution_desc_t &cd, memory_desc_t &diff_src_d,
236
+ memory_desc_t &weights_d, memory_desc_t &diff_dst_d, int nthreads);
237
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
238
+ const jit_conv_conf_t &jcp);
239
+
240
+ private:
241
+ using reg64_t = const XReg;
242
+ enum {
243
+ typesize = sizeof(float),
244
+ };
245
+ int ker_reg_base_idx = (jcp.nb_ic_blocking == 1) ? 16 : 24;
246
+
247
+ reg64_t param = abi_param1;
248
+ reg64_t reg_dst = x1;
249
+ reg64_t reg_ker = x2;
250
+ reg64_t reg_src = x3;
251
+
252
+ reg64_t reg_dst_prf = x23;
253
+ reg64_t reg_ker_prf = x5;
254
+ reg64_t reg_src_prf = x6;
255
+ reg64_t reg_iwb = x24;
256
+
257
+ reg64_t aux_reg_dst = x7;
258
+ reg64_t aux_reg_ker = x8;
259
+
260
+ reg64_t aux_reg_dst_prf = x9;
261
+ reg64_t aux_reg_ker_prf = x10;
262
+
263
+ reg64_t aux_reg_dst_d_prf = x6;
264
+ reg64_t aux_reg_dst_d = x11;
265
+ reg64_t aux_reg_ker_d_prf = x12;
266
+ reg64_t aux_reg_ker_d = x2;
267
+ reg64_t reg_ki = x3;
268
+
269
+ reg64_t reg_kj = x13;
270
+ reg64_t reg_oi = x11;
271
+ reg64_t reg_kh = x12;
272
+
273
+ reg64_t reg_channel = x9;
274
+
275
+ reg64_t reg_tmp = x14;
276
+ reg64_t reg_long_offt = x7;
277
+
278
+ /* Temporary registers for ARM insts */
279
+ reg64_t reg_prev_bcast_addr = x15;
280
+ reg64_t reg_prev_bcast_addr2 = x17;
281
+ reg64_t reg_prev_bcast_addr3 = x21;
282
+ reg64_t reg_tmp_imm = x16;
283
+ reg64_t reg_tmp_addr = x27;
284
+
285
+ reg64_t reg_src_prf_org = x19;
286
+ reg64_t reg_src_org = x20;
287
+ reg64_t reg_oi_org = x25;
288
+ reg64_t reg_dst_org = x22;
289
+ reg64_t reg_ker_org = x26;
290
+ reg64_t reg_input_org = x22;
291
+ reg64_t reg_kernel_org = x26;
292
+
293
+ long long int prefetch(const std::string prfop, int level, reg64_t in,
294
+ long long int ofs, long long int prev_ofs) {
295
+ bool for_load = false;
296
+ if (prfop == "LD") {
297
+ for_load = true;
298
+ } else if (prfop == "ST") {
299
+ for_load = false;
300
+ } else {
301
+ assert(!"invalid prfop");
302
+ }
303
+
304
+ bool cacheline_aligned = ((ofs & 0xFF) == 0) ? true : false;
305
+ if (cacheline_aligned == true) {
306
+ Prfop op = PLDL1KEEP;
307
+ switch (level) {
308
+ case 1: op = (for_load == true) ? PLDL1KEEP : PSTL1KEEP; break;
309
+ case 2: op = (for_load == true) ? PLDL2KEEP : PSTL2KEEP; break;
310
+ case 3: op = (for_load == true) ? PLDL3KEEP : PSTL3KEEP; break;
311
+ default: assert(!"invalid prfop"); break;
312
+ }
313
+
314
+ long long int tmp_ofs = ofs - prev_ofs;
315
+ if ((ofs <= PRFMMAX) && (ofs >= 0)) {
316
+ prfm(op, ptr(in, static_cast<int32_t>(ofs)));
317
+ } else if ((tmp_ofs <= PRFMMAX) && (tmp_ofs >= 0)) {
318
+ prfm(op, ptr(reg_tmp_addr, static_cast<int32_t>(tmp_ofs)));
319
+ } else {
320
+ add_imm(reg_tmp_addr, in, ofs, reg_tmp_imm);
321
+ prfm(op, ptr(reg_tmp_addr));
322
+ prev_ofs = ofs;
323
+ }
324
+ } else {
325
+ PrfopSve op_sve = PLDL1KEEP_SVE;
326
+ switch (level) {
327
+ case 1:
328
+ op_sve = (for_load == true) ? PLDL1KEEP_SVE : PSTL1KEEP_SVE;
329
+ break;
330
+ case 2:
331
+ op_sve = (for_load == true) ? PLDL2KEEP_SVE : PSTL2KEEP_SVE;
332
+ break;
333
+ case 3:
334
+ op_sve = (for_load == true) ? PLDL3KEEP_SVE : PSTL3KEEP_SVE;
335
+ break;
336
+ default: assert(!"invalid prfop"); break;
337
+ }
338
+
339
+ long long int tmp_ofs = ofs - prev_ofs;
340
+ if ((VL_OFS(ofs) <= PRFWMAX)
341
+ && (VL_OFS(ofs) >= (-1 * PRFWMAX - 1))) {
342
+ prfw(op_sve, P_ALL_ONE,
343
+ ptr(in, static_cast<int32_t>(VL_OFS(ofs))));
344
+ } else if ((VL_OFS(tmp_ofs) <= PRFWMAX)
345
+ && (VL_OFS(tmp_ofs) >= (-1 * PRFWMAX - 1))) {
346
+ prfw(op_sve, P_ALL_ONE,
347
+ ptr(reg_tmp_addr,
348
+ static_cast<int32_t>(VL_OFS(tmp_ofs))));
349
+ } else {
350
+ add_imm(reg_tmp_addr, in, ofs, reg_tmp_imm);
351
+ prfw(op_sve, P_ALL_ONE, ptr(reg_tmp_addr));
352
+ prev_ofs = ofs;
353
+ }
354
+ }
355
+ return prev_ofs;
356
+ }
357
+
358
+ ZReg reg_wei = ZReg(31);
359
+
360
+ inline void prepare_output(int ur_w);
361
+ inline void store_output(int ur_w);
362
+ inline void compute_loop_fma(int ur_w, int l_overflow, int r_overflow);
363
+ inline void compute_loop_fma_core(
364
+ int ur_w, int l_overflow, int r_overflow, int k_offset);
365
+ inline void compute_loop(
366
+ int ur_w, int l_overflow, int r_overflow, int k_offset = 0);
367
+ void generate() override;
368
+
369
+ inline int get_iw_start(int ki, int l_overflow) {
370
+ int res = (jcp.iw - 1 + jcp.r_pad) % jcp.stride_w
371
+ + l_overflow * jcp.stride_w
372
+ - (jcp.kw - 1 - ki) * (jcp.dilate_w + 1);
373
+ while (res < 0)
374
+ res += jcp.stride_w;
375
+
376
+ return res;
377
+ }
378
+
379
+ inline int get_iw_end(int ur_w, int ki, int r_overflow) {
380
+ if (utils::one_of(ur_w, jcp.iw, jcp.ur_w_tail))
381
+ ur_w += nstl::min(0, jcp.r_pad); // remove negative padding
382
+ int res = (ur_w - 1 + jcp.l_pad) % jcp.stride_w
383
+ + r_overflow * jcp.stride_w - ki * (jcp.dilate_w + 1);
384
+ while (res < 0)
385
+ res += jcp.stride_w;
386
+
387
+ return ur_w - res;
388
+ }
389
+
390
+ inline size_t get_diff_src_offset(int iw, int icb) {
391
+ const bool is_nxc_layout = is_dsrc_layout_nxc();
392
+ size_t iw_str = is_nxc_layout ? jcp.ngroups * jcp.ic : jcp.ic_block;
393
+ size_t icb_str = is_nxc_layout
394
+ ? jcp.ic_block
395
+ : (size_t)jcp.id * jcp.ih * jcp.iw * jcp.ic_block;
396
+
397
+ return typesize * (icb * icb_str + iw * iw_str);
398
+ }
399
+
400
+ inline ptrdiff_t get_dst_offset(int iw, int oc, int kw) {
401
+ ptrdiff_t ow
402
+ = (iw + jcp.l_pad - kw * (jcp.dilate_w + 1)) / jcp.stride_w;
403
+ ptrdiff_t ow_str
404
+ = is_ddst_layout_nxc() ? jcp.ngroups * jcp.oc : jcp.oc_block;
405
+
406
+ return typesize * (ow * ow_str + oc);
407
+ };
408
+
409
+ inline bool is_dsrc_layout_nxc() {
410
+ return utils::one_of(jcp.src_tag, format_tag::ndhwc, format_tag::nhwc,
411
+ format_tag::nwc);
412
+ }
413
+ inline bool is_ddst_layout_nxc() {
414
+ return utils::one_of(jcp.dst_tag, format_tag::ndhwc, format_tag::nhwc,
415
+ format_tag::nwc);
416
+ }
417
+ };
418
+
419
+ struct jit_sve_512_conv_bwd_weights_kernel_f32 : public jit_generator {
420
+
421
+ jit_sve_512_conv_bwd_weights_kernel_f32(const jit_conv_conf_t &ajcp)
422
+ : jcp(ajcp) {}
423
+
424
+ void generate() override {
425
+ if (jcp.harness != harness_nxc) {
426
+ generate_kernel();
427
+ } else {
428
+ assert(!"none microkernel");
429
+ }
430
+ }
431
+
432
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_sve_512_conv_bwd_weights_kernel_f32)
433
+
434
+ static status_t init_conf(jit_conv_conf_t &jcp,
435
+ const convolution_desc_t &cd, memory_desc_t &src_md,
436
+ memory_desc_t &diff_weights_md, memory_desc_t &diff_bias_md,
437
+ memory_desc_t &diff_dst_md, int nthreads);
438
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
439
+ const jit_conv_conf_t &jcp);
440
+
441
+ jit_conv_conf_t jcp;
442
+
443
+ private:
444
+ using reg64_t = const XReg;
445
+ enum { typesize = sizeof(float) };
446
+ static const int max_ur_w;
447
+ static const int min_oh_reduce;
448
+
449
+ reg64_t param = abi_param1;
450
+ reg64_t reg_input = x1;
451
+ reg64_t reg_kernel = x2;
452
+ reg64_t reg_output = x3;
453
+ reg64_t b_ic = x20;
454
+ reg64_t kj = x5;
455
+ reg64_t reg_kh = x6;
456
+ reg64_t reg_ur_w_trips = x7;
457
+ reg64_t reg_oj = x8;
458
+ reg64_t reg_tmp = x10;
459
+ reg64_t reg_icb = x9;
460
+
461
+ reg64_t ki = x11;
462
+ reg64_t reg_kd_count = x12;
463
+ reg64_t reg_oi = x12;
464
+ reg64_t reg_d_index = x13;
465
+ reg64_t reg_input_d = x8;
466
+ reg64_t reg_output_d = x9;
467
+ reg64_t aux_reg_input = x12;
468
+ reg64_t aux_reg_kernel = x13;
469
+ reg64_t reg_bias = x9;
470
+ reg64_t reg_oc_tail = x10;
471
+
472
+ /* Temporary registers */
473
+ reg64_t reg_add_tmp = x14;
474
+ reg64_t reg_tmp_imm = x15;
475
+
476
+ reg64_t reg_kd_count_org = x16;
477
+ reg64_t reg_input_d_org = x17;
478
+ reg64_t reg_output_d_org = x19;
479
+
480
+ reg64_t reg_input_org = x24;
481
+ reg64_t reg_kernel_org = x22;
482
+ reg64_t reg_output_org = x23;
483
+
484
+ reg64_t reg_pre_addr_input = x25;
485
+ reg64_t reg_pre_addr_out = x26;
486
+ reg64_t reg_pre_addr_ker = x26;
487
+ reg64_t reg_ker_start_addr = x27;
488
+ reg64_t reg_addr_diff_input = x28;
489
+
490
+ void prefetch(
491
+ const std::string prfop, int level, reg64_t in, long long int ofs) {
492
+ bool for_load = false;
493
+ if (prfop == "LD") {
494
+ for_load = true;
495
+ } else if (prfop == "ST") {
496
+ for_load = false;
497
+ } else {
498
+ assert(!"invalid prfop");
499
+ }
500
+
501
+ bool cacheline_aligned = ((ofs & 0xFF) == 0) ? true : false;
502
+ if (cacheline_aligned == true) {
503
+ Prfop op = PLDL1KEEP;
504
+ switch (level) {
505
+ case 1: op = (for_load == true) ? PLDL1KEEP : PSTL1KEEP; break;
506
+ case 2: op = (for_load == true) ? PLDL2KEEP : PSTL2KEEP; break;
507
+ case 3: op = (for_load == true) ? PLDL3KEEP : PSTL3KEEP; break;
508
+ default: assert(!"invalid prfop"); break;
509
+ }
510
+
511
+ if ((ofs <= PRFMMAX) && (ofs >= 0)) {
512
+ prfm(op, ptr(in, static_cast<int32_t>(ofs)));
513
+ } else {
514
+ add_imm(reg_add_tmp, in, ofs, reg_tmp_imm);
515
+ prfm(op, ptr(reg_add_tmp));
516
+ }
517
+ } else {
518
+ PrfopSve op_sve;
519
+ switch (level) {
520
+ case 1:
521
+ op_sve = (for_load == true) ? PLDL1KEEP_SVE : PSTL1KEEP_SVE;
522
+ break;
523
+ case 2:
524
+ op_sve = (for_load == true) ? PLDL2KEEP_SVE : PSTL2KEEP_SVE;
525
+ break;
526
+ case 3:
527
+ op_sve = (for_load == true) ? PLDL3KEEP_SVE : PSTL3KEEP_SVE;
528
+ break;
529
+ default: assert(!"invalid prfop"); break;
530
+ }
531
+
532
+ if ((VL_OFS(ofs) <= PRFWMAX)
533
+ && (VL_OFS(ofs) >= (-1 * PRFWMAX - 1))) {
534
+ prfw(op_sve, P_ALL_ONE,
535
+ ptr(in, static_cast<int32_t>(VL_OFS(ofs))));
536
+ } else {
537
+ add_imm(reg_add_tmp, in, ofs, reg_tmp_imm);
538
+ prfw(op_sve, P_ALL_ONE, ptr(reg_add_tmp));
539
+ }
540
+ }
541
+ }
542
+
543
+ inline void bias_kernel_2d();
544
+ inline void bias_kernel_3d();
545
+ inline void maybe_zero_kernel();
546
+ inline void compute_oh_step_unroll_ow_icblock(
547
+ int ic_block_step, int max_ur_w);
548
+ inline void od_step_comeback_pointers();
549
+ inline void oh_step_comeback_pointers();
550
+ inline void compute_oh_step_unroll_ow(int ic_block_step, int max_ur_w);
551
+ inline void compute_ic_block_step(int ur_w, int pad_l, int pad_r,
552
+ int ic_block_step, int input_offset, int kernel_offset,
553
+ int output_offset, bool input_wraparound = false);
554
+ inline void compute_oh_step_common(int ic_block_step, int max_ur_w);
555
+ inline void compute_oh_step_disp();
556
+ inline void compute_oh_loop_common();
557
+ inline void compute_oh_loop_partial();
558
+ inline void compute_od_loop_partial();
559
+
560
+ inline bool compute_full_spat_loop();
561
+ inline bool flat_4ops_compute();
562
+
563
+ inline void compute_loop();
564
+ inline bool is_src_layout_nxc() {
565
+ return utils::one_of(jcp.src_tag, format_tag::ndhwc, format_tag::nhwc,
566
+ format_tag::nwc);
567
+ }
568
+ inline bool is_ddst_layout_nxc() {
569
+ return utils::one_of(jcp.dst_tag, format_tag::ndhwc, format_tag::nhwc,
570
+ format_tag::nwc);
571
+ }
572
+
573
+ inline ptrdiff_t get_full_src_offset(
574
+ int i_iw, int i_ic, ptrdiff_t input_offset) {
575
+ const bool is_nxc_layout = is_src_layout_nxc();
576
+ const size_t w_shift_st = (jcp.is_hw_transp ? jcp.iw : 1)
577
+ * (jcp.is_1stconv ? 1 : jcp.ic_block);
578
+ ptrdiff_t w_shift = is_nxc_layout ? jcp.ngroups * jcp.ic : w_shift_st;
579
+ ptrdiff_t ic_shift = (jcp.is_1stconv && !is_nxc_layout
580
+ ? (ptrdiff_t)jcp.ih * jcp.iw * jcp.id
581
+ : 1);
582
+
583
+ ptrdiff_t local_input_offset = i_iw * w_shift + i_ic * ic_shift;
584
+ return input_offset + typesize * local_input_offset;
585
+ };
586
+
587
+ inline int get_iw_idx(int ow, int kw, int l_pad) {
588
+ return ow * jcp.stride_w + kw * (jcp.dilate_w + 1) - l_pad;
589
+ }
590
+
591
+ void generate_kernel();
592
+
593
+ static void balance(const jit_conv_conf_t &j, int &nthr, int &nthr_mb,
594
+ int &nthr_g, int &nthr_oc_b, int &nthr_ic_b, int nthreads);
595
+ };
596
+
597
+ } // namespace aarch64
598
+ } // namespace cpu
599
+ } // namespace impl
600
+ } // namespace dnnl
601
+
602
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_convolution.hpp ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2021 Intel Corporation
3
+ * Copyright 2020-2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_CONVOLUTION_HPP
19
+ #define CPU_AARCH64_JIT_SVE_CONVOLUTION_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/dnnl_thread.hpp"
23
+ #include "common/memory_tracking.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/utils.hpp"
26
+
27
+ #include "cpu/aarch64/cpu_barrier.hpp"
28
+ #include "cpu/aarch64/cpu_reducer.hpp"
29
+ #include "cpu/cpu_convolution_pd.hpp"
30
+
31
+ #include "cpu/aarch64/jit_sve_512_conv_kernel.hpp"
32
+
33
+ namespace dnnl {
34
+ namespace impl {
35
+ namespace cpu {
36
+ namespace aarch64 {
37
+
38
+ template <impl::data_type_t src_type, impl::data_type_t wei_type = src_type,
39
+ impl::data_type_t dst_type = src_type>
40
+ struct jit_sve_512_convolution_fwd_t : public primitive_t {
41
+ struct pd_t : public cpu_convolution_fwd_pd_t {
42
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
43
+ const typename pd_t::base_class *hint_fwd_pd)
44
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd), jcp_() {}
45
+
46
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:", sve_512, ""),
47
+ jit_sve_512_convolution_fwd_t);
48
+
49
+ status_t init(engine_t *engine) {
50
+ bool ok = true && is_fwd()
51
+ && set_default_alg_kind(alg_kind::convolution_direct)
52
+ && expect_data_types(src_type, wei_type, dst_type, dst_type,
53
+ data_type::undef)
54
+ && attr()->has_default_values(
55
+ primitive_attr_t::skip_mask_t::post_ops, dst_type)
56
+ && !has_zero_dim_memory();
57
+ if (!ok) return status::unimplemented;
58
+
59
+ status_t status = jit_sve_512_conv_fwd_kernel::init_conf(jcp_,
60
+ *desc(), src_md_, weights_md_, dst_md_, bias_md_, *attr(),
61
+ dnnl_get_max_threads());
62
+ if (status != status::success) return status;
63
+
64
+ auto scratchpad = scratchpad_registry().registrar();
65
+ jit_sve_512_conv_fwd_kernel::init_scratchpad(scratchpad, jcp_);
66
+
67
+ return status;
68
+ }
69
+
70
+ jit_conv_conf_t jcp_;
71
+ };
72
+
73
+ jit_sve_512_convolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
74
+
75
+ typedef typename prec_traits<src_type>::type src_data_t;
76
+ typedef typename prec_traits<wei_type>::type wei_data_t;
77
+ typedef typename prec_traits<dst_type>::type dst_data_t;
78
+
79
+ status_t init(engine_t *engine) override {
80
+ CHECK(safe_ptr_assign(kernel_,
81
+ new jit_sve_512_conv_fwd_kernel(pd()->jcp_, *pd()->attr())));
82
+ return kernel_->create_kernel();
83
+ }
84
+
85
+ status_t execute(const exec_ctx_t &ctx) const override {
86
+ if (pd()->ndims() == 3)
87
+ execute_forward_1d(ctx);
88
+ else if (pd()->ndims() == 4)
89
+ execute_forward_2d(ctx);
90
+ else if (pd()->ndims() == 5)
91
+ execute_forward_3d(ctx);
92
+ else
93
+ assert(false);
94
+
95
+ if (pd()->wants_zero_pad_dst()) ctx.zero_pad_output(DNNL_ARG_DST);
96
+
97
+ return status::success;
98
+ }
99
+
100
+ private:
101
+ void prepare_padded_bias(const dst_data_t *&bias,
102
+ const memory_tracking::grantor_t &scratchpad) const;
103
+ void execute_forward_1d(const exec_ctx_t &ctx) const;
104
+ void execute_forward_2d(const exec_ctx_t &ctx) const;
105
+ void execute_forward_3d(const exec_ctx_t &ctx) const;
106
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
107
+
108
+ std::unique_ptr<jit_sve_512_conv_fwd_kernel> kernel_;
109
+ };
110
+
111
+ template <impl::data_type_t diff_dst_type,
112
+ impl::data_type_t wei_type = diff_dst_type,
113
+ impl::data_type_t diff_src_type = diff_dst_type>
114
+ struct jit_sve_512_convolution_bwd_data_t : public primitive_t {
115
+ struct pd_t : public cpu_convolution_bwd_data_pd_t {
116
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
117
+ const convolution_fwd_pd_t *hint_fwd_pd)
118
+ : cpu_convolution_bwd_data_pd_t(adesc, attr, hint_fwd_pd), jcp_() {}
119
+
120
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:", sve_512, ""),
121
+ jit_sve_512_convolution_bwd_data_t);
122
+
123
+ status_t init(engine_t *engine) {
124
+ bool ok = true && desc()->prop_kind == prop_kind::backward_data
125
+ && set_default_alg_kind(alg_kind::convolution_direct)
126
+ && expect_data_types(diff_src_type, wei_type,
127
+ data_type::undef, diff_dst_type, data_type::undef)
128
+ && attr()->has_default_values() && !has_zero_dim_memory();
129
+ if (!ok) return status::unimplemented;
130
+
131
+ status_t status = jit_sve_512_conv_bwd_data_kernel_f32::init_conf(
132
+ jcp_, *desc(), diff_src_md_, weights_md_, diff_dst_md_,
133
+ dnnl_get_max_threads());
134
+ if (status != status::success) return status;
135
+
136
+ auto scratchpad = scratchpad_registry().registrar();
137
+ jit_sve_512_conv_bwd_data_kernel_f32::init_scratchpad(
138
+ scratchpad, jcp_);
139
+
140
+ return status::success;
141
+ }
142
+
143
+ jit_conv_conf_t jcp_;
144
+ };
145
+
146
+ jit_sve_512_convolution_bwd_data_t(const pd_t *apd) : primitive_t(apd) {}
147
+
148
+ typedef typename prec_traits<diff_dst_type>::type diff_dst_data_t;
149
+ typedef typename prec_traits<wei_type>::type wei_data_t;
150
+ typedef typename prec_traits<diff_src_type>::type diff_src_data_t;
151
+
152
+ status_t init(engine_t *engine) override {
153
+ CHECK(safe_ptr_assign(
154
+ kernel_, new jit_sve_512_conv_bwd_data_kernel_f32(pd()->jcp_)));
155
+ return kernel_->create_kernel();
156
+ }
157
+
158
+ status_t execute(const exec_ctx_t &ctx) const override {
159
+ if (pd()->ndims() == 3)
160
+ execute_backward_data_1d(ctx);
161
+ else if (pd()->ndims() == 4)
162
+ execute_backward_data_2d(ctx);
163
+ else if (pd()->ndims() == 5)
164
+ execute_backward_data_3d(ctx);
165
+ else
166
+ assert(false);
167
+ return status::success;
168
+ }
169
+
170
+ private:
171
+ void execute_backward_data_1d(const exec_ctx_t &ctx) const;
172
+ void execute_backward_data_2d(const exec_ctx_t &ctx) const;
173
+ void execute_backward_data_3d(const exec_ctx_t &ctx) const;
174
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
175
+
176
+ std::unique_ptr<jit_sve_512_conv_bwd_data_kernel_f32> kernel_;
177
+ };
178
+
179
+ template <impl::data_type_t src_type,
180
+ impl::data_type_t diff_dst_type = src_type,
181
+ impl::data_type_t diff_weights_type = src_type>
182
+ struct jit_sve_512_convolution_bwd_weights_t : public primitive_t {
183
+ struct pd_t : public cpu_convolution_bwd_weights_pd_t {
184
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
185
+ const convolution_fwd_pd_t *hint_fwd_pd)
186
+ : cpu_convolution_bwd_weights_pd_t(adesc, attr, hint_fwd_pd)
187
+ , jcp_() {}
188
+
189
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:", sve_512, ""),
190
+ jit_sve_512_convolution_bwd_weights_t);
191
+
192
+ status_t init(engine_t *engine) {
193
+ bool ok = true && desc()->prop_kind == prop_kind::backward_weights
194
+ && set_default_alg_kind(alg_kind::convolution_direct)
195
+ && expect_data_types(src_type, diff_weights_type,
196
+ diff_weights_type, diff_dst_type, data_type::undef)
197
+ && attr()->has_default_values() && !has_zero_dim_memory();
198
+ if (!ok) return status::unimplemented;
199
+
200
+ status_t status
201
+ = jit_sve_512_conv_bwd_weights_kernel_f32::init_conf(jcp_,
202
+ *desc(), src_md_, diff_weights_md_, diff_bias_md_,
203
+ diff_dst_md_, dnnl_get_max_threads());
204
+ if (status != status::success) return status;
205
+
206
+ init_balancers();
207
+
208
+ auto scratchpad = scratchpad_registry().registrar();
209
+ jit_sve_512_conv_bwd_weights_kernel_f32::init_scratchpad(
210
+ scratchpad, jcp_);
211
+
212
+ auto reducer_bia_scratchpad = memory_tracking::registrar_t(
213
+ scratchpad, memory_tracking::names::prefix_reducer_bia);
214
+ reducer_bia_conf_.init_scratchpad(reducer_bia_scratchpad);
215
+
216
+ return status;
217
+ }
218
+
219
+ jit_conv_conf_t jcp_;
220
+ typename cpu_reducer_t<diff_weights_type>::conf_t reducer_bia_conf_;
221
+
222
+ private:
223
+ void init_balancers() {
224
+ const size_t max_buffer_size = jcp_.nthr * 3 * 5 * 5 * 16 * 16;
225
+ if (with_bias()) {
226
+ reducer_bia_conf_.init(reduce_balancer_t(jcp_.nthr,
227
+ jcp_.oc_block, jcp_.ngroups * jcp_.nb_oc, jcp_.mb,
228
+ max_buffer_size, true));
229
+ }
230
+ }
231
+ };
232
+
233
+ jit_sve_512_convolution_bwd_weights_t(const pd_t *apd) : primitive_t(apd) {}
234
+
235
+ typedef typename prec_traits<src_type>::type src_data_t;
236
+ typedef typename prec_traits<diff_dst_type>::type diff_dst_data_t;
237
+ typedef typename prec_traits<diff_weights_type>::type diff_weights_data_t;
238
+
239
+ status_t init(engine_t *engine) override;
240
+
241
+ status_t execute(const exec_ctx_t &ctx) const override {
242
+ execute_backward_weights(ctx);
243
+ return status::success;
244
+ }
245
+
246
+ private:
247
+ void execute_backward_weights(const exec_ctx_t &ctx) const;
248
+ void prepare_scratchpad_data(const exec_ctx_t &ctx) const;
249
+ struct thread_info_t;
250
+ void compute_diff_weights(const thread_info_t *) const;
251
+ void compute_diff_weights_2d(const thread_info_t *) const;
252
+ void compute_diff_weights_3d(const thread_info_t *) const;
253
+ void reduce_diff_weights(const thread_info_t *) const;
254
+ void reduce_diff_weights_3d(const thread_info_t *) const;
255
+ void compute_diff_bias(const thread_info_t *) const;
256
+ void reduce_diff_bias(const thread_info_t *) const;
257
+
258
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
259
+
260
+ int nthr_, nthr_mb_, nthr_g_, nthr_oc_b_, nthr_ic_b_;
261
+
262
+ jit_sve_512_conv_bwd_weights_kernel_f32 *kernel_;
263
+ cpu_accumulator_1d_t<diff_weights_type> *acc_ker_;
264
+ cpu_reducer_t<diff_weights_type> *reducer_bias_;
265
+ };
266
+
267
+ } // namespace aarch64
268
+ } // namespace cpu
269
+ } // namespace impl
270
+ } // namespace dnnl
271
+
272
+ #endif
273
+
274
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_core_x8s8s32x_deconvolution.hpp ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2018-2022 Intel Corporation
3
+ * Copyright 2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_512_CORE_X8S8S32X_DECONVOLUTION_HPP
19
+ #define CPU_AARCH64_JIT_SVE_512_CORE_X8S8S32X_DECONVOLUTION_HPP
20
+
21
+ #include <functional>
22
+ #include <vector>
23
+
24
+ #include "common/c_types_map.hpp"
25
+ #include "common/dnnl_thread.hpp"
26
+ #include "common/memory.hpp"
27
+ #include "common/nstl.hpp"
28
+ #include "common/primitive.hpp"
29
+ #include "common/type_helpers.hpp"
30
+ #include "common/utils.hpp"
31
+
32
+ #include "cpu/aarch64/jit_generator.hpp"
33
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
34
+ #include "cpu/aarch64/jit_uni_deconv_zp_pad_str_kernel.hpp"
35
+ #include "cpu/cpu_deconvolution_pd.hpp"
36
+
37
+ namespace dnnl {
38
+ namespace impl {
39
+ namespace cpu {
40
+ namespace aarch64 {
41
+
42
+ using namespace Xbyak_aarch64;
43
+
44
+ typedef enum {
45
+ no_last_block = 0x1U,
46
+ last_ic_block = 0x2U,
47
+ last_sp_block = 0x4U,
48
+ } ker_block_t;
49
+
50
+ struct ur_w_blks_params_t {
51
+ struct single_ur_w_blk_params_t {
52
+ single_ur_w_blk_params_t(
53
+ int l_overflow, int r_overflow, bool process_sp_carefully)
54
+ : l_overflow(l_overflow)
55
+ , r_overflow(r_overflow)
56
+ , process_sp_carefully(process_sp_carefully) {}
57
+
58
+ // l_overflow - no. of spatial elements of weights standing out of
59
+ // src spatial when computing the 1st output pixel in the current blk
60
+ int l_overflow;
61
+ // r_overflow - no. of spatial elements of weights standing out of
62
+ // src spatial when computing the lst output pixel in the current blk
63
+ int r_overflow;
64
+ // process_sp_carefully - indicates if loading the last src sp
65
+ // for computation of the last dst sp of the block can't be done
66
+ // by fetching 4 src sp at once
67
+ bool process_sp_carefully;
68
+ };
69
+ std::vector<single_ur_w_blk_params_t> blks_params;
70
+ int num_pre_blks; // num of blocks with l_overflow>0
71
+ int num_post_blks; // num of blocks with r_overflow>0 or that need to be
72
+ // processed carefully
73
+ };
74
+
75
+ template <cpu_isa_t isa>
76
+ struct jit_sve_512_core_x8s8s32x_deconv_fwd_kernel : public jit_generator {
77
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_sve_512_core_x8s8s32x_deconv_fwd_ker_t);
78
+
79
+ jit_sve_512_core_x8s8s32x_deconv_fwd_kernel(const jit_conv_conf_t &ajcp,
80
+ const primitive_attr_t &attr, const memory_desc_t &dst_md);
81
+ ~jit_sve_512_core_x8s8s32x_deconv_fwd_kernel();
82
+
83
+ const jit_conv_conf_t &jcp;
84
+ const primitive_attr_t &attr_;
85
+
86
+ private:
87
+ const int ic_sub_step = 4;
88
+ const uint64_t isa_sveLen = cpu_isa_traits<isa>::vlen;
89
+
90
+ /* data regs */
91
+ const XReg reg_src = x8;
92
+ const XReg reg_filt = x9;
93
+ const XReg reg_dst = x10;
94
+ const XReg param1 = abi_param1;
95
+ const XReg reg_kh = abi_param2;
96
+ const XReg reg_ki = x14;
97
+
98
+ const XReg reg_nur_w = x3;
99
+ const XReg reg_bias = x2;
100
+ const XReg reg_icb = reg_bias;
101
+ const XReg reg_ptr_scales = x16;
102
+ const WReg reg_ptr_saturation_ubound = w16;
103
+ const XReg reg_oc_blocks = x6;
104
+
105
+ const XReg aux_reg_src = x11;
106
+ const XReg aux_reg_filt = x12;
107
+
108
+ const XReg aux_reg_src_d = x13;
109
+ const XReg aux_reg_filt_d = x17;
110
+
111
+ const XReg reg_compensation = x14;
112
+ const XReg reg_bias_alpha = abi_not_param1;
113
+ const XReg reg_overflow = x16;
114
+ const XReg reg_comp_strides = reg_overflow;
115
+ const XReg reg_ker_long_offt = x17;
116
+ const XReg &reg_zp_dst_ = x17;
117
+ const XReg &reg_zp_src_ = x17;
118
+ const XReg &reg_zp_compensation = x11;
119
+ const XReg reg_zp_src_pad_comp = x20;
120
+
121
+ PReg ktail_mask = p2;
122
+ const PReg mask_tmp = p4;
123
+
124
+ const ZReg vmm_tmp0 = z28;
125
+ const ZReg vmm_tmp1 = z29;
126
+ /* used during write-out section of store_output */
127
+ const ZReg vmm_saturation = z31;
128
+ const ZReg vmm_wei = z31;
129
+
130
+ /* unsigned input */
131
+ const ZReg vmm_shift = z30;
132
+ const ZReg vmm_comp = z30;
133
+ ///
134
+
135
+ ZReg vmm_out(int i_ur, int i_oc) {
136
+ int idx = i_ur * jcp.nb_oc_blocking + i_oc;
137
+ assert(idx < 31);
138
+ return ZReg(idx);
139
+ }
140
+
141
+ ZReg vmm_inp(int i_ic, int nb_x_blocking) const {
142
+ int idx = i_ic + nb_x_blocking * jcp.ur_w;
143
+ assert(idx < 31);
144
+ return ZReg(idx);
145
+ }
146
+ ZReg vmm_bias_alpha() { return ZReg(jcp.nb_oc_blocking * jcp.ur_w); }
147
+
148
+ template <typename T>
149
+ ZReg compress_addr(const XReg &base, T offt, const bool mask_flag = false,
150
+ const bool bcast = false) {
151
+ assert(bcast == false);
152
+ PReg mask = P_ALL_ONE;
153
+ XReg addr = base;
154
+
155
+ if (offt) {
156
+ add_imm(X_DEFAULT_ADDR, base, offt, X_TMP_0);
157
+ addr = X_DEFAULT_ADDR;
158
+ }
159
+
160
+ if (mask_flag) mask = PReg(ktail_mask.getIdx());
161
+
162
+ mov(X_TMP_0, 64);
163
+ ld1w(vmm_tmp0.s, mask / T_z, ptr(addr));
164
+ return vmm_tmp0;
165
+ }
166
+
167
+ int get_ow_start(int ki, int l_overflow) {
168
+ int res = (jcp.ow - 1 + jcp.r_pad) % jcp.stride_w
169
+ + l_overflow * jcp.stride_w
170
+ - (jcp.kw - 1 - ki) * (jcp.dilate_w + 1);
171
+ while (res < 0)
172
+ res += jcp.stride_w;
173
+ return res;
174
+ }
175
+
176
+ int get_ow_end(int ur_w, int ki, int r_overflow) {
177
+ if (utils::one_of(ur_w, jcp.ow, jcp.ur_w_tail))
178
+ ur_w += nstl::min(0, jcp.r_pad); // remove negative padding
179
+ int res = (ur_w - 1 + jcp.l_pad) % jcp.stride_w
180
+ + r_overflow * jcp.stride_w - ki * (jcp.dilate_w + 1);
181
+ while (res < 0)
182
+ res += jcp.stride_w;
183
+ return ur_w - res;
184
+ }
185
+
186
+ int get_blocking_size() const noexcept;
187
+ int get_tail_size() const noexcept;
188
+ void prepare_output(int ur_w);
189
+ void store_output(int ur_w, bool last_oc_block);
190
+ void compute(
191
+ const ZReg &vreg_acc, const ZReg &vreg_wei, const ZReg &vreg_src);
192
+ std::function<uint32_t()> prepare_round_robin_vmm_inp_generator(
193
+ int ur_w) const noexcept;
194
+ void apply_zp_src_pad_str_comp(
195
+ int ur_w, int l_overflow, int r_overflow, bool h_padded);
196
+ void append_zp_src_pad_str_comp(int ur_w, int l_overflow, int r_overflow,
197
+ bool h_padded, bool last_oc_block);
198
+ void compute_ker(int ur_w, int l_overflow, int r_overflow,
199
+ ker_block_t last_ic_block_flag, bool h_padded = false);
200
+ void kh_loop(int ur_w, int pad_l, int pad_r, ker_block_t last_ker_block);
201
+ void icb_loop(int ur_w, int pad_l, int pad_r, bool last_block);
202
+
203
+ ur_w_blks_params_t get_ur_w_blks_params();
204
+
205
+ void generate() override;
206
+ void cvt2ps(const data_type_t type_in, const ZReg &vmm_in, const ZReg &op,
207
+ const bool mask_flag);
208
+
209
+ void uni_ld1r(const VReg4S &d, const XReg &addr) { ld1r(d, ptr(addr)); }
210
+
211
+ void uni_ld1r(const ZRegS &d, const XReg &addr) {
212
+ ld1rw(d, P_ALL_ONE / T_z, ptr(addr));
213
+ }
214
+
215
+ void uni_fmin(const VReg4S &d, const VReg4S &s) { fmin(d, d, s); }
216
+
217
+ void uni_fmin(const ZRegS &d, const ZRegS &s) {
218
+ fmin(d, P_ALL_ONE / T_m, s);
219
+ }
220
+ };
221
+
222
+ struct _jit_sve_512_core_x8s8s32x_deconv_fwd_kernel {
223
+ _jit_sve_512_core_x8s8s32x_deconv_fwd_kernel(const jit_conv_conf_t &ajcp,
224
+ const primitive_attr_t &attr, const memory_desc_t &dst_md)
225
+ : kernel_(nullptr) {
226
+
227
+ int ch_block = ajcp.is_depthwise ? ajcp.ch_block : ajcp.ic_block;
228
+ switch (ch_block) {
229
+ case 16:
230
+ kernel_ = new jit_sve_512_core_x8s8s32x_deconv_fwd_kernel<
231
+ sve_512>(ajcp, attr, dst_md);
232
+ return;
233
+ case 8:
234
+ kernel_ = new jit_sve_512_core_x8s8s32x_deconv_fwd_kernel<
235
+ sve_256>(ajcp, attr, dst_md);
236
+ return;
237
+ case 4:
238
+ kernel_ = new jit_sve_512_core_x8s8s32x_deconv_fwd_kernel<
239
+ sve_128>(ajcp, attr, dst_md);
240
+ return;
241
+ default: assert(!"invalid channel blocking");
242
+ }
243
+ }
244
+
245
+ status_t create_kernel() { return kernel_->create_kernel(); }
246
+
247
+ ~_jit_sve_512_core_x8s8s32x_deconv_fwd_kernel() { delete kernel_; }
248
+
249
+ void operator()(const jit_deconv_call_s *p) const { (*kernel_)(p); }
250
+
251
+ static status_t init_conf(jit_conv_conf_t &jcp,
252
+ const deconvolution_desc_t &cd, memory_desc_t &src_md,
253
+ memory_desc_t &weights_md, memory_desc_t &dst_md,
254
+ const bool with_bias, memory_desc_t &bias_md,
255
+ primitive_attr_t &attr, int nthreads);
256
+
257
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
258
+ const jit_conv_conf_t &jcp, const primitive_attr_t &attr);
259
+
260
+ private:
261
+ DNNL_DISALLOW_COPY_AND_ASSIGN(_jit_sve_512_core_x8s8s32x_deconv_fwd_kernel);
262
+ jit_generator *kernel_;
263
+ };
264
+
265
+ struct jit_sve_512_core_x8s8s32x_deconvolution_fwd_t : public primitive_t {
266
+ struct pd_t : public cpu_deconvolution_fwd_pd_t {
267
+ using cpu_deconvolution_fwd_pd_t::cpu_deconvolution_fwd_pd_t;
268
+
269
+ DECLARE_COMMON_PD_T(
270
+ JIT_IMPL_NAME_HELPER("jit_deconvolution:", sve_512, ""),
271
+ jit_sve_512_core_x8s8s32x_deconvolution_fwd_t);
272
+
273
+ status_t init(engine_t *engine) {
274
+ using namespace data_type;
275
+ using skip_mask_t = primitive_attr_t::skip_mask_t;
276
+ const bool ok = mayiuse(sve_512) && is_fwd()
277
+ && (desc()->alg_kind & alg_kind::deconvolution_direct)
278
+ && utils::one_of(src_md(0)->data_type, s8, u8)
279
+ && weights_md(0)->data_type == s8
280
+ && IMPLICATION(with_bias(),
281
+ utils::one_of(
282
+ weights_md(1)->data_type, f32, s32, s8, u8))
283
+ && utils::one_of(dst_md(0)->data_type, f32, s32, s8, u8)
284
+ && desc()->accum_data_type == s32
285
+ && attr()->has_default_values(skip_mask_t::oscale_runtime
286
+ | skip_mask_t::post_ops
287
+ | skip_mask_t::zero_points_runtime);
288
+ if (!ok) return status::unimplemented;
289
+
290
+ CHECK(_jit_sve_512_core_x8s8s32x_deconv_fwd_kernel::init_conf(jcp_,
291
+ *desc(), src_md_, weights_md_, dst_md_, with_bias(),
292
+ bias_md_, attr_, dnnl_get_max_threads()));
293
+
294
+ auto scratchpad = scratchpad_registry().registrar();
295
+ _jit_sve_512_core_x8s8s32x_deconv_fwd_kernel::init_scratchpad(
296
+ scratchpad, jcp_, *attr());
297
+
298
+ return status::success;
299
+ }
300
+
301
+ jit_conv_conf_t jcp_;
302
+ };
303
+
304
+ jit_sve_512_core_x8s8s32x_deconvolution_fwd_t(const pd_t *apd)
305
+ : primitive_t(apd) {}
306
+
307
+ status_t init(engine_t *engine) override {
308
+ CHECK(safe_ptr_assign(kernel_,
309
+ new _jit_sve_512_core_x8s8s32x_deconv_fwd_kernel(
310
+ pd()->jcp_, *pd()->attr(), *pd()->dst_md(0))));
311
+
312
+ if (zp::should_calculate_deconv_zp_src_pad_str_comp(pd()->jcp_)) {
313
+ CHECK(safe_ptr_assign(zp_src_pad_comp_kernel_,
314
+ zp::create_deconv_zp_pad_str_comp_ker<sve_512>(
315
+ pd()->jcp_)));
316
+ const auto zp_kernel_status
317
+ = zp_src_pad_comp_kernel_->create_kernel();
318
+ if (zp_kernel_status != status::success) return zp_kernel_status;
319
+ }
320
+
321
+ return kernel_->create_kernel();
322
+ }
323
+
324
+ status_t execute(const exec_ctx_t &ctx) const override {
325
+ auto ndims = pd()->ndims();
326
+ if (ndims == 3)
327
+ return execute_forward_1d(ctx);
328
+ else if (ndims == 4)
329
+ return execute_forward_2d(ctx);
330
+ else if (ndims == 5)
331
+ return execute_forward_3d(ctx);
332
+ return status::runtime_error;
333
+ }
334
+
335
+ private:
336
+ status_t execute_forward_1d(const exec_ctx_t &ctx) const;
337
+ status_t execute_forward_2d(const exec_ctx_t &ctx) const;
338
+ status_t execute_forward_3d(const exec_ctx_t &ctx) const;
339
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
340
+ std::unique_ptr<_jit_sve_512_core_x8s8s32x_deconv_fwd_kernel> kernel_;
341
+ std::unique_ptr<zp::jit_uni_deconv_zp_pad_str_kernel_base_t>
342
+ zp_src_pad_comp_kernel_;
343
+ };
344
+
345
+ } // namespace aarch64
346
+ } // namespace cpu
347
+ } // namespace impl
348
+ } // namespace dnnl
349
+
350
+ #endif
351
+
352
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_x8s8s32x_conv_kernel.hpp ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021 Intel Corporation
3
+ * Copyright 2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_512_X8S8S32X_CONV_KERNEL_HPP
19
+ #define CPU_AARCH64_JIT_SVE_512_X8S8S32X_CONV_KERNEL_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/memory_tracking.hpp"
23
+
24
+ #include "cpu/aarch64/jit_generator.hpp"
25
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
26
+
27
+ namespace dnnl {
28
+ namespace impl {
29
+ namespace cpu {
30
+ namespace aarch64 {
31
+
32
+ using namespace Xbyak_aarch64;
33
+
34
+ struct jit_sve_512_x8s8s32x_fwd_kernel : public jit_generator {
35
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(_jit_sve_512_x8s8s32x_conv_fwd_ker_t)
36
+
37
+ enum { STATE_FIRST_DST_LOAD = 0x1U };
38
+
39
+ jit_sve_512_x8s8s32x_fwd_kernel(
40
+ const jit_conv_conf_t &ajcp, const primitive_attr_t &attr)
41
+ : jcp(ajcp), attr_(attr) {
42
+ if (jcp.with_eltwise) assert(!"not supported");
43
+
44
+ int ch_block = jcp.is_depthwise ? jcp.ch_block : jcp.ic_block;
45
+ switch (ch_block) {
46
+ case 16: sve_len_ = 64; break;
47
+ case 8: sve_len_ = 32; break;
48
+ case 4: sve_len_ = 16; break;
49
+ default: assert(!"unreachable"); break;
50
+ }
51
+ }
52
+
53
+ ~jit_sve_512_x8s8s32x_fwd_kernel() {}
54
+
55
+ jit_conv_conf_t jcp;
56
+ const primitive_attr_t &attr_;
57
+
58
+ static status_t init_conf(jit_conv_conf_t &jcp,
59
+ const convolution_desc_t &cd, memory_desc_t &src_pd,
60
+ memory_desc_t &weights_pd, memory_desc_t &dst_pd,
61
+ memory_desc_t &bias_pd, const primitive_attr_t &attr, int nthreads);
62
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
63
+ const jit_conv_conf_t &jcp, const primitive_attr_t &attr);
64
+
65
+ private:
66
+ size_t sve_len_;
67
+
68
+ enum {
69
+ typesize = sizeof(float),
70
+ ker_reg_base_idx = 28,
71
+ ker_dw_reg_base_idx = 30,
72
+ ker_zp_reg_base_idx = 26,
73
+ };
74
+ typedef enum {
75
+ no_last_block,
76
+ last_ic_block,
77
+ last_sp_block,
78
+ } ic_block_t;
79
+
80
+ /* data regs */
81
+ const XReg reg_ptr_scales = x7;
82
+ const XReg aux_reg_saturation = x7;
83
+ const XReg reg_inp = x8;
84
+ const XReg reg_ker = x9;
85
+ const XReg reg_out = x10;
86
+ const XReg aux_reg_inp = x11;
87
+ const XReg reg_ptr_sum_scale = x11;
88
+ const XReg aux_reg_ker = x12;
89
+ const XReg reg_compensation = x14;
90
+ const XReg aux_reg_inp_d = x13;
91
+ const XReg aux_reg_ker_d = x15;
92
+ // Using 3d regs as depthwise_3d is not yet supported
93
+ const XReg reg_inp_buffer_ptr = aux_reg_inp_d;
94
+ const XReg aux_reg_inp_buffer_ptr = aux_reg_ker_d;
95
+
96
+ /* counter regs */
97
+ const XReg reg_bias_alpha = x1;
98
+ const XReg reg_param1 = x0;
99
+ const XReg reg_oi = x3;
100
+ const XReg reg_bias = x2;
101
+ const XReg reg_oc_blocks = x6;
102
+ const XReg reg_owb = aux_reg_ker;
103
+ const XReg reg_scratch = reg_compensation;
104
+ const XReg reg_kj = reg_ptr_scales;
105
+ const XReg reg_ki = reg_compensation;
106
+ const XReg reg_overflow = reg_ptr_scales;
107
+ const XReg reg_icb = reg_bias;
108
+ const XReg reg_jmp_tbl_base = reg_kj;
109
+
110
+ XReg reg_stack = x22; // translator stack register
111
+
112
+ /* Temporay registers */
113
+ XReg reg_tmp0_imm = x23; // tmp for add_imm
114
+ XReg reg_tmp1_imm = x24; // tmp for add_imm
115
+ XReg reg_tmp0_adr = x25; // tmp for address value
116
+
117
+ const PReg ktail_mask = p2;
118
+ const PReg kblend_mask = p8;
119
+
120
+ const PReg mask_tmp = p3;
121
+ const PReg mask_tmp2 = p9;
122
+ const PReg mask_all_one = p4;
123
+
124
+ const ZReg vmm_wei = ZReg(31);
125
+ /* used during bias section of store_output */
126
+ const ZReg vmm_comp = ZReg(30); // only for unsigned input
127
+ const ZReg vmm_bias = ZReg(31);
128
+ const ZReg vmm_pre_load = ZReg(30); // only for signed input
129
+ /* used during post_op sum section of store_output */
130
+ const ZReg vmm_prev_dst = ZReg(31);
131
+ /* used during write-out section of store_output */
132
+ const ZReg vmm_saturation = ZReg(30);
133
+ const ZReg vmm_zero = ZReg(31);
134
+
135
+ /* used in compute_ker (but set during prepare_output) */
136
+ const ZReg vmm_shift = vmm_comp; // only for unsigned input
137
+ const ZReg vmm_tmp = ZReg(28); // not used for depthwise
138
+ const ZReg vmm_one
139
+ = ZReg(29); // set at start of kernel, not used for depthwise.
140
+
141
+ /* registers use only for depthwise
142
+ groups are always blocked by 16(padded if needed),
143
+ hence use only ZReg registers */
144
+ const ZReg zmm_wei = ZReg(31);
145
+ ZReg zmm_tmp = ZReg(0);
146
+ ZReg zmm_src = ZReg(0);
147
+ ZReg zmm_shifted_zero = ZReg(0);
148
+ ZReg zmm_permute = ZReg(0);
149
+
150
+ bool mask_gflag;
151
+
152
+ ZReg vmm_out(int i_ur, int i_oc) {
153
+ int nb_x_blocking
154
+ = jcp.is_depthwise ? jcp.nb_ch_blocking : jcp.nb_oc_blocking;
155
+ int idx = i_ur * nb_x_blocking + i_oc;
156
+ assert(idx
157
+ < (jcp.is_depthwise ? ker_dw_reg_base_idx : ker_reg_base_idx));
158
+ return ZReg(idx);
159
+ }
160
+ ZReg zmm_out(int i_ur, int i_oc) {
161
+ int idx = vmm_out(i_ur, i_oc).getIdx();
162
+ assert(idx
163
+ < (jcp.is_depthwise ? ker_dw_reg_base_idx : ker_reg_base_idx));
164
+ return ZReg(idx);
165
+ }
166
+ ZReg vmm_inp(int i_ic, int nb_x_blocking) {
167
+ int idx = i_ic + nb_x_blocking * jcp.ur_w;
168
+ assert(idx < 31);
169
+ return ZReg(idx);
170
+ }
171
+ ZReg zmm_inp(int i_ic, int nb_x_blocking) {
172
+ int idx = i_ic + nb_x_blocking * jcp.ur_w;
173
+ const int max_idx = ker_dw_reg_base_idx;
174
+ assert(idx < max_idx);
175
+ MAYBE_UNUSED(max_idx);
176
+
177
+ return ZReg(idx);
178
+ }
179
+ ZReg vmm_bias_alpha() {
180
+ int nb_c_block
181
+ = jcp.is_depthwise ? jcp.nb_ch_blocking : jcp.nb_oc_blocking;
182
+ return ZReg(nb_c_block * jcp.ur_w);
183
+ }
184
+ ZReg xmm_bias_alpha() {
185
+ int nb_c_block
186
+ = jcp.is_depthwise ? jcp.nb_ch_blocking : jcp.nb_oc_blocking;
187
+ return ZReg(nb_c_block * jcp.ur_w);
188
+ }
189
+ int get_ow_start(int ki, int pad_l) {
190
+ return nstl::max(0,
191
+ utils::div_up(pad_l - ki * (jcp.dilate_w + 1), jcp.stride_w));
192
+ }
193
+ int get_ow_end(int ur_w, int ki, int pad_r) {
194
+ return ur_w
195
+ - nstl::max(0,
196
+ utils::div_up(
197
+ pad_r - (jcp.kw - 1 - ki) * (jcp.dilate_w + 1),
198
+ jcp.stride_w));
199
+ }
200
+
201
+ void prepare_output(int ur_w);
202
+ void store_output(int ur_w, bool last_oc_block_flag);
203
+ void compute_ker_dw(int ur_w, int pad_l, int pad_r,
204
+ ic_block_t last_ic_block_flag, bool h_padded);
205
+ void compute_ker(int ur_w, int pad_l, int pad_r,
206
+ ic_block_t last_ic_block_flag, bool h_padded = false);
207
+ void kh_loop(int ur_w, int pad_l, int pad_r, ic_block_t last_ic_block_flag);
208
+ void icb_loop(int ur_w, int pad_l, int pad_r, bool is_last_spatial_block);
209
+ void generate() override;
210
+ void cvt2ps(data_type_t type_in, ZReg ymm_in, const XReg reg_base,
211
+ const int offset, bool mask_flag);
212
+ void vmm_mask_all_one();
213
+ void vmm_load_src(ZReg src, XReg reg_addr, bool mask_flag);
214
+
215
+ int get_offset(int raw_offt) {
216
+ auto offt = raw_offt;
217
+ int scale = 0;
218
+ const int EVEX_max_8b_offt = 0x200;
219
+ if (EVEX_max_8b_offt <= offt && offt < 3 * EVEX_max_8b_offt) {
220
+ offt = offt - 2 * EVEX_max_8b_offt;
221
+ scale = 1;
222
+ } else if (3 * EVEX_max_8b_offt <= offt
223
+ && offt < 5 * EVEX_max_8b_offt) {
224
+ offt = offt - 4 * EVEX_max_8b_offt;
225
+ scale = 2;
226
+ }
227
+
228
+ auto re = offt;
229
+ if (scale) re = re + (2 * EVEX_max_8b_offt) * scale;
230
+
231
+ return re;
232
+ }
233
+
234
+ XReg get_comp_addr_reg(XReg base, int offset = 0) {
235
+ auto offt = get_offset(offset);
236
+
237
+ if (offt == 0) return base;
238
+
239
+ auto reg_tmp_adr = reg_tmp0_adr;
240
+ auto reg_tmp_imm = reg_tmp0_imm;
241
+ add_imm(reg_tmp_adr, base, offt, reg_tmp_imm);
242
+
243
+ return reg_tmp_adr;
244
+ }
245
+
246
+ static bool post_ops_ok(jit_conv_conf_t &jcp, const primitive_attr_t &attr);
247
+ };
248
+
249
+ } // namespace aarch64
250
+ } // namespace cpu
251
+ } // namespace impl
252
+ } // namespace dnnl
253
+
254
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_sve_512_x8s8s32x_convolution.hpp ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021 Intel Corporation
3
+ * Copyright 2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_SVE_X8S8S32X_CONVOLUTION_HPP
19
+ #define CPU_AARCH64_JIT_SVE_X8S8S32X_CONVOLUTION_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/dnnl_thread.hpp"
23
+ #include "common/memory_tracking.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/utils.hpp"
26
+
27
+ #include "cpu/cpu_convolution_pd.hpp"
28
+
29
+ #include "cpu/aarch64/jit_sve_512_x8s8s32x_conv_kernel.hpp"
30
+
31
+ namespace dnnl {
32
+ namespace impl {
33
+ namespace cpu {
34
+ namespace aarch64 {
35
+
36
+ template <impl::data_type_t src_type, impl::data_type_t dst_type>
37
+ struct jit_sve_512_x8s8s32x_convolution_fwd_t : public primitive_t {
38
+ struct pd_t : public cpu_convolution_fwd_pd_t {
39
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
40
+ const typename pd_t::base_class *hint_fwd_pd)
41
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd), jcp_() {}
42
+
43
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_int8:", sve_512, ""),
44
+ jit_sve_512_x8s8s32x_convolution_fwd_t);
45
+
46
+ status_t init(engine_t *engine) {
47
+ using smask_t = primitive_attr_t::skip_mask_t;
48
+ bool ok = true && is_fwd()
49
+ && set_default_alg_kind(alg_kind::convolution_direct)
50
+ && expect_data_types(src_type, data_type::s8,
51
+ data_type::undef, dst_type, data_type::s32)
52
+ && IMPLICATION(with_bias(),
53
+ utils::one_of(bias_md_.data_type, data_type::f32,
54
+ data_type::s32, data_type::s8,
55
+ data_type::u8))
56
+ && attr()->has_default_values(
57
+ smask_t::oscale_runtime | smask_t::post_ops,
58
+ dst_type)
59
+ && !has_zero_dim_memory();
60
+ if (!ok) return status::unimplemented;
61
+
62
+ status_t status = jit_sve_512_x8s8s32x_fwd_kernel::init_conf(jcp_,
63
+ *desc(), src_md_, weights_md_, dst_md_, bias_md_, *attr(),
64
+ dnnl_get_max_threads());
65
+ if (status != status::success) return status;
66
+
67
+ auto scratchpad = scratchpad_registry().registrar();
68
+ jit_sve_512_x8s8s32x_fwd_kernel::init_scratchpad(
69
+ scratchpad, jcp_, *attr());
70
+
71
+ return status;
72
+ }
73
+
74
+ jit_conv_conf_t jcp_;
75
+ };
76
+
77
+ jit_sve_512_x8s8s32x_convolution_fwd_t(const pd_t *apd)
78
+ : primitive_t(apd) {}
79
+
80
+ typedef typename prec_traits<src_type>::type src_data_t;
81
+ typedef typename prec_traits<data_type::s8>::type wei_data_t;
82
+ typedef typename prec_traits<dst_type>::type dst_data_t;
83
+
84
+ status_t init(engine_t *engine) override {
85
+ CHECK(safe_ptr_assign(kernel_,
86
+ new jit_sve_512_x8s8s32x_fwd_kernel(
87
+ pd()->jcp_, *pd()->attr())));
88
+ return kernel_->create_kernel();
89
+ }
90
+
91
+ status_t execute(const exec_ctx_t &ctx) const override {
92
+ const auto &_pd = pd();
93
+ if (_pd->ndims() == 3)
94
+ return execute_forward_1d(ctx);
95
+ else if (_pd->ndims() == 4)
96
+ if (_pd->jcp_.is_depthwise)
97
+ return execute_forward_2d_dw(ctx);
98
+ else
99
+ return execute_forward_2d(ctx);
100
+ else if (_pd->ndims() == 5)
101
+ return execute_forward_3d(ctx);
102
+ return status::unimplemented;
103
+ }
104
+
105
+ private:
106
+ status_t execute_forward_1d(const exec_ctx_t &ctx) const;
107
+ status_t execute_forward_2d(const exec_ctx_t &ctx) const;
108
+ status_t execute_forward_2d_dw(const exec_ctx_t &ctx) const;
109
+ status_t execute_forward_3d(const exec_ctx_t &ctx) const;
110
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
111
+
112
+ std::unique_ptr<jit_sve_512_x8s8s32x_fwd_kernel> kernel_;
113
+ };
114
+
115
+ } // namespace aarch64
116
+ } // namespace cpu
117
+ } // namespace impl
118
+ } // namespace dnnl
119
+
120
+ #endif
121
+
122
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_1x1_conv_utils.hpp ADDED
@@ -0,0 +1,680 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Intel Corporation
3
+ * Copyright 2021-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_1X1_CONV_UTILS_HPP
19
+ #define CPU_AARCH64_JIT_UNI_1X1_CONV_UTILS_HPP
20
+
21
+ #include "common/convolution_pd.hpp"
22
+ #include "common/dnnl_thread.hpp"
23
+ #include "common/memory_tracking.hpp"
24
+ #include "common/nstl.hpp"
25
+ #include "common/primitive_desc_iterator.hpp"
26
+ #include "common/type_helpers.hpp"
27
+ #include "common/utils.hpp"
28
+
29
+ #include "cpu/aarch64/jit_generator.hpp"
30
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
31
+
32
+ namespace dnnl {
33
+ namespace impl {
34
+ namespace cpu {
35
+ namespace aarch64 {
36
+
37
+ struct reduce_to_unit_stride_t {
38
+ convolution_desc_t conv_d_;
39
+ bool reduce_src_;
40
+ size_t space_per_thread_;
41
+ };
42
+
43
+ /* 1x1-kernel does not support non-unit strides so far, so the idea is:
44
+ * - for fwd or bwd_weights: to copy src to a scratch memory (with strides
45
+ * equal to 1) and then call the kernel
46
+ * - for bwd_data: reduce the problem to the one with unit stride by
47
+ * performing computations in a scratch memory (with strides equal to 1)
48
+ * and then copy the result to diff_src */
49
+ template <typename conv_pd_t>
50
+ inline void rtus_prepare(conv_pd_t *self, const convolution_desc_t *&conv_d,
51
+ const memory_desc_t *&src_d, const memory_desc_t *dst_d) {
52
+ const int ndims = src_d->ndims;
53
+
54
+ bool rtus_applicable = utils::one_of(ndims, 3, 4);
55
+ if (ndims == 3)
56
+ rtus_applicable = rtus_applicable && conv_d->strides[0] != 1
57
+ && conv_d->src_desc.data_type != data_type::s32;
58
+ else
59
+ rtus_applicable = rtus_applicable
60
+ && (conv_d->strides[0] != 1 || conv_d->strides[1] != 1);
61
+ for (int d = 2; d < ndims; ++d) {
62
+ /* TODO: relax these conditions (by improving reducer) */
63
+ rtus_applicable = rtus_applicable && conv_d->padding[0][d - 2] == 0
64
+ && dst_d->dims[d] * conv_d->strides[d - 2] == src_d->dims[d];
65
+ }
66
+ if (!rtus_applicable) return;
67
+
68
+ const auto dat_tag = ndims == 3
69
+ ? memory_desc_wrapper(src_d).matches_one_of_tag(
70
+ format_tag::nCw8c, format_tag::nCw16c, format_tag::nwc)
71
+ : memory_desc_wrapper(src_d).matches_one_of_tag(
72
+ format_tag::nChw8c, format_tag::nChw16c, format_tag::nhwc);
73
+ if (dat_tag == format_tag::undef) return;
74
+
75
+ const bool is_nspc
76
+ = utils::one_of(dat_tag, format_tag::nwc, format_tag::nhwc);
77
+ if (is_nspc && !mayiuse(sve_128)) return;
78
+
79
+ // rtus is applicable, configure it.
80
+ self->rtus_.reduce_src_ = true;
81
+ conv_d = &(self->rtus_.conv_d_ = *conv_d);
82
+ self->rtus_.conv_d_.strides[0] = 1;
83
+ if (ndims == 4) self->rtus_.conv_d_.strides[1] = 1;
84
+ utils::array_set(self->rtus_.conv_d_.padding[0], 0, 2);
85
+ if (ndims == 4) utils::array_set(self->rtus_.conv_d_.padding[1], 0, 2);
86
+ const int ic = src_d->dims[1];
87
+ if (self->desc()->prop_kind == prop_kind::backward_data) {
88
+ data_type_t data_type = self->rtus_.conv_d_.diff_src_desc.data_type;
89
+ src_d = &(self->rtus_.conv_d_.diff_src_desc = *dst_d);
90
+ self->rtus_.conv_d_.diff_src_desc.dims[1] = ic;
91
+ self->rtus_.conv_d_.diff_src_desc.data_type = data_type;
92
+ memory_desc_wrapper::compute_blocking(
93
+ self->rtus_.conv_d_.diff_src_desc, dat_tag);
94
+ } else {
95
+ data_type_t data_type = self->rtus_.conv_d_.src_desc.data_type;
96
+ src_d = &(self->rtus_.conv_d_.src_desc = *dst_d);
97
+ self->rtus_.conv_d_.src_desc.dims[1] = ic;
98
+ self->rtus_.conv_d_.src_desc.data_type = data_type;
99
+ memory_desc_wrapper::compute_blocking(
100
+ self->rtus_.conv_d_.src_desc, dat_tag);
101
+ }
102
+ }
103
+
104
+ template <typename conv_pd_t>
105
+ inline void rtus_prepare_space_info(conv_pd_t *self,
106
+ memory_tracking::registrar_t &scratchpad, int max_threads) {
107
+ if (!self->rtus_.reduce_src_) return;
108
+ const auto &jcp = self->jcp_;
109
+ const bool is_nspc
110
+ = utils::one_of(jcp.src_tag, format_tag::nhwc, format_tag::nwc);
111
+
112
+ const size_t factor = utils::pick_by_prop_kind(self->desc()->prop_kind,
113
+ jcp.nb_reduce, jcp.nb_load_blocking_max, jcp.nb_bcast_blocking);
114
+ size_t typesize
115
+ = types::data_type_size(self->invariant_src_md()->data_type);
116
+
117
+ self->rtus_.space_per_thread_
118
+ = is_nspc ? jcp.is * jcp.ic : factor * jcp.is * jcp.ic_block;
119
+ scratchpad.book(memory_tracking::names::key_conv_rtus_space,
120
+ max_threads * self->rtus_.space_per_thread_, typesize);
121
+ }
122
+
123
+ template <cpu_isa_t isa>
124
+ struct rtus_driver_t : public jit_generator {
125
+
126
+ struct call_params_t {
127
+ const void *ws; /* reduced image (w/ strides = 1) */
128
+ const void *src; /* source image (w/ non-unit strides) */
129
+ size_t icb;
130
+ size_t os;
131
+ size_t iw_start;
132
+ };
133
+
134
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(rtus_driver_t)
135
+
136
+ Xbyak_aarch64::XReg reg_ws = x5;
137
+ Xbyak_aarch64::XReg reg_src = x6;
138
+ Xbyak_aarch64::XReg reg_icb = x7;
139
+ Xbyak_aarch64::XReg reg_os = x8;
140
+ Xbyak_aarch64::XReg reg_iw_start = x9;
141
+
142
+ Xbyak_aarch64::XReg reg_cur_os = x10;
143
+ Xbyak_aarch64::XReg reg_cur_iw = x11;
144
+ Xbyak_aarch64::XReg reg_cur_src = x12;
145
+ Xbyak_aarch64::XReg reg_cur_src_fin = reg_cur_iw; /* just reuse */
146
+
147
+ Xbyak_aarch64::PReg tail_mask = p1;
148
+
149
+ // nspc section
150
+ Xbyak_aarch64::XReg reg_cur_icb = x13;
151
+ Xbyak_aarch64::XReg reg_tail_mask = x14;
152
+ Xbyak_aarch64::XReg reg_icb_remainder = x15;
153
+ Xbyak_aarch64::XReg reg_ws_copy = x16;
154
+
155
+ int iw_, stride_w_;
156
+ int src_step_h_, src_step_icb_, ws_step_icb_, vlen_, vlen_shift_;
157
+ bool src_to_ws_;
158
+ size_t typesize_;
159
+ int ic_, ic_tail_;
160
+ bool is_nspc_;
161
+
162
+ Xbyak_aarch64::ZReg reg_zero = Xbyak_aarch64::ZReg(0);
163
+ Xbyak_aarch64::ZReg reg_v = Xbyak_aarch64::ZReg(1);
164
+
165
+ rtus_driver_t(int iw, int stride_w, int src_step_h, int src_step_icb,
166
+ int ws_step_icb, bool src_to_ws, size_t typesize, int ic,
167
+ bool is_nspc = false)
168
+ : iw_(iw)
169
+ , stride_w_(stride_w)
170
+ , src_step_h_(src_step_h)
171
+ , src_step_icb_(src_step_icb)
172
+ , ws_step_icb_(ws_step_icb)
173
+ , src_to_ws_(src_to_ws)
174
+ , typesize_(typesize)
175
+ , ic_(ic)
176
+ , is_nspc_(is_nspc) {
177
+ using namespace Xbyak_aarch64;
178
+
179
+ assert(ic_ > 0);
180
+
181
+ auto Vmm = [=](int idx, size_t typesize) {
182
+ ZReg res = ZReg(idx);
183
+ if (is_nspc_) {
184
+ switch (isa) {
185
+ case sve_512: res = ZReg(idx); break;
186
+ default: assert(!"Not supported isa"); res = ZReg(idx);
187
+ }
188
+ return res;
189
+ }
190
+ switch (isa) {
191
+ case sve_512:
192
+ switch (typesize) {
193
+ case 4: res = ZReg(idx); break;
194
+ default:
195
+ assert(!"Not supported typesize");
196
+ res = ZReg(idx);
197
+ }
198
+ }
199
+ return res;
200
+ };
201
+
202
+ reg_zero = Vmm(0, typesize);
203
+ reg_v = Vmm(1, typesize);
204
+
205
+ vlen_ = reg_v.getBit() / 8;
206
+ vlen_shift_ = 0;
207
+
208
+ int tvlen = is_nspc_ ? typesize_ : vlen_;
209
+ while (tvlen > 1) {
210
+ tvlen /= 2;
211
+ vlen_shift_++;
212
+ }
213
+
214
+ const int simd_w = vlen_ / sizeof(float);
215
+ ic_tail_ = ic_ % simd_w;
216
+ }
217
+
218
+ void loop_is() {
219
+ using namespace Xbyak_aarch64;
220
+
221
+ mov(reg_cur_src, reg_src);
222
+ mov(reg_cur_iw, reg_iw_start);
223
+ mov(reg_cur_os, reg_os);
224
+
225
+ Label is_loop;
226
+ L(is_loop);
227
+
228
+ if (src_to_ws_) {
229
+ ldr(reg_v, ptr(reg_cur_src));
230
+ str(reg_v, ptr(reg_ws));
231
+ } else {
232
+ ldr(reg_v, ptr(reg_ws));
233
+ str(reg_v, ptr(reg_cur_src));
234
+ for (int w = 1; w < stride_w_; ++w) {
235
+ add_imm(X_TMP_3, reg_cur_src, w * vlen_, X_TMP_4);
236
+ str(reg_zero, ptr(X_TMP_3));
237
+ }
238
+ }
239
+
240
+ add_imm(reg_ws, reg_ws, vlen_, X_TMP_4);
241
+ add_imm(reg_cur_src, reg_cur_src, stride_w_ * vlen_, X_TMP_4);
242
+
243
+ // for 1d or stride_h=1 convolutions the loop over h should be skipped
244
+ if (!(src_step_icb_ == iw_ || src_step_h_ == iw_)) {
245
+ Label skip_h_step;
246
+ add_imm(reg_cur_iw, reg_cur_iw, stride_w_, X_TMP_4);
247
+ cmp(reg_cur_iw, iw_);
248
+ b(LT, skip_h_step);
249
+
250
+ if (src_to_ws_) {
251
+ add_imm(reg_cur_src, reg_cur_src, (src_step_h_ - iw_) * vlen_,
252
+ X_TMP_4);
253
+ } else {
254
+ mov(reg_cur_src_fin, reg_cur_src);
255
+ add_imm(reg_cur_src_fin, reg_cur_src_fin,
256
+ (src_step_h_ - iw_) * vlen_, X_TMP_4);
257
+ Label ih_loop;
258
+ L(ih_loop);
259
+
260
+ for (int w = 0; w < stride_w_; ++w) {
261
+ add_imm(X_TMP_3, reg_cur_src, w * vlen_, X_TMP_4);
262
+ str(reg_zero, ptr(X_TMP_3));
263
+ }
264
+
265
+ add_imm(reg_cur_src, reg_cur_src, stride_w_ * vlen_, X_TMP_4);
266
+ cmp(reg_cur_src, reg_cur_src_fin);
267
+ b(LT, ih_loop);
268
+ }
269
+ mov(reg_cur_iw, 0);
270
+ L(skip_h_step);
271
+ }
272
+
273
+ subs_imm(reg_cur_os, reg_cur_os, vlen_, X_TMP_4);
274
+ b(NE, is_loop);
275
+
276
+ /* restore dst */
277
+ sub(reg_ws, reg_ws, reg_os);
278
+ }
279
+
280
+ void loop_is_nspc() {
281
+ using namespace Xbyak_aarch64;
282
+
283
+ assert(is_nspc_);
284
+
285
+ mov(reg_cur_src, reg_src);
286
+ mov(reg_cur_iw, reg_iw_start);
287
+
288
+ if (isa == sve_512) {
289
+ and_(reg_icb_remainder, reg_icb, (vlen_ / typesize_) - 1);
290
+ mov_imm(X_TMP_0, 0);
291
+ whilelt(tail_mask.s, X_TMP_0, reg_icb_remainder);
292
+ }
293
+
294
+ auto load_reg = [=](const ZReg &vreg, const XReg &reg,
295
+ const int64_t offset, bool tail = false) {
296
+ if (is_superset(isa, sve_128)) {
297
+ add_imm(X_DEFAULT_ADDR, reg, offset, X_TMP_0);
298
+ switch (typesize_) {
299
+ case 4:
300
+ if (tail)
301
+ ld1w(vreg.s, tail_mask / T_z, ptr(X_DEFAULT_ADDR));
302
+ else
303
+ ld1w(vreg.s, P_ALL_ONE / T_z, ptr(X_DEFAULT_ADDR));
304
+ break;
305
+ case 2:
306
+ if (tail)
307
+ ld1h(vreg.h, tail_mask / T_z, ptr(X_DEFAULT_ADDR));
308
+ else
309
+ ld1h(vreg.h, P_ALL_ONE / T_z, ptr(X_DEFAULT_ADDR));
310
+ break;
311
+ case 1:
312
+ if (tail)
313
+ ld1b(vreg.b, tail_mask / T_z, ptr(X_DEFAULT_ADDR));
314
+ else
315
+ ld1b(vreg.b, P_ALL_ONE / T_z, ptr(X_DEFAULT_ADDR));
316
+ break;
317
+ default: assert(!"Unsupported typesize");
318
+ }
319
+ } else {
320
+ assert("!Unsupported isa");
321
+ }
322
+ };
323
+
324
+ auto store_reg = [=](const XReg &reg, const ZReg &vreg,
325
+ const int64_t offset, bool tail = false) {
326
+ if (is_superset(isa, sve_128)) {
327
+ add_imm(X_DEFAULT_ADDR, reg, offset, X_TMP_0);
328
+ switch (typesize_) {
329
+ case 4:
330
+ if (tail)
331
+ st1w(vreg.s, tail_mask / T_z, ptr(X_DEFAULT_ADDR));
332
+ else
333
+ st1w(vreg.s, P_ALL_ONE / T_z, ptr(X_DEFAULT_ADDR));
334
+ break;
335
+ case 2:
336
+ if (tail)
337
+ st1h(vreg.h, tail_mask / T_z, ptr(X_DEFAULT_ADDR));
338
+ else
339
+ st1h(vreg.h, P_ALL_ONE / T_z, ptr(X_DEFAULT_ADDR));
340
+ break;
341
+ case 1:
342
+ if (tail)
343
+ st1b(vreg.b, tail_mask / T_z, ptr(X_DEFAULT_ADDR));
344
+ else
345
+ st1b(vreg.b, P_ALL_ONE / T_z, ptr(X_DEFAULT_ADDR));
346
+ break;
347
+ default: assert(!"Unsupported typesize");
348
+ }
349
+ } else {
350
+ assert("!Unsupported isa");
351
+ }
352
+ };
353
+
354
+ mov(reg_ws_copy, reg_ws);
355
+ lsl(reg_icb, reg_icb, vlen_shift_);
356
+
357
+ const size_t w_step_factor = ic_ * typesize_;
358
+ const size_t max_load_store_bytes = typesize_ == 4 ? 32 : 16;
359
+ const size_t load_store_size
360
+ = isa == sve_512 ? vlen_ : max_load_store_bytes;
361
+
362
+ Label is_loop, ic_loop, ic_loop_tail, ic_loop_finish;
363
+ L(is_loop);
364
+ {
365
+ mov(reg_cur_src, reg_src);
366
+ mov(reg_ws, reg_ws_copy);
367
+ mov(reg_cur_icb, reg_icb);
368
+
369
+ L(ic_loop);
370
+ {
371
+ cmp(reg_cur_icb, load_store_size);
372
+ b(LT, ic_loop_tail);
373
+
374
+ if (src_to_ws_) {
375
+ load_reg(reg_v, reg_cur_src, 0);
376
+ store_reg(reg_ws, reg_v, 0);
377
+ } else {
378
+ load_reg(reg_v, reg_ws, 0);
379
+ store_reg(reg_cur_src, reg_v, 0);
380
+ for (int w = 1; w < stride_w_; ++w)
381
+ store_reg(reg_cur_src, reg_zero, w * w_step_factor);
382
+ }
383
+ add_imm(reg_ws, reg_ws, load_store_size, X_TMP_0);
384
+ add_imm(reg_cur_src, reg_cur_src, load_store_size, X_TMP_0);
385
+
386
+ sub_imm(reg_cur_icb, reg_cur_icb, load_store_size, X_TMP_0);
387
+ b(ic_loop);
388
+ }
389
+
390
+ L(ic_loop_tail);
391
+ {
392
+ cmp(reg_cur_icb, 0);
393
+ b(EQ, ic_loop_finish);
394
+
395
+ if (src_to_ws_) {
396
+ load_reg(reg_v, reg_cur_src, 0, true);
397
+ store_reg(reg_ws, reg_v, 0, true);
398
+ } else {
399
+ load_reg(reg_v, reg_ws, 0, true);
400
+ store_reg(reg_cur_src, reg_v, 0, true);
401
+ for (int w = 1; w < stride_w_; ++w)
402
+ store_reg(
403
+ reg_cur_src, reg_zero, w * w_step_factor, true);
404
+ }
405
+ }
406
+ L(ic_loop_finish);
407
+
408
+ add_imm(reg_ws_copy, reg_ws_copy, w_step_factor, X_TMP_0);
409
+ add_imm(reg_src, reg_src, stride_w_ * w_step_factor, X_TMP_0);
410
+
411
+ // for 1d or stride_h=1 convolutions the loop over h should be skipped
412
+ const bool skip_oh_step = src_step_h_ == iw_;
413
+ if (!skip_oh_step) {
414
+ mov(reg_cur_src, reg_src);
415
+ Label skip_h_step;
416
+ add_imm(reg_cur_iw, reg_cur_iw, stride_w_, X_TMP_0);
417
+ cmp(reg_cur_iw, iw_);
418
+ b(LT, skip_h_step);
419
+
420
+ if (src_to_ws_) {
421
+ add_imm(reg_src, reg_src,
422
+ (src_step_h_ - iw_) * w_step_factor, X_TMP_0);
423
+ } else {
424
+ mov(reg_cur_src_fin, reg_cur_src);
425
+ add_imm(reg_cur_src_fin, reg_cur_src_fin,
426
+ (src_step_h_ - iw_) * w_step_factor, X_TMP_0);
427
+ Label ih_loop_nhwc, ic_ih_loop_nhwc, ic_tail_ih_loop_nhwc,
428
+ ic_finish_ih_loop_nhwc;
429
+ L(ih_loop_nhwc);
430
+ mov(reg_cur_src, reg_src);
431
+ mov(reg_cur_icb, reg_icb);
432
+ L(ic_ih_loop_nhwc);
433
+ cmp(reg_cur_icb, load_store_size);
434
+ b(LT, ic_tail_ih_loop_nhwc);
435
+
436
+ for (int w = 0; w < stride_w_; ++w)
437
+ store_reg(reg_cur_src, reg_zero, w * w_step_factor);
438
+
439
+ add_imm(reg_cur_src, reg_cur_src, load_store_size, X_TMP_0);
440
+ subs_imm(
441
+ reg_cur_icb, reg_cur_icb, load_store_size, X_TMP_0);
442
+ b(NE, ic_ih_loop_nhwc);
443
+
444
+ L(ic_tail_ih_loop_nhwc);
445
+ cmp(reg_cur_icb, 0);
446
+ b(LE, ic_finish_ih_loop_nhwc);
447
+
448
+ for (int w = 0; w < stride_w_; ++w)
449
+ store_reg(
450
+ reg_cur_src, reg_zero, w * w_step_factor, true);
451
+
452
+ L(ic_finish_ih_loop_nhwc);
453
+
454
+ add_imm(reg_src, reg_src, stride_w_ * w_step_factor,
455
+ X_TMP_0);
456
+ cmp(reg_src, reg_cur_src_fin);
457
+ b(LT, ih_loop_nhwc);
458
+ }
459
+ eor(reg_cur_iw, reg_cur_iw, reg_cur_iw);
460
+ L(skip_h_step);
461
+ }
462
+
463
+ subs(reg_os, reg_os, 1);
464
+ b(NE, is_loop);
465
+ }
466
+ }
467
+
468
+ void generate() override {
469
+ using namespace Xbyak_aarch64;
470
+ assert(isa == sve_512);
471
+
472
+ preamble();
473
+ #define READ_PARAM(what) \
474
+ ldr(reg_##what, \
475
+ ptr(abi_param1, \
476
+ static_cast<int32_t>(offsetof(call_params_t, what))))
477
+ READ_PARAM(src);
478
+ READ_PARAM(icb);
479
+ READ_PARAM(os);
480
+ READ_PARAM(iw_start);
481
+ READ_PARAM(ws);
482
+ #undef READ_PARAM
483
+
484
+ if (!src_to_ws_) {
485
+ switch (reg_zero.getBit() / 8) {
486
+ case 64 /*ZReg*/: {
487
+ Xbyak_aarch64::ZRegS zreg_s(reg_zero.getIdx());
488
+ fmov(zreg_s); // zero clear
489
+ break;
490
+ }
491
+ default: assert(!"rtus kernel failure");
492
+ }
493
+ }
494
+ if (is_nspc_) {
495
+ loop_is_nspc();
496
+ } else {
497
+ lsl(reg_os, reg_os, vlen_shift_);
498
+
499
+ Label icb_loop;
500
+ L(icb_loop);
501
+
502
+ loop_is();
503
+
504
+ add_imm(reg_ws, reg_ws, ws_step_icb_ * vlen_, X_TMP_4);
505
+ add_imm(reg_src, reg_src, src_step_icb_ * vlen_, X_TMP_4);
506
+
507
+ subs_imm(reg_icb, reg_icb, vlen_ / typesize_, X_TMP_4);
508
+ b(NE, icb_loop);
509
+ }
510
+
511
+ postamble();
512
+ }
513
+ };
514
+
515
+ template <cpu_isa_t isa, typename conv_t>
516
+ inline status_t init_rtus_driver(conv_t *self) {
517
+ const auto &conf = *self->pd();
518
+ if (!conf.rtus_.reduce_src_) return status::success;
519
+
520
+ const auto &cd = *conf.desc();
521
+ const int ndims = conf.ndims();
522
+ const int stride_h = (conf.ndims() == 3) ? 1 : cd.strides[0];
523
+ const int stride_w = cd.strides[ndims - 3];
524
+
525
+ const bool is_bwd_data = cd.prop_kind == prop_kind::backward_data;
526
+ const auto &src_d = is_bwd_data ? *conf.diff_src_md() : *conf.src_md();
527
+
528
+ const int ih = ndims == 3 ? 1 : src_d.dims[2];
529
+ const int iw = src_d.dims[ndims - 1];
530
+ const int ic = src_d.dims[1];
531
+
532
+ const auto src_tag = memory_desc_wrapper(src_d).matches_one_of_tag(
533
+ format_tag::nhwc, format_tag::nwc);
534
+ const bool is_nspc = src_tag != format_tag::undef;
535
+ const int src_step_h = stride_h * iw;
536
+ const int src_step_icb = !is_nspc ? ih * iw : 1;
537
+ const int ws_step_icb = !is_nspc ? conf.jcp_.is : 1;
538
+ const bool src_to_ws = !is_bwd_data;
539
+ const size_t typesize
540
+ = types::data_type_size(self->pd()->invariant_src_md()->data_type);
541
+
542
+ CHECK(safe_ptr_assign(self->rtus_driver_,
543
+ new rtus_driver_t<isa>(iw, stride_w, src_step_h, src_step_icb,
544
+ ws_step_icb, src_to_ws, typesize, ic, is_nspc)));
545
+
546
+ return self->rtus_driver_->create_kernel();
547
+ }
548
+
549
+ inline int best_divider(int value, int min_divider, int max_divider,
550
+ bool find_max, int step = 1) {
551
+ using namespace dnnl::impl::utils;
552
+ max_divider = nstl::max(1, nstl::min(max_divider, value));
553
+ min_divider = nstl::max(1, nstl::min(min_divider, max_divider));
554
+
555
+ auto loss_ratio = [](int total, int chunk) {
556
+ return float(rnd_up(total, chunk) - total) / rnd_up(total, chunk);
557
+ };
558
+
559
+ float min_loss = FLT_MAX;
560
+ int x_divider = max_divider;
561
+ for (int divider = max_divider; divider >= min_divider; divider -= step) {
562
+ const float loss = loss_ratio(value, divider);
563
+ if ((find_max && loss < min_loss) || (!find_max && loss <= min_loss)) {
564
+ min_loss = loss;
565
+ x_divider = divider;
566
+ }
567
+ }
568
+ return x_divider;
569
+ }
570
+
571
+ typedef jit_1x1_conv_conf_t jcp_t;
572
+
573
+ inline bool is_bcast_layout_nxc(const jcp_t &jcp) {
574
+ switch (jcp.prop_kind) {
575
+ case prop_kind::forward_training:
576
+ case prop_kind::forward_inference:
577
+ case prop_kind::backward_weights:
578
+ return utils::one_of(jcp.src_tag, format_tag::ndhwc,
579
+ format_tag::nhwc, format_tag::nwc);
580
+ case prop_kind::backward_data:
581
+ return utils::one_of(jcp.dst_tag, format_tag::ndhwc,
582
+ format_tag::nhwc, format_tag::nwc);
583
+ default: assert(!"invalid prop_kind"); return false;
584
+ }
585
+ }
586
+
587
+ inline bool is_load_layout_nxc(const jcp_t &jcp) {
588
+ return jcp.prop_kind == prop_kind::backward_weights
589
+ && utils::one_of(jcp.dst_tag, format_tag::ndhwc, format_tag::nhwc,
590
+ format_tag::nwc);
591
+ }
592
+
593
+ inline bool is_out_layout_nxc(const jcp_t &jcp) {
594
+ switch (jcp.prop_kind) {
595
+ case prop_kind::forward_training:
596
+ case prop_kind::forward_inference:
597
+ return utils::one_of(jcp.dst_tag, format_tag::ndhwc,
598
+ format_tag::nhwc, format_tag::nwc);
599
+ case prop_kind::backward_data:
600
+ return utils::one_of(jcp.src_tag, format_tag::ndhwc,
601
+ format_tag::nhwc, format_tag::nwc);
602
+ case prop_kind::backward_weights: return false;
603
+ default: assert(!"invalid prop_kind"); return false;
604
+ }
605
+ }
606
+
607
+ inline size_t get_bcast_u_offset(const jcp_t &jcp) {
608
+ return is_bcast_layout_nxc(jcp) ? jcp.ic : jcp.ic_block;
609
+ }
610
+
611
+ inline size_t get_bcast_j_offset(const jcp_t &jcp) {
612
+ return is_bcast_layout_nxc(jcp) ? jcp.reduce_dim : jcp.reduce_loop_unroll;
613
+ }
614
+
615
+ inline size_t get_bcast_offset(const jcp_t &jcp, int u, int j) {
616
+ size_t offset;
617
+ if (utils::one_of(jcp.prop_kind, prop_kind::forward_training,
618
+ prop_kind::forward_inference, prop_kind::backward_data)) {
619
+ assert(jcp.reduce_loop_unroll == jcp.reduce_block);
620
+ if (is_bcast_layout_nxc(jcp) || u != jcp.reduce_loop_unroll) {
621
+ offset = j * get_bcast_j_offset(jcp) + u;
622
+ } else {
623
+ offset = (jcp.bcast_dim + j) * get_bcast_j_offset(jcp);
624
+ }
625
+ } else {
626
+ offset = u * get_bcast_u_offset(jcp) + j;
627
+ }
628
+ return sizeof(float) * offset;
629
+ }
630
+
631
+ inline size_t get_load_u_offset(const jcp_t &jcp) {
632
+ return is_load_layout_nxc(jcp) ? jcp.oc : jcp.oc_block;
633
+ }
634
+
635
+ inline size_t get_load_i_offset(const jcp_t &jcp) {
636
+ return is_load_layout_nxc(jcp) ? jcp.oc_block : jcp.os;
637
+ }
638
+
639
+ inline size_t get_load_bwd_w_offset(const jcp_t &jcp, int i, int u0) {
640
+ if (is_load_layout_nxc(jcp)) {
641
+ return i * get_load_i_offset(jcp) + u0 * get_load_u_offset(jcp);
642
+ } else {
643
+ return (i * get_load_i_offset(jcp) + u0) * get_load_u_offset(jcp);
644
+ }
645
+ }
646
+
647
+ inline size_t get_output_i_offset(const jcp_t &jcp) {
648
+ if (is_out_layout_nxc(jcp)) {
649
+ return jcp.load_block;
650
+ } else {
651
+ return (jcp.with_dw_conv ? jcp.ow : jcp.bcast_dim) * jcp.load_block;
652
+ }
653
+ }
654
+
655
+ inline size_t get_output_j_offset(const jcp_t &jcp) {
656
+ return is_out_layout_nxc(jcp) ? jcp.load_dim : jcp.load_block;
657
+ }
658
+
659
+ inline size_t get_load_loop_output_fwd_offset(
660
+ const jcp_t &jcp, int load_loop_blk) {
661
+ size_t offset = load_loop_blk * jcp.oc_block * sizeof(float);
662
+ if (!is_out_layout_nxc(jcp)) {
663
+ offset *= jcp.with_dw_conv ? jcp.ow : jcp.os;
664
+ }
665
+ return offset;
666
+ }
667
+
668
+ inline size_t get_load_loop_output_bwd_d_offset(
669
+ const jcp_t &jcp, int load_loop_blk) {
670
+ size_t offset = load_loop_blk * jcp.ic_block * sizeof(float);
671
+ if (!is_out_layout_nxc(jcp)) { offset *= jcp.os; }
672
+ return offset;
673
+ }
674
+
675
+ } // namespace aarch64
676
+ } // namespace cpu
677
+ } // namespace impl
678
+ } // namespace dnnl
679
+
680
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_batch_normalization.hpp ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2017-2022 Intel Corporation
3
+ * Copyright 2020-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_BATCH_NORMALIZATION_HPP
19
+ #define CPU_AARCH64_JIT_UNI_BATCH_NORMALIZATION_HPP
20
+
21
+ #include <assert.h>
22
+
23
+ #include "common/c_types_map.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/type_helpers.hpp"
26
+ #include "common/utils.hpp"
27
+
28
+ #include "cpu/cpu_batch_normalization_pd.hpp"
29
+
30
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
31
+
32
+ namespace dnnl {
33
+ namespace impl {
34
+ namespace cpu {
35
+ namespace aarch64 {
36
+
37
+ namespace bnorm_impl {
38
+ template <cpu_isa_t isa>
39
+ struct driver_t;
40
+ }
41
+
42
+ template <cpu_isa_t isa>
43
+ struct jit_uni_batch_normalization_fwd_t : public primitive_t {
44
+ struct pd_t : public cpu_batch_normalization_fwd_pd_t {
45
+ pd_t(const batch_normalization_desc_t *adesc,
46
+ const primitive_attr_t *attr,
47
+ const batch_normalization_fwd_pd_t *hint_fwd_pd)
48
+ : cpu_batch_normalization_fwd_pd_t(adesc, attr, hint_fwd_pd) {}
49
+
50
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("bnorm_jit:", isa, ""),
51
+ jit_uni_batch_normalization_fwd_t);
52
+
53
+ status_t init(engine_t *engine);
54
+ int nthr_; // To not exceed the limit in execute used for set up.
55
+ };
56
+
57
+ jit_uni_batch_normalization_fwd_t(const pd_t *apd);
58
+ ~jit_uni_batch_normalization_fwd_t();
59
+
60
+ status_t init(engine_t *engine) override;
61
+
62
+ status_t execute(const exec_ctx_t &ctx) const override;
63
+
64
+ private:
65
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
66
+
67
+ bnorm_impl::driver_t<isa> *bnorm_driver_;
68
+ };
69
+
70
+ template <cpu_isa_t isa>
71
+ struct jit_uni_batch_normalization_bwd_t : public primitive_t {
72
+ struct pd_t : public cpu_batch_normalization_bwd_pd_t {
73
+ pd_t(const batch_normalization_desc_t *adesc,
74
+ const primitive_attr_t *attr,
75
+ const batch_normalization_fwd_pd_t *hint_fwd_pd)
76
+ : cpu_batch_normalization_bwd_pd_t(adesc, attr, hint_fwd_pd) {}
77
+
78
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("bnorm_jit:", isa, ""),
79
+ jit_uni_batch_normalization_bwd_t);
80
+
81
+ status_t init(engine_t *engine);
82
+ int nthr_; // To not exceed the limit in execute used for set up.
83
+ };
84
+
85
+ jit_uni_batch_normalization_bwd_t(const pd_t *apd);
86
+ ~jit_uni_batch_normalization_bwd_t();
87
+
88
+ status_t init(engine_t *engine) override;
89
+
90
+ status_t execute(const exec_ctx_t &ctx) const override;
91
+
92
+ private:
93
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
94
+
95
+ bnorm_impl::driver_t<isa> *bnorm_driver_;
96
+ };
97
+
98
+ } // namespace aarch64
99
+ } // namespace cpu
100
+ } // namespace impl
101
+ } // namespace dnnl
102
+
103
+ #endif
104
+
105
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_batch_normalization_s8.hpp ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021 Intel Corporation
3
+ * Copyright 2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_BATCH_NORMALIZATION_S8_HPP
19
+ #define CPU_AARCH64_JIT_UNI_BATCH_NORMALIZATION_S8_HPP
20
+
21
+ #include <assert.h>
22
+
23
+ #include "common/c_types_map.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/type_helpers.hpp"
26
+ #include "common/utils.hpp"
27
+
28
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
29
+ #include "cpu/cpu_batch_normalization_pd.hpp"
30
+
31
+ namespace dnnl {
32
+ namespace impl {
33
+ namespace cpu {
34
+ namespace aarch64 {
35
+
36
+ namespace bnorm_s8_impl {
37
+ template <cpu_isa_t isa>
38
+ struct driver_t;
39
+ }
40
+
41
+ template <cpu_isa_t isa>
42
+ struct jit_uni_batch_normalization_s8_fwd_t : public primitive_t {
43
+ struct pd_t : public cpu_batch_normalization_fwd_pd_t {
44
+ pd_t(const batch_normalization_desc_t *adesc,
45
+ const primitive_attr_t *attr,
46
+ const batch_normalization_fwd_pd_t *hint_fwd_pd)
47
+ : cpu_batch_normalization_fwd_pd_t(adesc, attr, hint_fwd_pd) {}
48
+
49
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("bnorm_s8_jit:", isa, ""),
50
+ jit_uni_batch_normalization_s8_fwd_t);
51
+
52
+ status_t init(engine_t *engine);
53
+ };
54
+
55
+ typedef int8_t data_t;
56
+
57
+ jit_uni_batch_normalization_s8_fwd_t(const pd_t *apd);
58
+ ~jit_uni_batch_normalization_s8_fwd_t();
59
+
60
+ status_t init(engine_t *engine) override;
61
+
62
+ status_t execute(const exec_ctx_t &ctx) const override;
63
+
64
+ private:
65
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
66
+
67
+ bnorm_s8_impl::driver_t<isa> *bnorm_driver_;
68
+ };
69
+
70
+ } // namespace aarch64
71
+ } // namespace cpu
72
+ } // namespace impl
73
+ } // namespace dnnl
74
+
75
+ #endif
76
+
77
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_binary.hpp ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2019-2023 Intel Corporation
3
+ * Copyright 2022-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_BINARY_HPP
19
+ #define CPU_AARCH64_JIT_UNI_BINARY_HPP
20
+
21
+ #include "common/primitive.hpp"
22
+
23
+ #include "cpu/cpu_eltwise_pd.hpp"
24
+
25
+ #include "cpu/aarch64/jit_uni_binary_kernel.hpp"
26
+
27
+ namespace dnnl {
28
+ namespace impl {
29
+ namespace cpu {
30
+ namespace aarch64 {
31
+
32
+ struct binary_kernel_t;
33
+
34
+ using op_t = binary_op_t;
35
+ using bcast_t = binary_bcast_t;
36
+
37
+ struct jit_uni_binary_t : public primitive_t {
38
+ struct pd_t : public cpu_binary_pd_t {
39
+ using cpu_binary_pd_t::cpu_binary_pd_t;
40
+
41
+ DECLARE_COMMON_PD_T("jit:uni", jit_uni_binary_t);
42
+
43
+ status_t init(engine_t *engine);
44
+
45
+ jit_binary_conf_t get_conf() const { return conf_; };
46
+
47
+ private:
48
+ op_t get_op_type(const memory_desc_wrapper &src0_d);
49
+ bool is_only_dim0_bcasted(const dims_t &bcast_dims, const int ndims);
50
+ bcast_t get_bcast_type(
51
+ const memory_desc_wrapper &src1_d, const dims_t &bcast_dims);
52
+
53
+ // alg_preserves_zero returns true if operation preserves zero in case
54
+ // of both inputs contain zero.
55
+ bool alg_preserves_zero() const;
56
+ bool check_scales_mask() const;
57
+ bool is_bcast_pattern(const dims_t &bcast_dims, const dim_t ndims,
58
+ const dim_t N_bcast, const dim_t C_bcast,
59
+ const dim_t W_bcast) const;
60
+ bool is_bcast_pattern(const dims_t &bcast_dims, const dim_t N_bcast,
61
+ const dim_t C_bcast) const;
62
+ bool is_bcast_allowed(const int ndims) const;
63
+ bool is_format_non_blocked(const memory_desc_wrapper &mdw) const;
64
+ bool is_different_layouts_allowed(const memory_desc_wrapper &src0_d,
65
+ const memory_desc_wrapper &src1_d) const;
66
+ bool is_applicable();
67
+
68
+ jit_binary_conf_t conf_;
69
+ };
70
+
71
+ jit_uni_binary_t(const pd_t *apd);
72
+ ~jit_uni_binary_t() = default;
73
+
74
+ status_t init(engine_t *engine) override;
75
+
76
+ using data_t = int8_t;
77
+
78
+ void execute_no_bcast_strategy(const data_t *src0, const data_t *src1,
79
+ data_t *dst, const float *scale0, const float *scale1,
80
+ const std::vector<const void *> &post_ops_binary_rhs_arg_vec,
81
+ const bcast_t bcast_type) const;
82
+ void execute_bcast_per_batch_strategy(const data_t *src0,
83
+ const data_t *src1, data_t *dst, const float *scale0,
84
+ const float *scale1,
85
+ const std::vector<const void *> &post_ops_binary_rhs_arg_vec) const;
86
+ void execute_bcast_per_c_strategy(const data_t *src0, const data_t *src1,
87
+ data_t *dst, const float *scale0, const float *scale1,
88
+ const std::vector<const void *> &post_ops_binary_rhs_arg_vec,
89
+ const op_t op_type, const bcast_t bcast_type,
90
+ const bool blocked_oc_tail) const;
91
+ void execute_bcast_per_w_strategy(const data_t *src0, const data_t *src1,
92
+ data_t *dst, const float *scale0, const float *scale1,
93
+ const std::vector<const void *> &post_ops_binary_rhs_arg_vec,
94
+ const op_t op_type, const bool blocked_oc_tail) const;
95
+
96
+ status_t execute(const exec_ctx_t &ctx) const override;
97
+
98
+ private:
99
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
100
+ static bool post_ops_ok(const primitive_attr_t *attr,
101
+ const memory_desc_wrapper &src0_d, const memory_desc_wrapper &dst_d,
102
+ const bool is_src1_different_layouts, const cpu_isa_t isa);
103
+
104
+ std::unique_ptr<binary_kernel_t> kernel_;
105
+ // used only in bcast_c_blocked strategy if tail exists
106
+ std::unique_ptr<binary_kernel_t> kernel_tail_;
107
+ };
108
+
109
+ } // namespace aarch64
110
+ } // namespace cpu
111
+ } // namespace impl
112
+ } // namespace dnnl
113
+
114
+ #endif
115
+
116
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_binary_kernel.hpp ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2023 Intel Corporation
3
+ * Copyright 2022-2023 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_UNI_BINARY_KERNEL_HPP
19
+ #define CPU_AARCH64_UNI_BINARY_KERNEL_HPP
20
+
21
+ #include <cassert>
22
+
23
+ #include "common/c_types_map.hpp"
24
+ #include "common/type_helpers.hpp"
25
+ #include "common/utils.hpp"
26
+
27
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
28
+ #include "cpu/aarch64/injectors/jit_uni_postops_injector.hpp"
29
+ #include "cpu/aarch64/jit_generator.hpp"
30
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
31
+ #include "cpu/aarch64/utils/jit_io_helper.hpp"
32
+
33
+ #include "cpu/cpu_binary_pd.hpp"
34
+
35
+ namespace dnnl {
36
+ namespace impl {
37
+ namespace cpu {
38
+ namespace aarch64 {
39
+
40
+ using namespace Xbyak_aarch64;
41
+
42
+ struct binary_kernel_t : public jit_generator {
43
+ using op_t = binary_op_t;
44
+ using bcast_t = binary_bcast_t;
45
+
46
+ binary_kernel_t(const size_t vlen, const binary_pd_t *pd,
47
+ const jit_binary_conf_t conf, bool tail_kernel = false);
48
+ ~binary_kernel_t() override = default;
49
+
50
+ void operator()(jit_binary_call_s *p) { jit_generator::operator()(p); }
51
+
52
+ size_t simd_w() const noexcept { return simd_w_; }
53
+ size_t vlen() const noexcept { return vlen_; }
54
+
55
+ protected:
56
+ size_t get_tail_size() const;
57
+
58
+ const size_t vlen_;
59
+ const size_t simd_w_;
60
+ constexpr static int vmm_start_idx_ = 1;
61
+ const binary_pd_t *pd_;
62
+ const jit_binary_conf_t conf_;
63
+ const bool is_tail_kernel_;
64
+ const bool is_src1_outer_dims_tail_;
65
+ const size_t tail_size_;
66
+ const size_t padding_tail_size_;
67
+ };
68
+
69
+ template <cpu_isa_t isa>
70
+ struct jit_uni_binary_kernel_t : public binary_kernel_t {
71
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_binary_kernel_t)
72
+
73
+ using Vmm = typename cpu_isa_traits<isa>::TReg;
74
+
75
+ const XReg reg_param_ = abi_param1;
76
+ const XReg reg_src0_ = x8;
77
+ const XReg reg_src1_ = x9;
78
+ const XReg reg_dst_ = x10;
79
+ const XReg reg_offt_src0_ = x11;
80
+ const XReg reg_outer_dims_range_ = x12;
81
+ const XReg reg_offt_src1_ = x1;
82
+ const XReg reg_src1_stride_range_ = x15;
83
+ const XReg reg_reverse_src1_stride_range_ = x1;
84
+ const XReg reg_reverse_spat_offt_ = x13;
85
+ const XReg reg_tmp_ = x14;
86
+ const XReg reg_tmp1_ = x6;
87
+ const XReg reg_elt_inj_table_ = x15;
88
+ const XReg reg_off_rhs_postops_ = x2;
89
+ const XReg reg_scales_src0_ = x3;
90
+ const XReg reg_scales_src1_ = x5;
91
+ const XReg reg_offt_dst_ = x2;
92
+ const PReg tail_opmask_ = p2;
93
+ const PReg cmp_mask = p3;
94
+ const PReg full_mask_ = p4;
95
+ const Vmm vmm_tail_vmask_ = Vmm(0);
96
+ const Vmm vreg_sum_scale_ = Vmm(17);
97
+ const VReg xreg_sum_scale_ = VReg(9);
98
+ const Vmm vreg_zero_ = Vmm(18);
99
+ const Vmm vreg_one_ = Vmm(19);
100
+ const Vmm vreg_saturation_ubound_ = Vmm(20);
101
+ const Vmm vreg_bcast_src1_ = Vmm(21);
102
+ const VReg xreg_bcast_src1_ = VReg(13);
103
+ const Vmm vreg_scales_src0_ = Vmm(22);
104
+ const Vmm vreg_scales_src1_ = Vmm(23);
105
+
106
+ const Vmm vmm_full_mask_ = Vmm(24);
107
+ const Vmm vmm_tmp_gather_ = Vmm(25);
108
+ const Vmm vmm_indices_ = Vmm(30);
109
+ const Vmm vmm_gathered_src_ = Vmm(31);
110
+
111
+ const size_t unroll_regs_ = 8;
112
+ const size_t offt_src0_;
113
+ const size_t offt_src1_;
114
+
115
+ static constexpr cpu_isa_t inject_isa = isa;
116
+ io::jit_io_multi_dt_helper_t<Vmm> io_;
117
+ std::unique_ptr<injector::jit_uni_postops_injector_t<inject_isa>>
118
+ postops_injector_;
119
+ const PReg elt_inj_opmask_ = p1;
120
+ const PReg elt_inj_p_tmp0_ = p2;
121
+ const PReg elt_inj_p_all_ = p3;
122
+
123
+ void init();
124
+ void init_post_ops_injector();
125
+ void apply_postops(int unroll, bool tail);
126
+ void load_kernel_params();
127
+ XReg src0_ptr(size_t offt = 0);
128
+ XReg src1_ptr(size_t offt = 0);
129
+ XReg dst_ptr(size_t offt = 0);
130
+ unsigned int cmp_predicate(alg_kind_t alg);
131
+ void perform_op(
132
+ const Vmm &v0, const Vmm &v1, const Vmm &s_src0, const Vmm &s_src1);
133
+ void prepare_isa_kernel();
134
+ void compute_bcast(bool tail);
135
+ void load_src1(const Vmm &vreg_src1, const int offt, bool tail);
136
+ void store(int unroll, bool tail);
137
+ void compute_dst_body(int unroll, bool tail);
138
+ void compute_dst(int unroll, bool tail);
139
+ void forward();
140
+ void forward_over_outer_dims();
141
+ void generate() override;
142
+
143
+ void compute_cmp_mask(const Xbyak_aarch64::PReg &cmp_dst,
144
+ const Vmm &cmp_src, const Vmm &cmp_src2, const unsigned int uimm);
145
+
146
+ void push(const XReg &reg);
147
+ void pop(const XReg &reg);
148
+
149
+ void uni_broadcast(const Vmm &dst, const Xbyak_aarch64::XReg &addr);
150
+
151
+ jit_uni_binary_kernel_t(const binary_pd_t *pd, const jit_binary_conf_t conf,
152
+ bool tail_kernel = false);
153
+ ~jit_uni_binary_kernel_t() override = default;
154
+
155
+ std::map<data_type_t, io::io_saturation_conf_t>
156
+ create_saturation_vmm_map() const;
157
+ };
158
+
159
+ } // namespace aarch64
160
+ } // namespace cpu
161
+ } // namespace impl
162
+ } // namespace dnnl
163
+
164
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_deconv_zp_pad_str_kernel.hpp ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2022 Intel Corporation
3
+ * Copyright 2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_DECONV_ZP_PAD_STR_KERNEL_HPP
19
+ #define CPU_AARCH64_JIT_UNI_DECONV_ZP_PAD_STR_KERNEL_HPP
20
+
21
+ #include "cpu/aarch64/jit_generator.hpp"
22
+
23
+ namespace dnnl {
24
+ namespace impl {
25
+ namespace cpu {
26
+ namespace aarch64 {
27
+
28
+ struct jit_conv_conf_t;
29
+
30
+ namespace zp {
31
+
32
+ struct jit_uni_deconv_zp_pad_str_call_params_t {
33
+ const int8_t *wei;
34
+ const int32_t *src_zero_point;
35
+ int32_t *dst_scratchpad;
36
+ bool last_oc_block;
37
+ };
38
+
39
+ /*
40
+ * Compute zero point source compensation applied during filter application on
41
+ * the padding as well as stride holes.
42
+ *
43
+ * zp_pad_str_compensation = conv(1, weights_s8) * zero_point_source
44
+ *
45
+ * output_format - dhwc
46
+ */
47
+ class jit_uni_deconv_zp_pad_str_kernel_base_t : public jit_generator {
48
+ public:
49
+ jit_uni_deconv_zp_pad_str_kernel_base_t(const jit_conv_conf_t &jcp);
50
+
51
+ void operator()(const jit_uni_deconv_zp_pad_str_call_params_t *params) {
52
+ jit_generator::operator()(params);
53
+ }
54
+
55
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_deconv_zp_pad_str_kernel_base_t);
56
+
57
+ private:
58
+ DNNL_DISALLOW_COPY_AND_ASSIGN(jit_uni_deconv_zp_pad_str_kernel_base_t);
59
+
60
+ void generate() override;
61
+ void load_addresses();
62
+ void compute();
63
+ virtual void compute_step(const dim_t icb_offset) = 0;
64
+ virtual void apply_zero_point() = 0;
65
+ virtual void store_result() = 0;
66
+ virtual void init() = 0;
67
+
68
+ protected:
69
+ size_t number_reserved_vmms_ = 0;
70
+ size_t reserve_vmm();
71
+
72
+ const jit_conv_conf_t &jcp_;
73
+
74
+ const Xbyak_aarch64::XReg &reg_src_zp_ = x8;
75
+ const Xbyak_aarch64::XReg &reg_wei_ = x9;
76
+ const Xbyak_aarch64::XReg &reg_dst_ = x10;
77
+ const Xbyak_aarch64::WReg &reg_last_oc_block_ = w12;
78
+ const size_t tail_size_;
79
+ };
80
+
81
+ template <cpu_isa_t isa>
82
+ class jit_uni_deconv_zp_pad_str_kernel_t
83
+ : public jit_uni_deconv_zp_pad_str_kernel_base_t {
84
+ public:
85
+ jit_uni_deconv_zp_pad_str_kernel_t(const jit_conv_conf_t &jcp);
86
+
87
+ private:
88
+ using TReg = typename cpu_isa_traits<isa>::TReg;
89
+
90
+ void init() override;
91
+ void compute_step(const dim_t icb_offset) override;
92
+ void apply_zero_point() override;
93
+ void store_result() override;
94
+
95
+ uint32_t get_next_vmm_idx();
96
+
97
+ const TReg result_acc_;
98
+ const TReg vmm_tmp_;
99
+ const TReg vmm_one_bytes_;
100
+ const TReg vmm_one_words_;
101
+
102
+ const Xbyak_aarch64::PReg &ktail_mask_ = p2;
103
+ dim_t current_vmm_;
104
+ };
105
+
106
+ bool should_calculate_deconv_zp_src_pad_str_comp(
107
+ const jit_conv_conf_t &jcp) noexcept;
108
+
109
+ template <cpu_isa_t isa>
110
+ jit_uni_deconv_zp_pad_str_kernel_base_t *create_deconv_zp_pad_str_comp_ker(
111
+ const jit_conv_conf_t &jcp);
112
+
113
+ void compute_deconv_zp_pad_str_comp_ker(const jit_conv_conf_t &jcp_,
114
+ const bool with_groups, const memory_desc_wrapper &wei_d,
115
+ const int8_t *wei, const int32_t *src_zp, int32_t *dst,
116
+ jit_uni_deconv_zp_pad_str_kernel_base_t *ker);
117
+
118
+ } // namespace zp
119
+ } // namespace aarch64
120
+ } // namespace cpu
121
+ } // namespace impl
122
+ } // namespace dnnl
123
+
124
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_dw_conv_kernel_f32.hpp ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2022 Intel Corporation
3
+ * Copyright 2021-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_DW_CONV_KERNEL_F32_HPP
19
+ #define CPU_AARCH64_JIT_UNI_DW_CONV_KERNEL_F32_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/memory_tracking.hpp"
23
+
24
+ #include "cpu/aarch64/jit_generator.hpp"
25
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
26
+
27
+ #include "cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp"
28
+
29
+ using namespace Xbyak_aarch64;
30
+
31
+ namespace dnnl {
32
+ namespace impl {
33
+ namespace cpu {
34
+ namespace aarch64 {
35
+
36
+ template <cpu_isa_t isa>
37
+ struct jit_uni_dw_conv_fwd_kernel_f32 : public jit_generator {
38
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_dw_conv_fwd_kernel_f32)
39
+
40
+ jit_uni_dw_conv_fwd_kernel_f32(jit_conv_conf_t ajcp)
41
+ : jcp(ajcp), eltwise_injector_(nullptr) {
42
+ if (jcp.with_eltwise)
43
+ eltwise_injector_ = new jit_uni_eltwise_injector_f32<sve_512>(
44
+ this, jcp.eltwise);
45
+ }
46
+
47
+ ~jit_uni_dw_conv_fwd_kernel_f32() { delete eltwise_injector_; }
48
+
49
+ jit_conv_conf_t jcp;
50
+
51
+ private:
52
+ using reg64_t = const XReg;
53
+ const int vlen = cpu_isa_traits<isa>::vlen;
54
+
55
+ // dw convolution
56
+ reg64_t reg_input = x1;
57
+ reg64_t aux_reg_input = x2;
58
+ reg64_t reg_kernel = x3;
59
+ reg64_t aux_reg_kernel = x5;
60
+ reg64_t reg_ch_blocks = x6;
61
+ reg64_t reg_output = x7;
62
+ reg64_t reg_bias = x8;
63
+ reg64_t reg_kh = x9;
64
+ reg64_t iter_kh = x10;
65
+ reg64_t reg_oi = x11;
66
+ reg64_t aux_reg_ch_blocks = x12;
67
+ // fused convolution
68
+ reg64_t reg_input_buffer_ptr = x13;
69
+ reg64_t aux_reg_input_buffer_ptr = x14;
70
+ reg64_t reg_iw_offset = reg_input;
71
+
72
+ /* Temprary regs */
73
+ reg64_t reg_tmp_imm = x15;
74
+ reg64_t reg_kernel_stack = x16;
75
+ reg64_t reg_input_stack = x17;
76
+ reg64_t reg_output_stack = x27;
77
+ reg64_t reg_bias_stack = x19;
78
+ reg64_t reg_tmp_addr = x20;
79
+
80
+ inline void load_src(int ur_ch_blocks, int ur_w);
81
+ inline void compute_loop(int ur_w, int ur_ch_blocks, int pad_l, int pad_r);
82
+ inline void ow_loop(int ur_ch_blocks);
83
+ inline void apply_filter_unrolled(
84
+ int ur_ch_blocks, int ur_w, int pad_l, int pad_r);
85
+ inline void apply_activation(int ur_ch_blocks, int ur_w);
86
+ inline void store_dst(int ur_ch_blocks, int ur_w);
87
+
88
+ inline ZReg get_ker_reg(int idx) {
89
+ assert(idx <= 31);
90
+ return ZReg(idx + 0);
91
+ }
92
+ inline ZRegS get_ker_reg_s(int idx) {
93
+ assert(idx <= 31);
94
+ return ZRegS(idx + 0);
95
+ }
96
+ inline ZReg get_src_reg(int idx) {
97
+ assert((idx + 1) <= 31);
98
+ return ZReg(idx + 1);
99
+ }
100
+ inline ZRegS get_src_reg_s(int idx) {
101
+ assert((idx + 1) <= 31);
102
+ return ZRegS(idx + 1);
103
+ }
104
+
105
+ inline ZReg get_acc_reg(int idx) {
106
+ assert((idx + 4) <= 31);
107
+ return ZReg(idx + 4);
108
+ }
109
+ inline ZRegS get_acc_reg_s(int idx) {
110
+ assert((idx + 4) <= 31);
111
+ return ZRegS(idx + 4);
112
+ }
113
+
114
+ int get_ow_start(int ki, int pad_l) {
115
+ return nstl::max(0,
116
+ utils::div_up(pad_l - ki * (jcp.dilate_w + 1), jcp.stride_w));
117
+ }
118
+
119
+ int get_ow_end(int ur_w, int ki, int pad_r) {
120
+ return ur_w
121
+ - nstl::max(0,
122
+ utils::div_up(
123
+ pad_r - (jcp.kw - 1 - ki) * (jcp.dilate_w + 1),
124
+ jcp.stride_w));
125
+ }
126
+
127
+ inline bool is_src_layout_nxc() {
128
+ return utils::one_of(jcp.src_tag, format_tag::ndhwc, format_tag::nhwc,
129
+ format_tag::nwc);
130
+ }
131
+ inline bool is_dst_layout_nxc() {
132
+ return utils::one_of(jcp.dst_tag, format_tag::ndhwc, format_tag::nhwc,
133
+ format_tag::nwc);
134
+ }
135
+
136
+ jit_uni_eltwise_injector_f32<sve_512> *eltwise_injector_;
137
+ void generate() override;
138
+ };
139
+
140
+ template <cpu_isa_t isa>
141
+ struct jit_uni_dw_conv_bwd_data_kernel_f32 : public jit_generator {
142
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_dw_conv_bwd_data_kernel_f32)
143
+
144
+ jit_uni_dw_conv_bwd_data_kernel_f32(jit_conv_conf_t ajcp) : jcp(ajcp) {}
145
+ jit_conv_conf_t jcp;
146
+
147
+ private:
148
+ using reg64_t = const XReg;
149
+
150
+ inline ZReg get_ker_reg(int idx) { return ZReg(idx + 0); }
151
+ inline ZReg get_src_reg(int idx) { return ZReg(idx + 1); }
152
+ inline ZReg get_acc_reg(int idx) { return ZReg(idx + 4); }
153
+ inline ZRegS get_ker_reg_s(int idx) { return ZRegS(idx + 0); }
154
+ inline ZRegS get_src_reg_s(int idx) { return ZRegS(idx + 1); }
155
+ inline ZRegS get_acc_reg_s(int idx) { return ZRegS(idx + 4); }
156
+
157
+ reg64_t reg_ddst = x1;
158
+ reg64_t aux_reg_ddst = x2;
159
+ reg64_t aux1_reg_ddst = x3;
160
+ reg64_t reg_kernel = x5;
161
+ reg64_t aux_reg_kernel = x6;
162
+ reg64_t aux1_reg_kernel = x7;
163
+ reg64_t reg_dsrc = x8;
164
+
165
+ reg64_t reg_ur_str_w = x9;
166
+ reg64_t reg_ch_blocks = x10;
167
+
168
+ reg64_t iter_kh = x11;
169
+ reg64_t iter_kw = x12;
170
+ reg64_t reg_kh = x13;
171
+ reg64_t reg_kw = x14;
172
+
173
+ /* Temprary regs */
174
+ reg64_t reg_tmp_imm = x15;
175
+ reg64_t reg_tmp_addr = x16;
176
+
177
+ inline void loop_body(int ur_ch_blocks);
178
+ inline void load_ddst(int ur_ch_blocks, int ur_str_w);
179
+ inline void apply_filter(int ur_ch_blocks, int ur_str_w);
180
+ inline void store_dsrc(int ur_ch_blocks, int ur_str_w);
181
+
182
+ void generate() override;
183
+ };
184
+
185
+ template <cpu_isa_t isa>
186
+ struct jit_uni_dw_conv_bwd_weights_kernel_f32 : public jit_generator {
187
+
188
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_dw_conv_bwd_weights_kernel_f32)
189
+
190
+ jit_uni_dw_conv_bwd_weights_kernel_f32(jit_conv_conf_t ajcp) : jcp(ajcp) {}
191
+
192
+ jit_conv_conf_t jcp;
193
+
194
+ private:
195
+ using reg64_t = const XReg;
196
+ int simd_w = cpu_isa_traits<isa>::vlen / sizeof(float);
197
+
198
+ inline ZReg get_bias_reg(int idx = 0) { return ZReg(idx); }
199
+ inline ZReg get_output_reg(int idx) { return ZReg(idx + 1); }
200
+ inline ZReg get_input_reg(int idx) { return ZReg(idx + 5); }
201
+ inline ZReg get_acc_reg(int idx) { return ZReg(idx + 2); }
202
+ inline ZReg get_aux_reg() { return ZReg(0); }
203
+ inline ZRegS get_bias_reg_s(int idx = 0) { return ZRegS(idx); }
204
+ inline ZRegS get_output_reg_s(int idx) { return ZRegS(idx + 1); }
205
+ inline ZRegS get_input_reg_s(int idx) { return ZRegS(idx + 5); }
206
+ inline ZRegS get_acc_reg_s(int idx) { return ZRegS(idx + 2); }
207
+ inline ZRegS get_aux_reg_s() { return ZRegS(0); }
208
+
209
+ reg64_t reg_tmp_input = x1;
210
+ reg64_t reg_tmp_output = x2;
211
+ reg64_t reg_tmp_filter = x3;
212
+ reg64_t reg_kh_offset = x5;
213
+
214
+ /* parameter passed by driver into kernel */
215
+ reg64_t reg_exec_flags = x14;
216
+
217
+ reg64_t reg_oh_worksize = x6;
218
+ reg64_t reg_oh = x5;
219
+
220
+ reg64_t reg_iter_ow_blk = x7;
221
+
222
+ reg64_t reg_kh = x8;
223
+ reg64_t reg_kh_count = x9;
224
+
225
+ /* Base addresses for convolution parameters. */
226
+ reg64_t reg_input_baddr = x10;
227
+ reg64_t reg_output_baddr = x11;
228
+ reg64_t reg_filter_baddr = x12;
229
+ reg64_t reg_bias_baddr = x13;
230
+
231
+ /* Temporary regs */
232
+ reg64_t reg_tmp_imm = x15;
233
+ reg64_t reg_tmp_addr = x16;
234
+
235
+ /* Micro-kernel JIT'ing, fusing 'kw' and 'ow_block' loops into unrolled FMAs
236
+ */
237
+ inline void compute_ow_step_unroll(
238
+ int unroll_w, int l_pad, int pad_offset, int ow_block);
239
+
240
+ /* JIT'ing the outer loops for the micro-kernel -> {kh, oh_block} */
241
+ inline void compute_h_step(
242
+ int unroll_w, int l_pad, int pad_offset, int ow_block);
243
+ inline void compute_h_loop(
244
+ int unroll_w, int l_pad, int pad_offset, int ow_block);
245
+
246
+ /* Write 'width' micro-kernel JITs; depending on the padding and convolution
247
+ * size, write a micro-kernel for the left ow-block, middle ow-block(s), and
248
+ * right ow-block.*/
249
+ inline void compute_ow_block_unroll();
250
+
251
+ inline void compute_zero_filter();
252
+ inline void load_filter();
253
+ inline void zero_filter();
254
+ inline void load_bias();
255
+ inline void zero_bias();
256
+ inline void compute_bias_step_unroll(const int unroll_w);
257
+ inline void compute_bias_loop(const int block_size);
258
+ inline void store_filter();
259
+ inline void store_bias();
260
+
261
+ void generate() override;
262
+ };
263
+ } // namespace aarch64
264
+ } // namespace cpu
265
+ } // namespace impl
266
+ } // namespace dnnl
267
+
268
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_dw_conv_kernel_utils.hpp ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021-2022 Intel Corporation
3
+ * Copyright 2021-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_DW_CONV_KERNEL_UTILS_HPP
19
+ #define CPU_AARCH64_JIT_UNI_DW_CONV_KERNEL_UTILS_HPP
20
+
21
+ #include "common/nstl.hpp"
22
+ #include "common/type_helpers.hpp"
23
+ #include "common/utils.hpp"
24
+
25
+ #include "common/c_types_map.hpp"
26
+ #include "common/memory_tracking.hpp"
27
+
28
+ #include "cpu/aarch64/jit_generator.hpp"
29
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
30
+ #include "cpu/aarch64/jit_uni_dw_conv_kernel_f32.hpp"
31
+
32
+ #include "cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp"
33
+
34
+ namespace dnnl {
35
+ namespace impl {
36
+ namespace cpu {
37
+ namespace aarch64 {
38
+
39
+ template <cpu_isa_t isa, data_type_t kernel_dt>
40
+ struct jit_uni_dw_conv_fwd_kernel {
41
+
42
+ jit_uni_dw_conv_fwd_kernel(jit_conv_conf_t ajcp) : ker_(nullptr) {
43
+ ker_ = new jit_uni_dw_conv_fwd_kernel_f32<isa>(ajcp);
44
+ }
45
+ status_t create_kernel() { return ker_->create_kernel(); }
46
+ ~jit_uni_dw_conv_fwd_kernel() { delete ker_; }
47
+
48
+ static bool post_ops_ok(jit_conv_conf_t &jcp, const primitive_attr_t &attr);
49
+
50
+ static status_t init_conf(jit_conv_conf_t &jcp,
51
+ const convolution_desc_t &cd, memory_desc_t &src_md,
52
+ memory_desc_t &weights_md, memory_desc_t &bias_md,
53
+ memory_desc_t &dst_md, const primitive_attr_t &attr);
54
+
55
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
56
+ const jit_conv_conf_t &jcp);
57
+
58
+ jit_generator *ker() const { return ker_; }
59
+ void operator()(const jit_conv_call_s *p) const { (*ker_)(p); }
60
+
61
+ private:
62
+ jit_uni_dw_conv_fwd_kernel_f32<isa> *ker_;
63
+ };
64
+
65
+ template <cpu_isa_t isa, data_type_t kernel_dt>
66
+ bool jit_uni_dw_conv_fwd_kernel<isa, kernel_dt>::post_ops_ok(
67
+ jit_conv_conf_t &jcp, const primitive_attr_t &attr) {
68
+ const auto &p = attr.post_ops_;
69
+
70
+ auto is_eltwise = [&](int idx) {
71
+ return p.entry_[idx].is_eltwise()
72
+ && eltwise_injector::is_supported(
73
+ isa, p.entry_[idx].eltwise.alg);
74
+ };
75
+ auto is_sum = [&](int idx) { return p.entry_[idx].is_sum(); };
76
+
77
+ switch (p.len()) {
78
+ case 0: return true; // no post_ops
79
+ case 1: return is_eltwise(0) || is_sum(0); // sum OR eltwise
80
+ case 2: return is_sum(0) && is_eltwise(1); // sum -> eltwise
81
+ default: return false;
82
+ }
83
+
84
+ return false;
85
+ }
86
+
87
+ template <cpu_isa_t isa, data_type_t kernel_dt>
88
+ status_t jit_uni_dw_conv_fwd_kernel<isa, kernel_dt>::init_conf(
89
+ jit_conv_conf_t &jcp, const convolution_desc_t &cd,
90
+ memory_desc_t &src_md, memory_desc_t &weights_md,
91
+ memory_desc_t &bias_md, memory_desc_t &dst_md,
92
+ const primitive_attr_t &attr) {
93
+
94
+ using namespace dnnl::impl::format_tag;
95
+ using namespace dnnl::impl::utils;
96
+
97
+ const memory_desc_wrapper src_d(&src_md);
98
+ const memory_desc_wrapper weights_d(&weights_md);
99
+ const memory_desc_wrapper dst_d(&dst_md);
100
+ const memory_desc_wrapper bias_d(&bias_md);
101
+
102
+ const int ndims = src_d.ndims();
103
+ // Currently this kernel only supports 2D convolutions.
104
+ if (ndims != 4) return status::unimplemented;
105
+
106
+ const auto blocked_tag = isa == sve_512 ? nChw16c : nChw8c;
107
+ const auto wei_tag = isa == sve_512 ? Goihw16g : Goihw8g;
108
+ const auto nxc_tag = nhwc;
109
+ jcp.with_bias = cd.bias_desc.format_kind != format_kind::undef;
110
+ if ((blocked_tag != nChw16c) || (wei_tag != Goihw16g))
111
+ return status::unimplemented;
112
+
113
+ if (src_d.format_kind() == format_kind::any) {
114
+ CHECK(memory_desc_init_by_tag(src_md, blocked_tag));
115
+ jcp.src_tag = blocked_tag;
116
+ } else {
117
+ jcp.src_tag = src_d.matches_one_of_tag(blocked_tag, nxc_tag);
118
+ }
119
+
120
+ if (weights_d.format_kind() == format_kind::any) {
121
+ CHECK(memory_desc_init_by_tag(weights_md, wei_tag));
122
+ jcp.wei_tag = wei_tag;
123
+ } else {
124
+ jcp.wei_tag = weights_d.matches_one_of_tag(wei_tag);
125
+ }
126
+
127
+ if (dst_d.format_kind() == format_kind::any) {
128
+ CHECK(memory_desc_init_by_tag(dst_md, blocked_tag));
129
+ jcp.dst_tag = blocked_tag;
130
+ } else {
131
+ jcp.dst_tag = dst_d.matches_one_of_tag(blocked_tag, nxc_tag);
132
+ }
133
+
134
+ if (jcp.with_bias) {
135
+ if (bias_d.format_kind() == format_kind::any)
136
+ CHECK(memory_desc_init_by_tag(bias_md, format_tag::x));
137
+ }
138
+
139
+ if (jcp.dst_tag != jcp.src_tag) return status::unimplemented;
140
+ const auto data_tag = jcp.src_tag;
141
+ const bool is_data_layout_nxc = data_tag == nxc_tag;
142
+
143
+ jcp.dst_dt = cd.dst_desc.data_type;
144
+ jcp.isa = isa;
145
+
146
+ if (!mayiuse(isa)) return status::unimplemented;
147
+
148
+ const int simd_w = isa == sve_512 ? 16 : 8;
149
+ if (simd_w != 16) return status::unimplemented;
150
+
151
+ jcp.prop_kind = cd.prop_kind;
152
+
153
+ const bool with_groups = weights_d.ndims() == src_d.ndims() + 1;
154
+ if (!with_groups) return status::unimplemented;
155
+
156
+ jcp.ngroups = weights_d.dims()[0];
157
+ jcp.mb = src_d.dims()[0];
158
+
159
+ jcp.oc = dst_d.dims()[1];
160
+ jcp.oc_without_padding = jcp.oc;
161
+ jcp.ic = src_d.dims()[1];
162
+
163
+ jcp.ih = src_d.dims()[2];
164
+ jcp.iw = src_d.dims()[3];
165
+ jcp.oh = dst_d.dims()[2];
166
+ jcp.ow = dst_d.dims()[3];
167
+
168
+ jcp.kh = weights_d.dims()[3];
169
+ jcp.kw = weights_d.dims()[4];
170
+
171
+ jcp.t_pad = cd.padding[0][0];
172
+ jcp.l_pad = cd.padding[0][1];
173
+ jcp.b_pad = cd.padding[1][0];
174
+ jcp.r_pad = cd.padding[1][1];
175
+
176
+ jcp.stride_h = cd.strides[0];
177
+ jcp.stride_w = cd.strides[1];
178
+
179
+ jcp.dilate_h = cd.dilates[0];
180
+ jcp.dilate_w = cd.dilates[1];
181
+
182
+ int ext_kw = calculate_extended_filter_size(jcp.kw, jcp.dilate_w);
183
+ int ext_kh = calculate_extended_filter_size(jcp.kh, jcp.dilate_h);
184
+ jcp.r_pad = calculate_end_padding(
185
+ jcp.l_pad, jcp.ow, jcp.iw, jcp.stride_w, ext_kw);
186
+ jcp.b_pad = calculate_end_padding(
187
+ jcp.t_pad, jcp.oh, jcp.ih, jcp.stride_h, ext_kh);
188
+ bool kernel_outside_src = false || ext_kw <= jcp.l_pad
189
+ || ext_kw <= jcp.r_pad || ext_kh <= jcp.t_pad
190
+ || ext_kh <= jcp.b_pad;
191
+ if (kernel_outside_src) return status::unimplemented;
192
+
193
+ jcp.typesize_out = types::data_type_size(dst_d.data_type());
194
+ jcp.typesize_in = types::data_type_size(src_d.data_type());
195
+
196
+ jcp.loop_order = loop_ngcw;
197
+
198
+ jcp.ur_w = isa == sve_512 ? 6 : isa == sve_256 ? 4 : 3;
199
+ jcp.ur_w = nstl::min(jcp.ur_w, jcp.ow);
200
+
201
+ jcp.ch_block = simd_w;
202
+ jcp.nb_ch = div_up(jcp.oc, jcp.ch_block);
203
+ jcp.nb_ch_blocking = isa == sve_512 ? 4 : isa == sve_256 ? 3 : 2;
204
+ if (jcp.nb_ch < jcp.nb_ch_blocking) jcp.nb_ch_blocking = jcp.nb_ch;
205
+
206
+ if (is_data_layout_nxc) {
207
+ jcp.loop_order = loop_nhwcg;
208
+ bool cache_aliasing
209
+ = (jcp.ngroups * jcp.iw * jcp.typesize_in) % 1024 == 0;
210
+ if (cache_aliasing) {
211
+ // currently only tuned for mobilenet-v1 shapes
212
+ const int limit = jcp.ow > 7 ? 7 : 4;
213
+ jcp.ur_w = nstl::min(jcp.ur_w, limit);
214
+ }
215
+ } else {
216
+ const size_t max_ch_off
217
+ = static_cast<size_t>(jcp.nb_ch_blocking - 1) * jcp.ch_block;
218
+ constexpr size_t max_ex_off = 0;
219
+
220
+ // check that input offsets fit into s32
221
+ const size_t max_ic_off = max_ch_off * jcp.ih * jcp.iw;
222
+ const size_t max_iw_idx
223
+ = static_cast<size_t>(jcp.ur_w - 1) * jcp.stride_w
224
+ + (ext_kw - 1);
225
+ const size_t max_iw_off = max_iw_idx * jcp.ch_block;
226
+ const size_t max_input_offset
227
+ = (max_ic_off + max_iw_off + max_ex_off) * jcp.typesize_in;
228
+ if (max_input_offset > INT_MAX) return status::unimplemented;
229
+
230
+ // check that output offsets fit into s32
231
+ const size_t max_oc_off = max_ch_off * jcp.oh * jcp.ow;
232
+ const size_t max_ow_off
233
+ = static_cast<size_t>(jcp.ur_w - 1) * jcp.ch_block;
234
+ const size_t max_output_offset
235
+ = (max_oc_off + max_ow_off + max_ex_off) * jcp.typesize_out;
236
+ if (max_output_offset > INT_MAX) return status::unimplemented;
237
+ }
238
+
239
+ jcp.ur_w_tail = jcp.ow % jcp.ur_w;
240
+
241
+ int r_pad_no_tail = nstl::max(0,
242
+ calculate_end_padding(jcp.l_pad, jcp.ow - jcp.ur_w_tail, jcp.iw,
243
+ jcp.stride_w, ext_kw));
244
+ if (jcp.l_pad > jcp.ur_w || r_pad_no_tail > jcp.ur_w)
245
+ return status::unimplemented;
246
+
247
+ if (!post_ops_ok(jcp, attr)) return status::unimplemented;
248
+
249
+ const auto &p = attr.post_ops_;
250
+ jcp.with_sum = p.find(primitive_kind::sum) != -1;
251
+ const int eltwise_ind = p.find(primitive_kind::eltwise);
252
+ jcp.with_eltwise = eltwise_ind != -1;
253
+
254
+ if (jcp.with_eltwise) {
255
+ jcp.eltwise = p.entry_[eltwise_ind].eltwise;
256
+ if (jcp.eltwise.alg == alg_kind::eltwise_pow)
257
+ return status::unimplemented;
258
+ if (dst_d.data_type() == data_type::s32) return status::unimplemented;
259
+ }
260
+ bool ok_to_pad_channels = true && jcp.oc == jcp.ngroups
261
+ && jcp.ic == jcp.ngroups && isa == sve_512;
262
+ if (ok_to_pad_channels) {
263
+ jcp.oc = rnd_up(jcp.oc, simd_w);
264
+ jcp.ic = rnd_up(jcp.oc, simd_w);
265
+ jcp.ngroups = rnd_up(jcp.ngroups, simd_w);
266
+ }
267
+
268
+ bool args_ok = true && jcp.oc == jcp.ngroups && jcp.ic == jcp.ngroups
269
+ && jcp.ngroups % simd_w == 0 && jcp.wei_tag == wei_tag
270
+ && data_tag != format_tag::undef && jcp.ic <= src_d.padded_dims()[1]
271
+ && jcp.oc <= dst_d.padded_dims()[1]
272
+ && jcp.ngroups <= weights_d.padded_dims()[0];
273
+ if (!args_ok) return status::unimplemented;
274
+
275
+ jcp.bia_dt = jcp.with_bias ? cd.bias_desc.data_type : data_type::undef;
276
+
277
+ return status::success;
278
+ }
279
+
280
+ template <cpu_isa_t isa, data_type_t kernel_dt>
281
+ void jit_uni_dw_conv_fwd_kernel<isa, kernel_dt>::init_scratchpad(
282
+ memory_tracking::registrar_t &scratchpad, const jit_conv_conf_t &jcp) {
283
+ using namespace dnnl::impl::memory_tracking::names;
284
+ if (jcp.with_bias && jcp.oc_without_padding != jcp.oc)
285
+ scratchpad.book<float>(key_conv_padded_bias, jcp.oc);
286
+ }
287
+
288
+ template struct jit_uni_dw_conv_fwd_kernel<sve_512, data_type::f32>;
289
+
290
+ template <cpu_isa_t isa, data_type_t kernel_dt>
291
+ struct jit_uni_dw_conv_bwd_data_kernel {
292
+
293
+ jit_uni_dw_conv_bwd_data_kernel(jit_conv_conf_t ajcp) : ker_(nullptr) {
294
+ ker_ = new jit_uni_dw_conv_bwd_data_kernel_f32<isa>(ajcp);
295
+ }
296
+
297
+ status_t create_kernel() { return ker_->create_kernel(); }
298
+ ~jit_uni_dw_conv_bwd_data_kernel() { delete ker_; }
299
+
300
+ static status_t init_conf(jit_conv_conf_t &jcp,
301
+ const convolution_desc_t &cd, const memory_desc_wrapper &diff_src_d,
302
+ const memory_desc_wrapper &weights_d,
303
+ const memory_desc_wrapper &diff_dst_d);
304
+
305
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
306
+ const jit_conv_conf_t &jcp);
307
+
308
+ void operator()(const jit_conv_call_s *p) const { (*ker_)(p); }
309
+
310
+ private:
311
+ jit_uni_dw_conv_bwd_data_kernel_f32<isa> *ker_;
312
+
313
+ DNNL_DISALLOW_COPY_AND_ASSIGN(jit_uni_dw_conv_bwd_data_kernel);
314
+ };
315
+
316
+ template <cpu_isa_t isa, data_type_t kernel_dt>
317
+ status_t jit_uni_dw_conv_bwd_data_kernel<isa, kernel_dt>::init_conf(
318
+ jit_conv_conf_t &jcp, const convolution_desc_t &cd,
319
+ const memory_desc_wrapper &diff_src_d,
320
+ const memory_desc_wrapper &weights_d,
321
+ const memory_desc_wrapper &diff_dst_d) {
322
+ using namespace dnnl::impl::format_tag;
323
+ using namespace dnnl::impl::utils;
324
+
325
+ jcp.dsrc_dt = cd.diff_src_desc.data_type;
326
+ jcp.isa = isa;
327
+
328
+ if (!mayiuse(isa)) return status::unimplemented;
329
+
330
+ const int simd_w = isa == sve_512 ? 16 : 8;
331
+
332
+ const bool with_groups = weights_d.ndims() == diff_src_d.ndims() + 1;
333
+ if (!with_groups) return status::unimplemented;
334
+
335
+ jcp.ngroups = weights_d.dims()[0];
336
+ jcp.mb = diff_src_d.dims()[0];
337
+
338
+ jcp.oc = diff_dst_d.dims()[1];
339
+ jcp.oc_without_padding = jcp.oc;
340
+ jcp.ic = diff_src_d.dims()[1];
341
+
342
+ jcp.ih = diff_src_d.dims()[2];
343
+ jcp.iw = diff_src_d.dims()[3];
344
+ jcp.oh = diff_dst_d.dims()[2];
345
+ jcp.ow = diff_dst_d.dims()[3];
346
+
347
+ jcp.kh = weights_d.dims()[3];
348
+ jcp.kw = weights_d.dims()[4];
349
+
350
+ jcp.t_pad = cd.padding[0][0];
351
+ jcp.l_pad = cd.padding[0][1];
352
+ jcp.b_pad = cd.padding[1][0];
353
+ jcp.r_pad = cd.padding[1][1];
354
+
355
+ jcp.stride_h = cd.strides[0];
356
+ jcp.stride_w = cd.strides[1];
357
+
358
+ jcp.dilate_h = cd.dilates[0];
359
+ jcp.dilate_w = cd.dilates[1];
360
+ int ext_kw = calculate_extended_filter_size(jcp.kw, jcp.dilate_w);
361
+ int ext_kh = calculate_extended_filter_size(jcp.kh, jcp.dilate_h);
362
+ jcp.r_pad = calculate_end_padding(
363
+ jcp.l_pad, jcp.ow, jcp.iw, jcp.stride_w, ext_kw);
364
+ jcp.b_pad = calculate_end_padding(
365
+ jcp.t_pad, jcp.oh, jcp.ih, jcp.stride_h, ext_kh);
366
+ bool kernel_outside_src = false || ext_kw <= jcp.l_pad
367
+ || ext_kw <= jcp.r_pad || ext_kh <= jcp.t_pad
368
+ || ext_kh <= jcp.b_pad;
369
+ if (kernel_outside_src) { return status::unimplemented; }
370
+
371
+ jcp.ihp = jcp.ih + jcp.t_pad + jcp.b_pad;
372
+ jcp.iwp = jcp.iw + jcp.l_pad + jcp.r_pad;
373
+
374
+ bool ok_to_pad_channels = true && jcp.oc == jcp.ngroups
375
+ && jcp.ic == jcp.ngroups && isa == sve_512;
376
+ if (ok_to_pad_channels) {
377
+ jcp.oc = rnd_up(jcp.oc, simd_w);
378
+ jcp.ic = rnd_up(jcp.oc, simd_w);
379
+ jcp.ngroups = rnd_up(jcp.ngroups, simd_w);
380
+ }
381
+
382
+ auto dat_tag = isa == sve_512 ? nChw16c : nChw8c;
383
+ auto wei_tag = isa == sve_512 ? Goihw16g : Goihw8g;
384
+
385
+ jcp.src_tag = diff_src_d.matches_one_of_tag(dat_tag);
386
+ jcp.wei_tag = weights_d.matches_one_of_tag(wei_tag);
387
+ jcp.dst_tag = diff_dst_d.matches_one_of_tag(dat_tag);
388
+
389
+ bool args_ok = true && jcp.oc == jcp.ngroups && jcp.ic == jcp.ngroups
390
+ && jcp.ngroups % simd_w == 0 && jcp.src_tag == dat_tag
391
+ && jcp.wei_tag == wei_tag && jcp.dst_tag == dat_tag
392
+ && jcp.dilate_h == 0 && jcp.dilate_w == 0
393
+ && jcp.oh == (jcp.ihp - jcp.kh) / jcp.stride_h + 1
394
+ && jcp.ow == (jcp.iwp - jcp.kw) / jcp.stride_w + 1
395
+ && jcp.ic <= diff_src_d.padded_dims()[1]
396
+ && jcp.oc <= diff_dst_d.padded_dims()[1]
397
+ && jcp.ngroups <= weights_d.padded_dims()[0];
398
+ if (!args_ok) return status::unimplemented;
399
+
400
+ jcp.typesize_out = types::data_type_size(diff_src_d.data_type());
401
+ jcp.typesize_in = types::data_type_size(diff_dst_d.data_type());
402
+
403
+ jcp.ur_w = isa == sve_512 ? 6 : isa == sve_256 ? 4 : 3;
404
+
405
+ jcp.ch_block = simd_w;
406
+ jcp.nb_ch = jcp.ic / jcp.ch_block;
407
+ jcp.nb_ch_blocking = isa == sve_512 ? 4 : isa == sve_256 ? 3 : 2;
408
+ if (jcp.nb_ch < jcp.nb_ch_blocking) jcp.nb_ch_blocking = jcp.nb_ch;
409
+
410
+ return status::success;
411
+ }
412
+
413
+ template <cpu_isa_t isa, data_type_t kernel_dt>
414
+ void jit_uni_dw_conv_bwd_data_kernel<isa, kernel_dt>::init_scratchpad(
415
+ memory_tracking::registrar_t &scratchpad, const jit_conv_conf_t &jcp) {
416
+ UNUSED(scratchpad);
417
+ UNUSED(jcp);
418
+ }
419
+
420
+ template struct jit_uni_dw_conv_bwd_data_kernel<sve_512, data_type::f32>;
421
+
422
+ template <cpu_isa_t isa, data_type_t kernel_dt>
423
+ struct jit_uni_dw_conv_bwd_weights_kernel {
424
+
425
+ jit_uni_dw_conv_bwd_weights_kernel(jit_conv_conf_t ajcp) : ker_(nullptr) {
426
+ ker_ = new jit_uni_dw_conv_bwd_weights_kernel_f32<isa>(ajcp);
427
+ }
428
+
429
+ status_t create_kernel() { return ker_->create_kernel(); }
430
+ ~jit_uni_dw_conv_bwd_weights_kernel() { delete ker_; }
431
+
432
+ static status_t init_conf(jit_conv_conf_t &jcp,
433
+ const convolution_desc_t &cd, const memory_desc_wrapper &src_d,
434
+ const memory_desc_wrapper &diff_weights_d,
435
+ const memory_desc_wrapper &diff_dst_d, int nthreads);
436
+
437
+ static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
438
+ const jit_conv_conf_t &jcp);
439
+
440
+ static void balance(jit_conv_conf_t &jcp, int nthreads);
441
+
442
+ void operator()(const jit_dw_conv_call_s *p) const { (*ker_)(p); }
443
+
444
+ private:
445
+ jit_uni_dw_conv_bwd_weights_kernel_f32<isa> *ker_;
446
+ };
447
+
448
+ template <cpu_isa_t isa, data_type_t kernel_dt>
449
+ status_t jit_uni_dw_conv_bwd_weights_kernel<isa, kernel_dt>::init_conf(
450
+ jit_conv_conf_t &jcp, const convolution_desc_t &cd,
451
+ const memory_desc_wrapper &src_d,
452
+ const memory_desc_wrapper &diff_weights_d,
453
+ const memory_desc_wrapper &diff_dst_d, int nthreads) {
454
+ using namespace dnnl::impl::format_tag;
455
+ using namespace dnnl::impl::utils;
456
+
457
+ jcp.dwei_dt = cd.diff_weights_desc.data_type;
458
+ jcp.isa = isa;
459
+
460
+ if (!mayiuse(isa)) return status::unimplemented;
461
+
462
+ jcp.ngroups = diff_weights_d.dims()[0];
463
+ jcp.oc = diff_dst_d.dims()[1] / jcp.ngroups;
464
+ jcp.ic = src_d.dims()[1] / jcp.ngroups;
465
+
466
+ const bool with_groups = diff_weights_d.ndims() == src_d.ndims() + 1;
467
+
468
+ jcp.is_depthwise = true && with_groups && everyone_is(1, jcp.oc, jcp.ic);
469
+
470
+ if (!jcp.is_depthwise) return status::unimplemented;
471
+
472
+ jcp.ch_block = isa == sve_512 ? 16 : 8;
473
+ jcp.simd_w = jcp.ch_block;
474
+
475
+ jcp.mb = src_d.dims()[0];
476
+
477
+ jcp.ih = src_d.dims()[2];
478
+ jcp.iw = src_d.dims()[3];
479
+ jcp.oh = diff_dst_d.dims()[2];
480
+ jcp.ow = diff_dst_d.dims()[3];
481
+
482
+ jcp.kh = diff_weights_d.dims()[3];
483
+ jcp.kw = diff_weights_d.dims()[4];
484
+
485
+ jcp.stride_h = cd.strides[0];
486
+ jcp.stride_w = cd.strides[1];
487
+
488
+ jcp.t_pad = cd.padding[0][0];
489
+ jcp.b_pad = cd.padding[1][0];
490
+
491
+ jcp.l_pad = cd.padding[0][1];
492
+ jcp.r_pad = cd.padding[1][1];
493
+
494
+ jcp.dilate_h = cd.dilates[0];
495
+ jcp.dilate_w = cd.dilates[1];
496
+
497
+ jcp.ihp = jcp.ih + jcp.t_pad + jcp.b_pad;
498
+ jcp.iwp = jcp.iw + jcp.l_pad + jcp.r_pad;
499
+
500
+ jcp.with_bias = cd.diff_bias_desc.format_kind != format_kind::undef;
501
+
502
+ auto dat_tag = isa == sve_512 ? nChw16c : nChw8c;
503
+ auto wei_tag = isa == sve_512 ? Goihw16g : Goihw8g;
504
+
505
+ jcp.src_tag = src_d.matches_one_of_tag(dat_tag);
506
+ jcp.wei_tag = diff_weights_d.matches_one_of_tag(wei_tag);
507
+ jcp.dst_tag = diff_dst_d.matches_one_of_tag(dat_tag);
508
+
509
+ bool args_ok = true && jcp.src_tag == dat_tag && jcp.wei_tag == wei_tag
510
+ && jcp.dst_tag == dat_tag && jcp.ngroups % jcp.ch_block == 0
511
+ && jcp.dilate_h == 0 && jcp.dilate_w == 0 && jcp.kw <= 3
512
+ && jcp.stride_w <= jcp.kw // no gaps in kernel
513
+ && jcp.oh == (jcp.ihp - jcp.kh) / jcp.stride_h + 1
514
+ && jcp.ow == (jcp.iwp - jcp.kw) / jcp.stride_w + 1;
515
+ if (!args_ok) return status::unimplemented;
516
+
517
+ jcp.nb_ch = jcp.ngroups / jcp.ch_block;
518
+
519
+ /* kernel applicability check wrt boundaries
520
+ * the conditions are quite general across the kernels we have,
521
+ * but ideally the check should belong to a specific kernel... */
522
+ const int max_hpad = (jcp.kh - 1 + 1) / 2;
523
+ const int max_wpad = (jcp.kw - 1 + 1) / 2;
524
+ const int min_ih = jcp.kh + nstl::modulo(-jcp.t_pad, jcp.stride_h);
525
+ const bool boundaries_ok = true && jcp.t_pad <= max_hpad
526
+ && jcp.b_pad <= max_hpad && jcp.l_pad <= max_wpad
527
+ && jcp.r_pad <= max_wpad
528
+ // input must fully accommodate the filter
529
+ && jcp.ih >= min_ih
530
+ // non-unit padding must be a multiple of the stride
531
+ && IMPLICATION(jcp.t_pad > 1, jcp.t_pad % jcp.stride_h == 0)
532
+ && IMPLICATION(jcp.b_pad > 1, jcp.b_pad % jcp.stride_h == 0);
533
+ if (!boundaries_ok) return status::unimplemented;
534
+
535
+ /* BF16: accumulation of output happens in f32, down-conversion to bf16
536
+ * happens during the reduction phase. */
537
+ jcp.typesize_out = sizeof(float);
538
+ jcp.typesize_in = types::data_type_size(src_d.data_type());
539
+ jcp.bia_dt = jcp.with_bias ? cd.diff_bias_desc.data_type : data_type::undef;
540
+
541
+ balance(jcp, nthreads);
542
+
543
+ return status::success;
544
+ }
545
+
546
+ template <cpu_isa_t isa, data_type_t kernel_dt>
547
+ void jit_uni_dw_conv_bwd_weights_kernel<isa, kernel_dt>::init_scratchpad(
548
+ memory_tracking::registrar_t &scratchpad, const jit_conv_conf_t &jcp) {
549
+ using namespace dnnl::impl::memory_tracking::names;
550
+ /* Notes: if splitting thread work on 'mb', then a reduction has to take
551
+ * place. Hence, book a per-thread, local weights-buffer for the
552
+ * reduction */
553
+ if (jcp.nthr_mb > 1) {
554
+ const size_t mb = jcp.dwei_dt == data_type::bf16 ? jcp.nthr_mb
555
+ : jcp.nthr_mb - 1;
556
+ const size_t wei_size = jcp.ngroups * jcp.kh * jcp.kw;
557
+ scratchpad.book<float>(key_conv_wei_reduction, wei_size * mb);
558
+
559
+ if (jcp.with_bias)
560
+ scratchpad.book<float>(
561
+ key_conv_bia_reduction, jcp.ngroups * (jcp.nthr_mb - 1));
562
+ } else if (jcp.nthr_mb == 1 && jcp.dwei_dt == data_type::bf16) {
563
+ const size_t wei_size = jcp.ngroups * jcp.kh * jcp.kw;
564
+ scratchpad.book<float>(key_conv_wei_reduction, wei_size);
565
+ }
566
+ if (jcp.bia_dt == data_type::bf16)
567
+ scratchpad.book<float>(key_conv_bias_bf16_convert_wsp, jcp.ngroups);
568
+ }
569
+
570
+ template <cpu_isa_t isa, data_type_t kernel_dt>
571
+ void jit_uni_dw_conv_bwd_weights_kernel<isa, kernel_dt>::balance(
572
+ jit_conv_conf_t &jcp, int nthreads) {
573
+ jcp.nthr = nthreads;
574
+ jcp.nthr_g = jcp.nthr_mb = 1;
575
+
576
+ /* Basic-Heuristics for parallel strategy:
577
+ * 1) Tries to parallel on the number of Groups (g) where tasks are
578
+ * independent. Otherwise,
579
+ * 2) Tries to split the work across g and MiniBatch (mb).
580
+ * Parallelizing on mb requires computing a reduction for weights.
581
+ *
582
+ * NOTE: because of 'task partitioning' scheme, there will be unbalanced
583
+ * per-thread load when the number of threads is high (e.g. > 16).
584
+ */
585
+ jcp.nthr_g = nstl::min(jcp.nb_ch, jcp.nthr);
586
+ jcp.nthr_mb = nstl::min(nstl::max(1, jcp.nthr / jcp.nthr_g), jcp.mb);
587
+
588
+ jcp.nthr = jcp.nthr_g * jcp.nthr_mb;
589
+ }
590
+
591
+ template struct jit_uni_dw_conv_bwd_weights_kernel<sve_512, data_type::f32>;
592
+ } // namespace aarch64
593
+ } // namespace cpu
594
+ } // namespace impl
595
+ } // namespace dnnl
596
+ #endif /* CPU_X64_JIT_UNI_DW_CONV_KERNEL_UTILS_HPP */
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_dw_convolution.hpp ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021 Intel Corporation
3
+ * Copyright 2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_DW_CONVOLUTION_HPP
19
+ #define CPU_AARCH64_JIT_UNI_DW_CONVOLUTION_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/memory_tracking.hpp"
23
+ #include "common/primitive.hpp"
24
+
25
+ #include "cpu/aarch64/cpu_barrier.hpp"
26
+ #include "cpu/aarch64/cpu_reducer.hpp"
27
+ #include "cpu/cpu_convolution_pd.hpp"
28
+
29
+ #include "cpu/aarch64/jit_uni_dw_conv_kernel_utils.hpp"
30
+
31
+ namespace dnnl {
32
+ namespace impl {
33
+ namespace cpu {
34
+ namespace aarch64 {
35
+
36
+ template <cpu_isa_t isa, data_type_t src_type, data_type_t dst_type = src_type>
37
+ struct jit_uni_dw_convolution_fwd_t : public primitive_t {
38
+ struct pd_t : public cpu_convolution_fwd_pd_t {
39
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
40
+ const typename pd_t::base_class *hint_fwd_pd)
41
+ : cpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd), jcp_() {}
42
+
43
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_dw:", jcp_.isa, ""),
44
+ jit_uni_dw_convolution_fwd_t);
45
+
46
+ status_t init(engine_t *engine) {
47
+ bool ok = true && is_fwd()
48
+ && set_default_alg_kind(alg_kind::convolution_direct)
49
+ && expect_data_types(src_type, src_type, data_type::undef,
50
+ dst_type, data_type::f32)
51
+ && IMPLICATION(this->with_bias(),
52
+ utils::one_of(this->desc()->bias_desc.data_type,
53
+ data_type::f32, data_type::bf16))
54
+ && attr()->has_default_values(
55
+ primitive_attr_t::skip_mask_t::post_ops, dst_type)
56
+ && !has_zero_dim_memory();
57
+ if (!ok) return status::unimplemented;
58
+
59
+ status_t status
60
+ = jit_uni_dw_conv_fwd_kernel<isa, src_type>::init_conf(jcp_,
61
+ *desc(), src_md_, weights_md_, bias_md_, dst_md_,
62
+ *attr());
63
+ if (status != status::success) return status;
64
+
65
+ auto scratchpad = scratchpad_registry().registrar();
66
+ jit_uni_dw_conv_fwd_kernel<isa, src_type>::init_scratchpad(
67
+ scratchpad, jcp_);
68
+
69
+ return status::success;
70
+ }
71
+
72
+ jit_conv_conf_t jcp_;
73
+ };
74
+
75
+ jit_uni_dw_convolution_fwd_t(const pd_t *apd) : primitive_t(apd) {}
76
+
77
+ typedef typename prec_traits<data_type::f32>::type f32_data_t;
78
+ typedef typename prec_traits<data_type::bf16>::type bf16_data_t;
79
+ typedef typename prec_traits<src_type>::type data_t;
80
+ typedef typename prec_traits<dst_type>::type dst_data_t;
81
+
82
+ status_t init(engine_t *engine) override {
83
+ CHECK(safe_ptr_assign(kernel_,
84
+ new jit_uni_dw_conv_fwd_kernel<isa, src_type>(pd()->jcp_)));
85
+ return kernel_->create_kernel();
86
+ }
87
+
88
+ status_t execute(const exec_ctx_t &ctx) const override {
89
+ execute_forward(ctx);
90
+ return status::success;
91
+ }
92
+
93
+ private:
94
+ void execute_forward(const exec_ctx_t &ctx) const;
95
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
96
+
97
+ std::unique_ptr<jit_uni_dw_conv_fwd_kernel<isa, src_type>> kernel_;
98
+ };
99
+
100
+ using jit_sve_512_dw_convolution_fwd_t
101
+ = jit_uni_dw_convolution_fwd_t<sve_512, data_type::f32>;
102
+
103
+ template <cpu_isa_t isa, data_type_t diff_dst_type,
104
+ data_type_t diff_src_type = diff_dst_type>
105
+ struct jit_uni_dw_convolution_bwd_data_t : public primitive_t {
106
+ struct pd_t : public cpu_convolution_bwd_data_pd_t {
107
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
108
+ const convolution_fwd_pd_t *hint_fwd_pd)
109
+ : cpu_convolution_bwd_data_pd_t(adesc, attr, hint_fwd_pd), jcp_() {}
110
+
111
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_dw:", jcp_.isa, ""),
112
+ jit_uni_dw_convolution_bwd_data_t);
113
+
114
+ status_t init(engine_t *engine) {
115
+ bool ok = true && desc()->prop_kind == prop_kind::backward_data
116
+ && set_default_alg_kind(alg_kind::convolution_direct)
117
+ && expect_data_types(diff_src_type, diff_dst_type,
118
+ data_type::undef, diff_dst_type, data_type::f32)
119
+ && attr()->has_default_values() && !has_zero_dim_memory()
120
+ && set_default_formats();
121
+
122
+ if (!ok) return status::unimplemented;
123
+
124
+ status_t status = jit_uni_dw_conv_bwd_data_kernel<isa,
125
+ diff_dst_type>::init_conf(jcp_, *desc(), *diff_src_md(),
126
+ *weights_md(), *diff_dst_md());
127
+ if (status != status::success) return status;
128
+
129
+ auto scratchpad = scratchpad_registry().registrar();
130
+ jit_uni_dw_conv_bwd_data_kernel<isa,
131
+ diff_dst_type>::init_scratchpad(scratchpad, jcp_);
132
+
133
+ return status::success;
134
+ }
135
+
136
+ jit_conv_conf_t jcp_;
137
+
138
+ protected:
139
+ bool set_default_formats() {
140
+ using namespace format_tag;
141
+
142
+ auto dat_tag = nChw16c;
143
+ auto wei_tag = Goihw16g;
144
+
145
+ return set_default_formats_common(dat_tag, wei_tag, dat_tag);
146
+ }
147
+ };
148
+
149
+ jit_uni_dw_convolution_bwd_data_t(const pd_t *apd) : primitive_t(apd) {}
150
+
151
+ typedef typename prec_traits<diff_src_type>::type diff_src_data_t;
152
+ typedef typename prec_traits<diff_dst_type>::type diff_dst_data_t;
153
+ typedef typename prec_traits<diff_dst_type>::type wei_data_t;
154
+
155
+ status_t init(engine_t *engine) override {
156
+ CHECK(safe_ptr_assign(kernel_,
157
+ new jit_uni_dw_conv_bwd_data_kernel<isa, diff_dst_type>(
158
+ pd()->jcp_)));
159
+ return kernel_->create_kernel();
160
+ }
161
+
162
+ status_t execute(const exec_ctx_t &ctx) const override {
163
+ execute_backward_data(ctx);
164
+ return status::success;
165
+ }
166
+
167
+ private:
168
+ void execute_backward_data(const exec_ctx_t &ctx) const;
169
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
170
+
171
+ std::unique_ptr<jit_uni_dw_conv_bwd_data_kernel<isa, diff_dst_type>>
172
+ kernel_;
173
+ };
174
+
175
+ using jit_sve_512_dw_convolution_bwd_data_t
176
+ = jit_uni_dw_convolution_bwd_data_t<sve_512, data_type::f32>;
177
+
178
+ template <cpu_isa_t isa, data_type_t src_type,
179
+ data_type_t diff_weights_type = src_type>
180
+ struct jit_uni_dw_convolution_bwd_weights_t : public primitive_t {
181
+ struct pd_t : public cpu_convolution_bwd_weights_pd_t {
182
+ pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr,
183
+ const convolution_fwd_pd_t *hint_fwd_pd)
184
+ : cpu_convolution_bwd_weights_pd_t(adesc, attr, hint_fwd_pd)
185
+ , jcp_() {}
186
+ using jit_uni_dw_convolution_bwd_weights
187
+ = jit_uni_dw_convolution_bwd_weights_t<isa, src_type,
188
+ diff_weights_type>;
189
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_dw:", jcp_.isa, ""),
190
+ jit_uni_dw_convolution_bwd_weights);
191
+
192
+ status_t init(engine_t *engine) {
193
+ bool ok = true && desc()->prop_kind == prop_kind::backward_weights
194
+ && set_default_alg_kind(alg_kind::convolution_direct)
195
+ && expect_data_types(src_type, diff_weights_type,
196
+ data_type::undef, src_type, data_type::f32)
197
+ && IMPLICATION(this->with_bias(),
198
+ utils::one_of(
199
+ this->desc()->diff_bias_desc.data_type,
200
+ data_type::f32, data_type::bf16))
201
+ && attr()->has_default_values() && !has_zero_dim_memory()
202
+ && set_default_formats();
203
+ if (!ok) return status::unimplemented;
204
+
205
+ const int max_threads
206
+ = dnnl_in_parallel() ? 1 : dnnl_get_max_threads();
207
+
208
+ status_t status = jit_uni_dw_conv_bwd_weights_kernel<isa,
209
+ src_type>::init_conf(jcp_, *desc(), *src_md(),
210
+ *diff_weights_md(), *diff_dst_md(), max_threads);
211
+ if (status != status::success) return status;
212
+
213
+ auto scratchpad = scratchpad_registry().registrar();
214
+ jit_uni_dw_conv_bwd_weights_kernel<isa, src_type>::init_scratchpad(
215
+ scratchpad, jcp_);
216
+
217
+ return status::success;
218
+ }
219
+
220
+ jit_conv_conf_t jcp_;
221
+
222
+ protected:
223
+ bool set_default_formats() {
224
+ using namespace format_tag;
225
+
226
+ auto dat_tag = isa == sve_512 ? nChw16c : nChw8c;
227
+ auto wei_tag = isa == sve_512 ? Goihw16g : Goihw8g;
228
+
229
+ return set_default_formats_common(dat_tag, wei_tag, dat_tag);
230
+ }
231
+ };
232
+
233
+ jit_uni_dw_convolution_bwd_weights_t(const pd_t *apd);
234
+
235
+ typedef typename prec_traits<data_type::bf16>::type bf16_data_t;
236
+ typedef typename prec_traits<data_type::f32>::type f32_data_t;
237
+ typedef typename prec_traits<src_type>::type src_data_t;
238
+ typedef typename prec_traits<src_type>::type diff_dst_data_t;
239
+ typedef typename prec_traits<diff_weights_type>::type diff_weights_data_t;
240
+
241
+ status_t init(engine_t *engine) override {
242
+ CHECK(safe_ptr_assign(kernel_,
243
+ new jit_uni_dw_conv_bwd_weights_kernel<isa, src_type>(
244
+ pd()->jcp_)));
245
+ CHECK(kernel_->create_kernel());
246
+
247
+ if (pd()->jcp_.nthr_mb > 1) {
248
+ CHECK(safe_ptr_assign(
249
+ acc_ker_, new cpu_accumulator_1d_t<data_type::f32>()));
250
+ CHECK(acc_ker_->create_kernel());
251
+ }
252
+ return status::success;
253
+ }
254
+
255
+ status_t execute(const exec_ctx_t &ctx) const override {
256
+ execute_backward_weights(ctx);
257
+ execute_reduction(ctx);
258
+ return status::success;
259
+ }
260
+
261
+ private:
262
+ void execute_backward_weights(const exec_ctx_t &ctx) const;
263
+ void execute_reduction(const exec_ctx_t &ctx) const;
264
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
265
+
266
+ std::unique_ptr<cpu_accumulator_1d_t<data_type::f32>> acc_ker_;
267
+ std::unique_ptr<jit_uni_dw_conv_bwd_weights_kernel<isa, src_type>> kernel_;
268
+ };
269
+
270
+ using jit_sve_512_dw_convolution_bwd_weights_t
271
+ = jit_uni_dw_convolution_bwd_weights_t<sve_512, data_type::f32>;
272
+ } // namespace aarch64
273
+ } // namespace cpu
274
+ } // namespace impl
275
+ } // namespace dnnl
276
+
277
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_eltwise.hpp ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2017-2021 Intel Corporation
3
+ * Copyright 2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_ELTWISE_HPP
19
+ #define CPU_AARCH64_JIT_UNI_ELTWISE_HPP
20
+
21
+ #include <assert.h>
22
+
23
+ #include "common/c_types_map.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/type_helpers.hpp"
26
+ #include "common/utils.hpp"
27
+
28
+ #include "cpu/cpu_eltwise_pd.hpp"
29
+
30
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
31
+
32
+ namespace dnnl {
33
+ namespace impl {
34
+ namespace cpu {
35
+ namespace aarch64 {
36
+
37
+ struct jit_uni_eltwise_kernel;
38
+
39
+ template <cpu_isa_t isa, impl::data_type_t d_type>
40
+ struct jit_uni_eltwise_fwd_t : public primitive_t {
41
+ struct pd_t : public cpu_eltwise_fwd_pd_t {
42
+ using cpu_eltwise_fwd_pd_t::cpu_eltwise_fwd_pd_t;
43
+
44
+ DECLARE_COMMON_PD_T(
45
+ JIT_IMPL_NAME_HELPER("jit:", isa, ""), jit_uni_eltwise_fwd_t);
46
+
47
+ status_t init(engine_t *engine);
48
+ };
49
+
50
+ jit_uni_eltwise_fwd_t(const pd_t *apd);
51
+ virtual ~jit_uni_eltwise_fwd_t();
52
+
53
+ typedef typename prec_traits<d_type>::type data_t;
54
+
55
+ status_t init(engine_t *engine) override;
56
+
57
+ status_t execute(const exec_ctx_t &ctx) const override;
58
+
59
+ private:
60
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
61
+ std::unique_ptr<jit_uni_eltwise_kernel> kernel_;
62
+ };
63
+
64
+ template <cpu_isa_t isa, impl::data_type_t d_type>
65
+ struct jit_uni_eltwise_bwd_t : public primitive_t {
66
+ struct pd_t : public cpu_eltwise_bwd_pd_t {
67
+ using cpu_eltwise_bwd_pd_t::cpu_eltwise_bwd_pd_t;
68
+
69
+ DECLARE_COMMON_PD_T(
70
+ JIT_IMPL_NAME_HELPER("jit:", isa, ""), jit_uni_eltwise_bwd_t);
71
+
72
+ status_t init(engine_t *engine);
73
+ };
74
+
75
+ jit_uni_eltwise_bwd_t(const pd_t *apd);
76
+ virtual ~jit_uni_eltwise_bwd_t();
77
+
78
+ typedef typename prec_traits<d_type>::type data_t;
79
+
80
+ status_t init(engine_t *engine) override;
81
+
82
+ status_t execute(const exec_ctx_t &ctx) const override;
83
+
84
+ private:
85
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
86
+ std::unique_ptr<jit_uni_eltwise_kernel> kernel_;
87
+ };
88
+
89
+ } // namespace aarch64
90
+ } // namespace cpu
91
+ } // namespace impl
92
+ } // namespace dnnl
93
+
94
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_eltwise_int.hpp ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021 Intel Corporation
3
+ * Copyright 2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_ELTWISE_INT_HPP
19
+ #define CPU_AARCH64_JIT_UNI_ELTWISE_INT_HPP
20
+
21
+ #include <assert.h>
22
+
23
+ #include "common/c_types_map.hpp"
24
+ #include "common/primitive.hpp"
25
+ #include "common/type_helpers.hpp"
26
+ #include "common/utils.hpp"
27
+
28
+ #include "cpu/cpu_eltwise_pd.hpp"
29
+
30
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
31
+
32
+ namespace dnnl {
33
+ namespace impl {
34
+ namespace cpu {
35
+ namespace aarch64 {
36
+
37
+ struct jit_uni_eltwise_int_kernel;
38
+
39
+ template <cpu_isa_t isa, impl::data_type_t d_type>
40
+ struct jit_uni_eltwise_int_fwd_t : public primitive_t {
41
+ struct pd_t : public cpu_eltwise_fwd_pd_t {
42
+ using cpu_eltwise_fwd_pd_t::cpu_eltwise_fwd_pd_t;
43
+
44
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_int8:", isa, ""),
45
+ jit_uni_eltwise_int_fwd_t);
46
+
47
+ status_t init(engine_t *engine);
48
+ };
49
+
50
+ jit_uni_eltwise_int_fwd_t(const pd_t *apd);
51
+ ~jit_uni_eltwise_int_fwd_t();
52
+
53
+ typedef typename prec_traits<d_type>::type data_t;
54
+
55
+ status_t init(engine_t *engine) override;
56
+
57
+ status_t execute(const exec_ctx_t &ctx) const override {
58
+ return execute_forward(ctx);
59
+ }
60
+
61
+ private:
62
+ status_t execute_forward(const exec_ctx_t &ctx) const;
63
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
64
+ jit_uni_eltwise_int_kernel *kernel_ = nullptr;
65
+ };
66
+
67
+ } // namespace aarch64
68
+ } // namespace cpu
69
+ } // namespace impl
70
+ } // namespace dnnl
71
+
72
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_i8i8_pooling.hpp ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ * Copyright 2020-2021 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_I8I8_POOLING_HPP
19
+ #define CPU_AARCH64_JIT_UNI_I8I8_POOLING_HPP
20
+
21
+ #include "common/c_types_map.hpp"
22
+ #include "common/primitive.hpp"
23
+ #include "common/type_helpers.hpp"
24
+
25
+ #include "cpu/cpu_pooling_pd.hpp"
26
+
27
+ #include "cpu/aarch64/cpu_isa_traits.hpp"
28
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
29
+
30
+ namespace dnnl {
31
+ namespace impl {
32
+ namespace cpu {
33
+ namespace aarch64 {
34
+
35
+ template <cpu_isa_t isa>
36
+ struct jit_uni_i8i8_pooling_fwd_ker_t;
37
+
38
+ template <cpu_isa_t isa>
39
+ struct jit_uni_i8i8_pooling_fwd_t : public primitive_t {
40
+ struct pd_t : public cpu_pooling_fwd_pd_t {
41
+ using cpu_pooling_fwd_pd_t::cpu_pooling_fwd_pd_t;
42
+
43
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_int:", isa, ""),
44
+ jit_uni_i8i8_pooling_fwd_t);
45
+
46
+ status_t init(engine_t *engine) {
47
+ bool ok = true && mayiuse(isa) && utils::one_of(ndims(), 3, 4, 5)
48
+ && set_default_params() == status::success
49
+ && desc()->prop_kind == prop_kind::forward_inference
50
+ && utils::one_of(desc()->alg_kind, alg_kind::pooling_max,
51
+ alg_kind::pooling_avg_include_padding,
52
+ alg_kind::pooling_avg_exclude_padding)
53
+ && utils::one_of(src_md()->data_type, data_type::s32,
54
+ data_type::s8, data_type::u8)
55
+ && src_md()->data_type == dst_md()->data_type
56
+ && attr()->has_default_values(
57
+ primitive_attr_t::skip_mask_t::post_ops)
58
+ && memory_desc_matches_one_of_tag(*src_md(),
59
+ format_tag::nwc, format_tag::nhwc,
60
+ format_tag::ndhwc)
61
+ != format_tag::undef
62
+ && memory_desc_matches_one_of_tag(*dst_md(),
63
+ format_tag::nwc, format_tag::nhwc,
64
+ format_tag::ndhwc)
65
+ != format_tag::undef
66
+ && !is_dilated();
67
+ if (!ok) return status::unimplemented;
68
+
69
+ return jit_conf();
70
+ }
71
+
72
+ jit_pool_conf_t jpp_;
73
+
74
+ protected:
75
+ status_t jit_conf();
76
+ };
77
+
78
+ jit_uni_i8i8_pooling_fwd_t(const pd_t *apd);
79
+ ~jit_uni_i8i8_pooling_fwd_t();
80
+
81
+ status_t init(engine_t *engine) override;
82
+
83
+ status_t execute(const exec_ctx_t &ctx) const override {
84
+ return execute_forward(ctx);
85
+ }
86
+
87
+ private:
88
+ status_t execute_forward(const exec_ctx_t &ctx) const;
89
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
90
+
91
+ std::unique_ptr<jit_uni_i8i8_pooling_fwd_ker_t<isa>> ker_;
92
+ };
93
+
94
+ } // namespace aarch64
95
+ } // namespace cpu
96
+ } // namespace impl
97
+ } // namespace dnnl
98
+
99
+ #endif
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_pool_kernel.hpp ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2017-2022 Intel Corporation
3
+ * Copyright 2018 YANDEX LLC
4
+ * Copyright 2020-2022 FUJITSU LIMITED
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *******************************************************************************/
18
+
19
+ #ifndef CPU_AARCH64_JIT_UNI_POOL_KERNEL_HPP
20
+ #define CPU_AARCH64_JIT_UNI_POOL_KERNEL_HPP
21
+
22
+ #include <cfloat>
23
+ #include <functional>
24
+ #include <memory>
25
+
26
+ #include "common/memory_tracking.hpp"
27
+
28
+ #include "cpu/aarch64/injectors/jit_uni_postops_injector.hpp"
29
+ #include "cpu/aarch64/jit_generator.hpp"
30
+ #include "cpu/aarch64/jit_primitive_conf.hpp"
31
+
32
+ using namespace Xbyak_aarch64;
33
+
34
+ namespace dnnl {
35
+ namespace impl {
36
+ namespace cpu {
37
+ namespace aarch64 {
38
+
39
+ template <cpu_isa_t isa>
40
+ struct jit_uni_pool_kernel : public jit_generator {
41
+
42
+ jit_uni_pool_kernel(
43
+ const jit_pool_conf_t &ajpp, const memory_desc_t *dst_md);
44
+ jit_pool_conf_t jpp;
45
+ ~jit_uni_pool_kernel();
46
+
47
+ DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_uni_pool_kernel)
48
+
49
+ static status_t init_conf(jit_pool_conf_t &jbp,
50
+ memory_tracking::registrar_t &scratchpad, primitive_attr_t &attr,
51
+ const pooling_pd_t *ppd);
52
+
53
+ private:
54
+ using TReg = typename cpu_isa_traits<isa>::TReg;
55
+ using TRegS = typename cpu_isa_traits<isa>::TRegS;
56
+
57
+ int vmm_idx_upper_bound() const noexcept { return 31; }
58
+
59
+ int reg_idx(int idx) const noexcept { return vmm_idx_upper_bound() - idx; }
60
+
61
+ VReg xreg(int idx) const noexcept { return VReg(reg_idx(idx)); }
62
+ ZReg yreg(int idx) const noexcept { return ZReg(reg_idx(idx)); }
63
+ ZReg zreg(int idx) const noexcept { return ZReg(reg_idx(idx)); }
64
+ TReg vreg(int idx) const noexcept { return TReg(reg_idx(idx)); }
65
+
66
+ VReg vmm_mask = VReg(0);
67
+ ZReg ymm_tmp_1 = ZReg(0);
68
+ TRegS vmm_tmp_1 = TRegS(0);
69
+
70
+ TReg vmm_c_tail_mask = TReg(2);
71
+
72
+ VReg xmm_ker_area_h = VReg(2);
73
+ VReg xmm_one = VReg(2);
74
+ VReg xmm_tmp = VReg(3);
75
+
76
+ TRegS vmm_ker_area_h = TRegS(2);
77
+ TRegS vmm_one = TRegS(2);
78
+ TReg vmm_tmp = TReg(3);
79
+ ZReg ymm_tmp = ZReg(3);
80
+
81
+ TRegS vmm_k_offset = TRegS(1);
82
+
83
+ inline uint32_t reg_idx() {
84
+ if (!jpp.is_backward) {
85
+ return (jpp.is_training) ? 4 : 1;
86
+ } else
87
+ return 4;
88
+ }
89
+
90
+ ZReg z_tmp0 = z4;
91
+
92
+ PReg k_c_tail_mask_s = p4;
93
+ PReg k_c_tail_mask_s_not = p2;
94
+ PReg k_c_tail_mask_b = p7;
95
+ PReg k_mask_cvt = p5;
96
+ PReg k_store_mask = p6;
97
+
98
+ /* Caution: Chose predicate registers not used by x64's implementation. */
99
+ PReg p_all_zero = p1;
100
+ PReg p_tmp0 = p3;
101
+
102
+ using xreg_t = const XReg;
103
+ xreg_t reg_param = x0;
104
+ xreg_t reg_input = x4;
105
+ xreg_t aux_reg_input = x5;
106
+ xreg_t reg_index = x10;
107
+ xreg_t reg_output = x12;
108
+ xreg_t reg_kd_pad_shift = x13;
109
+
110
+ xreg_t kj = x14;
111
+ xreg_t oi_iter = x15;
112
+ xreg_t reg_kh = x7;
113
+ const WReg reg_k_shift = w3;
114
+ xreg_t tmp_gpr = x6;
115
+ xreg_t reg_ker_area_h = x2;
116
+ xreg_t reg_nbc = x1;
117
+
118
+ xreg_t reg_zero_ptr = x5;
119
+ xreg_t reg_zero_id = x13;
120
+ xreg_t reg_zero_ih = x14;
121
+ xreg_t aux_reg_zero_ih = x15;
122
+ xreg_t ki = x12;
123
+ xreg_t aux_reg_input_d = x4;
124
+
125
+ int prev_kw;
126
+
127
+ void prepare_tail_mask();
128
+ void push_vmm_val(const int idx);
129
+ void pop_vmm_val(const int idx);
130
+ void load(const int idx, const xreg_t &reg_ptr, const int offset,
131
+ const bool is_c_tail_proccessing);
132
+ void store(const int idx, const xreg_t &reg_ptr, const int offset,
133
+ const bool is_c_tail_proccessing);
134
+
135
+ void maybe_recalculate_divisor(int jj, int ur_w, int pad_l, int pad_r,
136
+ bool with_c_tail_proccessing);
137
+ void avg_step(int ur_w, int ur_bc, int pad_l, int pad_r,
138
+ bool with_c_tail_proccessing);
139
+ void max_step_fwd(int ur_w, int ur_bc, int pad_l, int pad_r,
140
+ bool with_c_tail_proccessing);
141
+ void max_step_bwd(int ur_w, int ur_bc, int pad_l, int pad_r,
142
+ bool with_c_tail_proccessing);
143
+
144
+ void zero_diff_src(int ur_bc, bool with_c_tail_proccessing);
145
+
146
+ void step(int ur_w, int ur_bc, int pad_l, int pad_r,
147
+ bool with_c_tail_proccessing) {
148
+ if (jpp.alg == alg_kind::pooling_max) {
149
+ if (jpp.is_backward)
150
+ max_step_bwd(
151
+ ur_w, ur_bc, pad_l, pad_r, with_c_tail_proccessing);
152
+ else
153
+ max_step_fwd(
154
+ ur_w, ur_bc, pad_l, pad_r, with_c_tail_proccessing);
155
+ } else
156
+ avg_step(ur_w, ur_bc, pad_l, pad_r, with_c_tail_proccessing);
157
+ }
158
+
159
+ void generate() override;
160
+
161
+ void apply_postops(int ur_bc, int ur_w, int c_block,
162
+ const std::function<bool(int)> &is_tail_predicate);
163
+
164
+ static bool post_ops_ok(jit_pool_conf_t &jpp, const primitive_attr_t &attr,
165
+ const memory_desc_wrapper &dst_d);
166
+
167
+ std::unique_ptr<injector::jit_uni_postops_injector_t<isa>>
168
+ postops_injector_;
169
+ };
170
+
171
+ } // namespace aarch64
172
+ } // namespace cpu
173
+ } // namespace impl
174
+ } // namespace dnnl
175
+
176
+ #endif
177
+
178
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_pooling.hpp ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2017-2022 Intel Corporation
3
+ * Copyright 2020-2022 FUJITSU LIMITED
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef CPU_AARCH64_JIT_UNI_POOLING_HPP
19
+ #define CPU_AARCH64_JIT_UNI_POOLING_HPP
20
+
21
+ #include <assert.h>
22
+ #include <memory>
23
+
24
+ #include "common/c_types_map.hpp"
25
+ #include "common/dnnl_thread.hpp"
26
+ #include "common/primitive.hpp"
27
+ #include "common/type_helpers.hpp"
28
+ #include "common/utils.hpp"
29
+
30
+ #include "cpu/cpu_pooling_pd.hpp"
31
+
32
+ #include "cpu/aarch64/jit_uni_pool_kernel.hpp"
33
+ #include "cpu/aarch64/jit_uni_reorder.hpp"
34
+
35
+ namespace dnnl {
36
+ namespace impl {
37
+ namespace cpu {
38
+ namespace aarch64 {
39
+
40
+ namespace jit_uni_pooling_utils {
41
+ struct trans_wrapper_t;
42
+ struct trans_context_t;
43
+ } // namespace jit_uni_pooling_utils
44
+
45
+ template <cpu_isa_t isa, impl::data_type_t d_type>
46
+ struct jit_uni_pooling_fwd_t : public primitive_t {
47
+ struct pd_t : public cpu_pooling_fwd_pd_t {
48
+ using cpu_pooling_fwd_pd_t::cpu_pooling_fwd_pd_t;
49
+
50
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:", jpp_.isa, ""),
51
+ jit_uni_pooling_fwd_t);
52
+
53
+ status_t init(engine_t *engine) {
54
+ using namespace utils;
55
+
56
+ const bool ok = is_fwd() && !has_zero_dim_memory()
57
+ && everyone_is(
58
+ d_type, src_md()->data_type, dst_md()->data_type)
59
+ && attr()->has_default_values(
60
+ primitive_attr_t::skip_mask_t::post_ops, d_type)
61
+ && !is_dilated() && set_default_params() == status::success;
62
+ if (!ok) return status::unimplemented;
63
+
64
+ const bool is_training
65
+ = desc_.prop_kind == prop_kind::forward_training;
66
+ if (desc()->alg_kind == alg_kind::pooling_max && is_training)
67
+ init_default_ws();
68
+
69
+ auto scratchpad = scratchpad_registry().registrar();
70
+
71
+ CHECK(jit_uni_pool_kernel<isa>::init_conf(
72
+ jpp_, scratchpad, attr_, this));
73
+
74
+ return status::success;
75
+ }
76
+
77
+ jit_pool_conf_t jpp_;
78
+ };
79
+
80
+ explicit jit_uni_pooling_fwd_t(const pd_t *apd);
81
+ jit_uni_pooling_fwd_t(jit_uni_pooling_fwd_t &&) = default;
82
+ jit_uni_pooling_fwd_t &operator=(jit_uni_pooling_fwd_t &&) = default;
83
+ ~jit_uni_pooling_fwd_t();
84
+
85
+ using data_t = typename prec_traits<d_type>::type;
86
+
87
+ status_t init(engine_t *engine) override;
88
+
89
+ status_t execute(const exec_ctx_t &ctx) const override {
90
+ auto src = CTX_IN_MEM(const data_t *, DNNL_ARG_SRC);
91
+ auto dst = CTX_OUT_MEM(data_t *, DNNL_ARG_DST);
92
+ auto ws = CTX_OUT_MEM(char *, DNNL_ARG_WORKSPACE);
93
+
94
+ if (pd()->ndims() == 5)
95
+ execute_forward_3d(src, dst, ws, ctx);
96
+ else
97
+ execute_forward(src, dst, ws, ctx);
98
+
99
+ return status::success;
100
+ }
101
+
102
+ private:
103
+ void execute_forward(const data_t *src, data_t *dst, char *indices,
104
+ const exec_ctx_t &ctx) const;
105
+ void execute_forward_3d(const data_t *src, data_t *dst, char *indices,
106
+ const exec_ctx_t &ctx) const;
107
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
108
+ status_t init_ncsp_trans_ctx();
109
+
110
+ std::unique_ptr<jit_uni_pool_kernel<isa>> kernel_;
111
+ std::unique_ptr<jit_uni_pooling_utils::trans_context_t> trans_ctx_;
112
+ static constexpr data_type_t wsp_dt_ = data_type::f32;
113
+ };
114
+
115
+ template <cpu_isa_t isa, impl::data_type_t d_type>
116
+ struct jit_uni_pooling_bwd_t : public primitive_t {
117
+ struct pd_t : public cpu_pooling_bwd_pd_t {
118
+ using cpu_pooling_bwd_pd_t::cpu_pooling_bwd_pd_t;
119
+
120
+ DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit:", jpp_.isa, ""),
121
+ jit_uni_pooling_bwd_t);
122
+
123
+ status_t init(engine_t *engine) {
124
+ using namespace utils;
125
+
126
+ const bool ok = true && set_default_params() == status::success
127
+ && !is_fwd() && !has_zero_dim_memory()
128
+ && everyone_is(d_type, diff_src_md()->data_type,
129
+ diff_dst_md()->data_type)
130
+ && attr()->has_default_values() && !is_dilated();
131
+ if (!ok) return status::unimplemented;
132
+
133
+ if (desc()->alg_kind == alg_kind::pooling_max) {
134
+ init_default_ws();
135
+ if (!compare_ws(hint_fwd_pd_)) return status::unimplemented;
136
+ }
137
+
138
+ auto scratchpad = scratchpad_registry().registrar();
139
+
140
+ CHECK(jit_uni_pool_kernel<isa>::init_conf(
141
+ jpp_, scratchpad, attr_, this));
142
+
143
+ return status::success;
144
+ }
145
+
146
+ jit_pool_conf_t jpp_;
147
+ };
148
+
149
+ explicit jit_uni_pooling_bwd_t(const pd_t *apd);
150
+ jit_uni_pooling_bwd_t(jit_uni_pooling_bwd_t &&) = default;
151
+ jit_uni_pooling_bwd_t &operator=(jit_uni_pooling_bwd_t &&) = default;
152
+ ~jit_uni_pooling_bwd_t();
153
+
154
+ using data_t = typename prec_traits<d_type>::type;
155
+
156
+ status_t init(engine_t *engine) override;
157
+
158
+ status_t execute(const exec_ctx_t &ctx) const override {
159
+ auto diff_dst = CTX_IN_MEM(const data_t *, DNNL_ARG_DIFF_DST);
160
+ auto ws = CTX_IN_MEM(const char *, DNNL_ARG_WORKSPACE);
161
+ auto diff_src = CTX_OUT_MEM(data_t *, DNNL_ARG_DIFF_SRC);
162
+
163
+ if (pd()->ndims() == 5)
164
+ execute_backward_3d(diff_dst, ws, diff_src, ctx);
165
+ else
166
+ execute_backward(diff_dst, ws, diff_src, ctx);
167
+
168
+ return status::success;
169
+ }
170
+
171
+ private:
172
+ void execute_backward(const data_t *diff_dst, const char *indices,
173
+ data_t *diff_src, const exec_ctx_t &ctx) const;
174
+ void execute_backward_3d(const data_t *diff_dst, const char *indices,
175
+ data_t *diff_src, const exec_ctx_t &ctx) const;
176
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
177
+ status_t init_ncsp_trans_ctx();
178
+
179
+ std::unique_ptr<jit_uni_pool_kernel<isa>> kernel_;
180
+ std::unique_ptr<jit_uni_pooling_utils::trans_context_t> trans_ctx_;
181
+ static constexpr data_type_t wsp_dt_ = data_type::f32;
182
+ };
183
+
184
+ } // namespace aarch64
185
+ } // namespace cpu
186
+ } // namespace impl
187
+ } // namespace dnnl
188
+
189
+ #endif
190
+
191
+ // vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
miniconda3/envs/active_proaction/lib/python3.10/site-packages/tensorflow/include/external/onednn/src/cpu/aarch64/jit_uni_reorder.hpp ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2018-2023 Intel Corporation
3
+ * Copyright 2020-2023 FUJITSU LIMITED
4
+ * Copyright 2022 Arm Ltd. and affiliates
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *******************************************************************************/
18
+
19
+ #ifndef CPU_AARCH64_JIT_UNI_REORDER_HPP
20
+ #define CPU_AARCH64_JIT_UNI_REORDER_HPP
21
+
22
+ #include <assert.h>
23
+
24
+ #include "common/c_types_map.hpp"
25
+ #include "common/type_helpers.hpp"
26
+
27
+ #include "cpu/reorder/cpu_reorder_pd.hpp"
28
+
29
+ namespace dnnl {
30
+ namespace impl {
31
+ namespace cpu {
32
+ namespace aarch64 {
33
+
34
+ namespace tr {
35
+
36
+ constexpr int max_ndims = DNNL_MAX_NDIMS;
37
+
38
+ struct node_t {
39
+ static constexpr int64_t empty_field = -1;
40
+
41
+ size_t n = 0;
42
+ size_t tail_size = 0;
43
+ int dim_id = empty_field;
44
+ int parent_node_id = empty_field;
45
+ bool is_zero_pad_needed = false;
46
+ ptrdiff_t is = 0; // input stride
47
+ ptrdiff_t os = 0; // output stride
48
+ ptrdiff_t ss = 0; // scale stride
49
+ ptrdiff_t cs = 0; // compensation stride
50
+
51
+ bool is_dim_id_empty() const { return dim_id == empty_field; }
52
+ bool is_parent_empty() const { return parent_node_id == empty_field; }
53
+ };
54
+
55
+ enum class scale_type_t { NONE, COMMON, MANY };
56
+
57
+ struct prb_t {
58
+ /* The compensation mask value indicates how big an additional buffer should be.
59
+ * Possible values for reorder:
60
+ * 1) standard compensation = 1 = 0b01
61
+ * 2) asymmetric compensation = 2 = 0b10
62
+ * 3) compensation if tensor contains group = 3 = 0b11 */
63
+ static constexpr int invalid_comp_mask = 0;
64
+ static constexpr int standard_comp_mask = 0b1;
65
+ static constexpr int asymmetric_comp_mask = 0b10;
66
+ static constexpr int comp_mask_with_groups
67
+ = standard_comp_mask + asymmetric_comp_mask;
68
+
69
+ bool is_tail_in_one_of_child_nodes(int parent_node_id) const {
70
+ for (int i = parent_node_id; i >= 0; i--) {
71
+ if (nodes[i].parent_node_id == parent_node_id) {
72
+ if (nodes[i].tail_size != 0)
73
+ return true;
74
+ else
75
+ parent_node_id = i;
76
+ }
77
+ }
78
+
79
+ return false;
80
+ }
81
+
82
+ int tail(int d) const {
83
+ assert(d < ndims);
84
+ return static_cast<int>(nodes[d].tail_size);
85
+ }
86
+
87
+ int n(int d) const {
88
+ assert(d < ndims);
89
+ return static_cast<int>(nodes[d].n);
90
+ }
91
+ int is(int d) const {
92
+ assert(d < ndims);
93
+ return static_cast<int>(nodes[d].is);
94
+ }
95
+ int os(int d) const {
96
+ assert(d < ndims);
97
+ return static_cast<int>(nodes[d].os);
98
+ }
99
+ int ss(int d) const {
100
+ assert(d < ndims);
101
+ return static_cast<int>(nodes[d].ss);
102
+ }
103
+
104
+ int cs(int d) const {
105
+ assert(d < ndims);
106
+ return static_cast<int>(nodes[d].cs);
107
+ }
108
+
109
+ data_type_t itype;
110
+ data_type_t otype;
111
+ int ndims;
112
+ node_t nodes[max_ndims];
113
+ ptrdiff_t ioff;
114
+ ptrdiff_t ooff;
115
+ scale_type_t src_scale_type;
116
+ scale_type_t dst_scale_type;
117
+ float beta;
118
+ int full_ndims;
119
+ bool is_tail_present = false;
120
+ float scale_adjust = 1.f;
121
+ int compensation_mask = invalid_comp_mask;
122
+ bool req_s8s8_comp = false;
123
+ bool req_asymmetric_comp = false;
124
+ bool req_src_zp = false;
125
+ bool req_dst_zp = false;
126
+ };
127
+
128
+ status_t prb_init(prb_t &prb, const memory_desc_t &imd,
129
+ const memory_desc_t &omd, const primitive_attr_t *attr);
130
+
131
+ /** sorts the problem nodes so that output strides come in ascending order */
132
+ void prb_normalize(prb_t &p);
133
+
134
+ /** fill parent node info for blocked nodes */
135
+ void prb_node_dependency(prb_t &p);
136
+
137
+ /** folds nodes together if possible */
138
+ void prb_simplify(prb_t &p);
139
+
140
+ /** splits the node dim into two of sizes n1 and n / n1
141
+ * @warning n must be multiple of n1 */
142
+ void prb_node_split(prb_t &p, int dim, size_t n1);
143
+
144
+ /** swaps d0 and d1 nodes */
145
+ void prb_node_swap(prb_t &p, int d0, int d1);
146
+
147
+ /** moves node d0 to the d1 position.
148
+ * nodes (d0, d1] are shifted to the left if d0 < d1 or
149
+ * to the right if d0 > d1 */
150
+ void prb_node_move(prb_t &p, int d0, int d1);
151
+
152
+ /** dumps the problem to stdout */
153
+ void prb_dump(const prb_t &p);
154
+
155
+ struct call_param_t {
156
+ const void *in = nullptr;
157
+ void *out = nullptr;
158
+ const float *src_scales = nullptr;
159
+ const float *dst_scales = nullptr;
160
+ int32_t src_zp = 0;
161
+ int32_t dst_zp = 0;
162
+ int32_t *compensation_scratch = nullptr;
163
+ };
164
+
165
+ // The additional structure is needed because
166
+ // using a data structure with tail processing
167
+ // data for non-tail cases reduces kernel
168
+ // performance. This is because there is too
169
+ // much data that has to be transferred to the kernel.
170
+ struct tail_call_param_t {
171
+ call_param_t base_params;
172
+ int64_t curr_data_chunks[DNNL_MAX_NDIMS] = {-1};
173
+ int64_t zeroing_data = static_cast<int64_t>(false);
174
+ int64_t skip_kernel_execution = static_cast<int64_t>(false);
175
+ };
176
+
177
+ struct kernel_t {
178
+ struct desc_t {
179
+ int id;
180
+ prb_t prb;
181
+ };
182
+
183
+ kernel_t(const desc_t &desc)
184
+ : desc_(desc)
185
+ , compensation_needed_(
186
+ desc.prb.req_s8s8_comp || desc.prb.req_asymmetric_comp) {}
187
+ virtual void operator()(const call_param_t *c) const = 0;
188
+ virtual void operator()(const tail_call_param_t *c) const = 0;
189
+ virtual status_t create_kernel() = 0;
190
+ virtual ~kernel_t() {}
191
+
192
+ /** inits kernel descriptor:
193
+ * desc -- kernel descriptor (output)
194
+ * prb -- transposition problem (input)
195
+ * ndims_ker_max -- limit the maximum number of dimensions kernel
196
+ * will process (optional, 0 -- no limitation) */
197
+ static status_t desc_init(
198
+ desc_t &desc, const prb_t &prb, int ndims_ker_max = 0);
199
+
200
+ /** creates kernel for the problem described in desc */
201
+ static kernel_t *create(const desc_t &desc);
202
+
203
+ protected:
204
+ const desc_t desc_;
205
+ const prb_t &prb_ = desc_.prb;
206
+ bool compensation_needed_ = false;
207
+ };
208
+
209
+ /* TODO: add trans_t class */
210
+
211
+ struct jit_single_blk_kernel_t;
212
+
213
+ } // namespace tr
214
+
215
+ struct jit_uni_reorder_t : public primitive_t {
216
+ using primitive_t::primitive_t;
217
+ struct pd_t : public cpu_reorder_pd_t {
218
+ using cpu_reorder_pd_t::cpu_reorder_pd_t;
219
+
220
+ DECLARE_COMMON_PD_T("jit:uni", jit_uni_reorder_t);
221
+
222
+ tr::prb_t prb_;
223
+ tr::kernel_t::desc_t ker_desc_;
224
+ int nthr_;
225
+ bool with_groups_ = false;
226
+ dim_t D_mask_ = 0;
227
+
228
+ status_t init(
229
+ engine_t *engine, engine_t *src_engine, engine_t *dst_engine);
230
+
231
+ private:
232
+ status_t init_scratchpad();
233
+ static status_t create(reorder_pd_t **reorder_pd, engine_t *engine,
234
+ const primitive_attr_t *attr, engine_t *src_engine,
235
+ const memory_desc_t *src_md, engine_t *dst_engine,
236
+ const memory_desc_t *dst_md);
237
+
238
+ friend dnnl::impl::impl_list_item_t;
239
+ };
240
+
241
+ status_t init(engine_t *engine) override;
242
+ status_t execute(const exec_ctx_t &ctx) const override;
243
+
244
+ enum { ndims_driver_max = 4 };
245
+
246
+ private:
247
+ void omp_driver_0d(int off, const char *in, char *out,
248
+ const float *src_scales, const float *dst_scales, int src_zp,
249
+ int dst_zp, int32_t *compensation_scratch) const;
250
+ void omp_driver_1d(int ithr, int nthr, int off, const char *in, char *out,
251
+ const float *src_scales, const float *dst_scales, int src_zp,
252
+ int dst_zp, int32_t *compensation_scratch) const;
253
+ void omp_driver_2d(int ithr, int nthr, int off, const char *in, char *out,
254
+ const float *src_scales, const float *dst_scales, int src_zp,
255
+ int dst_zp, int32_t *compensation_scratch) const;
256
+ void omp_driver_3d(int ithr, int nthr, int off, const char *in, char *out,
257
+ const float *src_scales, const float *dst_scales, int src_zp,
258
+ int dst_zp, int32_t *compensation_scratch) const;
259
+ void omp_driver_4d(int ithr, int nthr, int off, const char *in, char *out,
260
+ const float *src_scales, const float *dst_scales, int src_zp,
261
+ int dst_zp, int32_t *compensation_scratch) const;
262
+
263
+ void omp_driver(const char *in, char *out, const float *src_scales,
264
+ const float *dst_scales, int src_zp, int dst_zp,
265
+ const memory_tracking::grantor_t &scratchpad) const;
266
+
267
+ void fill_curr_data_chunks(const tr::prb_t &prb, const int off,
268
+ const ptrdiff_t *omp_data_chunks, const int omp_ndims,
269
+ tr::tail_call_param_t &c) const;
270
+
271
+ void reduce_compensation(char *out,
272
+ const int32_t *compensation_reduce_scratch, const int nthr,
273
+ const dim_t wspace_per_thr_size) const;
274
+
275
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
276
+ std::unique_ptr<tr::kernel_t> kernel_;
277
+ };
278
+
279
+ struct jit_blk_reorder_t : public primitive_t {
280
+ using primitive_t::primitive_t;
281
+ struct pd_t : public cpu_reorder_pd_t {
282
+ using cpu_reorder_pd_t::cpu_reorder_pd_t;
283
+ DECLARE_COMMON_PD_T("jit:blk", jit_blk_reorder_t);
284
+
285
+ tr::prb_t prb_;
286
+
287
+ private:
288
+ static status_t create(reorder_pd_t **reorder_pd, engine_t *engine,
289
+ const primitive_attr_t *attr, engine_t *src_engine,
290
+ const memory_desc_t *src_md, engine_t *dst_engine,
291
+ const memory_desc_t *dst_md);
292
+
293
+ // Swap last two nodes, put block 4, 8, 16 nodes to first
294
+ static void prb_tile_normalize(tr::prb_t &p);
295
+ friend dnnl::impl::impl_list_item_t;
296
+ };
297
+
298
+ status_t init(engine_t *engine) override;
299
+ status_t execute(const exec_ctx_t &ctx) const override;
300
+
301
+ jit_blk_reorder_t(const pd_t *apd);
302
+ ~jit_blk_reorder_t();
303
+
304
+ private:
305
+ const pd_t *pd() const { return (const pd_t *)primitive_t::pd().get(); }
306
+ std::unique_ptr<tr::jit_single_blk_kernel_t> kernel_;
307
+ };
308
+
309
+ } // namespace aarch64
310
+ } // namespace cpu
311
+ } // namespace impl
312
+ } // namespace dnnl
313
+
314
+ #endif